diff --git a/mozilla/layout/html/document/src/nsHTMLIFrame.cpp b/mozilla/layout/html/document/src/nsHTMLIFrame.cpp index 40cfa8f59e5..047825b4e50 100644 --- a/mozilla/layout/html/document/src/nsHTMLIFrame.cpp +++ b/mozilla/layout/html/document/src/nsHTMLIFrame.cpp @@ -20,6 +20,7 @@ #include "nsLeafFrame.h" #include "nsIWebWidget.h" #include "nsIPresContext.h" +#include "nsIPresShell.h" #include "nsHTMLIIDs.h" #include "nsRepository.h" #include "nsIStreamListener.h" @@ -27,12 +28,19 @@ #include "nsIDocument.h" #include "nsIWebFrame.h" #include "nsIView.h" +#include "nsIViewManager.h" +#include "nsWidgetsCID.h" +#include "nsViewsCID.h" +#include "nsHTMLAToms.h" static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMNOTIFICATION_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIWebWidgetIID, NS_IWEBWIDGET_IID); static NS_DEFINE_IID(kIWebFrameIID, NS_IWEBFRAME_IID); static NS_DEFINE_IID(kCWebWidgetCID, NS_WEBWIDGET_CID); +static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID); +static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID); +static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID); // XXX temporary until doc manager/loader is in place class TempObserver : public nsIStreamListener @@ -97,7 +105,7 @@ protected: const nsReflowState& aReflowState, nsReflowMetrics& aDesiredSize); - void CreateWebWidget(nscoord aWidgth, nscoord aHeight, nsString& aURL); + void CreateWebWidget(nsSize aSize, nsString& aURL); nsIWebWidget* mWebWidget; @@ -113,6 +121,9 @@ public: nsIStyleContext* aStyleContext, nsIFrame*& aResult); + void GetSize(float aPixelsToTwips, nsSize& aSize); + PRBool GetURL(nsString& aURLSpec); + #if 0 virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, nsHTMLValue& aValue) const; @@ -123,7 +134,7 @@ public: protected: nsHTMLIFrame(nsIAtom* aTag); virtual ~nsHTMLIFrame(); - + friend nsresult NS_NewHTMLIFrame(nsIHTMLContent** aInstancePtrResult, nsIAtom* aTag); @@ -205,51 +216,13 @@ float nsHTMLIFrameFrame::GetTwipsToPixels() NS_METHOD nsHTMLIFrameFrame::MoveTo(nscoord aX, nscoord aY) { -printf("MoveTo %d %d \n", aX, aY); - if ((aX != mRect.x) || (aY != mRect.y)) { - mRect.x = aX; - mRect.y = aY; - if (mWebWidget) { - float t2p = GetTwipsToPixels(); - mWebWidget->Move(NS_TO_INT_ROUND(t2p * aX), - NS_TO_INT_ROUND(t2p * aY)); - } -#if 0 - // Let the view know - nsIView* view = nsnull; - GetView(view); - if (nsnull != view) { - // Position view relative to it's parent, not relative to our - // parent frame (our parent frame may not have a view). Also, - // inset the view by the border+padding if present - nsIView* parentWithView; - nsPoint origin; - GetOffsetFromView(origin, parentWithView); - view->SetPosition(origin.x, origin.y); - NS_IF_RELEASE(parentWithView); - NS_RELEASE(view); - } -#endif - } - return NS_OK; + return nsLeafFrame::MoveTo(aX, aY); } NS_METHOD nsHTMLIFrameFrame::SizeTo(nscoord aWidth, nscoord aHeight) { - mRect.width = aWidth; - mRect.height = aHeight; -#if 0 - // Let the view know the correct size - nsIView* view = nsnull; - GetView(view); - if (nsnull != view) { - // XXX combo boxes need revision, they cannot have their height altered - view->SetDimensions(aWidth, aHeight); - NS_RELEASE(view); - } -#endif - return NS_OK; + return nsLeafFrame::SizeTo(aWidth, aWidth); } NS_IMETHODIMP @@ -257,7 +230,7 @@ nsHTMLIFrameFrame::Paint(nsIPresContext& aPresContext, nsIRenderingContext& aRenderingContext, const nsRect& aDirtyRect) { - //mWebWidget->Show(); + mWebWidget->Show(); return NS_OK; } @@ -277,8 +250,9 @@ void TempMakeAbsURL(nsIContent* aContent, nsString& aRelURL, nsString& aAbsURL) NS_IF_RELEASE(docURL); } -void nsHTMLIFrameFrame::CreateWebWidget(nscoord aWidth, nscoord aHeight, nsString& aURL) +void nsHTMLIFrameFrame::CreateWebWidget(nsSize aSize, nsString& aURL) { + // create the web widget NSRepository::CreateInstance(kCWebWidgetCID, nsnull, kIWebWidgetIID, (void**)&mWebWidget); if (nsnull == mWebWidget) { @@ -287,15 +261,16 @@ void nsHTMLIFrameFrame::CreateWebWidget(nscoord aWidth, nscoord aHeight, nsStrin } nsresult result; - // Get the parent web widget + // Get the parent web widget, set the parentage nsIFrame* parent; - GetGeometricParent(parent); + GetGeometricParent(parent); // don't need to release nsIWebWidget* parentWebWidget = nsnull; while (nsnull != parent) { - nsIWebFrame* webFrame; + nsIWebFrame* webFrame; result = parent->QueryInterface(kIWebFrameIID, (void**)&webFrame); if (NS_OK == result) { parentWebWidget = webFrame->GetWebWidget(); + NS_RELEASE(webFrame); break; } parent->GetGeometricParent(parent); @@ -305,30 +280,50 @@ void nsHTMLIFrameFrame::CreateWebWidget(nscoord aWidth, nscoord aHeight, nsStrin } mWebWidget->SetContainer(parentWebWidget); + // Get the view manager, conversion + float t2p = 0.0f; + nsIViewManager* viewMan = nsnull; + nsIPresContext* presContext = parentWebWidget->GetPresContext(); + t2p = presContext->GetTwipsToPixels(); + nsIPresShell *presShell = presContext->GetShell(); + viewMan = presShell->GetViewManager(); + NS_RELEASE(presShell); + NS_RELEASE(presContext); + NS_RELEASE(parentWebWidget); - float t2p = presContext->GetTwipsToPixels(); - nsIView* parentWithView; + // create, init, set the parent of the view + nsIView* view; + result = NSRepository::CreateInstance(kCViewCID, nsnull, kIViewIID, + (void **)&view); + if (NS_OK != result) { + NS_ASSERTION(0, "Could not create view for nsHTMLIFrame"); + return; + } + + nsIView* parView; nsPoint origin; - GetOffsetFromView(origin, parentWithView); - //view->SetPosition(origin.x, origin.y); - NS_IF_RELEASE(parentWithView); - //NS_RELEASE(view); + GetOffsetFromView(origin, parView); + nsRect viewBounds(origin.x, origin.y, aSize.width, aSize.height); - - nsRect rect(NS_TO_INT_ROUND(origin.x * t2p), NS_TO_INT_ROUND(origin.y * t2p), - NS_TO_INT_ROUND(aWidth * t2p), NS_TO_INT_ROUND(aHeight * t2p)); - nsIWidget* parentWin; - GetWindow(parentWin); - mWebWidget->Init(parentWin->GetNativeData(NS_NATIVE_WINDOW), rect); - NS_IF_RELEASE(parentWin); + result = view->Init(viewMan, viewBounds, parView, &kCChildCID); + viewMan->InsertChild(parView, view, 0); + NS_RELEASE(viewMan); + NS_RELEASE(parView); + + // init the web widget + nsIWidget* widget = view->GetWidget(); + NS_RELEASE(view); + nsRect webBounds(0, 0, NS_TO_INT_ROUND(aSize.width * t2p), + NS_TO_INT_ROUND(aSize.height * t2p)); + mWebWidget->Init(widget->GetNativeData(NS_NATIVE_WINDOW), webBounds); + NS_RELEASE(widget); // load the document nsString absURL; TempMakeAbsURL(mContent, aURL, absURL); mWebWidget->LoadURL(absURL, mTempObserver); - //mWebWidget->Show(); } NS_IMETHODIMP @@ -340,8 +335,11 @@ nsHTMLIFrameFrame::Reflow(nsIPresContext* aPresContext, GetDesiredSize(aPresContext, aReflowState, aDesiredSize); if (nsnull == mWebWidget) { - nsAutoString url("test9a.html"); - CreateWebWidget(aDesiredSize.width, aDesiredSize.height, url); + nsHTMLIFrame* content = (nsHTMLIFrame*)mContent; + nsAutoString url; + content->GetURL(url); + nsSize size(aDesiredSize.width, aDesiredSize.height); + CreateWebWidget(size, url); mWebWidget->Show(); } aStatus = NS_FRAME_COMPLETE; @@ -353,9 +351,10 @@ nsHTMLIFrameFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsReflowState& aReflowState, nsReflowMetrics& aDesiredSize) { - float p2t = aPresContext->GetPixelsToTwips(); - aDesiredSize.width = (int) (p2t * 200); - aDesiredSize.height = (int) (p2t * 200); + nsSize size; + ((nsHTMLIFrame*)mContent)->GetSize(aPresContext->GetPixelsToTwips(), size); + aDesiredSize.width = size.width; + aDesiredSize.height = size.height; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; } @@ -384,6 +383,52 @@ nsHTMLIFrame::CreateFrame(nsIPresContext* aPresContext, return NS_OK; } +void nsHTMLIFrame::GetSize(float aPixelsToTwips, nsSize& aSize) +{ + aSize.width = 200; + aSize.height = 200; + + PRInt32 status; + nsHTMLValue htmlVal; + nsAutoString stringVal; + PRInt32 intVal; + + if (eContentAttr_HasValue == (GetAttribute(nsHTMLAtoms::width, htmlVal))) { + if (eHTMLUnit_String == htmlVal.GetUnit()) { + htmlVal.GetStringValue(stringVal); + intVal = stringVal.ToInteger(&status); + if (NS_OK == status) { + aSize.width = intVal; + } + } + } + if (eContentAttr_HasValue == (GetAttribute(nsHTMLAtoms::height, htmlVal))) { + if (eHTMLUnit_String == htmlVal.GetUnit()) { + htmlVal.GetStringValue(stringVal); + intVal = stringVal.ToInteger(&status); + if (NS_OK == status) { + aSize.height = intVal; + } + } + } + + aSize.width = (nscoord)(aSize.width * aPixelsToTwips + 0.5); + aSize.height = (nscoord)(aSize.height * aPixelsToTwips + 0.5); +} + +PRBool nsHTMLIFrame::GetURL(nsString& aURLSpec) +{ + nsHTMLValue value; + if (eContentAttr_HasValue == (GetAttribute(nsHTMLAtoms::src, value))) { + if (eHTMLUnit_String == value.GetUnit()) { + value.GetStringValue(aURLSpec); + return PR_TRUE; + } + } + aURLSpec.SetLength(0); + return PR_FALSE; +} + nsresult NS_NewHTMLIFrame(nsIHTMLContent** aInstancePtrResult, nsIAtom* aTag) diff --git a/mozilla/webshell/tests/viewer/Makefile b/mozilla/webshell/tests/viewer/Makefile index 735ceb2d2bf..3a27768cef1 100644 --- a/mozilla/webshell/tests/viewer/Makefile +++ b/mozilla/webshell/tests/viewer/Makefile @@ -140,6 +140,8 @@ install:: $(TARGETS) $(INSTALL) samples/test8siz.html $(DIST)/bin/res/samples $(INSTALL) samples/test8sca.html $(DIST)/bin/res/samples $(INSTALL) samples/test8tab.html $(DIST)/bin/res/samples + $(INSTALL) samples/test9.html $(DIST)/bin/res/samples + $(INSTALL) samples/test9a.html $(DIST)/bin/res/samples $(INSTALL) samples/raptor.jpg $(DIST)/bin/res/samples $(INSTALL) samples/Anieyes.gif $(DIST)/bin/res/samples $(INSTALL) samples/gear1.gif $(DIST)/bin/res/samples @@ -157,6 +159,11 @@ clobber:: rm -f $(DIST)/bin/res/samples/test6.html rm -f $(DIST)/bin/res/samples/test7.html rm -f $(DIST)/bin/res/samples/test8.html + rm -f $(DIST)/bin/res/samples/test8siz.html + rm -f $(DIST)/bin/res/samples/test8sca.html + rm -f $(DIST)/bin/res/samples/test8tab.html + rm -f $(DIST)/bin/res/samples/test9.html + rm -f $(DIST)/bin/res/samples/test9a.html rm -f $(DIST)/bin/res/samples/raptor.jpg rm -f $(DIST)/bin/res/samples/Anieyes.gif rm -f $(DIST)/bin/res/samples/gear1.gif diff --git a/mozilla/webshell/tests/viewer/makefile.win b/mozilla/webshell/tests/viewer/makefile.win index 6e723bd9214..7549b279865 100644 --- a/mozilla/webshell/tests/viewer/makefile.win +++ b/mozilla/webshell/tests/viewer/makefile.win @@ -77,6 +77,8 @@ install:: $(PROGRAM) $(MAKE_INSTALL) samples\test8siz.html $(DIST)\bin\res\samples $(MAKE_INSTALL) samples\test8sca.html $(DIST)\bin\res\samples $(MAKE_INSTALL) samples\test8tab.html $(DIST)\bin\res\samples + $(MAKE_INSTALL) samples\test9.html $(DIST)\bin\res\samples + $(MAKE_INSTALL) samples\test9a.html $(DIST)\bin\res\samples $(MAKE_INSTALL) samples\raptor.jpg $(DIST)\bin\res\samples $(MAKE_INSTALL) samples\Anieyes.gif $(DIST)\bin\res\samples $(MAKE_INSTALL) samples\gear1.gif $(DIST)\bin\res\samples @@ -94,6 +96,11 @@ clobber:: rm -f $(DIST)\bin\res\samples\test6.html rm -f $(DIST)\bin\res\samples\test7.html rm -f $(DIST)\bin\res\samples\test8.html + rm -f $(DIST)\bin\res\samples\test8siz.html + rm -f $(DIST)\bin\res\samples\test8sca.html + rm -f $(DIST)\bin\res\samples\test8tab.html + rm -f $(DIST)\bin\res\samples\test9.html + rm -f $(DIST)\bin\res\samples\test9a.html rm -f $(DIST)\bin\res\samples\raptor.jpg rm -f $(DIST)\bin\res\samples\Anieyes.gif rm -f $(DIST)\bin\res\samples\gear1.gif diff --git a/mozilla/webshell/tests/viewer/nsViewer.cpp b/mozilla/webshell/tests/viewer/nsViewer.cpp index 0389793eed0..aa9013cfedd 100644 --- a/mozilla/webshell/tests/viewer/nsViewer.cpp +++ b/mozilla/webshell/tests/viewer/nsViewer.cpp @@ -948,6 +948,7 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd) case VIEWER_DEMO6: case VIEWER_DEMO7: case VIEWER_DEMO8: + case VIEWER_DEMO9: if ((nsnull != wd) && (nsnull != wd->ww)) { PRIntn ix = aId - VIEWER_DEMO0; char* url = new char[500]; diff --git a/mozilla/webshell/tests/viewer/resources.h b/mozilla/webshell/tests/viewer/resources.h index 8e47a313d0e..4b07ad013a2 100644 --- a/mozilla/webshell/tests/viewer/resources.h +++ b/mozilla/webshell/tests/viewer/resources.h @@ -35,23 +35,24 @@ #define VIEWER_DEMO6 40017 #define VIEWER_DEMO7 40018 #define VIEWER_DEMO8 40019 +#define VIEWER_DEMO9 40020 -#define VIEWER_VISUAL_DEBUGGING 40020 -#define VIEWER_REFLOW_TEST 40021 -#define VIEWER_DUMP_CONTENT 40022 -#define VIEWER_DUMP_FRAMES 40023 -#define VIEWER_DUMP_VIEWS 40024 -#define VIEWER_DUMP_STYLE_SHEETS 40025 -#define VIEWER_DUMP_STYLE_CONTEXTS 40026 -#define VIEWER_DEBUGROBOT 40027 -#define VIEWER_SHOW_CONTENT_SIZE 40028 -#define VIEWER_SHOW_FRAME_SIZE 40029 -#define VIEWER_SHOW_STYLE_SIZE 40030 +#define VIEWER_VISUAL_DEBUGGING 40021 +#define VIEWER_REFLOW_TEST 40022 +#define VIEWER_DUMP_CONTENT 40023 +#define VIEWER_DUMP_FRAMES 40024 +#define VIEWER_DUMP_VIEWS 40025 +#define VIEWER_DUMP_STYLE_SHEETS 40026 +#define VIEWER_DUMP_STYLE_CONTEXTS 40027 +#define VIEWER_DEBUGROBOT 40028 +#define VIEWER_SHOW_CONTENT_SIZE 40029 +#define VIEWER_SHOW_FRAME_SIZE 40030 +#define VIEWER_SHOW_STYLE_SIZE 40031 // Note: must be in ascending sequential order -#define VIEWER_ONE_COLUMN 40031 -#define VIEWER_TWO_COLUMN 40032 -#define VIEWER_THREE_COLUMN 40033 +#define VIEWER_ONE_COLUMN 40032 +#define VIEWER_TWO_COLUMN 40033 +#define VIEWER_THREE_COLUMN 40034 #define JS_CONSOLE 40100 diff --git a/mozilla/webshell/tests/viewer/samples/test9.html b/mozilla/webshell/tests/viewer/samples/test9.html index 6cb49ac9f50..1a2aac8d1eb 100644 --- a/mozilla/webshell/tests/viewer/samples/test9.html +++ b/mozilla/webshell/tests/viewer/samples/test9.html @@ -5,6 +5,8 @@

