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
+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.
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");
_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);
}
}
return;
var selectionRange = selection.getRangeAt(0);
- if (selectionRange.commonAncestorContainer !== element && !selectionRange.commonAncestorContainer.isDescendant(element))
+ if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
return;
var originalValue = element.textContent;
_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.
showUISourceCode: function(uiSourceCode)
{
- this._showSourceLine(uiSourceCode, null);
+ this._showSourceLine(uiSourceCode);
},
/**
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);
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()
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)
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;
}
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;
if (pasteCallback)
element.removeEventListener("paste", pasteEventListener, true);
- if (element === WebInspector.currentFocusElement() || element.isAncestor(WebInspector.currentFocusElement()))
- WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
+ WebInspector.restoreFocusFromElement(element);
}
/** @this {Element} */
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) {
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);
}
/**
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;