2006-01-26 05:29:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2006-04-18 03:16:46 +04:00
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2006-01-26 05:29:17 +03:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Novell code.
|
|
|
|
*
|
2006-03-31 10:28:40 +04:00
|
|
|
* The Initial Developer of the Original Code is Novell Corporation.
|
2007-10-06 16:08:39 +04:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-01-26 05:29:17 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* robert@ocallahan.org
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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 MPL, 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 MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/*
|
|
|
|
* structures that represent things to be painted (ordered in z-order),
|
|
|
|
* used during painting and hit testing
|
|
|
|
*/
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRegion.h"
|
2006-04-27 06:45:03 +04:00
|
|
|
#include "nsFrameManager.h"
|
2006-02-16 02:21:12 +03:00
|
|
|
#include "gfxContext.h"
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
|
2008-04-11 07:46:37 +04:00
|
|
|
PRBool aIsForEvents, PRBool aBuildCaret)
|
2006-01-26 05:29:17 +03:00
|
|
|
: mReferenceFrame(aReferenceFrame),
|
2008-04-11 07:46:37 +04:00
|
|
|
mMovingFrame(nsnull),
|
2006-01-26 05:29:17 +03:00
|
|
|
mIgnoreScrollFrame(nsnull),
|
2008-04-06 15:34:14 +04:00
|
|
|
mCurrentTableItem(nsnull),
|
2006-04-18 03:16:46 +04:00
|
|
|
mBuildCaret(aBuildCaret),
|
2006-01-26 05:29:17 +03:00
|
|
|
mEventDelivery(aIsForEvents),
|
2007-03-19 06:25:05 +03:00
|
|
|
mIsAtRootOfPseudoStackingContext(PR_FALSE),
|
|
|
|
mPaintAllFrames(PR_FALSE) {
|
2006-01-26 05:29:17 +03:00
|
|
|
PL_InitArenaPool(&mPool, "displayListArena", 1024, sizeof(void*)-1);
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
2006-01-26 05:29:17 +03:00
|
|
|
nsIPresShell *shell = pc->PresShell();
|
|
|
|
PRBool suppressed;
|
|
|
|
shell->IsPaintingSuppressed(&suppressed);
|
|
|
|
mIsBackgroundOnly = suppressed;
|
|
|
|
if (pc->IsRenderingOnlySelection()) {
|
|
|
|
nsCOMPtr<nsISelectionController> selcon(do_QueryInterface(shell));
|
|
|
|
if (selcon) {
|
|
|
|
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(mBoundingSelection));
|
|
|
|
}
|
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
|
|
|
if (mIsBackgroundOnly) {
|
|
|
|
mBuildCaret = PR_FALSE;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
// Destructor function for the dirty rect property
|
|
|
|
static void
|
|
|
|
DestroyRectFunc(void* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue,
|
|
|
|
void* aDtorData)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
delete static_cast<nsRect*>(aPropertyValue);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MarkFrameForDisplay(nsIFrame* aFrame, nsIFrame* aStopAtFrame) {
|
2007-03-31 01:11:41 +04:00
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->PresShell()->FrameManager();
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, f)) {
|
2006-04-27 06:45:03 +04:00
|
|
|
if (f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)
|
|
|
|
return;
|
|
|
|
f->AddStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
if (f == aStopAtFrame) {
|
|
|
|
// we've reached a frame that we know will be painted, so we can stop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MarkOutOfFlowFrameForDisplay(nsIFrame* aDirtyFrame, nsIFrame* aFrame,
|
|
|
|
const nsRect& aDirtyRect) {
|
|
|
|
nsRect dirty = aDirtyRect - aFrame->GetOffsetTo(aDirtyFrame);
|
|
|
|
nsRect overflowRect = aFrame->GetOverflowRect();
|
|
|
|
if (!dirty.IntersectRect(dirty, overflowRect))
|
|
|
|
return;
|
|
|
|
// if "new nsRect" fails, this won't do anything, but that's okay
|
2006-12-26 20:47:52 +03:00
|
|
|
aFrame->SetProperty(nsGkAtoms::outOfFlowDirtyRectProperty,
|
2006-04-27 06:45:03 +04:00
|
|
|
new nsRect(dirty), DestroyRectFunc);
|
|
|
|
|
|
|
|
MarkFrameForDisplay(aFrame, aDirtyFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnmarkFrameForDisplay(nsIFrame* aFrame) {
|
2006-12-26 20:47:52 +03:00
|
|
|
aFrame->DeleteProperty(nsGkAtoms::outOfFlowDirtyRectProperty);
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->PresShell()->FrameManager();
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, f)) {
|
2006-04-27 06:45:03 +04:00
|
|
|
if (!(f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO))
|
|
|
|
return;
|
|
|
|
f->RemoveStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListBuilder::~nsDisplayListBuilder() {
|
2008-01-04 04:53:01 +03:00
|
|
|
NS_ASSERTION(mFramesMarkedForDisplay.Length() == 0,
|
|
|
|
"All frames should have been unmarked");
|
|
|
|
NS_ASSERTION(mPresShellStates.Length() == 0,
|
|
|
|
"All presshells should have been exited");
|
2008-04-06 15:34:14 +04:00
|
|
|
NS_ASSERTION(!mCurrentTableItem, "No table item should be active");
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
PL_FreeArenaPool(&mPool);
|
|
|
|
PL_FinishArenaPool(&mPool);
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
nsICaret *
|
|
|
|
nsDisplayListBuilder::GetCaret() {
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
2008-01-04 04:53:01 +03:00
|
|
|
CurrentPresShellState()->mPresShell->GetCaret(getter_AddRefs(caret));
|
2006-04-18 03:16:46 +04:00
|
|
|
return caret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-04 04:53:01 +03:00
|
|
|
PresShellState* state = mPresShellStates.AppendElement();
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
state->mPresShell = aReferenceFrame->PresContext()->PresShell();
|
|
|
|
state->mCaretFrame = nsnull;
|
|
|
|
state->mFirstFrameMarkedForDisplay = mFramesMarkedForDisplay.Length();
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
if (!mBuildCaret)
|
2006-04-18 03:16:46 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
2008-01-04 04:53:01 +03:00
|
|
|
state->mPresShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
state->mCaretFrame = caret->GetCaretFrame();
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2008-01-04 04:53:01 +03:00
|
|
|
if (state->mCaretFrame) {
|
2006-04-27 06:45:03 +04:00
|
|
|
// Check if the dirty rect intersects with the caret's dirty rect.
|
|
|
|
nsRect caretRect =
|
2008-01-04 04:53:01 +03:00
|
|
|
caret->GetCaretRect() + state->mCaretFrame->GetOffsetTo(aReferenceFrame);
|
2006-04-27 06:45:03 +04:00
|
|
|
if (caretRect.Intersects(aDirtyRect)) {
|
|
|
|
// Okay, our rects intersect, let's mark the frame and all of its ancestors.
|
2008-01-04 04:53:01 +03:00
|
|
|
mFramesMarkedForDisplay.AppendElement(state->mCaretFrame);
|
|
|
|
MarkFrameForDisplay(state->mCaretFrame, nsnull);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::LeavePresShell(nsIFrame* aReferenceFrame,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
2008-01-04 04:53:01 +03:00
|
|
|
if (CurrentPresShellState()->mPresShell != aReferenceFrame->PresContext()->PresShell()) {
|
|
|
|
// Must have not allocated a state for this presshell, presumably due
|
|
|
|
// to OOM.
|
2006-04-18 03:16:46 +04:00
|
|
|
return;
|
2008-01-04 04:53:01 +03:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2008-01-04 04:53:01 +03:00
|
|
|
// Unmark and pop off the frames marked for display in this pres shell.
|
|
|
|
PRUint32 firstFrameForShell = CurrentPresShellState()->mFirstFrameMarkedForDisplay;
|
|
|
|
for (PRUint32 i = firstFrameForShell;
|
|
|
|
i < mFramesMarkedForDisplay.Length(); ++i) {
|
|
|
|
UnmarkFrameForDisplay(mFramesMarkedForDisplay[i]);
|
|
|
|
}
|
|
|
|
mFramesMarkedForDisplay.SetLength(firstFrameForShell);
|
|
|
|
mPresShellStates.SetLength(mPresShellStates.Length() - 1);
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame, nsIFrame* aFrames,
|
|
|
|
const nsRect& aDirtyRect) {
|
|
|
|
while (aFrames) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(aFrames);
|
|
|
|
MarkOutOfFlowFrameForDisplay(aDirtyFrame, aFrames, aDirtyRect);
|
|
|
|
aFrames = aFrames->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void*
|
|
|
|
nsDisplayListBuilder::Allocate(size_t aSize) {
|
|
|
|
void *tmp;
|
|
|
|
PL_ARENA_ALLOCATE(tmp, &mPool, aSize);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayListSet::MoveTo(const nsDisplayListSet& aDestination) const
|
|
|
|
{
|
|
|
|
aDestination.BorderBackground()->AppendToTop(BorderBackground());
|
|
|
|
aDestination.BlockBorderBackgrounds()->AppendToTop(BlockBorderBackgrounds());
|
|
|
|
aDestination.Floats()->AppendToTop(Floats());
|
|
|
|
aDestination.Content()->AppendToTop(Content());
|
|
|
|
aDestination.PositionedDescendants()->AppendToTop(PositionedDescendants());
|
|
|
|
aDestination.Outlines()->AppendToTop(Outlines());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suitable for leaf items only, overridden by nsDisplayWrapList
|
|
|
|
PRBool
|
|
|
|
nsDisplayItem::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
nsRect bounds = GetBounds(aBuilder);
|
|
|
|
if (!aVisibleRegion->Intersects(bounds))
|
|
|
|
return PR_FALSE;
|
2008-04-11 07:46:37 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsIFrame* f = GetUnderlyingFrame();
|
|
|
|
NS_ASSERTION(f, "GetUnderlyingFrame() must return non-null for leaf items");
|
2008-04-11 07:46:37 +04:00
|
|
|
PRBool isMoving = aBuilder->IsMovingFrame(f);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
if (IsOpaque(aBuilder)) {
|
2008-04-11 07:46:37 +04:00
|
|
|
nsRect opaqueArea = bounds;
|
|
|
|
if (isMoving) {
|
|
|
|
// The display list should include items for both the before and after
|
|
|
|
// states (see nsLayoutUtils::ComputeRepaintRegionForCopy. So the
|
|
|
|
// only area we want to cover is the the area that was opaque in the
|
|
|
|
// before state and in the after state.
|
|
|
|
opaqueArea.IntersectRect(bounds - aBuilder->GetMoveDelta(), bounds);
|
|
|
|
}
|
|
|
|
aVisibleRegion->SimpleSubtract(opaqueArea);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2008-04-11 07:46:37 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-11 23:31:39 +03:00
|
|
|
nsDisplayList::FlattenTo(nsTArray<nsDisplayItem*>* aElements) {
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = RemoveBottom()) != nsnull) {
|
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_WRAPLIST) {
|
|
|
|
item->GetList()->FlattenTo(aElements);
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
} else {
|
|
|
|
aElements->AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayList::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
2007-11-11 23:31:39 +03:00
|
|
|
nsAutoTArray<nsDisplayItem*, 512> elements;
|
2006-01-26 05:29:17 +03:00
|
|
|
FlattenTo(&elements);
|
2007-11-11 23:31:39 +03:00
|
|
|
|
|
|
|
for (PRInt32 i = elements.Length() - 1; i >= 0; --i) {
|
|
|
|
nsDisplayItem* item = elements[i];
|
|
|
|
nsDisplayItem* belowItem = i < 1 ? nsnull : elements[i - 1];
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
if (belowItem && item->TryMerge(aBuilder, belowItem)) {
|
2006-01-29 21:48:58 +03:00
|
|
|
belowItem->~nsDisplayItem();
|
2007-11-11 23:31:39 +03:00
|
|
|
elements.ReplaceElementsAt(i - 1, 1, item);
|
2006-01-26 05:29:17 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->OptimizeVisibility(aBuilder, aVisibleRegion)) {
|
|
|
|
AppendToBottom(item);
|
|
|
|
} else {
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::Paint(nsDisplayListBuilder* aBuilder, nsIRenderingContext* aCtx,
|
|
|
|
const nsRect& aDirtyRect) const {
|
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nsnull; i = i->GetAbove()) {
|
|
|
|
i->Paint(aBuilder, aCtx, aDirtyRect);
|
|
|
|
}
|
2007-05-05 03:28:00 +04:00
|
|
|
nsCSSRendering::DidPaint();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 nsDisplayList::Count() const {
|
|
|
|
PRUint32 count = 0;
|
|
|
|
for (nsDisplayItem* i = GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem* nsDisplayList::RemoveBottom() {
|
|
|
|
nsDisplayItem* item = mSentinel.mAbove;
|
|
|
|
if (!item)
|
|
|
|
return nsnull;
|
|
|
|
mSentinel.mAbove = item->mAbove;
|
|
|
|
if (item == mTop) {
|
|
|
|
// must have been the only item
|
|
|
|
mTop = &mSentinel;
|
|
|
|
}
|
|
|
|
item->mAbove = nsnull;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::DeleteBottom() {
|
|
|
|
nsDisplayItem* item = RemoveBottom();
|
|
|
|
if (item) {
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::DeleteAll() {
|
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = RemoveBottom()) != nsnull) {
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-04 05:08:29 +03:00
|
|
|
nsIFrame* nsDisplayList::HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
nsDisplayItem::HitTestState* aState) const {
|
|
|
|
PRInt32 itemBufferStart = aState->mItemBuffer.Length();
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayItem* item;
|
|
|
|
for (item = GetBottom(); item; item = item->GetAbove()) {
|
2008-01-04 05:08:29 +03:00
|
|
|
aState->mItemBuffer.AppendElement(item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2008-01-04 05:08:29 +03:00
|
|
|
for (PRInt32 i = aState->mItemBuffer.Length() - 1; i >= itemBufferStart; --i) {
|
|
|
|
// Pop element off the end of the buffer. We want to shorten the buffer
|
|
|
|
// so that recursive calls to HitTest have more buffer space.
|
|
|
|
item = aState->mItemBuffer[i];
|
|
|
|
aState->mItemBuffer.SetLength(i);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
if (item->GetBounds(aBuilder).Contains(aPt)) {
|
2008-01-04 05:08:29 +03:00
|
|
|
nsIFrame* f = item->HitTest(aBuilder, aPt, aState);
|
2006-01-26 05:29:17 +03:00
|
|
|
// Handle the XUL 'mousethrough' feature.
|
|
|
|
if (f) {
|
2008-01-04 05:08:29 +03:00
|
|
|
if (!f->GetMouseThrough()) {
|
|
|
|
aState->mItemBuffer.SetLength(itemBufferStart);
|
2006-01-26 05:29:17 +03:00
|
|
|
return f;
|
2008-01-04 05:08:29 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-04 05:08:29 +03:00
|
|
|
NS_ASSERTION(aState->mItemBuffer.Length() == itemBufferStart,
|
|
|
|
"How did we forget to pop some elements?");
|
2006-01-26 05:29:17 +03:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-04-18 02:16:24 +04:00
|
|
|
static void Sort(nsDisplayList* aList, PRInt32 aCount, nsDisplayList::SortLEQ aCmp,
|
|
|
|
void* aClosure) {
|
2006-01-26 05:29:17 +03:00
|
|
|
if (aCount < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsDisplayList list1;
|
|
|
|
nsDisplayList list2;
|
|
|
|
int i;
|
|
|
|
PRInt32 half = aCount/2;
|
|
|
|
PRBool sorted = PR_TRUE;
|
|
|
|
nsDisplayItem* prev = nsnull;
|
|
|
|
for (i = 0; i < aCount; ++i) {
|
|
|
|
nsDisplayItem* item = aList->RemoveBottom();
|
|
|
|
(i < half ? &list1 : &list2)->AppendToTop(item);
|
|
|
|
if (sorted && prev && !aCmp(prev, item, aClosure)) {
|
|
|
|
sorted = PR_FALSE;
|
|
|
|
}
|
|
|
|
prev = item;
|
|
|
|
}
|
|
|
|
if (sorted) {
|
|
|
|
aList->AppendToTop(&list1);
|
|
|
|
aList->AppendToTop(&list2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sort(&list1, half, aCmp, aClosure);
|
|
|
|
Sort(&list2, aCount - half, aCmp, aClosure);
|
|
|
|
|
|
|
|
for (i = 0; i < aCount; ++i) {
|
|
|
|
if (list1.GetBottom() &&
|
|
|
|
(!list2.GetBottom() ||
|
|
|
|
aCmp(list1.GetBottom(), list2.GetBottom(), aClosure))) {
|
|
|
|
aList->AppendToTop(list1.RemoveBottom());
|
|
|
|
} else {
|
|
|
|
aList->AppendToTop(list2.RemoveBottom());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool IsContentLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
|
|
|
void* aClosure) {
|
|
|
|
// These GetUnderlyingFrame calls return non-null because we're only used
|
|
|
|
// in sorting
|
|
|
|
return nsLayoutUtils::CompareTreePosition(
|
|
|
|
aItem1->GetUnderlyingFrame()->GetContent(),
|
|
|
|
aItem2->GetUnderlyingFrame()->GetContent(),
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIContent*>(aClosure)) <= 0;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool IsZOrderLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
|
|
|
void* aClosure) {
|
|
|
|
// These GetUnderlyingFrame calls return non-null because we're only used
|
|
|
|
// in sorting
|
|
|
|
PRInt32 diff = nsLayoutUtils::GetZIndex(aItem1->GetUnderlyingFrame()) -
|
|
|
|
nsLayoutUtils::GetZIndex(aItem2->GetUnderlyingFrame());
|
|
|
|
if (diff == 0)
|
|
|
|
return IsContentLEQ(aItem1, aItem2, aClosure);
|
|
|
|
return diff < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::ExplodeAnonymousChildLists(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// See if there's anything to do
|
|
|
|
PRBool anyAnonymousItems = PR_FALSE;
|
|
|
|
nsDisplayItem* i;
|
|
|
|
for (i = GetBottom(); i != nsnull; i = i->GetAbove()) {
|
|
|
|
if (!i->GetUnderlyingFrame()) {
|
|
|
|
anyAnonymousItems = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!anyAnonymousItems)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsDisplayList tmp;
|
|
|
|
while ((i = RemoveBottom()) != nsnull) {
|
|
|
|
if (i->GetUnderlyingFrame()) {
|
|
|
|
tmp.AppendToTop(i);
|
|
|
|
} else {
|
|
|
|
nsDisplayList* list = i->GetList();
|
|
|
|
NS_ASSERTION(list, "leaf items can't be anonymous");
|
|
|
|
list->ExplodeAnonymousChildLists(aBuilder);
|
|
|
|
nsDisplayItem* j;
|
|
|
|
while ((j = list->RemoveBottom()) != nsnull) {
|
2007-07-08 11:08:04 +04:00
|
|
|
tmp.AppendToTop(static_cast<nsDisplayWrapList*>(i)->
|
2006-01-26 05:29:17 +03:00
|
|
|
WrapWithClone(aBuilder, j));
|
|
|
|
}
|
2006-01-29 21:48:58 +03:00
|
|
|
i->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendToTop(&tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByZOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 06:25:23 +04:00
|
|
|
Sort(aBuilder, IsZOrderLEQ, aCommonAncestor);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByContentOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 06:25:23 +04:00
|
|
|
Sort(aBuilder, IsContentLEQ, aCommonAncestor);
|
2006-04-18 02:16:24 +04:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:25:23 +04:00
|
|
|
void nsDisplayList::Sort(nsDisplayListBuilder* aBuilder,
|
|
|
|
SortLEQ aCmp, void* aClosure) {
|
|
|
|
ExplodeAnonymousChildLists(aBuilder);
|
2006-04-18 02:16:24 +04:00
|
|
|
::Sort(this, Count(), aCmp, aClosure);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayBackground::IsOpaque(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// theme background overrides any other background
|
2007-12-18 08:26:38 +03:00
|
|
|
if (mIsThemed)
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground* bg;
|
|
|
|
PRBool hasBG =
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg, &isCanvas);
|
2006-11-23 04:12:52 +03:00
|
|
|
if (!hasBG || (bg->mBackgroundFlags & NS_STYLE_BG_COLOR_TRANSPARENT) ||
|
|
|
|
bg->mBackgroundClip != NS_STYLE_BG_CLIP_BORDER ||
|
2007-05-10 19:46:42 +04:00
|
|
|
nsLayoutUtils::HasNonZeroSide(mFrame->GetStyleBorder()->mBorderRadius) ||
|
2006-11-23 04:12:52 +03:00
|
|
|
NS_GET_A(bg->mBackgroundColor) < 255)
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
2006-11-23 04:12:52 +03:00
|
|
|
return PR_TRUE;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayBackground::IsUniform(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// theme background overrides any other background
|
2007-12-18 08:26:38 +03:00
|
|
|
if (mIsThemed)
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground* bg;
|
|
|
|
PRBool hasBG =
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg, &isCanvas);
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!hasBG)
|
|
|
|
return PR_TRUE;
|
|
|
|
if ((bg->mBackgroundFlags & NS_STYLE_BG_IMAGE_NONE) &&
|
2007-05-10 19:46:42 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroSide(mFrame->GetStyleBorder()->mBorderRadius) &&
|
2006-01-26 05:29:17 +03:00
|
|
|
bg->mBackgroundClip == NS_STYLE_BG_CLIP_BORDER)
|
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-04-11 07:46:37 +04:00
|
|
|
nsDisplayBackground::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2008-04-11 07:46:37 +04:00
|
|
|
NS_ASSERTION(aBuilder->IsMovingFrame(mFrame),
|
|
|
|
"IsVaryingRelativeToMovingFrame called on non-moving frame!");
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2006-01-26 05:29:17 +03:00
|
|
|
PRBool isCanvas;
|
|
|
|
const nsStyleBackground* bg;
|
|
|
|
PRBool hasBG =
|
2008-04-11 07:46:37 +04:00
|
|
|
nsCSSRendering::FindBackground(presContext, mFrame, &bg, &isCanvas);
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!hasBG)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (!bg->HasFixedBackground())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-04-11 07:46:37 +04:00
|
|
|
nsIFrame* movingFrame = aBuilder->GetRootMovingFrame();
|
|
|
|
// movingFrame is the frame that is going to be moved. It must be equal
|
|
|
|
// to mFrame or some ancestor of mFrame, see assertion above.
|
|
|
|
// If mFrame is in the same document as movingFrame, then mFrame
|
2007-02-24 03:23:42 +03:00
|
|
|
// will move relative to its viewport, which means this display item will
|
2008-04-11 07:46:37 +04:00
|
|
|
// change when it is moved. If they are in different documents, we do not
|
2007-02-24 03:23:42 +03:00
|
|
|
// want to return true because mFrame won't move relative to its viewport.
|
2008-04-11 07:46:37 +04:00
|
|
|
return movingFrame->PresContext() == presContext;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayBackground::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
2006-01-26 05:29:17 +03:00
|
|
|
aDirtyRect, nsRect(offset, mFrame->GetSize()),
|
|
|
|
*mFrame->GetStyleBorder(),
|
|
|
|
*mFrame->GetStylePadding(),
|
|
|
|
mFrame->HonorPrintBackgroundSettings());
|
|
|
|
}
|
|
|
|
|
2007-12-18 08:26:38 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayBackground::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
if (mIsThemed)
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
|
|
|
|
return nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayOutline::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
// TODO join outlines together
|
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintOutline(mFrame->PresContext(), *aCtx, mFrame,
|
2006-01-26 05:29:17 +03:00
|
|
|
aDirtyRect, nsRect(offset, mFrame->GetSize()),
|
|
|
|
*mFrame->GetStyleBorder(),
|
|
|
|
*mFrame->GetStyleOutline(),
|
|
|
|
mFrame->GetStyleContext(), 0);
|
|
|
|
}
|
|
|
|
|
2006-09-20 01:58:52 +04:00
|
|
|
PRBool
|
|
|
|
nsDisplayOutline::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
if (!nsDisplayItem::OptimizeVisibility(aBuilder, aVisibleRegion))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleOutline* outline = mFrame->GetStyleOutline();
|
|
|
|
nsPoint origin = aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
if (nsRect(origin, mFrame->GetSize()).Contains(aVisibleRegion->GetBounds()) &&
|
2007-05-10 19:46:42 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroSide(outline->mOutlineRadius)) {
|
2006-09-20 01:58:52 +04:00
|
|
|
nscoord outlineOffset;
|
|
|
|
outline->GetOutlineOffset(outlineOffset);
|
|
|
|
if (outlineOffset >= 0) {
|
|
|
|
// the visible region is entirely inside the border-rect, and the outline
|
|
|
|
// isn't rendered inside the border-rect, so the outline is not visible
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
void
|
|
|
|
nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
// Note: Because we exist, we know that the caret is visible, so we don't
|
|
|
|
// need to check for the caret's visibility.
|
2008-06-23 12:50:52 +04:00
|
|
|
mCaret->PaintCaret(aBuilder, aCtx, mFrame, aBuilder->ToReferenceFrame(mFrame));
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2006-09-20 01:58:52 +04:00
|
|
|
PRBool
|
|
|
|
nsDisplayBorder::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
if (!nsDisplayItem::OptimizeVisibility(aBuilder, aVisibleRegion))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-09-28 02:52:32 +04:00
|
|
|
nsRect paddingRect = mFrame->GetPaddingRect() - mFrame->GetPosition() +
|
|
|
|
aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
if (paddingRect.Contains(aVisibleRegion->GetBounds()) &&
|
|
|
|
!nsLayoutUtils::HasNonZeroSide(mFrame->GetStyleBorder()->mBorderRadius)) {
|
2006-09-20 01:58:52 +04:00
|
|
|
// the visible region is entirely inside the content rect, and no part
|
|
|
|
// of the border is rendered inside the content rect, so we are not
|
|
|
|
// visible
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2006-01-26 05:29:17 +03:00
|
|
|
aDirtyRect, nsRect(offset, mFrame->GetSize()),
|
|
|
|
*mFrame->GetStyleBorder(),
|
|
|
|
mFrame->GetStyleContext(), mFrame->GetSkipSides());
|
|
|
|
}
|
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadow::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
nsCSSRendering::PaintBoxShadow(mFrame->PresContext(), *aCtx,
|
|
|
|
mFrame, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayBoxShadow::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsIFrame* aFrame, nsDisplayList* aList)
|
2006-03-14 23:43:18 +03:00
|
|
|
: nsDisplayItem(aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsIFrame* aFrame, nsDisplayItem* aItem)
|
2006-03-14 23:43:18 +03:00
|
|
|
: nsDisplayItem(aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
2008-01-04 05:08:29 +03:00
|
|
|
nsDisplayWrapList::HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
HitTestState* aState) {
|
|
|
|
return mList.HitTest(aBuilder, aPt, aState);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayWrapList::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
nsRect bounds;
|
|
|
|
for (nsDisplayItem* i = mList.GetBottom(); i != nsnull; i = i->GetAbove()) {
|
|
|
|
bounds.UnionRect(bounds, i->GetBounds(aBuilder));
|
|
|
|
}
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayWrapList::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
mList.OptimizeVisibility(aBuilder, aVisibleRegion);
|
|
|
|
// If none of the items are visible, they will all have been deleted
|
|
|
|
return mList.GetTop() != nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayWrapList::IsOpaque(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// We could try to do something but let's conservatively just return PR_FALSE.
|
|
|
|
// We reimplement OptimizeVisibility and that's what really matters
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayWrapList::IsUniform(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// We could try to do something but let's conservatively just return PR_FALSE.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-04-11 07:46:37 +04:00
|
|
|
PRBool nsDisplayWrapList::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// The only existing consumer of IsVaryingRelativeToMovingFrame is
|
|
|
|
// nsLayoutUtils::ComputeRepaintRegionForCopy, which refrains from calling
|
|
|
|
// this on wrapped lists.
|
|
|
|
NS_WARNING("nsDisplayWrapList::IsVaryingRelativeToMovingFrame called unexpectedly");
|
|
|
|
// We could try to do something but let's conservatively just return PR_TRUE.
|
|
|
|
return PR_TRUE;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayWrapList::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
mList.Paint(aBuilder, aCtx, aDirtyRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
WrapDisplayList(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
|
|
|
if (!aList->GetTop())
|
|
|
|
return NS_OK;
|
|
|
|
nsDisplayItem* item = aWrapper->WrapList(aBuilder, aFrame, aList);
|
|
|
|
if (!item)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// aList was emptied
|
|
|
|
aList->AppendToTop(item);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
WrapEachDisplayItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
|
|
|
nsDisplayList newList;
|
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = aList->RemoveBottom())) {
|
|
|
|
item = aWrapper->WrapItem(aBuilder, item);
|
|
|
|
if (!item)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newList.AppendToTop(item);
|
|
|
|
}
|
|
|
|
// aList was emptied
|
|
|
|
aList->AppendToTop(&newList);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDisplayWrapper::WrapLists(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsDisplayListSet& aIn, const nsDisplayListSet& aOut)
|
|
|
|
{
|
|
|
|
nsresult rv = WrapListsInPlace(aBuilder, aFrame, aIn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (&aOut == &aIn)
|
|
|
|
return NS_OK;
|
|
|
|
aOut.BorderBackground()->AppendToTop(aIn.BorderBackground());
|
|
|
|
aOut.BlockBorderBackgrounds()->AppendToTop(aIn.BlockBorderBackgrounds());
|
|
|
|
aOut.Floats()->AppendToTop(aIn.Floats());
|
|
|
|
aOut.Content()->AppendToTop(aIn.Content());
|
|
|
|
aOut.PositionedDescendants()->AppendToTop(aIn.PositionedDescendants());
|
|
|
|
aOut.Outlines()->AppendToTop(aIn.Outlines());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDisplayWrapper::WrapListsInPlace(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (WrapBorderBackground()) {
|
|
|
|
// Our border-backgrounds are in-flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.BorderBackground(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// Our block border-backgrounds are in-flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.BlockBorderBackgrounds(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The floats are not in flow
|
|
|
|
rv = WrapEachDisplayItem(aBuilder, aLists.Floats(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Our child content is in flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.Content(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The positioned descendants may not be in-flow
|
|
|
|
rv = WrapEachDisplayItem(aBuilder, aLists.PositionedDescendants(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The outlines may not be in-flow
|
|
|
|
return WrapEachDisplayItem(aBuilder, aLists.Outlines(), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayOpacity::nsDisplayOpacity(nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aFrame, aList), mNeedAlpha(PR_TRUE) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOpacity::~nsDisplayOpacity() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOpacity);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2006-01-29 21:48:58 +03:00
|
|
|
#endif
|
2006-01-26 05:29:17 +03:00
|
|
|
|
|
|
|
PRBool nsDisplayOpacity::IsOpaque(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// We are never opaque, if our opacity was < 1 then we wouldn't have
|
|
|
|
// been created.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayOpacity::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect)
|
|
|
|
{
|
2006-02-09 04:24:30 +03:00
|
|
|
float opacity = mFrame->GetStyleDisplay()->mOpacity;
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect bounds;
|
|
|
|
bounds.IntersectRect(GetBounds(aBuilder), aDirtyRect);
|
2006-02-09 04:24:30 +03:00
|
|
|
|
2006-02-16 02:21:12 +03:00
|
|
|
nsCOMPtr<nsIDeviceContext> devCtx;
|
|
|
|
aCtx->GetDeviceContext(*getter_AddRefs(devCtx));
|
|
|
|
|
2008-06-11 04:37:11 +04:00
|
|
|
gfxContext* ctx = aCtx->ThebesContext();
|
2006-02-16 02:21:12 +03:00
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
ctx->NewPath();
|
2008-06-11 04:37:11 +04:00
|
|
|
gfxRect r(bounds.x, bounds.y, bounds.width, bounds.height);
|
|
|
|
r.ScaleInverse(devCtx->AppUnitsPerDevPixel());
|
|
|
|
ctx->Rectangle(r, PR_TRUE);
|
2006-02-16 02:21:12 +03:00
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
if (mNeedAlpha)
|
2006-08-10 00:25:07 +04:00
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2006-02-16 02:21:12 +03:00
|
|
|
else
|
2006-08-10 00:25:07 +04:00
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR);
|
2006-02-16 02:21:12 +03:00
|
|
|
|
|
|
|
nsDisplayWrapList::Paint(aBuilder, aCtx, bounds);
|
|
|
|
|
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
ctx->Paint(opacity);
|
|
|
|
|
|
|
|
ctx->Restore();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayOpacity::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
// Our children are translucent so we should not allow them to subtract
|
|
|
|
// area from aVisibleRegion. We do need to find out what is visible under
|
|
|
|
// our children in the temporary compositing buffer, because if our children
|
|
|
|
// paint our entire bounds opaquely then we don't need an alpha channel in
|
|
|
|
// the temporary compositing buffer.
|
|
|
|
nsRegion visibleUnderChildren = *aVisibleRegion;
|
|
|
|
PRBool anyVisibleChildren =
|
|
|
|
nsDisplayWrapList::OptimizeVisibility(aBuilder, &visibleUnderChildren);
|
|
|
|
if (!anyVisibleChildren)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
mNeedAlpha = visibleUnderChildren.Intersects(GetBounds(aBuilder));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayOpacity::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_OPACITY)
|
|
|
|
return PR_FALSE;
|
|
|
|
// items for the same content element should be merged into a single
|
|
|
|
// compositing group
|
|
|
|
// aItem->GetUnderlyingFrame() returns non-null because it's nsDisplayOpacity
|
|
|
|
if (aItem->GetUnderlyingFrame()->GetContent() != mFrame->GetContent())
|
|
|
|
return PR_FALSE;
|
2007-07-08 11:08:04 +04:00
|
|
|
mList.AppendToBottom(&static_cast<nsDisplayOpacity*>(aItem)->mList);
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-18 13:21:21 +04:00
|
|
|
nsDisplayClip::nsDisplayClip(nsIFrame* aFrame, nsIFrame* aClippingFrame,
|
|
|
|
nsDisplayItem* aItem, const nsRect& aRect)
|
|
|
|
: nsDisplayWrapList(aFrame, aItem),
|
|
|
|
mClippingFrame(aClippingFrame), mClip(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2008-04-18 13:21:21 +04:00
|
|
|
nsDisplayClip::nsDisplayClip(nsIFrame* aFrame, nsIFrame* aClippingFrame,
|
|
|
|
nsDisplayList* aList, const nsRect& aRect)
|
|
|
|
: nsDisplayWrapList(aFrame, aList),
|
|
|
|
mClippingFrame(aClippingFrame), mClip(aRect) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect nsDisplayClip::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
nsRect r = nsDisplayWrapList::GetBounds(aBuilder);
|
|
|
|
r.IntersectRect(mClip, r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-01-29 21:48:58 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayClip::~nsDisplayClip() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayClip);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void nsDisplayClip::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx, const nsRect& aDirtyRect) {
|
|
|
|
nsRect dirty;
|
|
|
|
dirty.IntersectRect(mClip, aDirtyRect);
|
|
|
|
aCtx->PushState();
|
|
|
|
aCtx->SetClipRect(dirty, nsClipCombine_kIntersect);
|
|
|
|
nsDisplayWrapList::Paint(aBuilder, aCtx, dirty);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayClip::OptimizeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
nsRegion rNew(clipped);
|
|
|
|
PRBool anyVisible = nsDisplayWrapList::OptimizeVisibility(aBuilder, &rNew);
|
|
|
|
nsRegion subtracted;
|
|
|
|
subtracted.Sub(clipped, rNew);
|
|
|
|
aVisibleRegion->SimpleSubtract(subtracted);
|
|
|
|
return anyVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayClip::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_CLIP)
|
|
|
|
return PR_FALSE;
|
2007-07-08 11:08:04 +04:00
|
|
|
nsDisplayClip* other = static_cast<nsDisplayClip*>(aItem);
|
2008-04-18 13:21:21 +04:00
|
|
|
if (other->mClip != mClip || other->mClippingFrame != mClippingFrame)
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
mList.AppendToBottom(&other->mList);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList* nsDisplayClip::WrapWithClone(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
2008-04-18 13:21:21 +04:00
|
|
|
return new (aBuilder)
|
|
|
|
nsDisplayClip(aItem->GetUnderlyingFrame(), mClippingFrame, aItem, mClip);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|