Skip to content
This repository has been archived by the owner on May 12, 2020. It is now read-only.

Commit

Permalink
Make gui.StyleHelper 100% typed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vandenoever committed Dec 2, 2013
1 parent e220c89 commit 9afb698
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,13 @@ set(TYPEDLIBJSFILES
lib/odf/ObjectNameGenerator.js
lib/odf/TextStyleApplicator.js
lib/odf/Formatting.js
lib/gui/StyleHelper.js
)
# This list is generated automatically, do not edit this list by hand.
set(UNTYPEDLIBJSFILES
# These files depend only on files that are 100% typed.
lib/core/RawDeflate.js
lib/gui/SelectionMover.js
lib/gui/StyleHelper.js
lib/odf/OdfCanvas.js
lib/ops/Member.js
lib/ops/StepsTranslator.js
Expand Down
32 changes: 16 additions & 16 deletions webodf/lib/gui/StyleHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ gui.StyleHelper = function StyleHelper(formatting) {
/**
* Returns true if all the node within given range have the same value for
* the property; otherwise false.
* @param {!Array.<Object>} appliedStyles
* @param {!string} propertyName
* @param {!string} propertyValue
* @return {!boolean}
* @param {!Array.<!Object.<string,!Object.<string,string>>>} appliedStyles
* @param {string} propertyName
* @param {string} propertyValue
* @return {boolean}
*/
function hasTextPropertyValue(appliedStyles, propertyName, propertyValue) {
var hasOtherValue = true,
properties, i;
var hasOtherValue = true, properties, i;

for (i = 0; i < appliedStyles.length; i += 1) {
properties = appliedStyles[i]['style:text-properties'];
Expand Down Expand Up @@ -170,10 +169,11 @@ gui.StyleHelper = function StyleHelper(formatting) {
* @return {!boolean}
*/
function hasParagraphPropertyValue(range, propertyName, propertyValues) {
var nodes = odfUtils.getParagraphElements(range),
var paragraphStyleName, paragraphStyleElement, paragraphStyleAttributes,
properties,
nodes = odfUtils.getParagraphElements(range),
isStyleChecked = {},
isDefaultParagraphStyleChecked = false,
paragraphStyleName, paragraphStyleElement, paragraphStyleAttributes, properties;
isDefaultParagraphStyleChecked = false;

function pickDefaultParagraphStyleElement() {
isDefaultParagraphStyleChecked = true;
Expand All @@ -188,14 +188,14 @@ gui.StyleHelper = function StyleHelper(formatting) {
paragraphStyleName = nodes[0].getAttributeNS(textns, 'style-name');
if (paragraphStyleName) {
if (!isStyleChecked[paragraphStyleName]) {
paragraphStyleElement = formatting.getStyleElement(paragraphStyleName, 'paragraph') ;
paragraphStyleElement = formatting.getStyleElement(paragraphStyleName, 'paragraph');
isStyleChecked[paragraphStyleName] = true;
// in no such style node exists, fallback to default style
if (!paragraphStyleElement && !isDefaultParagraphStyleChecked) {
pickDefaultParagraphStyleElement();
}
}
} else if(!isDefaultParagraphStyleChecked) {
} else if (!isDefaultParagraphStyleChecked) {
pickDefaultParagraphStyleElement();
} else {
paragraphStyleElement = undefined;
Expand All @@ -206,7 +206,7 @@ gui.StyleHelper = function StyleHelper(formatting) {
if (paragraphStyleElement === null) {
paragraphStyleAttributes = formatting.getSystemDefaultStyleAttributes('paragraph');
} else {
paragraphStyleAttributes = formatting.getInheritedStyleAttributes(/**@type {!Element}*/(paragraphStyleElement), true);
paragraphStyleAttributes = formatting.getInheritedStyleAttributes(/**@type{!Element}*/(paragraphStyleElement), true);
}
properties = paragraphStyleAttributes['style:paragraph-properties'];
if (properties && propertyValues.indexOf(properties[propertyName]) === -1) {
Expand All @@ -224,7 +224,7 @@ gui.StyleHelper = function StyleHelper(formatting) {
* @param {!Range} range
* @return {!boolean}
*/
this.isAlignedLeft = function(range) {
this.isAlignedLeft = function (range) {
return hasParagraphPropertyValue(range, 'fo:text-align', ['left', 'start']);
};

Expand All @@ -233,7 +233,7 @@ gui.StyleHelper = function StyleHelper(formatting) {
* @param {!Range} range
* @return {!boolean}
*/
this.isAlignedCenter = function(range) {
this.isAlignedCenter = function (range) {
return hasParagraphPropertyValue(range, 'fo:text-align', ['center']);
};

Expand All @@ -242,7 +242,7 @@ gui.StyleHelper = function StyleHelper(formatting) {
* @param {!Range} range
* @return {!boolean}
*/
this.isAlignedRight = function(range) {
this.isAlignedRight = function (range) {
return hasParagraphPropertyValue(range, 'fo:text-align', ['right', 'end']);
};

Expand All @@ -251,7 +251,7 @@ gui.StyleHelper = function StyleHelper(formatting) {
* @param {!Range} range
* @return {!boolean}
*/
this.isAlignedJustified = function(range) {
this.isAlignedJustified = function (range) {
return hasParagraphPropertyValue(range, 'fo:text-align', ['justify']);
};
};
8 changes: 4 additions & 4 deletions webodf/lib/odf/Formatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ odf.Formatting = function Formatting() {
* of a given style family.
* Creates a deep copy, so the result can be modified by the callee.
* If there are no such attributes, null is returned.
* @param {!string} styleFamily
* @return {?Object}
* @param {string} styleFamily
* @return {!Object.<string,!Object.<string,string>>}
*/
function getSystemDefaultStyleAttributes(styleFamily) {
var result,
Expand All @@ -103,7 +103,7 @@ odf.Formatting = function Formatting() {
// reusing mergeObjects to copy builtInDefaultStyleAttributes into the result
result = utils.mergeObjects({}, builtInDefaultStyleAttributes);
} else {
result = null;
result = {};
}

return result;
Expand Down Expand Up @@ -314,7 +314,7 @@ odf.Formatting = function Formatting() {
* inherited from it's ancestry - up to and including the default style for the family.
* @param {!Element} styleNode
* @param {!boolean=} includeSystemDefault
* @return {!Object}
* @return {!Object.<string,!Object.<string,string>>}
*/
function getInheritedStyleAttributes(styleNode, includeSystemDefault) {
var styleListElement = odfContainer.rootElement.styles,
Expand Down
1 change: 1 addition & 0 deletions webodf/tools/updateJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ function Main() {
"gui/Clipboard.js",
"gui/EditInfoHandle.js",
"gui/KeyboardHandler.js",
"gui/StyleHelper.js",
"odf/FontLoader.js",
"odf/Formatting.js",
"odf/MetadataManager.js",
Expand Down

0 comments on commit 9afb698

Please sign in to comment.