From 8e895a1b87652fc960410f34c7bb89fe7c854af4 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Thu, 25 Mar 2010 23:52:31 -0400 Subject: [PATCH] Bug 554951 - Context menu behavior and style fixes [r=vingtetun] --- mobile/chrome/content/browser-ui.js | 42 ++++++++++++++++++++++++++--- mobile/themes/hildon/browser.css | 7 ++++- mobile/themes/wince/browser.css | 5 ++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mobile/chrome/content/browser-ui.js b/mobile/chrome/content/browser-ui.js index 60ef1db14e1..f57efe9061c 100644 --- a/mobile/chrome/content/browser-ui.js +++ b/mobile/chrome/content/browser-ui.js @@ -1823,15 +1823,19 @@ const kXLinkNamespace = "http://www.w3.org/1999/xlink"; var ContextHelper = { popupNode: null, onLink: false, + onSaveableLink: false, onImage: false, linkURL: "", + linkProtocol: null, mediaURL: "", _clearState: function ch_clearState() { this.popupNode = null; this.onLink = false; + this.onSaveableLink = false; this.onImage = false; this.linkURL = ""; + this.linkProtocol = null; this.mediaURL = ""; }, @@ -1850,6 +1854,25 @@ var ContextHelper = { return Util.makeURLAbsolute(aLink.baseURI, href); }, + _getURI: function ch_getURI(aURL) { + try { + return makeURI(aURL); + } catch (ex) { } + + return null; + }, + + _getProtocol: function ch_getProtocol(aURI) { + if (aURI) + return aURI.scheme; + return null; + }, + + _isSaveable: function ch_isSaveable(aProtocol) { + // We don't do the Right Thing for news/snews yet, so turn them off until we do + return aProtocol && !(aProtocol == "mailto" || aProtocol == "javascript" || aProtocol == "news" || aProtocol == "snews"); + }, + handleEvent: function ch_handleEvent(aEvent) { this._clearState(); @@ -1876,8 +1899,10 @@ var ContextHelper = { elem.getAttributeNS(kXLinkNamespace, "type") == "simple")) { // Target is a link or a descendant of a link. - this.onLink = true; this.linkURL = this._getLinkURL(elem); + this.linkProtocol = this._getProtocol(this._getURI(this.linkURL)); + this.onLink = true; + this.onSaveableLink = this._isSaveable(this.linkProtocol); } } @@ -1895,7 +1920,12 @@ var ContextHelper = { last = command; command.hidden = false; continue; - } else if (type.indexOf("link") != -1 && this.onLink) { + } else if (type.indexOf("link") != -1 && this.onLink && this.onSaveableLink) { + first = (first ? first : command); + last = command; + command.hidden = false; + continue; + } else if (type.indexOf("mailto") != -1 && this.onLink && this.linkProtocol == "mailto") { first = (first ? first : command); last = command; command.hidden = false; @@ -1921,8 +1951,14 @@ var ContextHelper = { let container = document.getElementById("context-popup"); container.hidden = false; + // Make sure the container is at least sized to the content + let preferredHeight = 0; + for (let i=0; i richlistitem[selector="last-child"] { background: -moz-linear-gradient(top, rgb(245,245,245), rgb(215,215,215)); - -moz-border-radius: 0 0 8px 8px !important; + -moz-border-radius: 0 0 8px 8px; +} + +/* Force any command tap to highlight */ +#context-commands > richlistitem:hover:active { + background: #8db8d8; } .modal-block { diff --git a/mobile/themes/wince/browser.css b/mobile/themes/wince/browser.css index 10e708f256b..f45525fd80e 100644 --- a/mobile/themes/wince/browser.css +++ b/mobile/themes/wince/browser.css @@ -776,6 +776,11 @@ pageaction .pageaction-desc { -moz-border-radius: 0 0 8px 8px !important; } +/* Force any command tap to highlight */ +#context-commands > richlistitem:hover:active { + background: #8db8d8; +} + .modal-block { -moz-box-align: center; -moz-box-pack: center;