📄 nscontextmenu.js
字号:
// See if the user clicked on an image. if ( this.target.nodeType == Node.ELEMENT_NODE ) { if ( this.target instanceof Components.interfaces.nsIImageLoadingContent && this.target.currentURI ) { this.onImage = true; var request = this.target.getRequest( Components.interfaces.nsIImageLoadingContent.CURRENT_REQUEST ); if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE)) this.onLoadedImage = true; this.imageURL = this.target.currentURI.spec; if ( this.target.ownerDocument instanceof ImageDocument ) this.onStandaloneImage = true; } else if ( this.target instanceof HTMLInputElement) { type = this.target.getAttribute("type"); this.onTextInput = this.isTargetATextBox(this.target); } else if ( this.target instanceof HTMLTextAreaElement ) { this.onTextInput = true; } else if ( this.target instanceof HTMLHtmlElement ) { // pages with multiple <body>s are lame. we'll teach them a lesson. var bodyElt = this.target.ownerDocument.getElementsByTagName("body")[0]; if ( bodyElt ) { var computedURL = this.getComputedURL( bodyElt, "background-image" ); if ( computedURL ) { this.hasBGImage = true; this.bgImageURL = this.makeURLAbsolute( bodyElt.baseURI, computedURL ); } } } else if ( "HTTPIndex" in _content && _content.HTTPIndex instanceof Components.interfaces.nsIHTTPIndex ) { this.inDirList = true; // Bubble outward till we get to an element with URL attribute // (which should be the href). var root = this.target; while ( root && !this.link ) { if ( root.tagName == "tree" ) { // Hit root of tree; must have clicked in empty space; // thus, no link. break; } if ( root.getAttribute( "URL" ) ) { // Build pseudo link object so link-related functions work. this.onLink = true; this.link = { href : root.getAttribute("URL"), getAttribute: function (attr) { if (attr == "title") { return root.firstChild.firstChild.getAttribute("label"); } else { return ""; } } }; // If element is a directory, then you can't save it. if ( root.getAttribute( "container" ) == "true" ) { this.onSaveableLink = false; } else { this.onSaveableLink = true; } } else { root = root.parentNode; } } } } // We have meta data on images. this.onMetaDataItem = this.onImage; // See if the user clicked on MathML const NS_MathML = "http://www.w3.org/1998/Math/MathML"; if ((this.target.nodeType == Node.TEXT_NODE && this.target.parentNode.namespaceURI == NS_MathML) || (this.target.namespaceURI == NS_MathML)) this.onMathML = true; // See if the user clicked in a frame. if ( this.target.ownerDocument != window._content.document ) { this.inFrame = true; } // Bubble out, looking for items of interest var elem = this.target; while ( elem ) { if ( elem.nodeType == Node.ELEMENT_NODE ) { // Link? if ( !this.onLink && ( (elem instanceof HTMLAnchorElement && elem.href) || elem instanceof HTMLAreaElement || elem instanceof HTMLLinkElement || elem.getAttributeNS( "http://www.w3.org/1999/xlink", "type") == "simple" ) ) { // Clicked on a link. this.onLink = true; this.onMetaDataItem = true; // Remember corresponding element. this.link = elem; this.onMailtoLink = this.isLinkType( "mailto:", this.link ); // Remember if it is saveable. this.onSaveableLink = this.isLinkSaveable( this.link ); } // Text input? if ( !this.onTextInput ) { // Clicked on a link. this.onTextInput = this.isTargetATextBox(elem); } // Metadata item? if ( !this.onMetaDataItem ) { // We currently display metadata on anything which fits // the below test. if ( ( elem instanceof HTMLQuoteElement && elem.cite) || ( elem instanceof HTMLTableElement && elem.summary) || ( elem instanceof HTMLModElement && ( elem.cite || elem.dateTime ) ) || ( elem instanceof HTMLElement && ( elem.title || elem.lang ) ) ) { this.onMetaDataItem = true; } } // Background image? Don't bother if we've already found a // background image further down the hierarchy. Otherwise, // we look for the computed background-image style. if ( !this.hasBGImage ) { var bgImgUrl = this.getComputedURL( elem, "background-image" ); if ( bgImgUrl ) { this.hasBGImage = true; this.bgImageURL = this.makeURLAbsolute( elem.baseURI, bgImgUrl ); } } } elem = elem.parentNode; } }, initPopupURL: function() { // quick check: if no opener, it can't be a popup if (!window.content.opener) return; try { var show = false; // is it a popup window? const CI = Components.interfaces; var xulwin = window .QueryInterface(CI.nsIInterfaceRequestor) .getInterface(CI.nsIWebNavigation) .QueryInterface(CI.nsIDocShellTreeItem) .treeOwner .QueryInterface(CI.nsIInterfaceRequestor) .getInterface(CI.nsIXULWindow); if (xulwin.contextFlags & CI.nsIWindowCreator2.PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) { // do the pref settings allow site-by-site popup management? const PB = Components.classes["@mozilla.org/preferences-service;1"] .getService(CI.nsIPrefBranch); show = !PB.getBoolPref("dom.disable_open_during_load"); } if (show) { // initialize popupURL const IOS = Components.classes["@mozilla.org/network/io-service;1"] .getService(CI.nsIIOService); var spec = Components.lookupMethod(window.content.opener, "location") .call(); this.popupURL = IOS.newURI(spec, null, null); // but cancel if it's an unsuitable URL const PM = Components.classes["@mozilla.org/PopupWindowManager;1"] .getService(CI.nsIPopupWindowManager); } } catch(e) { } }, // Returns the computed style attribute for the given element. getComputedStyle: function( elem, prop ) { return elem.ownerDocument.defaultView.getComputedStyle( elem, '' ).getPropertyValue( prop ); }, // Returns a "url"-type computed style attribute value, with the url() stripped. getComputedURL: function( elem, prop ) { var url = elem.ownerDocument.defaultView.getComputedStyle( elem, '' ).getPropertyCSSValue( prop ); return ( url.primitiveType == CSSPrimitiveValue.CSS_URI ) ? url.getStringValue() : null; }, // Returns true iff clicked on link is saveable. isLinkSaveable : function ( link ) { // We don't do the Right Thing for news/snews yet, so turn them off // until we do. return !(this.isLinkType( "mailto:" , link ) || this.isLinkType( "javascript:" , link ) || this.isLinkType( "news:", link ) || this.isLinkType( "snews:", link ) ); }, // Returns true iff clicked on link is of type given. isLinkType : function ( linktype, link ) { try { // Test for missing protocol property. if ( !link.protocol ) { // We must resort to testing the URL string :-(. var protocol; if ( link.href ) { protocol = link.href.substr( 0, linktype.length ); } else { protocol = link.getAttributeNS("http://www.w3.org/1999/xlink","href"); if ( protocol ) { protocol = protocol.substr( 0, linktype.length ); } } return protocol.toLowerCase() === linktype; } else { // Presume all but javascript: urls are saveable. return link.protocol.toLowerCase() === linktype; } } catch (e) { // something was wrong with the link, // so we won't be able to save it anyway return false; } }, // Block popup windows rejectPopupWindows: function(andClose) { const PM = Components.classes["@mozilla.org/PopupWindowManager;1"] .getService(Components.interfaces.nsIPopupWindowManager); PM.add(this.popupURL, false); if (andClose) { const OS = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); OS.notifyObservers(window, "popup-perm-close", this.popupURL.spec); } }, // Unblock popup windows allowPopupWindows: function() { const PM = Components.classes["@mozilla.org/PopupWindowManager;1"] .getService(Components.interfaces.nsIPopupWindowManager); PM.add(this.popupURL, true); }, // Reload clicked-in frame. reloadFrame : function () { this.target.ownerDocument.location.reload(); }, // Open clicked-in frame in its own window. openFrame : function () { openNewWindowWith( this.target.ownerDocument.location.href ); }, // Open clicked-in frame in the same window showOnlyThisFrame : function () { window.loadURI(this.target.ownerDocument.location.href); }, // View Partial Source viewPartialSource : function ( context ) { var focusedWindow = document.commandDispatcher.focusedWindow; if (focusedWindow == window) focusedWindow = _content; var docCharset = null; if (focusedWindow) docCharset = "charset=" + focusedWindow.document.characterSet; // "View Selection Source" and others such as "View MathML Source" // are mutually exclusive, with the precedence given to the selection // when there is one var reference = null; if (context == "selection")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -