Bug 851596 - Move ContextMenuHandler element detection utils into Utils. r=fyan

This commit is contained in:
Jim Mathies 2013-03-17 09:55:37 -05:00
Родитель 07dfb30478
Коммит 90f007bf6a
2 изменённых файлов: 30 добавлений и 30 удалений

Просмотреть файл

@ -152,6 +152,29 @@ let Util = {
return null; return null;
}, },
isTextInput: function isTextInput(aElement) {
return ((aElement instanceof Ci.nsIDOMHTMLInputElement &&
aElement.mozIsTextField(false)) ||
aElement instanceof Ci.nsIDOMHTMLTextAreaElement);
},
isLink: function isLink(aElement) {
return ((aElement instanceof Ci.nsIDOMHTMLAnchorElement && aElement.href) ||
(aElement instanceof Ci.nsIDOMHTMLAreaElement && aElement.href) ||
aElement instanceof Ci.nsIDOMHTMLLinkElement ||
aElement.getAttributeNS(kXLinkNamespace, "type") == "simple");
},
isText: function isText(aElement) {
return (aElement instanceof Ci.nsIDOMHTMLParagraphElement ||
aElement instanceof Ci.nsIDOMHTMLDivElement ||
aElement instanceof Ci.nsIDOMHTMLLIElement ||
aElement instanceof Ci.nsIDOMHTMLPreElement ||
aElement instanceof Ci.nsIDOMHTMLHeadingElement ||
aElement instanceof Ci.nsIDOMHTMLTableCellElement ||
aElement instanceof Ci.nsIDOMHTMLBodyElement);
},
/* /*
* Rect and nsIDOMRect utilities * Rect and nsIDOMRect utilities
*/ */

Просмотреть файл

@ -133,7 +133,7 @@ var ContextMenuHandler = {
*/ */
_onSelectAll: function _onSelectAll() { _onSelectAll: function _onSelectAll() {
if (this._isTextInput(this._target)) { if (Util.isTextInput(this._target)) {
// select all text in the input control // select all text in the input control
this._target.select(); this._target.select();
} else { } else {
@ -145,7 +145,7 @@ var ContextMenuHandler = {
_onPaste: function _onPaste() { _onPaste: function _onPaste() {
// paste text if this is an input control // paste text if this is an input control
if (this._isTextInput(this._target)) { if (Util.isTextInput(this._target)) {
let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement); let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement);
if (edit) { if (edit) {
edit.editor.paste(Ci.nsIClipboard.kGlobalClipboard); edit.editor.paste(Ci.nsIClipboard.kGlobalClipboard);
@ -161,7 +161,7 @@ var ContextMenuHandler = {
}, },
_onCut: function _onCut() { _onCut: function _onCut() {
if (this._isTextInput(this._target)) { if (Util.isTextInput(this._target)) {
let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement); let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement);
if (edit) { if (edit) {
edit.editor.cut(); edit.editor.cut();
@ -173,7 +173,7 @@ var ContextMenuHandler = {
}, },
_onCopy: function _onCopy() { _onCopy: function _onCopy() {
if (this._isTextInput(this._target)) { if (Util.isTextInput(this._target)) {
let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement); let edit = this._target.QueryInterface(Ci.nsIDOMNSEditableElement);
if (edit) { if (edit) {
edit.editor.copy(); edit.editor.copy();
@ -281,7 +281,7 @@ var ContextMenuHandler = {
while (elem) { while (elem) {
if (elem.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) { if (elem.nodeType == Ci.nsIDOMNode.ELEMENT_NODE) {
// is the target a link or a descendant of a link? // is the target a link or a descendant of a link?
if (this._isLink(elem)) { if (Util.isLink(elem)) {
// If this is an image that links to itself, don't include both link and // If this is an image that links to itself, don't include both link and
// image otpions. // image otpions.
if (imageUrl == this._getLinkURL(elem)) { if (imageUrl == this._getLinkURL(elem)) {
@ -297,7 +297,7 @@ var ContextMenuHandler = {
// mark as text so we can pickup on selection below // mark as text so we can pickup on selection below
isText = true; isText = true;
break; break;
} else if (this._isTextInput(elem)) { } else if (Util.isTextInput(elem)) {
let selectionStart = elem.selectionStart; let selectionStart = elem.selectionStart;
let selectionEnd = elem.selectionEnd; let selectionEnd = elem.selectionEnd;
@ -330,7 +330,7 @@ var ContextMenuHandler = {
state.types.push("paste"); state.types.push("paste");
} }
break; break;
} else if (this._isText(elem)) { } else if (Util.isText(elem)) {
isText = true; isText = true;
} else if (elem instanceof Ci.nsIDOMHTMLMediaElement || } else if (elem instanceof Ci.nsIDOMHTMLMediaElement ||
elem instanceof Ci.nsIDOMHTMLVideoElement) { elem instanceof Ci.nsIDOMHTMLVideoElement) {
@ -381,29 +381,6 @@ var ContextMenuHandler = {
sendAsyncMessage("Content:ContextMenu", state); sendAsyncMessage("Content:ContextMenu", state);
}, },
_isTextInput: function _isTextInput(element) {
return ((element instanceof Ci.nsIDOMHTMLInputElement &&
element.mozIsTextField(false)) ||
element instanceof Ci.nsIDOMHTMLTextAreaElement);
},
_isLink: function _isLink(element) {
return ((element instanceof Ci.nsIDOMHTMLAnchorElement && element.href) ||
(element instanceof Ci.nsIDOMHTMLAreaElement && element.href) ||
element instanceof Ci.nsIDOMHTMLLinkElement ||
element.getAttributeNS(kXLinkNamespace, "type") == "simple");
},
_isText: function _isText(element) {
return (element instanceof Ci.nsIDOMHTMLParagraphElement ||
element instanceof Ci.nsIDOMHTMLDivElement ||
element instanceof Ci.nsIDOMHTMLLIElement ||
element instanceof Ci.nsIDOMHTMLPreElement ||
element instanceof Ci.nsIDOMHTMLHeadingElement ||
element instanceof Ci.nsIDOMHTMLTableCellElement ||
element instanceof Ci.nsIDOMHTMLBodyElement);
},
_getLinkURL: function ch_getLinkURL(aLink) { _getLinkURL: function ch_getLinkURL(aLink) {
let href = aLink.href; let href = aLink.href;
if (href) if (href)