more <iframe> support

git-svn-id: svn://10.0.0.236/trunk@3923 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
karnaze
1998-06-16 21:32:54 +00:00
parent 40dcf39805
commit f37ddeefc2
11 changed files with 426 additions and 28 deletions

View File

@@ -0,0 +1,25 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
EXPORTS=nsIWebFrame.h
MODULE=raptor
include <$(DEPTH)\layout\config\rules.mak>

View File

@@ -0,0 +1,28 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../../../..
EXPORTS = \
nsIWebFrame.h \
$(NULL)
MODULE = raptor
include $(DEPTH)/config/config.mk
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,25 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..\..
EXPORTS=nsIWebFrame.h
MODULE=raptor
include <$(DEPTH)\layout\config\rules.mak>

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIWebFrame_h___
#define nsIWebFrame_h___
#include "nsCom.h"
#include "nsISupports.h"
#include "nsIWebWidget.h"
// IID for the nsIWebFrame interface
#define NS_IWEBFRAME_IID \
{ 0xecace1b0, 0x541, 0x11d2, \
{ 0x80, 0x34, 0x0, 0x60, 0x8, 0x15, 0xa7, 0x91 } }
/**
* Interface used for distinguishing frames that have web widgets associated
* with them (i.e. <iframe>, <frame>)
*/
class nsIWebFrame : public nsISupports {
public:
/**
* Get the associated web widget and increment the ref count.
*/
virtual nsIWebWidget* GetWebWidget() = 0;
};
#endif /* nsIWebWidget_h___ */

View File

@@ -26,7 +26,7 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS=nsHTMLContentSink.cpp nsHTMLDocument.cpp nsHTMLIFrame.cpp
CPP_OBJS=.\$(OBJDIR)\nsHTMLContentSink.obj \
.\$(OBJDIR)\nsHTMLDocument.obj nsHTMLIFrame.obj
.\$(OBJDIR)\nsHTMLDocument.obj .\$(OBJDIR)\nsHTMLIFrame.obj
EXPORTS = \
nsIHTMLDocument.h \

View File

