From 6eeeaff2b06aa7d7d062765848a616eaf030b303 Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Thu, 30 Sep 1999 11:40:42 +0000 Subject: [PATCH] Added ConsumeFocusEvents method to consume all focus event and make sure they don't get dispatched --- content/events/public/nsIEventStateManager.h | 3 + content/events/src/nsEventStateManager.cpp | 66 ++++++++++++++++++-- content/events/src/nsEventStateManager.h | 4 ++ layout/events/public/nsIEventStateManager.h | 3 + layout/events/src/nsEventStateManager.cpp | 66 ++++++++++++++++++-- layout/events/src/nsEventStateManager.h | 4 ++ 6 files changed, 136 insertions(+), 10 deletions(-) diff --git a/content/events/public/nsIEventStateManager.h b/content/events/public/nsIEventStateManager.h index d5d5eca1555..c7e161cbb95 100644 --- a/content/events/public/nsIEventStateManager.h +++ b/content/events/public/nsIEventStateManager.h @@ -64,6 +64,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState) = 0; NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; + + // This is an experiement and may be temporary + NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; }; #define NS_EVENT_STATE_UNSPECIFIED 0x0000 diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 24a8020bd75..f441e46aa60 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -82,6 +82,7 @@ nsEventStateManager::nsEventStateManager() mPresContext = nsnull; mCurrentTabIndex = 0; mLastWindowToHaveFocus = nsnull; + mConsumeFocusEvents = PR_FALSE; NS_INIT_REFCNT(); } @@ -114,6 +115,13 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext, nsEventStatus& aStatus, nsIView* aView) { + // This is an experiement and may be temporary + // this consumes the very next focus event + if (mConsumeFocusEvents && aEvent->message == NS_GOTFOCUS) { + //mConsumeFocusEvents = PR_FALSE; + return NS_ERROR_FAILURE; // this should consume the event + } + mCurrentTarget = aTargetFrame; NS_IF_RELEASE(mCurrentTargetContent); @@ -368,13 +376,13 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_DOWN: { if (nsEventStatus_eConsumeNoDefault != aStatus) { - nsIContent* newFocus; - mCurrentTarget->GetContent(&newFocus); + nsCOMPtr newFocus; + mCurrentTarget->GetContent(getter_AddRefs(newFocus)); nsCOMPtr focusable; if (newFocus) { // Look for the nearest enclosing focusable content. - nsCOMPtr current = dont_QueryInterface(newFocus); + nsCOMPtr current = newFocus; while (current) { focusable = do_QueryInterface(current); if (focusable) @@ -384,7 +392,56 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, current->GetParent(*getter_AddRefs(parent)); current = parent; } - + + // if a focusable piece of content is an anonymous node + // weed to find the parent and have the parent be the + // new focusable node + // + // We fist to check here to see if the focused content + // is anonymous content + if (focusable) { + nsCOMPtr parent; + current->GetParent(*getter_AddRefs(parent)); + NS_ASSERTION(parent.get(), "parent is null. this should not happen."); + PRInt32 numChilds; + parent->ChildCount(numChilds); + PRInt32 i; + PRBool isChild = PR_FALSE; + for (i=0;i child; + parent->ChildAt(i, *getter_AddRefs(child)); + if (child.get() == current.get()) { + isChild = PR_TRUE; + break; + } + } + // if it isn't a child of the parent, then it is anonynous content + // Now, go up the parent list to find a focusable content node + if (!isChild) { + current = parent; + while (current) { + focusable = do_QueryInterface(current); + if (focusable) + break; + + nsCOMPtr tempParent; + current->GetParent(*getter_AddRefs(tempParent)); + current = tempParent; + } + } + // now we ned to get the content node's frame and reset + // the mCurrentTarget target + nsCOMPtr shell; + if (mPresContext) { + nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(current, &mCurrentTarget); + } + } + // now adjust the value for the "newFocus" + newFocus = current; + } + PRBool focusChangeFailed = PR_TRUE; if (focusable) { if (current.get() != mCurrentFocus) { @@ -406,7 +463,6 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, SetContentState(newFocus, NS_EVENT_STATE_ACTIVE); - NS_IF_RELEASE(newFocus); } } diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index 2d546361f54..057e5d95f5f 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -58,6 +58,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState); NS_IMETHOD GetFocusedContent(nsIContent **aContent); + // This is an experiement and may be temporary + NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; } + protected: void UpdateCursor(nsIPresContext& aPresContext, nsPoint& aPoint, nsIFrame* aTargetFrame, nsEventStatus& aStatus); void GenerateMouseEnterExit(nsIPresContext& aPresContext, nsGUIEvent* aEvent); @@ -99,6 +102,7 @@ protected: nsIContent* mCurrentFocus; PRInt32 mCurrentTabIndex; nsIWidget * mLastWindowToHaveFocus; // last native window to get focus via the evs + PRBool mConsumeFocusEvents; nsIPresContext* mPresContext; // Not refcnted nsIDocument* mDocument; // [OWNER], but doesn't need to be. diff --git a/layout/events/public/nsIEventStateManager.h b/layout/events/public/nsIEventStateManager.h index d5d5eca1555..c7e161cbb95 100644 --- a/layout/events/public/nsIEventStateManager.h +++ b/layout/events/public/nsIEventStateManager.h @@ -64,6 +64,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState) = 0; NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0; + + // This is an experiement and may be temporary + NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0; }; #define NS_EVENT_STATE_UNSPECIFIED 0x0000 diff --git a/layout/events/src/nsEventStateManager.cpp b/layout/events/src/nsEventStateManager.cpp index 24a8020bd75..f441e46aa60 100644 --- a/layout/events/src/nsEventStateManager.cpp +++ b/layout/events/src/nsEventStateManager.cpp @@ -82,6 +82,7 @@ nsEventStateManager::nsEventStateManager() mPresContext = nsnull; mCurrentTabIndex = 0; mLastWindowToHaveFocus = nsnull; + mConsumeFocusEvents = PR_FALSE; NS_INIT_REFCNT(); } @@ -114,6 +115,13 @@ nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext, nsEventStatus& aStatus, nsIView* aView) { + // This is an experiement and may be temporary + // this consumes the very next focus event + if (mConsumeFocusEvents && aEvent->message == NS_GOTFOCUS) { + //mConsumeFocusEvents = PR_FALSE; + return NS_ERROR_FAILURE; // this should consume the event + } + mCurrentTarget = aTargetFrame; NS_IF_RELEASE(mCurrentTargetContent); @@ -368,13 +376,13 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, case NS_MOUSE_RIGHT_BUTTON_DOWN: { if (nsEventStatus_eConsumeNoDefault != aStatus) { - nsIContent* newFocus; - mCurrentTarget->GetContent(&newFocus); + nsCOMPtr newFocus; + mCurrentTarget->GetContent(getter_AddRefs(newFocus)); nsCOMPtr focusable; if (newFocus) { // Look for the nearest enclosing focusable content. - nsCOMPtr current = dont_QueryInterface(newFocus); + nsCOMPtr current = newFocus; while (current) { focusable = do_QueryInterface(current); if (focusable) @@ -384,7 +392,56 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, current->GetParent(*getter_AddRefs(parent)); current = parent; } - + + // if a focusable piece of content is an anonymous node + // weed to find the parent and have the parent be the + // new focusable node + // + // We fist to check here to see if the focused content + // is anonymous content + if (focusable) { + nsCOMPtr parent; + current->GetParent(*getter_AddRefs(parent)); + NS_ASSERTION(parent.get(), "parent is null. this should not happen."); + PRInt32 numChilds; + parent->ChildCount(numChilds); + PRInt32 i; + PRBool isChild = PR_FALSE; + for (i=0;i child; + parent->ChildAt(i, *getter_AddRefs(child)); + if (child.get() == current.get()) { + isChild = PR_TRUE; + break; + } + } + // if it isn't a child of the parent, then it is anonynous content + // Now, go up the parent list to find a focusable content node + if (!isChild) { + current = parent; + while (current) { + focusable = do_QueryInterface(current); + if (focusable) + break; + + nsCOMPtr tempParent; + current->GetParent(*getter_AddRefs(tempParent)); + current = tempParent; + } + } + // now we ned to get the content node's frame and reset + // the mCurrentTarget target + nsCOMPtr shell; + if (mPresContext) { + nsresult rv = mPresContext->GetShell(getter_AddRefs(shell)); + if (NS_SUCCEEDED(rv) && shell){ + shell->GetPrimaryFrameFor(current, &mCurrentTarget); + } + } + // now adjust the value for the "newFocus" + newFocus = current; + } + PRBool focusChangeFailed = PR_TRUE; if (focusable) { if (current.get() != mCurrentFocus) { @@ -406,7 +463,6 @@ nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext, SetContentState(newFocus, NS_EVENT_STATE_ACTIVE); - NS_IF_RELEASE(newFocus); } } diff --git a/layout/events/src/nsEventStateManager.h b/layout/events/src/nsEventStateManager.h index 2d546361f54..057e5d95f5f 100644 --- a/layout/events/src/nsEventStateManager.h +++ b/layout/events/src/nsEventStateManager.h @@ -58,6 +58,9 @@ public: NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState); NS_IMETHOD GetFocusedContent(nsIContent **aContent); + // This is an experiement and may be temporary + NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; } + protected: void UpdateCursor(nsIPresContext& aPresContext, nsPoint& aPoint, nsIFrame* aTargetFrame, nsEventStatus& aStatus); void GenerateMouseEnterExit(nsIPresContext& aPresContext, nsGUIEvent* aEvent); @@ -99,6 +102,7 @@ protected: nsIContent* mCurrentFocus; PRInt32 mCurrentTabIndex; nsIWidget * mLastWindowToHaveFocus; // last native window to get focus via the evs + PRBool mConsumeFocusEvents; nsIPresContext* mPresContext; // Not refcnted nsIDocument* mDocument; // [OWNER], but doesn't need to be.