Example 9: Frames

-before +hello +  + diff --git a/mozilla/webshell/tests/viewer/samples/test9a.html b/mozilla/webshell/tests/viewer/samples/test9a.html index c6e49000ac1..d733dfb0d27 100644 --- a/mozilla/webshell/tests/viewer/samples/test9a.html +++ b/mozilla/webshell/tests/viewer/samples/test9a.html @@ -1,47 +1,7 @@ -
- -
-this is the contents of bar1 -
-this is the contents of bar2 -
-this is the contents of bar3 -
-this is the contents of bar4 -
-this is the contents of bar5 -
-this is the contents of bar6 -
-this is the contents of bar7 -
-this is the contents of bar8 -
-this is the contents of bar9 -
-this is the contents of bar10 -
-this is the contents of bar11 -
-this is the contents of bar12 -
-this is the contents of bar13 -
-this is the contents of bar14 -
-this is the contents of bar15 -
-this is the contents of bar16 -
-this is the contents of bar17 -
-this is the contents of bar17 -
-this is the contents of bar19 -
-this is the contents of bar20 -
+a frame within a frame +  + diff --git a/mozilla/webshell/tests/viewer/viewer.rc b/mozilla/webshell/tests/viewer/viewer.rc index 9e6464c2278..1caaa673f21 100644 --- a/mozilla/webshell/tests/viewer/viewer.rc +++ b/mozilla/webshell/tests/viewer/viewer.rc @@ -36,7 +36,8 @@ VIEWER MENU DISCARDABLE MENUITEM "demo #6", VIEWER_DEMO6 MENUITEM "demo #7", VIEWER_DEMO7 MENUITEM "demo #8", VIEWER_DEMO8 - } + MENUITEM "demo #9", VIEWER_DEMO9 + } POPUP "Print &Preview" { MENUITEM "One Column", VIEWER_ONE_COLUMN