@@ -25,6 +25,14 @@
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsIDocument.h"
#include "nsIWebFrame.h"
#include "nsIView.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);
// XXX temporary until doc manager/loader is in place
class TempObserver : public nsIStreamListener
@@ -51,7 +59,7 @@ protected:
nsString mOverTarget;
};
class nsHTMLIFrameFrame : public nsLeafFrame {
class nsHTMLIFrameFrame : public nsLeafFrame, public nsIWebFrame {
public:
@@ -72,6 +80,14 @@ public:
const nsReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD MoveTo(nscoord aX, nscoord aY);
NS_IMETHOD SizeTo(nscoord aWidth, nscoord aHeight);
virtual nsIWebWidget* GetWebWidget();
float GetTwipsToPixels();
NS_DECL_ISUPPORTS
protected:
@@ -81,7 +97,11 @@ protected:
const nsReflowState& aReflowState,
nsReflowMetrics& aDesiredSize);
void CreateWebWidget(nscoord aWidgth, nscoord aHeight, nsString& aURL);
nsIWebWidget* mWebWidget;
// XXX fix these
TempObserver* mTempObserver;
};
@@ -124,12 +144,120 @@ nsHTMLIFrameFrame::~nsHTMLIFrameFrame()
delete mTempObserver;
}
NS_IMPL_ADDREF(nsHTMLIFrameFrame);
NS_IMPL_RELEASE(nsHTMLIFrameFrame);
nsresult
nsHTMLIFrameFrame::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIWebFrameIID)) {
*aInstancePtrResult = (void*) ((nsIWebFrame*)this);
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtrResult = (void*) ((nsISupports*)((nsIWebFrame*)this));
AddRef();
return NS_OK;
}
return nsLeafFrame::QueryInterface(aIID, aInstancePtrResult);
}
nsIWebWidget* nsHTMLIFrameFrame::GetWebWidget()
{
NS_IF_ADDREF(mWebWidget);
return mWebWidget;
}
float nsHTMLIFrameFrame::GetTwipsToPixels()
{
nsISupports* parentSup;
if (mWebWidget) {
mWebWidget->GetContainer(&parentSup);
if (parentSup) {
nsIWebWidget* parentWidget;
nsresult res = parentSup->QueryInterface(kIWebWidgetIID, (void**)&parentWidget);
NS_RELEASE(parentSup);
if (NS_OK == res) {
nsIPresContext* presContext = parentWidget->GetPresContext();
NS_RELEASE(parentWidget);
if (presContext) {
float ret = presContext->GetTwipsToPixels();
NS_RELEASE(presContext);
return ret;
}
} else {
NS_ASSERTION(0, "invalid web widget container");
}
} else {
NS_ASSERTION(0, "invalid web widget container");
}
}
return (float)0.05; // this should not be reached
}
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;
}
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;
}
NS_IMETHODIMP
nsHTMLIFrameFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
mWebWidget->Show();
//mWebWidget->Show();
return NS_OK;
}
@@ -149,8 +277,59 @@ void TempMakeAbsURL(nsIContent* aContent, nsString& aRelURL, nsString& aAbsURL)
NS_IF_RELEASE(docURL);
}
static NS_DEFINE_IID(kCWebWidget, NS_WEBWIDGET_CID);
static NS_DEFINE_IID(kIWebWidget, NS_IWEBWIDGET_IID);
void nsHTMLIFrameFrame::CreateWebWidget(nscoord aWidth, nscoord aHeight, nsString& aURL)
{
NSRepository::CreateInstance(kCWebWidgetCID, nsnull, kIWebWidgetIID, (void**)&mWebWidget);
if (nsnull == mWebWidget) {
NS_ASSERTION(0, "could not create web widget");
return;
}
nsresult result;
// Get the parent web widget
nsIFrame* parent;
GetGeometricParent(parent);
nsIWebWidget* parentWebWidget = nsnull;
while (nsnull != parent) {
nsIWebFrame* webFrame;
result = parent->QueryInterface(kIWebFrameIID, (void**)&webFrame);
if (NS_OK == result) {
parentWebWidget = webFrame->GetWebWidget();
break;
}
parent->GetGeometricParent(parent);
}
if (!parentWebWidget) {
parentWebWidget = mWebWidget->GetRootWebWidget();
}
mWebWidget->SetContainer(parentWebWidget);
nsIPresContext* presContext = parentWebWidget->GetPresContext();
float t2p = presContext->GetTwipsToPixels();
nsIView* parentWithView;
nsPoint origin;
GetOffsetFromView(origin, parentWithView);
//view->SetPosition(origin.x, origin.y);
NS_IF_RELEASE(parentWithView);
//NS_RELEASE(view);
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);
// load the document
nsString absURL;
TempMakeAbsURL(mContent, aURL, absURL);
mWebWidget->LoadURL(absURL, mTempObserver);
//mWebWidget->Show();
}
NS_IMETHODIMP
nsHTMLIFrameFrame::Reflow(nsIPresContext* aPresContext,
@@ -161,25 +340,9 @@ nsHTMLIFrameFrame::Reflow(nsIPresContext* aPresContext,
GetDesiredSize(aPresContext, aReflowState, aDesiredSize);
if (nsnull == mWebWidget) {
NSRepository::CreateInstance(kCWebWidget, nsnull, kIWebWidget, (void**)&mWebWidget);
if (nsnull != mWebWidget) {
float t2p = aPresContext->GetTwipsToPixels();
nsRect rect(0, 0, NS_TO_INT_ROUND(aDesiredSize.width * t2p),
NS_TO_INT_ROUND(aDesiredSize.height * t2p));
nsIWidget* parentWin;
GetWindow(parentWin);
mWebWidget->Init(parentWin->GetNativeData(NS_NATIVE_WINDOW), rect);
NS_IF_RELEASE(parentWin);
nsString absURL;
nsAutoString relURL("bar.html");
TempMakeAbsURL(mContent, relURL, absURL);
mWebWidget->LoadURL(absURL, mTempObserver);
mWebWidget->Show();
}
else {
NS_ASSERTION(0, "could not instantiate web widget for sub document");
}
nsAutoString url("test9a.html");
CreateWebWidget(aDesiredSize.width, aDesiredSize.height, url);
mWebWidget->Show();
}
aStatus = NS_FRAME_COMPLETE;
return NS_OK;
@@ -243,9 +406,6 @@ NS_NewHTMLIFrame(nsIHTMLContent** aInstancePtrResult,
// XXX temp implementation
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMNOTIFICATION_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_IMPL_ADDREF(TempObserver);
NS_IMPL_RELEASE(TempObserver);

View File

@@ -38,6 +38,8 @@ public:
virtual void SetBounds(const nsRect& aBounds) = 0;
virtual void Move(PRInt32 aX, PRInt32 aY) = 0;
virtual void Show() = 0;
virtual void Hide() = 0;

View File

@@ -59,6 +59,10 @@ public:
NS_IMETHOD GetContainer(nsISupports** aResult) = 0;
// XXX temp hack
virtual void SetRootWebWidget(nsIWebWidget* aWebWidget) = 0;
virtual nsIWebWidget* GetRootWebWidget() = 0;
NS_IMETHOD SetLinkHandler(nsILinkHandler* aHandler) = 0;
NS_IMETHOD GetLinkHandler(nsILinkHandler** aResult) = 0;
@@ -85,6 +89,8 @@ public:
NS_IMETHOD ReleaseScriptContext() = 0;
virtual nsIPresContext* GetPresContext() = 0;
};
// Create a new web widget that uses the default (galley) presentation

View File

@@ -24,6 +24,7 @@
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIFrame.h"
#include "nsIWebFrame.h"
#include "nsIWidget.h"
#include "nsIScrollbar.h"
#include "nsUnitConversion.h"
@@ -74,6 +75,7 @@ public:
virtual nsRect GetBounds();
virtual void SetBounds(const nsRect& aBounds);
virtual void Move(PRInt32 aX, PRInt32 aY);
virtual void Show();
virtual void Hide();
@@ -81,6 +83,11 @@ public:
NS_IMETHOD GetContainer(nsISupports** aResult);
// XXX temp hack
virtual void SetRootWebWidget(nsIWebWidget* aWebWidget);
virtual nsIWebWidget* GetRootWebWidget();
nsIPresContext* GetPresContext();
NS_IMETHOD SetLinkHandler(nsILinkHandler* aHandler);
NS_IMETHOD GetLinkHandler(nsILinkHandler** aResult);
@@ -121,12 +128,16 @@ private:
nsISupports* mContainer;
nsIScriptContext* mScriptContext;
void* mScriptObject;
static nsIWebWidget* gRootWebWidget;
};
//----------------------------------------------------------------------
static NS_DEFINE_IID(kIWebWidgetIID, NS_IWEBWIDGET_IID);
nsIWebWidget* WebWidgetImpl::gRootWebWidget = nsnull;
// Note: operator new zeros our memory
WebWidgetImpl::WebWidgetImpl()
{
@@ -212,7 +223,6 @@ nsresult WebWidgetImpl::MakeWindow(nsNativeWindow aNativeParent,
nsnull,
kIViewIID,
(void **)&mView);
static NS_DEFINE_IID(kWidgetCID, NS_CHILD_CID);
if ((NS_OK != rv) || (NS_OK != mView->Init(mViewManager,
tbounds,
@@ -229,6 +239,7 @@ nsresult WebWidgetImpl::MakeWindow(nsNativeWindow aNativeParent,
if (mWindow) {
mViewManager->SetRootWindow(mWindow);
}
printf("webwidget.mView=%d widget=%d parent=%d \n", mView, mWindow, aNativeParent);
//set frame rate to 25 fps
mViewManager->SetFrameRate(25);
@@ -346,6 +357,12 @@ nsRect WebWidgetImpl::GetBounds()
return zr;
}
nsIPresContext* WebWidgetImpl::GetPresContext()
{
NS_IF_ADDREF(mPresContext);
return mPresContext;
}
void WebWidgetImpl::SetBounds(const nsRect& aBounds)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
@@ -356,6 +373,14 @@ void WebWidgetImpl::SetBounds(const nsRect& aBounds)
}
}
void WebWidgetImpl::Move(PRInt32 aX, PRInt32 aY)
{
NS_PRECONDITION(nsnull != mWindow, "null window");
if (nsnull != mWindow) {
mWindow->Move(aX, aY);
}
}
void WebWidgetImpl::Show()
{
NS_PRECONDITION(nsnull != mWindow, "null window");
@@ -393,6 +418,8 @@ nsresult WebWidgetImpl::ProvideDefaultHandlers()
// XXX need to save old document in case of failure? Does caller do that?
static NS_DEFINE_IID(kIWebFrameIID, NS_IWEBFRAME_IID);
NS_IMETHODIMP
WebWidgetImpl::LoadURL(const nsString& aURLSpec,
nsIStreamListener* aListener,
@@ -429,6 +456,18 @@ WebWidgetImpl::LoadURL(const nsString& aURLSpec,
nsIDocument* doc;
rv = NS_NewHTMLDocument(&doc);
// set the root web widget to this if its container is not
// an embedded web webwidget
nsISupports* parent;
rv = GetContainer(&parent);
if ((rv == NS_OK) && (nsnull != parent)) {
nsISupports* webFrame;
rv = parent->QueryInterface(kIWebFrameIID, (void**)&webFrame);
if (rv != NS_OK) {
SetRootWebWidget(this);
}
}
// Create style set
nsIStyleSet* styleSet = nsnull;
rv = CreateStyleSet(doc, &styleSet);
@@ -534,6 +573,19 @@ NS_IMETHODIMP WebWidgetImpl::GetContainer(nsISupports** aResult)
return NS_OK;
}
void WebWidgetImpl::SetRootWebWidget(nsIWebWidget* aWebWidget)
{
NS_IF_RELEASE(gRootWebWidget);
gRootWebWidget = aWebWidget;
NS_IF_ADDREF(gRootWebWidget);
}
nsIWebWidget* WebWidgetImpl::GetRootWebWidget()
{
NS_IF_ADDREF(gRootWebWidget);
return gRootWebWidget;
}
//----------------------------------------------------------------------
// Debugging methods

View File

@@ -0,0 +1,10 @@
<html>
<head>
<title>Example 9: Frames</title>
</head>
<body>
<H1>Example 9: Frames</H1>
before<iframe></iframe>
</body>
</html>

View File

@@ -0,0 +1,47 @@
<html>
<body>
<form>
<input type=text size=5>
</form>
this is the contents of bar1
<BR>
this is the contents of bar2
<BR>
this is the contents of bar3
<BR>
this is the contents of bar4
<BR>
this is the contents of bar5
<BR>
this is the contents of bar6
<BR>
this is the contents of bar7
<BR>
this is the contents of bar8
<BR>
this is the contents of bar9
<BR>
this is the contents of bar10
<BR>
this is the contents of bar11
<BR>
this is the contents of bar12
<BR>
this is the contents of bar13
<BR>
this is the contents of bar14
<BR>
this is the contents of bar15
<BR>
this is the contents of bar16
<BR>
this is the contents of bar17
<BR>
this is the contents of bar17
<BR>
this is the contents of bar19
<BR>
this is the contents of bar20
<BR>
</body>
</html>