From 22c80ea3f08d80c8673fe03d44d91eceb9d7edbe Mon Sep 17 00:00:00 2001 From: "dbaron%fas.harvard.edu" Date: Thu, 3 Feb 2000 02:49:58 +0000 Subject: [PATCH] Event Target Debugging (b=18175), a debugging feature to help with fixing bugs where events are going to the wrong elements. It shows (like Visual Debugging) which frame is receiving events, and one can therefore move the mouse over the page to see what frame gets events. All the code is #ifdef NS_DEBUG. However, it is not yet hooked up to the viewer menu (to be checked in later). r=joki git-svn-id: svn://10.0.0.236/trunk@59610 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsILayoutDebugger.h | 4 ++ mozilla/layout/base/nsLayoutDebugger.cpp | 18 +++++++++ mozilla/layout/base/nsPresShell.cpp | 38 +++++++++++++++++++ mozilla/layout/base/public/nsIFrameDebug.h | 4 ++ .../layout/base/public/nsILayoutDebugger.h | 4 ++ mozilla/layout/base/src/nsLayoutDebugger.cpp | 18 +++++++++ mozilla/layout/generic/nsFrame.cpp | 12 ++++++ mozilla/layout/generic/nsIFrameDebug.h | 4 ++ mozilla/layout/html/base/src/nsFrame.cpp | 12 ++++++ mozilla/layout/html/base/src/nsPresShell.cpp | 38 +++++++++++++++++++ 10 files changed, 152 insertions(+) diff --git a/mozilla/layout/base/nsILayoutDebugger.h b/mozilla/layout/base/nsILayoutDebugger.h index 51da819d6f1..75b4ba5b89c 100644 --- a/mozilla/layout/base/nsILayoutDebugger.h +++ b/mozilla/layout/base/nsILayoutDebugger.h @@ -41,6 +41,10 @@ public: NS_IMETHOD GetShowFrameBorders(PRBool* aResult) = 0; + NS_IMETHOD SetShowEventTargetFrameBorder(PRBool aEnable) = 0; + + NS_IMETHOD GetShowEventTargetFrameBorder(PRBool* aResult) = 0; + NS_IMETHOD GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult) = 0; diff --git a/mozilla/layout/base/nsLayoutDebugger.cpp b/mozilla/layout/base/nsLayoutDebugger.cpp index cba7d560ada..bb2991f202e 100644 --- a/mozilla/layout/base/nsLayoutDebugger.cpp +++ b/mozilla/layout/base/nsLayoutDebugger.cpp @@ -37,6 +37,10 @@ public: NS_IMETHOD GetShowFrameBorders(PRBool* aResult); + NS_IMETHOD SetShowEventTargetFrameBorder(PRBool aEnable); + + NS_IMETHOD GetShowEventTargetFrameBorder(PRBool* aResult); + NS_IMETHOD GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult); @@ -87,6 +91,20 @@ nsLayoutDebugger::GetShowFrameBorders(PRBool* aResult) return NS_OK; } +NS_IMETHODIMP +nsLayoutDebugger::SetShowEventTargetFrameBorder(PRBool aEnable) +{ + nsIFrameDebug::ShowEventTargetFrameBorder(aEnable); + return NS_OK; +} + +NS_IMETHODIMP +nsLayoutDebugger::GetShowEventTargetFrameBorder(PRBool* aResult) +{ + *aResult = nsIFrameDebug::GetShowEventTargetFrameBorder(); + return NS_OK; +} + NS_IMETHODIMP nsLayoutDebugger::GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult) diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index e8bcef5ac10..70447a02f2f 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -477,6 +477,10 @@ protected: nsIFrame* mCurrentEventFrame; nsIContent* mCurrentEventContent; nsVoidArray mCurrentEventFrameStack; +#ifdef NS_DEBUG + nsRect mCurrentTargetRect; + nsIView* mCurrentTargetView; +#endif nsCOMPtr mSelection; nsCOMPtr mCaret; @@ -618,6 +622,9 @@ PresShell::PresShell() mCurrentEventContent = nsnull; mCurrentEventFrame = nsnull; EnableScrolling(); +#ifdef NS_DEBUG + mCurrentTargetView = nsnull; +#endif mPendingReflowEvent = PR_FALSE; mDocumentIsLoading = PR_TRUE; mBatchReflows = PR_FALSE; @@ -2734,6 +2741,11 @@ PresShell::Paint(nsIView *aView, aRenderingContext.SetColor(NS_RGB(0,0,255)); aRenderingContext.DrawRect(0, 0, r.width, r.height); } + // Draw a border around the current event target + if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (aView == mCurrentTargetView)) { + aRenderingContext.SetColor(NS_RGB(128,0,128)); + aRenderingContext.DrawRect(mCurrentTargetRect.x, mCurrentTargetRect.y, mCurrentTargetRect.width, mCurrentTargetRect.height); + } #endif } @@ -2856,6 +2868,32 @@ PresShell::HandleEvent(nsIView *aView, NS_RELEASE(manager); NS_IF_RELEASE(focusContent); } +#ifdef NS_DEBUG + if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (GetCurrentEventFrame())) { + nsIView *oldView = mCurrentTargetView; + nsPoint offset(0,0); + nsRect oldTargetRect(mCurrentTargetRect); + mCurrentEventFrame->GetRect(mCurrentTargetRect); + mCurrentEventFrame->GetView(mPresContext, &mCurrentTargetView); + if ( ! mCurrentTargetView ) { + mCurrentEventFrame->GetOffsetFromView(mPresContext, offset, &mCurrentTargetView); + } + if (mCurrentTargetView) { + mCurrentTargetRect.x = offset.x; + mCurrentTargetRect.y = offset.y; + // use aView or mCurrentTargetView?? + if ( (mCurrentTargetRect != oldTargetRect) || (mCurrentTargetView != oldView)) { + nsIViewManager *vm; + if ((NS_OK == GetViewManager(&vm)) && vm) { + vm->UpdateView(mCurrentTargetView,mCurrentTargetRect,0); + if (oldView) + vm->UpdateView(oldView,oldTargetRect,0); + NS_IF_RELEASE(vm); + } + } + } + } +#endif PopCurrentEventFrame(); } else { diff --git a/mozilla/layout/base/public/nsIFrameDebug.h b/mozilla/layout/base/public/nsIFrameDebug.h index 7dd5cf034d6..29eaacbee54 100644 --- a/mozilla/layout/base/public/nsIFrameDebug.h +++ b/mozilla/layout/base/public/nsIFrameDebug.h @@ -115,6 +115,10 @@ public: static NS_LAYOUT void ShowFrameBorders(PRBool aEnable); static NS_LAYOUT PRBool GetShowFrameBorders(); + // Show frame border of event target + static NS_LAYOUT void ShowEventTargetFrameBorder(PRBool aEnable); + static NS_LAYOUT PRBool GetShowEventTargetFrameBorder(); + private: NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0; diff --git a/mozilla/layout/base/public/nsILayoutDebugger.h b/mozilla/layout/base/public/nsILayoutDebugger.h index 51da819d6f1..75b4ba5b89c 100644 --- a/mozilla/layout/base/public/nsILayoutDebugger.h +++ b/mozilla/layout/base/public/nsILayoutDebugger.h @@ -41,6 +41,10 @@ public: NS_IMETHOD GetShowFrameBorders(PRBool* aResult) = 0; + NS_IMETHOD SetShowEventTargetFrameBorder(PRBool aEnable) = 0; + + NS_IMETHOD GetShowEventTargetFrameBorder(PRBool* aResult) = 0; + NS_IMETHOD GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult) = 0; diff --git a/mozilla/layout/base/src/nsLayoutDebugger.cpp b/mozilla/layout/base/src/nsLayoutDebugger.cpp index cba7d560ada..bb2991f202e 100644 --- a/mozilla/layout/base/src/nsLayoutDebugger.cpp +++ b/mozilla/layout/base/src/nsLayoutDebugger.cpp @@ -37,6 +37,10 @@ public: NS_IMETHOD GetShowFrameBorders(PRBool* aResult); + NS_IMETHOD SetShowEventTargetFrameBorder(PRBool aEnable); + + NS_IMETHOD GetShowEventTargetFrameBorder(PRBool* aResult); + NS_IMETHOD GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult); @@ -87,6 +91,20 @@ nsLayoutDebugger::GetShowFrameBorders(PRBool* aResult) return NS_OK; } +NS_IMETHODIMP +nsLayoutDebugger::SetShowEventTargetFrameBorder(PRBool aEnable) +{ + nsIFrameDebug::ShowEventTargetFrameBorder(aEnable); + return NS_OK; +} + +NS_IMETHODIMP +nsLayoutDebugger::GetShowEventTargetFrameBorder(PRBool* aResult) +{ + *aResult = nsIFrameDebug::GetShowEventTargetFrameBorder(); + return NS_OK; +} + NS_IMETHODIMP nsLayoutDebugger::GetContentSize(nsIDocument* aDocument, PRInt32* aSizeInBytesResult) diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index a068cd83229..dda1e3fb000 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -107,6 +107,18 @@ NS_LAYOUT PRBool nsIFrameDebug::GetShowFrameBorders() return gShowFrameBorders; } +static PRBool gShowEventTargetFrameBorder = PR_FALSE; + +NS_LAYOUT void nsIFrameDebug::ShowEventTargetFrameBorder(PRBool aEnable) +{ + gShowEventTargetFrameBorder = aEnable; +} + +NS_LAYOUT PRBool nsIFrameDebug::GetShowEventTargetFrameBorder() +{ + return gShowEventTargetFrameBorder; +} + /** * Note: the log module is created during library initialization which * means that you cannot perform logging before then. diff --git a/mozilla/layout/generic/nsIFrameDebug.h b/mozilla/layout/generic/nsIFrameDebug.h index 7dd5cf034d6..29eaacbee54 100644 --- a/mozilla/layout/generic/nsIFrameDebug.h +++ b/mozilla/layout/generic/nsIFrameDebug.h @@ -115,6 +115,10 @@ public: static NS_LAYOUT void ShowFrameBorders(PRBool aEnable); static NS_LAYOUT PRBool GetShowFrameBorders(); + // Show frame border of event target + static NS_LAYOUT void ShowEventTargetFrameBorder(PRBool aEnable); + static NS_LAYOUT PRBool GetShowEventTargetFrameBorder(); + private: NS_IMETHOD_(nsrefcnt) AddRef(void) = 0; NS_IMETHOD_(nsrefcnt) Release(void) = 0; diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index a068cd83229..dda1e3fb000 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -107,6 +107,18 @@ NS_LAYOUT PRBool nsIFrameDebug::GetShowFrameBorders() return gShowFrameBorders; } +static PRBool gShowEventTargetFrameBorder = PR_FALSE; + +NS_LAYOUT void nsIFrameDebug::ShowEventTargetFrameBorder(PRBool aEnable) +{ + gShowEventTargetFrameBorder = aEnable; +} + +NS_LAYOUT PRBool nsIFrameDebug::GetShowEventTargetFrameBorder() +{ + return gShowEventTargetFrameBorder; +} + /** * Note: the log module is created during library initialization which * means that you cannot perform logging before then. diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index e8bcef5ac10..70447a02f2f 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -477,6 +477,10 @@ protected: nsIFrame* mCurrentEventFrame; nsIContent* mCurrentEventContent; nsVoidArray mCurrentEventFrameStack; +#ifdef NS_DEBUG + nsRect mCurrentTargetRect; + nsIView* mCurrentTargetView; +#endif nsCOMPtr mSelection; nsCOMPtr mCaret; @@ -618,6 +622,9 @@ PresShell::PresShell() mCurrentEventContent = nsnull; mCurrentEventFrame = nsnull; EnableScrolling(); +#ifdef NS_DEBUG + mCurrentTargetView = nsnull; +#endif mPendingReflowEvent = PR_FALSE; mDocumentIsLoading = PR_TRUE; mBatchReflows = PR_FALSE; @@ -2734,6 +2741,11 @@ PresShell::Paint(nsIView *aView, aRenderingContext.SetColor(NS_RGB(0,0,255)); aRenderingContext.DrawRect(0, 0, r.width, r.height); } + // Draw a border around the current event target + if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (aView == mCurrentTargetView)) { + aRenderingContext.SetColor(NS_RGB(128,0,128)); + aRenderingContext.DrawRect(mCurrentTargetRect.x, mCurrentTargetRect.y, mCurrentTargetRect.width, mCurrentTargetRect.height); + } #endif } @@ -2856,6 +2868,32 @@ PresShell::HandleEvent(nsIView *aView, NS_RELEASE(manager); NS_IF_RELEASE(focusContent); } +#ifdef NS_DEBUG + if ((nsIFrameDebug::GetShowEventTargetFrameBorder()) && (GetCurrentEventFrame())) { + nsIView *oldView = mCurrentTargetView; + nsPoint offset(0,0); + nsRect oldTargetRect(mCurrentTargetRect); + mCurrentEventFrame->GetRect(mCurrentTargetRect); + mCurrentEventFrame->GetView(mPresContext, &mCurrentTargetView); + if ( ! mCurrentTargetView ) { + mCurrentEventFrame->GetOffsetFromView(mPresContext, offset, &mCurrentTargetView); + } + if (mCurrentTargetView) { + mCurrentTargetRect.x = offset.x; + mCurrentTargetRect.y = offset.y; + // use aView or mCurrentTargetView?? + if ( (mCurrentTargetRect != oldTargetRect) || (mCurrentTargetView != oldView)) { + nsIViewManager *vm; + if ((NS_OK == GetViewManager(&vm)) && vm) { + vm->UpdateView(mCurrentTargetView,mCurrentTargetRect,0); + if (oldView) + vm->UpdateView(oldView,oldTargetRect,0); + NS_IF_RELEASE(vm); + } + } + } + } +#endif PopCurrentEventFrame(); } else {