Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(584)

Unified Diff: third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js
diff --git a/third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js b/third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js
index 3c9d08dd79c5e5e6901638537da4af0c8d806c62..3ae4256b849c6f78674f00bfc621bb2f891db59e 100644
--- a/third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js
+++ b/third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js
@@ -29,7 +29,6 @@
* Contains diff method based on Javascript Diff Algorithm By John Resig
* http://ejohn.org/files/jsdiff.js (released under the MIT license).
*/
-
/**
* @param {number} offset
* @param {string} stopCharacters
@@ -37,107 +36,106 @@
* @param {string=} direction
* @return {!Range}
*/
-Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, direction)
-{
- var startNode;
- var startOffset = 0;
- var endNode;
- var endOffset = 0;
-
- if (!stayWithinNode)
- stayWithinNode = this;
-
- if (!direction || direction === "backward" || direction === "both") {
- var node = this;
- while (node) {
- if (node === stayWithinNode) {
- if (!startNode)
- startNode = stayWithinNode;
- break;
- }
-
- if (node.nodeType === Node.TEXT_NODE) {
- var start = (node === this ? (offset - 1) : (node.nodeValue.length - 1));
- for (var i = start; i >= 0; --i) {
- if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
- startNode = node;
- startOffset = i + 1;
- break;
- }
- }
- }
-
- if (startNode)
- break;
-
- node = node.traversePreviousNode(stayWithinNode);
- }
+Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, direction) {
+ var startNode;
+ var startOffset = 0;
+ var endNode;
+ var endOffset = 0;
- if (!startNode) {
- startNode = stayWithinNode;
- startOffset = 0;
+ if (!stayWithinNode)
+ stayWithinNode = this;
+
+ if (!direction || direction === 'backward' || direction === 'both') {
+ var node = this;
+ while (node) {
+ if (node === stayWithinNode) {
+ if (!startNode)
+ startNode = stayWithinNode;
+ break;
+ }
+
+ if (node.nodeType === Node.TEXT_NODE) {
+ var start = (node === this ? (offset - 1) : (node.nodeValue.length - 1));
+ for (var i = start; i >= 0; --i) {
+ if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
+ startNode = node;
+ startOffset = i + 1;
+ break;
+ }
}
- } else {
- startNode = this;
- startOffset = offset;
+ }
+
+ if (startNode)
+ break;
+
+ node = node.traversePreviousNode(stayWithinNode);
}
- if (!direction || direction === "forward" || direction === "both") {
- node = this;
- while (node) {
- if (node === stayWithinNode) {
- if (!endNode)
- endNode = stayWithinNode;
- break;
- }
-
- if (node.nodeType === Node.TEXT_NODE) {
- var start = (node === this ? offset : 0);
- for (var i = start; i < node.nodeValue.length; ++i) {
- if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
- endNode = node;
- endOffset = i;
- break;
- }
- }
- }
-
- if (endNode)
- break;
-
- node = node.traverseNextNode(stayWithinNode);
- }
+ if (!startNode) {
+ startNode = stayWithinNode;
+ startOffset = 0;
+ }
+ } else {
+ startNode = this;
+ startOffset = offset;
+ }
- if (!endNode) {
- endNode = stayWithinNode;
- endOffset = stayWithinNode.nodeType === Node.TEXT_NODE ? stayWithinNode.nodeValue.length : stayWithinNode.childNodes.length;
+ if (!direction || direction === 'forward' || direction === 'both') {
+ node = this;
+ while (node) {
+ if (node === stayWithinNode) {
+ if (!endNode)
+ endNode = stayWithinNode;
+ break;
+ }
+
+ if (node.nodeType === Node.TEXT_NODE) {
+ var start = (node === this ? offset : 0);
+ for (var i = start; i < node.nodeValue.length; ++i) {
+ if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
+ endNode = node;
+ endOffset = i;
+ break;
+ }
}
- } else {
- endNode = this;
- endOffset = offset;
+ }
+
+ if (endNode)
+ break;
+
+ node = node.traverseNextNode(stayWithinNode);
}
- var result = this.ownerDocument.createRange();
- result.setStart(startNode, startOffset);
- result.setEnd(endNode, endOffset);
+ if (!endNode) {
+ endNode = stayWithinNode;
+ endOffset = stayWithinNode.nodeType === Node.TEXT_NODE ? stayWithinNode.nodeValue.length :
+ stayWithinNode.childNodes.length;
+ }
+ } else {
+ endNode = this;
+ endOffset = offset;
+ }
- return result;
+ var result = this.ownerDocument.createRange();
+ result.setStart(startNode, startOffset);
+ result.setEnd(endNode, endOffset);
+
+ return result;
};
/**
* @param {!Node=} stayWithin
* @return {?Node}
*/
-Node.prototype.traverseNextTextNode = function(stayWithin)
-{
- var node = this.traverseNextNode(stayWithin);
- if (!node)
- return null;
- var nonTextTags = { "STYLE": 1, "SCRIPT": 1 };
- while (node && (node.nodeType !== Node.TEXT_NODE || nonTextTags[node.parentElement.nodeName]))
- node = node.traverseNextNode(stayWithin);
+Node.prototype.traverseNextTextNode = function(stayWithin) {
+ var node = this.traverseNextNode(stayWithin);
+ if (!node)
+ return null;
+ var nonTextTags = {'STYLE': 1, 'SCRIPT': 1};
+ while (node && (node.nodeType !== Node.TEXT_NODE || nonTextTags[node.parentElement.nodeName]))
+ node = node.traverseNextNode(stayWithin);
- return node;
+ return node;
};
/**
@@ -145,63 +143,59 @@ Node.prototype.traverseNextTextNode = function(stayWithin)
* @param {number|undefined} y
* @param {!Element=} relativeTo
*/
-Element.prototype.positionAt = function(x, y, relativeTo)
-{
- var shift = {x: 0, y: 0};
- if (relativeTo)
- shift = relativeTo.boxInWindow(this.ownerDocument.defaultView);
+Element.prototype.positionAt = function(x, y, relativeTo) {
+ var shift = {x: 0, y: 0};
+ if (relativeTo)
+ shift = relativeTo.boxInWindow(this.ownerDocument.defaultView);
- if (typeof x === "number")
- this.style.setProperty("left", (shift.x + x) + "px");
- else
- this.style.removeProperty("left");
+ if (typeof x === 'number')
+ this.style.setProperty('left', (shift.x + x) + 'px');
+ else
+ this.style.removeProperty('left');
- if (typeof y === "number")
- this.style.setProperty("top", (shift.y + y) + "px");
- else
- this.style.removeProperty("top");
+ if (typeof y === 'number')
+ this.style.setProperty('top', (shift.y + y) + 'px');
+ else
+ this.style.removeProperty('top');
- if (typeof x === "number" || typeof y === "number")
- this.style.setProperty("position", "absolute");
- else
- this.style.removeProperty("position");
+ if (typeof x === 'number' || typeof y === 'number')
+ this.style.setProperty('position', 'absolute');
+ else
+ this.style.removeProperty('position');
};
/**
* @return {boolean}
*/
-Element.prototype.isScrolledToBottom = function()
-{
- // This code works only for 0-width border.
- // The scrollTop, clientHeight and scrollHeight are computed in double values internally.
- // However, they are exposed to javascript differently, each being either rounded (via
- // round, ceil or floor functions) or left intouch.
- // This adds up a total error up to 2.
- return Math.abs(this.scrollTop + this.clientHeight - this.scrollHeight) <= 2;
+Element.prototype.isScrolledToBottom = function() {
+ // This code works only for 0-width border.
+ // The scrollTop, clientHeight and scrollHeight are computed in double values internally.
+ // However, they are exposed to javascript differently, each being either rounded (via
+ // round, ceil or floor functions) or left intouch.
+ // This adds up a total error up to 2.
+ return Math.abs(this.scrollTop + this.clientHeight - this.scrollHeight) <= 2;
};
/**
* @param {!Array.<string>} nameArray
* @return {?Node}
*/
-Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray)
-{
- for (var node = this; node && node !== this.ownerDocument; node = node.parentNodeOrShadowHost()) {
- for (var i = 0; i < nameArray.length; ++i) {
- if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
- return node;
- }
+Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray) {
+ for (var node = this; node && node !== this.ownerDocument; node = node.parentNodeOrShadowHost()) {
+ for (var i = 0; i < nameArray.length; ++i) {
+ if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
+ return node;
}
- return null;
+ }
+ return null;
};
/**
* @param {string} nodeName
* @return {?Node}
*/
-Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName)
-{
- return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]);
+Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName) {
+ return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]);
};
/**
@@ -209,9 +203,8 @@ Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName)
* @param {!Element=} stayWithin
* @return {?Element}
*/
-Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin)
-{
- return this.enclosingNodeOrSelfWithClassList([className], stayWithin);
+Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin) {
+ return this.enclosingNodeOrSelfWithClassList([className], stayWithin);
};
/**
@@ -219,105 +212,96 @@ Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin)
* @param {!Element=} stayWithin
* @return {?Element}
*/
-Node.prototype.enclosingNodeOrSelfWithClassList = function(classNames, stayWithin)
-{
- for (var node = this; node && node !== stayWithin && node !== this.ownerDocument; node = node.parentNodeOrShadowHost()) {
- if (node.nodeType === Node.ELEMENT_NODE) {
- var containsAll = true;
- for (var i = 0; i < classNames.length && containsAll; ++i) {
- if (!node.classList.contains(classNames[i]))
- containsAll = false;
- }
- if (containsAll)
- return /** @type {!Element} */ (node);
- }
+Node.prototype.enclosingNodeOrSelfWithClassList = function(classNames, stayWithin) {
+ for (var node = this; node && node !== stayWithin && node !== this.ownerDocument;
+ node = node.parentNodeOrShadowHost()) {
+ if (node.nodeType === Node.ELEMENT_NODE) {
+ var containsAll = true;
+ for (var i = 0; i < classNames.length && containsAll; ++i) {
+ if (!node.classList.contains(classNames[i]))
+ containsAll = false;
+ }
+ if (containsAll)
+ return /** @type {!Element} */ (node);
}
- return null;
+ }
+ return null;
};
/**
* @return {?Element}
*/
-Node.prototype.parentElementOrShadowHost = function()
-{
- var node = this.parentNode;
- if (!node)
- return null;
- if (node.nodeType === Node.ELEMENT_NODE)
- return /** @type {!Element} */ (node);
- if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)
- return /** @type {!Element} */ (node.host);
+Node.prototype.parentElementOrShadowHost = function() {
+ var node = this.parentNode;
+ if (!node)
return null;
+ if (node.nodeType === Node.ELEMENT_NODE)
+ return /** @type {!Element} */ (node);
+ if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)
+ return /** @type {!Element} */ (node.host);
+ return null;
};
/**
* @return {?Node}
*/
-Node.prototype.parentNodeOrShadowHost = function()
-{
- return this.parentNode || this.host || null;
+Node.prototype.parentNodeOrShadowHost = function() {
+ return this.parentNode || this.host || null;
};
/**
* @return {?Selection}
*/
-Node.prototype.getComponentSelection = function()
-{
- var parent = this.parentNode;
- while (parent && parent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE)
- parent = parent.parentNode;
- return parent instanceof ShadowRoot ? parent.getSelection() : this.window().getSelection();
+Node.prototype.getComponentSelection = function() {
+ var parent = this.parentNode;
+ while (parent && parent.nodeType !== Node.DOCUMENT_FRAGMENT_NODE)
+ parent = parent.parentNode;
+ return parent instanceof ShadowRoot ? parent.getSelection() : this.window().getSelection();
};
-
/**
* @return {boolean}
*/
-Node.prototype.isComponentSelectionCollapsed = function()
-{
- // FIXME: crbug.com/447523, use selection.isCollapsed when it is fixed for shadow dom.
- var selection = this.getComponentSelection();
- var range = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
- return range ? range.collapsed : true;
+Node.prototype.isComponentSelectionCollapsed = function() {
+ // FIXME: crbug.com/447523, use selection.isCollapsed when it is fixed for shadow dom.
+ var selection = this.getComponentSelection();
+ var range = selection && selection.rangeCount ? selection.getRangeAt(0) : null;
+ return range ? range.collapsed : true;
};
/**
* @return {boolean}
*/
-Node.prototype.hasSelection = function()
-{
- if (this.isComponentSelectionCollapsed())
- return false;
- return this.getComponentSelection().containsNode(this, true);
+Node.prototype.hasSelection = function() {
+ if (this.isComponentSelectionCollapsed())
+ return false;
+ return this.getComponentSelection().containsNode(this, true);
};
/**
* @return {!Selection}
*/
-Node.prototype.getDeepSelection = function()
-{
- var activeElement = this.ownerDocument.activeElement;
- var shadowRoot = null;
- while (activeElement && activeElement.shadowRoot) {
- shadowRoot = activeElement.shadowRoot;
- activeElement = shadowRoot.activeElement;
- }
+Node.prototype.getDeepSelection = function() {
+ var activeElement = this.ownerDocument.activeElement;
+ var shadowRoot = null;
+ while (activeElement && activeElement.shadowRoot) {
+ shadowRoot = activeElement.shadowRoot;
+ activeElement = shadowRoot.activeElement;
+ }
- return shadowRoot ? shadowRoot.getSelection() : this.window().getSelection();
+ return shadowRoot ? shadowRoot.getSelection() : this.window().getSelection();
};
/**
* @return {!Window}
*/
-Node.prototype.window = function()
-{
- return this.ownerDocument.defaultView;
+Node.prototype.window = function() {
+ return this.ownerDocument.defaultView;
};
-Element.prototype.removeChildren = function()
-{
- if (this.firstChild)
- this.textContent = "";
+Element.prototype.removeChildren = function() {
+ if (this.firstChild)
+ this.textContent = '';
};
/**
@@ -326,9 +310,8 @@ Element.prototype.removeChildren = function()
* @return {!Element}
* @suppressGlobalPropertiesCheck
*/
-function createElement(tagName, customElementType)
-{
- return document.createElement(tagName, customElementType || "");
+function createElement(tagName, customElementType) {
+ return document.createElement(tagName, customElementType || '');
}
/**
@@ -336,9 +319,8 @@ function createElement(tagName, customElementType)
* @return {!Text}
* @suppressGlobalPropertiesCheck
*/
-function createTextNode(data)
-{
- return document.createTextNode(data);
+function createTextNode(data) {
+ return document.createTextNode(data);
}
/**
@@ -347,12 +329,11 @@ function createTextNode(data)
* @param {string=} customElementType
* @return {!Element}
*/
-Document.prototype.createElementWithClass = function(elementName, className, customElementType)
-{
- var element = this.createElement(elementName, customElementType || "");
- if (className)
- element.className = className;
- return element;
+Document.prototype.createElementWithClass = function(elementName, className, customElementType) {
+ var element = this.createElement(elementName, customElementType || '');
+ if (className)
+ element.className = className;
+ return element;
};
/**
@@ -362,9 +343,8 @@ Document.prototype.createElementWithClass = function(elementName, className, cus
* @return {!Element}
* @suppressGlobalPropertiesCheck
*/
-function createElementWithClass(elementName, className, customElementType)
-{
- return document.createElementWithClass(elementName, className, customElementType);
+function createElementWithClass(elementName, className, customElementType) {
+ return document.createElementWithClass(elementName, className, customElementType);
}
/**
@@ -372,12 +352,11 @@ function createElementWithClass(elementName, className, customElementType)
* @param {string=} className
* @return {!Element}
*/
-Document.prototype.createSVGElement = function(childType, className)
-{
- var element = this.createElementNS("http://www.w3.org/2000/svg", childType);
- if (className)
- element.setAttribute("class", className);
- return element;
+Document.prototype.createSVGElement = function(childType, className) {
+ var element = this.createElementNS('http://www.w3.org/2000/svg', childType);
+ if (className)
+ element.setAttribute('class', className);
+ return element;
};
/**
@@ -386,18 +365,16 @@ Document.prototype.createSVGElement = function(childType, className)
* @return {!Element}
* @suppressGlobalPropertiesCheck
*/
-function createSVGElement(childType, className)
-{
- return document.createSVGElement(childType, className);
+function createSVGElement(childType, className) {
+ return document.createSVGElement(childType, className);
}
/**
* @return {!DocumentFragment}
* @suppressGlobalPropertiesCheck
*/
-function createDocumentFragment()
-{
- return document.createDocumentFragment();
+function createDocumentFragment() {
+ return document.createDocumentFragment();
}
/**
@@ -406,11 +383,10 @@ function createDocumentFragment()
* @param {string=} customElementType
* @return {!Element}
*/
-Element.prototype.createChild = function(elementName, className, customElementType)
-{
- var element = this.ownerDocument.createElementWithClass(elementName, className, customElementType);
- this.appendChild(element);
- return element;
+Element.prototype.createChild = function(elementName, className, customElementType) {
+ var element = this.ownerDocument.createElementWithClass(elementName, className, customElementType);
+ this.appendChild(element);
+ return element;
};
DocumentFragment.prototype.createChild = Element.prototype.createChild;
@@ -419,11 +395,10 @@ DocumentFragment.prototype.createChild = Element.prototype.createChild;
* @param {string} text
* @return {!Text}
*/
-Element.prototype.createTextChild = function(text)
-{
- var element = this.ownerDocument.createTextNode(text);
- this.appendChild(element);
- return element;
+Element.prototype.createTextChild = function(text) {
+ var element = this.ownerDocument.createTextNode(text);
+ this.appendChild(element);
+ return element;
};
DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild;
@@ -431,10 +406,9 @@ DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild;
/**
* @param {...string} var_args
*/
-Element.prototype.createTextChildren = function(var_args)
-{
- for (var i = 0, n = arguments.length; i < n; ++i)
- this.createTextChild(arguments[i]);
+Element.prototype.createTextChildren = function(var_args) {
+ for (var i = 0, n = arguments.length; i < n; ++i)
+ this.createTextChild(arguments[i]);
};
DocumentFragment.prototype.createTextChildren = Element.prototype.createTextChildren;
@@ -442,26 +416,23 @@ DocumentFragment.prototype.createTextChildren = Element.prototype.createTextChil
/**
* @return {number}
*/
-Element.prototype.totalOffsetLeft = function()
-{
- return this.totalOffset().left;
+Element.prototype.totalOffsetLeft = function() {
+ return this.totalOffset().left;
};
/**
* @return {number}
*/
-Element.prototype.totalOffsetTop = function()
-{
- return this.totalOffset().top;
+Element.prototype.totalOffsetTop = function() {
+ return this.totalOffset().top;
};
/**
* @return {!{left: number, top: number}}
*/
-Element.prototype.totalOffset = function()
-{
- var rect = this.getBoundingClientRect();
- return { left: rect.left, top: rect.top };
+Element.prototype.totalOffset = function() {
+ var rect = this.getBoundingClientRect();
+ return {left: rect.left, top: rect.top};
};
/**
@@ -469,90 +440,87 @@ Element.prototype.totalOffset = function()
* @param {string=} className
* @return {!Element}
*/
-Element.prototype.createSVGChild = function(childType, className)
-{
- var child = this.ownerDocument.createSVGElement(childType, className);
- this.appendChild(child);
- return child;
+Element.prototype.createSVGChild = function(childType, className) {
+ var child = this.ownerDocument.createSVGElement(childType, className);
+ this.appendChild(child);
+ return child;
};
/**
- * @constructor
- * @param {number=} x
- * @param {number=} y
- * @param {number=} width
- * @param {number=} height
+ * @unrestricted
*/
-function AnchorBox(x, y, width, height)
-{
+var AnchorBox = class {
+ /**
+ * @param {number=} x
+ * @param {number=} y
+ * @param {number=} width
+ * @param {number=} height
+ */
+ constructor(x, y, width, height) {
this.x = x || 0;
this.y = y || 0;
this.width = width || 0;
this.height = height || 0;
-}
+ }
+};
/**
* @param {!AnchorBox} box
* @return {!AnchorBox}
*/
-AnchorBox.prototype.relativeTo = function(box)
-{
- return new AnchorBox(
- this.x - box.x, this.y - box.y, this.width, this.height);
+AnchorBox.prototype.relativeTo = function(box) {
+ return new AnchorBox(this.x - box.x, this.y - box.y, this.width, this.height);
};
/**
* @param {!Element} element
* @return {!AnchorBox}
*/
-AnchorBox.prototype.relativeToElement = function(element)
-{
- return this.relativeTo(element.boxInWindow(element.ownerDocument.defaultView));
+AnchorBox.prototype.relativeToElement = function(element) {
+ return this.relativeTo(element.boxInWindow(element.ownerDocument.defaultView));
};
/**
* @param {?AnchorBox} anchorBox
* @return {boolean}
*/
-AnchorBox.prototype.equals = function(anchorBox)
-{
- return !!anchorBox && this.x === anchorBox.x && this.y === anchorBox.y && this.width === anchorBox.width && this.height === anchorBox.height;
+AnchorBox.prototype.equals = function(anchorBox) {
+ return !!anchorBox && this.x === anchorBox.x && this.y === anchorBox.y && this.width === anchorBox.width &&
+ this.height === anchorBox.height;
};
/**
* @param {!Window=} targetWindow
* @return {!AnchorBox}
*/
-Element.prototype.boxInWindow = function(targetWindow)
-{
- targetWindow = targetWindow || this.ownerDocument.defaultView;
-
- var anchorBox = new AnchorBox();
- var curElement = this;
- var curWindow = this.ownerDocument.defaultView;
- while (curWindow && curElement) {
- anchorBox.x += curElement.totalOffsetLeft();
- anchorBox.y += curElement.totalOffsetTop();
- if (curWindow === targetWindow)
- break;
- curElement = curWindow.frameElement;
- curWindow = curWindow.parent;
- }
+Element.prototype.boxInWindow = function(targetWindow) {
+ targetWindow = targetWindow || this.ownerDocument.defaultView;
+
+ var anchorBox = new AnchorBox();
+ var curElement = this;
+ var curWindow = this.ownerDocument.defaultView;
+ while (curWindow && curElement) {
+ anchorBox.x += curElement.totalOffsetLeft();
+ anchorBox.y += curElement.totalOffsetTop();
+ if (curWindow === targetWindow)
+ break;
+ curElement = curWindow.frameElement;
+ curWindow = curWindow.parent;
+ }
- anchorBox.width = Math.min(this.offsetWidth, targetWindow.innerWidth - anchorBox.x);
- anchorBox.height = Math.min(this.offsetHeight, targetWindow.innerHeight - anchorBox.y);
- return anchorBox;
+ anchorBox.width = Math.min(this.offsetWidth, targetWindow.innerWidth - anchorBox.x);
+ anchorBox.height = Math.min(this.offsetHeight, targetWindow.innerHeight - anchorBox.y);
+ return anchorBox;
};
/**
* @param {boolean=} preventDefault
*/
-Event.prototype.consume = function(preventDefault)
-{
- this.stopImmediatePropagation();
- if (preventDefault)
- this.preventDefault();
- this.handled = true;
+Event.prototype.consume = function(preventDefault) {
+ this.stopImmediatePropagation();
+ if (preventDefault)
+ this.preventDefault();
+ this.handled = true;
};
/**
@@ -560,199 +528,190 @@ Event.prototype.consume = function(preventDefault)
* @param {number=} end
* @return {!Text}
*/
-Text.prototype.select = function(start, end)
-{
- start = start || 0;
- end = end || this.textContent.length;
+Text.prototype.select = function(start, end) {
+ start = start || 0;
+ end = end || this.textContent.length;
- if (start < 0)
- start = end + start;
+ if (start < 0)
+ start = end + start;
- var selection = this.getComponentSelection();
- selection.removeAllRanges();
- var range = this.ownerDocument.createRange();
- range.setStart(this, start);
- range.setEnd(this, end);
- selection.addRange(range);
- return this;
+ var selection = this.getComponentSelection();
+ selection.removeAllRanges();
+ var range = this.ownerDocument.createRange();
+ range.setStart(this, start);
+ range.setEnd(this, end);
+ selection.addRange(range);
+ return this;
};
/**
* @return {?number}
*/
-Element.prototype.selectionLeftOffset = function()
-{
- // Calculate selection offset relative to the current element.
+Element.prototype.selectionLeftOffset = function() {
+ // Calculate selection offset relative to the current element.
- var selection = this.getComponentSelection();
- if (!selection.containsNode(this, true))
- return null;
+ var selection = this.getComponentSelection();
+ if (!selection.containsNode(this, true))
+ return null;
- var leftOffset = selection.anchorOffset;
- var node = selection.anchorNode;
+ var leftOffset = selection.anchorOffset;
+ var node = selection.anchorNode;
- while (node !== this) {
- while (node.previousSibling) {
- node = node.previousSibling;
- leftOffset += node.textContent.length;
- }
- node = node.parentNodeOrShadowHost();
+ while (node !== this) {
+ while (node.previousSibling) {
+ node = node.previousSibling;
+ leftOffset += node.textContent.length;
}
+ node = node.parentNodeOrShadowHost();
+ }
- return leftOffset;
+ return leftOffset;
};
/**
* @param {...!Node} var_args
*/
-Node.prototype.appendChildren = function(var_args)
-{
- for (var i = 0, n = arguments.length; i < n; ++i)
- this.appendChild(arguments[i]);
+Node.prototype.appendChildren = function(var_args) {
+ for (var i = 0, n = arguments.length; i < n; ++i)
+ this.appendChild(arguments[i]);
};
/**
* @return {string}
*/
-Node.prototype.deepTextContent = function()
-{
- return this.childTextNodes().map(function(node) { return node.textContent; }).join("");
+Node.prototype.deepTextContent = function() {
+ return this.childTextNodes()
+ .map(function(node) {
+ return node.textContent;
+ })
+ .join('');
};
/**
* @return {!Array.<!Node>}
*/
-Node.prototype.childTextNodes = function()
-{
- var node = this.traverseNextTextNode(this);
- var result = [];
- var nonTextTags = { "STYLE": 1, "SCRIPT": 1 };
- while (node) {
- if (!nonTextTags[node.parentElement.nodeName])
- result.push(node);
- node = node.traverseNextTextNode(this);
- }
- return result;
+Node.prototype.childTextNodes = function() {
+ var node = this.traverseNextTextNode(this);
+ var result = [];
+ var nonTextTags = {'STYLE': 1, 'SCRIPT': 1};
+ while (node) {
+ if (!nonTextTags[node.parentElement.nodeName])
+ result.push(node);
+ node = node.traverseNextTextNode(this);
+ }
+ return result;
};
/**
* @param {?Node} node
* @return {boolean}
*/
-Node.prototype.isAncestor = function(node)
-{
- if (!node)
- return false;
-
- var currentNode = node.parentNodeOrShadowHost();
- while (currentNode) {
- if (this === currentNode)
- return true;
- currentNode = currentNode.parentNodeOrShadowHost();
- }
+Node.prototype.isAncestor = function(node) {
+ if (!node)
return false;
+
+ var currentNode = node.parentNodeOrShadowHost();
+ while (currentNode) {
+ if (this === currentNode)
+ return true;
+ currentNode = currentNode.parentNodeOrShadowHost();
+ }
+ return false;
};
/**
* @param {?Node} descendant
* @return {boolean}
*/
-Node.prototype.isDescendant = function(descendant)
-{
- return !!descendant && descendant.isAncestor(this);
+Node.prototype.isDescendant = function(descendant) {
+ return !!descendant && descendant.isAncestor(this);
};
/**
* @param {?Node} node
* @return {boolean}
*/
-Node.prototype.isSelfOrAncestor = function(node)
-{
- return !!node && (node === this || this.isAncestor(node));
+Node.prototype.isSelfOrAncestor = function(node) {
+ return !!node && (node === this || this.isAncestor(node));
};
/**
* @param {?Node} node
* @return {boolean}
*/
-Node.prototype.isSelfOrDescendant = function(node)
-{
- return !!node && (node === this || this.isDescendant(node));
+Node.prototype.isSelfOrDescendant = function(node) {
+ return !!node && (node === this || this.isDescendant(node));
};
/**
* @param {!Node=} stayWithin
* @return {?Node}
*/
-Node.prototype.traverseNextNode = function(stayWithin)
-{
- if (this.shadowRoot)
- return this.shadowRoot;
+Node.prototype.traverseNextNode = function(stayWithin) {
+ if (this.shadowRoot)
+ return this.shadowRoot;
- var distributedNodes = this.getDistributedNodes ? this.getDistributedNodes() : [];
+ var distributedNodes = this.getDistributedNodes ? this.getDistributedNodes() : [];
- if (distributedNodes.length)
- return distributedNodes[0];
+ if (distributedNodes.length)
+ return distributedNodes[0];
- if (this.firstChild)
- return this.firstChild;
-
- var node = this;
- while (node) {
- if (stayWithin && node === stayWithin)
- return null;
+ if (this.firstChild)
+ return this.firstChild;
- var sibling = nextSibling(node);
- if (sibling)
- return sibling;
+ var node = this;
+ while (node) {
+ if (stayWithin && node === stayWithin)
+ return null;
- node = insertionPoint(node) || node.parentNodeOrShadowHost();
- }
+ var sibling = nextSibling(node);
+ if (sibling)
+ return sibling;
- /**
- * @param {!Node} node
- * @return {?Node}
- */
- function nextSibling(node)
- {
- var parent = insertionPoint(node);
- if (!parent)
- return node.nextSibling;
- var distributedNodes = parent.getDistributedNodes ? parent.getDistributedNodes() : [];
-
- var position = Array.prototype.indexOf.call(distributedNodes, node);
- if (position + 1 < distributedNodes.length)
- return distributedNodes[position + 1];
- return null;
- }
+ node = insertionPoint(node) || node.parentNodeOrShadowHost();
+ }
- /**
- * @param {!Node} node
- * @return {?Node}
- */
- function insertionPoint(node)
- {
- var insertionPoints = node.getDestinationInsertionPoints ? node.getDestinationInsertionPoints() : [];
- return insertionPoints.length > 0 ? insertionPoints[insertionPoints.length - 1] : null;
- }
+ /**
+ * @param {!Node} node
+ * @return {?Node}
+ */
+ function nextSibling(node) {
+ var parent = insertionPoint(node);
+ if (!parent)
+ return node.nextSibling;
+ var distributedNodes = parent.getDistributedNodes ? parent.getDistributedNodes() : [];
+ var position = Array.prototype.indexOf.call(distributedNodes, node);
+ if (position + 1 < distributedNodes.length)
+ return distributedNodes[position + 1];
return null;
+ }
+
+ /**
+ * @param {!Node} node
+ * @return {?Node}
+ */
+ function insertionPoint(node) {
+ var insertionPoints = node.getDestinationInsertionPoints ? node.getDestinationInsertionPoints() : [];
+ return insertionPoints.length > 0 ? insertionPoints[insertionPoints.length - 1] : null;
+ }
+
+ return null;
};
/**
* @param {!Node=} stayWithin
* @return {?Node}
*/
-Node.prototype.traversePreviousNode = function(stayWithin)
-{
- if (stayWithin && this === stayWithin)
- return null;
- var node = this.previousSibling;
- while (node && node.lastChild)
- node = node.lastChild;
- if (node)
- return node;
- return this.parentNodeOrShadowHost();
+Node.prototype.traversePreviousNode = function(stayWithin) {
+ if (stayWithin && this === stayWithin)
+ return null;
+ var node = this.previousSibling;
+ while (node && node.lastChild)
+ node = node.lastChild;
+ if (node)
+ return node;
+ return this.parentNodeOrShadowHost();
};
/**
@@ -760,29 +719,27 @@ Node.prototype.traversePreviousNode = function(stayWithin)
* @param {string=} placeholder
* @return {boolean} true if was truncated
*/
-Node.prototype.setTextContentTruncatedIfNeeded = function(text, placeholder)
-{
- // Huge texts in the UI reduce rendering performance drastically.
- // Moreover, Blink/WebKit uses <unsigned short> internally for storing text content
- // length, so texts longer than 65535 are inherently displayed incorrectly.
- const maxTextContentLength = 10000;
+Node.prototype.setTextContentTruncatedIfNeeded = function(text, placeholder) {
+ // Huge texts in the UI reduce rendering performance drastically.
+ // Moreover, Blink/WebKit uses <unsigned short> internally for storing text content
+ // length, so texts longer than 65535 are inherently displayed incorrectly.
+ const maxTextContentLength = 10000;
- if (typeof text === "string" && text.length > maxTextContentLength) {
- this.textContent = typeof placeholder === "string" ? placeholder : text.trimMiddle(maxTextContentLength);
- return true;
- }
+ if (typeof text === 'string' && text.length > maxTextContentLength) {
+ this.textContent = typeof placeholder === 'string' ? placeholder : text.trimMiddle(maxTextContentLength);
+ return true;
+ }
- this.textContent = text;
- return false;
+ this.textContent = text;
+ return false;
};
/**
* @return {?Node}
*/
-Event.prototype.deepElementFromPoint = function()
-{
- var root = this.target && this.target.getComponentRoot();
- return root ? root.deepElementFromPoint(this.pageX, this.pageY) : null;
+Event.prototype.deepElementFromPoint = function() {
+ var root = this.target && this.target.getComponentRoot();
+ return root ? root.deepElementFromPoint(this.pageX, this.pageY) : null;
};
/**
@@ -790,12 +747,11 @@ Event.prototype.deepElementFromPoint = function()
* @param {number} y
* @return {?Node}
*/
-Document.prototype.deepElementFromPoint = function(x, y)
-{
- var node = this.elementFromPoint(x, y);
- while (node && node.shadowRoot)
- node = node.shadowRoot.elementFromPoint(x, y);
- return node;
+Document.prototype.deepElementFromPoint = function(x, y) {
+ var node = this.elementFromPoint(x, y);
+ while (node && node.shadowRoot)
+ node = node.shadowRoot.elementFromPoint(x, y);
+ return node;
};
DocumentFragment.prototype.deepElementFromPoint = Document.prototype.deepElementFromPoint;
@@ -803,12 +759,11 @@ DocumentFragment.prototype.deepElementFromPoint = Document.prototype.deepElement
/**
* @return {?Element}
*/
-Document.prototype.deepActiveElement = function()
-{
- var activeElement = this.activeElement;
- while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
- activeElement = activeElement.shadowRoot.activeElement;
- return activeElement;
+Document.prototype.deepActiveElement = function() {
+ var activeElement = this.activeElement;
+ while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
+ activeElement = activeElement.shadowRoot.activeElement;
+ return activeElement;
};
DocumentFragment.prototype.deepActiveElement = Document.prototype.deepActiveElement;
@@ -816,59 +771,53 @@ DocumentFragment.prototype.deepActiveElement = Document.prototype.deepActiveElem
/**
* @return {boolean}
*/
-Element.prototype.hasFocus = function()
-{
- var root = this.getComponentRoot();
- return !!root && this.isSelfOrAncestor(root.activeElement);
+Element.prototype.hasFocus = function() {
+ var root = this.getComponentRoot();
+ return !!root && this.isSelfOrAncestor(root.activeElement);
};
/**
* @return {?Document|?DocumentFragment}
*/
-Node.prototype.getComponentRoot = function()
-{
- var node = this;
- while (node && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE && node.nodeType !== Node.DOCUMENT_NODE)
- node = node.parentNode;
- return /** @type {?Document|?DocumentFragment} */ (node);
+Node.prototype.getComponentRoot = function() {
+ var node = this;
+ while (node && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE && node.nodeType !== Node.DOCUMENT_NODE)
+ node = node.parentNode;
+ return /** @type {?Document|?DocumentFragment} */ (node);
};
/**
* @param {!Event} event
* @return {boolean}
*/
-function isEnterKey(event)
-{
- // Check if in IME.
- return event.keyCode !== 229 && event.key === "Enter";
+function isEnterKey(event) {
+ // Check if in IME.
+ return event.keyCode !== 229 && event.key === 'Enter';
}
/**
* @param {!Event} event
* @return {boolean}
*/
-function isEscKey(event)
-{
- return event.keyCode === 27;
+function isEscKey(event) {
+ return event.keyCode === 27;
}
/**
* @param {function()} callback
* @suppressGlobalPropertiesCheck
*/
-function runOnWindowLoad(callback)
-{
- /**
- * @suppressGlobalPropertiesCheck
- */
- function windowLoaded()
- {
- window.removeEventListener("DOMContentLoaded", windowLoaded, false);
- callback();
- }
-
- if (document.readyState === "complete" || document.readyState === "interactive")
- callback();
- else
- window.addEventListener("DOMContentLoaded", windowLoaded, false);
+function runOnWindowLoad(callback) {
+ /**
+ * @suppressGlobalPropertiesCheck
+ */
+ function windowLoaded() {
+ window.removeEventListener('DOMContentLoaded', windowLoaded, false);
+ callback();
+ }
+
+ if (document.readyState === 'complete' || document.readyState === 'interactive')
+ callback();
+ else
+ window.addEventListener('DOMContentLoaded', windowLoaded, false);
}

Powered by Google App Engine
This is Rietveld 408576698