diff --git a/mozilla/accessible/src/base/nsCaretAccessible.cpp b/mozilla/accessible/src/base/nsCaretAccessible.cpp index 92f1e546bab..6f4a3903551 100644 --- a/mozilla/accessible/src/base/nsCaretAccessible.cpp +++ b/mozilla/accessible/src/base/nsCaretAccessible.cpp @@ -165,11 +165,7 @@ NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument *aDoc, ns nsIViewManager* viewManager = presShell->GetViewManager(); if (!presContext || !viewManager) return NS_OK; - nsIView *view = nsnull; - viewManager->GetRootView(view); - if (!view) - return NS_OK; - nsIWidget* widget = view->GetWidget(); + nsIWidget* widget = viewManager->RootView()->GetWidget(); if (!widget) return NS_OK; diff --git a/mozilla/accessible/src/base/nsDocAccessible.cpp b/mozilla/accessible/src/base/nsDocAccessible.cpp index ea46ccb1758..db8f854d09d 100644 --- a/mozilla/accessible/src/base/nsDocAccessible.cpp +++ b/mozilla/accessible/src/base/nsDocAccessible.cpp @@ -421,11 +421,7 @@ void nsDocAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aRelativeFrame) } } else { - nsIView *view; - vm->GetRootView(view); - if (view) { - viewBounds = view->GetBounds(); - } + viewBounds = vm->RootView()->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 f26de3e29a1..d14f8721320 100644 --- a/mozilla/content/base/src/nsContentSink.cpp +++ b/mozilla/content/base/src/nsContentSink.cpp @@ -978,22 +978,4 @@ 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 03b74d7f2e1..36c786e9b57 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -456,7 +456,6 @@ 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 @@ -1653,11 +1652,7 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - nsIView* view; - mViewManager->GetRootView(view); // views are not refCounted - if (view) { - mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); - } + mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); } else { mViewManager->DisableRefresh(); @@ -1844,12 +1839,6 @@ 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, @@ -1861,11 +1850,6 @@ 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; @@ -1908,10 +1892,13 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = view->Init(mViewManager, tbounds, containerView); + rv = mViewManager->Init(dx, 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; @@ -1935,9 +1922,6 @@ 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 b70db4602df..0d795b8f3b6 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -234,7 +234,6 @@ 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); @@ -2610,7 +2609,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = aPO->mViewManager->Init(mPrt->mPrintDocDC); + rv = aPO->mViewManager->Init(mPrt->mPrintDocDC, nsnull); if (NS_FAILED(rv)) { delete aPO->mStyleSet; return rv; @@ -2659,12 +2658,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) nsRect tbounds = nsRect(0, 0, width, height); - // 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); + aPO->mRootView = aPO->mViewManager->RootView(); + rv = aPO->mViewManager->ResizeView(aPO->mRootView, tbounds); if (NS_FAILED(rv)) { return rv; } @@ -2708,7 +2703,6 @@ 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()); @@ -4753,11 +4747,7 @@ DumpViews(nsIDocShell* aDocShell, FILE* out) if (shell) { nsIViewManager* vm = shell->GetViewManager(); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - root->List(out); - } + vm->RootView()->List(out); } } else { diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index ac0f61a39c1..846b3cc8fab 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -1584,11 +1584,7 @@ nsDocShell::SetZoom(float zoom) if (scrollableView) scrollableView->ComputeScrollOffsets(); - // get the root view - nsIView *rootView = nsnull; // views are not ref counted - vm->GetRootView(rootView); - if (rootView) - vm->UpdateView(rootView, 0); + vm->UpdateView(vm->RootView(), 0); return NS_OK; } @@ -3269,13 +3265,8 @@ 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 (view->GetVisibility() == nsViewVisibility_kHide) { + if (vm->RootView()->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 cdbf883118f..a1d454c03d2 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -4279,29 +4279,6 @@ 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) { @@ -4324,9 +4301,7 @@ GlobalWindowImpl::Activate() nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView; - vm->GetRootView(rootView); - NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + nsIView *rootView = vm->RootView(); // We're holding a STRONG REF to the widget to ensure it doesn't go away // during event processing @@ -4353,9 +4328,7 @@ GlobalWindowImpl::Deactivate() nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView; - vm->GetRootView(rootView); - NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + nsIView *rootView = vm->RootView(); // Hold a STRONG REF to keep the widget around during event processing nsCOMPtr widget = rootView->GetWidget(); @@ -5696,9 +5669,7 @@ nsGlobalChromeWindow::SetCursor(const nsAString& aCursor) nsIViewManager* vm = presShell->GetViewManager(); NS_ENSURE_TRUE(vm, NS_ERROR_FAILURE); - nsIView *rootView; - vm->GetRootView(rootView); - NS_ENSURE_TRUE(rootView, NS_ERROR_FAILURE); + nsIView *rootView = vm->RootView(); 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 dbf668b7abb..77eaf271cff 100644 --- a/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp +++ b/mozilla/editor/libeditor/text/nsEditorEventListeners.cpp @@ -1047,11 +1047,7 @@ nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent) // begin hack repaint nsIViewManager* viewmgr = ps->GetViewManager(); if (viewmgr) { - nsIView* view; - viewmgr->GetRootView(view); // views are not refCounted - if (view) { - viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE); - } + viewmgr->UpdateView(viewmgr->RootView(),NS_VMREFRESH_IMMEDIATE); } // end hack repaint #else @@ -1110,11 +1106,7 @@ nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent) nsIViewManager* viewmgr = ps->GetViewManager(); if (viewmgr) { - nsIView* view; - viewmgr->GetRootView(view); // views are not refCounted - if (view) { - viewmgr->UpdateView(view,NS_VMREFRESH_IMMEDIATE); - } + viewmgr->UpdateView(viewmgr->RootView(),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 5eb0c351c9b..2dd365a5bfa 100644 --- a/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/mozilla/extensions/inspector/base/src/inLayoutUtils.cpp @@ -139,15 +139,9 @@ 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 == rootView) { + if (view->ExternalIsRoot()) { break; } view = view->GetParent(); diff --git a/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp b/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp index 3393b23e885..4286e5789c9 100644 --- a/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp +++ b/mozilla/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp @@ -473,11 +473,7 @@ DumpViewsRecur(nsIDocShell* aDocShell, FILE* out) fprintf(out, "docshell=%p \n", NS_STATIC_CAST(void*, aDocShell)); nsCOMPtr vm(view_manager(aDocShell)); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - root->List(out); - } + vm->RootView()->List(out); } else { fputs("null view manager\n", out); @@ -564,11 +560,7 @@ void nsLayoutDebuggingTools::ForceRefresh() nsCOMPtr vm(view_manager(mDocShell)); if (!vm) return; - nsIView* root = nsnull; - vm->GetRootView(root); - if (root) { - vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); - } + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } nsresult diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 1c9997bb4b4..949e46d812c 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -3645,9 +3645,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // Bind the viewport frame to the root view nsIViewManager* viewManager = aPresContext->GetViewManager(); - nsIView* rootView; + nsIView* rootView = viewManager->RootView(); - viewManager->GetRootView(rootView); viewportFrame->SetView(rootView); nsContainerFrame::SyncFrameViewProperties(aPresContext, viewportFrame, diff --git a/mozilla/layout/base/nsCSSRendering.cpp b/mozilla/layout/base/nsCSSRendering.cpp index 7f2cb5aa1f5..4528b2ee95c 100644 --- a/mozilla/layout/base/nsCSSRendering.cpp +++ b/mozilla/layout/base/nsCSSRendering.cpp @@ -2754,8 +2754,7 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, nsIViewManager* vm = aPresContext->GetViewManager(); if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) { - nsIView* rootView; - vm->GetRootView(rootView); + nsIView* rootView = vm->RootView(); if (!rootView->GetParent()) { PRBool widgetIsTranslucent = PR_FALSE; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index 03b74d7f2e1..36c786e9b57 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -456,7 +456,6 @@ 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 @@ -1653,11 +1652,7 @@ DocumentViewerImpl::SetEnableRendering(PRBool aOn) if (mViewManager) { if (aOn) { mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - nsIView* view; - mViewManager->GetRootView(view); // views are not refCounted - if (view) { - mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); - } + mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); } else { mViewManager->DisableRefresh(); @@ -1844,12 +1839,6 @@ 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, @@ -1861,11 +1850,6 @@ 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; @@ -1908,10 +1892,13 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = view->Init(mViewManager, tbounds, containerView); + rv = mViewManager->Init(dx, 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; @@ -1935,9 +1922,6 @@ 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 063832d34c2..140cfa0484a 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -208,7 +208,6 @@ 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 @@ -5805,9 +5804,7 @@ 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. - nsIView *view; - vm->GetRootView(view); - if (view == aView) { + if (aView->IsRoot()) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged(); @@ -6434,9 +6431,7 @@ PresShell::ProcessReflowCommands(PRBool aInterruptible) if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can // see it. - nsIView* rootView; - mViewManager->GetRootView(rootView); - mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); + mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); mInVerifyReflow = PR_TRUE; PRBool ok = VerifyIncrementalReflow(); @@ -7023,44 +7018,28 @@ PresShell::VerifyIncrementalReflow() rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); - // 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); + void* nativeParentWidget = mViewManager->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); + rv = vm->Init(dc, nsnull); 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 = view->Init(vm, tbounds, nsnull); + rv = vm->ResizeView(vm->RootView(), tbounds); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); //now create the widget for the view - rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); + rv = vm->RootView()->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 0bb569b58c9..fc3b30bc901 100644 --- a/mozilla/layout/generic/nsContainerFrame.cpp +++ b/mozilla/layout/generic/nsContainerFrame.cpp @@ -601,8 +601,7 @@ SyncFrameViewGeometryDependentProperties(nsIPresContext* aPresContext, aView->SetHasUniformBackground(drawnOnUniformField); if (isCanvas) { - nsIView* rootView; - vm->GetRootView(rootView); + nsIView* rootView = vm->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 ab2c3e810cb..92336f4b397 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -1512,11 +1512,7 @@ nsHTMLFramesetFrame::MouseDrag(nsIPresContext* aPresContext, // Update the view immediately (make drag appear snappier) nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (root) { - vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); - } + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } } } diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 76c6be06d0e..df0eaf6fa07 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -1766,10 +1766,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // first, lets find out how big the window is, in pixels nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIView* view; - vm->GetRootView(view); - if (view) { - nsIWidget* win = view->GetWidget(); + nsIWidget* win = vm->RootView()->GetWidget(); if (win) { nsRect visibleRect; win->GetBounds(visibleRect); @@ -1802,7 +1799,6 @@ 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 0bb569b58c9..fc3b30bc901 100644 --- a/mozilla/layout/html/base/src/nsContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsContainerFrame.cpp @@ -601,8 +601,7 @@ SyncFrameViewGeometryDependentProperties(nsIPresContext* aPresContext, aView->SetHasUniformBackground(drawnOnUniformField); if (isCanvas) { - nsIView* rootView; - vm->GetRootView(rootView); + nsIView* rootView = vm->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 76c6be06d0e..df0eaf6fa07 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -1766,10 +1766,7 @@ nsObjectFrame::Paint(nsIPresContext* aPresContext, // first, lets find out how big the window is, in pixels nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIView* view; - vm->GetRootView(view); - if (view) { - nsIWidget* win = view->GetWidget(); + nsIWidget* win = vm->RootView()->GetWidget(); if (win) { nsRect visibleRect; win->GetBounds(visibleRect); @@ -1802,7 +1799,6 @@ 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 063832d34c2..140cfa0484a 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -208,7 +208,6 @@ 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 @@ -5805,9 +5804,7 @@ 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. - nsIView *view; - vm->GetRootView(view); - if (view == aView) { + if (aView->IsRoot()) { aHandled = PR_TRUE; *aEventStatus = nsEventStatus_eConsumeDoDefault; return mPresContext->SysColorChanged(); @@ -6434,9 +6431,7 @@ PresShell::ProcessReflowCommands(PRBool aInterruptible) if (GetVerifyReflowEnable()) { // First synchronously render what we have so far so that we can // see it. - nsIView* rootView; - mViewManager->GetRootView(rootView); - mViewManager->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); + mViewManager->UpdateView(mViewManager->RootView(), NS_VMREFRESH_IMMEDIATE); mInVerifyReflow = PR_TRUE; PRBool ok = VerifyIncrementalReflow(); @@ -7023,44 +7018,28 @@ PresShell::VerifyIncrementalReflow() rv = cx->Init(dc); NS_ENSURE_SUCCESS(rv, rv); - // 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); + void* nativeParentWidget = mViewManager->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); + rv = vm->Init(dc, nsnull); 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 = view->Init(vm, tbounds, nsnull); + rv = vm->ResizeView(vm->RootView(), tbounds); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); //now create the widget for the view - rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); + rv = vm->RootView()->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 ab2c3e810cb..92336f4b397 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp @@ -1512,11 +1512,7 @@ nsHTMLFramesetFrame::MouseDrag(nsIPresContext* aPresContext, // Update the view immediately (make drag appear snappier) nsIViewManager* vm = aPresContext->GetViewManager(); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (root) { - vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); - } + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } } } diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 1c9997bb4b4..949e46d812c 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -3645,9 +3645,8 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell, // Bind the viewport frame to the root view nsIViewManager* viewManager = aPresContext->GetViewManager(); - nsIView* rootView; + nsIView* rootView = viewManager->RootView(); - viewManager->GetRootView(rootView); viewportFrame->SetView(rootView); nsContainerFrame::SyncFrameViewProperties(aPresContext, viewportFrame, diff --git a/mozilla/layout/html/style/src/nsCSSRendering.cpp b/mozilla/layout/html/style/src/nsCSSRendering.cpp index 7f2cb5aa1f5..4528b2ee95c 100644 --- a/mozilla/layout/html/style/src/nsCSSRendering.cpp +++ b/mozilla/layout/html/style/src/nsCSSRendering.cpp @@ -2754,8 +2754,7 @@ nsCSSRendering::PaintBackground(nsIPresContext* aPresContext, nsIViewManager* vm = aPresContext->GetViewManager(); if (canvasColor.mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) { - nsIView* rootView; - vm->GetRootView(rootView); + nsIView* rootView = vm->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 edbccbdd5fa..4ba28485c06 100644 --- a/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp +++ b/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp @@ -478,17 +478,9 @@ GeometryTest::GeometryTest(BasicTest *aDoc) fprintf(out, "bad view manager"); NS_ASSERTION(PR_FALSE, "bad view manager"); } - vm->Init(pc); + vm->Init(pc, nsnull); - 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); + nsIView * rootView = vm->GetRootView(); if ((NS_FAILED(status)) || nsnull==rootView) { @@ -496,9 +488,7 @@ GeometryTest::GeometryTest(BasicTest *aDoc) NS_ASSERTION(PR_FALSE, "bad view"); } nsRect bounds(0, 0, 10000, 10000); - rootView->Init(vm, bounds, nsnull); - - vm->SetRootView(rootView); + vm->ResizeView(rootView, bounds); nsCOMPtr ss(do_CreateInstance(kStyleSetCID,&status)); if ((NS_FAILED(status))) @@ -566,7 +556,7 @@ void GeometryTest::CreateGeometry(BasicTest * aDoc, nsIPresContext *aPC) fprintf(out, "bad view manager"); NS_ASSERTION(PR_FALSE, ""); } - nsIView* rootView = mViewManager->GetRootView(); + nsIView* rootView = mViewManager->RootView(); 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 b70db4602df..0d795b8f3b6 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -234,7 +234,6 @@ 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); @@ -2610,7 +2609,7 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) return rv; } - rv = aPO->mViewManager->Init(mPrt->mPrintDocDC); + rv = aPO->mViewManager->Init(mPrt->mPrintDocDC, nsnull); if (NS_FAILED(rv)) { delete aPO->mStyleSet; return rv; @@ -2659,12 +2658,8 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) nsRect tbounds = nsRect(0, 0, width, height); - // 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); + aPO->mRootView = aPO->mViewManager->RootView(); + rv = aPO->mViewManager->ResizeView(aPO->mRootView, tbounds); if (NS_FAILED(rv)) { return rv; } @@ -2708,7 +2703,6 @@ 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()); @@ -4753,11 +4747,7 @@ DumpViews(nsIDocShell* aDocShell, FILE* out) if (shell) { nsIViewManager* vm = shell->GetViewManager(); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - root->List(out); - } + vm->RootView()->List(out); } } else { diff --git a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp index 2e305f08ff3..a7c496fcbca 100644 --- a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -190,8 +190,7 @@ nsMenuPopupFrame::Init(nsIPresContext* aPresContext, viewManager->RemoveChild(ourView); // Reinsert ourselves as the root view with a maximum z-index. - nsIView* rootView; - viewManager->GetRootView(rootView); + nsIView* rootView = viewManager->RootView(); viewManager->SetViewZIndex(ourView, PR_FALSE, kMaxZ); viewManager->InsertChild(rootView, ourView, nsnull, PR_TRUE); @@ -415,8 +414,7 @@ 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()->GetRootView(rootView); + nsIView* rootView = aView->GetViewManager()->RootView(); nsIView *parent; @@ -490,7 +488,7 @@ nsMenuPopupFrame::GetRootViewForPopup(nsIPresContext* aPresContext, if (view) { nsIView* rootView = nsnull; if (aStopAtViewManagerRoot) { - view->GetViewManager()->GetRootView(rootView); + rootView = view->GetViewManager()->RootView(); } while (view) { @@ -561,9 +559,7 @@ nsMenuPopupFrame::AdjustClientXYForNestedDocuments ( nsIDOMXULDocument* inPopupD nsIWidget* popupDocumentWidget = nsnull; nsIViewManager* viewManager = inPopupShell->GetViewManager(); if ( viewManager ) { - nsIView* rootView; - viewManager->GetRootView(rootView); - if ( rootView ) + nsIView* rootView = viewManager->RootView(); popupDocumentWidget = rootView->GetNearestWidget(nsnull); } NS_WARN_IF_FALSE(popupDocumentWidget, "ACK, BAD WIDGET"); @@ -605,11 +601,8 @@ nsMenuPopupFrame::AdjustClientXYForNestedDocuments ( nsIDOMXULDocument* inPopupD // widget. nsIViewManager* viewManagerTarget = shell->GetViewManager(); if ( viewManagerTarget ) { - nsIView* rootViewTarget; - viewManagerTarget->GetRootView(rootViewTarget); - if ( rootViewTarget ) { + nsIView* rootViewTarget = viewManagerTarget->RootView(); targetDocumentWidget = rootViewTarget->GetNearestWidget(nsnull); - } } } } diff --git a/mozilla/view/public/nsIView.h b/mozilla/view/public/nsIView.h index 416c2daa3a0..e51bc9aa83a 100644 --- a/mozilla/view/public/nsIView.h +++ b/mozilla/view/public/nsIView.h @@ -183,10 +183,8 @@ 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 - * SetRootView(NULL) if the view is the root view and calling RemoveChild() - * otherwise. + * RemoveChild() if the view is not the root view. */ void Destroy(); diff --git a/mozilla/view/public/nsIViewManager.h b/mozilla/view/public/nsIViewManager.h index a796d708c84..143fc2924af 100644 --- a/mozilla/view/public/nsIViewManager.h +++ b/mozilla/view/public/nsIViewManager.h @@ -50,6 +50,7 @@ struct nsRect; class nsRegion; class nsIDeviceContext; class nsIViewObserver; +class nsView; enum nsRectVisibility { nsRectVisibility_kVisible, @@ -70,35 +71,20 @@ 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. - * @result The result of the initialization, NS_OK if no errors + * This constructs the root view with the given parent. */ - NS_IMETHOD Init(nsIDeviceContext* aContext) = 0; + virtual nsresult Init(nsIDeviceContext* aContext, nsIView *aParent) = 0; /** * Get the root of the view tree. * @result the root view */ - 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; + nsIView* RootView() { return mRootView; } /** * Set the dimensions of the root window. @@ -510,6 +496,8 @@ 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 88702147a60..6f34eff8dae 100644 --- a/mozilla/view/src/nsView.cpp +++ b/mozilla/view/src/nsView.cpp @@ -125,27 +125,12 @@ 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) @@ -249,7 +234,12 @@ nsresult nsIView::Init(nsIViewManager* aManager, void nsIView::Destroy() { - delete this; + // 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; + } } NS_IMETHODIMP nsView::Paint(nsIRenderingContext& rc, const nsRect& rect, @@ -749,7 +739,7 @@ nsresult nsView::GetDirtyRegion(nsIRegion*& aRegion) PRBool nsIView::IsRoot() const { NS_ASSERTION(mViewManager != nsnull," View manager is null in nsView::IsRoot()"); - return mViewManager->GetRootView() == this; + return mViewManager->RootView() == this; } PRBool nsIView::ExternalIsRoot() const diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index 586f10faaa5..0e89fd6dfd7 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -447,9 +447,9 @@ nsViewManager::nsViewManager() nsViewManager::~nsViewManager() { - if (mRootView) { + if (RootView()) { // Destroy any remaining views - mRootView->Destroy(); + delete RootView(); 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. -NS_IMETHODIMP nsViewManager::Init(nsIDeviceContext* aContext) +nsresult nsViewManager::Init(nsIDeviceContext* aContext, nsIView* aParent) { NS_PRECONDITION(nsnull != aContext, "null ptr"); @@ -557,68 +557,34 @@ NS_IMETHODIMP nsViewManager::Init(nsIDeviceContext* aContext) 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); - mRootView->SetDimensions(dim); - } + RootView()->SetDimensions(dim); //printf("new dims: %d %d\n", aWidth, aHeight); // Inform the presentation shell that we've been resized if (nsnull != mObserver) - mObserver->ResizeReflow(mRootView, aWidth, aHeight); + mObserver->ResizeReflow(RootView(), aWidth, aHeight); //printf("reflow done\n"); return NS_OK; @@ -1573,7 +1539,7 @@ nsViewManager::UpdateViewAfterScroll(nsIView *aView, PRInt32 aDX, PRInt32 aDY) return; } - nsView* realRoot = mRootView; + nsView* realRoot = RootView(); while (realRoot->GetParent()) { realRoot = realRoot->GetParent(); } @@ -1717,7 +1683,7 @@ NS_IMETHODIMP nsViewManager::UpdateView(nsIView *aView, const nsRect &aRect, PRU } else { damagedRect.MoveBy(ComputeViewOffset(view)); - nsView* realRoot = mRootView; + nsView* realRoot = RootView(); while (realRoot->GetParent()) { realRoot = realRoot->GetParent(); } @@ -1741,7 +1707,7 @@ NS_IMETHODIMP nsViewManager::UpdateView(nsIView *aView, const nsRect &aRect, PRU NS_IMETHODIMP nsViewManager::UpdateAllViews(PRUint32 aUpdateFlags) { - UpdateViews(mRootView, aUpdateFlags); + UpdateViews(RootView(), aUpdateFlags); return NS_OK; } @@ -1780,7 +1746,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 == mRootView) + if (view == RootView()) { // Convert from pixels to twips float p2t; @@ -1937,14 +1903,14 @@ NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus *aS nsView *parent; parent = baseView; - while (mRootView != parent) { + while (RootView() != parent) { parent->ConvertToParentCoords(&offset.x, &offset.y); parent = parent->GetParent(); } //Subtract back offset from root of view parent = view; - while (mRootView != parent) { + while (RootView() != parent) { parent->ConvertFromParentCoords(&offset.x, &offset.y); parent = parent->GetParent(); } @@ -2751,7 +2717,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 = mRootView->GetFirstChild(); + nsView* fixedView = RootView()->GetFirstChild(); while (fixedView != nsnull) { if (fixedView->GetZParent() != nsnull && fixedView->GetZIndex() >= 0) { opaqueRegion.Or(opaqueRegion, fixedView->GetBounds()); @@ -2871,7 +2837,7 @@ NS_IMETHODIMP nsViewManager::SetViewVisibility(nsIView *aView, nsViewVisibility PRBool nsViewManager::IsViewInserted(nsView *aView) { - if (mRootView == aView) { + if (RootView() == aView) { return PR_TRUE; } else if (aView->GetParent() == nsnull) { return PR_FALSE; @@ -2896,7 +2862,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 == mRootView) { + if (aView == RootView()) { return rv; } @@ -3097,7 +3063,7 @@ NS_IMETHODIMP nsViewManager::EnableRefresh(PRUint32 aUpdateFlags) mRefreshEnabled = PR_TRUE; if (aUpdateFlags & NS_VMREFRESH_IMMEDIATE) { - ProcessPendingUpdates(mRootView); + ProcessPendingUpdates(RootView()); mHasPendingInvalidates = PR_FALSE; Composite(); } else { @@ -3943,7 +3909,7 @@ nsViewManager::CacheWidgetChanges(PRBool aCache) // if we turned it off. Then move and size all the widgets. if (mCachingWidgetChanges == 0) - ProcessWidgetChanges(mRootView); + ProcessWidgetChanges(RootView()); #endif return NS_OK; @@ -3967,7 +3933,7 @@ NS_IMETHODIMP nsViewManager::FlushPendingInvalidates() { if (mHasPendingInvalidates) { - ProcessPendingUpdates(mRootView); + ProcessPendingUpdates(RootView()); mHasPendingInvalidates = PR_FALSE; } return NS_OK; diff --git a/mozilla/view/src/nsViewManager.h b/mozilla/view/src/nsViewManager.h index 964ccb333c7..54a4cd74b33 100644 --- a/mozilla/view/src/nsViewManager.h +++ b/mozilla/view/src/nsViewManager.h @@ -123,12 +123,8 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD Init(nsIDeviceContext* aContext); + virtual nsresult Init(nsIDeviceContext* aContext, nsIView* aParent); - 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); @@ -351,7 +347,7 @@ private: void GetMaxWidgetBounds(nsRect& aMaxWidgetBounds) const; public: // NOT in nsIViewManager, so private to the view module - nsView* GetRootView() const { return mRootView; } + nsView* RootView() const { return NS_STATIC_CAST(nsView*, mRootView); } nsView* GetMouseEventGrabber() const { return mMouseGrabber; } nsView* GetKeyEventGrabber() const { return mKeyGrabber; } @@ -377,11 +373,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; @@ -391,7 +387,6 @@ 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 2b801592ac4..fd302495b0f 100644 --- a/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsBrowserWindow.cpp @@ -1157,11 +1157,7 @@ NS_IMETHODIMP nsBrowserWindow::ForceRefresh() nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); - } + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } NS_RELEASE(shell); } @@ -2487,11 +2483,7 @@ DumpViewsRecurse(nsIDocShell* aDocShell, FILE* out) nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - root->List(out); - } + vm->RootView()->List(out); } NS_RELEASE(shell); } diff --git a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp index e6003e9d412..efb88d83123 100644 --- a/mozilla/webshell/tests/viewer/nsWebCrawler.cpp +++ b/mozilla/webshell/tests/viewer/nsWebCrawler.cpp @@ -445,9 +445,7 @@ nsWebCrawler::OnStateChange(nsIWebProgress* aWebProgress, nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - nsIView* rootView; - vm->GetRootView(rootView); - vm->UpdateView(rootView, NS_VMREFRESH_IMMEDIATE); + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } if (mJiggleLayout) { diff --git a/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp b/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp index 13366ce8d48..2cd2375536b 100644 --- a/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp +++ b/mozilla/webshell/tests/viewer/nsXPBaseWindow.cpp @@ -261,11 +261,7 @@ void nsXPBaseWindow::ForceRefresh() nsCOMPtr vm; shell->GetViewManager(getter_AddRefs(vm)); if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - vm->UpdateView(root, NS_VMREFRESH_IMMEDIATE); - } + vm->UpdateView(vm->RootView(), NS_VMREFRESH_IMMEDIATE); } NS_RELEASE(shell); } diff --git a/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp b/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp index e1a282a1ff0..1f5590d845f 100644 --- a/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp +++ b/mozilla/widget/src/xpwidgets/nsBaseFilePicker.cpp @@ -85,12 +85,8 @@ nsIWidget *nsBaseFilePicker::DOMWindowToWidget(nsIDOMWindow *dw) nsresult rv = docShell->GetPresShell(getter_AddRefs(presShell)); if (NS_SUCCEEDED(rv) && presShell) { - nsIView *view; - rv = presShell->GetViewManager()->GetRootView(view); - - if (NS_SUCCEEDED(rv)) { + nsIView *view = presShell->GetViewManager()->RootView(); return view->GetWidget(); - } } } }