From 36ce4195bc53760b3c1ed312e99c433f1e926786 Mon Sep 17 00:00:00 2001 From: "sharparrow1%yahoo.com" Date: Sun, 18 Feb 2007 04:44:21 +0000 Subject: [PATCH] Bug 370642: remove use of views in layout/inspector. r+sr=dbaron. git-svn-id: svn://10.0.0.236/trunk@220501 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsPresShell.cpp | 22 +++++++++++-- mozilla/layout/inspector/src/inFlasher.cpp | 32 ++++--------------- mozilla/layout/inspector/src/inFlasher.h | 2 -- .../layout/inspector/src/inLayoutUtils.cpp | 30 ----------------- mozilla/layout/inspector/src/inLayoutUtils.h | 12 ------- mozilla/layout/style/nsIInspectorCSSUtils.h | 8 ++--- mozilla/layout/style/nsInspectorCSSUtils.cpp | 29 ----------------- mozilla/layout/style/nsInspectorCSSUtils.h | 1 - 8 files changed, 29 insertions(+), 107 deletions(-) diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 249fba25f8c..e2d87af0f6b 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -3562,9 +3562,23 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame, } nsIWidget* widget = nsnull; - // Never pass a widget to a print rendering context - if (mPresContext->IsScreen()) - widget = aFrame->GetWindow(); + nsPoint offset(0,0); + if (mPresContext->IsScreen()) { + // Get the widget to create the rendering context for and calculate + // the offset from the frame to it. (Calculating the offset is important + // if the frame isn't the root frame.) + nsPoint viewOffset; + nsIView* view = aFrame->GetClosestView(&viewOffset); + nsPoint widgetOffset; + widget = view->GetNearestWidget(&widgetOffset); + offset = viewOffset + widgetOffset; + } else { + nsIFrame* pageFrame = nsLayoutUtils::GetPageFrame(aFrame); + // This might not always come up with a frame, i.e. during reflow; + // that's fine, because the translation doesn't matter during reflow. + if (pageFrame) + offset = aFrame->GetOffsetTo(pageFrame); + } nsresult rv; nsIRenderingContext* result = nsnull; @@ -3577,6 +3591,8 @@ PresShell::CreateRenderingContext(nsIFrame *aFrame, } *aResult = result; + result->Translate(offset.x, offset.y); + return rv; } diff --git a/mozilla/layout/inspector/src/inFlasher.cpp b/mozilla/layout/inspector/src/inFlasher.cpp index 05dddc3a9e7..b50a48ed6d8 100644 --- a/mozilla/layout/inspector/src/inFlasher.cpp +++ b/mozilla/layout/inspector/src/inFlasher.cpp @@ -40,9 +40,6 @@ #include "inLayoutUtils.h" #include "nsIServiceManager.h" -#include "nsIViewManager.h" -#include "nsIDeviceContext.h" -#include "nsIWidget.h" #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsReadableUtils.h" @@ -58,7 +55,6 @@ inFlasher::inFlasher() : mThickness(0), mInvert(PR_FALSE) { - mCSSUtils = do_GetService(kInspectorCSSUtilsCID); } inFlasher::~inFlasher() @@ -145,17 +141,7 @@ inFlasher::RepaintElement(nsIDOMElement* aElement) nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell); if (!frame) return NS_OK; - nsIFrame* parentWithView = frame->GetAncestorWithViewExternal(); - if (parentWithView) { - nsIView* view = parentWithView->GetViewExternal(); - if (view) { - nsIViewManager* viewManager = view->GetViewManager(); - if (viewManager) { - nsRect rect = parentWithView->GetRect(); - viewManager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC); - } - } - } + frame->Invalidate(frame->GetRect()); return NS_OK; } @@ -168,18 +154,14 @@ inFlasher::DrawElementOutline(nsIDOMElement* aElement) nsCOMPtr presShell = inLayoutUtils::GetPresShellFor(window); if (!presShell) return NS_OK; - PRBool isFirstFrame = PR_TRUE; - nsCOMPtr rcontext; nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement, presShell); + + PRBool isFirstFrame = PR_TRUE; + while (frame) { - if (!rcontext) { - presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext)); - } - // get view bounds in case this frame is being scrolled - nsRect rect = frame->GetRect(); - nsPoint origin = inLayoutUtils::GetClientOrigin(frame); - rect.MoveTo(origin); - mCSSUtils->AdjustRectForMargins(frame, rect); + nsCOMPtr rcontext; + presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext)); + nsRect rect(nsPoint(0,0), frame->GetSize()); if (mInvert) { rcontext->InvertRect(rect); diff --git a/mozilla/layout/inspector/src/inFlasher.h b/mozilla/layout/inspector/src/inFlasher.h index 2bf1e2f5cdc..f871f781967 100644 --- a/mozilla/layout/inspector/src/inFlasher.h +++ b/mozilla/layout/inspector/src/inFlasher.h @@ -69,8 +69,6 @@ protected: PRBool aDir, PRBool aBounds, nsIRenderingContext* aRenderContext); - nsCOMPtr mCSSUtils; - nscolor mColor; PRUint16 mThickness; diff --git a/mozilla/layout/inspector/src/inLayoutUtils.cpp b/mozilla/layout/inspector/src/inLayoutUtils.cpp index 4ea514e302e..97d500cb3c1 100644 --- a/mozilla/layout/inspector/src/inLayoutUtils.cpp +++ b/mozilla/layout/inspector/src/inLayoutUtils.cpp @@ -95,14 +95,6 @@ inLayoutUtils::GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell) return aShell->GetPrimaryFrameFor(content); } -already_AddRefed -inLayoutUtils::GetRenderingContextFor(nsIPresShell* aShell) -{ - nsCOMPtr widget; - aShell->GetViewManager()->GetWidget(getter_AddRefs(widget)); - return widget->GetRenderingContext(); // AddRefs -} - nsIEventStateManager* inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) { @@ -123,28 +115,6 @@ inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) return shell->GetPresContext()->EventStateManager(); } -nsPoint -inLayoutUtils::GetClientOrigin(nsIFrame* aFrame) -{ - nsPoint result(0,0); - nsIView* view; - aFrame->GetOffsetFromView(result, &view); - nsIView* rootView = nsnull; - if (view) { - nsIViewManager* viewManager = view->GetViewManager(); - NS_ASSERTION(viewManager, "View must have a viewmanager"); - viewManager->GetRootView(rootView); - } - while (view) { - result += view->GetPosition(); - if (view == rootView) { - break; - } - view = view->GetParent(); - } - return result; -} - nsBindingManager* inLayoutUtils::GetBindingManagerFor(nsIDOMNode* aNode) { diff --git a/mozilla/layout/inspector/src/inLayoutUtils.h b/mozilla/layout/inspector/src/inLayoutUtils.h index a9b43240426..965ab996355 100644 --- a/mozilla/layout/inspector/src/inLayoutUtils.h +++ b/mozilla/layout/inspector/src/inLayoutUtils.h @@ -55,22 +55,10 @@ public: static nsIDOMWindowInternal* GetWindowFor(nsIDOMDocument* aDoc); static nsIPresShell* GetPresShellFor(nsISupports* aThing); static nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell); - static already_AddRefed GetRenderingContextFor(nsIPresShell* aShell); static nsIEventStateManager* GetEventStateManagerFor(nsIDOMElement *aElement); static nsBindingManager* GetBindingManagerFor(nsIDOMNode* aNode); static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode); static nsIDOMNode* GetContainerFor(nsIDOMDocument* aDoc); - /** - * This function returns the offset of a frame with respect to the - * root view of the aPresContext's viewmanager (for use by - * inFlasher::DrawElementOutline and the like) - * - * @param aFrame the frame whose offset we want - * @param aPresContext the presentation context - * @return the offset - */ - static nsPoint GetClientOrigin(nsIFrame* aFrame); - }; #endif // __inLayoutUtils_h__ diff --git a/mozilla/layout/style/nsIInspectorCSSUtils.h b/mozilla/layout/style/nsIInspectorCSSUtils.h index 3663ca153e2..a0302f1783a 100644 --- a/mozilla/layout/style/nsIInspectorCSSUtils.h +++ b/mozilla/layout/style/nsIInspectorCSSUtils.h @@ -52,9 +52,10 @@ class nsIContent; class nsIDOMElement; class nsIArray; +// 35dfc2a6-b069-4014-ad4b-01927e77d828 #define NS_IINSPECTORCSSUTILS_IID \ - { 0xdf2072d2, 0x57f0, 0x4c62, \ - {0xa7, 0x3f, 0xa5, 0x2f, 0xf2, 0xf0, 0x99, 0xa6 } } + { 0x35dfc2a6, 0xb069, 0x4014, \ + {0xad, 0x4b, 0x01, 0x92, 0x7e, 0x77, 0xd8, 0x28 } } // 7ef2f07f-6e34-410b-8336-88acd1cd16b7 #define NS_INSPECTORCSSUTILS_CID \ @@ -76,9 +77,6 @@ public: NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule) = 0; NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot) = 0; - // Hooks to avoid having to use nsStyleCoord. - NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) = 0; - // Hooks to methods that need nsStyleContext NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent, nsRuleNode** aParent) = 0; diff --git a/mozilla/layout/style/nsInspectorCSSUtils.cpp b/mozilla/layout/style/nsInspectorCSSUtils.cpp index a8ba40a1f9f..892815b0c14 100644 --- a/mozilla/layout/style/nsInspectorCSSUtils.cpp +++ b/mozilla/layout/style/nsInspectorCSSUtils.cpp @@ -96,35 +96,6 @@ nsInspectorCSSUtils::IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot) return NS_OK; } -NS_IMETHODIMP -nsInspectorCSSUtils::AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect) -{ - const nsStyleMargin* margins = aFrame->GetStyleMargin(); - - // adjust coordinates for margins - nsStyleCoord coord; - if (margins->mMargin.GetTopUnit() == eStyleUnit_Coord) { - margins->mMargin.GetTop(coord); - aRect.y -= coord.GetCoordValue(); - aRect.height += coord.GetCoordValue(); - } - if (margins->mMargin.GetLeftUnit() == eStyleUnit_Coord) { - margins->mMargin.GetLeft(coord); - aRect.x -= coord.GetCoordValue(); - aRect.width += coord.GetCoordValue(); - } - if (margins->mMargin.GetRightUnit() == eStyleUnit_Coord) { - margins->mMargin.GetRight(coord); - aRect.width += coord.GetCoordValue(); - } - if (margins->mMargin.GetBottomUnit() == eStyleUnit_Coord) { - margins->mMargin.GetBottom(coord); - aRect.height += coord.GetCoordValue(); - } - - return NS_OK; -} - /* static */ nsStyleContext* nsInspectorCSSUtils::GetStyleContextForFrame(nsIFrame* aFrame) diff --git a/mozilla/layout/style/nsInspectorCSSUtils.h b/mozilla/layout/style/nsInspectorCSSUtils.h index 813132f2efd..37258bcd01a 100644 --- a/mozilla/layout/style/nsInspectorCSSUtils.h +++ b/mozilla/layout/style/nsInspectorCSSUtils.h @@ -62,7 +62,6 @@ public: NS_IMETHOD GetRuleNodeParent(nsRuleNode *aNode, nsRuleNode **aParent); NS_IMETHOD GetRuleNodeRule(nsRuleNode *aNode, nsIStyleRule **aRule); NS_IMETHOD IsRuleNodeRoot(nsRuleNode *aNode, PRBool *aIsRoot); - NS_IMETHOD AdjustRectForMargins(nsIFrame* aFrame, nsRect& aRect); NS_IMETHOD GetRuleNodeForContent(nsIContent* aContent, nsRuleNode** aRuleNode); NS_IMETHOD GetBindingURLs(nsIDOMElement *aElement, nsIArray **aResult);