2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.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"
|
2003-10-15 04:49:03 +04:00
|
|
|
#include "nsLayoutUtils.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 "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 "nsHTMLParts.h"
|
1998-06-04 21:50:19 +04:00
|
|
|
#include "nsIView.h"
|
1998-09-23 06:29:31 +04:00
|
|
|
#include "nsIViewManager.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-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"
|
2004-01-22 02:05:10 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-10-07 01:01:41 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLContainerFrame::Paint(nsPresContext* 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(
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext,
|
2002-12-11 07:00:18 +03:00
|
|
|
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;
|
2002-12-19 03:24:18 +03:00
|
|
|
PRBool isVisible;
|
2002-12-11 07:00:18 +03:00
|
|
|
|
2003-12-25 00:51:50 +03:00
|
|
|
if (eCompatibility_NavQuirks != aPresContext->CompatibilityMode() &&
|
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)) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleFont* font = GetStyleFont();
|
2002-12-11 07:00:18 +03:00
|
|
|
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;
|
2005-05-13 00:02:33 +04:00
|
|
|
const nsStyleVisibility* visibility = GetStyleVisibility();
|
|
|
|
deviceContext->GetMetricsFor(font->mFont, visibility->mLangGroup, *getter_AddRefs(fm));
|
2002-12-11 07:00:18 +03:00
|
|
|
}
|
|
|
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
HasTextFrameDescendantOrInFlow(nsPresContext* aPresContext, nsIFrame* aFrame);
|
2000-05-17 02:12:54 +04:00
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLContainerFrame::GetTextDecorations(nsPresContext* aPresContext,
|
2002-12-11 07:00:18 +03:00
|
|
|
PRBool aIsBlock,
|
|
|
|
PRUint8& aDecorations,
|
|
|
|
nscolor& aUnderColor,
|
|
|
|
nscolor& aOverColor,
|
|
|
|
nscolor& aStrikeColor)
|
|
|
|
{
|
|
|
|
aDecorations = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
if (!mStyleContext->HasTextDecorations()) {
|
2004-11-10 10:27:11 +03:00
|
|
|
// This is a necessary, but not sufficient, condition for text
|
2002-12-11 07:00:18 +03:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
if (!aIsBlock) {
|
2003-05-15 07:42:21 +04:00
|
|
|
aDecorations = GetStyleTextReset()->mTextDecoration & decorMask;
|
2002-12-11 07:00:18 +03:00
|
|
|
if (aDecorations) {
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleColor* styleColor = GetStyleColor();
|
2002-12-11 07:00:18 +03:00
|
|
|
aUnderColor = styleColor->mColor;
|
|
|
|
aOverColor = styleColor->mColor;
|
|
|
|
aStrikeColor = styleColor->mColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// walk tree
|
2003-06-29 07:43:05 +04:00
|
|
|
for (nsIFrame *frame = this; frame && decorMask; frame = frame->GetParent()) {
|
2002-12-11 07:00:18 +03:00
|
|
|
// find text-decorations. "Inherit" from parent *block* frames
|
|
|
|
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = frame->GetStyleContext();
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleDisplay* styleDisplay = styleContext->GetStyleDisplay();
|
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-05-15 07:42:21 +04:00
|
|
|
const nsStyleTextReset* styleText = styleContext->GetStyleTextReset();
|
2002-12-11 07:00:18 +03:00
|
|
|
PRUint8 decors = decorMask & styleText->mTextDecoration;
|
|
|
|
if (decors) {
|
|
|
|
// A *new* text-decoration is found.
|
2003-05-15 07:42:21 +04:00
|
|
|
nscolor color = styleContext->GetStyleColor()->mColor;
|
2002-12-11 07:00:18 +03:00
|
|
|
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_UNDERLINE & decors) {
|
2003-05-15 07:42:21 +04:00
|
|
|
aUnderColor = color;
|
2002-12-11 07:00:18 +03:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_UNDERLINE;
|
|
|
|
aDecorations |= NS_STYLE_TEXT_DECORATION_UNDERLINE;
|
|
|
|
}
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_OVERLINE & decors) {
|
2003-05-15 07:42:21 +04:00
|
|
|
aOverColor = color;
|
2002-12-11 07:00:18 +03:00
|
|
|
decorMask &= ~NS_STYLE_TEXT_DECORATION_OVERLINE;
|
|
|
|
aDecorations |= NS_STYLE_TEXT_DECORATION_OVERLINE;
|
|
|
|
}
|
|
|
|
if (NS_STYLE_TEXT_DECORATION_LINE_THROUGH & decors) {
|
2003-05-15 07:42:21 +04:00
|
|
|
aStrikeColor = color;
|
2002-12-11 07:00:18 +03:00
|
|
|
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
|
2003-06-20 05:42:32 +04:00
|
|
|
if (!HasTextFrameDescendantOrInFlow(aPresContext, this)) {
|
2002-12-11 07:00:18 +03:00
|
|
|
aDecorations = NS_STYLE_TEXT_DECORATION_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
HasTextFrameDescendant(nsPresContext* aPresContext, nsIFrame* aParent)
|
2002-12-11 07:00:18 +03:00
|
|
|
{
|
2004-01-09 17:20:53 +03:00
|
|
|
for (nsIFrame* kid = aParent->GetFirstChild(nsnull); kid;
|
2003-06-29 07:43:05 +04:00
|
|
|
kid = kid->GetNextSibling())
|
2002-12-11 07:00:18 +03:00
|
|
|
{
|
2003-10-31 23:19:18 +03:00
|
|
|
if (kid->GetType() == nsLayoutAtoms::textFrame) {
|
2002-12-11 07:00:18 +03:00
|
|
|
// 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.
|
2003-11-11 02:36:06 +03:00
|
|
|
if (!kid->IsEmpty()) {
|
2002-12-11 07:00:18 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HasTextFrameDescendant(aPresContext, kid)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-06-20 05:42:32 +04:00
|
|
|
static PRBool
|
2004-08-01 03:15:21 +04:00
|
|
|
HasTextFrameDescendantOrInFlow(nsPresContext* aPresContext, nsIFrame* aFrame)
|
2003-06-20 05:42:32 +04:00
|
|
|
{
|
2004-09-14 06:28:03 +04:00
|
|
|
for (nsIFrame *f = aFrame->GetFirstInFlow(); f; f = f->GetNextInFlow()) {
|
2003-06-20 05:42:32 +04:00
|
|
|
if (HasTextFrameDescendant(aPresContext, f))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-12-11 07:00:18 +03:00
|
|
|
/*virtual*/ void
|
|
|
|
nsHTMLContainerFrame::PaintTextDecorationLines(
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
nscolor aColor,
|
|
|
|
nscoord aOffset,
|
|
|
|
nscoord aAscent,
|
|
|
|
nscoord aSize)
|
|
|
|
{
|
|
|
|
nsMargin bp;
|
|
|
|
CalcBorderPadding(bp);
|
2004-10-26 03:48:29 +04:00
|
|
|
PRIntn skip = GetSkipSides();
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
if (skip & (1 << side)) {
|
2005-04-29 19:44:38 +04:00
|
|
|
bp.side(side) = 0;
|
2004-10-26 03:48:29 +04:00
|
|
|
}
|
|
|
|
}
|
2002-12-11 07:00:18 +03:00
|
|
|
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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLContainerFrame::CreateNextInFlow(nsPresContext* 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;
|
|
|
|
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* nextInFlow = aFrame->GetNextInFlow();
|
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.
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIFrame* nextFrame = aFrame->GetNextSibling();
|
1999-02-24 07:03:50 +03:00
|
|
|
|
2004-01-08 01:30:53 +03:00
|
|
|
aPresContext->PresShell()->FrameConstructor()->
|
2003-12-21 08:36:36 +03:00
|
|
|
CreateContinuingFrame(aPresContext, aFrame, aOuterFrame, &nextInFlow);
|
1999-02-24 07:03:50 +03:00
|
|
|
|
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
|
2004-05-13 19:33:18 +04:00
|
|
|
ReparentFrameViewTo(nsIFrame* aFrame,
|
1999-08-24 23:26:03 +04:00
|
|
|
nsIViewManager* aViewManager,
|
|
|
|
nsIView* aNewParentView,
|
|
|
|
nsIView* aOldParentView)
|
1999-04-11 08:22:00 +04:00
|
|
|
{
|
|
|
|
|
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?
|
2003-06-20 03:44:01 +04:00
|
|
|
if (aFrame->HasView()) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIView* view = aFrame->GetView();
|
1999-04-11 08:22:00 +04:00
|
|
|
// 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.
|
2003-10-15 04:49:03 +04:00
|
|
|
nsIView* insertBefore = nsLayoutUtils::FindSiblingViewFor(aNewParentView, aFrame);
|
|
|
|
aViewManager->InsertChild(aNewParentView, view, insertBefore, insertBefore != nsnull);
|
1999-04-11 08:22:00 +04:00
|
|
|
} else {
|
2003-04-09 00:50:57 +04:00
|
|
|
PRInt32 listIndex = 0;
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIAtom* listName = nsnull;
|
2003-04-09 00:50:57 +04:00
|
|
|
// This loop iterates through every child list name, and also
|
|
|
|
// executes once with listName == nsnull.
|
|
|
|
do {
|
|
|
|
// Iterate the child frames, and check each child frame to see if it has
|
|
|
|
// a view
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aFrame->GetFirstChild(listName);
|
2003-06-29 07:43:05 +04:00
|
|
|
for (; childFrame; childFrame = childFrame->GetNextSibling()) {
|
2004-05-13 19:33:18 +04:00
|
|
|
ReparentFrameViewTo(childFrame, aViewManager,
|
2003-04-09 00:50:57 +04:00
|
|
|
aNewParentView, aOldParentView);
|
|
|
|
}
|
2004-01-09 17:20:53 +03:00
|
|
|
listName = aFrame->GetAdditionalChildListName(listIndex++);
|
2003-04-09 00:50:57 +04:00
|
|
|
} while (listName);
|
1999-04-11 08:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLContainerFrame::ReparentFrameView(nsPresContext* aPresContext,
|
1999-10-26 08:44:41 +04:00
|
|
|
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
|
|
|
// 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
|
2003-06-20 03:44:01 +04:00
|
|
|
if (!aChildFrame->HasView()) {
|
1999-08-24 23:26:03 +04:00
|
|
|
// Child frame doesn't have a view. See if it has any child frames
|
2004-01-09 17:20:53 +03:00
|
|
|
if (!aChildFrame->GetFirstChild(nsnull)) {
|
1999-08-24 23:26:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if either the old parent frame or the new parent frame have a view
|
|
|
|
|
2003-06-20 03:44:01 +04:00
|
|
|
while (!aOldParentFrame->HasView() && !aNewParentFrame->HasView()) {
|
1999-08-24 23:26:03 +04:00
|
|
|
// 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
|
2003-06-29 07:43:05 +04:00
|
|
|
aOldParentFrame = aOldParentFrame->GetParent();
|
|
|
|
aNewParentFrame = aNewParentFrame->GetParent();
|
2003-06-20 03:44:01 +04:00
|
|
|
|
|
|
|
// We should never walk all the way to the root frame without finding
|
|
|
|
// a view
|
|
|
|
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
|
1999-08-24 23:26:03 +04:00
|
|
|
|
2003-06-20 03:44:01 +04:00
|
|
|
// See if we reached a common ancestor
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
break;
|
|
|
|
}
|
1999-08-24 23:26:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2003-06-20 03:44:01 +04:00
|
|
|
// We found views for one or both of the ancestor frames before we
|
|
|
|
// found a common ancestor.
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIView* oldParentView = aOldParentFrame->GetClosestView();
|
|
|
|
nsIView* newParentView = aNewParentFrame->GetClosestView();
|
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
|
|
|
// They're not so we need to reparent any child views
|
2004-05-13 19:33:18 +04:00
|
|
|
return ReparentFrameViewTo(aChildFrame, oldParentView->GetViewManager(), 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
|
2004-08-01 03:15:21 +04:00
|
|
|
nsHTMLContainerFrame::ReparentFrameViewList(nsPresContext* aPresContext,
|
2000-03-12 06:09:36 +03:00
|
|
|
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");
|
|
|
|
|
|
|
|
// See if either the old parent frame or the new parent frame have a view
|
2003-06-20 03:44:01 +04:00
|
|
|
while (!aOldParentFrame->HasView() && !aNewParentFrame->HasView()) {
|
2000-03-12 06:09:36 +03:00
|
|
|
// 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
|
2003-06-29 07:43:05 +04:00
|
|
|
aOldParentFrame = aOldParentFrame->GetParent();
|
|
|
|
aNewParentFrame = aNewParentFrame->GetParent();
|
2003-06-20 03:44:01 +04:00
|
|
|
|
|
|
|
// We should never walk all the way to the root frame without finding
|
|
|
|
// a view
|
|
|
|
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
|
2000-03-12 06:09:36 +03:00
|
|
|
|
2003-06-20 03:44:01 +04:00
|
|
|
// See if we reached a common ancestor
|
|
|
|
if (aOldParentFrame == aNewParentFrame) {
|
|
|
|
break;
|
|
|
|
}
|
2000-03-12 06:09:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2003-06-20 03:44:01 +04:00
|
|
|
// We found views for one or both of the ancestor frames before we
|
|
|
|
// found a common ancestor.
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIView* oldParentView = aOldParentFrame->GetClosestView();
|
|
|
|
nsIView* newParentView = aNewParentFrame->GetClosestView();
|
2000-03-12 06:09:36 +03: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
|
|
|
|
if (oldParentView != newParentView) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIViewManager* viewManager = oldParentView->GetViewManager();
|
2000-03-12 06:09:36 +03:00
|
|
|
|
|
|
|
// They're not so we need to reparent any child views
|
2003-06-29 07:43:05 +04:00
|
|
|
for (nsIFrame* f = aChildFrameList; f; f = f->GetNextSibling()) {
|
2004-05-13 19:33:18 +04:00
|
|
|
ReparentFrameViewTo(f, viewManager, newParentView,
|
2000-03-12 06:09:36 +03:00
|
|
|
oldParentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 06:29:31 +04:00
|
|
|
nsresult
|
2003-10-17 06:38:37 +04:00
|
|
|
nsHTMLContainerFrame::CreateViewForFrame(nsIFrame* aFrame,
|
2000-08-12 23:44:11 +04:00
|
|
|
nsIFrame* aContentParentFrame,
|
1998-09-23 06:29:31 +04:00
|
|
|
PRBool aForce)
|
|
|
|
{
|
2003-06-20 03:44:01 +04:00
|
|
|
if (aFrame->HasView()) {
|
2002-09-30 15:56:37 +04:00
|
|
|
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
|
2003-10-17 06:38:37 +04:00
|
|
|
if (!(aForce || FrameNeedsView(aFrame))) {
|
2002-09-30 15:56:37 +04:00
|
|
|
// don't need a view
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2005-04-08 03:54:28 +04:00
|
|
|
nsIView* parentView = aFrame->GetParent()->GetParentViewForChildFrame(aFrame);
|
2002-09-30 15:56:37 +04:00
|
|
|
NS_ASSERTION(parentView, "no parent with view");
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIViewManager* viewManager = parentView->GetViewManager();
|
|
|
|
NS_ASSERTION(viewManager, "null view manager");
|
2002-09-30 15:56:37 +04:00
|
|
|
|
2004-11-04 18:06:50 +03:00
|
|
|
// Create a view
|
|
|
|
nsIView* view = viewManager->CreateView(aFrame->GetRect(), parentView);
|
|
|
|
if (!view)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-09-30 15:56:37 +04:00
|
|
|
|
2003-10-17 06:38:37 +04:00
|
|
|
SyncFrameViewProperties(aFrame->GetPresContext(), aFrame, nsnull, view);
|
2002-09-30 15:56:37 +04:00
|
|
|
|
|
|
|
// Insert the view into the view hierarchy. If the parent view is a
|
|
|
|
// scrolling view we need to do this differently
|
2004-11-24 03:19:21 +03:00
|
|
|
nsIScrollableView* scrollingView = parentView->ToScrollableView();
|
|
|
|
if (scrollingView) {
|
2002-09-30 15:56:37 +04:00
|
|
|
scrollingView->SetScrolledView(view);
|
|
|
|
} else {
|
2003-10-15 04:49:03 +04:00
|
|
|
nsIView* insertBefore = nsLayoutUtils::FindSiblingViewFor(parentView, aFrame);
|
|
|
|
// we insert this view 'above' the insertBefore view, unless insertBefore is null,
|
|
|
|
// in which case we want to call with aAbove == PR_FALSE to insert at the beginning
|
|
|
|
// in document order
|
|
|
|
viewManager->InsertChild(parentView, view, insertBefore, insertBefore != nsnull);
|
2002-09-30 15:56:37 +04:00
|
|
|
|
|
|
|
if (nsnull != aContentParentFrame) {
|
2003-06-29 07:43:05 +04:00
|
|
|
nsIView* zParentView = aContentParentFrame->GetClosestView();
|
2002-09-30 15:56:37 +04:00
|
|
|
if (zParentView != parentView) {
|
2003-10-15 04:49:03 +04:00
|
|
|
insertBefore = nsLayoutUtils::FindSiblingViewFor(zParentView, aFrame);
|
|
|
|
viewManager->InsertZPlaceholder(zParentView, view, insertBefore, insertBefore != nsnull);
|
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
|
2003-10-17 06:38:37 +04:00
|
|
|
const nsStyleDisplay* display = aFrame->GetStyleContext()->GetStyleDisplay();
|
2002-09-30 15:56:37 +04:00
|
|
|
if (NS_STYLE_POSITION_FIXED == display->mPosition) {
|
2005-04-07 07:59:02 +04:00
|
|
|
aFrame->CreateWidgetForView(view);
|
2002-09-30 15:56:37 +04:00
|
|
|
}
|
1998-09-23 06:29:31 +04:00
|
|
|
|
2004-05-13 19:33:18 +04:00
|
|
|
// Reparent views on any child frames (or their descendants) to this
|
|
|
|
// view. We can just call ReparentFrameViewTo on this frame because
|
|
|
|
// we know this frame has no view, so it will crawl the children. Also,
|
|
|
|
// we know that any descendants with views must have 'parentView' as their
|
|
|
|
// parent view.
|
|
|
|
ReparentFrameViewTo(aFrame, viewManager, view, parentView);
|
|
|
|
|
2002-09-30 15:56:37 +04:00
|
|
|
// Remember our view
|
2003-06-29 07:43:05 +04:00
|
|
|
aFrame->SetView(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;
|
|
|
|
}
|