From 8d217e0cbc2ffb0b35fdc8cc78918bff4e30ae55 Mon Sep 17 00:00:00 2001 From: "vsevik@chromium.org" Date: Thu, 19 Jan 2012 13:56:09 +0000 Subject: [PATCH] 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): (): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105409 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/ChangeLog | 32 ++++++++++++++++++++++ Source/WebCore/inspector/front-end/Drawer.js | 3 +- Source/WebCore/inspector/front-end/HelpScreen.js | 2 +- .../inspector/front-end/MetricsSidebarPane.js | 2 +- Source/WebCore/inspector/front-end/Popover.js | 2 +- Source/WebCore/inspector/front-end/ScriptsPanel.js | 2 +- .../inspector/front-end/StylesSidebarPane.js | 2 +- Source/WebCore/inspector/front-end/TextPrompt.js | 5 ++-- Source/WebCore/inspector/front-end/TextViewer.js | 4 +-- Source/WebCore/inspector/front-end/UIUtils.js | 9 ++++-- Source/WebCore/inspector/front-end/utilities.js | 12 +++++++- 11 files changed, 60 insertions(+), 15 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 4765dc7..d75a65e 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,35 @@ +2012-01-19 Vsevolod Vlasov + + 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 DynamicNodeList: Simplify internal Caches object. diff --git a/Source/WebCore/inspector/front-end/Drawer.js b/Source/WebCore/inspector/front-end/Drawer.js index e022242..9bf372a 100644 --- a/Source/WebCore/inspector/front-end/Drawer.js +++ b/Source/WebCore/inspector/front-end/Drawer.js @@ -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"); diff --git a/Source/WebCore/inspector/front-end/HelpScreen.js b/Source/WebCore/inspector/front-end/HelpScreen.js index c3493c8..6b60da9 100644 --- a/Source/WebCore/inspector/front-end/HelpScreen.js +++ b/Source/WebCore/inspector/front-end/HelpScreen.js @@ -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); } } diff --git a/Source/WebCore/inspector/front-end/MetricsSidebarPane.js b/Source/WebCore/inspector/front-end/MetricsSidebarPane.js index 952a968..6467004 100644 --- a/Source/WebCore/inspector/front-end/MetricsSidebarPane.js +++ b/Source/WebCore/inspector/front-end/MetricsSidebarPane.js @@ -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; diff --git a/Source/WebCore/inspector/front-end/Popover.js b/Source/WebCore/inspector/front-end/Popover.js index 4bfd6a3..fbb54f9 100644 --- a/Source/WebCore/inspector/front-end/Popover.js +++ b/Source/WebCore/inspector/front-end/Popover.js @@ -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. diff --git a/Source/WebCore/inspector/front-end/ScriptsPanel.js b/Source/WebCore/inspector/front-end/ScriptsPanel.js index 3dc10c8..b1805f8 100644 --- a/Source/WebCore/inspector/front-end/ScriptsPanel.js +++ b/Source/WebCore/inspector/front-end/ScriptsPanel.js @@ -465,7 +465,7 @@ WebInspector.ScriptsPanel.prototype = { showUISourceCode: function(uiSourceCode) { - this._showSourceLine(uiSourceCode, null); + this._showSourceLine(uiSourceCode); }, /** diff --git a/Source/WebCore/inspector/front-end/StylesSidebarPane.js b/Source/WebCore/inspector/front-end/StylesSidebarPane.js index b4d0708..f21fcfa 100644 --- a/Source/WebCore/inspector/front-end/StylesSidebarPane.js +++ b/Source/WebCore/inspector/front-end/StylesSidebarPane.js @@ -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); diff --git a/Source/WebCore/inspector/front-end/TextPrompt.js b/Source/WebCore/inspector/front-end/TextPrompt.js index d755b28..89c0b03 100644 --- a/Source/WebCore/inspector/front-end/TextPrompt.js +++ b/Source/WebCore/inspector/front-end/TextPrompt.js @@ -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) diff --git a/Source/WebCore/inspector/front-end/TextViewer.js b/Source/WebCore/inspector/front-end/TextViewer.js index eb44a5e..054415d 100644 --- a/Source/WebCore/inspector/front-end/TextViewer.js +++ b/Source/WebCore/inspector/front-end/TextViewer.js @@ -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; diff --git a/Source/WebCore/inspector/front-end/UIUtils.js b/Source/WebCore/inspector/front-end/UIUtils.js index 897892b..31ac004 100644 --- a/Source/WebCore/inspector/front-end/UIUtils.js +++ b/Source/WebCore/inspector/front-end/UIUtils.js @@ -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) { diff --git a/Source/WebCore/inspector/front-end/utilities.js b/Source/WebCore/inspector/front-end/utilities.js index 61bc924..36eb2b7 100644 --- a/Source/WebCore/inspector/front-end/utilities.js +++ b/Source/WebCore/inspector/front-end/utilities.js @@ -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; -- 2.7.4