2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
1998-05-03 07:51:48 +04:00
|
|
|
#include "nsIPresShell.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIContent.h"
|
1999-08-08 05:15:30 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsILinkHandler.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURL.h"
|
1998-05-05 08:47:53 +04:00
|
|
|
#include "nsPlaceholderFrame.h"
|
1998-05-29 06:13:25 +04:00
|
|
|
#include "nsIHTMLContent.h"
|
|
|
|
#include "nsHTMLParts.h"
|
1998-06-04 21:50:19 +04:00
|
|
|
#include "nsIView.h"
|
1998-09-23 06:29:31 +04:00
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsViewsCID.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
1998-12-18 08:25:36 +03:00
|
|
|
#include "nsIScrollableView.h"
|
1999-01-28 20:14:13 +03:00
|
|
|
#include "nsWidgetsCID.h"
|
1999-02-24 07:03:50 +03:00
|
|
|
#include "nsIStyleSet.h"
|
1999-08-24 23:26:03 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2002-12-11 07:00:18 +03:00
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
2002-05-10 22:22:41 +04:00
|
|
|
#include "nsReflowPath.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2001-10-25 05:08:40 +04:00
|
|
|
static NS_DEFINE_CID(kCChildCID, NS_CHILD_CID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-10-07 01:01:41 +04:00
|
|
|
NS_IMETHODIMP
|
2001-09-19 16:35:19 +04:00
|
|
|
nsHTMLContainerFrame::Paint(nsIPresContext* aPresContext,
|
1998-10-07 01:01:41 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
2001-09-19 16:35:19 +04:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRUint32 aFlags)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-08-28 01:48:21 +04:00
|
|
|
if (NS_FRAME_IS_UNFLOWABLE & mState) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-05 01:45:47 +04:00
|
|
|
|
|
|
|
// Paint inline element backgrounds in the foreground layer, but
|
2002-12-11 07:00:18 +03:00
|
|
|
// others in the background (bug 36710). (nsInlineFrame::Paint does
|
|
|
|
// this differently.)
|
|
|
|
if (NS_FRAME_PAINT_LAYER_BACKGROUND == aWhichLayer) {
|
2002-12-24 01:05:47 +03:00
|
|
|
PaintSelf(aPresContext, aRenderingContext, aDirtyRect);
|
2002-12-11 07:00:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer, aFlags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLContainerFrame::PaintDecorationsAndChildren(
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer,
|
|
|
|
PRBool aIsBlock,
|
|
|
|
PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
// Do standards mode painting of 'text-decoration's: under+overline
|
|
|
|
// behind children, line-through in front. For Quirks mode, see
|
|
|
|
// nsTextFrame::PaintTextDecorations. (See bug 1777.)
|
|
|
|
nscolor underColor, overColor, strikeColor;
|
|
|
|
PRUint8 decorations = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
2002-12-19 03:24:18 +03:00
|
|
|
PRBool isVisible;
|
2002-12-11 07:00:18 +03:00
|
|
|
|
|
|
|
if (eCompatibility_NavQuirks != mode &&
|
2002-12-19 03:24:18 +03:00
|
|
|
NS_FRAME_PAINT_LAYER_FOREGROUND == aWhichLayer &&
|
|
|
|
NS_SUCCEEDED(IsVisibleForPainting(aPresContext, aRenderingContext,
|
|
|
|
PR_TRUE, &isVisible)) &&
|
|
|
|
isVisible) {
|
2002-12-11 07:00:18 +03:00
|
|
|
GetTextDecorations(aPresContext, aIsBlock, decorations, underColor,
|
|
|
|
overColor, strikeColor);
|
|
|
|
if (decorations & (NS_STYLE_TEXT_DECORATION_UNDERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_OVERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_THROUGH)) {
|
|
|
|
const nsStyleFont* font;
|
|
|
|
::GetStyleData(this, &font);
|
|
|
|
NS_ASSERTION(font->mFont.decorations == NS_FONT_DECORATION_NONE,
|
|
|
|
"fonts on style structs shouldn't have decorations");
|
|
|
|
|
|
|
|
// XXX This is relatively slow and shouldn't need to be used here.
|
|
|
|
nsCOMPtr<nsIDeviceContext> deviceContext;
|
|
|
|
aRenderingContext.GetDeviceContext(*getter_AddRefs(deviceContext));
|
|
|
|
nsCOMPtr<nsIFontMetrics> normalFont;
|
|
|
|
deviceContext->GetMetricsFor(font->mFont, *getter_AddRefs(fm));
|
|
|
|
}
|
|
|
|
if (decorations & NS_STYLE_TEXT_DECORATION_UNDERLINE) {
|
|
|
|
PaintTextDecorations(aRenderingContext, fm,
|
|
|
|
NS_STYLE_TEXT_DECORATION_UNDERLINE, underColor);
|
|
|
|
}
|
|
|
|
if (decorations & NS_STYLE_TEXT_DECORATION_OVERLINE) {
|
|
|
|
PaintTextDecorations(aRenderingContext, fm,
|
|
|
|
NS_STYLE_TEXT_DECORATION_OVERLINE, overColor);
|
1998-10-07 01:01:41 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-11-19 06:52:29 +03:00
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect,
|
|
|
|
aWhichLayer, aFlags);
|
|
|
|
|
|
|
|
if (decorations & NS_STYLE_TEXT_DECORATION_LINE_THROUGH) {
|
|
|
|
PaintTextDecorations(aRenderingContext, fm,
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_THROUGH, strikeColor);
|
2001-04-25 23:52:49 +04:00
|
|
|
}
|
2002-12-11 07:00:18 +03:00
|
|
|
}
|
2001-04-25 23:52:49 +04:00
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
static PRBool
|
|
|
|
HasTextFrameDescendant(nsIPresContext* aPresContext, nsIFrame* parent);
|
2000-05-17 02:12:54 +04:00
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
void
|
|
|
|
nsHTMLContainerFrame::GetTextDecorations(nsIPresContext* aPresContext,
|
|
|
|
PRBool aIsBlock,
|
|
|
|
PRUint8& aDecorations,
|
|
|
|
nscolor& aUnderColor,
|
|
|
|
nscolor& aOverColor,
|
|
|
|
nscolor& aStrikeColor)
|
|
|
|
{
|
|
|
|
aDecorations = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
if (!mStyleContext->HasTextDecorations()) {
|
|
|
|
// This is a neccessary, but not sufficient, condition for text
|
|
|
|
// decorations.
|
|
|
|
return;
|
|
|
|
}
|
2000-08-09 03:38:00 +04:00
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
// A mask of all possible decorations.
|
|
|
|
PRUint8 decorMask = NS_STYLE_TEXT_DECORATION_UNDERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_OVERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
|
|
|
|
|
|
|
|
const nsStyleTextReset* styleText;
|
|
|
|
::GetStyleData(mStyleContext, &styleText);
|
|
|
|
|
|
|
|
if (!aIsBlock) {
|
|
|
|
aDecorations = styleText->mTextDecoration & decorMask;
|
|
|
|
if (aDecorations) {
|
|
|
|
const nsStyleColor* styleColor;
|
|
|
|
::GetStyleData(mStyleContext, &styleColor);
|
|
|
|
aUnderColor = styleColor->mColor;
|
|
|
|
aOverColor = styleColor->mColor;
|
|
|
|
aStrikeColor = styleColor->mColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// walk tree
|
|
|
|
for (nsIFrame *frame = this; frame && decorMask; frame->GetParent(&frame)) {
|
|
|
|
// find text-decorations. "Inherit" from parent *block* frames
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = frame->GetStyleContext();
|
2002-12-11 07:00:18 +03:00
|
|
|
const nsStyleDisplay* styleDisplay;
|
2003-02-22 03:32:13 +03:00
|
|
|
::GetStyleData(styleContext, &styleDisplay);
|
2003-01-18 02:42:37 +03:00
|
|
|
if (!styleDisplay->IsBlockLevel() &&
|
|
|
|
styleDisplay->mDisplay != NS_STYLE_DISPLAY_TABLE_CELL) {
|
2002-12-11 07:00:18 +03:00
|
|
|
// If an inline frame is discovered while walking up the tree,
|
|
|
|
// we should stop according to CSS3 draft. CSS2 is rather vague
|
|
|
|
// about this.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
::GetStyleData(styleContext, &styleText);
|
2002-12-11 07:00:18 +03:00
|
|
|
PRUint8 decors = decorMask & styleText->mTextDecoration;
|
|
|
|
if (decors) {
|
|
|
|
// A *new* text-decoration is found.
|
|
|
|
const nsStyleColor* styleColor;
|
2003-02-22 03:32:13 +03:00
|
|
|
::GetStyleData(styleContext, &styleColor);
|
2002-12-11 07:00:18 +03:00
|
|
|
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decors) {
|
|
|
|
aUnderColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;
|
|
|
|
aDecorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE;
|
|
|
|
}
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_OVERLINE & decors) {
|
|
|
|
aOverColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;
|
|
|
|
aDecorations |= NS_STYLE_TEXT_DECORATION_OVERLINE;
|
|
|
|
}
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decors) {
|
|
|
|
aStrikeColor = styleColor->mColor;
|
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
|
|
|
|
aDecorations |= NS_STYLE_TEXT_DECORATION_LINE_THROUGH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aDecorations) {
|
|
|
|
// If this frame contains no text, we're required to ignore this property
|
|
|
|
if (!HasTextFrameDescendant(aPresContext, this)) {
|
|
|
|
aDecorations = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
HasTextFrameDescendant(nsIPresContext* aPresContext, nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
nsIFrame* kid = nsnull;
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
|
|
|
|
for (aParent->FirstChild(aPresContext, nsnull, &kid); kid;
|
|
|
|
kid->GetNextSibling(&kid))
|
|
|
|
{
|
|
|
|
kid->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (frameType == nsLayoutAtoms::textFrame) {
|
|
|
|
// This is only a candidate. We need to determine if this text
|
|
|
|
// frame is empty, as in containing only (non-pre) whitespace.
|
|
|
|
// See bug 20163.
|
|
|
|
nsCompatibility mode;
|
|
|
|
aPresContext->GetCompatibilityMode(&mode);
|
|
|
|
const nsStyleText* styleText;
|
|
|
|
::GetStyleData(kid, &styleText);
|
|
|
|
// XXXldb This is the wrong way to set |isPre|.
|
|
|
|
PRBool isPre = NS_STYLE_WHITESPACE_PRE == styleText->mWhiteSpace ||
|
|
|
|
NS_STYLE_WHITESPACE_MOZ_PRE_WRAP == styleText->mWhiteSpace;
|
|
|
|
PRBool isEmpty;
|
|
|
|
kid->IsEmpty(mode, isPre, &isEmpty);
|
|
|
|
if (!isEmpty) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HasTextFrameDescendant(aPresContext, kid)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*virtual*/ void
|
|
|
|
nsHTMLContainerFrame::PaintTextDecorationLines(
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nscolor aColor,
|
|
|
|
nscoord aOffset,
|
|
|
|
nscoord aAscent,
|
|
|
|
nscoord aSize)
|
|
|
|
{
|
|
|
|
nsMargin bp;
|
|
|
|
CalcBorderPadding(bp);
|
|
|
|
aRenderingContext.SetColor(aColor);
|
|
|
|
nscoord innerWidth = mRect.width - bp.left - bp.right;
|
|
|
|
aRenderingContext.FillRect(bp.left,
|
|
|
|
bp.top + aAscent - aOffset, innerWidth, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLContainerFrame::PaintTextDecorations(
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nsIFontMetrics* aFontMetrics,
|
|
|
|
PRUint8 aDecoration,
|
|
|
|
nscolor aColor)
|
|
|
|
{
|
|
|
|
nscoord ascent, offset, size;
|
|
|
|
aFontMetrics->GetMaxAscent(ascent);
|
|
|
|
if (aDecoration &
|
|
|
|
(NS_STYLE_TEXT_DECORATION_UNDERLINE
|
|
|
|
| NS_STYLE_TEXT_DECORATION_OVERLINE)) {
|
|
|
|
aFontMetrics->GetUnderline(offset, size);
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & aDecoration) {
|
|
|
|
PaintTextDecorationLines(aRenderingContext, aColor, offset, ascent, size);
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_TEXT_DECORATION_OVERLINE & aDecoration) {
|
|
|
|
PaintTextDecorationLines(aRenderingContext, aColor, ascent, ascent, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & aDecoration) {
|
|
|
|
aFontMetrics->GetStrikeout(offset, size);
|
|
|
|
PaintTextDecorationLines(aRenderingContext, aColor, offset, ascent, size);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-23 06:29:31 +04:00
|
|
|
/**
|
|
|
|
* Create a next-in-flow for aFrame. Will return the newly created
|
|
|
|
* frame in aNextInFlowResult <b>if and only if</b> a new frame is
|
|
|
|
* created; otherwise nsnull is returned in aNextInFlowResult.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsHTMLContainerFrame::CreateNextInFlow(nsIPresContext* aPresContext,
|
2002-05-29 02:50:43 +04:00
|
|
|
nsIFrame* aOuterFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame*& aNextInFlowResult)
|
1998-09-23 06:29:31 +04:00
|
|
|
{
|
|
|
|
aNextInFlowResult = nsnull;
|
|
|
|
|
|
|
|
nsIFrame* nextInFlow;
|
1999-02-24 07:48:08 +03:00
|
|
|
aFrame->GetNextInFlow(&nextInFlow);
|
1998-09-23 06:29:31 +04:00
|
|
|
if (nsnull == nextInFlow) {
|
|
|
|
// Create a continuation frame for the child frame and insert it
|
|
|
|
// into our lines child list.
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 09:13:38 +03:00
|
|
|
aFrame->GetNextSibling(&nextFrame);
|
1999-02-24 07:03:50 +03:00
|
|
|
|
|
|
|
nsIPresShell* presShell;
|
|
|
|
nsIStyleSet* styleSet;
|
1999-11-24 09:03:41 +03:00
|
|
|
aPresContext->GetShell(&presShell);
|
1999-02-24 07:03:50 +03:00
|
|
|
presShell->GetStyleSet(&styleSet);
|
|
|
|
NS_RELEASE(presShell);
|
1999-11-24 09:03:41 +03:00
|
|
|
styleSet->CreateContinuingFrame(aPresContext, aFrame, aOuterFrame, &nextInFlow);
|
1999-02-24 07:03:50 +03:00
|
|
|
NS_RELEASE(styleSet);
|
|
|
|
|
1998-09-23 06:29:31 +04:00
|
|
|
if (nsnull == nextInFlow) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aFrame->SetNextSibling(nextInFlow);
|
|
|
|
nextInFlow->SetNextSibling(nextFrame);
|
|
|
|
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_NEW_FRAMES,
|
1999-03-19 00:03:25 +03:00
|
|
|
("nsHTMLContainerFrame::MaybeCreateNextInFlow: frame=%p nextInFlow=%p",
|
1998-09-23 06:29:31 +04:00
|
|
|
aFrame, nextInFlow));
|
|
|
|
|
|
|
|
aNextInFlowResult = nextInFlow;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-11 08:22:00 +04:00
|
|
|
static nsresult
|
1999-10-26 08:44:41 +04:00
|
|
|
ReparentFrameViewTo(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
1999-08-24 23:26:03 +04:00
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIView* aNewParentView,
|
|
|
|
nsIView* aOldParentView)
|
1999-04-11 08:22:00 +04:00
|
|
|
{
|
|
|
|
nsIView* view;
|
|
|
|
|
2001-12-01 17:31:45 +03:00
|
|
|
// XXX What to do about placeholder views for "position: fixed" elements?
|
|
|
|
// They should be reparented too.
|
|
|
|
|
1999-04-11 08:22:00 +04:00
|
|
|
// Does aFrame have a view?
|
1999-10-26 08:44:41 +04:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
1999-04-11 08:22:00 +04:00
|
|
|
if (view) {
|
|
|
|
// Verify that the current parent view is what we think it is
|
2001-04-12 05:26:57 +04:00
|
|
|
//nsIView* parentView;
|
2000-08-08 18:11:09 +04:00
|
|
|
//NS_ASSERTION(parentView == aOldParentView, "unexpected parent view");
|
1999-04-11 08:22:00 +04:00
|
|
|
|
2001-12-01 17:31:45 +03:00
|
|
|
aViewManager->RemoveChild(view);
|
1999-04-11 08:22:00 +04:00
|
|
|
|
2001-12-01 17:31:45 +03:00
|
|
|
// The view will remember the Z-order and other attributes that have been set on it.
|
|
|
|
// XXX Pretend this view is last of the parent's views in document order
|
|
|
|
aViewManager->InsertChild(aNewParentView, view, nsnull, PR_TRUE);
|
1999-04-11 08:22:00 +04:00
|
|
|
} else {
|
2003-04-09 00:50:57 +04:00
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsCOMPtr<nsIAtom> listName;
|
|
|
|
// This loop iterates through every child list name, and also
|
|
|
|
// executes once with listName == nsnull.
|
|
|
|
do {
|
|
|
|
aFrame->GetAdditionalChildListName(listIndex, getter_AddRefs(listName));
|
|
|
|
listIndex++;
|
|
|
|
|
|
|
|
// Iterate the child frames, and check each child frame to see if it has
|
|
|
|
// a view
|
|
|
|
nsIFrame* childFrame;
|
|
|
|
aFrame->FirstChild(aPresContext, listName, &childFrame);
|
|
|
|
for (; childFrame; childFrame->GetNextSibling(&childFrame)) {
|
|
|
|
ReparentFrameViewTo(aPresContext, childFrame, aViewManager,
|
|
|
|
aNewParentView, aOldParentView);
|
|
|
|
}
|
|
|
|
} while (listName);
|
1999-04-11 08:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-24 23:26:03 +04:00
|
|
|
// Helper function that returns the nearest view to this frame. Checks
|
|
|
|
// this frame, its parent frame, its parent frame, ...
|
1999-04-11 08:22:00 +04:00
|
|
|
static nsIView*
|
1999-10-26 08:44:41 +04:00
|
|
|
GetClosestViewFor(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
1999-04-11 08:22:00 +04:00
|
|
|
{
|
1999-08-24 23:26:03 +04:00
|
|
|
NS_PRECONDITION(aFrame, "null frame pointer");
|
1999-04-11 08:22:00 +04:00
|
|
|
nsIView* view;
|
|
|
|
|
1999-08-24 23:26:03 +04:00
|
|
|
do {
|
1999-10-26 08:44:41 +04:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
1999-08-24 23:26:03 +04:00
|
|
|
if (view) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aFrame->GetParent(&aFrame);
|
|
|
|
} while (aFrame);
|
1999-04-11 08:22:00 +04:00
|
|
|
|
|
|
|
NS_POSTCONDITION(view, "no containing view");
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-10-26 08:44:41 +04:00
|
|
|
nsHTMLContainerFrame::ReparentFrameView(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIFrame* aOldParentFrame,
|
|
|
|
nsIFrame* aNewParentFrame)
|
1999-04-11 08:22:00 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aChildFrame, "null child frame pointer");
|
|
|
|
NS_PRECONDITION(aOldParentFrame, "null old parent frame pointer");
|
|
|
|
NS_PRECONDITION(aNewParentFrame, "null new parent frame pointer");
|
|
|
|
NS_PRECONDITION(aOldParentFrame != aNewParentFrame, "same old and new parent frame");
|
|
|
|
|
1999-08-24 23:26:03 +04:00
|
|
|
nsIView* childView;
|
|
|
|
nsIView* oldParentView;
|
|
|
|
nsIView* newParentView;
|
|
|
|
|
|
|
|
// This code is called often and we need it to be as fast as possible, so
|
|
|
|
// see if we can trivially detect that no work needs to be done
|
1999-10-26 08:44:41 +04:00
|
|
|
aChildFrame->GetView(aPresContext, &childView);
|
1999-08-24 23:26:03 +04:00
|
|
|
if (!childView) {
|
|
|
|
// Child frame doesn't have a view. See if it has any child frames
|
|
|
|
nsIFrame* firstChild;
|
2000-01-22 04:16:50 +03:00
|
|
|
aChildFrame->FirstChild(aPresContext, nsnull, &firstChild);
|
1999-08-24 23:26:03 +04:00
|
|
|
if (!firstChild) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if either the old parent frame or the new parent frame have a view
|
1999-10-26 08:44:41 +04:00
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
1999-08-24 23:26:03 +04:00
|
|
|
|
|
|
|
if (!oldParentView && !newParentView) {
|
|
|
|
// Walk up both the old parent frame and the new parent frame nodes
|
|
|
|
// stopping when we either find a common parent or views for one
|
|
|
|
// or both of the frames.
|
|
|
|
//
|
|
|
|
// This works well in the common case where we push/pull and the old parent
|
|
|
|
// frame and the new parent frame are part of the same flow. They will
|
|
|
|
// typically be the same distance (height wise) from the
|
|
|
|
do {
|
|
|
|
aOldParentFrame->GetParent(&aOldParentFrame);
|
|
|
|
aNewParentFrame->GetParent(&aNewParentFrame);
|
|
|
|
|
|
|
|
// We should never walk all the way to the root frame without finding
|
|
|
|
// a view
|
|
|
|
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
|
1999-04-11 08:22:00 +04:00
|
|
|
|
1999-08-24 23:26:03 +04:00
|
|
|
// See if we reached a common parent
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the views
|
1999-10-26 08:44:41 +04:00
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
1999-08-24 23:26:03 +04:00
|
|
|
} while (!(oldParentView || newParentView));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See if we found a common parent frame
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
// We found a common parent and there are no views between the old parent
|
|
|
|
// and the common parent or the new parent frame and the common parent.
|
|
|
|
// Because neither the old parent frame nor the new parent frame have views,
|
|
|
|
// then any child views don't need reparenting
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found views for one or both of the parent frames before we found a
|
|
|
|
// common parent
|
|
|
|
NS_ASSERTION(oldParentView || newParentView, "internal error");
|
|
|
|
if (!oldParentView) {
|
1999-10-26 08:44:41 +04:00
|
|
|
oldParentView = GetClosestViewFor(aPresContext, aOldParentFrame);
|
1999-08-24 23:26:03 +04:00
|
|
|
}
|
|
|
|
if (!newParentView) {
|
1999-10-26 08:44:41 +04:00
|
|
|
newParentView = GetClosestViewFor(aPresContext, aNewParentFrame);
|
1999-08-24 23:26:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if the old parent frame and the new parent frame are in the
|
|
|
|
// same view sub-hierarchy. If they are then we don't have to do
|
|
|
|
// anything
|
1999-04-11 08:22:00 +04:00
|
|
|
if (oldParentView != newParentView) {
|
1999-08-24 23:26:03 +04:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
oldParentView->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
|
|
|
|
// They're not so we need to reparent any child views
|
1999-10-26 08:44:41 +04:00
|
|
|
return ReparentFrameViewTo(aPresContext, aChildFrame, viewManager, newParentView,
|
1999-08-24 23:26:03 +04:00
|
|
|
oldParentView);
|
1999-04-11 08:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-12 06:09:36 +03:00
|
|
|
nsresult
|
|
|
|
nsHTMLContainerFrame::ReparentFrameViewList(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aChildFrameList,
|
|
|
|
nsIFrame* aOldParentFrame,
|
|
|
|
nsIFrame* aNewParentFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aChildFrameList, "null child frame list");
|
|
|
|
NS_PRECONDITION(aOldParentFrame, "null old parent frame pointer");
|
|
|
|
NS_PRECONDITION(aNewParentFrame, "null new parent frame pointer");
|
|
|
|
NS_PRECONDITION(aOldParentFrame != aNewParentFrame, "same old and new parent frame");
|
|
|
|
|
|
|
|
nsIView* oldParentView;
|
|
|
|
nsIView* newParentView;
|
|
|
|
|
|
|
|
// See if either the old parent frame or the new parent frame have a view
|
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
|
|
|
|
|
|
|
if (!oldParentView && !newParentView) {
|
|
|
|
// Walk up both the old parent frame and the new parent frame nodes
|
|
|
|
// stopping when we either find a common parent or views for one
|
|
|
|
// or both of the frames.
|
|
|
|
//
|
|
|
|
// This works well in the common case where we push/pull and the old parent
|
|
|
|
// frame and the new parent frame are part of the same flow. They will
|
|
|
|
// typically be the same distance (height wise) from the
|
|
|
|
do {
|
|
|
|
aOldParentFrame->GetParent(&aOldParentFrame);
|
|
|
|
aNewParentFrame->GetParent(&aNewParentFrame);
|
|
|
|
|
|
|
|
// We should never walk all the way to the root frame without finding
|
|
|
|
// a view
|
|
|
|
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
|
|
|
|
|
|
|
|
// See if we reached a common parent
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the views
|
|
|
|
aOldParentFrame->GetView(aPresContext, &oldParentView);
|
|
|
|
aNewParentFrame->GetView(aPresContext, &newParentView);
|
|
|
|
} while (!(oldParentView || newParentView));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// See if we found a common parent frame
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
// We found a common parent and there are no views between the old parent
|
|
|
|
// and the common parent or the new parent frame and the common parent.
|
|
|
|
// Because neither the old parent frame nor the new parent frame have views,
|
|
|
|
// then any child views don't need reparenting
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We found views for one or both of the parent frames before we found a
|
|
|
|
// common parent
|
|
|
|
NS_ASSERTION(oldParentView || newParentView, "internal error");
|
|
|
|
if (!oldParentView) {
|
|
|
|
oldParentView = GetClosestViewFor(aPresContext, aOldParentFrame);
|
|
|
|
}
|
|
|
|
if (!newParentView) {
|
|
|
|
newParentView = GetClosestViewFor(aPresContext, aNewParentFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the old parent frame and the new parent frame are in the
|
|
|
|
// same view sub-hierarchy. If they are then we don't have to do
|
|
|
|
// anything
|
|
|
|
if (oldParentView != newParentView) {
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
oldParentView->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
|
|
|
|
// They're not so we need to reparent any child views
|
|
|
|
for (nsIFrame* f = aChildFrameList; f; f->GetNextSibling(&f)) {
|
|
|
|
ReparentFrameViewTo(aPresContext, f, viewManager, newParentView,
|
|
|
|
oldParentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 06:29:31 +04:00
|
|
|
nsresult
|
1999-11-24 09:03:41 +03:00
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(nsIPresContext* aPresContext,
|
1998-09-23 06:29:31 +04:00
|
|
|
nsIFrame* aFrame,
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* aStyleContext,
|
2000-08-12 23:44:11 +04:00
|
|
|
nsIFrame* aContentParentFrame,
|
1998-09-23 06:29:31 +04:00
|
|
|
PRBool aForce)
|
|
|
|
{
|
|
|
|
nsIView* view;
|
1999-11-24 09:03:41 +03:00
|
|
|
aFrame->GetView(aPresContext, &view);
|
2002-09-30 15:56:37 +04:00
|
|
|
if (nsnull != view) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-04 22:03:44 +03:00
|
|
|
// If we don't yet have a view, see if we need a view
|
2002-09-30 15:56:37 +04:00
|
|
|
if (!(aForce || FrameNeedsView(aPresContext, aFrame, aStyleContext))) {
|
|
|
|
// don't need a view
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
// Create a view
|
|
|
|
nsIFrame* parent = nsnull;
|
|
|
|
aFrame->GetParentWithView(aPresContext, &parent);
|
|
|
|
NS_ASSERTION(parent, "GetParentWithView failed");
|
2002-07-02 16:50:14 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
nsIView* parentView = nsnull;
|
|
|
|
parent->GetView(aPresContext, &parentView);
|
|
|
|
NS_ASSERTION(parentView, "no parent with view");
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
// Create a view
|
|
|
|
static NS_DEFINE_CID(kViewCID, NS_VIEW_CID);
|
|
|
|
nsresult result = CallCreateInstance(kViewCID, &view);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
|
|
|
parentView->GetViewManager(*getter_AddRefs(viewManager));
|
|
|
|
NS_ASSERTION(nsnull != viewManager, "null view manager");
|
|
|
|
|
|
|
|
// Initialize the view
|
|
|
|
nsRect bounds;
|
|
|
|
aFrame->GetRect(bounds);
|
|
|
|
view->Init(viewManager, bounds, parentView);
|
|
|
|
|
|
|
|
SyncFrameViewProperties(aPresContext, aFrame, aStyleContext, view);
|
|
|
|
|
|
|
|
// Insert the view into the view hierarchy. If the parent view is a
|
|
|
|
// scrolling view we need to do this differently
|
|
|
|
nsIScrollableView* scrollingView;
|
|
|
|
if (NS_SUCCEEDED(CallQueryInterface(parentView, &scrollingView))) {
|
|
|
|
scrollingView->SetScrolledView(view);
|
|
|
|
} else {
|
|
|
|
// XXX Drop it at the end of the document order until we can do better
|
|
|
|
viewManager->InsertChild(parentView, view, nsnull, PR_TRUE);
|
|
|
|
|
|
|
|
if (nsnull != aContentParentFrame) {
|
|
|
|
// If, for some reason, GetView below fails to initialize zParentView,
|
|
|
|
// then ensure that we completely bypass InsertZPlaceholder below.
|
|
|
|
// The effect will be as if we never knew about aContentParentFrame
|
|
|
|
// in the first place, so at least this code won't be doing any damage.
|
|
|
|
nsIView* zParentView = parentView;
|
|
|
|
|
|
|
|
aContentParentFrame->GetView(aPresContext, &zParentView);
|
|
|
|
|
|
|
|
if (nsnull == zParentView) {
|
|
|
|
nsIFrame* zParentFrame = nsnull;
|
|
|
|
|
|
|
|
aContentParentFrame->GetParentWithView(aPresContext, &zParentFrame);
|
|
|
|
NS_ASSERTION(zParentFrame, "GetParentWithView failed");
|
|
|
|
zParentFrame->GetView(aPresContext, &zParentView);
|
|
|
|
NS_ASSERTION(zParentView, "no parent with view");
|
1998-12-04 08:56:06 +03:00
|
|
|
}
|
2002-09-30 15:56:37 +04:00
|
|
|
|
|
|
|
if (zParentView != parentView) {
|
|
|
|
viewManager->InsertZPlaceholder(zParentView, view, nsnull, PR_TRUE);
|
2000-04-25 08:43:11 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-30 15:56:37 +04:00
|
|
|
}
|
2000-04-25 08:43:11 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
// XXX If it's fixed positioned, then create a widget so it floats
|
|
|
|
// above the scrolling area
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
::GetStyleData(aStyleContext, &display);
|
|
|
|
if (NS_STYLE_POSITION_FIXED == display->mPosition) {
|
|
|
|
view->CreateWidget(kCChildCID);
|
|
|
|
}
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
// Remember our view
|
|
|
|
aFrame->SetView(aPresContext, view);
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsHTMLContainerFrame::CreateViewForFrame: frame=%p view=%p",
|
|
|
|
aFrame));
|
1998-09-23 06:29:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-28 11:53:41 +04:00
|
|
|
|
|
|
|
void
|
2003-04-06 01:27:45 +04:00
|
|
|
nsHTMLContainerFrame::CheckInvalidateSizeChange(nsIPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState)
|
2002-04-28 11:53:41 +04:00
|
|
|
{
|
2003-04-06 01:27:45 +04:00
|
|
|
if (aDesiredSize.width == mRect.width
|
|
|
|
&& aDesiredSize.height == mRect.height)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Below, we invalidate the old frame area (or, in the case of
|
|
|
|
// outline, combined area) if the outline, border or background
|
|
|
|
// settings indicate that something other than the difference
|
|
|
|
// between the old and new areas needs to be painted. We are
|
|
|
|
// assuming that the difference between the old and new areas will
|
|
|
|
// be invalidated by some other means. That also means invalidating
|
|
|
|
// the old frame area is the same as invalidating the new frame area
|
|
|
|
// (since in either case the UNION of old and new areas will be
|
|
|
|
// invalidated)
|
|
|
|
|
|
|
|
// Invalidate the entire old frame+outline if the frame has an outline
|
|
|
|
|
|
|
|
// This assumes 'outline' is painted outside the element, as CSS2 requires.
|
|
|
|
// Currently we actually paint 'outline' inside the element so this code
|
|
|
|
// isn't strictly necessary. But we're trying to get ready to switch to
|
|
|
|
// CSS2 compliance.
|
|
|
|
const nsStyleOutline* outline;
|
|
|
|
::GetStyleData(this, &outline);
|
|
|
|
PRUint8 outlineStyle = outline->GetOutlineStyle();
|
|
|
|
if (outlineStyle != NS_STYLE_BORDER_STYLE_NONE
|
|
|
|
&& outlineStyle != NS_STYLE_BORDER_STYLE_HIDDEN) {
|
|
|
|
nscoord width;
|
|
|
|
outline->GetOutlineWidth(width);
|
|
|
|
if (width > 0) {
|
|
|
|
nsRect r(0, 0, mRect.width, mRect.height);
|
|
|
|
r.Inflate(width, width);
|
|
|
|
Invalidate(aPresContext, r);
|
|
|
|
return;
|
2002-04-28 11:53:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-06 01:27:45 +04:00
|
|
|
// Invalidate the old frame if the frame has borders. Those borders
|
|
|
|
// may be moving.
|
|
|
|
const nsStyleBorder* border;
|
|
|
|
::GetStyleData(this, &border);
|
|
|
|
if (border->IsBorderSideVisible(NS_SIDE_LEFT)
|
|
|
|
|| border->IsBorderSideVisible(NS_SIDE_RIGHT)
|
|
|
|
|| border->IsBorderSideVisible(NS_SIDE_TOP)
|
|
|
|
|| border->IsBorderSideVisible(NS_SIDE_BOTTOM)) {
|
|
|
|
Invalidate(aPresContext, nsRect(0, 0, mRect.width, mRect.height));
|
|
|
|
return;
|
|
|
|
}
|
2002-04-28 11:53:41 +04:00
|
|
|
|
2003-04-06 01:27:45 +04:00
|
|
|
// Invalidate the old frame if the frame has a background
|
|
|
|
// whose position depends on the size of the frame
|
|
|
|
const nsStyleBackground* background;
|
|
|
|
::GetStyleData(this, &background);
|
|
|
|
if (background->mBackgroundFlags &
|
|
|
|
(NS_STYLE_BG_X_POSITION_PERCENT | NS_STYLE_BG_Y_POSITION_PERCENT)) {
|
|
|
|
Invalidate(aPresContext, nsRect(0, 0, mRect.width, mRect.height));
|
|
|
|
return;
|
2002-04-28 11:53:41 +04:00
|
|
|
}
|
|
|
|
}
|