diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 143ce748671..ce48912f033 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -991,6 +991,13 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, mViewManager->DisableRefresh(); mViewManager->SetWindowDimensions(width, height); + /* Setup default view manager background color */ + /* This may be overridden by the docshell with the background color for the + last document loaded into the docshell */ + nscolor bgcolor = NS_RGB(0, 0, 0); + mPresContext->GetDefaultBackgroundColor(&bgcolor); + mViewManager->SetDefaultBackgroundColor(bgcolor); + if (!makeCX) { // Make shell an observer for next time // XXX - we observe the docuement always, see above after preshell is created diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 0ec9bd742a6..cc6a7e78c69 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -3927,6 +3927,28 @@ nsDocShell::SetupNewViewer(nsIContentViewer * aNewViewer) // Stop any activity that may be happening in the old document before // releasing it... mContentViewer->Stop(); + + // Try to extract the default background color from the old + // view manager, so we can use it for the next document. + nsCOMPtr docviewer = + do_QueryInterface(mContentViewer); + + if (docviewer) { + nsCOMPtr shell; + docviewer->GetPresShell(*getter_AddRefs(shell)); + + if (shell) { + nsCOMPtr vm; + shell->GetViewManager(getter_AddRefs(vm)); + + if (vm) { + vm->GetDefaultBackgroundColor(&bgcolor); + // If the background color is not known, don't propagate it. + bgSet = NS_GET_A(bgcolor) != 0; + } + } + } + mContentViewer->Destroy(); aNewViewer->SetPreviousViewer(mContentViewer); mContentViewer = nsnull; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 143ce748671..ce48912f033 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -991,6 +991,13 @@ DocumentViewerImpl::Init(nsIWidget* aParentWidget, mViewManager->DisableRefresh(); mViewManager->SetWindowDimensions(width, height); + /* Setup default view manager background color */ + /* This may be overridden by the docshell with the background color for the + last document loaded into the docshell */ + nscolor bgcolor = NS_RGB(0, 0, 0); + mPresContext->GetDefaultBackgroundColor(&bgcolor); + mViewManager->SetDefaultBackgroundColor(bgcolor); + if (!makeCX) { // Make shell an observer for next time // XXX - we observe the docuement always, see above after preshell is created diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index e4a1878c848..b9b1c9cadff 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -4039,21 +4039,22 @@ nsFrame::IsMouseCaptured(nsIPresContext* aPresContext) void nsFrame::SetDefaultBackgroundColor(nsIPresContext* aPresContext) { - nsCOMPtr shell; - aPresContext->GetShell(getter_AddRefs(shell)); + nsStyleColor color; + mStyleContext->GetStyle(eStyleStruct_Color, color); - if (shell) { - nsCOMPtr vm; - shell->GetViewManager(getter_AddRefs(vm)); + if ((color.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) != 0) { + NS_WARNING("Frame setting default background color but it has transparent background!"); + } else { + nsCOMPtr shell; + aPresContext->GetShell(getter_AddRefs(shell)); - if (vm) { - nsStyleColor color; - mStyleContext->GetStyle(eStyleStruct_Color, color); + if (shell) { + nsCOMPtr vm; + shell->GetViewManager(getter_AddRefs(vm)); - vm->SetDefaultBackgroundColor( - (color.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) == 0 - ? color.mBackgroundColor - : NS_RGBA(0, 0, 0, 0)); + if (vm) { + vm->SetDefaultBackgroundColor(color.mBackgroundColor); + } } } } diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index e4a1878c848..b9b1c9cadff 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -4039,21 +4039,22 @@ nsFrame::IsMouseCaptured(nsIPresContext* aPresContext) void nsFrame::SetDefaultBackgroundColor(nsIPresContext* aPresContext) { - nsCOMPtr shell; - aPresContext->GetShell(getter_AddRefs(shell)); + nsStyleColor color; + mStyleContext->GetStyle(eStyleStruct_Color, color); - if (shell) { - nsCOMPtr vm; - shell->GetViewManager(getter_AddRefs(vm)); + if ((color.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) != 0) { + NS_WARNING("Frame setting default background color but it has transparent background!"); + } else { + nsCOMPtr shell; + aPresContext->GetShell(getter_AddRefs(shell)); - if (vm) { - nsStyleColor color; - mStyleContext->GetStyle(eStyleStruct_Color, color); + if (shell) { + nsCOMPtr vm; + shell->GetViewManager(getter_AddRefs(vm)); - vm->SetDefaultBackgroundColor( - (color.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) == 0 - ? color.mBackgroundColor - : NS_RGBA(0, 0, 0, 0)); + if (vm) { + vm->SetDefaultBackgroundColor(color.mBackgroundColor); + } } } } diff --git a/mozilla/layout/xul/base/src/nsBoxFrame.cpp b/mozilla/layout/xul/base/src/nsBoxFrame.cpp index 52e5152dab4..ea8e017e004 100644 --- a/mozilla/layout/xul/base/src/nsBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsBoxFrame.cpp @@ -1306,15 +1306,6 @@ nsBoxFrame::Paint(nsIPresContext* aPresContext, nsCSSRendering::PaintOutline(aPresContext, aRenderingContext, this, aDirtyRect, rect, *border, *outline, mStyleContext, 0); - // See if we need to cache the background color - nsIFrame* parent = nsnull; - GetParent(&parent); - nsIAtom* parentType = nsnull; - parent->GetFrameType(&parentType); - if (nsLayoutAtoms::rootFrame == parentType) { - SetDefaultBackgroundColor(aPresContext); - } - // The sole purpose of this is to trigger display // of the selection window for Named Anchors, // which don't have any children and normally don't diff --git a/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp b/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp index f7e0848623c..0ab03238853 100644 --- a/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsRootBoxFrame.cpp @@ -82,6 +82,12 @@ public: const nsPoint& aPoint, nsFramePaintLayer aWhichLayer, nsIFrame** aFrame); + + NS_IMETHOD Paint(nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer); + /** * Get the "type" of the frame * @@ -246,6 +252,16 @@ nsRootBoxFrame::GetFrameType(nsIAtom** aType) const return NS_OK; } +NS_IMETHODIMP +nsRootBoxFrame::Paint(nsIPresContext* aPresContext, + nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect, + nsFramePaintLayer aWhichLayer) +{ + SetDefaultBackgroundColor(aPresContext); + return nsBoxFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); +} + #ifdef DEBUG NS_IMETHODIMP nsRootBoxFrame::GetFrameName(nsString& aResult) const diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index 119ec156db8..6c6274afb83 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -964,13 +964,8 @@ void nsViewManager::DefaultRefresh(nsIView* aView, const nsRect* aRect) nscolor bgcolor = mDefaultBackgroundColor; if (NS_GET_A(mDefaultBackgroundColor) == 0) { - // If we haven't been given a default bgcolor, then use the - // widget's bgcolor. - nsCOMPtr widget; - GetWidgetForView(aView, getter_AddRefs(widget)); - - if (widget) - bgcolor = widget->GetBackgroundColor(); + NS_WARNING("nsViewManager: Asked to paint a default background, but no default background color is set!"); + return; } context->SetColor(bgcolor);