From 7137e91d6ab89a83c8148ae7e4ca41809a24053a Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Thu, 4 May 2006 03:46:19 +0000 Subject: [PATCH] Bug 130078. Test checkin of patch to unify view manager hierarchy. We need to see how this affects performance metrics. r+sr=dbaron git-svn-id: svn://10.0.0.236/trunk@195951 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/base/nsCSSRendering.cpp | 23 ++++++------ mozilla/layout/base/nsDisplayList.cpp | 21 ++++++++--- mozilla/layout/base/nsDocumentViewer.cpp | 48 ++++++++---------------- mozilla/view/public/nsIView.h | 14 +++++++ 4 files changed, 56 insertions(+), 50 deletions(-) diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 307751a5a07..842d9884c92 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2791,19 +2791,18 @@ nsCSSRendering::PaintBackground(nsPresContext* aPresContext, if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) { nsIView* rootView; vm->GetRootView(rootView); - if (!rootView->GetParent()) { - PRBool widgetIsTranslucent = PR_FALSE; + PRBool useDefaultBackgroundColor = rootView->IsUsingDefaultBackgroundColor(); + if (!rootView->GetParent() && rootView->HasWidget()) { + PRBool widgetIsTranslucent; + rootView->GetWidget()->GetWindowTranslucency(widgetIsTranslucent); + useDefaultBackgroundColor = !widgetIsTranslucent; + } - if (rootView->HasWidget()) { - rootView->GetWidget()->GetWindowTranslucency(widgetIsTranslucent); - } - - if (!widgetIsTranslucent) { - // Ensure that we always paint a color for the root (in case there's - // no background at all or a partly transparent image). - canvasColor.mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT; - canvasColor.mBackgroundColor = aPresContext->DefaultBackgroundColor(); - } + if (useDefaultBackgroundColor) { + // Ensure that we always paint a color for the root (in case there's + // no background at all or a partly transparent image). + canvasColor.mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT; + canvasColor.mBackgroundColor = aPresContext->DefaultBackgroundColor(); } } diff --git a/mozilla/layout/base/nsDisplayList.cpp b/mozilla/layout/base/nsDisplayList.cpp index b663c41d597..fa773e5fe45 100644 --- a/mozilla/layout/base/nsDisplayList.cpp +++ b/mozilla/layout/base/nsDisplayList.cpp @@ -508,14 +508,23 @@ nsDisplayBackground::IsOpaque(nsDisplayListBuilder* aBuilder) { PRBool isCanvas; const nsStyleBackground* bg; + nsPresContext* presContext = mFrame->GetPresContext(); PRBool hasBG = - nsCSSRendering::FindBackground(mFrame->GetPresContext(), mFrame, &bg, &isCanvas); - if (!hasBG || (bg->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) || - bg->mBackgroundClip != NS_STYLE_BG_CLIP_BORDER || - HasNonZeroBorderRadius(mFrame->GetStyleBorder()) || - NS_GET_A(bg->mBackgroundColor) < 255) + nsCSSRendering::FindBackground(presContext, mFrame, &bg, &isCanvas); + if (!hasBG) return PR_FALSE; - return PR_TRUE; + PRBool isTranslucentColor = NS_GET_A(bg->mBackgroundColor) < 255 || + (bg->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT); + if (isCanvas) { + nsIView* rootView; + presContext->GetViewManager()->GetRootView(rootView); + if (rootView->IsUsingDefaultBackgroundColor()) { + isTranslucentColor = NS_GET_A(presContext->DefaultBackgroundColor()) < 255; + } + } + return !isTranslucentColor && + bg->mBackgroundClip == NS_STYLE_BG_CLIP_BORDER && + !HasNonZeroBorderRadius(mFrame->GetStyleBorder()); } PRBool diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index efc59125e07..9e33244fa36 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -2294,45 +2294,29 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, tbounds.y = 0; // Create a child window of the parent that is our "root view/window" - // if aParentWidget has a view, we'll hook our view manager up to its view tree nsIView* containerView = nsView::GetViewFor(aParentWidget); - if (containerView) { - // see if the containerView has already been hooked into a foreign view manager hierarchy - // if it has, then we have to hook into the hierarchy too otherwise bad things will happen. - nsIViewManager* containerVM = containerView->GetViewManager(); - nsIView* pView = containerView; - do { - pView = pView->GetParent(); - } while (pView && pView->GetViewManager() == containerVM); - - if (!pView) { - // OK, so the container is not already hooked up into a foreign view manager hierarchy. - // That means we can choose not to hook ourselves up. - // - // If the parent container is a chrome shell then we won't hook into its view - // tree. This will improve performance a little bit (especially given scrolling/painting perf bugs) - // but is really just for peace of mind. This check can be removed if we want to support fancy - // chrome effects like transparent controls floating over content, transparent Web browsers, and - // things like that, and the perf bugs are fixed. - nsCOMPtr container(do_QueryReferent(mContainer)); - nsCOMPtr parentContainer; - PRInt32 itemType; - if (nsnull == container - || NS_FAILED(container->GetParent(getter_AddRefs(parentContainer))) - || nsnull == parentContainer - || NS_FAILED(parentContainer->GetItemType(&itemType)) - || itemType != nsIDocShellTreeItem::typeContent) { - containerView = nsnull; - } - } - } - // Create a view nsIView* view = mViewManager->CreateView(tbounds, containerView); if (!view) return NS_ERROR_OUT_OF_MEMORY; + if (containerView) { + nsCOMPtr container(do_QueryReferent(mContainer)); + nsCOMPtr parentContainer; + PRInt32 itemType; + PRInt32 parentItemType; + if (container + && NS_SUCCEEDED(container->GetItemType(&itemType)) + && itemType == nsIDocShellTreeItem::typeContent + && NS_SUCCEEDED(container->GetParent(getter_AddRefs(parentContainer))) + && parentContainer + && NS_SUCCEEDED(parentContainer->GetItemType(&parentItemType)) + && parentItemType != nsIDocShellTreeItem::typeContent) { + view->SetUseDefaultBackgroundColor(PR_TRUE); + } + } + // pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone. // otherwise the view will find its own parent widget and "do the right thing" to // establish a parent/child widget relationship diff --git a/mozilla/view/public/nsIView.h b/mozilla/view/public/nsIView.h index f86ddf72276..1a5673fc4ac 100644 --- a/mozilla/view/public/nsIView.h +++ b/mozilla/view/public/nsIView.h @@ -90,6 +90,8 @@ enum nsViewVisibility { // is z-index:auto also #define NS_VIEW_FLAG_TOPMOST 0x0010 +#define NS_VIEW_FLAG_USE_DEFAULT_BACKGROUND 0x0020 + struct nsViewZIndex { PRBool mIsAuto; PRInt32 mZIndex; @@ -282,7 +284,19 @@ public: PRBool HasUniformBackground() { return mVFlags & NS_VIEW_FLAG_UNIFORM_BACKGROUND; } + + void SetUseDefaultBackgroundColor(PRBool aUseDefault) { + if (aUseDefault) { + mVFlags |= NS_VIEW_FLAG_USE_DEFAULT_BACKGROUND; + } else { + mVFlags &= ~NS_VIEW_FLAG_USE_DEFAULT_BACKGROUND; + } + } + PRBool IsUsingDefaultBackgroundColor() { + return mVFlags & NS_VIEW_FLAG_USE_DEFAULT_BACKGROUND; + } + /** * Set the view's link to client owned data. * @param aData - data to associate with view. nsnull to disassociate