2006-01-26 02:29:17 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2006-04-17 23:16:46 +00:00
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2006-01-26 02:29:17 +00: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 06:28:40 +00:00
|
|
|
* The Initial Developer of the Original Code is Novell Corporation.
|
2007-10-06 12:08:39 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2006-01-26 02:29:17 +00: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 05:56:38 +00:00
|
|
|
/*
|
|
|
|
* structures that represent things to be painted (ordered in z-order),
|
|
|
|
* used during painting and hit testing
|
|
|
|
*/
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRegion.h"
|
2006-04-27 02:45:03 +00:00
|
|
|
#include "nsFrameManager.h"
|
2006-02-15 23:21:12 +00:00
|
|
|
#include "gfxContext.h"
|
2008-07-17 06:30:25 +00:00
|
|
|
#include "nsStyleStructInlines.h"
|
2008-09-13 09:42:11 +00:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
|
|
|
#include "gfxMatrix.h"
|
2008-09-11 00:24:16 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
#endif
|
2009-07-22 00:44:57 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-02-15 23:21:12 +00:00
|
|
|
|
2009-04-08 15:19:51 +00:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
|
2008-04-11 03:46:37 +00:00
|
|
|
PRBool aIsForEvents, PRBool aBuildCaret)
|
2006-01-26 02:29:17 +00:00
|
|
|
: mReferenceFrame(aReferenceFrame),
|
2008-04-11 03:46:37 +00:00
|
|
|
mMovingFrame(nsnull),
|
2009-08-14 02:09:51 +00:00
|
|
|
mSaveVisibleRegionOfMovingContent(nsnull),
|
2006-01-26 02:29:17 +00:00
|
|
|
mIgnoreScrollFrame(nsnull),
|
2008-04-06 11:34:14 +00:00
|
|
|
mCurrentTableItem(nsnull),
|
2006-04-17 23:16:46 +00:00
|
|
|
mBuildCaret(aBuildCaret),
|
2006-01-26 02:29:17 +00:00
|
|
|
mEventDelivery(aIsForEvents),
|
2007-03-19 03:25:05 +00:00
|
|
|
mIsAtRootOfPseudoStackingContext(PR_FALSE),
|
2009-07-22 00:44:56 +00:00
|
|
|
mPaintAllFrames(PR_FALSE),
|
2009-07-22 00:45:14 +00:00
|
|
|
mAccurateVisibleRegions(PR_FALSE),
|
2009-09-12 22:44:18 +00:00
|
|
|
mInTransform(PR_FALSE),
|
|
|
|
mSyncDecodeImages(PR_FALSE) {
|
2006-01-26 02:29:17 +00:00
|
|
|
PL_InitArenaPool(&mPool, "displayListArena", 1024, sizeof(void*)-1);
|
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
2006-01-26 02:29:17 +00: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-17 23:16:46 +00:00
|
|
|
|
|
|
|
if (mIsBackgroundOnly) {
|
|
|
|
mBuildCaret = PR_FALSE;
|
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2006-04-27 02:45:03 +00:00
|
|
|
// Destructor function for the dirty rect property
|
|
|
|
static void
|
|
|
|
DestroyRectFunc(void* aFrame,
|
|
|
|
nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue,
|
|
|
|
void* aDtorData)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
delete static_cast<nsRect*>(aPropertyValue);
|
2006-04-27 02:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MarkFrameForDisplay(nsIFrame* aFrame, nsIFrame* aStopAtFrame) {
|
2007-03-30 21:11:41 +00:00
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->PresShell()->FrameManager();
|
2006-04-27 02:45:03 +00:00
|
|
|
|
2006-10-19 01:47:47 +00:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, f)) {
|
2006-04-27 02:45:03 +00: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 17:47:52 +00:00
|
|
|
aFrame->SetProperty(nsGkAtoms::outOfFlowDirtyRectProperty,
|
2006-04-27 02:45:03 +00:00
|
|
|
new nsRect(dirty), DestroyRectFunc);
|
|
|
|
|
|
|
|
MarkFrameForDisplay(aFrame, aDirtyFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnmarkFrameForDisplay(nsIFrame* aFrame) {
|
2006-12-26 17:47:52 +00:00
|
|
|
aFrame->DeleteProperty(nsGkAtoms::outOfFlowDirtyRectProperty);
|
2006-04-27 02:45:03 +00:00
|
|
|
|
2007-03-30 21:11:41 +00:00
|
|
|
nsFrameManager* frameManager = aFrame->PresContext()->PresShell()->FrameManager();
|
2006-04-27 02:45:03 +00:00
|
|
|
|
2006-10-19 01:47:47 +00:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(frameManager, f)) {
|
2006-04-27 02:45:03 +00:00
|
|
|
if (!(f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO))
|
|
|
|
return;
|
|
|
|
f->RemoveStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDisplayListBuilder::~nsDisplayListBuilder() {
|
2008-01-04 01:53:01 +00: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 11:34:14 +00:00
|
|
|
NS_ASSERTION(!mCurrentTableItem, "No table item should be active");
|
2006-04-27 02:45:03 +00:00
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
PL_FreeArenaPool(&mPool);
|
|
|
|
PL_FinishArenaPool(&mPool);
|
|
|
|
}
|
|
|
|
|
2009-09-12 22:44:18 +00:00
|
|
|
PRUint32
|
|
|
|
nsDisplayListBuilder::GetBackgroundPaintFlags() {
|
|
|
|
PRUint32 flags = 0;
|
|
|
|
if (mSyncDecodeImages) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-08-14 02:09:51 +00:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion,
|
|
|
|
const nsRegion& aRegion)
|
|
|
|
{
|
2009-09-19 12:12:48 +00:00
|
|
|
nsRegion tmp;
|
|
|
|
tmp.Sub(*aVisibleRegion, aRegion);
|
|
|
|
// Don't let *aVisibleRegion get too complex, but don't let it fluff out
|
|
|
|
// to its bounds either, which can be very bad (see bug 516740).
|
|
|
|
if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15) {
|
|
|
|
*aVisibleRegion = tmp;
|
2009-08-14 02:09:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 00:44:57 +00:00
|
|
|
PRBool
|
|
|
|
nsDisplayListBuilder::IsMovingFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return mMovingFrame &&
|
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(mMovingFrame, aFrame, mReferenceFrame);
|
|
|
|
}
|
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
nsCaret *
|
2006-04-17 23:16:46 +00:00
|
|
|
nsDisplayListBuilder::GetCaret() {
|
2008-07-16 10:52:01 +00:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2008-01-04 01:53:01 +00:00
|
|
|
CurrentPresShellState()->mPresShell->GetCaret(getter_AddRefs(caret));
|
2006-04-17 23:16:46 +00:00
|
|
|
return caret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-04 01:53:01 +00:00
|
|
|
PresShellState* state = mPresShellStates.AppendElement();
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
state->mPresShell = aReferenceFrame->PresContext()->PresShell();
|
|
|
|
state->mCaretFrame = nsnull;
|
|
|
|
state->mFirstFrameMarkedForDisplay = mFramesMarkedForDisplay.Length();
|
|
|
|
|
2009-04-25 08:19:23 +00:00
|
|
|
state->mPresShell->UpdateCanvasBackground();
|
|
|
|
|
2006-04-27 02:45:03 +00:00
|
|
|
if (!mBuildCaret)
|
2006-04-17 23:16:46 +00:00
|
|
|
return;
|
|
|
|
|
2008-07-16 10:52:01 +00:00
|
|
|
nsRefPtr<nsCaret> caret;
|
2008-01-04 01:53:01 +00:00
|
|
|
state->mPresShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
state->mCaretFrame = caret->GetCaretFrame();
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2008-01-04 01:53:01 +00:00
|
|
|
if (state->mCaretFrame) {
|
2006-04-27 02:45:03 +00:00
|
|
|
// Check if the dirty rect intersects with the caret's dirty rect.
|
|
|
|
nsRect caretRect =
|
2008-01-04 01:53:01 +00:00
|
|
|
caret->GetCaretRect() + state->mCaretFrame->GetOffsetTo(aReferenceFrame);
|
2006-04-27 02:45:03 +00:00
|
|
|
if (caretRect.Intersects(aDirtyRect)) {
|
|
|
|
// Okay, our rects intersect, let's mark the frame and all of its ancestors.
|
2008-01-04 01:53:01 +00:00
|
|
|
mFramesMarkedForDisplay.AppendElement(state->mCaretFrame);
|
|
|
|
MarkFrameForDisplay(state->mCaretFrame, nsnull);
|
2006-04-27 02:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-17 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::LeavePresShell(nsIFrame* aReferenceFrame,
|
2009-04-25 08:19:23 +00:00
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-04 01:53:01 +00:00
|
|
|
if (CurrentPresShellState()->mPresShell != aReferenceFrame->PresContext()->PresShell()) {
|
|
|
|
// Must have not allocated a state for this presshell, presumably due
|
|
|
|
// to OOM.
|
2006-04-17 23:16:46 +00:00
|
|
|
return;
|
2008-01-04 01:53:01 +00:00
|
|
|
}
|
2006-04-17 23:16:46 +00:00
|
|
|
|
2008-01-04 01:53:01 +00: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-17 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2006-04-27 02:45:03 +00:00
|
|
|
void
|
2009-07-28 12:51:09 +00:00
|
|
|
nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame,
|
|
|
|
const nsFrameList& aFrames,
|
2006-04-27 02:45:03 +00:00
|
|
|
const nsRect& aDirtyRect) {
|
2009-07-28 12:51:09 +00:00
|
|
|
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(e.get());
|
|
|
|
MarkOutOfFlowFrameForDisplay(aDirtyFrame, e.get(), aDirtyRect);
|
2006-04-27 02:45:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void*
|
|
|
|
nsDisplayListBuilder::Allocate(size_t aSize) {
|
|
|
|
void *tmp;
|
|
|
|
PL_ARENA_ALLOCATE(tmp, &mPool, aSize);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2009-08-14 02:09:51 +00:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::AccumulateVisibleRegionOfMovingContent(const nsRegion& aMovingContent,
|
2009-10-07 04:28:41 +00:00
|
|
|
const nsRegion& aVisibleRegionBeforeMove,
|
|
|
|
const nsRegion& aVisibleRegionAfterMove)
|
2009-08-14 02:09:51 +00:00
|
|
|
{
|
|
|
|
if (!mSaveVisibleRegionOfMovingContent)
|
|
|
|
return;
|
|
|
|
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion beforeRegion = aMovingContent;
|
|
|
|
beforeRegion.MoveBy(-mMoveDelta);
|
|
|
|
beforeRegion.And(beforeRegion, aVisibleRegionBeforeMove);
|
|
|
|
nsRegion afterRegion = aMovingContent;
|
|
|
|
afterRegion.And(afterRegion, aVisibleRegionAfterMove);
|
|
|
|
|
|
|
|
// Accumulate these regions into our result
|
|
|
|
mSaveVisibleRegionOfMovingContent->Or(
|
|
|
|
*mSaveVisibleRegionOfMovingContent, beforeRegion);
|
2009-08-14 02:09:51 +00:00
|
|
|
mSaveVisibleRegionOfMovingContent->Or(
|
2009-10-07 04:28:41 +00:00
|
|
|
*mSaveVisibleRegionOfMovingContent, afterRegion);
|
2009-08-14 02:09:51 +00:00
|
|
|
mSaveVisibleRegionOfMovingContent->SimplifyOutward(15);
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-11 20:31:39 +00:00
|
|
|
nsDisplayList::FlattenTo(nsTArray<nsDisplayItem*>* aElements) {
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = RemoveBottom()) != nsnull) {
|
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_WRAPLIST) {
|
|
|
|
item->GetList()->FlattenTo(aElements);
|
2006-01-29 18:48:58 +00:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 02:29:17 +00:00
|
|
|
} else {
|
|
|
|
aElements->AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 00:24:16 +00:00
|
|
|
nsRect
|
|
|
|
nsDisplayList::GetBounds(nsDisplayListBuilder* aBuilder) const {
|
|
|
|
nsRect bounds;
|
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nsnull; i = i->GetAbove()) {
|
|
|
|
bounds.UnionRect(bounds, i->GetBounds(aBuilder));
|
|
|
|
}
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayList::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
2007-11-11 20:31:39 +00:00
|
|
|
nsAutoTArray<nsDisplayItem*, 512> elements;
|
2006-01-26 02:29:17 +00:00
|
|
|
FlattenTo(&elements);
|
2007-11-11 20:31:39 +00:00
|
|
|
|
2009-11-03 18:39:42 +00:00
|
|
|
// Accumulate the bounds of all moving content we find in this list.
|
|
|
|
// For speed, we store only a bounding box, not a region.
|
2009-08-14 02:09:51 +00:00
|
|
|
nsRect movingContentAccumulatedBounds;
|
2009-10-07 04:28:41 +00:00
|
|
|
// Store an overapproximation of the visible regions for the moving
|
2009-08-14 02:09:51 +00:00
|
|
|
// content in this list
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion movingContentVisibleRegionBeforeMove;
|
|
|
|
nsRegion movingContentVisibleRegionAfterMove;
|
2009-08-14 02:09:51 +00:00
|
|
|
|
2007-11-11 20:31:39 +00: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 02:29:17 +00:00
|
|
|
|
|
|
|
if (belowItem && item->TryMerge(aBuilder, belowItem)) {
|
2006-01-29 18:48:58 +00:00
|
|
|
belowItem->~nsDisplayItem();
|
2007-11-11 20:31:39 +00:00
|
|
|
elements.ReplaceElementsAt(i - 1, 1, item);
|
2006-01-26 02:29:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-08-14 02:09:51 +00:00
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
nsRect bounds = item->GetBounds(aBuilder);
|
|
|
|
|
2009-08-14 02:09:51 +00:00
|
|
|
nsIFrame* f = item->GetUnderlyingFrame();
|
2009-09-07 00:35:14 +00:00
|
|
|
PRBool isMoving = f && aBuilder->IsMovingFrame(f);
|
2009-11-03 18:39:42 +00:00
|
|
|
// Record bounds of moving visible items in movingContentAccumulatedBounds.
|
|
|
|
// We do not need to add items that are uniform across the entire visible
|
|
|
|
// area, since they have no visible movement.
|
|
|
|
if (isMoving &&
|
|
|
|
!(item->IsUniform(aBuilder) &&
|
|
|
|
bounds.Contains(aVisibleRegion->GetBounds()) &&
|
|
|
|
bounds.Contains(aVisibleRegionBeforeMove->GetBounds()))) {
|
2009-08-14 02:09:51 +00:00
|
|
|
if (movingContentAccumulatedBounds.IsEmpty()) {
|
|
|
|
// *aVisibleRegion can only shrink during this loop, so storing
|
|
|
|
// the first one we see is a sound overapproximation
|
2009-10-07 04:28:41 +00:00
|
|
|
movingContentVisibleRegionBeforeMove = *aVisibleRegionBeforeMove;
|
|
|
|
movingContentVisibleRegionAfterMove = *aVisibleRegion;
|
2009-08-14 02:09:51 +00:00
|
|
|
}
|
2009-09-07 00:35:12 +00:00
|
|
|
nscoord appUnitsPerPixel = f->PresContext()->AppUnitsPerDevPixel();
|
2009-09-07 00:35:14 +00:00
|
|
|
nsRect roundOutBounds = bounds.
|
2009-09-07 00:35:12 +00:00
|
|
|
ToOutsidePixels(appUnitsPerPixel).ToAppUnits(appUnitsPerPixel);
|
2009-08-14 02:09:51 +00:00
|
|
|
movingContentAccumulatedBounds.UnionRect(movingContentAccumulatedBounds,
|
2009-09-07 00:35:14 +00:00
|
|
|
roundOutBounds);
|
2009-08-14 02:09:51 +00:00
|
|
|
}
|
2009-09-07 00:35:14 +00:00
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2009-10-07 04:28:41 +00:00
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
// Treat the item as visible if it was visible before or after the move.
|
|
|
|
itemVisible.Or(*aVisibleRegion, *aVisibleRegionBeforeMove);
|
|
|
|
itemVisible.And(itemVisible, bounds);
|
|
|
|
} else {
|
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
|
|
|
}
|
2009-09-07 00:35:14 +00:00
|
|
|
item->mVisibleRect = itemVisible.GetBounds();
|
|
|
|
|
|
|
|
if (!item->mVisibleRect.IsEmpty() &&
|
2009-10-07 04:28:41 +00:00
|
|
|
item->ComputeVisibility(aBuilder, aVisibleRegion, aVisibleRegionBeforeMove)) {
|
2006-01-26 02:29:17 +00:00
|
|
|
AppendToBottom(item);
|
2009-09-07 00:35:14 +00:00
|
|
|
|
|
|
|
if (item->IsOpaque(aBuilder) && f) {
|
2009-10-07 04:28:41 +00:00
|
|
|
// Subtract opaque item from the visible region
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, nsRegion(bounds));
|
|
|
|
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
nsRect opaqueAreaBeforeMove =
|
|
|
|
isMoving ? bounds - aBuilder->GetMoveDelta() : bounds;
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegionBeforeMove,
|
|
|
|
nsRegion(opaqueAreaBeforeMove));
|
2009-09-07 00:35:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
} else {
|
2006-01-29 18:48:58 +00:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-14 02:09:51 +00:00
|
|
|
|
|
|
|
aBuilder->AccumulateVisibleRegionOfMovingContent(
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion(movingContentAccumulatedBounds),
|
|
|
|
movingContentVisibleRegionBeforeMove,
|
|
|
|
movingContentVisibleRegionAfterMove);
|
2009-09-07 00:35:14 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mDidComputeVisibility = PR_TRUE;
|
|
|
|
#endif
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
void nsDisplayList::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIRenderingContext* aCtx) const {
|
|
|
|
NS_ASSERTION(mDidComputeVisibility,
|
|
|
|
"Must call ComputeVisibility before calling Paint");
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nsnull; i = i->GetAbove()) {
|
2009-09-07 00:35:14 +00:00
|
|
|
i->Paint(aBuilder, aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2007-05-04 23:28:00 +00:00
|
|
|
nsCSSRendering::DidPaint();
|
2006-01-26 02:29:17 +00: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 18:48:58 +00:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::DeleteAll() {
|
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = RemoveBottom()) != nsnull) {
|
2006-01-29 18:48:58 +00:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-04 02:08:29 +00:00
|
|
|
nsIFrame* nsDisplayList::HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
nsDisplayItem::HitTestState* aState) const {
|
|
|
|
PRInt32 itemBufferStart = aState->mItemBuffer.Length();
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDisplayItem* item;
|
|
|
|
for (item = GetBottom(); item; item = item->GetAbove()) {
|
2008-01-04 02:08:29 +00:00
|
|
|
aState->mItemBuffer.AppendElement(item);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2008-01-04 02:08:29 +00: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 02:29:17 +00:00
|
|
|
if (item->GetBounds(aBuilder).Contains(aPt)) {
|
2008-01-04 02:08:29 +00:00
|
|
|
nsIFrame* f = item->HitTest(aBuilder, aPt, aState);
|
2009-08-27 03:53:35 +00:00
|
|
|
// Handle the XUL 'mousethrough' feature and 'pointer-events'.
|
2006-01-26 02:29:17 +00:00
|
|
|
if (f) {
|
2009-08-27 03:53:35 +00:00
|
|
|
if (!f->GetMouseThrough() &&
|
|
|
|
f->GetStyleVisibility()->mPointerEvents != NS_STYLE_POINTER_EVENTS_NONE) {
|
2008-01-04 02:08:29 +00:00
|
|
|
aState->mItemBuffer.SetLength(itemBufferStart);
|
2006-01-26 02:29:17 +00:00
|
|
|
return f;
|
2008-01-04 02:08:29 +00:00
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-13 09:42:11 +00:00
|
|
|
NS_ASSERTION(aState->mItemBuffer.Length() == PRUint32(itemBufferStart),
|
2008-01-04 02:08:29 +00:00
|
|
|
"How did we forget to pop some elements?");
|
2006-01-26 02:29:17 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2006-04-17 22:16:24 +00:00
|
|
|
static void Sort(nsDisplayList* aList, PRInt32 aCount, nsDisplayList::SortLEQ aCmp,
|
|
|
|
void* aClosure) {
|
2006-01-26 02:29:17 +00: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 07:08:04 +00:00
|
|
|
static_cast<nsIContent*>(aClosure)) <= 0;
|
2006-01-26 02:29:17 +00: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 07:08:04 +00:00
|
|
|
tmp.AppendToTop(static_cast<nsDisplayWrapList*>(i)->
|
2006-01-26 02:29:17 +00:00
|
|
|
WrapWithClone(aBuilder, j));
|
|
|
|
}
|
2006-01-29 18:48:58 +00:00
|
|
|
i->~nsDisplayItem();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendToTop(&tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByZOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 02:25:23 +00:00
|
|
|
Sort(aBuilder, IsZOrderLEQ, aCommonAncestor);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByContentOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 02:25:23 +00:00
|
|
|
Sort(aBuilder, IsContentLEQ, aCommonAncestor);
|
2006-04-17 22:16:24 +00:00
|
|
|
}
|
|
|
|
|
2006-04-27 02:25:23 +00:00
|
|
|
void nsDisplayList::Sort(nsDisplayListBuilder* aBuilder,
|
|
|
|
SortLEQ aCmp, void* aClosure) {
|
|
|
|
ExplodeAnonymousChildLists(aBuilder);
|
2006-04-17 22:16:24 +00:00
|
|
|
::Sort(this, Count(), aCmp, aClosure);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2009-04-25 08:19:23 +00:00
|
|
|
void nsDisplaySolidColor::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2009-04-25 08:19:23 +00:00
|
|
|
aCtx->SetColor(mColor);
|
2009-09-07 00:35:14 +00:00
|
|
|
aCtx->FillRect(mVisibleRect);
|
2009-04-25 08:19:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 09:24:44 +00:00
|
|
|
// Returns TRUE if aContainedRect is guaranteed to be contained in
|
|
|
|
// the rounded rect defined by aRoundedRect and aRadii. Complex cases are
|
|
|
|
// handled conservatively by returning FALSE in some situations where
|
|
|
|
// a more thorough analysis could return TRUE.
|
|
|
|
static PRBool RoundedRectContainsRect(const nsRect& aRoundedRect,
|
|
|
|
const nscoord aRadii[8],
|
|
|
|
const nsRect& aContainedRect) {
|
|
|
|
// rectFullHeight and rectFullWidth together will approximately contain
|
|
|
|
// the total area of the frame minus the rounded corners.
|
|
|
|
nsRect rectFullHeight = aRoundedRect;
|
2009-09-16 15:01:36 +00:00
|
|
|
nscoord xDiff = NS_MAX(aRadii[NS_CORNER_TOP_LEFT_X], aRadii[NS_CORNER_BOTTOM_LEFT_X]);
|
2009-04-24 09:24:44 +00:00
|
|
|
rectFullHeight.x += xDiff;
|
2009-09-16 15:01:36 +00:00
|
|
|
rectFullHeight.width -= NS_MAX(aRadii[NS_CORNER_TOP_RIGHT_X],
|
2009-04-24 09:24:44 +00:00
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X]) + xDiff;
|
|
|
|
if (rectFullHeight.Contains(aContainedRect))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
nsRect rectFullWidth = aRoundedRect;
|
2009-09-16 15:01:36 +00:00
|
|
|
nscoord yDiff = NS_MAX(aRadii[NS_CORNER_TOP_LEFT_Y], aRadii[NS_CORNER_TOP_RIGHT_Y]);
|
2009-04-24 09:24:44 +00:00
|
|
|
rectFullWidth.y += yDiff;
|
2009-09-16 15:01:36 +00:00
|
|
|
rectFullWidth.height -= NS_MAX(aRadii[NS_CORNER_BOTTOM_LEFT_Y],
|
2009-04-24 09:24:44 +00:00
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) + yDiff;
|
|
|
|
if (rectFullWidth.Contains(aContainedRect))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
PRBool
|
|
|
|
nsDisplayBackground::IsOpaque(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// theme background overrides any other background
|
2007-12-18 05:26:38 +00:00
|
|
|
if (mIsThemed)
|
2006-01-26 02:29:17 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleBackground* bg;
|
2008-09-12 15:35:53 +00:00
|
|
|
|
2009-04-08 15:19:51 +00:00
|
|
|
if (!nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleBackground::Layer& bottomLayer = bg->BottomLayer();
|
|
|
|
|
|
|
|
// bottom layer's clip is used for the color
|
|
|
|
if (bottomLayer.mClip != NS_STYLE_BG_CLIP_BORDER ||
|
|
|
|
nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-07-04 09:30:59 +00:00
|
|
|
if (NS_GET_A(bg->mBackgroundColor) == 255 &&
|
|
|
|
!nsCSSRendering::IsCanvasFrame(mFrame))
|
2009-04-08 15:19:51 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
2009-08-21 20:39:25 +00:00
|
|
|
return bottomLayer.mRepeat == NS_STYLE_BG_REPEAT_XY &&
|
|
|
|
bottomLayer.mImage.IsOpaque();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayBackground::IsUniform(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// theme background overrides any other background
|
2007-12-18 05:26:38 +00:00
|
|
|
if (mIsThemed)
|
2006-01-26 02:29:17 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleBackground* bg;
|
|
|
|
PRBool hasBG =
|
2009-02-16 01:11:34 +00:00
|
|
|
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bg);
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!hasBG)
|
|
|
|
return PR_TRUE;
|
2009-08-21 20:39:25 +00:00
|
|
|
if (bg->BottomLayer().mImage.IsEmpty() &&
|
2009-02-20 05:29:21 +00:00
|
|
|
bg->mImageCount == 1 &&
|
2008-10-01 05:50:52 +00:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius) &&
|
2009-02-20 05:29:21 +00:00
|
|
|
bg->BottomLayer().mClip == NS_STYLE_BG_CLIP_BORDER)
|
2006-01-26 02:29:17 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-04-11 03:46:37 +00:00
|
|
|
nsDisplayBackground::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2008-04-11 03:46:37 +00:00
|
|
|
NS_ASSERTION(aBuilder->IsMovingFrame(mFrame),
|
|
|
|
"IsVaryingRelativeToMovingFrame called on non-moving frame!");
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2006-01-26 02:29:17 +00:00
|
|
|
const nsStyleBackground* bg;
|
|
|
|
PRBool hasBG =
|
2009-02-16 01:11:34 +00:00
|
|
|
nsCSSRendering::FindBackground(presContext, mFrame, &bg);
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!hasBG)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (!bg->HasFixedBackground())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-04-11 03:46:37 +00: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 00:23:42 +00:00
|
|
|
// will move relative to its viewport, which means this display item will
|
2008-04-11 03:46:37 +00:00
|
|
|
// change when it is moved. If they are in different documents, we do not
|
2007-02-24 00:23:42 +00:00
|
|
|
// want to return true because mFrame won't move relative to its viewport.
|
2008-04-11 03:46:37 +00:00
|
|
|
return movingFrame->PresContext() == presContext;
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2006-01-26 02:29:17 +00:00
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2009-09-12 22:44:18 +00:00
|
|
|
PRUint32 flags = aBuilder->GetBackgroundPaintFlags();
|
2009-05-28 05:01:42 +00:00
|
|
|
nsDisplayItem* nextItem = GetAbove();
|
|
|
|
if (nextItem && nextItem->GetUnderlyingFrame() == mFrame &&
|
|
|
|
nextItem->GetType() == TYPE_BORDER) {
|
2009-09-12 22:44:18 +00:00
|
|
|
flags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER;
|
2009-05-28 05:01:42 +00:00
|
|
|
}
|
2007-03-30 21:11:41 +00:00
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 00:35:14 +00:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2009-05-28 05:01:42 +00:00
|
|
|
flags);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 05:26:38 +00:00
|
|
|
nsRect
|
|
|
|
nsDisplayBackground::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
if (mIsThemed)
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
|
|
|
|
return nsRect(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsRect
|
|
|
|
nsDisplayOutline::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2006-01-26 02:29:17 +00:00
|
|
|
// TODO join outlines together
|
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2007-03-30 21:11:41 +00:00
|
|
|
nsCSSRendering::PaintOutline(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 00:35:14 +00:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2006-01-26 02:29:17 +00:00
|
|
|
*mFrame->GetStyleBorder(),
|
2008-08-06 10:33:18 +00:00
|
|
|
*mFrame->GetStyleOutline(),
|
|
|
|
mFrame->GetStyleContext());
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 21:58:52 +00:00
|
|
|
PRBool
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayOutline::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aVisibleRegionBeforeMove))
|
2006-09-19 21:58:52 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleOutline* outline = mFrame->GetStyleOutline();
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRect borderBox(aBuilder->ToReferenceFrame(mFrame), mFrame->GetSize());
|
|
|
|
if (borderBox.Contains(aVisibleRegion->GetBounds()) &&
|
|
|
|
(!aVisibleRegionBeforeMove ||
|
|
|
|
borderBox.Contains(aVisibleRegionBeforeMove->GetBounds())) &&
|
2008-10-01 05:50:52 +00:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(outline->mOutlineRadius)) {
|
2008-09-13 03:45:37 +00:00
|
|
|
if (outline->mOutlineOffset >= 0) {
|
2006-09-19 21:58:52 +00:00
|
|
|
// 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-17 23:16:46 +00:00
|
|
|
void
|
|
|
|
nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2006-04-17 23:16:46 +00:00
|
|
|
// 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 08:50:52 +00:00
|
|
|
mCaret->PaintCaret(aBuilder, aCtx, mFrame, aBuilder->ToReferenceFrame(mFrame));
|
2006-04-17 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 21:58:52 +00:00
|
|
|
PRBool
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayBorder::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aVisibleRegionBeforeMove))
|
2006-09-19 21:58:52 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-09-27 22:52:32 +00:00
|
|
|
nsRect paddingRect = mFrame->GetPaddingRect() - mFrame->GetPosition() +
|
|
|
|
aBuilder->ToReferenceFrame(mFrame);
|
2008-07-17 06:30:25 +00:00
|
|
|
const nsStyleBorder *styleBorder;
|
2007-09-27 22:52:32 +00:00
|
|
|
if (paddingRect.Contains(aVisibleRegion->GetBounds()) &&
|
2009-10-07 04:28:41 +00:00
|
|
|
(!aVisibleRegionBeforeMove ||
|
|
|
|
paddingRect.Contains(aVisibleRegionBeforeMove->GetBounds())) &&
|
2008-07-17 06:30:25 +00:00
|
|
|
!(styleBorder = mFrame->GetStyleBorder())->IsBorderImageLoaded() &&
|
2008-10-01 05:50:52 +00:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(styleBorder->mBorderRadius)) {
|
2006-09-19 21:58:52 +00: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
|
2008-07-17 06:30:25 +00:00
|
|
|
// Skip this if there's a border-image (which draws a background
|
|
|
|
// too) or if there is a border-radius (which makes the border draw
|
|
|
|
// further in).
|
2006-09-19 21:58:52 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void
|
|
|
|
nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2006-01-26 02:29:17 +00:00
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2007-03-30 21:11:41 +00:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 00:35:14 +00:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2006-01-26 02:29:17 +00:00
|
|
|
*mFrame->GetStyleBorder(),
|
2008-08-06 10:33:18 +00:00
|
|
|
mFrame->GetStyleContext(),
|
|
|
|
mFrame->GetSkipSides());
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2009-11-30 23:14:04 +00:00
|
|
|
// Given a region, compute a conservative approximation to it as a list
|
|
|
|
// of rectangles that aren't vertically adjacent (i.e., vertically
|
|
|
|
// adjacent or overlapping rectangles are combined).
|
|
|
|
// Right now this is only approximate, some vertically overlapping rectangles
|
|
|
|
// aren't guaranteed to be combined.
|
|
|
|
static void
|
|
|
|
ComputeDisjointRectangles(const nsRegion& aRegion,
|
|
|
|
nsTArray<nsRect>* aRects) {
|
|
|
|
nscoord accumulationMargin = nsPresContext::CSSPixelsToAppUnits(25);
|
|
|
|
nsRect accumulated;
|
|
|
|
nsRegionRectIterator iter(aRegion);
|
|
|
|
while (PR_TRUE) {
|
|
|
|
const nsRect* r = iter.Next();
|
|
|
|
if (r && !accumulated.IsEmpty() &&
|
|
|
|
accumulated.YMost() >= r->y - accumulationMargin) {
|
|
|
|
accumulated.UnionRect(accumulated, *r);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!accumulated.IsEmpty()) {
|
|
|
|
aRects->AppendElement(accumulated);
|
|
|
|
accumulated.Empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
accumulated = *r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-08 00:57:47 +00:00
|
|
|
void
|
2009-02-10 08:45:13 +00:00
|
|
|
nsDisplayBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2008-07-08 00:57:47 +00:00
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2009-11-30 23:14:04 +00:00
|
|
|
nsRect borderRect = nsRect(offset, mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < rects.Length(); ++i) {
|
|
|
|
aCtx->PushState();
|
|
|
|
aCtx->SetClipRect(rects[i], nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBoxShadowOuter(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
2008-07-08 00:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2009-02-10 08:45:13 +00:00
|
|
|
nsDisplayBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2008-07-08 00:57:47 +00:00
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
2009-01-30 07:03:46 +00:00
|
|
|
PRBool
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayBoxShadowOuter::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aVisibleRegionBeforeMove))
|
2009-01-30 07:03:46 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-11-30 23:14:04 +00:00
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
|
2009-01-30 07:03:46 +00:00
|
|
|
nsPoint origin = aBuilder->ToReferenceFrame(mFrame);
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRect visibleBounds = aVisibleRegion->GetBounds();
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
visibleBounds.UnionRect(visibleBounds, aVisibleRegionBeforeMove->GetBounds());
|
|
|
|
}
|
2009-04-24 09:24:44 +00:00
|
|
|
nsRect frameRect(origin, mFrame->GetSize());
|
|
|
|
if (!frameRect.Contains(visibleBounds))
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// the visible region is entirely inside the border-rect, and box shadows
|
|
|
|
// never render within the border-rect (unless there's a border radius).
|
|
|
|
nscoord twipsRadii[8];
|
|
|
|
PRBool hasBorderRadii =
|
|
|
|
nsCSSRendering::GetBorderRadiusTwips(mFrame->GetStyleBorder()->mBorderRadius,
|
|
|
|
frameRect.width,
|
|
|
|
twipsRadii);
|
|
|
|
if (!hasBorderRadii)
|
2009-01-30 07:03:46 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-04-24 09:24:44 +00:00
|
|
|
return !RoundedRectContainsRect(frameRect, twipsRadii, visibleBounds);
|
2009-01-30 07:03:46 +00:00
|
|
|
}
|
|
|
|
|
2009-02-10 08:45:13 +00:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadowInner::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2009-02-10 08:45:13 +00:00
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mFrame);
|
2009-11-30 23:14:04 +00:00
|
|
|
nsRect borderRect = nsRect(offset, mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < rects.Length(); ++i) {
|
|
|
|
aCtx->PushState();
|
|
|
|
aCtx->SetClipRect(rects[i], nsClipCombine_kIntersect);
|
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aVisibleRegionBeforeMove))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
return PR_TRUE;
|
2009-02-10 08:45:13 +00:00
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsIFrame* aFrame, nsDisplayList* aList)
|
2006-03-14 20:43:18 +00:00
|
|
|
: nsDisplayItem(aFrame) {
|
2006-01-26 02:29:17 +00:00
|
|
|
mList.AppendToTop(aList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsIFrame* aFrame, nsDisplayItem* aItem)
|
2006-03-14 20:43:18 +00:00
|
|
|
: nsDisplayItem(aFrame) {
|
2006-01-26 02:29:17 +00:00
|
|
|
mList.AppendToTop(aItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
2008-01-04 02:08:29 +00:00
|
|
|
nsDisplayWrapList::HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
HitTestState* aState) {
|
|
|
|
return mList.HitTest(aBuilder, aPt, aState);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayWrapList::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2008-09-11 00:24:16 +00:00
|
|
|
return mList.GetBounds(aBuilder);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayWrapList::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
mList.ComputeVisibility(aBuilder, aVisibleRegion, aVisibleRegionBeforeMove);
|
2006-01-26 02:29:17 +00:00
|
|
|
// 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.
|
2009-09-07 00:35:14 +00:00
|
|
|
// We reimplement ComputeVisibility and that's what really matters
|
2006-01-26 02:29:17 +00:00
|
|
|
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 03:46:37 +00: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 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayWrapList::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
|
|
|
mList.Paint(aBuilder, aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
WrapDisplayList(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
2009-08-14 02:09:51 +00:00
|
|
|
if (!aList->GetTop() && !aBuilder->HasMovingFrames())
|
2006-01-26 02:29:17 +00:00
|
|
|
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 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOpacity::~nsDisplayOpacity() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOpacity);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2006-01-29 18:48:58 +00:00
|
|
|
#endif
|
2006-01-26 02:29:17 +00: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,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2006-02-09 01:24:30 +00:00
|
|
|
float opacity = mFrame->GetStyleDisplay()->mOpacity;
|
|
|
|
|
2006-02-15 23:21:12 +00:00
|
|
|
nsCOMPtr<nsIDeviceContext> devCtx;
|
|
|
|
aCtx->GetDeviceContext(*getter_AddRefs(devCtx));
|
|
|
|
|
2008-06-11 00:37:11 +00:00
|
|
|
gfxContext* ctx = aCtx->ThebesContext();
|
2006-02-15 23:21:12 +00:00
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
ctx->NewPath();
|
2009-09-07 00:35:14 +00:00
|
|
|
gfxRect r(mVisibleRect.x, mVisibleRect.y,
|
|
|
|
mVisibleRect.width, mVisibleRect.height);
|
2008-06-11 00:37:11 +00:00
|
|
|
r.ScaleInverse(devCtx->AppUnitsPerDevPixel());
|
|
|
|
ctx->Rectangle(r, PR_TRUE);
|
2006-02-15 23:21:12 +00:00
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
if (mNeedAlpha)
|
2006-08-09 20:25:07 +00:00
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
2006-02-15 23:21:12 +00:00
|
|
|
else
|
2006-08-09 20:25:07 +00:00
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR);
|
2006-02-15 23:21:12 +00:00
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
nsDisplayWrapList::Paint(aBuilder, aCtx);
|
2006-02-15 23:21:12 +00:00
|
|
|
|
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
ctx->Paint(opacity);
|
|
|
|
|
|
|
|
ctx->Restore();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
PRBool nsDisplayOpacity::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
// 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;
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion visibleUnderChildrenBeforeMove;
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
visibleUnderChildrenBeforeMove = *aVisibleRegionBeforeMove;
|
|
|
|
}
|
2006-01-26 02:29:17 +00:00
|
|
|
PRBool anyVisibleChildren =
|
2009-10-07 04:28:41 +00:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren,
|
|
|
|
aVisibleRegionBeforeMove ? &visibleUnderChildrenBeforeMove : nsnull);
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!anyVisibleChildren)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-10-07 04:28:41 +00:00
|
|
|
// If we're analyzing moving content, then it doesn't really matter
|
|
|
|
// what we set mNeedAlpha to, so let's conservatively set it to true so
|
|
|
|
// we don't have to worry about getting it "correct" for the moving case.
|
|
|
|
mNeedAlpha = aVisibleRegionBeforeMove ||
|
|
|
|
visibleUnderChildren.Intersects(mVisibleRect);
|
2006-01-26 02:29:17 +00:00
|
|
|
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 07:08:04 +00:00
|
|
|
mList.AppendToBottom(&static_cast<nsDisplayOpacity*>(aItem)->mList);
|
2006-01-26 02:29:17 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-04-18 09:21:21 +00:00
|
|
|
nsDisplayClip::nsDisplayClip(nsIFrame* aFrame, nsIFrame* aClippingFrame,
|
|
|
|
nsDisplayItem* aItem, const nsRect& aRect)
|
|
|
|
: nsDisplayWrapList(aFrame, aItem),
|
|
|
|
mClippingFrame(aClippingFrame), mClip(aRect) {
|
2006-01-29 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 09:21:21 +00:00
|
|
|
nsDisplayClip::nsDisplayClip(nsIFrame* aFrame, nsIFrame* aClippingFrame,
|
|
|
|
nsDisplayList* aList, const nsRect& aRect)
|
|
|
|
: nsDisplayWrapList(aFrame, aList),
|
|
|
|
mClippingFrame(aClippingFrame), mClip(aRect) {
|
2006-01-29 18:48:58 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect nsDisplayClip::GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
nsRect r = nsDisplayWrapList::GetBounds(aBuilder);
|
|
|
|
r.IntersectRect(mClip, r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-01-29 18:48:58 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayClip::~nsDisplayClip() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayClip);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
void nsDisplayClip::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx) {
|
2006-01-26 02:29:17 +00:00
|
|
|
aCtx->PushState();
|
2009-09-07 00:35:14 +00:00
|
|
|
aCtx->SetClipRect(mClip, nsClipCombine_kIntersect);
|
|
|
|
nsDisplayWrapList::Paint(aBuilder, aCtx);
|
2006-01-26 02:29:17 +00:00
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
PRBool nsDisplayClip::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
|
|
|
PRBool isMoving = aBuilder->IsMovingFrame(mClippingFrame);
|
2009-08-14 02:09:51 +00:00
|
|
|
|
2009-10-07 04:28:41 +00:00
|
|
|
if (aBuilder->HasMovingFrames() && !isMoving) {
|
2009-08-14 02:09:51 +00:00
|
|
|
// There may be some clipped moving children that were visible before
|
|
|
|
// but are clipped out now. Conservatively assume they were there
|
|
|
|
// and add their possible area to the visible region of moving
|
|
|
|
// content.
|
|
|
|
// Compute the after-move region of moving content that could have been
|
|
|
|
// totally clipped out.
|
|
|
|
nsRegion r;
|
|
|
|
r.Sub(mClip + aBuilder->GetMoveDelta(), mClip);
|
2009-10-07 04:28:41 +00:00
|
|
|
// These hypothetical items are not visible after the move, so we pass
|
|
|
|
// an empty region for the after-move visible region to make sure they
|
|
|
|
// don't get added in the after-move position, only the before-move position.
|
|
|
|
aBuilder->AccumulateVisibleRegionOfMovingContent(r, *aVisibleRegionBeforeMove,
|
|
|
|
nsRegion());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
nsRegion clippedBeforeMove;
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
nsRect beforeMoveClip = isMoving ? mClip - aBuilder->GetMoveDelta() : mClip;
|
|
|
|
clippedBeforeMove.And(*aVisibleRegionBeforeMove, beforeMoveClip);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion finalClipped(clipped);
|
|
|
|
nsRegion finalClippedBeforeMove(clippedBeforeMove);
|
|
|
|
PRBool anyVisible =
|
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &finalClipped,
|
|
|
|
aVisibleRegionBeforeMove ? &finalClippedBeforeMove : nsnull);
|
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(clipped, finalClipped);
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
removed.Sub(clippedBeforeMove, finalClippedBeforeMove);
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegionBeforeMove, removed);
|
2009-08-14 02:09:51 +00:00
|
|
|
}
|
|
|
|
|
2006-01-26 02:29:17 +00:00
|
|
|
return anyVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayClip::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_CLIP)
|
|
|
|
return PR_FALSE;
|
2007-07-08 07:08:04 +00:00
|
|
|
nsDisplayClip* other = static_cast<nsDisplayClip*>(aItem);
|
2008-04-18 09:21:21 +00:00
|
|
|
if (other->mClip != mClip || other->mClippingFrame != mClippingFrame)
|
2006-01-26 02:29:17 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
mList.AppendToBottom(&other->mList);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList* nsDisplayClip::WrapWithClone(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
2008-04-18 09:21:21 +00:00
|
|
|
return new (aBuilder)
|
|
|
|
nsDisplayClip(aItem->GetUnderlyingFrame(), mClippingFrame, aItem, mClip);
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
2008-09-11 00:24:16 +00:00
|
|
|
|
2008-09-13 09:42:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// nsDisplayTransform Implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
// Write #define UNIFIED_CONTINUATIONS here to have the transform property try
|
|
|
|
// to transform content with continuations as one unified block instead of
|
|
|
|
// several smaller ones. This is currently disabled because it doesn't work
|
2009-07-27 08:47:02 +00:00
|
|
|
// correctly, since when the frames are initially being reflowed, their
|
2008-09-13 09:42:11 +00:00
|
|
|
// continuations all compute their bounding rects independently of each other
|
|
|
|
// and consequently get the wrong value. Write #define DEBUG_HIT here to have
|
|
|
|
// the nsDisplayTransform class dump out a bunch of information about hit
|
|
|
|
// detection.
|
|
|
|
#undef UNIFIED_CONTINUATIONS
|
|
|
|
#undef DEBUG_HIT
|
|
|
|
|
|
|
|
/* Returns the bounds of a frame as defined for transforms. If
|
|
|
|
* UNIFIED_CONTINUATIONS is not defined, this is simply the frame's bounding
|
|
|
|
* rectangle, translated to the origin. Otherwise, returns the smallest
|
|
|
|
* rectangle containing a frame and all of its continuations. For example, if
|
|
|
|
* there is a <span> element with several continuations split over several
|
|
|
|
* lines, this function will return the rectangle containing all of those
|
|
|
|
* continuations. This rectangle is relative to the origin of the frame's local
|
|
|
|
* coordinate space.
|
|
|
|
*/
|
|
|
|
#ifndef UNIFIED_CONTINUATIONS
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get the bounds of a nonexistent frame!");
|
|
|
|
return nsRect(nsPoint(0, 0), aFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get the bounds of a nonexistent frame!");
|
|
|
|
|
|
|
|
nsRect result;
|
|
|
|
|
|
|
|
/* Iterate through the continuation list, unioning together all the
|
|
|
|
* bounding rects.
|
|
|
|
*/
|
|
|
|
for (const nsIFrame *currFrame = aFrame->GetFirstContinuation();
|
|
|
|
currFrame != nsnull;
|
|
|
|
currFrame = currFrame->GetNextContinuation())
|
|
|
|
{
|
|
|
|
/* Get the frame rect in local coordinates, then translate back to the
|
|
|
|
* original coordinates.
|
|
|
|
*/
|
|
|
|
result.UnionRect(result, nsRect(currFrame->GetOffsetTo(aFrame),
|
|
|
|
currFrame->GetSize()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Returns the delta specified by the -moz-tranform-origin property.
|
|
|
|
* This is a positive delta, meaning that it indicates the direction to move
|
|
|
|
* to get from (0, 0) of the frame to the transform origin.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
gfxPoint GetDeltaToMozTransformOrigin(const nsIFrame* aFrame,
|
|
|
|
float aFactor,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get delta for a null frame!");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->HasTransform(),
|
|
|
|
"Can't get a delta for an untransformed frame!");
|
|
|
|
|
|
|
|
/* For both of the coordinates, if the value of -moz-transform is a
|
|
|
|
* percentage, it's relative to the size of the frame. Otherwise, if it's
|
|
|
|
* a distance, it's already computed for us!
|
|
|
|
*/
|
|
|
|
const nsStyleDisplay* display = aFrame->GetStyleDisplay();
|
|
|
|
nsRect boundingRect = (aBoundsOverride ? *aBoundsOverride :
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(aFrame));
|
|
|
|
|
|
|
|
/* Allows us to access named variables by index. */
|
|
|
|
gfxPoint result;
|
|
|
|
gfxFloat* coords[2] = {&result.x, &result.y};
|
|
|
|
const nscoord* dimensions[2] =
|
|
|
|
{&boundingRect.width, &boundingRect.height};
|
|
|
|
|
|
|
|
for (PRUint8 index = 0; index < 2; ++index) {
|
|
|
|
/* If the -moz-transform-origin specifies a percentage, take the percentage
|
|
|
|
* of the size of the box.
|
|
|
|
*/
|
|
|
|
if (display->mTransformOrigin[index].GetUnit() == eStyleUnit_Percent)
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(*dimensions[index], aFactor) *
|
|
|
|
display->mTransformOrigin[index].GetPercentValue();
|
|
|
|
|
|
|
|
/* Otherwise, it's a length. */
|
|
|
|
else
|
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(display->
|
|
|
|
mTransformOrigin[index].GetCoordValue(),
|
|
|
|
aFactor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust based on the origin of the rectangle. */
|
|
|
|
result.x += NSAppUnitsToFloatPixels(boundingRect.x, aFactor);
|
|
|
|
result.y += NSAppUnitsToFloatPixels(boundingRect.y, aFactor);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wraps up the -moz-transform matrix in a change-of-basis matrix pair that
|
|
|
|
* translates from local coordinate space to transform coordinate space, then
|
|
|
|
* hands it back.
|
|
|
|
*/
|
|
|
|
gfxMatrix
|
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin,
|
|
|
|
float aFactor,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Cannot get transform matrix for a null frame!");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->HasTransform(),
|
|
|
|
"Cannot get transform matrix if frame isn't transformed!");
|
|
|
|
|
|
|
|
/* Account for the -moz-transform-origin property by translating the
|
|
|
|
* coordinate space to the new origin.
|
|
|
|
*/
|
|
|
|
gfxPoint toMozOrigin = GetDeltaToMozTransformOrigin(aFrame, aFactor, aBoundsOverride);
|
|
|
|
gfxPoint newOrigin = gfxPoint(NSAppUnitsToFloatPixels(aOrigin.x, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aOrigin.y, aFactor));
|
|
|
|
|
|
|
|
/* Get the underlying transform matrix. This requires us to get the
|
|
|
|
* bounds of the frame.
|
|
|
|
*/
|
|
|
|
const nsStyleDisplay* disp = aFrame->GetStyleDisplay();
|
|
|
|
nsRect bounds = (aBoundsOverride ? *aBoundsOverride :
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(aFrame));
|
|
|
|
|
|
|
|
/* Get the matrix, then change its basis to factor in the origin. */
|
|
|
|
return nsLayoutUtils::ChangeMatrixBasis
|
|
|
|
(newOrigin + toMozOrigin, disp->mTransform.GetThebesMatrix(bounds, aFactor));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Painting applies the transform, paints the sublist, then unapplies
|
|
|
|
* the transform.
|
|
|
|
*/
|
|
|
|
void nsDisplayTransform::Paint(nsDisplayListBuilder *aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext *aCtx)
|
2008-09-13 09:42:11 +00:00
|
|
|
{
|
2008-09-22 20:27:37 +00:00
|
|
|
/* Get the local transform matrix with which we'll transform all wrapped
|
|
|
|
* elements. If this matrix is singular, we shouldn't display anything
|
|
|
|
* and can abort.
|
2008-09-13 09:42:11 +00:00
|
|
|
*/
|
2008-09-22 20:27:37 +00:00
|
|
|
gfxMatrix newTransformMatrix =
|
|
|
|
GetResultingTransformMatrix(mFrame, aBuilder->ToReferenceFrame(mFrame),
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
nsnull);
|
|
|
|
if (newTransformMatrix.IsSingular())
|
|
|
|
return;
|
|
|
|
|
2008-09-13 09:42:11 +00:00
|
|
|
/* Get the context and automatically save and restore it. */
|
|
|
|
gfxContext* gfx = aCtx->ThebesContext();
|
|
|
|
gfxContextAutoSaveRestore autoRestorer(gfx);
|
|
|
|
|
2008-09-22 20:27:37 +00:00
|
|
|
/* Get the new CTM by applying this transform after all of the
|
|
|
|
* transforms preceding it.
|
2008-09-13 09:42:11 +00:00
|
|
|
*/
|
|
|
|
newTransformMatrix.Multiply(gfx->CurrentMatrix());
|
|
|
|
|
|
|
|
/* Set the matrix for the transform based on the old matrix and the new
|
|
|
|
* transform data.
|
|
|
|
*/
|
|
|
|
gfx->SetMatrix(newTransformMatrix);
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
/* Now, send the paint call down.
|
2008-09-13 09:42:11 +00:00
|
|
|
*/
|
2009-09-07 00:35:14 +00:00
|
|
|
mStoredList.Paint(aBuilder, aCtx);
|
2008-09-13 09:42:11 +00:00
|
|
|
|
|
|
|
/* The AutoSaveRestore object will clean things up. */
|
|
|
|
}
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
PRBool nsDisplayTransform::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion *aVisibleRegion,
|
|
|
|
nsRegion *aVisibleRegionBeforeMove)
|
2008-09-13 09:42:11 +00:00
|
|
|
{
|
2009-10-07 04:28:41 +00:00
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
/* As we do this, we need to be sure to
|
|
|
|
* untransform the visible rect, since we want everything that's painting to
|
|
|
|
* think that it's painting in its original rectangular coordinate space. */
|
|
|
|
nsRegion untransformedVisible =
|
|
|
|
UntransformRect(mVisibleRect, mFrame, aBuilder->ToReferenceFrame(mFrame));
|
2009-10-07 04:28:41 +00:00
|
|
|
|
|
|
|
nsRegion untransformedVisibleBeforeMove;
|
|
|
|
if (aVisibleRegionBeforeMove) {
|
|
|
|
// mVisibleRect contains areas visible before and after the move, so it's
|
|
|
|
// OK (although conservative) to just use the same regions here.
|
|
|
|
untransformedVisibleBeforeMove = untransformedVisible;
|
|
|
|
}
|
|
|
|
mStoredList.ComputeVisibility(aBuilder, &untransformedVisible,
|
2009-12-12 21:27:15 +00:00
|
|
|
aVisibleRegionBeforeMove
|
|
|
|
? &untransformedVisibleBeforeMove
|
|
|
|
: nsnull);
|
2008-09-13 09:42:11 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HitTest does some fun stuff with matrix transforms to obtain the answer. */
|
|
|
|
nsIFrame *nsDisplayTransform::HitTest(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsPoint aPt,
|
|
|
|
HitTestState *aState)
|
|
|
|
{
|
|
|
|
/* Here's how this works:
|
|
|
|
* 1. Get the matrix. If it's singular, abort (clearly we didn't hit
|
|
|
|
* anything).
|
|
|
|
* 2. Invert the matrix.
|
|
|
|
* 3. Use it to transform the point into the correct space.
|
|
|
|
* 4. Pass that point down through to the list's version of HitTest.
|
|
|
|
*/
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
gfxMatrix matrix =
|
|
|
|
GetResultingTransformMatrix(mFrame, aBuilder->ToReferenceFrame(mFrame),
|
|
|
|
factor, nsnull);
|
|
|
|
if (matrix.IsSingular())
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
/* We want to go from transformed-space to regular space.
|
|
|
|
* Thus we have to invert the matrix, which normally does
|
|
|
|
* the reverse operation (e.g. regular->transformed)
|
|
|
|
*/
|
|
|
|
matrix.Invert();
|
|
|
|
|
|
|
|
/* Now, apply the transform and pass it down the channel. */
|
|
|
|
gfxPoint result = matrix.Transform(gfxPoint(NSAppUnitsToFloatPixels(aPt.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aPt.y, factor)));
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
printf("Frame: %p\n", dynamic_cast<void *>(mFrame));
|
|
|
|
printf(" Untransformed point: (%f, %f)\n", result.x, result.y);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIFrame* resultFrame =
|
|
|
|
mStoredList.HitTest(aBuilder,
|
|
|
|
nsPoint(NSFloatPixelsToAppUnits(float(result.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(result.y), factor)), aState);
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
if (resultFrame)
|
|
|
|
printf(" Hit! Time: %f, frame: %p\n", static_cast<double>(clock()),
|
|
|
|
dynamic_cast<void *>(resultFrame));
|
|
|
|
printf("=== end of hit test ===\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return resultFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The bounding rectangle for the object is the overflow rectangle translated
|
|
|
|
* by the reference point.
|
|
|
|
*/
|
|
|
|
nsRect nsDisplayTransform::GetBounds(nsDisplayListBuilder *aBuilder)
|
|
|
|
{
|
|
|
|
return mFrame->GetOverflowRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is opaque iff the transform consists solely of scales and
|
|
|
|
* transforms and if the underlying content is opaque. Thus if the transform
|
|
|
|
* is of the form
|
|
|
|
*
|
|
|
|
* |a c e|
|
|
|
|
* |b d f|
|
|
|
|
* |0 0 1|
|
|
|
|
*
|
|
|
|
* We need b and c to be zero.
|
|
|
|
*/
|
|
|
|
PRBool nsDisplayTransform::IsOpaque(nsDisplayListBuilder *aBuilder)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
return disp->mTransform.GetMainMatrixEntry(1) == 0.0f &&
|
|
|
|
disp->mTransform.GetMainMatrixEntry(2) == 0.0f &&
|
|
|
|
mStoredList.IsOpaque(aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is uniform if it fills the entire bounding rect and the
|
|
|
|
* wrapped list is uniform. See IsOpaque for discussion of why this
|
|
|
|
* works.
|
|
|
|
*/
|
|
|
|
PRBool nsDisplayTransform::IsUniform(nsDisplayListBuilder *aBuilder)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
return disp->mTransform.GetMainMatrixEntry(1) == 0.0f &&
|
|
|
|
disp->mTransform.GetMainMatrixEntry(2) == 0.0f &&
|
|
|
|
mStoredList.IsUniform(aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If UNIFIED_CONTINUATIONS is defined, we can merge two display lists that
|
|
|
|
* share the same underlying content. Otherwise, doing so results in graphical
|
|
|
|
* glitches.
|
|
|
|
*/
|
|
|
|
#ifndef UNIFIED_CONTINUATIONS
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayTransform::TryMerge(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayItem *aItem)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayTransform::TryMerge(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayItem *aItem)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aItem, "Why did you try merging with a null item?");
|
|
|
|
NS_PRECONDITION(aBuilder, "Why did you try merging with a null builder?");
|
|
|
|
|
|
|
|
/* Make sure that we're dealing with two transforms. */
|
|
|
|
if (aItem->GetType() != TYPE_TRANSFORM)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
/* Check to see that both frames are part of the same content. */
|
|
|
|
if (aItem->GetUnderlyingFrame()->GetContent() != mFrame->GetContent())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
/* Now, move everything over to this frame and signal that
|
|
|
|
* we merged things!
|
|
|
|
*/
|
|
|
|
mStoredList.GetList()->
|
|
|
|
AppendToBottom(&static_cast<nsDisplayTransform *>(aItem)->mStoredList);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TransformRect takes in as parameters a rectangle (in app space) and returns
|
|
|
|
* the smallest rectangle (in app space) containing the transformed image of
|
|
|
|
* that rectangle. That is, it takes the four corners of the rectangle,
|
|
|
|
* transforms them according to the matrix associated with the specified frame,
|
|
|
|
* then returns the smallest rectangle containing the four transformed points.
|
|
|
|
*
|
|
|
|
* @param aUntransformedBounds The rectangle (in app units) to transform.
|
|
|
|
* @param aFrame The frame whose transformation should be applied.
|
|
|
|
* @param aOrigin The delta from the frame origin to the coordinate space origin
|
|
|
|
* @param aBoundsOverride (optional) Force the frame bounds to be the
|
|
|
|
* specified bounds.
|
|
|
|
* @return The smallest rectangle containing the image of the transformed
|
|
|
|
* rectangle.
|
|
|
|
*/
|
|
|
|
nsRect nsDisplayTransform::TransformRect(const nsRect &aUntransformedBounds,
|
|
|
|
const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->HasTransform(),
|
|
|
|
"Cannot transform a rectangle if there's no transformation!");
|
|
|
|
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
return nsLayoutUtils::MatrixTransformRect
|
|
|
|
(aUntransformedBounds,
|
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect nsDisplayTransform::UntransformRect(const nsRect &aUntransformedBounds,
|
|
|
|
const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
NS_PRECONDITION(aFrame->GetStyleDisplay()->HasTransform(),
|
|
|
|
"Cannot transform a rectangle if there's no transformation!");
|
|
|
|
|
|
|
|
|
|
|
|
/* Grab the matrix. If the transform is degenerate, just hand back the
|
|
|
|
* empty rect.
|
|
|
|
*/
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
gfxMatrix matrix = GetResultingTransformMatrix(aFrame, aOrigin, factor, nsnull);
|
|
|
|
if (matrix.IsSingular())
|
|
|
|
return nsRect();
|
|
|
|
|
|
|
|
/* We want to untransform the matrix, so invert the transformation first! */
|
|
|
|
matrix.Invert();
|
|
|
|
|
|
|
|
return nsLayoutUtils::MatrixTransformRect(aUntransformedBounds, matrix,
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
2008-09-11 00:24:16 +00:00
|
|
|
#ifdef MOZ_SVG
|
|
|
|
nsDisplaySVGEffects::nsDisplaySVGEffects(nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aFrame, aList), mEffectsFrame(aFrame),
|
2008-09-16 01:51:52 +00:00
|
|
|
mBounds(aFrame->GetOverflowRectRelativeToSelf())
|
2008-09-11 00:24:16 +00:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplaySVGEffects::~nsDisplaySVGEffects()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRBool nsDisplaySVGEffects::IsOpaque(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsDisplaySVGEffects::HitTest(nsDisplayListBuilder* aBuilder, nsPoint aPt,
|
|
|
|
HitTestState* aState)
|
|
|
|
{
|
|
|
|
if (!nsSVGIntegrationUtils::HitTestFrameForEffects(mEffectsFrame,
|
|
|
|
aPt - aBuilder->ToReferenceFrame(mEffectsFrame)))
|
|
|
|
return nsnull;
|
|
|
|
return mList.HitTest(aBuilder, aPt, aState);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplaySVGEffects::Paint(nsDisplayListBuilder* aBuilder,
|
2009-09-07 00:35:14 +00:00
|
|
|
nsIRenderingContext* aCtx)
|
2008-09-11 00:24:16 +00:00
|
|
|
{
|
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(aCtx,
|
2009-09-07 00:35:14 +00:00
|
|
|
mEffectsFrame, mVisibleRect, aBuilder, &mList);
|
2008-09-11 00:24:16 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 00:35:14 +00:00
|
|
|
PRBool nsDisplaySVGEffects::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2009-10-07 04:28:41 +00:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsRegion* aVisibleRegionBeforeMove) {
|
|
|
|
NS_ASSERTION((aVisibleRegionBeforeMove != nsnull) == aBuilder->HasMovingFrames(),
|
|
|
|
"Should have aVisibleRegionBeforeMove when there are moving frames");
|
2008-09-11 00:24:16 +00:00
|
|
|
|
2009-10-07 04:28:41 +00:00
|
|
|
nsPoint offset = aBuilder->ToReferenceFrame(mEffectsFrame);
|
|
|
|
nsRect dirtyRect =
|
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(mEffectsFrame,
|
|
|
|
mVisibleRect - offset) +
|
|
|
|
offset;
|
|
|
|
|
|
|
|
// Our children may be made translucent or arbitrarily deformed so we should
|
|
|
|
// not allow them to subtract area from aVisibleRegion.
|
|
|
|
nsRegion childrenVisible(dirtyRect);
|
|
|
|
// mVisibleRect contains areas visible before and after the move, so it's
|
|
|
|
// OK (although conservative) to just use the same regions here.
|
|
|
|
nsRegion childrenVisibleBeforeMove(dirtyRect);
|
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &childrenVisible,
|
|
|
|
aVisibleRegionBeforeMove ? &childrenVisibleBeforeMove : nsnull);
|
2009-09-07 00:35:14 +00:00
|
|
|
return PR_TRUE;
|
2008-09-11 00:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplaySVGEffects::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SVG_EFFECTS)
|
|
|
|
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 nsDisplaySVGEffects
|
|
|
|
if (aItem->GetUnderlyingFrame()->GetContent() != mFrame->GetContent())
|
|
|
|
return PR_FALSE;
|
|
|
|
nsDisplaySVGEffects* other = static_cast<nsDisplaySVGEffects*>(aItem);
|
|
|
|
mList.AppendToBottom(&other->mList);
|
|
|
|
mBounds.UnionRect(mBounds,
|
|
|
|
other->mBounds + other->mEffectsFrame->GetOffsetTo(mEffectsFrame));
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|