2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-10-25 01:08:40 +00:00
|
|
|
// vim:cindent:ts=2:et:sw=2:
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-29 18:29:03 +00:00
|
|
|
|
|
|
|
/* representation of one line within a block frame, a CSS line box */
|
|
|
|
|
1998-12-01 16:13:49 +00:00
|
|
|
#include "nsLineBox.h"
|
1998-12-05 16:01:11 +00:00
|
|
|
#include "nsLineLayout.h"
|
1998-12-01 16:13:49 +00:00
|
|
|
#include "prprf.h"
|
2001-10-25 01:08:40 +00:00
|
|
|
#include "nsBlockFrame.h"
|
2012-05-04 00:14:02 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsPresArena.h"
|
2006-03-12 09:49:48 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
#include "nsBidiPresUtils.h"
|
|
|
|
#endif
|
2012-08-02 11:38:51 +00:00
|
|
|
#include "nsStyleStructInlines.h"
|
2013-03-28 23:27:31 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
1998-12-01 16:13:49 +00:00
|
|
|
|
1999-10-19 23:04:19 +00:00
|
|
|
#ifdef DEBUG
|
2012-08-22 15:56:38 +00:00
|
|
|
static int32_t ctorCount;
|
|
|
|
int32_t nsLineBox::GetCtorCount() { return ctorCount; }
|
1999-10-19 23:04:19 +00:00
|
|
|
#endif
|
|
|
|
|
2012-03-11 02:32:27 +00:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
// static nsLineBox constant; initialized in the header file.
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t nsLineBox::kMinChildCountForHashtable;
|
2012-03-11 02:32:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineBox::nsLineBox(nsIFrame* aFrame, int32_t aCount, bool aIsBlock)
|
2012-05-04 00:14:02 +00:00
|
|
|
: mFirstChild(aFrame)
|
|
|
|
// NOTE: memory is already zeroed since we allocate with AllocateByObjectID.
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsLineBox);
|
1999-10-19 23:04:19 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
++ctorCount;
|
2005-03-23 03:35:08 +00:00
|
|
|
NS_ASSERTION(!aIsBlock || aCount == 1, "Blocks must have exactly one child");
|
|
|
|
nsIFrame* f = aFrame;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t n = aCount; n > 0; f = f->GetNextSibling(), --n) {
|
2012-08-02 11:38:51 +00:00
|
|
|
NS_ASSERTION(aIsBlock == f->IsBlockOutside(),
|
2005-03-23 03:35:08 +00:00
|
|
|
"wrong kind of child frame");
|
|
|
|
}
|
1999-10-19 23:04:19 +00:00
|
|
|
#endif
|
1999-10-14 23:10:03 +00:00
|
|
|
|
2013-03-28 23:27:31 +00:00
|
|
|
MOZ_STATIC_ASSERT(NS_STYLE_CLEAR_LAST_VALUE <= 15,
|
|
|
|
"FlagBits needs more bits to store the full range of "
|
|
|
|
"break type ('clear') values");
|
1999-10-14 23:10:03 +00:00
|
|
|
#if NS_STYLE_CLEAR_NONE > 0
|
1999-10-12 23:24:22 +00:00
|
|
|
mFlags.mBreakType = NS_STYLE_CLEAR_NONE;
|
1999-10-14 23:10:03 +00:00
|
|
|
#endif
|
2012-03-11 02:32:27 +00:00
|
|
|
mChildCount = aCount;
|
1999-10-14 23:10:03 +00:00
|
|
|
MarkDirty();
|
|
|
|
mFlags.mBlock = aIsBlock;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox::~nsLineBox()
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsLineBox);
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(mFlags.mHasHashedFrames)) {
|
2012-03-11 02:32:27 +00:00
|
|
|
delete mFrames;
|
|
|
|
}
|
1999-10-19 23:04:19 +00:00
|
|
|
Cleanup();
|
|
|
|
}
|
1999-10-14 23:10:03 +00:00
|
|
|
|
2000-03-12 03:00:51 +00:00
|
|
|
nsLineBox*
|
2012-03-11 02:32:27 +00:00
|
|
|
NS_NewLineBox(nsIPresShell* aPresShell, nsIFrame* aFrame, bool aIsBlock)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsLineBox(aFrame, 1, aIsBlock);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox*
|
|
|
|
NS_NewLineBox(nsIPresShell* aPresShell, nsLineBox* aFromLine,
|
2012-08-22 15:56:38 +00:00
|
|
|
nsIFrame* aFrame, int32_t aCount)
|
2012-03-11 02:32:27 +00:00
|
|
|
{
|
|
|
|
nsLineBox* newLine = new (aPresShell) nsLineBox(aFrame, aCount, false);
|
2012-11-07 19:55:53 +00:00
|
|
|
newLine->NoteFramesMovedFrom(aFromLine);
|
2012-03-11 02:32:27 +00:00
|
|
|
return newLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineBox::StealHashTableFrom(nsLineBox* aFromLine, uint32_t aFromLineNewCount)
|
2012-03-11 02:32:27 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mFlags.mHasHashedFrames);
|
2012-08-22 15:56:38 +00:00
|
|
|
MOZ_ASSERT(GetChildCount() >= int32_t(aFromLineNewCount));
|
2012-03-11 02:32:27 +00:00
|
|
|
mFrames = aFromLine->mFrames;
|
|
|
|
mFlags.mHasHashedFrames = 1;
|
|
|
|
aFromLine->mFlags.mHasHashedFrames = 0;
|
|
|
|
aFromLine->mChildCount = aFromLineNewCount;
|
|
|
|
// remove aFromLine's frames that aren't on this line
|
|
|
|
nsIFrame* f = aFromLine->mFirstChild;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < aFromLineNewCount; f = f->GetNextSibling(), ++i) {
|
2012-03-11 02:32:27 +00:00
|
|
|
mFrames->RemoveEntry(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::NoteFramesMovedFrom(nsLineBox* aFromLine)
|
2000-03-12 03:00:51 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t fromCount = aFromLine->GetChildCount();
|
|
|
|
uint32_t toCount = GetChildCount();
|
2012-03-11 02:32:27 +00:00
|
|
|
MOZ_ASSERT(toCount <= fromCount, "moved more frames than aFromLine has");
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t fromNewCount = fromCount - toCount;
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_LIKELY(!aFromLine->mFlags.mHasHashedFrames)) {
|
2012-03-11 02:32:27 +00:00
|
|
|
aFromLine->mChildCount = fromNewCount;
|
|
|
|
MOZ_ASSERT(toCount < kMinChildCountForHashtable);
|
|
|
|
} else if (fromNewCount < kMinChildCountForHashtable) {
|
|
|
|
// aFromLine has a hash table but will not have it after moving the frames
|
|
|
|
// so this line can steal the hash table if it needs it.
|
|
|
|
if (toCount >= kMinChildCountForHashtable) {
|
|
|
|
StealHashTableFrom(aFromLine, fromNewCount);
|
|
|
|
} else {
|
|
|
|
delete aFromLine->mFrames;
|
|
|
|
aFromLine->mFlags.mHasHashedFrames = 0;
|
|
|
|
aFromLine->mChildCount = fromNewCount;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// aFromLine still needs a hash table.
|
|
|
|
if (toCount < kMinChildCountForHashtable) {
|
|
|
|
// remove the moved frames from it
|
|
|
|
nsIFrame* f = mFirstChild;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < toCount; f = f->GetNextSibling(), ++i) {
|
2012-03-11 02:32:27 +00:00
|
|
|
aFromLine->mFrames->RemoveEntry(f);
|
|
|
|
}
|
|
|
|
} else if (toCount <= fromNewCount) {
|
|
|
|
// This line needs a hash table, allocate a hash table for it since that
|
|
|
|
// means fewer hash ops.
|
|
|
|
nsIFrame* f = mFirstChild;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < toCount; f = f->GetNextSibling(), ++i) {
|
2012-03-11 02:32:27 +00:00
|
|
|
aFromLine->mFrames->RemoveEntry(f); // toCount RemoveEntry
|
|
|
|
}
|
|
|
|
SwitchToHashtable(); // toCount PutEntry
|
|
|
|
} else {
|
|
|
|
// This line needs a hash table, but it's fewer hash ops to steal
|
|
|
|
// aFromLine's hash table and allocate a new hash table for that line.
|
|
|
|
StealHashTableFrom(aFromLine, fromNewCount); // fromNewCount RemoveEntry
|
|
|
|
aFromLine->SwitchToHashtable(); // fromNewCount PutEntry
|
|
|
|
}
|
|
|
|
}
|
2000-03-12 03:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overloaded new operator. Uses an arena (which comes from the presShell)
|
|
|
|
// to perform the allocation.
|
2009-08-18 03:21:06 +00:00
|
|
|
void*
|
2002-07-02 20:25:30 +00:00
|
|
|
nsLineBox::operator new(size_t sz, nsIPresShell* aPresShell) CPP_THROW_NEW
|
2000-03-12 03:00:51 +00:00
|
|
|
{
|
2012-05-04 00:14:02 +00:00
|
|
|
return aPresShell->AllocateByObjectID(nsPresArena::nsLineBox_id, sz);
|
2000-03-12 03:00:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::Destroy(nsIPresShell* aPresShell)
|
|
|
|
{
|
2012-03-11 02:32:27 +00:00
|
|
|
this->nsLineBox::~nsLineBox();
|
2012-05-04 00:14:02 +00:00
|
|
|
aPresShell->FreeByObjectID(nsPresArena::nsLineBox_id, this);
|
2000-03-12 03:00:51 +00:00
|
|
|
}
|
|
|
|
|
1999-10-19 23:04:19 +00:00
|
|
|
void
|
|
|
|
nsLineBox::Cleanup()
|
|
|
|
{
|
1999-10-29 14:35:36 +00:00
|
|
|
if (mData) {
|
|
|
|
if (IsBlock()) {
|
1999-10-14 23:10:03 +00:00
|
|
|
delete mBlockData;
|
|
|
|
}
|
1999-10-29 14:35:36 +00:00
|
|
|
else {
|
1999-10-14 23:10:03 +00:00
|
|
|
delete mInlineData;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mData = nullptr;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
1999-10-19 23:04:19 +00:00
|
|
|
}
|
|
|
|
|
1999-11-01 22:12:45 +00:00
|
|
|
#ifdef DEBUG
|
1998-12-01 16:13:49 +00:00
|
|
|
static void
|
2012-08-22 15:56:38 +00:00
|
|
|
ListFloats(FILE* out, int32_t aIndent, const nsFloatCacheList& aFloats)
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* fc = aFloats.Head();
|
1999-09-15 00:28:10 +00:00
|
|
|
while (fc) {
|
|
|
|
nsFrame::IndentBy(out, aIndent);
|
2009-08-31 18:25:35 +00:00
|
|
|
nsIFrame* frame = fc->mFloat;
|
|
|
|
fprintf(out, "floatframe@%p ", static_cast<void*>(frame));
|
|
|
|
if (frame) {
|
|
|
|
nsAutoString frameName;
|
|
|
|
frame->GetFrameName(frameName);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(frameName).get(), out);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fputs("\n###!!! NULL out-of-flow frame", out);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
2009-08-31 18:25:35 +00:00
|
|
|
fprintf(out, "\n");
|
1999-09-15 00:28:10 +00:00
|
|
|
fc = fc->Next();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-01 22:12:45 +00:00
|
|
|
#endif
|
1998-12-01 16:13:49 +00:00
|
|
|
|
2001-10-25 01:08:40 +00:00
|
|
|
#ifdef DEBUG
|
2002-01-09 03:04:29 +00:00
|
|
|
const char *
|
2012-08-22 15:56:38 +00:00
|
|
|
BreakTypeToString(uint8_t aBreakType)
|
2002-01-09 03:04:29 +00:00
|
|
|
{
|
|
|
|
switch (aBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_NONE: return "nobr";
|
|
|
|
case NS_STYLE_CLEAR_LEFT: return "leftbr";
|
|
|
|
case NS_STYLE_CLEAR_RIGHT: return "rightbr";
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT: return "leftbr+rightbr";
|
|
|
|
case NS_STYLE_CLEAR_LINE: return "linebr";
|
|
|
|
case NS_STYLE_CLEAR_BLOCK: return "blockbr";
|
|
|
|
case NS_STYLE_CLEAR_COLUMN: return "columnbr";
|
|
|
|
case NS_STYLE_CLEAR_PAGE: return "pagebr";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
1998-12-01 16:13:49 +00:00
|
|
|
char*
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineBox::StateToString(char* aBuf, int32_t aBufSize) const
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2004-11-25 14:51:00 +00:00
|
|
|
PR_snprintf(aBuf, aBufSize, "%s,%s,%s,%s,%s,before:%s,after:%s[0x%x]",
|
1999-10-12 23:24:22 +00:00
|
|
|
IsBlock() ? "block" : "inline",
|
2000-03-22 23:19:10 +00:00
|
|
|
IsDirty() ? "dirty" : "clean",
|
2001-10-25 01:08:40 +00:00
|
|
|
IsPreviousMarginDirty() ? "prevmargindirty" : "prevmarginclean",
|
2003-10-13 21:51:02 +00:00
|
|
|
IsImpactedByFloat() ? "impacted" : "not impacted",
|
2002-01-09 03:04:29 +00:00
|
|
|
IsLineWrapped() ? "wrapped" : "not wrapped",
|
2004-11-25 14:51:00 +00:00
|
|
|
BreakTypeToString(GetBreakTypeBefore()),
|
|
|
|
BreakTypeToString(GetBreakTypeAfter()),
|
1999-10-12 23:24:22 +00:00
|
|
|
mAllFlags);
|
1998-12-01 16:13:49 +00:00
|
|
|
return aBuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-19 14:36:35 +00:00
|
|
|
nsLineBox::List(FILE* out, int32_t aIndent, uint32_t aFlags) const
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2012-10-08 20:06:04 +00:00
|
|
|
nsFrame::IndentBy(out, aIndent);
|
1999-01-16 00:00:50 +00:00
|
|
|
char cbuf[100];
|
|
|
|
fprintf(out, "line %p: count=%d state=%s ",
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<const void*>(this), GetChildCount(),
|
2001-10-25 01:08:40 +00:00
|
|
|
StateToString(cbuf, sizeof(cbuf)));
|
|
|
|
if (IsBlock() && !GetCarriedOutBottomMargin().IsZero()) {
|
|
|
|
fprintf(out, "bm=%d ", GetCarriedOutBottomMargin().get());
|
1999-01-16 00:00:50 +00:00
|
|
|
}
|
1999-10-14 23:10:03 +00:00
|
|
|
fprintf(out, "{%d,%d,%d,%d} ",
|
|
|
|
mBounds.x, mBounds.y, mBounds.width, mBounds.height);
|
|
|
|
if (mData) {
|
2010-10-07 04:25:45 +00:00
|
|
|
fprintf(out, "vis-overflow={%d,%d,%d,%d} scr-overflow={%d,%d,%d,%d} ",
|
|
|
|
mData->mOverflowAreas.VisualOverflow().x,
|
|
|
|
mData->mOverflowAreas.VisualOverflow().y,
|
|
|
|
mData->mOverflowAreas.VisualOverflow().width,
|
|
|
|
mData->mOverflowAreas.VisualOverflow().height,
|
|
|
|
mData->mOverflowAreas.ScrollableOverflow().x,
|
|
|
|
mData->mOverflowAreas.ScrollableOverflow().y,
|
|
|
|
mData->mOverflowAreas.ScrollableOverflow().width,
|
|
|
|
mData->mOverflowAreas.ScrollableOverflow().height);
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "<\n");
|
1998-12-01 16:13:49 +00:00
|
|
|
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n = GetChildCount();
|
1998-12-01 16:13:49 +00:00
|
|
|
while (--n >= 0) {
|
2012-09-19 14:36:35 +00:00
|
|
|
frame->List(out, aIndent + 1, aFlags);
|
2003-06-30 10:46:59 +00:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
if (HasFloats()) {
|
2012-10-08 20:06:04 +00:00
|
|
|
nsFrame::IndentBy(out, aIndent);
|
2003-10-13 21:51:02 +00:00
|
|
|
fputs("> floats <\n", out);
|
|
|
|
ListFloats(out, aIndent + 1, mInlineData->mFloats);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
2012-10-08 20:06:04 +00:00
|
|
|
nsFrame::IndentBy(out, aIndent);
|
1999-01-16 00:00:50 +00:00
|
|
|
fputs(">\n", out);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
1999-11-01 22:12:45 +00:00
|
|
|
#endif
|
1998-12-01 16:13:49 +00:00
|
|
|
|
2012-03-08 01:57:37 +00:00
|
|
|
#ifdef DEBUG
|
1998-12-01 16:13:49 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsLineBox::LastChild() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n = GetChildCount() - 1;
|
1998-12-01 16:13:49 +00:00
|
|
|
while (--n >= 0) {
|
2003-06-30 10:46:59 +00:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
2012-03-08 01:57:37 +00:00
|
|
|
#endif
|
1998-12-01 16:13:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
1999-04-20 21:52:22 +00:00
|
|
|
nsLineBox::IndexOf(nsIFrame* aFrame) const
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i, n = GetChildCount();
|
1998-12-01 16:13:49 +00:00
|
|
|
nsIFrame* frame = mFirstChild;
|
1999-04-20 21:52:22 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
1998-12-01 16:13:49 +00:00
|
|
|
if (frame == aFrame) {
|
1999-04-20 21:52:22 +00:00
|
|
|
return i;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
2003-06-30 10:46:59 +00:00
|
|
|
frame = frame->GetNextSibling();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
1999-04-20 21:52:22 +00:00
|
|
|
return -1;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2003-11-10 23:36:06 +00:00
|
|
|
nsLineBox::IsEmpty() const
|
2001-10-25 01:08:40 +00:00
|
|
|
{
|
|
|
|
if (IsBlock())
|
2003-11-10 23:36:06 +00:00
|
|
|
return mFirstChild->IsEmpty();
|
2001-10-25 01:08:40 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n;
|
2001-10-25 01:08:40 +00:00
|
|
|
nsIFrame *kid;
|
|
|
|
for (n = GetChildCount(), kid = mFirstChild;
|
|
|
|
n > 0;
|
2003-06-30 10:46:59 +00:00
|
|
|
--n, kid = kid->GetNextSibling())
|
2001-10-25 01:08:40 +00:00
|
|
|
{
|
2003-11-10 23:36:06 +00:00
|
|
|
if (!kid->IsEmpty())
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-10-25 01:08:40 +00:00
|
|
|
}
|
2009-08-11 02:48:42 +00:00
|
|
|
if (HasBullet()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-08-11 02:48:42 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2001-10-25 01:08:40 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-11-07 05:25:56 +00:00
|
|
|
nsLineBox::CachedIsEmpty()
|
2004-11-24 13:22:10 +00:00
|
|
|
{
|
|
|
|
if (mFlags.mDirty) {
|
|
|
|
return IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFlags.mEmptyCacheValid) {
|
|
|
|
return mFlags.mEmptyCacheState;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool result;
|
2006-02-27 04:15:05 +00:00
|
|
|
if (IsBlock()) {
|
|
|
|
result = mFirstChild->CachedIsEmpty();
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n;
|
2006-02-27 04:15:05 +00:00
|
|
|
nsIFrame *kid;
|
2011-10-17 14:59:28 +00:00
|
|
|
result = true;
|
2006-02-27 04:15:05 +00:00
|
|
|
for (n = GetChildCount(), kid = mFirstChild;
|
|
|
|
n > 0;
|
|
|
|
--n, kid = kid->GetNextSibling())
|
|
|
|
{
|
|
|
|
if (!kid->CachedIsEmpty()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
result = false;
|
2006-02-27 04:15:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-11 02:48:42 +00:00
|
|
|
if (HasBullet()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
result = false;
|
2009-08-11 02:48:42 +00:00
|
|
|
}
|
2006-02-27 04:15:05 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mFlags.mEmptyCacheValid = true;
|
2004-11-24 13:22:10 +00:00
|
|
|
mFlags.mEmptyCacheState = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-12-01 16:13:49 +00:00
|
|
|
void
|
2009-12-24 05:21:15 +00:00
|
|
|
nsLineBox::DeleteLineList(nsPresContext* aPresContext, nsLineList& aLines,
|
2012-10-15 01:34:23 +00:00
|
|
|
nsIFrame* aDestructRoot, nsFrameList* aFrames)
|
1998-12-01 16:13:49 +00:00
|
|
|
{
|
2012-10-15 01:34:23 +00:00
|
|
|
nsIPresShell* shell = aPresContext->PresShell();
|
|
|
|
|
|
|
|
// Keep our line list and frame list up to date as we
|
|
|
|
// remove frames, in case something wants to traverse the
|
|
|
|
// frame tree while we're destroying.
|
|
|
|
while (!aLines.empty()) {
|
|
|
|
nsLineBox* line = aLines.front();
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(line->mFlags.mHasHashedFrames)) {
|
2012-10-15 01:34:23 +00:00
|
|
|
line->SwitchToCounter(); // Avoid expensive has table removals.
|
|
|
|
}
|
|
|
|
while (line->GetChildCount() > 0) {
|
|
|
|
nsIFrame* child = aFrames->RemoveFirstChild();
|
|
|
|
MOZ_ASSERT(child == line->mFirstChild, "Lines out of sync");
|
|
|
|
line->mFirstChild = aFrames->FirstChild();
|
|
|
|
line->NoteFrameRemoved(child);
|
|
|
|
child->DestroyFrom(aDestructRoot);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 01:34:23 +00:00
|
|
|
aLines.pop_front();
|
|
|
|
line->Destroy(shell);
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2001-10-25 01:08:40 +00:00
|
|
|
nsLineBox::RFindLineContaining(nsIFrame* aFrame,
|
|
|
|
const nsLineList::iterator& aBegin,
|
|
|
|
nsLineList::iterator& aEnd,
|
2009-10-02 16:31:43 +00:00
|
|
|
nsIFrame* aLastFrameBeforeEnd,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aFrameIndexInLine)
|
2001-10-25 01:08:40 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null ptr");
|
2012-03-11 02:32:27 +00:00
|
|
|
|
2009-10-02 16:31:43 +00:00
|
|
|
nsIFrame* curFrame = aLastFrameBeforeEnd;
|
2001-10-25 01:08:40 +00:00
|
|
|
while (aBegin != aEnd) {
|
|
|
|
--aEnd;
|
2012-03-08 01:57:37 +00:00
|
|
|
NS_ASSERTION(aEnd->LastChild() == curFrame, "Unexpected curFrame");
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(aEnd->mFlags.mHasHashedFrames) &&
|
2012-03-11 02:32:27 +00:00
|
|
|
!aEnd->Contains(aFrame)) {
|
|
|
|
if (aEnd->mFirstChild) {
|
|
|
|
curFrame = aEnd->mFirstChild->GetPrevSibling();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-02 16:31:43 +00:00
|
|
|
// i is the index of curFrame in aEnd
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t i = aEnd->GetChildCount() - 1;
|
2009-10-02 16:31:43 +00:00
|
|
|
while (i >= 0) {
|
|
|
|
if (curFrame == aFrame) {
|
|
|
|
*aFrameIndexInLine = i;
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-10-02 16:31:43 +00:00
|
|
|
}
|
|
|
|
--i;
|
|
|
|
curFrame = curFrame->GetPrevSibling();
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
2012-03-11 02:32:27 +00:00
|
|
|
MOZ_ASSERT(!aEnd->mFlags.mHasHashedFrames, "Contains lied to us!");
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
1999-04-20 21:52:22 +00:00
|
|
|
*aFrameIndexInLine = -1;
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1998-12-01 16:13:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-25 01:08:40 +00:00
|
|
|
nsCollapsingMargin
|
1999-10-14 23:10:03 +00:00
|
|
|
nsLineBox::GetCarriedOutBottomMargin() const
|
|
|
|
{
|
2001-10-25 01:08:40 +00:00
|
|
|
NS_ASSERTION(IsBlock(),
|
|
|
|
"GetCarriedOutBottomMargin called on non-block line.");
|
|
|
|
return (IsBlock() && mBlockData)
|
|
|
|
? mBlockData->mCarriedOutBottomMargin
|
|
|
|
: nsCollapsingMargin();
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2001-10-25 01:08:40 +00:00
|
|
|
nsLineBox::SetCarriedOutBottomMargin(nsCollapsingMargin aValue)
|
1999-10-14 23:10:03 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool changed = false;
|
1999-10-14 23:10:03 +00:00
|
|
|
if (IsBlock()) {
|
2004-09-18 14:39:07 +00:00
|
|
|
if (!aValue.IsZero()) {
|
1999-10-14 23:10:03 +00:00
|
|
|
if (!mBlockData) {
|
|
|
|
mBlockData = new ExtraBlockData(mBounds);
|
|
|
|
}
|
2011-04-29 05:02:16 +00:00
|
|
|
changed = aValue != mBlockData->mCarriedOutBottomMargin;
|
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
else if (mBlockData) {
|
2004-09-18 14:39:07 +00:00
|
|
|
changed = aValue != mBlockData->mCarriedOutBottomMargin;
|
1999-10-14 23:10:03 +00:00
|
|
|
mBlockData->mCarriedOutBottomMargin = aValue;
|
|
|
|
MaybeFreeData();
|
|
|
|
}
|
|
|
|
}
|
2004-09-18 14:39:07 +00:00
|
|
|
return changed;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineBox::MaybeFreeData()
|
|
|
|
{
|
2010-10-07 04:25:45 +00:00
|
|
|
if (mData && mData->mOverflowAreas == nsOverflowAreas(mBounds, mBounds)) {
|
1999-10-14 23:10:03 +00:00
|
|
|
if (IsInline()) {
|
2003-10-13 21:51:02 +00:00
|
|
|
if (mInlineData->mFloats.IsEmpty()) {
|
1999-10-14 23:10:03 +00:00
|
|
|
delete mInlineData;
|
2012-07-30 14:20:58 +00:00
|
|
|
mInlineData = nullptr;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
2001-10-25 01:08:40 +00:00
|
|
|
else if (mBlockData->mCarriedOutBottomMargin.IsZero()) {
|
1999-10-14 23:10:03 +00:00
|
|
|
delete mBlockData;
|
2012-07-30 14:20:58 +00:00
|
|
|
mBlockData = nullptr;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX get rid of this???
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache*
|
|
|
|
nsLineBox::GetFirstFloat()
|
1999-10-14 23:10:03 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
2012-07-30 14:20:58 +00:00
|
|
|
return mInlineData ? mInlineData->mFloats.Head() : nullptr;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX this might be too eager to free memory
|
|
|
|
void
|
2003-10-13 21:51:02 +00:00
|
|
|
nsLineBox::FreeFloats(nsFloatCacheFreeList& aFreeList)
|
1999-10-14 23:10:03 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
2006-04-17 01:47:11 +00:00
|
|
|
if (IsInline() && mInlineData) {
|
|
|
|
if (mInlineData->mFloats.NotEmpty()) {
|
2003-10-13 21:51:02 +00:00
|
|
|
aFreeList.Append(mInlineData->mFloats);
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
2006-04-17 01:47:11 +00:00
|
|
|
MaybeFreeData();
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-13 21:51:02 +00:00
|
|
|
nsLineBox::AppendFloats(nsFloatCacheFreeList& aFreeList)
|
2000-03-22 23:19:10 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
1999-10-14 23:10:03 +00:00
|
|
|
if (IsInline()) {
|
|
|
|
if (aFreeList.NotEmpty()) {
|
|
|
|
if (!mInlineData) {
|
|
|
|
mInlineData = new ExtraInlineData(mBounds);
|
|
|
|
}
|
2011-04-29 05:02:16 +00:00
|
|
|
mInlineData->mFloats.Append(aFreeList);
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2003-10-13 21:51:02 +00:00
|
|
|
nsLineBox::RemoveFloat(nsIFrame* aFrame)
|
1998-12-05 16:01:11 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
NS_ABORT_IF_FALSE(IsInline(), "block line can't have floats");
|
1999-10-14 23:10:03 +00:00
|
|
|
if (IsInline() && mInlineData) {
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* fc = mInlineData->mFloats.Find(aFrame);
|
1999-10-14 23:10:03 +00:00
|
|
|
if (fc) {
|
|
|
|
// Note: the placeholder is part of the line's child list
|
|
|
|
// and will be removed later.
|
2003-10-13 21:51:02 +00:00
|
|
|
mInlineData->mFloats.Remove(fc);
|
2005-10-21 22:23:28 +00:00
|
|
|
delete fc;
|
1999-10-14 23:10:03 +00:00
|
|
|
MaybeFreeData();
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-07 04:25:45 +00:00
|
|
|
nsLineBox::SetOverflowAreas(const nsOverflowAreas& aOverflowAreas)
|
|
|
|
{
|
|
|
|
NS_FOR_FRAME_OVERFLOW_TYPES(otype) {
|
|
|
|
NS_ASSERTION(aOverflowAreas.Overflow(otype).width >= 0,
|
|
|
|
"illegal width for combined area");
|
|
|
|
NS_ASSERTION(aOverflowAreas.Overflow(otype).height >= 0,
|
|
|
|
"illegal height for combined area");
|
|
|
|
}
|
2011-04-19 03:07:23 +00:00
|
|
|
if (!aOverflowAreas.VisualOverflow().IsEqualInterior(mBounds) ||
|
|
|
|
!aOverflowAreas.ScrollableOverflow().IsEqualEdges(mBounds)) {
|
2010-10-07 04:25:45 +00:00
|
|
|
if (!mData) {
|
1999-10-14 23:10:03 +00:00
|
|
|
if (IsInline()) {
|
2010-10-07 04:25:45 +00:00
|
|
|
mInlineData = new ExtraInlineData(mBounds);
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-10-07 04:25:45 +00:00
|
|
|
mBlockData = new ExtraBlockData(mBounds);
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-07 04:25:45 +00:00
|
|
|
mData->mOverflowAreas = aOverflowAreas;
|
1999-10-14 23:10:03 +00:00
|
|
|
}
|
2010-10-07 04:25:45 +00:00
|
|
|
else if (mData) {
|
|
|
|
// Store away new value so that MaybeFreeData compares against
|
|
|
|
// the right value.
|
|
|
|
mData->mOverflowAreas = aOverflowAreas;
|
1999-10-14 23:10:03 +00:00
|
|
|
MaybeFreeData();
|
|
|
|
}
|
1998-12-05 16:01:11 +00:00
|
|
|
}
|
1999-05-10 22:28:49 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-05-13 00:54:28 +00:00
|
|
|
|
1999-05-10 22:28:49 +00:00
|
|
|
static nsLineBox* gDummyLines[1];
|
|
|
|
|
|
|
|
nsLineIterator::nsLineIterator()
|
|
|
|
{
|
1999-05-13 00:54:28 +00:00
|
|
|
mLines = gDummyLines;
|
1999-05-10 22:28:49 +00:00
|
|
|
mNumLines = 0;
|
|
|
|
mIndex = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
mRightToLeft = false;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLineIterator::~nsLineIterator()
|
|
|
|
{
|
|
|
|
if (mLines != gDummyLines) {
|
|
|
|
delete [] mLines;
|
|
|
|
}
|
1999-05-10 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
2008-10-30 19:17:59 +00:00
|
|
|
/* virtual */ void
|
|
|
|
nsLineIterator::DisposeLineIterator()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
1999-05-13 00:54:28 +00:00
|
|
|
|
1999-05-10 22:28:49 +00:00
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
nsLineIterator::Init(nsLineList& aLines, bool aRightToLeft)
|
1999-05-10 22:28:49 +00:00
|
|
|
{
|
1999-05-13 00:54:28 +00:00
|
|
|
mRightToLeft = aRightToLeft;
|
|
|
|
|
1999-05-10 22:28:49 +00:00
|
|
|
// Count the lines
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t numLines = aLines.size();
|
1999-05-10 22:28:49 +00:00
|
|
|
if (0 == numLines) {
|
|
|
|
// Use gDummyLines so that we don't need null pointer checks in
|
|
|
|
// the accessor methods
|
|
|
|
mLines = gDummyLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a linear array of the lines
|
|
|
|
mLines = new nsLineBox*[numLines];
|
|
|
|
if (!mLines) {
|
|
|
|
// Use gDummyLines so that we don't need null pointer checks in
|
|
|
|
// the accessor methods
|
|
|
|
mLines = gDummyLines;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nsLineBox** lp = mLines;
|
2001-10-25 01:08:40 +00:00
|
|
|
for (nsLineList::iterator line = aLines.begin(), line_end = aLines.end() ;
|
|
|
|
line != line_end;
|
|
|
|
++line)
|
|
|
|
{
|
1999-05-10 22:28:49 +00:00
|
|
|
*lp++ = line;
|
|
|
|
}
|
|
|
|
mNumLines = numLines;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2008-10-30 19:17:59 +00:00
|
|
|
nsLineIterator::GetNumLines()
|
1999-05-10 22:28:49 +00:00
|
|
|
{
|
2008-10-30 19:17:59 +00:00
|
|
|
return mNumLines;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-10-30 19:17:59 +00:00
|
|
|
nsLineIterator::GetDirection()
|
1999-05-13 00:54:28 +00:00
|
|
|
{
|
2008-10-30 19:17:59 +00:00
|
|
|
return mRightToLeft;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineIterator::GetLine(int32_t aLineNumber,
|
1999-05-13 00:54:28 +00:00
|
|
|
nsIFrame** aFirstFrameOnLine,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aNumFramesOnLine,
|
1999-10-12 23:24:22 +00:00
|
|
|
nsRect& aLineBounds,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t* aLineFlags)
|
1999-05-13 00:54:28 +00:00
|
|
|
{
|
1999-10-12 23:24:22 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aFirstFrameOnLine);
|
|
|
|
NS_ENSURE_ARG_POINTER(aNumFramesOnLine);
|
|
|
|
NS_ENSURE_ARG_POINTER(aLineFlags);
|
|
|
|
|
1999-05-13 00:54:28 +00:00
|
|
|
if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aFirstFrameOnLine = nullptr;
|
1999-05-13 00:54:28 +00:00
|
|
|
*aNumFramesOnLine = 0;
|
|
|
|
aLineBounds.SetRect(0, 0, 0, 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsLineBox* line = mLines[aLineNumber];
|
|
|
|
*aFirstFrameOnLine = line->mFirstChild;
|
1999-10-14 23:10:03 +00:00
|
|
|
*aNumFramesOnLine = line->GetChildCount();
|
1999-05-13 00:54:28 +00:00
|
|
|
aLineBounds = line->mBounds;
|
1999-10-12 23:24:22 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags = 0;
|
1999-10-12 23:24:22 +00:00
|
|
|
if (line->IsBlock()) {
|
|
|
|
flags |= NS_LINE_FLAG_IS_BLOCK;
|
|
|
|
}
|
|
|
|
else {
|
2004-11-25 14:51:00 +00:00
|
|
|
if (line->HasBreakAfter())
|
1999-10-12 23:24:22 +00:00
|
|
|
flags |= NS_LINE_FLAG_ENDS_IN_BREAK;
|
|
|
|
}
|
|
|
|
*aLineFlags = flags;
|
|
|
|
|
1999-05-13 00:54:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
nsLineIterator::FindLineContaining(nsIFrame* aFrame, int32_t aStartLine)
|
1999-05-13 00:54:28 +00:00
|
|
|
{
|
2011-09-07 02:57:46 +00:00
|
|
|
NS_PRECONDITION(aStartLine <= mNumLines, "Bogus line numbers");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t lineNumber = aStartLine;
|
2001-10-25 01:08:40 +00:00
|
|
|
while (lineNumber != mNumLines) {
|
2011-09-07 02:57:46 +00:00
|
|
|
nsLineBox* line = mLines[lineNumber];
|
1999-05-13 00:54:28 +00:00
|
|
|
if (line->Contains(aFrame)) {
|
2008-10-30 19:17:59 +00:00
|
|
|
return lineNumber;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
2011-09-07 02:57:46 +00:00
|
|
|
++lineNumber;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
2008-10-30 19:17:59 +00:00
|
|
|
return -1;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
2001-03-09 03:29:00 +00:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineIterator::CheckLineOrder(int32_t aLine,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *aIsReordered,
|
2001-03-09 03:29:00 +00:00
|
|
|
nsIFrame **aFirstVisual,
|
|
|
|
nsIFrame **aLastVisual)
|
|
|
|
{
|
2006-03-20 09:20:49 +00:00
|
|
|
NS_ASSERTION (aLine >= 0 && aLine < mNumLines, "aLine out of range!");
|
2006-03-12 09:49:48 +00:00
|
|
|
nsLineBox* line = mLines[aLine];
|
2006-03-20 09:20:49 +00:00
|
|
|
|
|
|
|
if (!line->mFirstChild) { // empty line
|
2011-10-17 14:59:28 +00:00
|
|
|
*aIsReordered = false;
|
2012-07-30 14:20:58 +00:00
|
|
|
*aFirstVisual = nullptr;
|
|
|
|
*aLastVisual = nullptr;
|
2006-03-20 09:20:49 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-04-27 08:47:18 +00:00
|
|
|
|
2006-03-12 09:49:48 +00:00
|
|
|
nsIFrame* leftmostFrame;
|
|
|
|
nsIFrame* rightmostFrame;
|
2011-04-13 09:23:49 +00:00
|
|
|
*aIsReordered = nsBidiPresUtils::CheckLineOrder(line->mFirstChild, line->GetChildCount(), &leftmostFrame, &rightmostFrame);
|
2001-03-09 03:29:00 +00:00
|
|
|
|
2006-03-12 09:49:48 +00:00
|
|
|
// map leftmost/rightmost to first/last according to paragraph direction
|
|
|
|
*aFirstVisual = mRightToLeft ? rightmostFrame : leftmostFrame;
|
|
|
|
*aLastVisual = mRightToLeft ? leftmostFrame : rightmostFrame;
|
2001-03-09 03:29:00 +00:00
|
|
|
|
2006-03-12 09:49:48 +00:00
|
|
|
return NS_OK;
|
2001-03-09 03:29:00 +00:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-05-13 00:54:28 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineIterator::FindFrameAt(int32_t aLineNumber,
|
1999-05-13 00:54:28 +00:00
|
|
|
nscoord aX,
|
|
|
|
nsIFrame** aFrameFound,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aXIsBeforeFirstFrame,
|
|
|
|
bool* aXIsAfterLastFrame)
|
1999-05-13 00:54:28 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrameFound && aXIsBeforeFirstFrame && aXIsAfterLastFrame,
|
|
|
|
"null OUT ptr");
|
|
|
|
if (!aFrameFound || !aXIsBeforeFirstFrame || !aXIsAfterLastFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if ((aLineNumber < 0) || (aLineNumber >= mNumLines)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineBox* line = mLines[aLineNumber];
|
|
|
|
if (!line) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aFrameFound = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
*aXIsBeforeFirstFrame = true;
|
|
|
|
*aXIsAfterLastFrame = false;
|
1999-05-13 00:54:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-10-30 13:05:45 +00:00
|
|
|
if (line->mBounds.width == 0 && line->mBounds.height == 0)
|
2003-04-02 12:05:43 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
1999-05-13 00:54:28 +00:00
|
|
|
nsIFrame* frame = line->mFirstChild;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIFrame* closestFromLeft = nullptr;
|
|
|
|
nsIFrame* closestFromRight = nullptr;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t n = line->GetChildCount();
|
2005-08-02 21:55:55 +00:00
|
|
|
while (n--) {
|
|
|
|
nsRect rect = frame->GetRect();
|
|
|
|
if (rect.width > 0) {
|
|
|
|
// If aX is inside this frame - this is it
|
|
|
|
if (rect.x <= aX && rect.XMost() > aX) {
|
|
|
|
closestFromLeft = closestFromRight = frame;
|
1999-05-13 00:54:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-02 21:55:55 +00:00
|
|
|
if (rect.x < aX) {
|
|
|
|
if (!closestFromLeft ||
|
|
|
|
rect.XMost() > closestFromLeft->GetRect().XMost())
|
|
|
|
closestFromLeft = frame;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-08-02 21:55:55 +00:00
|
|
|
if (!closestFromRight ||
|
|
|
|
rect.x < closestFromRight->GetRect().x)
|
|
|
|
closestFromRight = frame;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
}
|
2005-08-02 21:55:55 +00:00
|
|
|
frame = frame->GetNextSibling();
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
2005-08-02 21:55:55 +00:00
|
|
|
if (!closestFromLeft && !closestFromRight) {
|
|
|
|
// All frames were zero-width. Just take the first one.
|
|
|
|
closestFromLeft = closestFromRight = line->mFirstChild;
|
|
|
|
}
|
|
|
|
*aXIsBeforeFirstFrame = mRightToLeft ? !closestFromRight : !closestFromLeft;
|
|
|
|
*aXIsAfterLastFrame = mRightToLeft ? !closestFromLeft : !closestFromRight;
|
|
|
|
if (closestFromLeft == closestFromRight) {
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
}
|
|
|
|
else if (!closestFromLeft) {
|
|
|
|
*aFrameFound = closestFromRight;
|
|
|
|
}
|
|
|
|
else if (!closestFromRight) {
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
}
|
|
|
|
else { // we're between two frames
|
|
|
|
nscoord delta = closestFromRight->GetRect().x - closestFromLeft->GetRect().XMost();
|
|
|
|
if (aX < closestFromLeft->GetRect().XMost() + delta/2)
|
|
|
|
*aFrameFound = closestFromLeft;
|
|
|
|
else
|
|
|
|
*aFrameFound = closestFromRight;
|
1999-05-13 00:54:28 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-05-10 22:28:49 +00:00
|
|
|
}
|
1999-09-15 00:28:10 +00:00
|
|
|
|
2000-05-11 01:04:39 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsLineIterator::GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber)
|
2000-05-11 01:04:39 +00:00
|
|
|
{
|
2003-06-30 10:46:59 +00:00
|
|
|
aFrame = aFrame->GetNextSibling();
|
|
|
|
return NS_OK;
|
2000-05-11 01:04:39 +00:00
|
|
|
}
|
|
|
|
|
1999-09-15 00:28:10 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2005-10-21 22:23:28 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsFloatCacheList::nsFloatCacheList() :
|
2012-07-30 14:20:58 +00:00
|
|
|
mHead(nullptr)
|
2005-10-21 22:23:28 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatCacheList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCacheList::~nsFloatCacheList()
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2006-06-29 01:19:48 +00:00
|
|
|
DeleteAll();
|
|
|
|
MOZ_COUNT_DTOR(nsFloatCacheList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatCacheList::DeleteAll()
|
|
|
|
{
|
|
|
|
nsFloatCache* c = mHead;
|
|
|
|
while (c) {
|
|
|
|
nsFloatCache* next = c->Next();
|
|
|
|
delete c;
|
|
|
|
c = next;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
mHead = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::Tail() const
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 00:28:10 +00:00
|
|
|
while (fc) {
|
|
|
|
if (!fc->mNext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->mNext;
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCacheList::Append(nsFloatCacheFreeList& aList)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2006-04-17 01:47:11 +00:00
|
|
|
NS_PRECONDITION(aList.NotEmpty(), "Appending empty list will fail");
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* tail = Tail();
|
1999-09-15 00:28:10 +00:00
|
|
|
if (tail) {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!tail->mNext, "Bogus!");
|
1999-09-15 00:28:10 +00:00
|
|
|
tail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!mHead, "Bogus!");
|
1999-09-15 00:28:10 +00:00
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
aList.mHead = nullptr;
|
|
|
|
aList.mTail = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::Find(nsIFrame* aOutOfFlowFrame)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 00:28:10 +00:00
|
|
|
while (fc) {
|
2009-08-31 18:25:35 +00:00
|
|
|
if (fc->mFloat == aOutOfFlowFrame) {
|
1999-09-15 00:28:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fc = fc->Next();
|
|
|
|
}
|
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
2006-06-29 01:19:48 +00:00
|
|
|
nsFloatCache*
|
|
|
|
nsFloatCacheList::RemoveAndReturnPrev(nsFloatCache* aElement)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2006-06-29 01:19:48 +00:00
|
|
|
nsFloatCache* fc = mHead;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsFloatCache* prev = nullptr;
|
2006-06-29 01:19:48 +00:00
|
|
|
while (fc) {
|
1999-09-15 00:28:10 +00:00
|
|
|
if (fc == aElement) {
|
2006-06-29 01:19:48 +00:00
|
|
|
if (prev) {
|
|
|
|
prev->mNext = fc->mNext;
|
|
|
|
} else {
|
|
|
|
mHead = fc->mNext;
|
|
|
|
}
|
|
|
|
return prev;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
2006-06-29 01:19:48 +00:00
|
|
|
prev = fc;
|
|
|
|
fc = fc->mNext;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2005-10-21 22:23:28 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsFloatCacheFreeList::nsFloatCacheFreeList() :
|
2012-07-30 14:20:58 +00:00
|
|
|
mTail(nullptr)
|
2005-10-21 22:23:28 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsFloatCacheFreeList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFloatCacheFreeList::~nsFloatCacheFreeList()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsFloatCacheFreeList);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-15 00:28:10 +00:00
|
|
|
void
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCacheFreeList::Append(nsFloatCacheList& aList)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2006-04-17 01:47:11 +00:00
|
|
|
NS_PRECONDITION(aList.NotEmpty(), "Appending empty list will fail");
|
|
|
|
|
1999-09-15 00:28:10 +00:00
|
|
|
if (mTail) {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!mTail->mNext, "Bogus");
|
1999-09-15 00:28:10 +00:00
|
|
|
mTail->mNext = aList.mHead;
|
|
|
|
}
|
|
|
|
else {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!mHead, "Bogus");
|
1999-09-15 00:28:10 +00:00
|
|
|
mHead = aList.mHead;
|
|
|
|
}
|
|
|
|
mTail = aList.Tail();
|
2012-07-30 14:20:58 +00:00
|
|
|
aList.mHead = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
|
2006-06-29 01:19:48 +00:00
|
|
|
void
|
|
|
|
nsFloatCacheFreeList::Remove(nsFloatCache* aElement)
|
|
|
|
{
|
|
|
|
nsFloatCache* prev = nsFloatCacheList::RemoveAndReturnPrev(aElement);
|
|
|
|
if (mTail == aElement) {
|
|
|
|
mTail = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFloatCacheFreeList::DeleteAll()
|
|
|
|
{
|
|
|
|
nsFloatCacheList::DeleteAll();
|
2012-07-30 14:20:58 +00:00
|
|
|
mTail = nullptr;
|
2006-06-29 01:19:48 +00:00
|
|
|
}
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache*
|
2009-08-31 18:25:36 +00:00
|
|
|
nsFloatCacheFreeList::Alloc(nsIFrame* aFloat)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2009-08-31 18:25:36 +00:00
|
|
|
NS_PRECONDITION(aFloat->GetStateBits() & NS_FRAME_OUT_OF_FLOW,
|
|
|
|
"This is a float cache, why isn't the frame out-of-flow?");
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache* fc = mHead;
|
1999-09-15 00:28:10 +00:00
|
|
|
if (mHead) {
|
|
|
|
if (mHead == mTail) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mHead = mTail = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mHead = fc->mNext;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
fc->mNext = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-10-13 21:51:02 +00:00
|
|
|
fc = new nsFloatCache();
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
2009-08-31 18:25:36 +00:00
|
|
|
fc->mFloat = aFloat;
|
1999-09-15 00:28:10 +00:00
|
|
|
return fc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCacheFreeList::Append(nsFloatCache* aFloat)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!aFloat->mNext, "Bogus!");
|
2012-07-30 14:20:58 +00:00
|
|
|
aFloat->mNext = nullptr;
|
1999-09-15 00:28:10 +00:00
|
|
|
if (mTail) {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!mTail->mNext, "Bogus!");
|
2003-10-13 21:51:02 +00:00
|
|
|
mTail->mNext = aFloat;
|
|
|
|
mTail = aFloat;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-10-21 22:23:28 +00:00
|
|
|
NS_ASSERTION(!mHead, "Bogus!");
|
2003-10-13 21:51:02 +00:00
|
|
|
mHead = mTail = aFloat;
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache::nsFloatCache()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mFloat(nullptr),
|
|
|
|
mNext(nullptr)
|
1999-09-15 00:28:10 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
MOZ_COUNT_CTOR(nsFloatCache);
|
1999-09-15 00:28:10 +00:00
|
|
|
}
|
1999-10-08 20:41:19 +00:00
|
|
|
|
2000-12-16 18:56:06 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2003-10-13 21:51:02 +00:00
|
|
|
nsFloatCache::~nsFloatCache()
|
1999-10-08 20:41:19 +00:00
|
|
|
{
|
2003-10-13 21:51:02 +00:00
|
|
|
MOZ_COUNT_DTOR(nsFloatCache);
|
1999-10-08 20:41:19 +00:00
|
|
|
}
|
|
|
|
#endif
|