mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 940155 make marks button work in Australis menu panel, r=markh
This commit is contained in:
parent
47254b9a46
commit
8cbeba7cc6
@ -68,6 +68,7 @@ SocialUI = {
|
||||
Services.prefs.addObserver("social.toast-notifications.enabled", this, false);
|
||||
|
||||
gBrowser.addEventListener("ActivateSocialFeature", this._activationEventHandler.bind(this), true, true);
|
||||
document.getElementById("PanelUI-popup").addEventListener("popupshown", SocialMarks.updatePanelButtons, true);
|
||||
|
||||
if (!Social.initialized) {
|
||||
Social.init();
|
||||
@ -92,6 +93,8 @@ SocialUI = {
|
||||
|
||||
Services.prefs.removeObserver("social.sidebar.open", this);
|
||||
Services.prefs.removeObserver("social.toast-notifications.enabled", this);
|
||||
|
||||
document.getElementById("PanelUI-popup").removeEventListener("popupshown", SocialMarks.updatePanelButtons, true);
|
||||
},
|
||||
|
||||
_matchesCurrentProvider: function (origin) {
|
||||
@ -1641,6 +1644,22 @@ SocialMarks = {
|
||||
elt.update();
|
||||
},
|
||||
|
||||
updatePanelButtons: function() {
|
||||
// querySelectorAll does not work on the menu panel the panel, so we have to
|
||||
// do this the hard way.
|
||||
let providers = SocialMarks.getProviders();
|
||||
let panel = document.getElementById("PanelUI-popup");
|
||||
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)
|
||||
node.update();
|
||||
}
|
||||
},
|
||||
|
||||
getProviders: function() {
|
||||
// only rely on providers that the user has placed in the UI somewhere. This
|
||||
// also means that populateToolbarPalette must be called prior to using this
|
||||
|
@ -9,23 +9,52 @@
|
||||
<binding id="toolbarbutton-marks" display="xul:button"
|
||||
extends="chrome://global/content/bindings/toolbarbutton.xml#toolbarbutton">
|
||||
<content disabled="true">
|
||||
<xul:panel anonid="panel" hidden="true" type="arrow" class="social-panel">
|
||||
<xul:iframe type="content" flex="1" tooltip="aHTMLTooltip"
|
||||
class="social-panel-frame" context="contentAreaContextMenu"
|
||||
xbl:inherits="src,origin"/>
|
||||
</xul:panel>
|
||||
<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"
|
||||
xbl:inherits="value=label,accesskey,crop"/>
|
||||
</content>
|
||||
<implementation implements="nsIDOMEventListener, nsIObserver">
|
||||
<field name="panel" readonly="true">
|
||||
document.getAnonymousElementByAttribute(this, "anonid", "panel");
|
||||
</field>
|
||||
<field name="inMenuPanel">false</field>
|
||||
|
||||
<field name="content" readonly="true">
|
||||
this.panel.firstChild;
|
||||
</field>
|
||||
<property name="panel">
|
||||
<getter>
|
||||
let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id"));
|
||||
let widget = widgetGroup.forWindow(window);
|
||||
this.inMenuPanel = widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL;
|
||||
if (this.inMenuPanel) {
|
||||
widget.node.setAttribute("noautoclose", "true");
|
||||
return document.getElementById("PanelUI-socialapi");
|
||||
}
|
||||
return document.getAnonymousElementByAttribute(this, "anonid", "panel");
|
||||
</getter>
|
||||
</property>
|
||||
|
||||
<property name="content">
|
||||
<getter><![CDATA[
|
||||
if (this._frame)
|
||||
return this._frame;
|
||||
let notificationFrameId = "social-mark-frame-" + this.getAttribute("origin");
|
||||
this._frame = SharedFrame.createFrame(
|
||||
notificationFrameId, /* frame name */
|
||||
this.panel, /* parent */
|
||||
{
|
||||
"type": "content",
|
||||
"mozbrowser": "true",
|
||||
"class": "social-panel-frame",
|
||||
"id": notificationFrameId,
|
||||
"tooltip": "aHTMLTooltip",
|
||||
"flex": "1",
|
||||
"context": "contentAreaContextMenu",
|
||||
"origin": this.getAttribute("origin"),
|
||||
"src": "about:blank"
|
||||
}
|
||||
);
|
||||
this._frame.addEventListener("DOMLinkAdded", this);
|
||||
this.setAttribute("notificationFrameId", notificationFrameId);
|
||||
return this._frame;
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="contentWindow">
|
||||
<getter>
|
||||
@ -46,16 +75,17 @@
|
||||
</property>
|
||||
|
||||
<property name="isMarked">
|
||||
<setter>
|
||||
<setter><![CDATA[
|
||||
this._isMarked = val;
|
||||
let provider = this.provider;
|
||||
// we cannot size the image when we apply it via listStyleImage, so
|
||||
// use the toolbar image
|
||||
if (val)
|
||||
this.setAttribute("image", provider.unmarkedIcon || provider.iconURL);
|
||||
else
|
||||
this.setAttribute("image", provider.markedIcon || provider.iconURL);
|
||||
</setter>
|
||||
let place = CustomizableUI.getPlaceForItem(this);
|
||||
val = val && place != "palette";
|
||||
let icon = val ? provider.markedIcon : provider.unmarkedIcon;
|
||||
let iconURL = icon || provider.icon32URL || provider.iconURL;
|
||||
this.setAttribute("image", iconURL);
|
||||
]]></setter>
|
||||
<getter>
|
||||
return this._isMarked;
|
||||
</getter>
|
||||
@ -69,12 +99,11 @@
|
||||
this._dynamicResizer.stop();
|
||||
this._dynamicResizer = null;
|
||||
}
|
||||
this.setAttribute("src", "about:blank");
|
||||
this.content.setAttribute("src", "about:blank");
|
||||
|
||||
// do we have a savable page loaded?
|
||||
let aURI = gBrowser.currentURI;
|
||||
this.disabled = !aURI || !(aURI.schemeIs('http') || aURI.schemeIs('https'));
|
||||
|
||||
if (this.disabled) {
|
||||
this.isMarked = false;
|
||||
} else {
|
||||
@ -82,11 +111,17 @@
|
||||
this.isMarked = isMarked;
|
||||
});
|
||||
}
|
||||
this.setAttribute("label", provider.name);
|
||||
this.setAttribute("tooltiptext", provider.name);
|
||||
this.setAttribute("origin", provider.origin);
|
||||
this.panel.hidePopup();
|
||||
this.panel.hidden = true;
|
||||
|
||||
this.content.setAttribute("origin", provider.origin);
|
||||
if (!this.inMenuPanel) {
|
||||
let panel = this.panel;
|
||||
// if customization is currently happening, we may not have a panel
|
||||
// that we can hide
|
||||
if (panel.hidePopup) {
|
||||
panel.hidePopup();
|
||||
panel.hidden = true;
|
||||
}
|
||||
}
|
||||
this.pageData = null;
|
||||
]]></body>
|
||||
</method>
|
||||
@ -95,21 +130,32 @@
|
||||
<parameter name="pageData"/>
|
||||
<body><![CDATA[
|
||||
let provider = this.provider;
|
||||
this.panel.hidden = false;
|
||||
let panel = this.panel;
|
||||
panel.hidden = false;
|
||||
|
||||
// reparent the iframe if we've been customized to a new location
|
||||
if (this.content.parentNode != panel)
|
||||
panel.appendChild(this.content);
|
||||
|
||||
let URLTemplate = provider.markURL;
|
||||
this.pageData = pageData || OpenGraphBuilder.getData(gBrowser);
|
||||
let endpoint = OpenGraphBuilder.generateEndpointURL(URLTemplate, this.pageData);
|
||||
|
||||
// setup listeners
|
||||
this.addEventListener("DOMContentLoaded", function DOMContentLoaded(event) {
|
||||
let DOMContentLoaded = (event) => {
|
||||
if (event.target != this.contentDocument)
|
||||
return;
|
||||
this._loading = false;
|
||||
this.removeEventListener("DOMContentLoaded", DOMContentLoaded, true);
|
||||
this.content.removeEventListener("DOMContentLoaded", DOMContentLoaded, true);
|
||||
// add our resizer after the dom is ready
|
||||
let DynamicResizeWatcher = Cu.import("resource:///modules/Social.jsm", {}).DynamicResizeWatcher;
|
||||
this._dynamicResizer = new DynamicResizeWatcher();
|
||||
this._dynamicResizer.start(this.panel, this.content);
|
||||
if (!this.inMenuPanel) {
|
||||
let DynamicResizeWatcher = Cu.import("resource:///modules/Social.jsm", {}).DynamicResizeWatcher;
|
||||
this._dynamicResizer = new DynamicResizeWatcher();
|
||||
this._dynamicResizer.start(this.panel, this.content);
|
||||
} else if (this._dynamicResizer) {
|
||||
this._dynamicResizer.stop();
|
||||
this._dynamicResizer = null;
|
||||
}
|
||||
// send the opengraph data
|
||||
let evt = this.contentDocument.createEvent("CustomEvent");
|
||||
evt.initCustomEvent("OpenGraphData", true, true, JSON.stringify(this.pageData));
|
||||
@ -134,24 +180,63 @@
|
||||
contentWindow.removeEventListener("unload", unload);
|
||||
contentWindow.removeEventListener("socialMarkUpdate", markUpdate);
|
||||
});
|
||||
}, true);
|
||||
}
|
||||
this.content.addEventListener("DOMContentLoaded", DOMContentLoaded, true);
|
||||
this._loading = true;
|
||||
this.setAttribute("src", endpoint);
|
||||
this.content.setAttribute("src", endpoint);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="openPanel">
|
||||
<parameter name="aResetOnClose"/>
|
||||
<body><![CDATA[
|
||||
let panel = this.panel;
|
||||
let frameId = this.getAttribute("notificationFrameId");
|
||||
|
||||
let wasAlive = SharedFrame.isGroupAlive(frameId);
|
||||
SharedFrame.setOwner(frameId, this.content);
|
||||
|
||||
// Clear dimensions on all browsers so the panel size will
|
||||
// only use the selected browser.
|
||||
let frameIter = panel.firstElementChild;
|
||||
while (frameIter) {
|
||||
frameIter.collapsed = (frameIter != this.content);
|
||||
frameIter = frameIter.nextElementSibling;
|
||||
}
|
||||
|
||||
// if we're a slice in the hambuger, use that panel instead
|
||||
let widgetGroup = CustomizableUI.getWidget(this.getAttribute("id"));
|
||||
let widget = widgetGroup.forWindow(window);
|
||||
let inMenuPanel = widgetGroup.areaType == CustomizableUI.TYPE_MENU_PANEL;
|
||||
if (inMenuPanel) {
|
||||
PanelUI.showSubView("PanelUI-socialapi", widget.node,
|
||||
CustomizableUI.AREA_PANEL);
|
||||
} else {
|
||||
panel.openPopup(this, "bottomcenter topright", 0, 0, false, false);
|
||||
}
|
||||
if (aResetOnClose) {
|
||||
let evName = inMenuPanel ? "ViewHiding": "popuphidden";
|
||||
panel.addEventListener(evName, function _hidden() {
|
||||
panel.removeEventListener(evName, _hidden);
|
||||
this.update();
|
||||
}.bind(this), false);
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="markCurrentPage">
|
||||
<parameter name="aOpenPanel"/>
|
||||
<body><![CDATA[
|
||||
// we always set the src on click if it has not been set for this tab,
|
||||
// but we only want to open the panel if it was previously annotated.
|
||||
let openPanel = this.isMarked || aOpenPanel || !this.provider.haveLoggedInUser();
|
||||
let src = this.getAttribute("src");
|
||||
let openPanel = this.isMarked || aOpenPanel ||
|
||||
this.inMenuPanel || !this.provider.haveLoggedInUser();
|
||||
let src = this.content.getAttribute("src");
|
||||
if (!src || src == "about:blank") {
|
||||
this.loadPanel();
|
||||
}
|
||||
if (openPanel)
|
||||
this.panel.openPopup(this, "bottomcenter topright", 0, 0, false, false);
|
||||
this.openPanel();
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@ -167,13 +252,9 @@
|
||||
// and show it since the url may not be the browser tab, but an image,
|
||||
// link, etc. inside the page. We also "update" the iframe to the
|
||||
// previous url when it is closed.
|
||||
this.setAttribute("src", "about:blank");
|
||||
this.content.setAttribute("src", "about:blank");
|
||||
this.loadPanel({ url: aUrl });
|
||||
this.panel.openPopup(this, "bottomcenter topright", 0, 0, false, false);
|
||||
this.panel.addEventListener("popuphidden", function _hidden() {
|
||||
this.panel.removeEventListener("popuphidden", _hidden);
|
||||
this.update();
|
||||
}.bind(this), false);
|
||||
this.openPanel(true);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@ -186,23 +267,67 @@
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="popupshown"><![CDATA[
|
||||
<method name="onShown">
|
||||
<body><![CDATA[
|
||||
// because the panel may be preloaded, we need to size the panel when
|
||||
// showing as well as after load
|
||||
let sizeSocialPanelToContent = Cu.import("resource:///modules/Social.jsm", {}).sizeSocialPanelToContent;
|
||||
if (!this._loading && this.contentDocument.readyState == "complete") {
|
||||
if (!this._loading && this.contentDocument &&
|
||||
this.contentDocument.readyState == "complete") {
|
||||
this.dispatchPanelEvent("socialFrameShow");
|
||||
sizeSocialPanelToContent(this.panel, this.content);
|
||||
if (!this.inMenuPanel)
|
||||
sizeSocialPanelToContent(this.panel, this.content);
|
||||
} else {
|
||||
let panelBrowserOnload = () => {
|
||||
this.content.addEventListener("load", function panelBrowserOnload(e) {
|
||||
this.content.removeEventListener("load", panelBrowserOnload, true);
|
||||
this.dispatchPanelEvent("socialFrameShow");
|
||||
sizeSocialPanelToContent(this.panel, this.content);
|
||||
};
|
||||
this.content.addEventListener("load", panelBrowserOnload, true);
|
||||
if (!this.inMenuPanel)
|
||||
sizeSocialPanelToContent(this.panel, this.content);
|
||||
}.bind(this), true);
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="handleEvent">
|
||||
<parameter name="aEvent"/>
|
||||
<body><![CDATA[
|
||||
if (aEvent.eventPhase != aEvent.BUBBLING_PHASE)
|
||||
return;
|
||||
switch(aEvent.type) {
|
||||
case "DOMLinkAdded": {
|
||||
// much of this logic is from DOMLinkHandler in browser.js, this sets
|
||||
// the presence icon for a chat user, we simply use favicon style
|
||||
// updating
|
||||
let link = aEvent.originalTarget;
|
||||
let rel = link.rel && link.rel.toLowerCase();
|
||||
if (!link || !link.ownerDocument || !rel || !link.href)
|
||||
return;
|
||||
if (link.rel.indexOf("icon") < 0)
|
||||
return;
|
||||
|
||||
let uri = DOMLinkHandler.getLinkIconURI(link);
|
||||
if (!uri)
|
||||
return;
|
||||
|
||||
// we cannot size the image when we apply it via listStyleImage, so
|
||||
// use the toolbar image
|
||||
this.setAttribute("image", uri.spec);
|
||||
}
|
||||
break;
|
||||
case "ViewShowing":
|
||||
this.onShown();
|
||||
break;
|
||||
case "ViewHiding":
|
||||
this.dispatchPanelEvent("socialFrameHide");
|
||||
break;
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
</implementation>
|
||||
<handlers>
|
||||
<handler event="popupshown"><![CDATA[
|
||||
this.onShown();
|
||||
]]></handler>
|
||||
<handler event="popuphidden"><![CDATA[
|
||||
this.dispatchPanelEvent("socialFrameHide");
|
||||
@ -210,25 +335,6 @@
|
||||
<handler event="command"><![CDATA[
|
||||
this.markCurrentPage();
|
||||
]]></handler>
|
||||
<handler event="DOMLinkAdded"><![CDATA[
|
||||
// much of this logic is from DOMLinkHandler in browser.js, this sets
|
||||
// the presence icon for a chat user, we simply use favicon style
|
||||
// updating
|
||||
let link = event.originalTarget;
|
||||
let rel = link.rel && link.rel.toLowerCase();
|
||||
if (!link || !link.ownerDocument || !rel || !link.href)
|
||||
return;
|
||||
if (link.rel.indexOf("icon") < 0)
|
||||
return;
|
||||
|
||||
let uri = DOMLinkHandler.getLinkIconURI(link);
|
||||
if (!uri)
|
||||
return;
|
||||
|
||||
// we cannot size the image when we apply it via listStyleImage, so
|
||||
// use the toolbar image
|
||||
this.setAttribute("image", uri.spec);
|
||||
]]></handler>
|
||||
</handlers>
|
||||
</binding>
|
||||
|
||||
|
@ -436,8 +436,14 @@ function CreateSocialMarkWidget(aId, aProvider) {
|
||||
node.id = this.id;
|
||||
node.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional social-mark-button');
|
||||
node.setAttribute('type', "socialmark");
|
||||
node.style.listStyleImage = "url(" + aProvider.iconURL + ")";
|
||||
node.style.listStyleImage = "url(" + (aProvider.unmarkedIcon || aProvider.icon32URL || aProvider.iconURL) + ")";
|
||||
node.setAttribute("origin", aProvider.origin);
|
||||
node.setAttribute("oncommand", "this.markCurrentPage();");
|
||||
|
||||
let window = aDocument.defaultView;
|
||||
let menuLabel = window.gNavigatorBundle.getFormattedString("social.markpageMenu.label", [aProvider.name]);
|
||||
node.setAttribute("label", menuLabel);
|
||||
node.setAttribute("tooltiptext", menuLabel);
|
||||
|
||||
return node;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user