1998-04-14 00:24:54 +04:00
|
|
|
/* -*- 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.
|
|
|
|
*/
|
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentDelegate.h"
|
|
|
|
#include "nsIFloaterContainer.h"
|
1998-05-30 03:12:26 +04:00
|
|
|
#include "nsBodyFrame.h"
|
1998-06-01 23:52:53 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsCSSLayout.h"
|
1998-06-03 19:57:24 +04:00
|
|
|
#include "nsIView.h"
|
1998-06-25 20:33:10 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-07-17 03:31:53 +04:00
|
|
|
#include "nsIPresContext.h"
|
1998-07-29 08:05:49 +04:00
|
|
|
#include "nsCSSLineLayout.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsresult
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPlaceholderFrame::NewFrame(nsIFrame** aInstancePtrResult,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-05-28 06:37:37 +04:00
|
|
|
nsIFrame* it = new nsPlaceholderFrame(aContent, aParent);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPlaceholderFrame::nsPlaceholderFrame(nsIContent* aContent, nsIFrame* aParent)
|
1998-06-10 09:33:38 +04:00
|
|
|
: nsFrame(aContent, aParent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPlaceholderFrame::~nsPlaceholderFrame()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-06-04 21:52:02 +04:00
|
|
|
NS_IMETHODIMP
|
1998-07-29 08:05:49 +04:00
|
|
|
nsPlaceholderFrame::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-07-29 08:05:49 +04:00
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIInlineReflowIID)) {
|
|
|
|
nsIInlineReflow* tmp = this;
|
|
|
|
*aInstancePtrResult = (void*) tmp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsFrame::QueryInterface(aIID, aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::FindTextRuns(nsCSSLineLayout& aLineLayout,
|
|
|
|
nsIReflowCommand* aReflowCommand)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::InlineReflow(nsCSSLineLayout& aLineLayout,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nsIPresContext& presContext = *aLineLayout.mPresContext;
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// Get the floater container in which we're inserted
|
1998-06-01 23:52:53 +04:00
|
|
|
nsIFrame* containingBlock;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIFloaterContainer* container = nsnull;
|
|
|
|
|
1998-06-01 23:52:53 +04:00
|
|
|
for (containingBlock = mGeometricParent;
|
|
|
|
nsnull != containingBlock;
|
|
|
|
containingBlock->GetGeometricParent(containingBlock))
|
|
|
|
{
|
|
|
|
if (NS_OK == containingBlock->QueryInterface(kIFloaterContainerIID, (void**)&container)) {
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ASSERTION(nsnull != container, "no floater container");
|
|
|
|
|
|
|
|
// Have we created the anchored item yet?
|
1998-06-10 09:33:38 +04:00
|
|
|
if (nsnull == mAnchoredItem) {
|
1998-05-30 03:12:26 +04:00
|
|
|
// If the content object is a container then wrap it in a body pseudo-frame
|
|
|
|
|
1998-06-04 21:52:02 +04:00
|
|
|
// XXX begin hack
|
1998-06-10 09:33:38 +04:00
|
|
|
// XXX More hack. We don't want to blindly wrap a body pseudo-frame around
|
|
|
|
// a table content object, because the body pseudo-frame will map the table's
|
|
|
|
// content children rather than create a table frame and let it map the
|
|
|
|
// children...
|
1998-06-04 21:52:02 +04:00
|
|
|
PRBool select = PR_FALSE;
|
|
|
|
nsIAtom* atom = mContent->GetTag();
|
|
|
|
nsAutoString tmp;
|
|
|
|
if (nsnull != atom) {
|
|
|
|
atom->ToString(tmp);
|
1998-06-10 09:33:38 +04:00
|
|
|
if (tmp.EqualsIgnoreCase("select") ||
|
1998-07-15 04:47:46 +04:00
|
|
|
tmp.EqualsIgnoreCase("table") ||
|
|
|
|
tmp.EqualsIgnoreCase("embed") ||
|
|
|
|
tmp.EqualsIgnoreCase("object") ||
|
|
|
|
tmp.EqualsIgnoreCase("applet")) {
|
1998-06-04 21:52:02 +04:00
|
|
|
select = PR_TRUE;
|
|
|
|
}
|
1998-06-05 01:04:50 +04:00
|
|
|
NS_RELEASE(atom);
|
1998-06-04 21:52:02 +04:00
|
|
|
}
|
|
|
|
// XXX end hack
|
1998-05-30 03:12:26 +04:00
|
|
|
|
1998-06-04 21:52:02 +04:00
|
|
|
if (mContent->CanContainChildren() && !select) {
|
1998-06-10 09:33:38 +04:00
|
|
|
nsBodyFrame::NewFrame(&mAnchoredItem, mContent, this);
|
1998-06-04 21:52:02 +04:00
|
|
|
|
|
|
|
// Use our style context for the pseudo-frame
|
1998-07-29 08:05:49 +04:00
|
|
|
mAnchoredItem->SetStyleContext(&presContext, mStyleContext);
|
1998-05-30 03:12:26 +04:00
|
|
|
} else {
|
|
|
|
// Create the anchored item
|
1998-07-29 08:05:49 +04:00
|
|
|
nsIContentDelegate* delegate = mContent->GetDelegate(&presContext);
|
|
|
|
nsresult rv = delegate->CreateFrame(&presContext, mContent,
|
1998-05-30 03:12:26 +04:00
|
|
|
mGeometricParent, mStyleContext,
|
1998-06-10 09:33:38 +04:00
|
|
|
mAnchoredItem);
|
1998-05-30 03:12:26 +04:00
|
|
|
NS_RELEASE(delegate);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-05-07 04:08:20 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-10 09:33:38 +04:00
|
|
|
// Notify our containing block that there's a new floater
|
1998-07-29 08:05:49 +04:00
|
|
|
container->AddFloater(&presContext, aReflowState, mAnchoredItem, this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-29 23:33:27 +04:00
|
|
|
aDesiredSize.width = 0;
|
|
|
|
aDesiredSize.height = 0;
|
|
|
|
aDesiredSize.ascent = 0;
|
1998-07-17 03:31:53 +04:00
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
if (nsnull != aDesiredSize.maxElementSize) {
|
|
|
|
aDesiredSize.maxElementSize->width = aDesiredSize.width;
|
|
|
|
aDesiredSize.maxElementSize->height = aDesiredSize.height;
|
|
|
|
}
|
1998-07-29 08:05:49 +04:00
|
|
|
return NS_FRAME_COMPLETE;
|
1998-07-17 03:31:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPlaceholderFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
if (nsIFrame::GetShowFrameBorders()) {
|
1998-07-29 23:33:27 +04:00
|
|
|
float p2t = aPresContext.GetPixelsToTwips();
|
1998-07-17 03:31:53 +04:00
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 255, 255));
|
1998-08-01 03:34:45 +04:00
|
|
|
nscoord x = NSIntPixelsToTwips(-5, p2t);
|
|
|
|
aRenderingContext.FillRect(x, 0, NSIntPixelsToTwips(13, p2t), NSIntPixelsToTwips(3, p2t));
|
|
|
|
nscoord y = NSIntPixelsToTwips(-10, p2t);
|
|
|
|
aRenderingContext.FillRect(0, y, NSIntPixelsToTwips(3, p2t), NSIntPixelsToTwips(10, p2t));
|
1998-07-17 03:31:53 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-07-01 01:35:07 +04:00
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ContentAppended(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContent == aContainer, "bad content-appended target");
|
|
|
|
|
|
|
|
// Forward the notification to the floater
|
|
|
|
if (nsnull != mAnchoredItem) {
|
|
|
|
return mAnchoredItem->ContentAppended(aShell, aPresContext, aContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ContentInserted(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContent == aContainer, "bad content-inserted target");
|
|
|
|
|
|
|
|
// Forward the notification to the floater
|
|
|
|
if (nsnull != mAnchoredItem) {
|
|
|
|
return mAnchoredItem->ContentInserted(aShell, aPresContext, aContainer,
|
|
|
|
aChild, aIndexInParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ContentReplaced(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aOldChild,
|
|
|
|
nsIContent* aNewChild,
|
|
|
|
PRInt32 aIndexInParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContent == aContainer, "bad content-replaced target");
|
|
|
|
|
|
|
|
// Forward the notification to the floater
|
|
|
|
if (nsnull != mAnchoredItem) {
|
|
|
|
return mAnchoredItem->ContentReplaced(aShell, aPresContext, aContainer,
|
|
|
|
aOldChild, aNewChild, aIndexInParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ContentDeleted(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
PRInt32 aIndexInParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContent == aContainer, "bad content-deleted target");
|
|
|
|
|
|
|
|
// Forward the notification to the floater
|
|
|
|
if (nsnull != mAnchoredItem) {
|
|
|
|
return mAnchoredItem->ContentDeleted(aShell, aPresContext, aContainer,
|
|
|
|
aChild, aIndexInParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ContentChanged(nsIPresShell* aShell,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsISupports* aSubContent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mContent == aChild, "bad content-changed target");
|
|
|
|
|
|
|
|
// Forward the notification to the floater
|
|
|
|
if (nsnull != mAnchoredItem) {
|
|
|
|
return mAnchoredItem->ContentChanged(aShell, aPresContext, aChild, aSubContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsPlaceholderFrame::ListTag(FILE* out) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
fputs("*placeholder", out);
|
1998-05-06 03:56:50 +04:00
|
|
|
PRInt32 contentIndex;
|
|
|
|
GetContentIndex(contentIndex);
|
|
|
|
fprintf(out, "(%d)@%p", contentIndex, this);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|