From de3e84d435f4e8abfb84bd1ffd8040ecd07e2703 Mon Sep 17 00:00:00 2001 From: "saari%netscape.com" Date: Thu, 2 Dec 1999 20:55:17 +0000 Subject: [PATCH] Adding new event state manager API GetFocusedEventTarget which returns the current frame in focus regardless of the ESM instance you call it from. Editor guys need this for bug 20225 git-svn-id: svn://10.0.0.236/trunk@55078 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/public/nsIEventStateManager.h | 3 ++ .../events/src/nsEventStateManager.cpp | 32 +++++++++++++++++++ .../content/events/src/nsEventStateManager.h | 3 ++ .../events/public/nsIEventStateManager.h | 3 ++ .../layout/events/src/nsEventStateManager.cpp | 32 +++++++++++++++++++ .../layout/events/src/nsEventStateManager.h | 3 ++ 6 files changed, 76 insertions(+) diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 831a71a59f7..371eb93012a 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -70,6 +70,9 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; + // Cross ESM methods, doesn't matter what instance you call it from + NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame) = 0; + // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; }; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index d6989b41174..51370ff138f 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -63,6 +63,10 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID); +nsIFrame * gCurrentlyFocusedTargetFrame = 0; +nsIContent * gCurrentlyFocusedContent = 0; // Weak because it mirrors the strong mCurrentFocus +nsIPresContext * gCurrentlyFocusedPresContext = 0; // Strong + nsIContent * gLastFocusedContent = 0; nsIDocument * gLastFocusedDocument = 0; // Strong reference @@ -123,6 +127,8 @@ nsEventStateManager::~nsEventStateManager() if(mInstanceCount == 0) { NS_IF_RELEASE(gLastFocusedContent); NS_IF_RELEASE(gLastFocusedDocument); + + NS_IF_RELEASE(gCurrentlyFocusedPresContext); } } @@ -1718,6 +1724,26 @@ nsEventStateManager::GetEventTarget(nsIFrame **aFrame) return NS_OK; } +// This API crosses ESM instances to give the currently focused frame, no matter what ESM instace +// you call it from. +NS_IMETHODIMP +nsEventStateManager::GetFocusedEventTarget(nsIFrame **aFrame) +{ + if (!gCurrentlyFocusedTargetFrame && gCurrentlyFocusedContent && gCurrentlyFocusedPresContext) { + nsCOMPtr shell; + if (gCurrentlyFocusedPresContext) { + nsresult rv = gCurrentlyFocusedPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(gCurrentlyFocusedContent, &gCurrentlyFocusedTargetFrame); + } + } + } + + *aFrame = gCurrentlyFocusedTargetFrame; + return NS_OK; +} + + NS_IMETHODIMP nsEventStateManager::GetEventTargetContent(nsIContent** aContent) { @@ -1803,6 +1829,12 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) notifyContent[3] = mCurrentFocus; mCurrentFocus = aContent; NS_IF_ADDREF(mCurrentFocus); + + gCurrentlyFocusedContent = mCurrentFocus; + + NS_IF_RELEASE(gCurrentlyFocusedPresContext); + gCurrentlyFocusedPresContext = mPresContext; + NS_IF_ADDREF(gCurrentlyFocusedPresContext); } if (aContent) { // notify about new content too diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index 7e01b6bd8a3..5e6494a98b6 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -64,6 +64,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState); NS_IMETHOD GetFocusedContent(nsIContent **aContent); + // Cross ESM methods + NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame); + // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; } diff --git a/mozilla/layout/events/public/nsIEventStateManager.h b/mozilla/layout/events/public/nsIEventStateManager.h index 831a71a59f7..371eb93012a 100644 --- a/mozilla/layout/events/public/nsIEventStateManager.h +++ b/mozilla/layout/events/public/nsIEventStateManager.h @@ -70,6 +70,9 @@ public: NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; + // Cross ESM methods, doesn't matter what instance you call it from + NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame) = 0; + // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; }; diff --git a/mozilla/layout/events/src/nsEventStateManager.cpp b/mozilla/layout/events/src/nsEventStateManager.cpp index d6989b41174..51370ff138f 100644 --- a/mozilla/layout/events/src/nsEventStateManager.cpp +++ b/mozilla/layout/events/src/nsEventStateManager.cpp @@ -63,6 +63,10 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID); static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID); +nsIFrame * gCurrentlyFocusedTargetFrame = 0; +nsIContent * gCurrentlyFocusedContent = 0; // Weak because it mirrors the strong mCurrentFocus +nsIPresContext * gCurrentlyFocusedPresContext = 0; // Strong + nsIContent * gLastFocusedContent = 0; nsIDocument * gLastFocusedDocument = 0; // Strong reference @@ -123,6 +127,8 @@ nsEventStateManager::~nsEventStateManager() if(mInstanceCount == 0) { NS_IF_RELEASE(gLastFocusedContent); NS_IF_RELEASE(gLastFocusedDocument); + + NS_IF_RELEASE(gCurrentlyFocusedPresContext); } } @@ -1718,6 +1724,26 @@ nsEventStateManager::GetEventTarget(nsIFrame **aFrame) return NS_OK; } +// This API crosses ESM instances to give the currently focused frame, no matter what ESM instace +// you call it from. +NS_IMETHODIMP +nsEventStateManager::GetFocusedEventTarget(nsIFrame **aFrame) +{ + if (!gCurrentlyFocusedTargetFrame && gCurrentlyFocusedContent && gCurrentlyFocusedPresContext) { + nsCOMPtr shell; + if (gCurrentlyFocusedPresContext) { + nsresult rv = gCurrentlyFocusedPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(gCurrentlyFocusedContent, &gCurrentlyFocusedTargetFrame); + } + } + } + + *aFrame = gCurrentlyFocusedTargetFrame; + return NS_OK; +} + + NS_IMETHODIMP nsEventStateManager::GetEventTargetContent(nsIContent** aContent) { @@ -1803,6 +1829,12 @@ nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState) notifyContent[3] = mCurrentFocus; mCurrentFocus = aContent; NS_IF_ADDREF(mCurrentFocus); + + gCurrentlyFocusedContent = mCurrentFocus; + + NS_IF_RELEASE(gCurrentlyFocusedPresContext); + gCurrentlyFocusedPresContext = mPresContext; + NS_IF_ADDREF(gCurrentlyFocusedPresContext); } if (aContent) { // notify about new content too diff --git a/mozilla/layout/events/src/nsEventStateManager.h b/mozilla/layout/events/src/nsEventStateManager.h index 7e01b6bd8a3..5e6494a98b6 100644 --- a/mozilla/layout/events/src/nsEventStateManager.h +++ b/mozilla/layout/events/src/nsEventStateManager.h @@ -64,6 +64,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState); NS_IMETHOD GetFocusedContent(nsIContent **aContent); + // Cross ESM methods + NS_IMETHOD GetFocusedEventTarget(nsIFrame **aFrame); + // This is an experiement and may be temporary NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; }