Web Inspector: Add isSelfOrAnsector and isSelfOrDescendant methods to utilities.
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 13:56:09 +0000 (13:56 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Jan 2012 13:56:09 +0000 (13:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76618

Added isSelfOrAncestor, isSelfOrDescendant and WebInspector.restoreFocusFromElement methods.

Reviewed by Pavel Feldman.

* inspector/front-end/Drawer.js:
* inspector/front-end/HelpScreen.js:
(WebInspector.HelpScreen.prototype._onBlur):
* inspector/front-end/MetricsSidebarPane.js:
(WebInspector.MetricsSidebarPane.prototype._handleKeyDown):
* inspector/front-end/Popover.js:
* inspector/front-end/ScriptsPanel.js:
(WebInspector.ScriptsPanel.prototype.showUISourceCode):
* inspector/front-end/StylesSidebarPane.js:
():
* inspector/front-end/TextPrompt.js:
(WebInspector.TextPrompt.prototype.detach):
(WebInspector.TextPrompt.prototype.isCaretAtEndOfPrompt):
* inspector/front-end/TextViewer.js:
(WebInspector.TextEditorMainPanel.prototype._updateSelectionOnStartEditing):
(WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
* inspector/front-end/UIUtils.js:
(WebInspector.startEditing.cleanUpAfterEditing):
(WebInspector.restoreFocusFromElement):
* inspector/front-end/utilities.js:
(Element.prototype.isInsertionCaretInside):
():

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105409 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/Drawer.js
Source/WebCore/inspector/front-end/HelpScreen.js
Source/WebCore/inspector/front-end/MetricsSidebarPane.js
Source/WebCore/inspector/front-end/Popover.js
Source/WebCore/inspector/front-end/ScriptsPanel.js
Source/WebCore/inspector/front-end/StylesSidebarPane.js
Source/WebCore/inspector/front-end/TextPrompt.js
Source/WebCore/inspector/front-end/TextViewer.js
Source/WebCore/inspector/front-end/UIUtils.js
Source/WebCore/inspector/front-end/utilities.js

index 4765dc7..d75a65e 100644 (file)
@@ -1,3 +1,35 @@
+2012-01-19  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: Add isSelfOrAnsector and isSelfOrDescendant methods to utilities.
+        https://bugs.webkit.org/show_bug.cgi?id=76618
+
+        Added isSelfOrAncestor, isSelfOrDescendant and WebInspector.restoreFocusFromElement methods.
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/front-end/Drawer.js:
+        * inspector/front-end/HelpScreen.js:
+        (WebInspector.HelpScreen.prototype._onBlur):
+        * inspector/front-end/MetricsSidebarPane.js:
+        (WebInspector.MetricsSidebarPane.prototype._handleKeyDown):
+        * inspector/front-end/Popover.js:
+        * inspector/front-end/ScriptsPanel.js:
+        (WebInspector.ScriptsPanel.prototype.showUISourceCode):
+        * inspector/front-end/StylesSidebarPane.js:
+        ():
+        * inspector/front-end/TextPrompt.js:
+        (WebInspector.TextPrompt.prototype.detach):
+        (WebInspector.TextPrompt.prototype.isCaretAtEndOfPrompt):
+        * inspector/front-end/TextViewer.js:
+        (WebInspector.TextEditorMainPanel.prototype._updateSelectionOnStartEditing):
+        (WebInspector.TextEditorMainPanel.prototype._handleDOMUpdates):
+        * inspector/front-end/UIUtils.js:
+        (WebInspector.startEditing.cleanUpAfterEditing):
+        (WebInspector.restoreFocusFromElement):
+        * inspector/front-end/utilities.js:
+        (Element.prototype.isInsertionCaretInside):
+        ():
+
 2012-01-19  Andreas Kling  <awesomekling@apple.com>
 
         DynamicNodeList: Simplify internal Caches object.
index e022242..9bf372a 100644 (file)
@@ -144,8 +144,7 @@ WebInspector.Drawer.prototype = {
 
         this._savedHeight = this.element.offsetHeight;
 
-        if (this.element === WebInspector.currentFocusElement() || this.element.isAncestor(WebInspector.currentFocusElement()))
-            WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
+        WebInspector.restoreFocusFromElement(this.element);
 
         var anchoredItems = document.getElementById("anchored-status-bar-items");
 
index c3493c8..6b60da9 100644 (file)
@@ -99,7 +99,7 @@ WebInspector.HelpScreen.prototype = {
     _onBlur: function(event)
     {
         // Pretend we're modal, grab focus back if we're still shown.
-        if (this._isShown && event.target !== this._element && !this._element.isAncestor(event.target))
+        if (this._isShown && !this._element.isSelfOrAncestor(event.target))
             WebInspector.setCurrentFocusElement(this._element);
     }
 }
index 952a968..6467004 100644 (file)
@@ -309,7 +309,7 @@ WebInspector.MetricsSidebarPane.prototype = {
             return;
 
         var selectionRange = selection.getRangeAt(0);
-        if (selectionRange.commonAncestorContainer !== element && !selectionRange.commonAncestorContainer.isDescendant(element))
+        if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
             return;
 
         var originalValue = element.textContent;
index 4bfd6a3..fbb54f9 100644 (file)
@@ -204,7 +204,7 @@ WebInspector.PopoverHelper.prototype = {
     _mouseMove: function(event)
     {
         // Pretend that nothing has happened.
-        if (this._hoverElement === event.target || (this._hoverElement && this._hoverElement.isAncestor(event.target)))
+        if (event.target.isSelfOrDescendant(this._hoverElement))
             return;
 
         // User has 500ms (this._timeout / 2) to reach the popup.
index 3dc10c8..b1805f8 100644 (file)
@@ -465,7 +465,7 @@ WebInspector.ScriptsPanel.prototype = {
 
     showUISourceCode: function(uiSourceCode)
     {
-        this._showSourceLine(uiSourceCode, null);
+        this._showSourceLine(uiSourceCode);
     },
 
     /**
index b4d0708..f21fcfa 100644 (file)
@@ -2292,7 +2292,7 @@ WebInspector.StylesSidebarPane.CSSPropertyPrompt.prototype = {
             return false;
 
         var selectionRange = selection.getRangeAt(0);
-        if (selectionRange.commonAncestorContainer !== this._sidebarPane.valueElement && !selectionRange.commonAncestorContainer.isDescendant(this._sidebarPane.valueElement))
+        if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(this._sidebarPane.valueElement))
             return false;
 
         var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, WebInspector.StylesSidebarPane.StyleValueDelimiters, this._sidebarPane.valueElement);
index d755b28..89c0b03 100644 (file)
@@ -126,8 +126,7 @@ WebInspector.TextPrompt.prototype = {
         this.proxyElement.parentElement.insertBefore(this._element, this.proxyElement);
         this.proxyElement.parentElement.removeChild(this.proxyElement);
         delete this._proxyElement;
-        if (this._element === WebInspector.currentFocusElement() || this._element.isAncestor(WebInspector.currentFocusElement()))
-            WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
+        WebInspector.restoreFocusFromElement(this._element);
     },
 
     get text()
@@ -585,7 +584,7 @@ WebInspector.TextPrompt.prototype = {
 
         var selectionRange = selection.getRangeAt(0);
         var node = selectionRange.startContainer;
-        if (node !== this._element && !node.isDescendant(this._element))
+        if (!node.isSelfOrDescendant(this._element))
             return false;
 
         if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < node.nodeValue.length)
index eb44a5e..054415d 100644 (file)
@@ -930,7 +930,7 @@ WebInspector.TextEditorMainPanel.prototype = {
         var selection = window.getSelection();
         if (selection.rangeCount) {
             var commonAncestorContainer = selection.getRangeAt(0).commonAncestorContainer;
-            if (this._container === commonAncestorContainer || this._container.isAncestor(commonAncestorContainer))
+            if (this._container.isSelfOrAncestor(commonAncestorContainer))
                 return;
         }
 
@@ -1652,7 +1652,7 @@ WebInspector.TextEditorMainPanel.prototype = {
         if (!lineRow)
             return;
 
-        if (lineRow.decorationsElement && (lineRow.decorationsElement === target || lineRow.decorationsElement.isAncestor(target))) {
+        if (lineRow.decorationsElement && lineRow.decorationsElement.isSelfOrAncestor(target)) {
             if (this._syncDecorationsForLineListener)
                 this._syncDecorationsForLineListener(lineRow.lineNumber);
             return;
index 897892b..31ac004 100644 (file)
@@ -304,8 +304,7 @@ WebInspector.startEditing = function(element, config)
         if (pasteCallback)
             element.removeEventListener("paste", pasteEventListener, true);
 
-        if (element === WebInspector.currentFocusElement() || element.isAncestor(WebInspector.currentFocusElement()))
-            WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
+        WebInspector.restoreFocusFromElement(element);
     }
 
     /** @this {Element} */
@@ -624,6 +623,12 @@ WebInspector.setCurrentFocusElement = function(x)
         WebInspector._previousFocusElement.blur();
 }
 
+WebInspector.restoreFocusFromElement = function(element)
+{
+    if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement()))
+        WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
+}
+
 WebInspector.setToolbarColors = function(backgroundColor, color)
 {
     if (!WebInspector._themeStyleElement) {
index 61bc924..36eb2b7 100644 (file)
@@ -234,7 +234,7 @@ Element.prototype.isInsertionCaretInside = function()
     if (!selection.rangeCount || !selection.isCollapsed)
         return false;
     var selectionRange = selection.getRangeAt(0);
-    return selectionRange.startContainer === this || selectionRange.startContainer.isDescendant(this);
+    return selectionRange.startContainer.isSelfOrDescendant(this);
 }
 
 /**
@@ -552,6 +552,16 @@ Node.prototype.isDescendant = function(descendant)
     return !!descendant && descendant.isAncestor(this);
 }
 
+Node.prototype.isSelfOrAncestor = function(node)
+{
+    return !!node && (node === this || this.isAncestor(node));
+}
+
+Node.prototype.isSelfOrDescendant = function(node)
+{
+    return !!node && (node === this || this.isDescendant(node));
+}
+
 Node.prototype.traverseNextNode = function(stayWithin)
 {
     var node = this.firstChild;