зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1014332 share button CUI widget, r=jaws
This commit is contained in:
Родитель
fe4fdca242
Коммит
eb7bee7d96
|
@ -119,7 +119,7 @@
|
|||
#endif
|
||||
<command id="History:UndoCloseTab" oncommand="undoCloseTab();"/>
|
||||
<command id="History:UndoCloseWindow" oncommand="undoCloseWindow();"/>
|
||||
<command id="Social:SharePage" oncommand="SocialShare.sharePage();" disabled="true"/>
|
||||
<command id="Social:SharePage" oncommand="SocialShare.sharePage();"/>
|
||||
<command id="Social:ToggleSidebar" oncommand="SocialSidebar.toggleSidebar();" hidden="true"/>
|
||||
<command id="Social:ToggleNotifications" oncommand="Social.toggleNotifications();" hidden="true"/>
|
||||
<command id="Social:Addons" oncommand="BrowserOpenAddonsMgr('addons://list/service');"/>
|
||||
|
@ -134,6 +134,7 @@
|
|||
</commandset>
|
||||
|
||||
<broadcasterset id="mainBroadcasterSet">
|
||||
<broadcaster id="Social:PageShareOrMark" disabled="true"/>
|
||||
<broadcaster id="viewBookmarksSidebar" autoCheck="false" label="&bookmarksButton.label;"
|
||||
type="checkbox" group="sidebar" sidebarurl="chrome://browser/content/bookmarks/bookmarksPanel.xul"
|
||||
oncommand="toggleSidebar('viewBookmarksSidebar');"/>
|
||||
|
|
|
@ -74,7 +74,7 @@ SocialUI = {
|
|||
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
||||
|
||||
gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
|
||||
PanelUI.panel.addEventListener("popupshown", SocialUI.updatePanelState, true);
|
||||
CustomizableUI.addListener(this);
|
||||
|
||||
// menupopups that list social providers. we only populate them when shown,
|
||||
// and if it has not been done already.
|
||||
|
@ -107,8 +107,8 @@ SocialUI = {
|
|||
Services.obs.removeObserver(this, "social:provider-disabled");
|
||||
|
||||
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
||||
CustomizableUI.removeListener(this);
|
||||
|
||||
PanelUI.panel.removeEventListener("popupshown", SocialUI.updatePanelState, true);
|
||||
document.getElementById("viewSidebarMenu").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
||||
document.getElementById("social-statusarea-popup").removeEventListener("popupshowing", SocialSidebar.populateSidebarMenu, true);
|
||||
|
||||
|
@ -172,7 +172,6 @@ SocialUI = {
|
|||
SocialShare.populateProviderMenu();
|
||||
SocialStatus.populateToolbarPalette();
|
||||
SocialMarks.populateToolbarPalette();
|
||||
SocialShare.update();
|
||||
},
|
||||
|
||||
// This handles "ActivateSocialFeature" events fired against content documents
|
||||
|
@ -230,6 +229,18 @@ SocialUI = {
|
|||
if (provider.sidebarURL) {
|
||||
SocialSidebar.show(provider.origin);
|
||||
}
|
||||
if (provider.shareURL) {
|
||||
// Ensure that the share button is somewhere usable.
|
||||
// SocialShare.shareButton may return null if it is in the menu-panel
|
||||
// and has never been visible, so we check the widget directly. If
|
||||
// there is no area for the widget we move it into the toolbar.
|
||||
let widget = CustomizableUI.getWidget("social-share-button");
|
||||
if (!widget.areaType) {
|
||||
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
|
||||
// ensure correct state
|
||||
SocialUI.onCustomizeEnd(window);
|
||||
}
|
||||
}
|
||||
if (provider.postActivationURL) {
|
||||
openUILinkIn(provider.postActivationURL, "tab");
|
||||
}
|
||||
|
@ -284,21 +295,49 @@ SocialUI = {
|
|||
return Social.providers.length > 0;
|
||||
},
|
||||
|
||||
updatePanelState :function(event) {
|
||||
// we only want to update when the panel is initially opened, not during
|
||||
// multiview changes
|
||||
if (event.target != PanelUI.panel)
|
||||
canShareOrMarkPage: function(aURI) {
|
||||
// Bug 898706 we do not enable social in private sessions since frameworker
|
||||
// would be shared between private and non-private windows
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
||||
return false;
|
||||
|
||||
return (aURI && (aURI.schemeIs('http') || aURI.schemeIs('https')));
|
||||
},
|
||||
|
||||
onCustomizeEnd: function(aWindow) {
|
||||
if (aWindow != window)
|
||||
return;
|
||||
SocialUI.updateState();
|
||||
// customization mode gets buttons out of sync with command updating, fix
|
||||
// the disabled state
|
||||
let canShare = this.canShareOrMarkPage(gBrowser.currentURI);
|
||||
let shareButton = SocialShare.shareButton;
|
||||
if (shareButton) {
|
||||
if (canShare) {
|
||||
shareButton.removeAttribute("disabled")
|
||||
} else {
|
||||
shareButton.setAttribute("disabled", "true")
|
||||
}
|
||||
}
|
||||
// update the disabled state of the button based on the command
|
||||
for (let node of SocialMarks.nodes) {
|
||||
if (canShare) {
|
||||
node.removeAttribute("disabled")
|
||||
} else {
|
||||
node.setAttribute("disabled", "true")
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// called on tab/urlbar/location changes and after customization. Update
|
||||
// anything that is tab specific.
|
||||
updateState: function() {
|
||||
if (location == "about:customizing")
|
||||
return;
|
||||
goSetCommandEnabled("Social:PageShareOrMark", this.canShareOrMarkPage(gBrowser.currentURI));
|
||||
if (!SocialUI.enabled)
|
||||
return;
|
||||
// larger update that may change button icons
|
||||
SocialMarks.update();
|
||||
SocialShare.update();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -495,6 +534,13 @@ SocialShare = {
|
|||
return provider;
|
||||
},
|
||||
|
||||
createTooltip: function(event) {
|
||||
let tt = event.target;
|
||||
let provider = Social._getProviderFromOrigin(tt.triggerNode.getAttribute("origin"));
|
||||
tt.firstChild.setAttribute("value", provider.name);
|
||||
tt.lastChild.setAttribute("value", provider.origin);
|
||||
},
|
||||
|
||||
populateProviderMenu: function() {
|
||||
if (!this.iframe)
|
||||
return;
|
||||
|
@ -513,7 +559,7 @@ SocialShare = {
|
|||
button.setAttribute("type", "radio");
|
||||
button.setAttribute("group", "share-providers");
|
||||
button.setAttribute("image", provider.iconURL);
|
||||
button.setAttribute("tooltiptext", provider.name);
|
||||
button.setAttribute("tooltip", "share-button-tooltip");
|
||||
button.setAttribute("origin", provider.origin);
|
||||
button.setAttribute("oncommand", "SocialShare.sharePage(this.getAttribute('origin'));");
|
||||
if (provider == selectedProvider) {
|
||||
|
@ -539,42 +585,6 @@ SocialShare = {
|
|||
return widget.forWindow(window).node;
|
||||
},
|
||||
|
||||
canSharePage: function(aURI) {
|
||||
// we do not enable sharing from private sessions
|
||||
if (PrivateBrowsingUtils.isWindowPrivate(window))
|
||||
return false;
|
||||
|
||||
if (!aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https')))
|
||||
return false;
|
||||
return true;
|
||||
},
|
||||
|
||||
update: function() {
|
||||
let widget = CustomizableUI.getWidget("social-share-button");
|
||||
if (!widget)
|
||||
return;
|
||||
let shareButton = widget.forWindow(window).node;
|
||||
// hidden state is based on available share providers and location of
|
||||
// button. It's always visible and disabled in the customization palette.
|
||||
shareButton.hidden = !SocialUI.enabled || (widget.areaType &&
|
||||
[p for (p of Social.providers) if (p.shareURL)].length == 0);
|
||||
let disabled = !widget.areaType || shareButton.hidden || !this.canSharePage(gBrowser.currentURI);
|
||||
|
||||
// 1. update the relevent command's disabled state so the keyboard
|
||||
// shortcut only works when available.
|
||||
// 2. If the button has been relocated to a place that is not visible by
|
||||
// default (e.g. menu panel) then the disabled attribute will not update
|
||||
// correctly based on the command, so we update the attribute directly as.
|
||||
let cmd = document.getElementById("Social:SharePage");
|
||||
if (disabled) {
|
||||
cmd.setAttribute("disabled", "true");
|
||||
shareButton.setAttribute("disabled", "true");
|
||||
} else {
|
||||
cmd.removeAttribute("disabled");
|
||||
shareButton.removeAttribute("disabled");
|
||||
}
|
||||
},
|
||||
|
||||
_onclick: function() {
|
||||
Services.telemetry.getHistogramById("SOCIAL_PANEL_CLICKS").add(0);
|
||||
},
|
||||
|
@ -631,7 +641,7 @@ SocialShare = {
|
|||
let pageData = graphData ? graphData : this.currentShare;
|
||||
let sharedURI = pageData ? Services.io.newURI(pageData.url, null, null) :
|
||||
gBrowser.currentURI;
|
||||
if (!this.canSharePage(sharedURI))
|
||||
if (!SocialUI.canShareOrMarkPage(sharedURI))
|
||||
return;
|
||||
|
||||
// the point of this action type is that we can use existing share
|
||||
|
@ -1334,20 +1344,27 @@ SocialStatus = {
|
|||
* Handles updates to toolbox and signals all buttons to update when necessary.
|
||||
*/
|
||||
SocialMarks = {
|
||||
update: function() {
|
||||
// querySelectorAll does not work on the menu panel the panel, so we have to
|
||||
// do this the hard way.
|
||||
let providers = SocialMarks.getProviders();
|
||||
get nodes() {
|
||||
let providers = [p for (p of Social.providers) if (p.markURL)];
|
||||
for (let p of providers) {
|
||||
let widgetId = SocialMarks._toolbarHelper.idFromOrigin(p.origin);
|
||||
let widget = CustomizableUI.getWidget(widgetId);
|
||||
if (!widget)
|
||||
continue;
|
||||
let node = widget.forWindow(window).node;
|
||||
if (node)
|
||||
yield node;
|
||||
}
|
||||
},
|
||||
update: function() {
|
||||
// querySelectorAll does not work on the menu panel, so we have to do this
|
||||
// the hard way.
|
||||
for (let node of this.nodes) {
|
||||
// xbl binding is not complete on startup when buttons are not in toolbar,
|
||||
// verify update is available
|
||||
if (node && node.update)
|
||||
if (node.update) {
|
||||
node.update();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -3774,7 +3774,7 @@ var XULBrowserWindow = {
|
|||
URLBarSetURI(aLocationURI);
|
||||
|
||||
BookmarkingUI.onLocationChange();
|
||||
SocialUI.updateState();
|
||||
SocialUI.updateState(location);
|
||||
}
|
||||
|
||||
// Utility functions for disabling find
|
||||
|
|
|
@ -500,6 +500,11 @@
|
|||
#endif
|
||||
</tooltip>
|
||||
|
||||
<tooltip id="share-button-tooltip" onpopupshowing="SocialShare.createTooltip(event);">
|
||||
<label class="tooltip-label"/>
|
||||
<label class="tooltip-label"/>
|
||||
</tooltip>
|
||||
|
||||
#include popup-notifications.inc
|
||||
|
||||
#include ../../components/customizableui/content/panelUI.inc.xul
|
||||
|
@ -673,7 +678,7 @@
|
|||
aria-label="&navbarCmd.label;"
|
||||
fullscreentoolbar="true" mode="icons" customizable="true"
|
||||
iconsize="small"
|
||||
defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,loop-call-button,social-share-button,social-toolbar-item"
|
||||
defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,loop-call-button"
|
||||
customizationtarget="nav-bar-customization-target"
|
||||
overflowable="true"
|
||||
overflowbutton="nav-bar-overflow-button"
|
||||
|
@ -920,15 +925,6 @@
|
|||
onclick="BrowserGoHome(event);"
|
||||
cui-areatype="toolbar"
|
||||
aboutHomeOverrideTooltip="&abouthome.pageTitle;"/>
|
||||
|
||||
<toolbarbutton id="social-share-button"
|
||||
class="toolbarbutton-1 chromeclass-toolbar-additional"
|
||||
label="&sharePageCmd.label;"
|
||||
tooltiptext="&sharePageCmd.label;"
|
||||
cui-areatype="toolbar"
|
||||
removable="true"
|
||||
hidden="true"
|
||||
command="Social:SharePage"/>
|
||||
</hbox>
|
||||
|
||||
<toolbarbutton id="nav-bar-overflow-button"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
<binding id="toolbarbutton-marks" display="xul:button"
|
||||
extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
|
||||
<content disabled="true">
|
||||
<content>
|
||||
<xul:panel anonid="panel" hidden="true" type="arrow" class="social-panel"/>
|
||||
<xul:image class="toolbarbutton-icon" xbl:inherits="validate,src=image,label"/>
|
||||
<xul:label class="toolbarbutton-text" crop="right" flex="1"
|
||||
|
@ -113,16 +113,11 @@
|
|||
if (this._frame.docShell)
|
||||
this._frame.docShell.createAboutBlankContentViewer(null);
|
||||
|
||||
// do we have a savable page loaded?
|
||||
let aURI = gBrowser.currentURI;
|
||||
let disabled = !aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https'));
|
||||
// when overflowed in toolbar, we must have the attribute set
|
||||
if (disabled) {
|
||||
this.setAttribute("disabled", "true");
|
||||
// disabled attr is set by Social:PageShareOrMark command
|
||||
if (this.hasAttribute("disabled")) {
|
||||
this.isMarked = false;
|
||||
} else {
|
||||
this.removeAttribute("disabled");
|
||||
Social.isURIMarked(provider.origin, aURI, (isMarked) => {
|
||||
Social.isURIMarked(provider.origin, gBrowser.currentURI, (isMarked) => {
|
||||
this.isMarked = isMarked;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -207,7 +207,6 @@ let CustomizableUIInternal = {
|
|||
"downloads-button",
|
||||
"home-button",
|
||||
"loop-call-button",
|
||||
"social-share-button",
|
||||
],
|
||||
defaultCollapsed: false,
|
||||
}, true);
|
||||
|
|
|
@ -393,6 +393,24 @@ const CustomizableWidgets = [
|
|||
let doc = aEvent.target.ownerDocument;
|
||||
clearSubview(doc.getElementById("PanelUI-sidebarItems"));
|
||||
}
|
||||
}, {
|
||||
id: "social-share-button",
|
||||
tooltiptext: "social-share-button.label",
|
||||
label: "social-share-button.tooltiptext",
|
||||
// custom build our button so we can attach to the share command
|
||||
type: "custom",
|
||||
onBuild: function(aDocument) {
|
||||
let node = aDocument.createElementNS(kNSXUL, "toolbarbutton");
|
||||
node.setAttribute("id", this.id);
|
||||
node.classList.add("toolbarbutton-1");
|
||||
node.classList.add("chromeclass-toolbar-additional");
|
||||
node.setAttribute("label", CustomizableUI.getLocalizedProperty(this, "label"));
|
||||
node.setAttribute("tooltiptext", CustomizableUI.getLocalizedProperty(this, "tooltiptext"));
|
||||
node.setAttribute("removable", "true");
|
||||
node.setAttribute("observes", "Social:PageShareOrMark");
|
||||
node.setAttribute("command", "Social:SharePage");
|
||||
return node;
|
||||
}
|
||||
}, {
|
||||
id: "add-ons-button",
|
||||
shortcutId: "key_openAddons",
|
||||
|
|
|
@ -100,6 +100,9 @@ quit-button.tooltiptext.mac = Quit %1$S (%2$S)
|
|||
loop-call-button2.label = Start a conversation
|
||||
loop-call-button2.tooltiptext = Start a conversation
|
||||
|
||||
social-share-button.label = Share This Page
|
||||
social-share-button.tooltiptext = Share This Page
|
||||
|
||||
panic-button.label = Forget
|
||||
panic-button.tooltiptext = Forget about some browsing history
|
||||
|
||||
|
|
|
@ -314,6 +314,7 @@ function CreateSocialMarkWidget(aId, aProvider) {
|
|||
let menuLabel = window.gNavigatorBundle.getFormattedString("social.markpageMenu.label", [aProvider.name]);
|
||||
node.setAttribute("label", menuLabel);
|
||||
node.setAttribute("tooltiptext", menuLabel);
|
||||
node.setAttribute("observes", "Social:PageShareOrMark");
|
||||
|
||||
return node;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче