diff --git a/mozilla/accessible/src/base/nsCaretAccessible.cpp b/mozilla/accessible/src/base/nsCaretAccessible.cpp index 6f4a3903551..92f1e546bab 100644 --- a/mozilla/accessible/src/base/nsCaretAccessible.cpp +++ b/mozilla/accessible/src/base/nsCaretAccessible.cpp @@ -165,7 +165,11 @@ NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument *aDoc, ns nsIViewManager* viewManager = presShell->GetViewManager(); if (!presContext || !viewManager) return NS_OK; - nsIWidget* widget = viewManager->RootView()->GetWidget(); + nsIView *view = nsnull; + viewManager->GetRootView(view); + if (!view) + return NS_OK; + nsIWidget* widget = view->GetWidget(); if (!widget) return NS_OK; diff --git a/mozilla/accessible/src/base/nsDocAccessible.cpp b/mozilla/accessible/src/base/nsDocAccessible.cpp index db8f854d09d..ea46ccb1758 100644 --- a/mozilla/accessible/src/base/nsDocAccessible.cpp +++ b/mozilla/accessible/src/base/nsDocAccessible.cpp @@ -421,7 +421,11 @@ void nsDocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame) } } else { - viewBounds = vm->RootView()->GetBounds(); + nsIView *view; + vm->GetRootView(view); + if (view) { + viewBounds = view->GetBounds(); + } } if (parentDoc) { // After first time thru loop diff --git a/mozilla/content/base/src/nsContentSink.cpp b/mozilla/content/base/src/nsContentSink.cpp index d14f8721320..f26de3e29a1 100644 --- a/mozilla/content/base/src/nsContentSink.cpp +++ b/mozilla/content/base/src/nsContentSink.cpp @@ -978,4 +978,22 @@ nsContentSink::StartLayout(PRBool aIsFrameset) mRef = Substring(start, end); } } + + if (!mRef.IsEmpty() || aIsFrameset) { + // Disable the scroll bars. + for (i = 0; i < ns; i++) { + nsIPresShell *shell = mDocument->GetShellAt(i); + + nsIViewManager* vm = shell->GetViewManager(); + if (vm) { + nsIView* rootView = nsnull; + vm->GetRootView(rootView); + nsCOMPtr sview(do_QueryInterface(rootView)); + + if (sview) { + sview->SetScrollPreference(nsScrollPreference_kNeverScroll); + } + } + } + } } diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index 716dddbb699..243b8195441 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -456,6 +456,7 @@ protected: // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); //------------------------------------------------------------------ nsresult @@ -1652,7 +1653,11 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* view; + mViewManager->GetRootView(view); // views are not refCounted + if (view) { + mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); + } } else { mViewManager->DisableRefresh(); @@ -1839,6 +1844,12 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, p2t = mPresContext->PixelsToTwips(); tbounds *= p2t; + // Initialize the view manager with an offset. This allows the viewmanager + // to manage a coordinate space offset from (0,0) + rv = mViewManager->Init(dx); + if (NS_FAILED(rv)) + return rv; + // Reset the bounds offset so the root view is set to 0,0. The // offset is specified in nsIViewManager::Init above. // Besides, layout will reset the root view to (0,0) during reflow, @@ -1850,6 +1861,11 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, // Create a child window of the parent that is our "root view/window" // Create a view + nsIView *view = nsnull; + rv = CallCreateInstance(kViewCID, &view); + if (NS_FAILED(rv)) + return rv; + // if aParentWidget has a view, we'll hook our view manager up to its view tree void* clientData; nsIView* containerView = nsnull; @@ -1892,13 +1908,10 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = mViewManager->Init(dx, containerView); + rv = view->Init(mViewManager, tbounds, containerView); if (NS_FAILED(rv)) return rv; - nsIView* view = mViewManager->RootView(); - mViewManager->ResizeView(view, tbounds); - nsCOMPtr treeItem(do_QueryInterface(mContainer)); NS_ENSURE_TRUE(treeItem, NS_ERROR_FAILURE); PRInt32 itemType; @@ -1922,6 +1935,9 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; + // Setup hierarchical relationship in view manager + mViewManager->SetRootView(view); + mWindow = view->GetWidget(); // This SetFocus is necessary so the Arrow Key and Page Key events diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index 0d795b8f3b6..b70db4602df 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -234,6 +234,7 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,nsIDeviceContext * aD // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); @@ -2609,7 +2610,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = aPO->mViewManager->Init(mPrt->mPrintDocDC, nsnull); + rv = aPO->mViewManager->Init(mPrt->mPrintDocDC); if (NS_FAILED(rv)) { delete aPO->mStyleSet; return rv; @@ -2658,8 +2659,12 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) nsRect tbounds = nsRect(0, 0, width, height); - aPO->mRootView = aPO->mViewManager->RootView(); - rv = aPO->mViewManager->ResizeView(aPO->mRootView, tbounds); + // Create a child window of the parent that is our "root view/window" + rv = CallCreateInstance(kViewCID, &aPO->mRootView); + if (NS_FAILED(rv)) { + return rv; + } + rv = (aPO->mRootView)->Init(aPO->mViewManager, tbounds, nsnull); if (NS_FAILED(rv)) { return rv; } @@ -2703,6 +2708,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) #endif // NS_PRINT_PREVIEW // Setup hierarchical relationship in view manager + aPO->mViewManager->SetRootView(aPO->mRootView); aPO->mPresShell->Init(aPO->mDocument, aPO->mPresContext, aPO->mViewManager, aPO->mStyleSet, mPresContext->CompatibilityMode()); @@ -4747,7 +4753,11 @@ DumpViews(nsIDocShell* aDocShell, FILE* out) if (shell) { nsIViewManager* vm = shell->GetViewManager(); if (vm) { - vm->RootView()->List(out); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + root->List(out); + } } } else { diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index ddb307e5061..6de02ebb159 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1603,7 +1603,11 @@ nsDocShell::SetZoom(float zoom) if (scrollableView) scrollableView->ComputeScrollOffsets(); - vm->UpdateView(vm->RootView(), 0); + // get the root view + nsIView *rootView = nsnull; // views are not ref counted + vm->GetRootView(rootView); + if (rootView) + vm->UpdateView(rootView, 0); return NS_OK; } @@ -3280,8 +3284,13 @@ nsDocShell::GetVisibility(PRBool * aVisibility) nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); + // get the root view + nsIView *view = nsnull; // views are not ref counted + NS_ENSURE_SUCCESS(vm->GetRootView(view), NS_ERROR_FAILURE); + NS_ENSURE_TRUE(view, NS_ERROR_FAILURE); + // if our root view is hidden, we are not visible - if (vm->RootView()->GetVisibility() == nsViewVisibility_kHide) { + if (view->GetVisibility() == nsViewVisibility_kHide) { *aVisibility = PR_FALSE; return NS_OK; } diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index a1d454c03d2..cdbf883118f 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -4279,6 +4279,29 @@ GlobalWindowImpl::GetObjectProperty(const PRUnichar *aProperty, nsresult GlobalWindowImpl::Activate() { +/* + nsCOMPtr treeOwnerAsWin; + GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); + if(treeOwnerAsWin) + treeOwnerAsWin->SetVisibility(PR_TRUE); + + nsCOMPtr presShell; + mDocShell->GetPresShell(getter_AddRefs(presShell)); + NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); + + nsIViewManager* vm = presShell->GetViewManager(); + NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); + + nsIView* rootView; + vm->GetRootView(rootView); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + + nsIWidget* widget = rootView->GetWidget(); + NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); + + return widget->SetFocus(); + + */ nsCOMPtr treeOwnerAsWin; GetTreeOwner(getter_AddRefs(treeOwnerAsWin)); if (treeOwnerAsWin) { @@ -4301,7 +4324,9 @@ GlobalWindowImpl::Activate() nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView = vm->RootView(); + nsIView *rootView; + vm->GetRootView(rootView); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); // We're holding a STRONG REF to the widget to ensure it doesn't go away // during event processing @@ -4328,7 +4353,9 @@ GlobalWindowImpl::Deactivate() nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView = vm->RootView(); + nsIView *rootView; + vm->GetRootView(rootView); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); // Hold a STRONG REF to keep the widget around during event processing nsCOMPtr widget = rootView->GetWidget(); @@ -5669,7 +5696,9 @@ nsGlobalChromeWindow::SetCursor(const nsAString& aCursor) nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView = vm->RootView(); + nsIView *rootView; + vm->GetRootView(rootView); + NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); nsIWidget* widget = rootView->GetWidget(); NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE); diff --git a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp index 77eaf271cff..dbf668b7abb 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -1047,7 +1047,11 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) // begin hack repaint nsIViewManager* viewmgr = ps->GetViewManager(); if (viewmgr) { - viewmgr->UpdateView(viewmgr->RootView(),NS_VMREFRESH_IMMEDIATE); + nsIView* view; + viewmgr->GetRootView(view); // views are not refCounted + if (view) { + viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE); + } } // end hack repaint #else @@ -1106,7 +1110,11 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) nsIViewManager* viewmgr = ps->GetViewManager(); if (viewmgr) { - viewmgr->UpdateView(viewmgr->RootView(),NS_VMREFRESH_IMMEDIATE); + nsIView* view; + viewmgr->GetRootView(view); // views are not refCounted + if (view) { + viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE); + } } // end hack repaint #else diff --git a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp index 2dd365a5bfa..5eb0c351c9b 100644 --- a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp @@ -139,9 +139,15 @@ inLayoutUtils::GetClientOrigin(nsIPresContext* aPresContext, nsPoint result(0,0); nsIView* view; aFrame->GetOffsetFromView(aPresContext, 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->ExternalIsRoot()) { + if (view == rootView) { break; } view = view->GetParent(); diff --git a/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp b/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp index 4286e5789c9..3393b23e885 100644 --- a/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp +++ b/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp @@ -473,7 +473,11 @@ DumpViewsRecur(nsIDocShell* aDocShell, FILE* out) fprintf(out, "docshell=%p \n", NS_STATIC_CAST(void*, aDocShell)); nsCOMPtr vm(view_manager(aDocShell)); if (vm) { - vm->RootView()->List(out); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + root->List(out); + } } else { fputs("null view manager\n", out); @@ -560,7 +564,11 @@ void nsLayoutDebuggingTools::ForceRefresh() nsCOMPtr vm(view_manager(mDocShell)); if (!vm) return; - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* root = nsnull; + vm->GetRootView(root); + if (root) { + vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); + } } nsresult diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index c4c6f9c29ad..70dbc7381e5 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -326,7 +326,10 @@ nsresult NS_NewScrollPortFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewGfxScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); +NS_NewHTMLScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); + +nsresult +NS_NewXULScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); nsresult NS_NewSliderFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -3652,8 +3655,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // Bind the viewport frame to the root view nsIViewManager* viewManager = aPresContext->GetViewManager(); - nsIView* rootView = viewManager->RootView(); + nsIView* rootView; + viewManager->GetRootView(rootView); viewportFrame->SetView(rootView); nsContainerFrame::SyncFrameViewProperties(aPresContext, viewportFrame, @@ -3796,7 +3800,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, viewportPseudoStyle); // Note that the viewport scrollframe is always built with - // overflow:auto style. This forces nsGfxScrollFrame to create + // overflow:auto style. This forces the scroll frame to create // anonymous content for both scrollbars. This is necessary even // if the HTML or BODY elements are overriding the viewport // scroll style to 'hidden' --- dynamic style changes might put @@ -4975,7 +4979,7 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell // would be inefficient. // nsGenericElement::SetDocument ought to keep a list like this one, - // but it can't because nsGfxScrollFrames get around this. + // but it can't because scroll frames get around this. if (!aIsRoot && aTag != nsHTMLAtoms::input && aTag != nsHTMLAtoms::textarea && @@ -5797,7 +5801,15 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh nsRefPtr contentStyle = aContentStyle; if (!gfxScrollFrame) { - NS_NewGfxScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + nsCOMPtr box = do_QueryInterface(aParentFrame); + + // Build a XULScrollFrame when the parent is a box, because XULScrollFrames + // do box layout well. Otherwise build an HTMLScrollFrame. + if (box) { + NS_NewXULScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + } else { + NS_NewHTMLScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + } InitAndRestoreFrame(aPresContext, aState, aContent, aParentFrame, contentStyle, nsnull, gfxScrollFrame); @@ -6012,7 +6024,7 @@ nsCSSFrameConstructor::InitGfxScrollFrame(nsIPresShell* aPresShell, aAnonymousFrames.AddChild(aScrollPortFrame); - // if there are any anonymous children for the nsGfxScrollFrame create frames for them. + // if there are any anonymous children for the scroll frame, create frames for them. CreateAnonymousFrames(aPresShell, aPresContext, aState, aContent, aDocument, aNewFrame, PR_FALSE, aAnonymousFrames); @@ -7321,7 +7333,7 @@ nsCSSFrameConstructor::GetFrameFor(nsIPresShell* aPresShell, // Check to see if the content is a select and // then if it has a drop down (thus making it a combobox) // The drop down is a ListControlFrame derived from a - // nsGfxScrollFrame then get the area frame and that will be the parent + // nsHTMLScrollFrame then get the area frame and that will be the parent // What is unclear here, is if any of this fails, should it return // the nsComboboxControlFrame or null? nsCOMPtr selectElement; diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 4528b2ee95c..7f2cb5aa1f5 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2754,7 +2754,8 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, nsIViewManager* vm = aPresContext->GetViewManager(); if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) { - nsIView* rootView = vm->RootView(); + nsIView* rootView; + vm->GetRootView(rootView); if (!rootView->GetParent()) { PRBool widgetIsTranslucent = PR_FALSE; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 716dddbb699..243b8195441 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -456,6 +456,7 @@ protected: // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); //------------------------------------------------------------------ nsresult @@ -1652,7 +1653,11 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* view; + mViewManager->GetRootView(view); // views are not refCounted + if (view) { + mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); + } } else { mViewManager->DisableRefresh(); @@ -1839,6 +1844,12 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, p2t = mPresContext->PixelsToTwips(); tbounds *= p2t; + // Initialize the view manager with an offset. This allows the viewmanager + // to manage a coordinate space offset from (0,0) + rv = mViewManager->Init(dx); + if (NS_FAILED(rv)) + return rv; + // Reset the bounds offset so the root view is set to 0,0. The // offset is specified in nsIViewManager::Init above. // Besides, layout will reset the root view to (0,0) during reflow, @@ -1850,6 +1861,11 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, // Create a child window of the parent that is our "root view/window" // Create a view + nsIView *view = nsnull; + rv = CallCreateInstance(kViewCID, &view); + if (NS_FAILED(rv)) + return rv; + // if aParentWidget has a view, we'll hook our view manager up to its view tree void* clientData; nsIView* containerView = nsnull; @@ -1892,13 +1908,10 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = mViewManager->Init(dx, containerView); + rv = view->Init(mViewManager, tbounds, containerView); if (NS_FAILED(rv)) return rv; - nsIView* view = mViewManager->RootView(); - mViewManager->ResizeView(view, tbounds); - nsCOMPtr treeItem(do_QueryInterface(mContainer)); NS_ENSURE_TRUE(treeItem, NS_ERROR_FAILURE); PRInt32 itemType; @@ -1922,6 +1935,9 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; + // Setup hierarchical relationship in view manager + mViewManager->SetRootView(view); + mWindow = view->GetWidget(); // This SetFocus is necessary so the Arrow Key and Page Key events diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 140cfa0484a..063832d34c2 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -208,6 +208,7 @@ static void ColorToString(nscolor aColor, nsAutoString &aString); // Class ID's static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); #undef NOISY @@ -5804,7 +5805,9 @@ PresShell::HandleEvent(nsIView *aView, // from the root views widget. This is necessary to prevent us from // dispatching the SysColorChanged notification for each child window // which may be redundant. - if (aView->IsRoot()) { + nsIView *view; + vm->GetRootView(view); + if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged(); @@ -6431,7 +6434,9 @@ PresShell::ProcessReflowCommands(PRBool aInterruptible) if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can // see it. - mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* rootView; + mViewManager->GetRootView(rootView); + mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); mInVerifyReflow = PR_TRUE; PRBool ok = VerifyIncrementalReflow(); @@ -7018,28 +7023,44 @@ PresShell::VerifyIncrementalReflow() rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); - void* nativeParentWidget = mViewManager->RootView()->GetWidget() - ->GetNativeData(NS_NATIVE_WIDGET); + // Get our scrolling preference + nsScrollPreference scrolling; + nsIView* rootView; + mViewManager->GetRootView(rootView); + nsIScrollableView* scrollView; + rv = rootView->QueryInterface(NS_GET_IID(nsIScrollableView), + (void**)&scrollView); + if (NS_SUCCEEDED (rv)) { + scrollView->GetScrollPreference(scrolling); + } + void* nativeParentWidget = rootView->GetWidget()->GetNativeData(NS_NATIVE_WIDGET); // Create a new view manager. rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager), (void**) &vm); NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create view manager"); - rv = vm->Init(dc, nsnull); + rv = vm->Init(dc); NS_ASSERTION(NS_SUCCEEDED (rv), "failed to init view manager"); // Create a child window of the parent that is our "root view/window" // Create a view nsRect tbounds = mPresContext->GetVisibleArea(); + nsIView* view; + rv = nsComponentManager::CreateInstance(kViewCID, nsnull, + NS_GET_IID(nsIView), + (void **) &view); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view"); - rv = vm->ResizeView(vm->RootView(), tbounds); + rv = view->Init(vm, tbounds, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); //now create the widget for the view - rv = vm->RootView()->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); + rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view widget"); + // Setup hierarchical relationship in view manager + vm->SetRootView(view); + // Make the new presentation context the same size as our // presentation context. nsRect r = mPresContext->GetVisibleArea(); diff --git a/mozilla/layout/generic/nsContainerFrame.cpp b/mozilla/layout/generic/nsContainerFrame.cpp index fc3b30bc901..0bb569b58c9 100644 --- a/mozilla/layout/generic/nsContainerFrame.cpp +++ b/mozilla/layout/generic/nsContainerFrame.cpp @@ -601,7 +601,8 @@ SyncFrameViewGeometryDependentProperties(nsIPresContext* aPresContext, aView->SetHasUniformBackground(drawnOnUniformField); if (isCanvas) { - nsIView* rootView = vm->RootView(); + nsIView* rootView; + vm->GetRootView(rootView); nsIView* rootParent = rootView->GetParent(); if (!rootParent) { // We're the root of a view manager hierarchy. We will have to diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 92336f4b397..ab2c3e810cb 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -1512,7 +1512,11 @@ nsHTMLFramesetFrame::MouseDrag(nsIPresContext* aPresContext, // Update the view immediately (make drag appear snappier) nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* root; + vm->GetRootView(root); + if (root) { + vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); + } } } } diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 2166b6e66ae..3302a500f6e 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -1770,7 +1770,10 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // first, lets find out how big the window is, in pixels nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIWidget* win = vm->RootView()->GetWidget(); + nsIView* view; + vm->GetRootView(view); + if (view) { + nsIWidget* win = view->GetWidget(); if (win) { nsRect visibleRect; win->GetBounds(visibleRect); @@ -1803,6 +1806,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } } } + } #endif inst->SetWindow(window); diff --git a/mozilla/layout/html/base/src/nsContainerFrame.cpp b/mozilla/layout/html/base/src/nsContainerFrame.cpp index fc3b30bc901..0bb569b58c9 100644 --- a/mozilla/layout/html/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsContainerFrame.cpp @@ -601,7 +601,8 @@ SyncFrameViewGeometryDependentProperties(nsIPresContext* aPresContext, aView->SetHasUniformBackground(drawnOnUniformField); if (isCanvas) { - nsIView* rootView = vm->RootView(); + nsIView* rootView; + vm->GetRootView(rootView); nsIView* rootParent = rootView->GetParent(); if (!rootParent) { // We're the root of a view manager hierarchy. We will have to diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 2166b6e66ae..3302a500f6e 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -1770,7 +1770,10 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // first, lets find out how big the window is, in pixels nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIWidget* win = vm->RootView()->GetWidget(); + nsIView* view; + vm->GetRootView(view); + if (view) { + nsIWidget* win = view->GetWidget(); if (win) { nsRect visibleRect; win->GetBounds(visibleRect); @@ -1803,6 +1806,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, } } } + } #endif inst->SetWindow(window); diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 140cfa0484a..063832d34c2 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -208,6 +208,7 @@ static void ColorToString(nscolor aColor, nsAutoString &aString); // Class ID's static NS_DEFINE_CID(kFrameSelectionCID, NS_FRAMESELECTION_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); #undef NOISY @@ -5804,7 +5805,9 @@ PresShell::HandleEvent(nsIView *aView, // from the root views widget. This is necessary to prevent us from // dispatching the SysColorChanged notification for each child window // which may be redundant. - if (aView->IsRoot()) { + nsIView *view; + vm->GetRootView(view); + if (view == aView) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged(); @@ -6431,7 +6434,9 @@ PresShell::ProcessReflowCommands(PRBool aInterruptible) if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can // see it. - mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* rootView; + mViewManager->GetRootView(rootView); + mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); mInVerifyReflow = PR_TRUE; PRBool ok = VerifyIncrementalReflow(); @@ -7018,28 +7023,44 @@ PresShell::VerifyIncrementalReflow() rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); - void* nativeParentWidget = mViewManager->RootView()->GetWidget() - ->GetNativeData(NS_NATIVE_WIDGET); + // Get our scrolling preference + nsScrollPreference scrolling; + nsIView* rootView; + mViewManager->GetRootView(rootView); + nsIScrollableView* scrollView; + rv = rootView->QueryInterface(NS_GET_IID(nsIScrollableView), + (void**)&scrollView); + if (NS_SUCCEEDED (rv)) { + scrollView->GetScrollPreference(scrolling); + } + void* nativeParentWidget = rootView->GetWidget()->GetNativeData(NS_NATIVE_WIDGET); // Create a new view manager. rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager), (void**) &vm); NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create view manager"); - rv = vm->Init(dc, nsnull); + rv = vm->Init(dc); NS_ASSERTION(NS_SUCCEEDED (rv), "failed to init view manager"); // Create a child window of the parent that is our "root view/window" // Create a view nsRect tbounds = mPresContext->GetVisibleArea(); + nsIView* view; + rv = nsComponentManager::CreateInstance(kViewCID, nsnull, + NS_GET_IID(nsIView), + (void **) &view); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view"); - rv = vm->ResizeView(vm->RootView(), tbounds); + rv = view->Init(vm, tbounds, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); //now create the widget for the view - rv = vm->RootView()->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); + rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view widget"); + // Setup hierarchical relationship in view manager + vm->SetRootView(view); + // Make the new presentation context the same size as our // presentation context. nsRect r = mPresContext->GetVisibleArea(); diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp index 92336f4b397..ab2c3e810cb 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp @@ -1512,7 +1512,11 @@ nsHTMLFramesetFrame::MouseDrag(nsIPresContext* aPresContext, // Update the view immediately (make drag appear snappier) nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* root; + vm->GetRootView(root); + if (root) { + vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); + } } } } diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index c4c6f9c29ad..70dbc7381e5 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -326,7 +326,10 @@ nsresult NS_NewScrollPortFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); nsresult -NS_NewGfxScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); +NS_NewHTMLScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); + +nsresult +NS_NewXULScrollFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRBool aIsRoot); nsresult NS_NewSliderFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame ); @@ -3652,8 +3655,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // Bind the viewport frame to the root view nsIViewManager* viewManager = aPresContext->GetViewManager(); - nsIView* rootView = viewManager->RootView(); + nsIView* rootView; + viewManager->GetRootView(rootView); viewportFrame->SetView(rootView); nsContainerFrame::SyncFrameViewProperties(aPresContext, viewportFrame, @@ -3796,7 +3800,7 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, viewportPseudoStyle); // Note that the viewport scrollframe is always built with - // overflow:auto style. This forces nsGfxScrollFrame to create + // overflow:auto style. This forces the scroll frame to create // anonymous content for both scrollbars. This is necessary even // if the HTML or BODY elements are overriding the viewport // scroll style to 'hidden' --- dynamic style changes might put @@ -4975,7 +4979,7 @@ nsCSSFrameConstructor::CreateAnonymousFrames(nsIPresShell* aPresShell // would be inefficient. // nsGenericElement::SetDocument ought to keep a list like this one, - // but it can't because nsGfxScrollFrames get around this. + // but it can't because scroll frames get around this. if (!aIsRoot && aTag != nsHTMLAtoms::input && aTag != nsHTMLAtoms::textarea && @@ -5797,7 +5801,15 @@ nsCSSFrameConstructor::BeginBuildingScrollFrame(nsIPresShell* aPresSh nsRefPtr contentStyle = aContentStyle; if (!gfxScrollFrame) { - NS_NewGfxScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + nsCOMPtr box = do_QueryInterface(aParentFrame); + + // Build a XULScrollFrame when the parent is a box, because XULScrollFrames + // do box layout well. Otherwise build an HTMLScrollFrame. + if (box) { + NS_NewXULScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + } else { + NS_NewHTMLScrollFrame(aPresShell, &gfxScrollFrame, aIsRoot); + } InitAndRestoreFrame(aPresContext, aState, aContent, aParentFrame, contentStyle, nsnull, gfxScrollFrame); @@ -6012,7 +6024,7 @@ nsCSSFrameConstructor::InitGfxScrollFrame(nsIPresShell* aPresShell, aAnonymousFrames.AddChild(aScrollPortFrame); - // if there are any anonymous children for the nsGfxScrollFrame create frames for them. + // if there are any anonymous children for the scroll frame, create frames for them. CreateAnonymousFrames(aPresShell, aPresContext, aState, aContent, aDocument, aNewFrame, PR_FALSE, aAnonymousFrames); @@ -7321,7 +7333,7 @@ nsCSSFrameConstructor::GetFrameFor(nsIPresShell* aPresShell, // Check to see if the content is a select and // then if it has a drop down (thus making it a combobox) // The drop down is a ListControlFrame derived from a - // nsGfxScrollFrame then get the area frame and that will be the parent + // nsHTMLScrollFrame then get the area frame and that will be the parent // What is unclear here, is if any of this fails, should it return // the nsComboboxControlFrame or null? nsCOMPtr selectElement; diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index 4528b2ee95c..7f2cb5aa1f5 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -2754,7 +2754,8 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, nsIViewManager* vm = aPresContext->GetViewManager(); if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) { - nsIView* rootView = vm->RootView(); + nsIView* rootView; + vm->GetRootView(rootView); if (!rootView->GetParent()) { PRBool widgetIsTranslucent = PR_FALSE; diff --git a/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp b/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp index 4ba28485c06..edbccbdd5fa 100644 --- a/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp +++ b/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp @@ -478,9 +478,17 @@ GeometryTest::GeometryTest(BasicTest *aDoc) fprintf(out, "bad view manager"); NS_ASSERTION(PR_FALSE, "bad view manager"); } - vm->Init(pc, nsnull); + vm->Init(pc); - nsIView * rootView = vm->GetRootView(); + nsIView * rootView = nsnull; + + // Create a view + static NS_DEFINE_IID(kScrollingViewCID, NS_SCROLL_PORT_VIEW_CID); + + status = nsComponentManager::CreateInstance(kScrollingViewCID, + nsnull, + NS_GET_IID(nsIView), + (void **)&rootView); if ((NS_FAILED(status)) || nsnull==rootView) { @@ -488,7 +496,9 @@ GeometryTest::GeometryTest(BasicTest *aDoc) NS_ASSERTION(PR_FALSE, "bad view"); } nsRect bounds(0, 0, 10000, 10000); - vm->ResizeView(rootView, bounds); + rootView->Init(vm, bounds, nsnull); + + vm->SetRootView(rootView); nsCOMPtr ss(do_CreateInstance(kStyleSetCID,&status)); if ((NS_FAILED(status))) @@ -556,7 +566,7 @@ void GeometryTest::CreateGeometry(BasicTest * aDoc, nsIPresContext *aPC) fprintf(out, "bad view manager"); NS_ASSERTION(PR_FALSE, ""); } - nsIView* rootView = mViewManager->RootView(); + nsIView* rootView = mViewManager->GetRootView(); NS_ASSERTION(nsnull!=rootView, "bad root view"); mRootFrame->SetView(rootView); NS_RELEASE(rootView); diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 0d795b8f3b6..b70db4602df 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -234,6 +234,7 @@ static void DumpPrintObjectsTreeLayout(nsPrintObject * aPO,nsIDeviceContext * aD // Class IDs static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); +static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); @@ -2609,7 +2610,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = aPO->mViewManager->Init(mPrt->mPrintDocDC, nsnull); + rv = aPO->mViewManager->Init(mPrt->mPrintDocDC); if (NS_FAILED(rv)) { delete aPO->mStyleSet; return rv; @@ -2658,8 +2659,12 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) nsRect tbounds = nsRect(0, 0, width, height); - aPO->mRootView = aPO->mViewManager->RootView(); - rv = aPO->mViewManager->ResizeView(aPO->mRootView, tbounds); + // Create a child window of the parent that is our "root view/window" + rv = CallCreateInstance(kViewCID, &aPO->mRootView); + if (NS_FAILED(rv)) { + return rv; + } + rv = (aPO->mRootView)->Init(aPO->mViewManager, tbounds, nsnull); if (NS_FAILED(rv)) { return rv; } @@ -2703,6 +2708,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) #endif // NS_PRINT_PREVIEW // Setup hierarchical relationship in view manager + aPO->mViewManager->SetRootView(aPO->mRootView); aPO->mPresShell->Init(aPO->mDocument, aPO->mPresContext, aPO->mViewManager, aPO->mStyleSet, mPresContext->CompatibilityMode()); @@ -4747,7 +4753,11 @@ DumpViews(nsIDocShell* aDocShell, FILE* out) if (shell) { nsIViewManager* vm = shell->GetViewManager(); if (vm) { - vm->RootView()->List(out); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + root->List(out); + } } } else { diff --git a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp index a7c496fcbca..2e305f08ff3 100644 --- a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -190,7 +190,8 @@ nsMenuPopupFrame::Init(nsIPresContext* aPresContext, viewManager->RemoveChild(ourView); // Reinsert ourselves as the root view with a maximum z-index. - nsIView* rootView = viewManager->RootView(); + nsIView* rootView; + viewManager->GetRootView(rootView); viewManager->SetViewZIndex(ourView, PR_FALSE, kMaxZ); viewManager->InsertChild(rootView, ourView, nsnull, PR_TRUE); @@ -414,7 +415,8 @@ nsMenuPopupFrame::GetViewOffset(nsIView* aView, nsPoint& aPoint) aPoint.y = 0; // Keep track of the root view so that we know to stop there - nsIView* rootView = aView->GetViewManager()->RootView(); + nsIView* rootView; + aView->GetViewManager()->GetRootView(rootView); nsIView *parent; @@ -488,7 +490,7 @@ nsMenuPopupFrame::GetRootViewForPopup(nsIPresContext* aPresContext, if (view) { nsIView* rootView = nsnull; if (aStopAtViewManagerRoot) { - rootView = view->GetViewManager()->RootView(); + view->GetViewManager()->GetRootView(rootView); } while (view) { @@ -559,7 +561,9 @@ nsMenuPopupFrame::AdjustClientXYForNestedDocuments ( nsIDOMXULDocument* inPopupD nsIWidget* popupDocumentWidget = nsnull; nsIViewManager* viewManager = inPopupShell->GetViewManager(); if ( viewManager ) { - nsIView* rootView = viewManager->RootView(); + nsIView* rootView; + viewManager->GetRootView(rootView); + if ( rootView ) popupDocumentWidget = rootView->GetNearestWidget(nsnull); } NS_WARN_IF_FALSE(popupDocumentWidget, "ACK, BAD WIDGET"); @@ -601,8 +605,11 @@ nsMenuPopupFrame::AdjustClientXYForNestedDocuments ( nsIDOMXULDocument* inPopupD // widget. nsIViewManager* viewManagerTarget = shell->GetViewManager(); if ( viewManagerTarget ) { - nsIView* rootViewTarget = viewManagerTarget->RootView(); + nsIView* rootViewTarget; + viewManagerTarget->GetRootView(rootViewTarget); + if ( rootViewTarget ) { targetDocumentWidget = rootViewTarget->GetNearestWidget(nsnull); + } } } } diff --git a/mozilla/view/public/nsIView.h b/mozilla/view/public/nsIView.h index e51bc9aa83a..416c2daa3a0 100644 --- a/mozilla/view/public/nsIView.h +++ b/mozilla/view/public/nsIView.h @@ -183,8 +183,10 @@ public: * * The view destroys its child views, and destroys and releases its * widget (if it has one). + * * Also informs the view manager that the view is destroyed by calling - * RemoveChild() if the view is not the root view. + * SetRootView(NULL) if the view is the root view and calling RemoveChild() + * otherwise. */ void Destroy(); diff --git a/mozilla/view/public/nsIViewManager.h b/mozilla/view/public/nsIViewManager.h index 143fc2924af..a796d708c84 100644 --- a/mozilla/view/public/nsIViewManager.h +++ b/mozilla/view/public/nsIViewManager.h @@ -50,7 +50,6 @@ struct nsRect; class nsRegion; class nsIDeviceContext; class nsIViewObserver; -class nsView; enum nsRectVisibility { nsRectVisibility_kVisible, @@ -71,20 +70,35 @@ class nsIViewManager : public nsISupports public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IVIEWMANAGER_IID) - /** * Initialize the ViewManager * Note: this instance does not hold a reference to the viewobserver * because it holds a reference to this instance. - * This constructs the root view with the given parent. + * @result The result of the initialization, NS_OK if no errors */ - virtual nsresult Init(nsIDeviceContext* aContext, nsIView *aParent) = 0; + NS_IMETHOD Init(nsIDeviceContext* aContext) = 0; /** * Get the root of the view tree. * @result the root view */ - nsIView* RootView() { return mRootView; } + NS_IMETHOD GetRootView(nsIView *&aView) = 0; + + /** + * Set the root of the view tree. Does not destroy the current root view. + * aView may have a parent view managed by a different view manager. + * aView may have a widget (anything but printing) or may not (printing). + * @param aView view to set as root + */ + NS_IMETHOD SetRootView(nsIView *aView) = 0; + + /** + * Get the dimensions of the root window. The dimensions are in + * twips + * @param aWidth out parameter for width of window in twips + * @param aHeight out parameter for height of window in twips + */ + NS_IMETHOD GetWindowDimensions(nscoord *aWidth, nscoord *aHeight) = 0; /** * Set the dimensions of the root window. @@ -496,8 +510,6 @@ public: PRUint16 aMinTwips, nsRectVisibility *aRectVisibility)=0; - protected: - nsIView* mRootView; }; //update view now? diff --git a/mozilla/view/src/nsView.cpp b/mozilla/view/src/nsView.cpp index 6f34eff8dae..88702147a60 100644 --- a/mozilla/view/src/nsView.cpp +++ b/mozilla/view/src/nsView.cpp @@ -125,12 +125,27 @@ nsView::~nsView() if (mViewManager) { + nsView *rootView = mViewManager->GetRootView(); + + if (rootView) + { // Root views can have parents! if (mParent) { mViewManager->RemoveChild(this); } + if (rootView == this) + { + // Inform the view manager that the root view has gone away... + mViewManager->SetRootView(nsnull); + } + } + else if (mParent) + { + mParent->RemoveChild(this); + } + mViewManager = nsnull; } else if (mParent) @@ -234,12 +249,7 @@ nsresult nsIView::Init(nsIViewManager* aManager, void nsIView::Destroy() { - // We don't want to tear down the root view when the viewport frame - // (which has the root view as its view) goes away. The root view will - // be deleted when the view manager dies. - if (!IsRoot()) { - delete this; - } + delete this; } NS_IMETHODIMP nsView::Paint(nsIRenderingContext& rc, const nsRect& rect, @@ -739,7 +749,7 @@ nsresult nsView::GetDirtyRegion(nsIRegion*& aRegion) PRBool nsIView::IsRoot() const { NS_ASSERTION(mViewManager != nsnull," View manager is null in nsView::IsRoot()"); - return mViewManager->RootView() == this; + return mViewManager->GetRootView() == this; } PRBool nsIView::ExternalIsRoot() const diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index bf7dd5f48c8..c88070b2609 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -447,9 +447,9 @@ nsViewManager::nsViewManager() nsViewManager::~nsViewManager() { - if (RootView()) { + if (mRootView) { // Destroy any remaining views - delete RootView(); + mRootView->Destroy(); mRootView = nsnull; } @@ -538,7 +538,7 @@ nsViewManager::CreateRegion(nsIRegion* *result) // We don't hold a reference to the presentation context because it // holds a reference to us. -nsresult nsViewManager::Init(nsIDeviceContext* aContext, nsIView* aParent) +NS_IMETHODIMP nsViewManager::Init(nsIDeviceContext* aContext) { NS_PRECONDITION(nsnull != aContext, "null ptr"); @@ -557,34 +557,68 @@ nsresult nsViewManager::Init(nsIDeviceContext* aContext, nsIView* aParent) mMouseGrabber = nsnull; mKeyGrabber = nsnull; - mRootView = new nsView(); - if (!mRootView) { - return NS_ERROR_OUT_OF_MEMORY; - } - mRootView->Init(this, nsRect(0, 0, 0, 0), aParent); - - if (aParent) { - NS_STATIC_CAST(nsView*, aParent)->InsertChild(RootView(), nsnull); - } - if (nsnull == mEventQueueService) { mEventQueueService = do_GetService(kEventQueueServiceCID); NS_ASSERTION(mEventQueueService, "couldn't get event queue service"); } + + return NS_OK; +} +NS_IMETHODIMP nsViewManager::GetRootView(nsIView *&aView) +{ + aView = mRootView; + return NS_OK; +} + +NS_IMETHODIMP nsViewManager::SetRootView(nsIView *aView) +{ + nsView* view = NS_STATIC_CAST(nsView*, aView); + + // Do NOT destroy the current root view. It's the caller's responsibility + // to destroy it + mRootView = view; + + if (mRootView) { + nsView* parent = mRootView->GetParent(); + if (parent) { + parent->InsertChild(mRootView, nsnull); + } + + mRootView->SetZIndex(PR_FALSE, 0, PR_FALSE); + } + + return NS_OK; +} + +NS_IMETHODIMP nsViewManager::GetWindowDimensions(nscoord *aWidth, nscoord *aHeight) +{ + if (nsnull != mRootView) { + nsRect dim; + mRootView->GetDimensions(dim); + *aWidth = dim.width; + *aHeight = dim.height; + } + else + { + *aWidth = 0; + *aHeight = 0; + } return NS_OK; } NS_IMETHODIMP nsViewManager::SetWindowDimensions(nscoord aWidth, nscoord aHeight) { // Resize the root view + if (nsnull != mRootView) { nsRect dim(0, 0, aWidth, aHeight); - RootView()->SetDimensions(dim); + mRootView->SetDimensions(dim); + } //printf("new dims: %d %d\n", aWidth, aHeight); // Inform the presentation shell that we've been resized if (nsnull != mObserver) - mObserver->ResizeReflow(RootView(), aWidth, aHeight); + mObserver->ResizeReflow(mRootView, aWidth, aHeight); //printf("reflow done\n"); return NS_OK; @@ -1539,7 +1573,7 @@ nsViewManager::UpdateViewAfterScroll(nsIView *aView, PRInt32 aDX, PRInt32 aDY) return; } - nsView* realRoot = RootView(); + nsView* realRoot = mRootView; while (realRoot->GetParent()) { realRoot = realRoot->GetParent(); } @@ -1683,7 +1717,7 @@ NS_IMETHODIMP nsViewManager::UpdateView(nsIView *aView, const nsRect &aRect, PRU } else { damagedRect.MoveBy(ComputeViewOffset(view)); - nsView* realRoot = RootView(); + nsView* realRoot = mRootView; while (realRoot->GetParent()) { realRoot = realRoot->GetParent(); } @@ -1707,7 +1741,7 @@ NS_IMETHODIMP nsViewManager::UpdateView(nsIView *aView, const nsRect &aRect, PRU NS_IMETHODIMP nsViewManager::UpdateAllViews(PRUint32 aUpdateFlags) { - UpdateViews(RootView(), aUpdateFlags); + UpdateViews(mRootView, aUpdateFlags); return NS_OK; } @@ -1746,7 +1780,7 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS // The root view may not be set if this is the resize associated with // window creation - if (view == RootView()) + if (view == mRootView) { // Convert from pixels to twips float p2t; @@ -1903,14 +1937,14 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS nsView *parent; parent = baseView; - while (RootView() != parent) { + while (mRootView != parent) { parent->ConvertToParentCoords(&offset.x, &offset.y); parent = parent->GetParent(); } //Subtract back offset from root of view parent = view; - while (RootView() != parent) { + while (mRootView != parent) { parent->ConvertFromParentCoords(&offset.x, &offset.y); parent = parent->GetParent(); } @@ -2233,7 +2267,7 @@ nsEventStatus nsViewManager::HandleEvent(nsView* aView, nsGUIEvent* aEvent, PRBo NS_IMETHODIMP nsViewManager::GrabMouseEvents(nsIView *aView, PRBool &aResult) { - nsView* rootParent = RootView()->GetParent(); + nsView* rootParent = mRootView ? mRootView->GetParent() : nsnull; if (rootParent) { return rootParent->GetViewManager()->GrabMouseEvents(aView, aResult); } @@ -2267,7 +2301,7 @@ NS_IMETHODIMP nsViewManager::GrabKeyEvents(nsIView *aView, PRBool &aResult) NS_IMETHODIMP nsViewManager::GetMouseEventGrabber(nsIView *&aView) { - nsView* rootParent = RootView()->GetParent(); + nsView* rootParent = mRootView ? mRootView->GetParent() : nsnull; if (rootParent) { return rootParent->GetViewManager()->GetMouseEventGrabber(aView); } @@ -2727,7 +2761,7 @@ PRBool nsViewManager::CanScrollWithBitBlt(nsView* aView) if (IsAncestorOf(NS_STATIC_CAST(const nsView*, scrollableClipView), aView)) { // add areas of fixed views to the opaque area. // This is a bit of a hack. We should not be doing special case processing for fixed views. - nsView* fixedView = RootView()->GetFirstChild(); + nsView* fixedView = mRootView->GetFirstChild(); while (fixedView != nsnull) { if (fixedView->GetZParent() != nsnull && fixedView->GetZIndex() >= 0) { opaqueRegion.Or(opaqueRegion, fixedView->GetBounds()); @@ -2847,7 +2881,7 @@ NS_IMETHODIMP nsViewManager::SetViewVisibility(nsIView *aView, nsViewVisibility PRBool nsViewManager::IsViewInserted(nsView *aView) { - if (RootView() == aView) { + if (mRootView == aView) { return PR_TRUE; } else if (aView->GetParent() == nsnull) { return PR_FALSE; @@ -2872,7 +2906,7 @@ NS_IMETHODIMP nsViewManager::SetViewZIndex(nsIView *aView, PRBool aAutoZIndex, P // don't allow the root view's z-index to be changed. It should always be zero. // This could be removed and replaced with a style rule, or just removed altogether, with interesting consequences - if (aView == RootView()) { + if (aView == mRootView) { return rv; } @@ -3073,7 +3107,7 @@ NS_IMETHODIMP nsViewManager::EnableRefresh(PRUint32 aUpdateFlags) mRefreshEnabled = PR_TRUE; if (aUpdateFlags & NS_VMREFRESH_IMMEDIATE) { - ProcessPendingUpdates(RootView()); + ProcessPendingUpdates(mRootView); mHasPendingInvalidates = PR_FALSE; Composite(); } else { @@ -3919,7 +3953,7 @@ nsViewManager::CacheWidgetChanges(PRBool aCache) // if we turned it off. Then move and size all the widgets. if (mCachingWidgetChanges == 0) - ProcessWidgetChanges(RootView()); + ProcessWidgetChanges(mRootView); #endif return NS_OK; @@ -3943,7 +3977,7 @@ NS_IMETHODIMP nsViewManager::FlushPendingInvalidates() { if (mHasPendingInvalidates) { - ProcessPendingUpdates(RootView()); + ProcessPendingUpdates(mRootView); mHasPendingInvalidates = PR_FALSE; } return NS_OK; diff --git a/mozilla/view/src/nsViewManager.h b/mozilla/view/src/nsViewManager.h index 54a4cd74b33..964ccb333c7 100644 --- a/mozilla/view/src/nsViewManager.h +++ b/mozilla/view/src/nsViewManager.h @@ -123,8 +123,12 @@ public: NS_DECL_ISUPPORTS - virtual nsresult Init(nsIDeviceContext* aContext, nsIView* aParent); + NS_IMETHOD Init(nsIDeviceContext* aContext); + NS_IMETHOD GetRootView(nsIView *&aView); + NS_IMETHOD SetRootView(nsIView *aView); + + NS_IMETHOD GetWindowDimensions(nscoord *width, nscoord *height); NS_IMETHOD SetWindowDimensions(nscoord width, nscoord height); NS_IMETHOD ResetScrolling(void); @@ -347,7 +351,7 @@ private: void GetMaxWidgetBounds(nsRect& aMaxWidgetBounds) const; public: // NOT in nsIViewManager, so private to the view module - nsView* RootView() const { return NS_STATIC_CAST(nsView*, mRootView); } + nsView* GetRootView() const { return mRootView; } nsView* GetMouseEventGrabber() const { return mMouseGrabber; } nsView* GetKeyEventGrabber() const { return mKeyGrabber; } @@ -373,11 +377,11 @@ public: // NOT in nsIViewManager, so private to the view module private: nsIDeviceContext *mContext; - nsView *mMouseGrabber; - nsView *mKeyGrabber; float mTwipsToPixels; float mPixelsToTwips; nsIViewObserver *mObserver; + nsView *mMouseGrabber; + nsView *mKeyGrabber; PRInt32 mUpdateCnt; PRInt32 mUpdateBatchCnt; nsIScrollableView *mRootScrollable; @@ -387,6 +391,7 @@ private: nsCOMPtr mBlender; nsISupportsArray *mCompositeListeners; nsCOMPtr mRegionFactory; + nsView *mRootView; nsCOMPtr mEventQueueService; nsCOMPtr mInvalidateEventQueue; PRPackedBool mRefreshEnabled; diff --git a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp index fd302495b0f..2b801592ac4 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -1157,7 +1157,11 @@ NS_IMETHODIMP nsBrowserWindow::ForceRefresh() nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); + } } NS_RELEASE(shell); } @@ -2483,7 +2487,11 @@ DumpViewsRecurse(nsIDocShell* aDocShell, FILE* out) nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - vm->RootView()->List(out); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + root->List(out); + } } NS_RELEASE(shell); } diff --git a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp index efb88d83123..e6003e9d412 100644 --- a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp +++ b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp @@ -445,7 +445,9 @@ nsWebCrawler::OnStateChange(nsIWebProgress* aWebProgress, nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* rootView; + vm->GetRootView(rootView); + vm->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); } if (mJiggleLayout) { diff --git a/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp b/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp index 2cd2375536b..13366ce8d48 100644 --- a/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp @@ -261,7 +261,11 @@ void nsXPBaseWindow::ForceRefresh() nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); + } } NS_RELEASE(shell); } diff --git a/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp b/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp index 1f5590d845f..e1a282a1ff0 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp @@ -85,8 +85,12 @@ nsIWidget *nsBaseFilePicker::DOMWindowToWidget(nsIDOMWindow *dw) nsresult rv = docShell->GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) { - nsIView *view = presShell->GetViewManager()->RootView(); + nsIView *view; + rv = presShell->GetViewManager()->GetRootView(view); + + if (NS_SUCCEEDED(rv)) { return view->GetWidget(); + } } } }