From 18c53f2f327ec870f80be3d6899f42d8051e6352 Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Thu, 4 Nov 2004 15:06:50 +0000 Subject: [PATCH] Bug 267302 Views should be created by the view manager r+sr=roc git-svn-id: svn://10.0.0.236/trunk@164914 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocumentViewer.cpp | 15 +++----- mozilla/content/base/src/nsPrintEngine.cpp | 11 ++---- mozilla/layout/base/nsDocumentViewer.cpp | 15 +++----- mozilla/layout/base/nsPresShell.cpp | 10 +++--- mozilla/layout/build/nsLayoutModule.cpp | 7 ---- mozilla/layout/generic/nsFrameFrame.cpp | 18 ++++------ mozilla/layout/generic/nsFrameSetFrame.cpp | 12 +++---- .../layout/generic/nsHTMLContainerFrame.cpp | 15 +++----- mozilla/layout/generic/nsObjectFrame.cpp | 17 +++------- .../html/base/src/nsHTMLContainerFrame.cpp | 15 +++----- .../layout/html/base/src/nsObjectFrame.cpp | 17 +++------- mozilla/layout/html/base/src/nsPresShell.cpp | 10 +++--- .../layout/html/document/src/nsFrameFrame.cpp | 18 ++++------ .../html/document/src/nsFrameSetFrame.cpp | 12 +++---- .../TableContentTest/TableContentTest.cpp | 13 ++----- mozilla/layout/printing/nsPrintEngine.cpp | 11 ++---- mozilla/layout/xul/base/src/nsBoxFrame.cpp | 18 ++++------ .../layout/xul/base/src/nsScrollBoxFrame.cpp | 18 ++++------ mozilla/view/public/nsIScrollableView.h | 4 +-- mozilla/view/public/nsIView.h | 23 ++----------- mozilla/view/public/nsIViewManager.h | 33 ++++++++++++++++-- mozilla/view/public/nsViewsCID.h | 8 ----- mozilla/view/src/nsScrollPortView.cpp | 3 +- mozilla/view/src/nsView.cpp | 34 ++----------------- mozilla/view/src/nsView.h | 3 +- mozilla/view/src/nsViewManager.cpp | 34 +++++++++++++++++-- mozilla/view/src/nsViewManager.h | 9 ++++- 27 files changed, 158 insertions(+), 245 deletions(-) diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index aac3995d5cb..43240d66eb6 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -450,7 +450,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 @@ -1853,13 +1852,6 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, tbounds.y = 0; // 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 nsIView* containerView = nsView::GetViewFor(aParentWidget); @@ -1894,9 +1886,10 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = view->Init(mViewManager, tbounds, containerView); - if (NS_FAILED(rv)) - return rv; + // Create a view + nsIView* view = mViewManager->CreateView(tbounds, containerView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; // pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone. // otherwise the view will find its own parent widget and "do the right thing" to diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index f35d6044485..5b452f8dd61 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -226,7 +226,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); @@ -2641,13 +2640,9 @@ 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); - if (NS_FAILED(rv)) { - return rv; + aPO->mRootView = aPO->mViewManager->CreateView(tbounds, nsnull); + if (!aPO->mRootView) { + return NS_ERROR_OUT_OF_MEMORY; } #ifdef NS_PRINT_PREVIEW diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index aac3995d5cb..43240d66eb6 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -450,7 +450,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 @@ -1853,13 +1852,6 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, tbounds.y = 0; // 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 nsIView* containerView = nsView::GetViewFor(aParentWidget); @@ -1894,9 +1886,10 @@ DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, } } - rv = view->Init(mViewManager, tbounds, containerView); - if (NS_FAILED(rv)) - return rv; + // Create a view + nsIView* view = mViewManager->CreateView(tbounds, containerView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; // pass in a native widget to be the parent widget ONLY if the view hierarchy will stand alone. // otherwise the view will find its own parent widget and "do the right thing" to diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 7d3ed501c41..21abf1c2674 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -205,7 +205,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 @@ -7026,11 +7025,10 @@ PresShell::VerifyIncrementalReflow() // Create a child window of the parent that is our "root view/window" // Create a view nsRect tbounds = mPresContext->GetVisibleArea(); - nsIView* view; - rv = CallCreateInstance(kViewCID, &view); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view"); - rv = view->Init(vm, tbounds, nsnull); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); + nsIView* view = vm->CreateView(tbounds, nsnull); + NS_ASSERTION(view, "failed to create view"); + if (!view) + return PR_FALSE; //now create the widget for the view rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 8c08dc36633..664b6c016b1 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -133,8 +133,6 @@ // view stuff #include "nsViewsCID.h" -#include "nsView.h" -#include "nsScrollPortView.h" #include "nsViewManager.h" #include "nsContentCreatorFunctions.h" #include "nsFrame.h" @@ -640,8 +638,6 @@ _InstanceClass##Constructor(nsISupports *aOuter, REFNSIID aIID, \ } \ NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewManager) -NS_GENERIC_FACTORY_CONSTRUCTOR_NOREFS(nsView) -NS_GENERIC_FACTORY_CONSTRUCTOR_NOREFS(nsScrollPortView) static NS_IMETHODIMP CreateHTMLImgElement(nsISupports* aOuter, REFNSIID aIID, void** aResult) @@ -1306,9 +1302,6 @@ static const nsModuleComponentInfo gComponents[] = { // view stuff { "View Manager", NS_VIEW_MANAGER_CID, "@mozilla.org/view-manager;1", nsViewManagerConstructor }, - { "View", NS_VIEW_CID, "@mozilla.org/view;1", nsViewConstructor }, - { "Scroll Port View", NS_SCROLL_PORT_VIEW_CID, - "@mozilla.org/scroll-port-view;1", nsScrollPortViewConstructor }, { "Plugin Document Loader Factory", NS_PLUGINDOCLOADERFACTORY_CID, diff --git a/mozilla/layout/generic/nsFrameFrame.cpp b/mozilla/layout/generic/nsFrameFrame.cpp index 0003f2c5546..b89268ab085 100644 --- a/mozilla/layout/generic/nsFrameFrame.cpp +++ b/mozilla/layout/generic/nsFrameFrame.cpp @@ -90,7 +90,6 @@ #endif #include "nsIServiceManager.h" -static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); /****************************************************************************** @@ -698,14 +697,6 @@ nsresult nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) { // create, init, set the parent of the view - nsIView* innerView; - nsresult rv = CallCreateInstance(kCViewCID, &innerView); - if (NS_FAILED(rv)) { - NS_ERROR("Could not create inner view"); - return rv; - } - mInnerView = innerView; - nsIView* outerView = GetView(); NS_ASSERTION(outerView, "Must have an outer view already"); nsRect viewBounds(0, 0, 0, 0); // size will be fixed during reflow @@ -713,8 +704,13 @@ nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) nsIViewManager* viewMan = outerView->GetViewManager(); // Create the inner view hidden if the outer view is already hidden // (it won't get hidden properly otherwise) - rv = innerView->Init(viewMan, viewBounds, outerView, - outerView->GetVisibility()); + nsIView* innerView = viewMan->CreateView(viewBounds, outerView, + outerView->GetVisibility()); + if (!innerView) { + NS_ERROR("Could not create inner view"); + return NS_ERROR_OUT_OF_MEMORY; + } + mInnerView = innerView; viewMan->InsertChild(outerView, innerView, nsnull, PR_TRUE); nsWidgetInitData initData; diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 1cee639ffe4..59d63a1b7c0 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -51,7 +51,6 @@ #include "nsIView.h" #include "nsIViewManager.h" #include "nsWidgetsCID.h" -#include "nsViewsCID.h" #include "nsHTMLAtoms.h" #include "nsIScrollableView.h" #include "nsStyleCoord.h" @@ -297,8 +296,6 @@ nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure) return 0; } -static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); - #define FRAMESET 0 #define FRAME 1 #define BLANK 2 @@ -329,13 +326,14 @@ nsHTMLFramesetFrame::Init(nsPresContext* aPresContext, } // create the view. a view is needed since it needs to be a mouse grabber - nsIView* view; - nsresult result = CallCreateInstance(kViewCID, &view); nsIViewManager* viewMan = aPresContext->GetViewManager(); nsIView *parView = GetAncestorWithView()->GetView(); nsRect boundBox(0, 0, 0, 0); - result = view->Init(viewMan, boundBox, parView); + nsIView* view = viewMan->CreateView(boundBox, parView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; + // XXX Put it last in document order until we can do better viewMan->InsertChild(parView, view, nsnull, PR_TRUE); SetView(view); @@ -351,7 +349,7 @@ nsHTMLFramesetFrame::Init(nsPresContext* aPresContext, NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!"); const nsFramesetSpec* rowSpecs = nsnull; const nsFramesetSpec* colSpecs = nsnull; - result = ourContent->GetRowSpec(&mNumRows, &rowSpecs); + nsresult result = ourContent->GetRowSpec(&mNumRows, &rowSpecs); NS_ENSURE_SUCCESS(result, result); result = ourContent->GetColSpec(&mNumCols, &colSpecs); NS_ENSURE_SUCCESS(result, result); diff --git a/mozilla/layout/generic/nsHTMLContainerFrame.cpp b/mozilla/layout/generic/nsHTMLContainerFrame.cpp index 569fc338666..9df92fc2ce2 100644 --- a/mozilla/layout/generic/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/generic/nsHTMLContainerFrame.cpp @@ -54,7 +54,6 @@ #include "nsHTMLParts.h" #include "nsIView.h" #include "nsIViewManager.h" -#include "nsViewsCID.h" #include "nsIDOMEvent.h" #include "nsIScrollableView.h" #include "nsWidgetsCID.h" @@ -548,19 +547,13 @@ nsHTMLContainerFrame::CreateViewForFrame(nsIFrame* aFrame, nsIView* parentView = parent->GetView(); NS_ASSERTION(parentView, "no parent with view"); - // Create a view - static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); - nsIView* view; - nsresult result = CallCreateInstance(kViewCID, &view); - if (NS_FAILED(result)) { - return result; - } - nsIViewManager* viewManager = parentView->GetViewManager(); NS_ASSERTION(viewManager, "null view manager"); - // Initialize the view - view->Init(viewManager, aFrame->GetRect(), parentView); + // Create a view + nsIView* view = viewManager->CreateView(aFrame->GetRect(), parentView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; SyncFrameViewProperties(aFrame->GetPresContext(), aFrame, nsnull, view); diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 7257669cd2e..3548deefb18 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -46,7 +46,6 @@ #include "nsPresContext.h" #include "nsIPresShell.h" #include "nsWidgetsCID.h" -#include "nsViewsCID.h" #include "nsIView.h" #include "nsIViewManager.h" #include "nsIDOMKeyListener.h" @@ -458,7 +457,6 @@ NS_IMETHODIMP nsObjectFrame::GetPluginPort(HWND *aPort) #endif -static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kCAppShellCID, NS_APPSHELL_CID); static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); @@ -755,15 +753,8 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, nscoord aHeight, PRBool aViewOnly) { - nsIView *view; - // Create our view and widget - nsresult result = CallCreateInstance(kViewCID, &view); - if (NS_FAILED(result)) { - return result; - } - nsRect boundBox(0, 0, aWidth, aHeight); nsIView *parView = GetAncestorWithView()->GetView(); @@ -771,12 +762,12 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, // nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted // initialize the view as hidden since we don't know the (x,y) until Paint - result = view->Init(viewMan, boundBox, parView, nsViewVisibility_kHide); + nsIView *view = viewMan->CreateView(boundBox, parView, nsViewVisibility_kHide); // if (nsnull != initData) { // delete(initData); // } - if (NS_FAILED(result)) { + if (!view) { return NS_OK; //XXX why OK? MMP } @@ -808,7 +799,7 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, // Bug 179822: Create widget and allow non-unicode SubClass nsWidgetInitData initData; initData.mUnicode = PR_FALSE; - result = view->CreateWidget(kWidgetCID, &initData); + nsresult result = view->CreateWidget(kWidgetCID, &initData); if (NS_FAILED(result)) { return NS_OK; //XXX why OK? MMP } @@ -846,7 +837,7 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, SetView(view); - return result; + return NS_OK; } #define EMBED_DEF_WIDTH 240 diff --git a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp index 569fc338666..9df92fc2ce2 100644 --- a/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp +++ b/mozilla/layout/html/base/src/nsHTMLContainerFrame.cpp @@ -54,7 +54,6 @@ #include "nsHTMLParts.h" #include "nsIView.h" #include "nsIViewManager.h" -#include "nsViewsCID.h" #include "nsIDOMEvent.h" #include "nsIScrollableView.h" #include "nsWidgetsCID.h" @@ -548,19 +547,13 @@ nsHTMLContainerFrame::CreateViewForFrame(nsIFrame* aFrame, nsIView* parentView = parent->GetView(); NS_ASSERTION(parentView, "no parent with view"); - // Create a view - static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); - nsIView* view; - nsresult result = CallCreateInstance(kViewCID, &view); - if (NS_FAILED(result)) { - return result; - } - nsIViewManager* viewManager = parentView->GetViewManager(); NS_ASSERTION(viewManager, "null view manager"); - // Initialize the view - view->Init(viewManager, aFrame->GetRect(), parentView); + // Create a view + nsIView* view = viewManager->CreateView(aFrame->GetRect(), parentView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; SyncFrameViewProperties(aFrame->GetPresContext(), aFrame, nsnull, view); diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 7257669cd2e..3548deefb18 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -46,7 +46,6 @@ #include "nsPresContext.h" #include "nsIPresShell.h" #include "nsWidgetsCID.h" -#include "nsViewsCID.h" #include "nsIView.h" #include "nsIViewManager.h" #include "nsIDOMKeyListener.h" @@ -458,7 +457,6 @@ NS_IMETHODIMP nsObjectFrame::GetPluginPort(HWND *aPort) #endif -static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); static NS_DEFINE_CID(kCAppShellCID, NS_APPSHELL_CID); static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); @@ -755,15 +753,8 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, nscoord aHeight, PRBool aViewOnly) { - nsIView *view; - // Create our view and widget - nsresult result = CallCreateInstance(kViewCID, &view); - if (NS_FAILED(result)) { - return result; - } - nsRect boundBox(0, 0, aWidth, aHeight); nsIView *parView = GetAncestorWithView()->GetView(); @@ -771,12 +762,12 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, // nsWidgetInitData* initData = GetWidgetInitData(aPresContext); // needs to be deleted // initialize the view as hidden since we don't know the (x,y) until Paint - result = view->Init(viewMan, boundBox, parView, nsViewVisibility_kHide); + nsIView *view = viewMan->CreateView(boundBox, parView, nsViewVisibility_kHide); // if (nsnull != initData) { // delete(initData); // } - if (NS_FAILED(result)) { + if (!view) { return NS_OK; //XXX why OK? MMP } @@ -808,7 +799,7 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, // Bug 179822: Create widget and allow non-unicode SubClass nsWidgetInitData initData; initData.mUnicode = PR_FALSE; - result = view->CreateWidget(kWidgetCID, &initData); + nsresult result = view->CreateWidget(kWidgetCID, &initData); if (NS_FAILED(result)) { return NS_OK; //XXX why OK? MMP } @@ -846,7 +837,7 @@ nsObjectFrame::CreateWidget(nsPresContext* aPresContext, SetView(view); - return result; + return NS_OK; } #define EMBED_DEF_WIDTH 240 diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 7d3ed501c41..21abf1c2674 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -205,7 +205,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 @@ -7026,11 +7025,10 @@ PresShell::VerifyIncrementalReflow() // Create a child window of the parent that is our "root view/window" // Create a view nsRect tbounds = mPresContext->GetVisibleArea(); - nsIView* view; - rv = CallCreateInstance(kViewCID, &view); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create scroll view"); - rv = view->Init(vm, tbounds, nsnull); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to init scroll view"); + nsIView* view = vm->CreateView(tbounds, nsnull); + NS_ASSERTION(view, "failed to create view"); + if (!view) + return PR_FALSE; //now create the widget for the view rv = view->CreateWidget(kWidgetCID, nsnull, nativeParentWidget, PR_TRUE); diff --git a/mozilla/layout/html/document/src/nsFrameFrame.cpp b/mozilla/layout/html/document/src/nsFrameFrame.cpp index 0003f2c5546..b89268ab085 100644 --- a/mozilla/layout/html/document/src/nsFrameFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameFrame.cpp @@ -90,7 +90,6 @@ #endif #include "nsIServiceManager.h" -static NS_DEFINE_CID(kCViewCID, NS_VIEW_CID); static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID); /****************************************************************************** @@ -698,14 +697,6 @@ nsresult nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) { // create, init, set the parent of the view - nsIView* innerView; - nsresult rv = CallCreateInstance(kCViewCID, &innerView); - if (NS_FAILED(rv)) { - NS_ERROR("Could not create inner view"); - return rv; - } - mInnerView = innerView; - nsIView* outerView = GetView(); NS_ASSERTION(outerView, "Must have an outer view already"); nsRect viewBounds(0, 0, 0, 0); // size will be fixed during reflow @@ -713,8 +704,13 @@ nsSubDocumentFrame::CreateViewAndWidget(nsContentType aContentType) nsIViewManager* viewMan = outerView->GetViewManager(); // Create the inner view hidden if the outer view is already hidden // (it won't get hidden properly otherwise) - rv = innerView->Init(viewMan, viewBounds, outerView, - outerView->GetVisibility()); + nsIView* innerView = viewMan->CreateView(viewBounds, outerView, + outerView->GetVisibility()); + if (!innerView) { + NS_ERROR("Could not create inner view"); + return NS_ERROR_OUT_OF_MEMORY; + } + mInnerView = innerView; viewMan->InsertChild(outerView, innerView, nsnull, PR_TRUE); nsWidgetInitData initData; diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp index 1cee639ffe4..59d63a1b7c0 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp @@ -51,7 +51,6 @@ #include "nsIView.h" #include "nsIViewManager.h" #include "nsWidgetsCID.h" -#include "nsViewsCID.h" #include "nsHTMLAtoms.h" #include "nsIScrollableView.h" #include "nsStyleCoord.h" @@ -297,8 +296,6 @@ nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure) return 0; } -static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); - #define FRAMESET 0 #define FRAME 1 #define BLANK 2 @@ -329,13 +326,14 @@ nsHTMLFramesetFrame::Init(nsPresContext* aPresContext, } // create the view. a view is needed since it needs to be a mouse grabber - nsIView* view; - nsresult result = CallCreateInstance(kViewCID, &view); nsIViewManager* viewMan = aPresContext->GetViewManager(); nsIView *parView = GetAncestorWithView()->GetView(); nsRect boundBox(0, 0, 0, 0); - result = view->Init(viewMan, boundBox, parView); + nsIView* view = viewMan->CreateView(boundBox, parView); + if (!view) + return NS_ERROR_OUT_OF_MEMORY; + // XXX Put it last in document order until we can do better viewMan->InsertChild(parView, view, nsnull, PR_TRUE); SetView(view); @@ -351,7 +349,7 @@ nsHTMLFramesetFrame::Init(nsPresContext* aPresContext, NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!"); const nsFramesetSpec* rowSpecs = nsnull; const nsFramesetSpec* colSpecs = nsnull; - result = ourContent->GetRowSpec(&mNumRows, &rowSpecs); + nsresult result = ourContent->GetRowSpec(&mNumRows, &rowSpecs); NS_ENSURE_SUCCESS(result, result); result = ourContent->GetColSpec(&mNumCols, &colSpecs); NS_ENSURE_SUCCESS(result, result); diff --git a/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp b/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp index 287bb1bb147..f17d98c6366 100644 --- a/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp +++ b/mozilla/layout/html/tests/table/TableContentTest/TableContentTest.cpp @@ -477,22 +477,15 @@ GeometryTest::GeometryTest(BasicTest *aDoc) } vm->Init(pc); - nsIView * rootView = nsnull; - - // Create a view - static NS_DEFINE_IID(kScrollingViewCID, NS_SCROLL_PORT_VIEW_CID); - - status = CallCreateInstance(kScrollingViewCID, &rootView); + nsRect bounds(0, 0, 10000, 10000); + nsIScrollableView * rootView = vm->CreateScrollableView(bounds, nsnull); if ((NS_FAILED(status)) || nsnull==rootView) { fprintf(out, "bad view"); NS_ASSERTION(PR_FALSE, "bad view"); } - nsRect bounds(0, 0, 10000, 10000); - rootView->Init(vm, bounds, nsnull); - - vm->SetRootView(rootView); + vm->SetRootView(rootView->View()); nsCOMPtr ss(do_CreateInstance(kStyleSetCID,&status)); if ((NS_FAILED(status))) diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index f35d6044485..5b452f8dd61 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -226,7 +226,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); @@ -2641,13 +2640,9 @@ 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); - if (NS_FAILED(rv)) { - return rv; + aPO->mRootView = aPO->mViewManager->CreateView(tbounds, nsnull); + if (!aPO->mRootView) { + return NS_ERROR_OUT_OF_MEMORY; } #ifdef NS_PRINT_PREVIEW diff --git a/mozilla/layout/xul/base/src/nsBoxFrame.cpp b/mozilla/layout/xul/base/src/nsBoxFrame.cpp index 9097b94162f..c74f2cf7b3c 100644 --- a/mozilla/layout/xul/base/src/nsBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsBoxFrame.cpp @@ -89,7 +89,6 @@ #include "nsWidgetsCID.h" #include "nsLayoutAtoms.h" #include "nsCSSAnonBoxes.h" -#include "nsViewsCID.h" #include "nsIScrollableView.h" #include "nsHTMLContainerFrame.h" #include "nsIWidget.h" @@ -2440,18 +2439,12 @@ nsBoxFrame::CreateViewForFrame(nsPresContext* aPresContext, NS_ASSERTION(parent, "GetAncestorWithView failed"); nsIView* parentView = parent->GetView(); NS_ASSERTION(parentView, "no parent with view"); + nsIViewManager* viewManager = parentView->GetViewManager(); + NS_ASSERTION(nsnull != viewManager, "null view manager"); // Create a view - static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); - nsIView *view; - nsresult result = CallCreateInstance(kViewCID, &view); - if (NS_SUCCEEDED(result)) { - nsIViewManager* viewManager = parentView->GetViewManager(); - NS_ASSERTION(nsnull != viewManager, "null view manager"); - - // Initialize the view - view->Init(viewManager, aFrame->GetRect(), parentView); - + nsIView *view = viewManager->CreateView(aFrame->GetRect(), parentView); + if (view) { // If the frame has a fixed background attachment, then indicate that the // view's contents should be repainted and not bitblt'd if (fixedBackgroundAttachment) { @@ -2525,7 +2518,8 @@ nsBoxFrame::CreateViewForFrame(nsPresContext* aPresContext, NS_FRAME_LOG(NS_FRAME_TRACE_CALLS, ("nsBoxFrame::CreateViewForFrame: frame=%p view=%p", aFrame)); - return result; + if (!view) + return NS_ERROR_OUT_OF_MEMORY; } } return NS_OK; diff --git a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp index 496b5d6e379..f179717cdb9 100644 --- a/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsScrollBoxFrame.cpp @@ -43,7 +43,6 @@ #include "nsPresContext.h" #include "nsIDeviceContext.h" #include "nsPageFrame.h" -#include "nsViewsCID.h" #include "nsIView.h" #include "nsIViewManager.h" #include "nsHTMLContainerFrame.h" @@ -62,7 +61,6 @@ #include "nsRepeatService.h" static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID); -static NS_DEFINE_IID(kScrollBoxViewCID, NS_SCROLL_PORT_VIEW_CID); //---------------------------------------------------------------------- @@ -224,8 +222,6 @@ nsScrollBoxFrame::GetMouseCapturer() const nsresult nsScrollBoxFrame::CreateScrollingView(nsPresContext* aPresContext) { - nsIView* view; - //Get parent frame nsIFrame* parent = GetAncestorWithView(); NS_ASSERTION(parent, "GetParentWithView failed"); @@ -238,11 +234,11 @@ nsScrollBoxFrame::CreateScrollingView(nsPresContext* aPresContext) nsIViewManager* viewManager = parentView->GetViewManager(); // Create the scrolling view - nsresult rv = CallCreateInstance(kScrollBoxViewCID, &view); + nsIScrollableView* scrollingView = viewManager->CreateScrollableView(mRect, parentView); - if (NS_SUCCEEDED(rv)) { + if (scrollingView) { // Initialize the scrolling view - view->Init(viewManager, mRect, parentView); + nsIView* view = scrollingView->View(); SyncFrameViewProperties(aPresContext, this, mStyleContext, view); @@ -253,10 +249,6 @@ nsScrollBoxFrame::CreateScrollingView(nsPresContext* aPresContext) // If it's fixed positioned, then create a widget too CreateScrollingViewWidget(view, GetStyleDisplay()); - // Get the nsIScrollableView interface - nsIScrollableView* scrollingView; - CallQueryInterface(view, &scrollingView); - // Have the scrolling view create its internal widgets if (NeedsClipWidget()) { scrollingView->CreateScrollControls(); @@ -264,8 +256,10 @@ nsScrollBoxFrame::CreateScrollingView(nsPresContext* aPresContext) // Remember our view SetView(view); + + return NS_OK; } - return rv; + return NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP diff --git a/mozilla/view/public/nsIScrollableView.h b/mozilla/view/public/nsIScrollableView.h index 32f7a372862..5744bd06eb0 100644 --- a/mozilla/view/public/nsIScrollableView.h +++ b/mozilla/view/public/nsIScrollableView.h @@ -51,8 +51,8 @@ struct nsMargin; // IID for the nsIScrollableView interface #define NS_ISCROLLABLEVIEW_IID \ -{ 0x6d63ae50, 0x55c7, 0x47b9, \ -{ 0xad, 0x00, 0xe7, 0xa7, 0x79, 0x1e, 0x3d, 0x87 } } +{ 0x3b88347a, 0x7a86, 0x4eff, \ +{ 0xa8, 0x37, 0xd9, 0xd1, 0x08, 0x8e, 0xc9, 0xa8 } } /** * A scrolling view allows an arbitrary view that you supply to be scrolled diff --git a/mozilla/view/public/nsIView.h b/mozilla/view/public/nsIView.h index 5ac610a2385..0bc9b9973cf 100644 --- a/mozilla/view/public/nsIView.h +++ b/mozilla/view/public/nsIView.h @@ -60,8 +60,8 @@ enum nsViewVisibility { // IID for the nsIView interface #define NS_IVIEW_IID \ -{ 0xf0a21c40, 0xa7e1, 0x11d1, \ -{ 0xa8, 0x24, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } +{ 0x658f72ee, 0x32ef, 0x4e93, \ +{ 0xb8, 0x4e, 0x5f, 0x0f, 0x8f, 0x77, 0xe4, 0x22 } } // Public view flags are defined in this file #define NS_VIEW_FLAGS_PUBLIC 0x00FF @@ -134,25 +134,6 @@ public: nsIViewManager* GetViewManager() const { return NS_REINTERPRET_CAST(nsIViewManager*, mViewManager); } - /** - * Initialize the view - * @param aManager view manager that "owns" the view. The view does NOT - * hold a reference to the view manager - * @param aBounds initial bounds for view - * XXX We should eliminate this parameter; you can set the bounds after Init - * @param aParent intended parent for view. this is not actually set in the - * nsIView through this method. it is only used by the initialization - * code to walk up the view tree, if necessary, to find resources. - * XXX We should eliminate this parameter! - * @param aVisibilityFlag initial visibility state of view - * XXX We should eliminate this parameter; you can set it after Init - * @result The result of the initialization, NS_OK if no errors - */ - nsresult Init(nsIViewManager* aManager, - const nsRect &aBounds, - const nsIView *aParent, - nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow); - /** * Destroy the view. * diff --git a/mozilla/view/public/nsIViewManager.h b/mozilla/view/public/nsIViewManager.h index 25ffd221150..819d5feee2a 100644 --- a/mozilla/view/public/nsIViewManager.h +++ b/mozilla/view/public/nsIViewManager.h @@ -62,8 +62,8 @@ enum nsRectVisibility { #define NS_IVIEWMANAGER_IID \ -{ 0x3a8863d0, 0xa7f3, 0x11d1, \ - { 0xa8, 0x24, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } } +{ 0xd9af8f22, 0xc64d, 0x4036, \ + { 0x9e, 0x8b, 0x69, 0x5a, 0x63, 0x69, 0x3f, 0xd3 } } class nsIViewManager : public nsISupports { @@ -78,6 +78,35 @@ public: */ NS_IMETHOD Init(nsIDeviceContext* aContext) = 0; + /** + * Create an ordinary view + * @param aBounds initial bounds for view + * XXX We should eliminate this parameter; you can set the bounds after CreateView + * @param aParent intended parent for view. this is not actually set in the + * nsIView through this method. it is only used by the initialization + * code to walk up the view tree, if necessary, to find resources. + * XXX We should eliminate this parameter! + * @param aVisibilityFlag initial visibility state of view + * XXX We should eliminate this parameter; you can set it after CreateView + * @result The new view + */ + NS_IMETHOD_(nsIView*) CreateView(const nsRect& aBounds, + const nsIView* aParent, + nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow) = 0; + + /** + * Create an scrollable view + * @param aBounds initial bounds for view + * XXX We should eliminate this parameter; you can set the bounds after CreateScrollableView + * @param aParent intended parent for view. this is not actually set in the + * nsIView through this method. it is only used by the initialization + * code to walk up the view tree, if necessary, to find resources. + * XXX We should eliminate this parameter! + * @result The new view + */ + NS_IMETHOD_(nsIScrollableView*) CreateScrollableView(const nsRect& aBounds, + const nsIView* aParent) = 0; + /** * Get the root of the view tree. * @result the root view diff --git a/mozilla/view/public/nsViewsCID.h b/mozilla/view/public/nsViewsCID.h index 37690083fa6..49b4f905535 100644 --- a/mozilla/view/public/nsViewsCID.h +++ b/mozilla/view/public/nsViewsCID.h @@ -46,12 +46,4 @@ { 0xc95f1831, 0xc376, 0x11d1, \ {0xb7, 0x21, 0x0, 0x60, 0x8, 0x91, 0xd8, 0xc9}} -#define NS_VIEW_CID \ -{ 0xc95f1832, 0xc376, 0x11d1, \ - {0xb7, 0x21, 0x0, 0x60, 0x8, 0x91, 0xd8, 0xc9}} - -#define NS_SCROLL_PORT_VIEW_CID \ -{ 0x3b733c91, 0x7223, 0x11d3, \ - { 0xb3, 0x61, 0x0, 0xa0, 0xcc, 0x3c, 0x1c, 0xde }} - #endif // nsViewsCID_h__ diff --git a/mozilla/view/src/nsScrollPortView.cpp b/mozilla/view/src/nsScrollPortView.cpp index 9265a45a619..49b132febdf 100644 --- a/mozilla/view/src/nsScrollPortView.cpp +++ b/mozilla/view/src/nsScrollPortView.cpp @@ -77,7 +77,8 @@ public: nscoord mDestinationY; }; -nsScrollPortView::nsScrollPortView() +nsScrollPortView::nsScrollPortView(nsViewManager* aViewManager) + : nsView(aViewManager) { mOffsetX = mOffsetY = 0; mOffsetXpx = mOffsetYpx = 0; diff --git a/mozilla/view/src/nsView.cpp b/mozilla/view/src/nsView.cpp index 164ec4720b1..0b0a8ee0a62 100644 --- a/mozilla/view/src/nsView.cpp +++ b/mozilla/view/src/nsView.cpp @@ -168,18 +168,18 @@ nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent) MOZ_DECL_CTOR_COUNTER(nsView) -nsView::nsView() +nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility) { MOZ_COUNT_CTOR(nsView); - mVis = nsViewVisibility_kShow; + mVis = aVisibility; // Views should be transparent by default. Not being transparent is // a promise that the view will paint all its pixels opaquely. Views // should make this promise explicitly by calling // SetViewContentTransparency. mVFlags = NS_VIEW_FLAG_TRANSPARENT; mOpacity = 1.0f; - mViewManager = nsnull; + mViewManager = aViewManager; mChildRemoved = PR_FALSE; mDirtyRegion = nsnull; } @@ -291,34 +291,6 @@ nsView* nsView::GetViewFor(nsIWidget* aWidget) return nsnull; } -nsresult nsIView::Init(nsIViewManager* aManager, - const nsRect &aBounds, - const nsIView *aParent, - nsViewVisibility aVisibilityFlag) -{ - //printf(" \n callback=%d data=%d", aWidgetCreateCallback, aCallbackData); - NS_PRECONDITION(nsnull != aManager, "null ptr"); - if (nsnull == aManager) { - return NS_ERROR_NULL_POINTER; - } - if (nsnull != mViewManager) { - return NS_ERROR_ALREADY_INITIALIZED; - } - // we don't hold a reference to the view manager - mViewManager = NS_STATIC_CAST(nsViewManager*, aManager); - - nsView* v = NS_STATIC_CAST(nsView*, this); - v->SetPosition(aBounds.x, aBounds.y); - nsRect dim(0, 0, aBounds.width, aBounds.height); - v->SetDimensions(dim, PR_FALSE); - v->SetVisibility(aVisibilityFlag); - - // We shouldn't set the parent here. It should be set when we put this view - // into the view hierarchy. - v->SetParent(NS_STATIC_CAST(nsView*, NS_CONST_CAST(nsIView*, aParent))); - return NS_OK; -} - void nsIView::Destroy() { delete this; diff --git a/mozilla/view/src/nsView.h b/mozilla/view/src/nsView.h index 70b2e603d1d..d1f0c4263b0 100644 --- a/mozilla/view/src/nsView.h +++ b/mozilla/view/src/nsView.h @@ -84,7 +84,8 @@ class nsZPlaceholderView; class nsView : public nsIView { public: - nsView(); + nsView(nsViewManager* aViewManager = nsnull, + nsViewVisibility aVisibility = nsViewVisibility_kShow); NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index a8bf2884353..7514094d840 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -602,6 +602,35 @@ NS_IMETHODIMP nsViewManager::Init(nsIDeviceContext* aContext) return NS_OK; } +NS_IMETHODIMP_(nsIView *) +nsViewManager::CreateView(const nsRect& aBounds, + const nsIView* aParent, + nsViewVisibility aVisibilityFlag) +{ + nsView *v = new nsView(this, aVisibilityFlag); + if (v) { + v->SetPosition(aBounds.x, aBounds.y); + nsRect dim(0, 0, aBounds.width, aBounds.height); + v->SetDimensions(dim, PR_FALSE); + v->SetParent(NS_STATIC_CAST(nsView*, NS_CONST_CAST(nsIView*, aParent))); + } + return v; +} + +NS_IMETHODIMP_(nsIScrollableView *) +nsViewManager::CreateScrollableView(const nsRect& aBounds, + const nsIView* aParent) +{ + nsScrollPortView *v = new nsScrollPortView(this); + if (v) { + v->SetPosition(aBounds.x, aBounds.y); + nsRect dim(0, 0, aBounds.width, aBounds.height); + v->SetDimensions(dim, PR_FALSE); + v->SetParent(NS_STATIC_CAST(nsView*, NS_CONST_CAST(nsIView*, aParent))); + } + return v; +} + NS_IMETHODIMP nsViewManager::GetRootView(nsIView *&aView) { aView = mRootView; @@ -2607,10 +2636,9 @@ NS_IMETHODIMP nsViewManager::InsertZPlaceholder(nsIView *aParent, nsIView *aChil NS_PRECONDITION(nsnull != parent, "null ptr"); NS_PRECONDITION(nsnull != child, "null ptr"); - nsZPlaceholderView* placeholder = new nsZPlaceholderView(); - nsRect bounds(0, 0, 0, 0); + nsZPlaceholderView* placeholder = new nsZPlaceholderView(this); // mark the placeholder as "shown" so that it will be included in a built display list - placeholder->Init(this, bounds, parent, nsViewVisibility_kShow); + placeholder->SetParent(parent); placeholder->SetReparentedView(child); placeholder->SetZIndex(child->GetZIndexIsAuto(), child->GetZIndex(), child->IsTopMost()); child->SetZParent(placeholder); diff --git a/mozilla/view/src/nsViewManager.h b/mozilla/view/src/nsViewManager.h index cc14dab6249..887b17ef6d2 100644 --- a/mozilla/view/src/nsViewManager.h +++ b/mozilla/view/src/nsViewManager.h @@ -126,7 +126,7 @@ class nsHashtable; class nsZPlaceholderView : public nsView { public: - nsZPlaceholderView() : nsView() {} + nsZPlaceholderView(nsViewManager* aViewManager) : nsView(aViewManager) {} void RemoveReparentedView() { mReparentedView = nsnull; } void SetReparentedView(nsView* aView) { mReparentedView = aView; } @@ -155,6 +155,13 @@ public: NS_IMETHOD Init(nsIDeviceContext* aContext); + NS_IMETHOD_(nsIView*) CreateView(const nsRect& aBounds, + const nsIView* aParent, + nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow); + + NS_IMETHOD_(nsIScrollableView*) CreateScrollableView(const nsRect& aBounds, + const nsIView* aParent); + NS_IMETHOD GetRootView(nsIView *&aView); NS_IMETHOD SetRootView(nsIView *aView);