Bug 1434399 part 1. Switch to nsINode for the popup node on windowroot. r=mystor

MozReview-Commit-ID: HyiHElDnmSH
This commit is contained in:
Boris Zbarsky 2018-01-31 14:49:26 -05:00
Родитель 94617f91cf
Коммит 99c47399c4
8 изменённых файлов: 63 добавлений и 90 удалений

Просмотреть файл

@ -14,6 +14,7 @@
class nsPIDOMWindowOuter;
class nsIControllers;
class nsIController;
class nsINode;
namespace mozilla {
namespace dom {
@ -33,8 +34,8 @@ public:
virtual nsPIDOMWindowOuter* GetWindow()=0;
// get and set the node that is the context of a popup menu
virtual nsIDOMNode* GetPopupNode() = 0;
virtual void SetPopupNode(nsIDOMNode* aNode) = 0;
virtual already_AddRefed<nsINode> GetPopupNode() = 0;
virtual void SetPopupNode(nsINode* aNode) = 0;
/**
* @param aForVisibleWindow true if caller needs controller which is

Просмотреть файл

@ -371,15 +371,15 @@ nsWindowRoot::GetEnabledDisabledCommands(nsTArray<nsCString>& aEnabledCommands,
}
}
nsIDOMNode*
already_AddRefed<nsINode>
nsWindowRoot::GetPopupNode()
{
nsCOMPtr<nsIDOMNode> popupNode = do_QueryReferent(mPopupNode);
return popupNode;
nsCOMPtr<nsINode> popupNode = do_QueryReferent(mPopupNode);
return popupNode.forget();
}
void
nsWindowRoot::SetPopupNode(nsIDOMNode* aNode)
nsWindowRoot::SetPopupNode(nsINode* aNode)
{
mPopupNode = do_GetWeakReference(aNode);
}

Просмотреть файл

@ -52,8 +52,8 @@ public:
virtual void GetEnabledDisabledCommands(nsTArray<nsCString>& aEnabledCommands,
nsTArray<nsCString>& aDisabledCommands) override;
virtual nsIDOMNode* GetPopupNode() override;
virtual void SetPopupNode(nsIDOMNode* aNode) override;
virtual already_AddRefed<nsINode> GetPopupNode() override;
virtual void SetPopupNode(nsINode* aNode) override;
virtual void SetParentTarget(mozilla::dom::EventTarget* aTarget) override
{

Просмотреть файл

@ -1315,8 +1315,8 @@ XULDocument::GetHeight(ErrorResult& aRv)
return height;
}
JSObject*
GetScopeObjectOfNode(nsIDOMNode* node)
static JSObject*
GetScopeObjectOfNode(nsINode* node)
{
MOZ_ASSERT(node, "Must not be called with null.");
@ -1328,11 +1328,8 @@ GetScopeObjectOfNode(nsIDOMNode* node)
// this, let's do the same check as nsNodeSH::PreCreate does to
// determine the scope and if it fails let's just return null in
// XULDocument::GetPopupNode.
nsCOMPtr<nsINode> inode = do_QueryInterface(node);
MOZ_ASSERT(inode, "How can this happen?");
nsIDocument* doc = inode->OwnerDoc();
MOZ_ASSERT(inode, "This should never happen.");
nsIDocument* doc = node->OwnerDoc();
MOZ_ASSERT(doc, "This should never happen.");
nsIGlobalObject* global = doc->GetScopeObject();
return global ? global->GetGlobalJSObject() : nullptr;
@ -1348,10 +1345,11 @@ XULDocument::GetPopupNode(nsIDOMNode** aNode)
{
*aNode = nullptr;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsINode> node;
nsCOMPtr<nsPIWindowRoot> rootWin = GetWindowRoot();
if (rootWin)
if (rootWin) {
node = rootWin->GetPopupNode(); // addref happens here
}
if (!node) {
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
@ -1362,7 +1360,8 @@ XULDocument::GetPopupNode(nsIDOMNode** aNode)
if (node && nsContentUtils::CanCallerAccess(node)
&& GetScopeObjectOfNode(node)) {
node.forget(aNode);
*aNode = node->AsDOMNode();
NS_ADDREF(*aNode);
}
return NS_OK;
@ -1381,15 +1380,16 @@ XULDocument::GetPopupNode()
NS_IMETHODIMP
XULDocument::SetPopupNode(nsIDOMNode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
if (aNode) {
// only allow real node objects
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_ARG(node);
}
nsCOMPtr<nsPIWindowRoot> rootWin = GetWindowRoot();
if (rootWin)
rootWin->SetPopupNode(aNode); // addref happens here
if (rootWin) {
rootWin->SetPopupNode(node);
}
return NS_OK;
}
@ -1472,9 +1472,11 @@ XULDocument::GetTooltipNode(nsIDOMNode** aNode)
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
nsCOMPtr<nsIDOMNode> node = pm->GetLastTriggerTooltipNode(this);
if (node && nsContentUtils::CanCallerAccess(node))
node.forget(aNode);
nsCOMPtr<nsINode> node = pm->GetLastTriggerTooltipNode(this);
if (node && nsContentUtils::CanCallerAccess(node)) {
*aNode = node->AsDOMNode();
NS_ADDREF(*aNode);
}
}
return NS_OK;

Просмотреть файл

@ -281,9 +281,9 @@ private:
*/
nsresult InitPresentationStuff(bool aDoInitialReflow);
nsresult GetPopupNode(nsIDOMNode** aNode);
nsresult GetPopupLinkNode(nsIDOMNode** aNode);
nsresult GetPopupImageNode(nsIImageLoadingContent** aNode);
already_AddRefed<nsINode> GetPopupNode();
already_AddRefed<nsINode> GetPopupLinkNode();
already_AddRefed<nsIImageLoadingContent> GetPopupImageNode();
nsresult GetContentSizeInternal(int32_t* aWidth, int32_t* aHeight,
nscoord aMaxWidth, nscoord aMaxHeight);
@ -2761,8 +2761,7 @@ NS_IMETHODIMP nsDocumentViewer::CopySelection()
NS_IMETHODIMP nsDocumentViewer::CopyLinkLocation()
{
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIDOMNode> node;
GetPopupLinkNode(getter_AddRefs(node));
nsCOMPtr<nsINode> node = GetPopupLinkNode();
// make noise if we're not in a link
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
@ -2785,8 +2784,7 @@ NS_IMETHODIMP nsDocumentViewer::CopyLinkLocation()
NS_IMETHODIMP nsDocumentViewer::CopyImage(int32_t aCopyFlags)
{
NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_INITIALIZED);
nsCOMPtr<nsIImageLoadingContent> node;
GetPopupImageNode(getter_AddRefs(node));
nsCOMPtr<nsIImageLoadingContent> node = GetPopupImageNode();
// make noise if we're not in an image
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
@ -2846,7 +2844,8 @@ NS_IMETHODIMP nsDocumentViewer::SetCommandNode(nsIDOMNode* aNode)
nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
NS_ENSURE_STATE(root);
root->SetPopupNode(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
root->SetPopupNode(node);
return NS_OK;
}
@ -3612,26 +3611,22 @@ nsresult nsDocViewerSelectionListener::Init(nsDocumentViewer *aDocViewer)
* not all content (images included) can receive focus.
*/
nsresult
nsDocumentViewer::GetPopupNode(nsIDOMNode** aNode)
already_AddRefed<nsINode>
nsDocumentViewer::GetPopupNode()
{
NS_ENSURE_ARG_POINTER(aNode);
*aNode = nullptr;
// get the document
nsIDocument* document = GetDocument();
NS_ENSURE_TRUE(document, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(document, nullptr);
// get the private dom window
nsCOMPtr<nsPIDOMWindowOuter> window(document->GetWindow());
NS_ENSURE_TRUE(window, NS_ERROR_NOT_AVAILABLE);
NS_ENSURE_TRUE(window, nullptr);
if (window) {
nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
NS_ENSURE_TRUE(root, nullptr);
// get the popup node
nsCOMPtr<nsIDOMNode> node = root->GetPopupNode();
nsCOMPtr<nsINode> node = root->GetPopupNode();
#ifdef MOZ_XUL
if (!node) {
nsPIDOMWindowOuter* rootWindow = root->GetWindow();
@ -3646,27 +3641,18 @@ nsDocumentViewer::GetPopupNode(nsIDOMNode** aNode)
}
}
#endif
node.swap(*aNode);
return node.forget();
}
return NS_OK;
return nullptr;
}
// GetPopupLinkNode: return popup link node or fail
nsresult
nsDocumentViewer::GetPopupLinkNode(nsIDOMNode** aNode)
already_AddRefed<nsINode>
nsDocumentViewer::GetPopupLinkNode()
{
NS_ENSURE_ARG_POINTER(aNode);
// you get null unless i say so
*aNode = nullptr;
// find popup node
nsCOMPtr<nsIDOMNode> domNode;
nsresult rv = GetPopupNode(getter_AddRefs(domNode));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsINode> node = do_QueryInterface(domNode);
nsCOMPtr<nsINode> node = GetPopupNode();
// find out if we have a link in our ancestry
while (node) {
@ -3674,9 +3660,7 @@ nsDocumentViewer::GetPopupLinkNode(nsIDOMNode** aNode)
if (content) {
nsCOMPtr<nsIURI> hrefURI = content->GetHrefURI();
if (hrefURI) {
*aNode = node->AsDOMNode();
NS_IF_ADDREF(*aNode); // addref
return NS_OK;
return node.forget();
}
}
@ -3685,27 +3669,17 @@ nsDocumentViewer::GetPopupLinkNode(nsIDOMNode** aNode)
}
// if we have no node, fail
return NS_ERROR_FAILURE;
return nullptr;
}
// GetPopupLinkNode: return popup image node or fail
nsresult
nsDocumentViewer::GetPopupImageNode(nsIImageLoadingContent** aNode)
already_AddRefed<nsIImageLoadingContent>
nsDocumentViewer::GetPopupImageNode()
{
NS_ENSURE_ARG_POINTER(aNode);
// you get null unless i say so
*aNode = nullptr;
// find popup node
nsCOMPtr<nsIDOMNode> node;
nsresult rv = GetPopupNode(getter_AddRefs(node));
NS_ENSURE_SUCCESS(rv, rv);
if (node)
CallQueryInterface(node, aNode);
return NS_OK;
nsCOMPtr<nsINode> node = GetPopupNode();
nsCOMPtr<nsIImageLoadingContent> img = do_QueryInterface(node);
return img.forget();
}
/*
@ -3731,9 +3705,7 @@ NS_IMETHODIMP nsDocumentViewer::GetInLink(bool* aInLink)
*aInLink = false;
// get the popup link
nsCOMPtr<nsIDOMNode> node;
nsresult rv = GetPopupLinkNode(getter_AddRefs(node));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsINode> node = GetPopupLinkNode();
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
// if we made it here, we're in a link
@ -3753,9 +3725,7 @@ NS_IMETHODIMP nsDocumentViewer::GetInImage(bool* aInImage)
*aInImage = false;
// get the popup image
nsCOMPtr<nsIImageLoadingContent> node;
nsresult rv = GetPopupImageNode(getter_AddRefs(node));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIImageLoadingContent> node = GetPopupImageNode();
if (!node) {
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -1706,20 +1706,20 @@ nsXULPopupManager::GetVisiblePopups(nsTArray<nsIFrame *>& aPopups)
}
}
already_AddRefed<nsIDOMNode>
already_AddRefed<nsINode>
nsXULPopupManager::GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip)
{
if (!aDocument)
return nullptr;
nsCOMPtr<nsIDOMNode> node;
nsCOMPtr<nsINode> node;
// if mOpeningPopup is set, it means that a popupshowing event is being
// fired. In this case, just use the cached node, as the popup is not yet in
// the list of open popups.
if (mOpeningPopup && mOpeningPopup->GetUncomposedDoc() == aDocument &&
aIsTooltip == mOpeningPopup->IsXULElement(nsGkAtoms::tooltip)) {
node = do_QueryInterface(nsMenuPopupFrame::GetTriggerContent(GetPopupFrameForContent(mOpeningPopup, false)));
node = nsMenuPopupFrame::GetTriggerContent(GetPopupFrameForContent(mOpeningPopup, false));
}
else {
nsMenuChainItem* item = mPopups;
@ -1727,7 +1727,7 @@ nsXULPopupManager::GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip)
// look for a popup of the same type and document.
if ((item->PopupType() == ePopupTypeTooltip) == aIsTooltip &&
item->Content()->GetUncomposedDoc() == aDocument) {
node = do_QueryInterface(nsMenuPopupFrame::GetTriggerContent(item->Frame()));
node = nsMenuPopupFrame::GetTriggerContent(item->Frame());
if (node)
break;
}

Просмотреть файл

@ -596,12 +596,12 @@ public:
* aDocument. aDocument must be non-null and be a document contained within
* the same window hierarchy as the popup to retrieve.
*/
already_AddRefed<nsIDOMNode> GetLastTriggerPopupNode(nsIDocument* aDocument)
already_AddRefed<nsINode> GetLastTriggerPopupNode(nsIDocument* aDocument)
{
return GetLastTriggerNode(aDocument, false);
}
already_AddRefed<nsIDOMNode> GetLastTriggerTooltipNode(nsIDocument* aDocument)
already_AddRefed<nsINode> GetLastTriggerTooltipNode(nsIDocument* aDocument)
{
return GetLastTriggerNode(aDocument, true);
}
@ -798,7 +798,7 @@ private:
protected:
already_AddRefed<nsIDOMNode> GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip);
already_AddRefed<nsINode> GetLastTriggerNode(nsIDocument* aDocument, bool aIsTooltip);
/**
* Set mouse capturing for the current popup. This traps mouse clicks that

Просмотреть файл

@ -103,12 +103,12 @@ nsXULTooltipListener::MouseOut(nsIDOMEvent* aEvent)
// hide the tooltip
if (currentTooltip) {
// which node did the mouse leave?
nsCOMPtr<nsIDOMNode> targetNode = do_QueryInterface(
nsCOMPtr<nsINode> targetNode = do_QueryInterface(
aEvent->InternalDOMEvent()->GetTarget());
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
if (pm) {
nsCOMPtr<nsIDOMNode> tooltipNode =
nsCOMPtr<nsINode> tooltipNode =
pm->GetLastTriggerTooltipNode(currentTooltip->GetUncomposedDoc());
if (tooltipNode == targetNode) {
// if the target node is the current tooltip target node, the mouse