From bbbc2fd341cad3a220a343530e66600e38bd79ca Mon Sep 17 00:00:00 2001 From: Juha Kotiranta Date: Fri, 17 Sep 2010 11:56:53 -0700 Subject: [PATCH] Bug 581916 - Fetching mouse cursor from window trough DOM window utils API. r=Olli.Pettay a=approval2.0 --- content/events/src/nsEventStateManager.cpp | 8 ++++++ content/events/src/nsEventStateManager.h | 2 ++ dom/base/nsDOMWindowUtils.cpp | 33 ++++++++++++++++++++++ dom/interfaces/base/nsIDOMWindowUtils.idl | 8 +++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 53fcaf62c87c..4072a300da5e 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -186,6 +186,7 @@ static PRInt32 sChromeAccessModifier = 0, sContentAccessModifier = 0; PRInt32 nsEventStateManager::sUserInputEventDepth = 0; PRBool nsEventStateManager::sNormalLMouseEventInProcess = PR_FALSE; nsEventStateManager* nsEventStateManager::sActiveESM = nsnull; +nsIDocument* nsEventStateManager::sMouseOverDocument = nsnull; static PRUint32 gMouseOrKeyboardEventCounter = 0; static nsITimer* gUserInteractionTimer = nsnull; @@ -860,6 +861,9 @@ nsEventStateManager::~nsEventStateManager() if (mClickHoldContextMenu) KillClickHoldTimer(); + if (mDocument == sMouseOverDocument) + sMouseOverDocument = nsnull; + --sESMInstanceCount; if(sESMInstanceCount == 0) { nsMouseWheelTransaction::Shutdown(); @@ -3410,6 +3414,10 @@ nsEventStateManager::SetCursor(PRInt32 aCursor, imgIContainer* aContainer, float aHotspotX, float aHotspotY, nsIWidget* aWidget, PRBool aLockCursor) { + EnsureDocument(mPresContext); + NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); + sMouseOverDocument = mDocument.get(); + nsCursor c; NS_ENSURE_TRUE(aWidget, NS_ERROR_FAILURE); diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index a32928f08f30..490b7081d852 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -147,6 +147,8 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsEventStateManager, nsIEventStateManager) + static nsIDocument* sMouseOverDocument; + protected: void UpdateCursor(nsPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus); /** diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 369cf2f31f5f..aecc957f2206 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -47,6 +47,7 @@ #include "nsIDocument.h" #include "nsFocusManager.h" #include "nsIEventStateManager.h" +#include "nsEventStateManager.h" #include "nsIScrollableFrame.h" @@ -1575,3 +1576,35 @@ nsDOMWindowUtils::RenderDocument(const nsRect& aRect, // Render Document return presShell->RenderDocument(aRect, aFlags, aBackgroundColor, aThebesContext); } + +NS_IMETHODIMP +nsDOMWindowUtils::GetCursorType(PRInt16 *aCursor) +{ + NS_ENSURE_ARG_POINTER(aCursor); + + PRBool isSameDoc = PR_FALSE; + nsCOMPtr doc(do_QueryInterface(mWindow->GetExtantDocument())); + + NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE); + + do { + if (nsEventStateManager::sMouseOverDocument == doc.get()) { + isSameDoc = PR_TRUE; + break; + } + } while ((doc = doc->GetParentDocument())); + + if (!isSameDoc) { + *aCursor = eCursor_none; + return NS_OK; + } + + nsCOMPtr widget = GetWidget(); + if (!widget) + return NS_ERROR_FAILURE; + + // fetch cursor value from window's widget + *aCursor = widget->GetCursor(); + + return NS_OK; +} diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 9ee69b72e580..8e7dc99bdeb3 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -60,7 +60,7 @@ interface nsIDOMEvent; interface nsITransferable; interface nsIQueryContentEventResult; -[scriptable, uuid(74fdd125-52c7-4345-a086-270df15b829a)] +[scriptable, uuid(8707ed93-3277-42a5-a235-533aa661a263)] interface nsIDOMWindowUtils : nsISupports { /** @@ -89,6 +89,12 @@ interface nsIDOMWindowUtils : nsISupports { */ readonly attribute boolean docCharsetIsForced; + /** + * Get current cursor type from this window + * @return the current value of nsCursor + */ + short getCursorType(); + /** * Function to get metadata associated with the window's current document * @param aName the name of the metadata. This should be all lowercase.