Bug 938904 - [e10s] Make tooltips work (r=smaug,enn)

This commit is contained in:
Bill McCloskey 2014-01-22 12:27:23 -08:00
parent ce48ae821d
commit aed56c33e5
8 changed files with 119 additions and 28 deletions

View File

@ -3459,6 +3459,21 @@ var XULBrowserWindow = {
LinkTargetDisplay.update();
},
showTooltip: function (x, y, tooltip) {
// The x,y coordinates are relative to the <browser> element using
// the chrome zoom level.
let elt = document.getElementById("remoteBrowserTooltip");
elt.label = tooltip;
let anchor = gBrowser.selectedBrowser;
elt.openPopupAtScreen(anchor.boxObject.screenX + x, anchor.boxObject.screenY + y, false, null);
},
hideTooltip: function () {
let elt = document.getElementById("remoteBrowserTooltip");
elt.hidePopup();
},
updateStatusField: function () {
var text, type, types = ["overLink"];
if (this._busyUI)

View File

@ -129,6 +129,7 @@
oncommand="gotoHistoryIndex(event); event.stopPropagation();"
onclick="checkForMiddleClick(this, event);"/>
<tooltip id="aHTMLTooltip" page="true"/>
<tooltip id="remoteBrowserTooltip"/>
<!-- for search and content formfill/pw manager -->
<panel type="autocomplete" id="PopupAutoComplete" noautofocus="true" hidden="true"/>

View File

@ -212,6 +212,13 @@ parent:
*/
SetStatus(uint32_t type, nsString status);
/**
* Show/hide a tooltip when the mouse hovers over an element in the content
* document.
*/
ShowTooltip(uint32_t x, uint32_t y, nsString tooltip);
HideTooltip();
/**
* Initiates an asynchronous request for permission for the
* provided principal.

View File

@ -735,6 +735,7 @@ NS_INTERFACE_MAP_BEGIN(TabChild)
NS_INTERFACE_MAP_ENTRY(nsIDialogCreator)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(TabChild)
@ -2512,6 +2513,20 @@ TabChild::GetFrom(nsIPresShell* aPresShell)
return GetFrom(docShell);
}
NS_IMETHODIMP
TabChild::OnShowTooltip(int32_t aXCoords, int32_t aYCoords, const char16_t *aTipText)
{
nsString str(aTipText);
SendShowTooltip(aXCoords, aYCoords, str);
return NS_OK;
}
NS_IMETHODIMP
TabChild::OnHideTooltip()
{
SendHideTooltip();
return NS_OK;
}
TabChildGlobal::TabChildGlobal(TabChild* aTabChild)
: mTabChild(aTabChild)

View File

@ -29,6 +29,7 @@
#include "nsIScriptObjectPrincipal.h"
#include "nsWeakReference.h"
#include "nsITabChild.h"
#include "nsITooltipListener.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/TabContext.h"
#include "mozilla/EventForwards.h"
@ -157,7 +158,8 @@ class TabChild : public PBrowserChild,
public nsITabChild,
public nsIObserver,
public ipc::MessageManagerCallback,
public TabContext
public TabContext,
public nsITooltipListener
{
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::layout::RenderFrameChild RenderFrameChild;
@ -191,6 +193,7 @@ public:
NS_DECL_NSIDIALOGCREATOR
NS_DECL_NSITABCHILD
NS_DECL_NSIOBSERVER
NS_DECL_NSITOOLTIPLISTENER
/**
* MessageManagerCallback methods that we override.

View File

@ -933,36 +933,75 @@ TabParent::RecvSetBackgroundColor(const nscolor& aColor)
return true;
}
nsIXULBrowserWindow*
TabParent::GetXULBrowserWindow()
{
nsCOMPtr<nsIContent> frame = do_QueryInterface(mFrameElement);
if (!frame) {
return nullptr;
}
nsCOMPtr<nsIDocShell> docShell = frame->OwnerDoc()->GetDocShell();
if (!docShell) {
return nullptr;
}
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
if (!treeOwner) {
return nullptr;
}
nsCOMPtr<nsIXULWindow> window = do_GetInterface(treeOwner);
if (!window) {
return nullptr;
}
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
window->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
return xulBrowserWindow;
}
bool
TabParent::RecvSetStatus(const uint32_t& aType, const nsString& aStatus)
{
nsCOMPtr<nsIContent> frame = do_QueryInterface(mFrameElement);
if (frame) {
nsCOMPtr<nsIDocShell> docShell = frame->OwnerDoc()->GetDocShell();
if (!docShell)
return true;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
docShell->GetTreeOwner(getter_AddRefs(treeOwner));
if (!treeOwner)
return true;
nsCOMPtr<nsIXULWindow> window = do_GetInterface(treeOwner);
if (window) {
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow;
window->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow));
if (xulBrowserWindow) {
switch (aType)
{
case nsIWebBrowserChrome::STATUS_SCRIPT:
xulBrowserWindow->SetJSStatus(aStatus);
break;
case nsIWebBrowserChrome::STATUS_LINK:
xulBrowserWindow->SetOverLink(aStatus, nullptr);
break;
}
}
}
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
if (!xulBrowserWindow) {
return true;
}
switch (aType) {
case nsIWebBrowserChrome::STATUS_SCRIPT:
xulBrowserWindow->SetJSStatus(aStatus);
break;
case nsIWebBrowserChrome::STATUS_LINK:
xulBrowserWindow->SetOverLink(aStatus, nullptr);
break;
}
return true;
}
bool
TabParent::RecvShowTooltip(const uint32_t& aX, const uint32_t& aY, const nsString& aTooltip)
{
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
if (!xulBrowserWindow) {
return true;
}
xulBrowserWindow->ShowTooltip(aX, aY, aTooltip);
return true;
}
bool
TabParent::RecvHideTooltip()
{
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow = GetXULBrowserWindow();
if (!xulBrowserWindow) {
return true;
}
xulBrowserWindow->HideTooltip();
return true;
}

View File

@ -17,6 +17,7 @@
#include "nsIDialogParamBlock.h"
#include "nsISecureBrowserUI.h"
#include "nsITabParent.h"
#include "nsIXULBrowserWindow.h"
#include "Units.h"
#include "js/TypeDecls.h"
@ -83,6 +84,8 @@ public:
already_AddRefed<nsILoadContext> GetLoadContext();
nsIXULBrowserWindow* GetXULBrowserWindow();
/**
* Return the TabParent that has decided it wants to capture an
* event series for fast-path dispatch to its subprocess, if one
@ -166,6 +169,8 @@ public:
virtual bool RecvSetCursor(const uint32_t& aValue) MOZ_OVERRIDE;
virtual bool RecvSetBackgroundColor(const nscolor& aValue) MOZ_OVERRIDE;
virtual bool RecvSetStatus(const uint32_t& aType, const nsString& aStatus) MOZ_OVERRIDE;
virtual bool RecvShowTooltip(const uint32_t& aX, const uint32_t& aY, const nsString& aTooltip);
virtual bool RecvHideTooltip();
virtual bool RecvGetDPI(float* aValue) MOZ_OVERRIDE;
virtual bool RecvGetDefaultScale(double* aValue) MOZ_OVERRIDE;
virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue) MOZ_OVERRIDE;

View File

@ -16,7 +16,7 @@ interface nsIDOMElement;
* internals of the browser area to tell the containing xul window to update
* its ui.
*/
[scriptable, uuid(7c91b4bd-f855-4872-b3fa-a2076d28eb03)]
[scriptable, uuid(e4ee85a0-645d-11e3-949a-0800200c9a66)]
interface nsIXULBrowserWindow : nsISupports
{
/**
@ -37,5 +37,11 @@ interface nsIXULBrowserWindow : nsISupports
in nsIURI linkURI,
in nsIDOMNode linkNode,
in boolean isAppTab);
/**
* Show/hide a tooltip (when the user mouses over a link, say).
*/
void showTooltip(in long x, in long y, in AString tooltip);
void hideTooltip();
};