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"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#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"
|
2008-07-17 10:30:25 +04:00
|
|
|
#include "nsStyleStructInlines.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
|
|
|
#include "gfxMatrix.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2009-07-22 04:44:57 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2010-07-16 01:08:12 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2010-07-24 13:35:29 +04:00
|
|
|
#include "nsThemeConstants.h"
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2009-04-08 19:19:51 +04:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2010-03-01 10:56:19 +03:00
|
|
|
#include "BasicLayers.h"
|
2010-11-30 17:59:46 +03:00
|
|
|
#include "nsBoxFrame.h"
|
2011-04-08 20:35:16 +04:00
|
|
|
#include "nsViewportFrame.h"
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
using namespace mozilla;
|
2010-03-01 10:56:19 +03:00
|
|
|
using namespace mozilla::layers;
|
2011-01-13 20:45:14 +03:00
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
|
2010-11-08 12:06:14 +03:00
|
|
|
Mode aMode, PRBool aBuildCaret)
|
2006-01-26 05:29:17 +03:00
|
|
|
: mReferenceFrame(aReferenceFrame),
|
|
|
|
mIgnoreScrollFrame(nsnull),
|
2008-04-06 15:34:14 +04:00
|
|
|
mCurrentTableItem(nsnull),
|
2011-01-03 04:48:09 +03:00
|
|
|
mFinalTransparentRegion(nsnull),
|
2010-11-08 12:06:14 +03:00
|
|
|
mMode(aMode),
|
2010-12-04 12:58:39 +03:00
|
|
|
mBuildCaret(aBuildCaret),
|
2010-09-02 00:44:48 +04:00
|
|
|
mIgnoreSuppression(PR_FALSE),
|
|
|
|
mHadToIgnoreSuppression(PR_FALSE),
|
2007-03-19 06:25:05 +03:00
|
|
|
mIsAtRootOfPseudoStackingContext(PR_FALSE),
|
2010-12-07 16:54:50 +03:00
|
|
|
mIncludeAllOutOfFlows(PR_FALSE),
|
2010-07-13 00:24:33 +04:00
|
|
|
mSelectedFramesOnly(PR_FALSE),
|
2009-07-22 04:45:14 +04:00
|
|
|
mAccurateVisibleRegions(PR_FALSE),
|
2009-09-13 02:44:18 +04:00
|
|
|
mInTransform(PR_FALSE),
|
2010-05-13 04:56:08 +04:00
|
|
|
mSyncDecodeImages(PR_FALSE),
|
2011-01-04 13:39:47 +03:00
|
|
|
mIsPaintingToWindow(PR_FALSE),
|
2011-05-31 01:44:10 +04:00
|
|
|
mSnappingEnabled(mMode != EVENT_DELIVERY),
|
2011-04-08 20:35:16 +04:00
|
|
|
mHasDisplayPort(PR_FALSE),
|
|
|
|
mHasFixedItems(PR_FALSE)
|
|
|
|
{
|
2010-06-21 20:21:41 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayListBuilder);
|
2010-07-20 05:29:25 +04:00
|
|
|
PL_InitArenaPool(&mPool, "displayListArena", 1024,
|
|
|
|
NS_MAX(NS_ALIGNMENT_OF(void*),NS_ALIGNMENT_OF(double))-1);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
2006-01-26 05:29:17 +03:00
|
|
|
nsIPresShell *shell = pc->PresShell();
|
|
|
|
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
|
|
|
|
2011-04-08 20:35:16 +04:00
|
|
|
if(mReferenceFrame->GetType() == nsGkAtoms::viewportFrame) {
|
|
|
|
ViewportFrame* viewportFrame = static_cast<ViewportFrame*>(mReferenceFrame);
|
2011-08-25 00:54:30 +04:00
|
|
|
if (!viewportFrame->GetChildList(nsIFrame::kFixedList).IsEmpty()) {
|
2011-04-08 20:35:16 +04:00
|
|
|
mHasFixedItems = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:09:08 +04:00
|
|
|
LayerBuilder()->Init(this);
|
|
|
|
|
2010-07-16 01:08:10 +04:00
|
|
|
PR_STATIC_ASSERT(nsDisplayItem::TYPE_MAX < (1 << nsDisplayItem::TYPE_BITS));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 20:35:16 +04:00
|
|
|
static PRBool IsFixedFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return aFrame && aFrame->GetParent() && !aFrame->GetParent()->GetParent();
|
|
|
|
}
|
|
|
|
|
2011-05-09 12:40:09 +04:00
|
|
|
static PRBool IsFixedItem(nsDisplayItem *aItem, nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aIsFixedBackground)
|
2011-04-08 20:35:16 +04:00
|
|
|
{
|
|
|
|
nsIFrame* activeScrolledRoot =
|
2011-05-09 12:40:09 +04:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(aItem, aBuilder, aIsFixedBackground);
|
2011-04-08 20:35:16 +04:00
|
|
|
return activeScrolledRoot &&
|
|
|
|
!nsLayoutUtils::ScrolledByViewportScrolling(activeScrolledRoot,
|
|
|
|
aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool ForceVisiblityForFixedItem(nsDisplayListBuilder* aBuilder,
|
2011-05-09 12:40:09 +04:00
|
|
|
nsDisplayItem* aItem,
|
|
|
|
PRBool* aIsFixedBackground)
|
2011-04-08 20:35:16 +04:00
|
|
|
{
|
2011-05-09 12:40:09 +04:00
|
|
|
return aBuilder->GetDisplayPort() && aBuilder->GetHasFixedItems() &&
|
|
|
|
IsFixedItem(aItem, aBuilder, aIsFixedBackground);
|
2011-04-08 20:35:16 +04:00
|
|
|
}
|
|
|
|
|
2011-05-13 17:21:59 +04:00
|
|
|
void nsDisplayListBuilder::SetDisplayPort(const nsRect& aDisplayPort)
|
|
|
|
{
|
|
|
|
static bool fixedPositionLayersEnabled = getenv("MOZ_ENABLE_FIXED_POSITION_LAYERS") != 0;
|
|
|
|
if (fixedPositionLayersEnabled) {
|
|
|
|
mHasDisplayPort = PR_TRUE;
|
|
|
|
mDisplayPort = aDisplayPort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 20:35:16 +04:00
|
|
|
void nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay(nsIFrame* aDirtyFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
2006-04-27 06:45:03 +04:00
|
|
|
nsRect dirty = aDirtyRect - aFrame->GetOffsetTo(aDirtyFrame);
|
2010-10-07 08:25:47 +04:00
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRect();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
|
|
|
if (mHasDisplayPort && IsFixedFrame(aFrame)) {
|
|
|
|
dirty = overflowRect;
|
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
if (!dirty.IntersectRect(dirty, overflowRect))
|
|
|
|
return;
|
2010-03-29 05:46:55 +04:00
|
|
|
aFrame->Properties().Set(nsDisplayListBuilder::OutOfFlowDirtyRectProperty(),
|
|
|
|
new nsRect(dirty));
|
2006-04-27 06:45:03 +04:00
|
|
|
|
|
|
|
MarkFrameForDisplay(aFrame, aDirtyFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnmarkFrameForDisplay(nsIFrame* aFrame) {
|
2010-03-29 05:46:55 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
presContext->PropertyTable()->
|
|
|
|
Delete(aFrame, nsDisplayListBuilder::OutOfFlowDirtyRectProperty());
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
nsFrameManager* frameManager = 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
static void RecordFrameMetrics(nsIFrame* aForFrame,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrollFrame,
|
2011-01-13 20:45:14 +03:00
|
|
|
ContainerLayer* aRoot,
|
2011-06-22 16:11:28 +04:00
|
|
|
const nsRect& aVisibleRect,
|
|
|
|
const nsRect& aViewport,
|
2011-03-10 00:35:27 +03:00
|
|
|
nsRect* aDisplayPort,
|
2011-06-22 16:11:28 +04:00
|
|
|
ViewID aScrollId,
|
|
|
|
const nsDisplayItem::ContainerParameters& aContainerParameters) {
|
2011-01-13 20:45:14 +03:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
2011-06-22 16:11:28 +04:00
|
|
|
PRInt32 auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-06-22 16:11:28 +04:00
|
|
|
nsIntRect visible = aVisibleRect.ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-13 20:45:14 +03:00
|
|
|
aRoot->SetVisibleRegion(nsIntRegion(visible));
|
|
|
|
|
|
|
|
FrameMetrics metrics;
|
|
|
|
|
2011-06-22 16:11:28 +04:00
|
|
|
metrics.mViewport = aViewport.ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
|
|
|
|
2011-03-10 00:35:27 +03:00
|
|
|
if (aDisplayPort) {
|
2011-06-22 16:11:28 +04:00
|
|
|
metrics.mDisplayPort = aDisplayPort->ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2011-03-10 00:35:27 +03:00
|
|
|
nsIScrollableFrame* scrollableFrame = nsnull;
|
2011-05-02 05:53:01 +04:00
|
|
|
if (aScrollFrame)
|
|
|
|
scrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
2011-03-16 02:20:19 +03:00
|
|
|
|
|
|
|
if (scrollableFrame) {
|
|
|
|
nsSize contentSize =
|
|
|
|
scrollableFrame->GetScrollRange().Size() +
|
|
|
|
scrollableFrame->GetScrollPortRect().Size();
|
2011-06-22 16:11:28 +04:00
|
|
|
metrics.mContentSize = contentSize.ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
|
|
|
metrics.mViewportScrollOffset = scrollableFrame->GetScrollPosition().ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-19 19:56:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsSize contentSize = aForFrame->GetSize();
|
2011-06-22 16:11:28 +04:00
|
|
|
metrics.mContentSize = contentSize.ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2011-01-19 19:56:22 +03:00
|
|
|
metrics.mScrollId = aScrollId;
|
2011-01-13 20:45:14 +03:00
|
|
|
aRoot->SetFrameMetrics(metrics);
|
|
|
|
}
|
|
|
|
|
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);
|
2010-06-21 20:21:41 +04:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayListBuilder);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32
|
|
|
|
nsDisplayListBuilder::GetBackgroundPaintFlags() {
|
|
|
|
PRUint32 flags = 0;
|
|
|
|
if (mSyncDecodeImages) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES;
|
|
|
|
}
|
2010-10-25 18:38:09 +04:00
|
|
|
if (mIsPaintingToWindow) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_TO_WINDOW;
|
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2011-01-04 11:43:47 +03:00
|
|
|
static PRUint64 RegionArea(const nsRegion& aRegion)
|
|
|
|
{
|
|
|
|
PRUint64 area = 0;
|
|
|
|
nsRegionRectIterator iter(aRegion);
|
|
|
|
const nsRect* r;
|
|
|
|
while ((r = iter.Next()) != nsnull) {
|
|
|
|
area += PRUint64(r->width)*r->height;
|
|
|
|
}
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2009-08-14 06:09:51 +04:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRegion& aRegion)
|
2009-08-14 06:09:51 +04:00
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
if (aRegion.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2009-09-19 16:12:48 +04: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).
|
2011-01-04 11:43:47 +03:00
|
|
|
// Do let aVisibleRegion get more complex if by doing so we reduce its
|
|
|
|
// area by at least half.
|
2011-05-13 20:40:46 +04:00
|
|
|
if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15 ||
|
2011-01-04 11:43:47 +03:00
|
|
|
RegionArea(tmp) <= RegionArea(*aVisibleRegion)/2) {
|
2009-09-19 16:12:48 +04:00
|
|
|
*aVisibleRegion = tmp;
|
2009-08-14 06:09:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
nsCaret *
|
2006-04-18 03:16:46 +04:00
|
|
|
nsDisplayListBuilder::GetCaret() {
|
2010-03-29 03:21:11 +04:00
|
|
|
nsRefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
|
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();
|
|
|
|
|
2009-04-25 12:19:23 +04:00
|
|
|
state->mPresShell->UpdateCanvasBackground();
|
|
|
|
|
2010-05-13 04:56:08 +04:00
|
|
|
if (mIsPaintingToWindow) {
|
2011-01-28 00:53:10 +03:00
|
|
|
mReferenceFrame->AddPaintedPresShell(state->mPresShell);
|
|
|
|
|
2010-05-13 04:56:08 +04:00
|
|
|
state->mPresShell->IncrementPaintCount();
|
|
|
|
}
|
|
|
|
|
2010-09-02 00:44:48 +04:00
|
|
|
PRBool buildCaret = mBuildCaret;
|
|
|
|
if (mIgnoreSuppression || !state->mPresShell->IsPaintingSuppressed()) {
|
|
|
|
if (state->mPresShell->IsPaintingSuppressed()) {
|
|
|
|
mHadToIgnoreSuppression = PR_TRUE;
|
|
|
|
}
|
|
|
|
state->mIsBackgroundOnly = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
state->mIsBackgroundOnly = PR_TRUE;
|
|
|
|
buildCaret = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buildCaret)
|
2006-04-18 03:16:46 +04:00
|
|
|
return;
|
|
|
|
|
2010-03-29 03:21:11 +04:00
|
|
|
nsRefPtr<nsCaret> caret = state->mPresShell->GetCaret();
|
2008-01-04 04:53:01 +03:00
|
|
|
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,
|
2009-04-25 12:19:23 +04:00
|
|
|
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
|
2009-07-28 16:51:09 +04:00
|
|
|
nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame,
|
|
|
|
const nsFrameList& aFrames,
|
2006-04-27 06:45:03 +04:00
|
|
|
const nsRect& aDirtyRect) {
|
2009-07-28 16:51:09 +04:00
|
|
|
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(e.get());
|
|
|
|
MarkOutOfFlowFrameForDisplay(aDirtyFrame, e.get(), aDirtyRect);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2010-07-16 01:07:49 +04:00
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_WRAP_LIST) {
|
2006-01-26 05:29:17 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04: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;
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:09 +04:00
|
|
|
PRBool
|
2010-08-28 03:15:08 +04:00
|
|
|
nsDisplayList::ComputeVisibilityForRoot(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2011-05-13 20:40:46 +04:00
|
|
|
return ComputeVisibilityForSublist(aBuilder, aVisibleRegion, r.GetBounds(), r.GetBounds());
|
2010-08-28 03:15:08 +04:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
static nsRegion
|
2010-11-08 12:06:14 +03:00
|
|
|
TreatAsOpaque(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aTransparentBackground)
|
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, aTransparentBackground);
|
2010-11-08 12:06:14 +03:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
2011-05-23 04:28:47 +04:00
|
|
|
// Treat all chrome items as opaque, unless their frames are opacity:0.
|
|
|
|
// Since opacity:0 frames generate an nsDisplayOpacity, that item will
|
|
|
|
// not be treated as opaque here, so opacity:0 chrome content will be
|
|
|
|
// effectively ignored, as it should be.
|
2010-11-08 12:06:14 +03:00
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
2011-05-23 04:28:47 +04:00
|
|
|
if (f && f->PresContext()->IsChrome() && f->GetStyleDisplay()->mOpacity != 0.0) {
|
2011-01-03 04:48:09 +03:00
|
|
|
opaque = aItem->GetBounds(aBuilder);
|
|
|
|
}
|
2010-11-08 12:06:14 +03:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return opaque;
|
2010-11-08 12:06:14 +03:00
|
|
|
}
|
|
|
|
|
2011-05-09 12:40:09 +04:00
|
|
|
static nsRect GetDisplayPortBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
PRBool aIgnoreTransform)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = aItem->GetUnderlyingFrame();
|
2011-08-03 07:04:21 +04:00
|
|
|
const nsRect* displayport = aBuilder->GetDisplayPort();
|
2011-05-09 12:40:09 +04:00
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
if (aIgnoreTransform) {
|
|
|
|
return *displayport;
|
2011-05-09 12:40:09 +04:00
|
|
|
}
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
return nsLayoutUtils::TransformRectToBoundsInAncestor(
|
|
|
|
frame,
|
2011-05-09 12:40:09 +04:00
|
|
|
nsRect(0, 0, displayport->width, displayport->height),
|
2011-08-03 07:04:21 +04:00
|
|
|
aBuilder->ReferenceFrame());
|
2011-05-09 12:40:09 +04:00
|
|
|
}
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
PRBool
|
|
|
|
nsDisplayList::ComputeVisibilityForSublist(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
2011-01-28 01:58:50 +03:00
|
|
|
const nsRect& aListVisibleBounds,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2010-08-28 03:15:08 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2011-04-19 07:07:23 +04:00
|
|
|
NS_ASSERTION(r.GetBounds().IsEqualInterior(aListVisibleBounds),
|
2010-08-28 03:15:08 +04:00
|
|
|
"bad aListVisibleBounds");
|
|
|
|
#endif
|
|
|
|
mVisibleRect = aListVisibleBounds;
|
2010-07-16 01:08:09 +04:00
|
|
|
PRBool anyVisible = PR_FALSE;
|
2010-03-10 23:55:05 +03:00
|
|
|
|
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
|
|
|
|
2010-10-19 21:02:25 +04:00
|
|
|
PRBool forceTransparentSurface = PR_FALSE;
|
|
|
|
|
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;
|
|
|
|
}
|
2009-08-14 06:09:51 +04:00
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayList* list = item->GetList();
|
|
|
|
if (list && item->ShouldFlattenAway(aBuilder)) {
|
|
|
|
// The elements on the list >= i no longer serve any use.
|
|
|
|
elements.SetLength(i);
|
|
|
|
list->FlattenTo(&elements);
|
|
|
|
i = elements.Length();
|
|
|
|
item->~nsDisplayItem();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
nsRect bounds = item->GetBounds(aBuilder);
|
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2011-05-09 12:40:09 +04:00
|
|
|
PRBool isFixedBackground;
|
|
|
|
if (ForceVisiblityForFixedItem(aBuilder, item, &isFixedBackground)) {
|
|
|
|
itemVisible.And(GetDisplayPortBounds(aBuilder, item, isFixedBackground), bounds);
|
|
|
|
} else {
|
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-04-08 20:35:16 +04:00
|
|
|
}
|
2011-05-09 12:40:09 +04:00
|
|
|
item->mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
2011-05-13 20:40:46 +04:00
|
|
|
if (item->ComputeVisibility(aBuilder, aVisibleRegion, aAllowVisibleRegionExpansion)) {
|
2010-07-16 01:08:09 +04:00
|
|
|
anyVisible = PR_TRUE;
|
2010-10-19 21:02:25 +04:00
|
|
|
PRBool transparentBackground = PR_FALSE;
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion opaque = TreatAsOpaque(item, aBuilder, &transparentBackground);
|
|
|
|
// Subtract opaque item from the visible region
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2010-10-19 21:02:25 +04:00
|
|
|
forceTransparentSurface = forceTransparentSurface || transparentBackground;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2010-07-16 01:08:09 +04:00
|
|
|
AppendToBottom(item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2009-08-14 06:09:51 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
mIsOpaque = !aVisibleRegion->Intersects(mVisibleRect);
|
2010-10-19 21:02:25 +04:00
|
|
|
mForceTransparentSurface = forceTransparentSurface;
|
2009-09-07 04:35:14 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mDidComputeVisibility = PR_TRUE;
|
|
|
|
#endif
|
2010-07-16 01:08:09 +04:00
|
|
|
return anyVisible;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-03-10 23:55:05 +03:00
|
|
|
void nsDisplayList::PaintRoot(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx,
|
2010-03-10 23:55:05 +03:00
|
|
|
PRUint32 aFlags) const {
|
|
|
|
PaintForFrame(aBuilder, aCtx, aBuilder->ReferenceFrame(), aFlags);
|
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
/**
|
|
|
|
* We paint by executing a layer manager transaction, constructing a
|
|
|
|
* single layer representing the display list, and then making it the
|
|
|
|
* root of the layer manager, drawing into the ThebesLayers.
|
|
|
|
*/
|
2010-03-10 23:55:05 +03:00
|
|
|
void nsDisplayList::PaintForFrame(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx,
|
2010-03-10 23:55:05 +03:00
|
|
|
nsIFrame* aForFrame,
|
|
|
|
PRUint32 aFlags) const {
|
2009-09-07 04:35:14 +04:00
|
|
|
NS_ASSERTION(mDidComputeVisibility,
|
|
|
|
"Must call ComputeVisibility before calling Paint");
|
|
|
|
|
2010-03-01 11:03:49 +03:00
|
|
|
nsRefPtr<LayerManager> layerManager;
|
2011-01-19 11:27:54 +03:00
|
|
|
bool allowRetaining = false;
|
|
|
|
bool doBeginTransaction = true;
|
2010-03-01 11:03:49 +03:00
|
|
|
if (aFlags & PAINT_USE_WIDGET_LAYERS) {
|
|
|
|
nsIFrame* referenceFrame = aBuilder->ReferenceFrame();
|
|
|
|
NS_ASSERTION(referenceFrame == nsLayoutUtils::GetDisplayRootFrame(referenceFrame),
|
|
|
|
"Reference frame must be a display root for us to use the layer manager");
|
2010-07-02 23:11:04 +04:00
|
|
|
nsIWidget* window = referenceFrame->GetNearestWidget();
|
2010-03-01 11:03:49 +03:00
|
|
|
if (window) {
|
2010-10-15 14:34:29 +04:00
|
|
|
layerManager = window->GetLayerManager(&allowRetaining);
|
2011-01-19 11:27:54 +03:00
|
|
|
if (layerManager) {
|
|
|
|
doBeginTransaction = !(aFlags & PAINT_EXISTING_TRANSACTION);
|
2010-07-16 01:07:51 +04:00
|
|
|
}
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!layerManager) {
|
|
|
|
if (!aCtx) {
|
|
|
|
NS_WARNING("Nowhere to paint into");
|
|
|
|
return;
|
|
|
|
}
|
2010-07-16 01:08:10 +04:00
|
|
|
layerManager = new BasicLayerManager();
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:52 +04:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
2011-01-19 11:27:54 +03:00
|
|
|
if (doBeginTransaction) {
|
|
|
|
if (aCtx) {
|
|
|
|
layerManager->BeginTransactionWithTarget(aCtx->ThebesContext());
|
|
|
|
} else {
|
|
|
|
layerManager->BeginTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allowRetaining) {
|
|
|
|
aBuilder->LayerBuilder()->DidBeginRetainedLayerTransaction(layerManager);
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2011-06-22 16:11:27 +04:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
|
|
|
|
nsDisplayItem::ContainerParameters containerParameters
|
|
|
|
(presShell->GetXResolution(), presShell->GetYResolution());
|
2010-09-04 00:10:45 +04:00
|
|
|
nsRefPtr<ContainerLayer> root = aBuilder->LayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, layerManager, aForFrame, nsnull, *this,
|
2011-06-22 16:11:27 +04:00
|
|
|
containerParameters, nsnull);
|
2010-03-01 10:56:19 +03:00
|
|
|
if (!root)
|
|
|
|
return;
|
2011-06-22 16:11:27 +04:00
|
|
|
// Root is being scaled up by the X/Y resolution. Scale it back down.
|
|
|
|
gfx3DMatrix rootTransform = root->GetTransform()*
|
2011-08-27 04:06:03 +04:00
|
|
|
gfx3DMatrix::ScalingMatrix(1.0f/containerParameters.mXScale,
|
|
|
|
1.0f/containerParameters.mYScale, 1.0f);
|
2011-06-22 16:11:27 +04:00
|
|
|
root->SetTransform(rootTransform);
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
ViewID id = presContext->IsRootContentDocument() ? FrameMetrics::ROOT_SCROLL_ID
|
|
|
|
: FrameMetrics::NULL_SCROLL_ID;
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2011-03-16 02:20:19 +03:00
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
2011-03-10 00:35:27 +03:00
|
|
|
nsRect displayport;
|
|
|
|
bool usingDisplayport = false;
|
2011-03-16 02:20:19 +03:00
|
|
|
if (rootScrollFrame) {
|
|
|
|
nsIContent* content = rootScrollFrame->GetContent();
|
|
|
|
if (content) {
|
2011-03-10 00:35:27 +03:00
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
2011-03-16 02:20:19 +03:00
|
|
|
}
|
|
|
|
}
|
2011-03-10 00:35:27 +03:00
|
|
|
RecordFrameMetrics(aForFrame, rootScrollFrame,
|
|
|
|
root, mVisibleRect, mVisibleRect,
|
2011-06-22 16:11:28 +04:00
|
|
|
(usingDisplayport ? &displayport : nsnull), id,
|
|
|
|
containerParameters);
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
layerManager->SetRoot(root);
|
2010-07-16 01:08:11 +04:00
|
|
|
aBuilder->LayerBuilder()->WillEndTransaction(layerManager);
|
2010-05-21 07:20:48 +04:00
|
|
|
layerManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer,
|
|
|
|
aBuilder);
|
2010-07-16 01:07:51 +04:00
|
|
|
aBuilder->LayerBuilder()->DidEndTransaction(layerManager);
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2010-07-16 01:07:52 +04:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
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::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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-30 17:59:46 +03:00
|
|
|
static PRBool
|
|
|
|
GetMouseThrough(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame->IsBoxFrame())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_ALWAYS) {
|
|
|
|
return PR_TRUE;
|
|
|
|
} else if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_NEVER) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
frame = frame->GetParentBox();
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void nsDisplayList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
nsDisplayItem::HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames) const {
|
2008-01-04 05:08:29 +03:00
|
|
|
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);
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
if (aRect.Intersects(item->GetBounds(aBuilder))) {
|
2011-09-23 07:50:57 +04:00
|
|
|
nsAutoTArray<nsIFrame*, 16> outFrames;
|
2010-04-08 04:31:26 +04:00
|
|
|
item->HitTest(aBuilder, aRect, aState, &outFrames);
|
|
|
|
|
|
|
|
for (PRUint32 j = 0; j < outFrames.Length(); j++) {
|
|
|
|
nsIFrame *f = outFrames.ElementAt(j);
|
|
|
|
// Handle the XUL 'mousethrough' feature and 'pointer-events'.
|
2010-11-30 17:59:46 +03:00
|
|
|
if (!GetMouseThrough(f) &&
|
2009-08-27 07:53:35 +04:00
|
|
|
f->GetStyleVisibility()->mPointerEvents != NS_STYLE_POINTER_EVENTS_NONE) {
|
2010-04-08 04:31:26 +04:00
|
|
|
aOutFrames->AppendElement(f);
|
2008-01-04 05:08:29 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2010-04-08 04:31:26 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
NS_ASSERTION(aState->mItemBuffer.Length() == PRUint32(itemBufferStart),
|
2008-01-04 05:08:29 +03:00
|
|
|
"How did we forget to pop some elements?");
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-27 04:01:46 +04:00
|
|
|
static PRBool IsZPositionLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
|
|
|
void* aClosure) {
|
|
|
|
if (!aItem1->GetUnderlyingFrame()->Preserves3D() ||
|
|
|
|
!aItem1->GetUnderlyingFrame()->Preserves3D()) {
|
|
|
|
return IsContentLEQ(aItem1, aItem2, aClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* ancestor;
|
|
|
|
gfx3DMatrix matrix1 = aItem1->GetUnderlyingFrame()->GetTransformMatrix(&ancestor);
|
|
|
|
gfx3DMatrix matrix2 = aItem2->GetUnderlyingFrame()->GetTransformMatrix(&ancestor);
|
|
|
|
|
|
|
|
if (matrix1._43 == matrix2._43) {
|
|
|
|
return IsContentLEQ(aItem1, aItem2, aClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
return matrix1._43 < matrix2._43;
|
|
|
|
}
|
|
|
|
|
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
|
2010-04-02 06:09:05 +04:00
|
|
|
// in sorting. Note that we can't just take the difference of the two
|
|
|
|
// z-indices here, because that might overflow a 32-bit int.
|
|
|
|
PRInt32 index1 = nsLayoutUtils::GetZIndex(aItem1->GetUnderlyingFrame());
|
|
|
|
PRInt32 index2 = nsLayoutUtils::GetZIndex(aItem2->GetUnderlyingFrame());
|
|
|
|
if (index1 == index2)
|
2011-08-27 04:01:46 +04:00
|
|
|
return IsZPositionLEQ(aItem1, aItem2, aClosure);
|
2010-04-02 06:09:05 +04:00
|
|
|
return index1 < index2;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-08-27 04:01:46 +04:00
|
|
|
void nsDisplayList::SortByZPosition(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
|
|
|
Sort(aBuilder, IsZPositionLEQ, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
PRBool nsDisplayItem::RecomputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
nsRect bounds = GetBounds(aBuilder);
|
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2011-05-09 12:40:09 +04:00
|
|
|
PRBool isFixedBackground;
|
|
|
|
if (ForceVisiblityForFixedItem(aBuilder, this, &isFixedBackground)) {
|
|
|
|
itemVisible.And(GetDisplayPortBounds(aBuilder, this, isFixedBackground), bounds);
|
|
|
|
} else {
|
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-04-08 20:35:16 +04:00
|
|
|
}
|
2011-05-09 12:40:09 +04:00
|
|
|
mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
// When we recompute visibility within layers we don't need to
|
|
|
|
// expand the visible region for content behind plugins (the plugin
|
|
|
|
// is not in the layer).
|
2011-05-13 20:40:46 +04:00
|
|
|
if (!ComputeVisibility(aBuilder, aVisibleRegion, nsRect()))
|
2010-07-16 01:07:51 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-11-08 12:06:14 +03:00
|
|
|
PRBool forceTransparentBackground;
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion opaque = TreatAsOpaque(this, aBuilder, &forceTransparentBackground);
|
2011-01-04 11:45:24 +03:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2010-07-16 01:07:51 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-12 18:59:09 +04:00
|
|
|
// Note that even if the rectangle we draw and snap is smaller than aRect,
|
|
|
|
// it's OK to call this to get a bounding rect for what we'll draw, because
|
|
|
|
// snapping a rectangle which is contained in R always gives you a
|
|
|
|
// rectangle which is contained in the snapped R.
|
|
|
|
static nsRect
|
|
|
|
SnapBounds(PRBool aSnappingEnabled, nsPresContext* aPresContext,
|
|
|
|
const nsRect& aRect) {
|
|
|
|
nsRect r = aRect;
|
|
|
|
if (aSnappingEnabled) {
|
|
|
|
nscoord appUnitsPerDevPixel = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
r = r.ToNearestPixels(appUnitsPerDevPixel).ToAppUnits(appUnitsPerDevPixel);
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplaySolidColor::GetBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
return SnapBounds(mSnappingEnabled, presContext, mBounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySolidColor::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
2009-04-25 12:19:23 +04:00
|
|
|
aCtx->SetColor(mColor);
|
2009-09-07 04:35:14 +04:00
|
|
|
aCtx->FillRect(mVisibleRect);
|
2009-04-25 12:19:23 +04:00
|
|
|
}
|
|
|
|
|
2010-07-24 13:35:29 +04:00
|
|
|
static void
|
2011-01-11 16:03:16 +03:00
|
|
|
RegisterThemeGeometry(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
2010-07-24 13:35:29 +04:00
|
|
|
{
|
|
|
|
nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
|
|
|
|
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
// Bail out if we're in a transformed subtree
|
|
|
|
if (f->IsTransformed())
|
|
|
|
return;
|
|
|
|
// Bail out if we're not in the displayRoot's document
|
|
|
|
if (!f->GetParent() && f != displayRoot)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect borderBox(aFrame->GetOffsetTo(displayRoot), aFrame->GetSize());
|
2011-01-11 16:03:16 +03:00
|
|
|
aBuilder->RegisterThemeGeometry(aFrame->GetStyleDisplay()->mAppearance,
|
|
|
|
borderBox.ToNearestPixels(aFrame->PresContext()->AppUnitsPerDevPixel()));
|
2010-07-24 13:35:29 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayBackground::nsDisplayBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2011-01-04 13:39:47 +03:00
|
|
|
: nsDisplayItem(aBuilder, aFrame),
|
|
|
|
mSnappingEnabled(aBuilder->IsSnappingEnabled() && !aBuilder->IsInTransform())
|
2010-07-24 13:35:29 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayBackground);
|
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
mIsThemed = mFrame->IsThemed(disp, &mThemeTransparency);
|
|
|
|
|
2011-04-08 20:35:16 +04:00
|
|
|
if (mIsThemed) {
|
|
|
|
// Perform necessary RegisterThemeGeometry
|
|
|
|
if (disp->mAppearance == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
|
|
|
|
disp->mAppearance == NS_THEME_TOOLBAR) {
|
|
|
|
RegisterThemeGeometry(aBuilder, aFrame);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Set HasFixedItems if we construct a background-attachment:fixed item
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsStyleContext* bgSC;
|
|
|
|
PRBool hasBG = nsCSSRendering::FindBackground(presContext, mFrame, &bgSC);
|
|
|
|
if (hasBG && bgSC->GetStyleBackground()->HasFixedBackground()) {
|
|
|
|
aBuilder->SetHasFixedItems();
|
|
|
|
}
|
2010-07-24 13:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
// Helper for RoundedRectIntersectsRect.
|
|
|
|
static PRBool
|
|
|
|
CheckCorner(nscoord aXOffset, nscoord aYOffset,
|
|
|
|
nscoord aXRadius, nscoord aYRadius)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aXOffset > 0 && aYOffset > 0,
|
|
|
|
"must not pass nonpositives to CheckCorner");
|
|
|
|
NS_ABORT_IF_FALSE(aXRadius >= 0 && aYRadius >= 0,
|
|
|
|
"must not pass negatives to CheckCorner");
|
|
|
|
|
|
|
|
// Avoid floating point math unless we're either (1) within the
|
|
|
|
// quarter-ellipse area at the rounded corner or (2) outside the
|
|
|
|
// rounding.
|
|
|
|
if (aXOffset >= aXRadius || aYOffset >= aYRadius)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// Convert coordinates to a unit circle with (0,0) as the center of
|
|
|
|
// curvature, and see if we're inside the circle or outside.
|
|
|
|
float scaledX = float(aXRadius - aXOffset) / float(aXRadius);
|
|
|
|
float scaledY = float(aYRadius - aYOffset) / float(aYRadius);
|
|
|
|
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return whether any part of aTestRect is inside of the rounded
|
|
|
|
* rectangle formed by aBounds and aRadii (which are indexed by the
|
|
|
|
* NS_CORNER_* constants in nsStyleConsts.h).
|
|
|
|
*
|
|
|
|
* See also RoundedRectContainsRect.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
RoundedRectIntersectsRect(const nsRect& aRoundedRect, nscoord aRadii[8],
|
|
|
|
const nsRect& aTestRect)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aTestRect.Intersects(aRoundedRect),
|
|
|
|
"we should already have tested basic rect intersection");
|
|
|
|
|
|
|
|
// distances from this edge of aRoundedRect to opposite edge of aTestRect,
|
|
|
|
// which we know are positive due to the Intersects check above.
|
|
|
|
nsMargin insets;
|
|
|
|
insets.top = aTestRect.YMost() - aRoundedRect.y;
|
|
|
|
insets.right = aRoundedRect.XMost() - aTestRect.x;
|
|
|
|
insets.bottom = aRoundedRect.YMost() - aTestRect.y;
|
|
|
|
insets.left = aTestRect.XMost() - aRoundedRect.x;
|
|
|
|
|
|
|
|
// Check whether the bottom-right corner of aTestRect is inside the
|
|
|
|
// top left corner of aBounds when rounded by aRadii, etc. If any
|
|
|
|
// corner is not, then fail; otherwise succeed.
|
|
|
|
return CheckCorner(insets.left, insets.top,
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
aRadii[NS_CORNER_TOP_LEFT_Y]) &&
|
|
|
|
CheckCorner(insets.right, insets.top,
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
aRadii[NS_CORNER_TOP_RIGHT_Y]) &&
|
|
|
|
CheckCorner(insets.right, insets.bottom,
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_RIGHT_Y]) &&
|
|
|
|
CheckCorner(insets.left, insets.bottom,
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
aRadii[NS_CORNER_BOTTOM_LEFT_Y]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the rounded border of aFrame, added to aToReferenceFrame,
|
|
|
|
// intersects aRect. Assumes that the unrounded border has already
|
|
|
|
// been checked for intersection.
|
|
|
|
static PRBool
|
|
|
|
RoundedBorderIntersectsRect(nsIFrame* aFrame,
|
|
|
|
const nsPoint& aFrameToReferenceFrame,
|
|
|
|
const nsRect& aTestRect)
|
|
|
|
{
|
2011-01-04 13:40:02 +03:00
|
|
|
if (!nsRect(aFrameToReferenceFrame, aFrame->GetSize()).Intersects(aTestRect))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
nscoord radii[8];
|
|
|
|
return !aFrame->GetBorderRadii(radii) ||
|
|
|
|
RoundedRectIntersectsRect(nsRect(aFrameToReferenceFrame,
|
|
|
|
aFrame->GetSize()),
|
|
|
|
radii, aTestRect);
|
|
|
|
}
|
|
|
|
|
2009-04-24 13:24:44 +04: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.
|
2010-10-11 22:03:12 +04:00
|
|
|
//
|
|
|
|
// See also RoundedRectIntersectsRect.
|
2009-04-24 13:24:44 +04:00
|
|
|
static PRBool RoundedRectContainsRect(const nsRect& aRoundedRect,
|
|
|
|
const nscoord aRadii[8],
|
|
|
|
const nsRect& aContainedRect) {
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(aRoundedRect, aRadii, aContainedRect);
|
|
|
|
return rgn.Contains(aContainedRect);
|
2009-04-24 13:24:44 +04:00
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
void
|
|
|
|
nsDisplayBackground::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
2011-08-08 22:31:52 +04:00
|
|
|
if (mIsThemed) {
|
|
|
|
// For theme backgrounds, assume that any point in our border rect is a hit.
|
|
|
|
if (!nsRect(ToReferenceFrame(), mFrame->GetSize()).Intersects(aRect))
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (!RoundedBorderIntersectsRect(mFrame, ToReferenceFrame(), aRect)) {
|
|
|
|
// aRect doesn't intersect our border-radius curve.
|
|
|
|
return;
|
|
|
|
}
|
2010-10-11 22:03:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:06 +04:00
|
|
|
PRBool
|
|
|
|
nsDisplayBackground::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-16 01:08:06 +04:00
|
|
|
{
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2010-07-16 01:08:09 +04:00
|
|
|
return PR_FALSE;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2010-07-16 01:08:09 +04:00
|
|
|
|
2010-07-16 01:08:06 +04:00
|
|
|
// Return false if the background was propagated away from this
|
|
|
|
// frame. We don't want this display item to show up and confuse
|
|
|
|
// anything.
|
|
|
|
nsStyleContext* bgSC;
|
|
|
|
return mIsThemed ||
|
|
|
|
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC);
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
2011-01-04 13:39:47 +03:00
|
|
|
nsDisplayBackground::GetInsideClipRegion(nsPresContext* aPresContext,
|
|
|
|
PRUint8 aClip, const nsRect& aRect)
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
|
|
|
nsRegion result;
|
|
|
|
if (aRect.IsEmpty())
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nscoord radii[8];
|
|
|
|
nsRect clipRect;
|
|
|
|
PRBool haveRadii;
|
|
|
|
switch (aClip) {
|
|
|
|
case NS_STYLE_BG_CLIP_BORDER:
|
|
|
|
haveRadii = mFrame->GetBorderRadii(radii);
|
|
|
|
clipRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_PADDING:
|
|
|
|
haveRadii = mFrame->GetPaddingBoxBorderRadii(radii);
|
|
|
|
clipRect = mFrame->GetPaddingRect() - mFrame->GetPosition() + ToReferenceFrame();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_CONTENT:
|
|
|
|
haveRadii = mFrame->GetContentBoxBorderRadii(radii);
|
|
|
|
clipRect = mFrame->GetContentRect() - mFrame->GetPosition() + ToReferenceFrame();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown clip type");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-04 13:39:47 +03:00
|
|
|
nsRect inputRect = SnapBounds(mSnappingEnabled, aPresContext, aRect);
|
|
|
|
clipRect = SnapBounds(mSnappingEnabled, aPresContext, clipRect);
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
if (haveRadii) {
|
2011-01-04 13:39:47 +03:00
|
|
|
result = nsLayoutUtils::RoundedRectIntersectRect(clipRect, radii, inputRect);
|
2011-01-03 04:48:09 +03:00
|
|
|
} else {
|
|
|
|
nsRect r;
|
2011-01-04 13:39:47 +03:00
|
|
|
r.IntersectRect(clipRect, inputRect);
|
2011-01-03 04:48:09 +03:00
|
|
|
result = r;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
|
|
|
nsDisplayBackground::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aForceTransparentSurface) {
|
|
|
|
nsRegion result;
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
// theme background overrides any other background
|
2010-10-19 21:02:25 +04:00
|
|
|
if (mIsThemed) {
|
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
*aForceTransparentSurface = disp->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
|
|
|
|
disp->mAppearance == NS_THEME_WIN_GLASS;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
if (mThemeTransparency == nsITheme::eOpaque) {
|
|
|
|
result = GetBounds(aBuilder);
|
|
|
|
}
|
|
|
|
return result;
|
2010-10-19 21:02:25 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2010-07-16 01:08:06 +04:00
|
|
|
nsStyleContext* bgSC;
|
2011-01-03 04:48:09 +03:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2010-04-03 05:58:26 +04:00
|
|
|
if (!nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC))
|
2011-01-03 04:48:09 +03:00
|
|
|
return result;
|
2010-04-03 05:58:26 +04:00
|
|
|
const nsStyleBackground* bg = bgSC->GetStyleBackground();
|
2009-04-08 19:19:51 +04:00
|
|
|
const nsStyleBackground::Layer& bottomLayer = bg->BottomLayer();
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2009-07-04 13:30:59 +04:00
|
|
|
if (NS_GET_A(bg->mBackgroundColor) == 255 &&
|
2011-01-03 04:48:09 +03:00
|
|
|
!nsCSSRendering::IsCanvasFrame(mFrame)) {
|
2011-01-04 13:39:47 +03:00
|
|
|
result = GetInsideClipRegion(presContext, bottomLayer.mClip, borderBox);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// For policies other than EACH_BOX, don't try to optimize here, since
|
|
|
|
// this could easily lead to O(N^2) behavior inside InlineBackgroundData,
|
|
|
|
// which expects frames to be sent to it in content order, not reverse
|
|
|
|
// content order which we'll produce here.
|
|
|
|
// Of course, if there's only one frame in the flow, it doesn't matter.
|
|
|
|
if (bg->mBackgroundInlinePolicy == NS_STYLE_BG_INLINE_POLICY_EACH_BOX ||
|
|
|
|
(!mFrame->GetPrevContinuation() && !mFrame->GetNextContinuation())) {
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
|
|
|
|
const nsStyleBackground::Layer& layer = bg->mLayers[i];
|
|
|
|
if (layer.mImage.IsOpaque()) {
|
|
|
|
nsRect r = nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
|
|
|
|
borderBox, *bg, layer);
|
2011-01-04 13:39:47 +03:00
|
|
|
result.Or(result, GetInsideClipRegion(presContext, layer.mClip, r));
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
return result;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-05-13 04:56:11 +04:00
|
|
|
nsDisplayBackground::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// theme background overrides any other background
|
2011-01-16 13:38:45 +03:00
|
|
|
if (mIsThemed) {
|
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
if (disp->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
|
|
|
|
disp->mAppearance == NS_THEME_WIN_GLASS) {
|
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
2011-01-16 13:38:45 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2010-04-03 05:58:26 +04:00
|
|
|
nsStyleContext *bgSC;
|
2006-01-26 05:29:17 +03:00
|
|
|
PRBool hasBG =
|
2010-04-03 05:58:26 +04:00
|
|
|
nsCSSRendering::FindBackground(mFrame->PresContext(), mFrame, &bgSC);
|
2010-05-13 04:56:11 +04:00
|
|
|
if (!hasBG) {
|
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_TRUE;
|
2010-05-13 04:56:11 +04:00
|
|
|
}
|
2010-04-03 05:58:26 +04:00
|
|
|
const nsStyleBackground* bg = bgSC->GetStyleBackground();
|
2009-08-22 00:39:25 +04:00
|
|
|
if (bg->BottomLayer().mImage.IsEmpty() &&
|
2009-02-20 08:29:21 +03:00
|
|
|
bg->mImageCount == 1 &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius) &&
|
2010-05-13 04:56:11 +04:00
|
|
|
bg->BottomLayer().mClip == NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
// Canvas frames don't actually render their background color, since that
|
|
|
|
// gets propagated to the solid color of the viewport
|
|
|
|
// (see nsCSSRendering::PaintBackgroundWithSC)
|
|
|
|
*aColor = nsCSSRendering::IsCanvasFrame(mFrame) ? NS_RGBA(0,0,0,0)
|
|
|
|
: bg->mBackgroundColor;
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_TRUE;
|
2010-05-13 04:56:11 +04:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2010-08-13 13:54:37 +04:00
|
|
|
nsDisplayBackground::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2010-07-16 01:08:12 +04:00
|
|
|
// theme background overrides any other background and is never fixed
|
|
|
|
if (mIsThemed)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-04-11 07:46:37 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2010-04-03 05:58:26 +04:00
|
|
|
nsStyleContext *bgSC;
|
2006-01-26 05:29:17 +03:00
|
|
|
PRBool hasBG =
|
2010-07-16 01:08:06 +04:00
|
|
|
nsCSSRendering::FindBackground(presContext, mFrame, &bgSC);
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!hasBG)
|
|
|
|
return PR_FALSE;
|
2010-04-03 05:58:26 +04:00
|
|
|
const nsStyleBackground* bg = bgSC->GetStyleBackground();
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!bg->HasFixedBackground())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-08-13 13:54:37 +04:00
|
|
|
// If aFrame is mFrame or an ancestor in this document, and aFrame is
|
|
|
|
// not the viewport frame, then moving aFrame will move mFrame
|
|
|
|
// relative to the viewport, so our fixed-pos background will change.
|
|
|
|
return aFrame->GetParent() &&
|
|
|
|
(aFrame == mFrame ||
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(aFrame, mFrame));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:12 +04:00
|
|
|
PRBool
|
2011-04-06 09:00:25 +04:00
|
|
|
nsDisplayBackground::ShouldFixToViewport(nsDisplayListBuilder* aBuilder)
|
2010-07-16 01:08:12 +04:00
|
|
|
{
|
|
|
|
if (mIsThemed)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsStyleContext* bgSC;
|
|
|
|
PRBool hasBG =
|
|
|
|
nsCSSRendering::FindBackground(presContext, mFrame, &bgSC);
|
|
|
|
if (!hasBG)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
const nsStyleBackground* bg = bgSC->GetStyleBackground();
|
|
|
|
if (!bg->HasFixedBackground())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
|
|
|
|
const nsStyleBackground::Layer& layer = bg->mLayers[i];
|
|
|
|
if (layer.mAttachment != NS_STYLE_BG_ATTACHMENT_FIXED &&
|
|
|
|
!layer.mImage.IsEmpty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
if (layer.mClip != NS_STYLE_BG_CLIP_BORDER)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsRect bounds = GetBounds(aBuilder);
|
|
|
|
nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
|
|
|
|
if (!rootScrollFrame)
|
|
|
|
return PR_FALSE;
|
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(rootScrollFrame);
|
|
|
|
nsRect scrollport = scrollable->GetScrollPortRect() +
|
|
|
|
aBuilder->ToReferenceFrame(rootScrollFrame);
|
|
|
|
return bounds.Contains(scrollport);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsDisplayBackground::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-09-13 02:44:18 +04:00
|
|
|
PRUint32 flags = aBuilder->GetBackgroundPaintFlags();
|
2009-05-28 09:01:42 +04:00
|
|
|
nsDisplayItem* nextItem = GetAbove();
|
|
|
|
if (nextItem && nextItem->GetUnderlyingFrame() == mFrame &&
|
|
|
|
nextItem->GetType() == TYPE_BORDER) {
|
2009-09-13 02:44:18 +04:00
|
|
|
flags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER;
|
2009-05-28 09:01:42 +04:00
|
|
|
}
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2009-05-28 09:01:42 +04:00
|
|
|
flags);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2007-12-18 08:26:38 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayBackground::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2011-01-04 13:39:47 +03:00
|
|
|
nsRect r(nsPoint(0,0), mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
|
2010-08-23 13:30:08 +04:00
|
|
|
if (mIsThemed) {
|
|
|
|
presContext->GetTheme()->
|
|
|
|
GetWidgetOverflow(presContext->DeviceContext(), mFrame,
|
|
|
|
mFrame->GetStyleDisplay()->mAppearance, &r);
|
|
|
|
}
|
2007-12-18 08:26:38 +03:00
|
|
|
|
2011-01-04 13:39:47 +03:00
|
|
|
return SnapBounds(mSnappingEnabled, presContext, r + ToReferenceFrame());
|
2007-12-18 08:26:38 +03:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayOutline::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2010-11-17 05:20:25 +03:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// TODO join outlines together
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintOutline(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2008-08-06 14:33:18 +04:00
|
|
|
mFrame->GetStyleContext());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2006-09-20 01:58:52 +04:00
|
|
|
PRBool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayOutline::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2006-09-20 01:58:52 +04:00
|
|
|
return PR_FALSE;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2006-09-20 01:58:52 +04:00
|
|
|
|
|
|
|
const nsStyleOutline* outline = mFrame->GetStyleOutline();
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect borderBox(ToReferenceFrame(), mFrame->GetSize());
|
2009-10-07 08:28:41 +04:00
|
|
|
if (borderBox.Contains(aVisibleRegion->GetBounds()) &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(outline->mOutlineRadius)) {
|
2008-09-13 07:45:37 +04:00
|
|
|
if (outline->mOutlineOffset >= 0) {
|
2006-09-20 01:58:52 +04: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;
|
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
void
|
|
|
|
nsDisplayEventReceiver::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
if (!RoundedBorderIntersectsRect(mFrame, ToReferenceFrame(), aRect)) {
|
|
|
|
// aRect doesn't intersect our border-radius curve.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
void
|
|
|
|
nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2006-04-18 03:16:46 +04:00
|
|
|
// Note: Because we exist, we know that the caret is visible, so we don't
|
|
|
|
// need to check for the caret's visibility.
|
2010-08-13 14:01:58 +04:00
|
|
|
mCaret->PaintCaret(aBuilder, aCtx, mFrame, ToReferenceFrame());
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2006-09-20 01:58:52 +04:00
|
|
|
PRBool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayBorder::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2006-09-20 01:58:52 +04:00
|
|
|
return PR_FALSE;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2006-09-20 01:58:52 +04:00
|
|
|
|
2007-09-28 02:52:32 +04:00
|
|
|
nsRect paddingRect = mFrame->GetPaddingRect() - mFrame->GetPosition() +
|
2010-08-13 14:01:58 +04:00
|
|
|
ToReferenceFrame();
|
2008-07-17 10:30:25 +04:00
|
|
|
const nsStyleBorder *styleBorder;
|
2007-09-28 02:52:32 +04:00
|
|
|
if (paddingRect.Contains(aVisibleRegion->GetBounds()) &&
|
2008-07-17 10:30:25 +04:00
|
|
|
!(styleBorder = mFrame->GetStyleBorder())->IsBorderImageLoaded() &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(styleBorder->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
|
2008-07-17 10:30:25 +04: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-20 01:58:52 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2008-08-06 14:33:18 +04:00
|
|
|
mFrame->GetStyleContext(),
|
|
|
|
mFrame->GetSkipSides());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-01-04 13:39:47 +03:00
|
|
|
nsRect
|
|
|
|
nsDisplayBorder::GetBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return SnapBounds(mSnappingEnabled, mFrame->PresContext(),
|
|
|
|
nsRect(ToReferenceFrame(), mFrame->GetSize()));
|
|
|
|
}
|
|
|
|
|
2009-12-01 02:14:04 +03: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);
|
2011-04-19 07:07:23 +04:00
|
|
|
accumulated.SetEmpty();
|
2009-12-01 02:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
accumulated = *r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
void
|
2009-02-10 11:45:13 +03:00
|
|
|
nsDisplayBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-12-01 02:14:04 +03: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();
|
2011-04-08 05:04:40 +04:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-12-01 02:14:04 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowOuter(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
2008-07-08 04:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2009-02-10 11:45:13 +03:00
|
|
|
nsDisplayBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2010-11-17 05:20:25 +03:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2008-07-08 04:57:47 +04:00
|
|
|
}
|
|
|
|
|
2009-01-30 10:03:46 +03:00
|
|
|
PRBool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayBoxShadowOuter::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2009-01-30 10:03:46 +03:00
|
|
|
return PR_FALSE;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2009-01-30 10:03:46 +03:00
|
|
|
|
2009-12-01 02:14:04 +03:00
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint origin = ToReferenceFrame();
|
2009-10-07 08:28:41 +04:00
|
|
|
nsRect visibleBounds = aVisibleRegion->GetBounds();
|
2009-04-24 13:24:44 +04: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];
|
2010-09-08 02:20:35 +04:00
|
|
|
PRBool hasBorderRadii = mFrame->GetBorderRadii(twipsRadii);
|
2009-04-24 13:24:44 +04:00
|
|
|
if (!hasBorderRadii)
|
2009-01-30 10:03:46 +03:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-04-24 13:24:44 +04:00
|
|
|
return !RoundedRectContainsRect(frameRect, twipsRadii, visibleBounds);
|
2009-01-30 10:03:46 +03:00
|
|
|
}
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadowInner::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-12-01 02:14:04 +03: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();
|
2011-04-08 05:04:40 +04:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-12-01 02:14:04 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2009-12-01 02:14:04 +03:00
|
|
|
return PR_FALSE;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2009-12-01 02:14:04 +03:00
|
|
|
|
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
return PR_TRUE;
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aList);
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aItem);
|
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayWrapList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayWrapList::GetBounds(nsDisplayListBuilder* aBuilder) {
|
2008-09-11 04:24:16 +04:00
|
|
|
return mList.GetBounds(aBuilder);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayWrapList::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2010-08-28 03:15:08 +04:00
|
|
|
return mList.ComputeVisibilityForSublist(aBuilder, aVisibleRegion,
|
2011-01-28 01:58:50 +03:00
|
|
|
mVisibleRect,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
|
|
|
nsDisplayWrapList::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aForceTransparentSurface) {
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
|
|
|
if (mList.IsOpaque()) {
|
|
|
|
result = GetBounds(aBuilder);
|
|
|
|
}
|
|
|
|
return result;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-05-13 04:56:11 +04:00
|
|
|
PRBool nsDisplayWrapList::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// We could try to do something but let's conservatively just return PR_FALSE.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-08-13 13:54:37 +04:00
|
|
|
PRBool nsDisplayWrapList::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame) {
|
2008-04-11 07:46:37 +04:00
|
|
|
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,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-03-01 10:56:19 +03:00
|
|
|
NS_ERROR("nsDisplayWrapList should have been flattened away for painting");
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
PRBool nsDisplayWrapList::ChildrenCanBeInactive(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const nsDisplayList& aList,
|
|
|
|
nsIFrame* aActiveScrolledRoot) {
|
|
|
|
for (nsDisplayItem* i = aList.GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
nsIFrame* f = i->GetUnderlyingFrame();
|
|
|
|
if (f) {
|
|
|
|
nsIFrame* activeScrolledRoot =
|
2010-08-08 22:49:06 +04:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(f, nsnull);
|
2010-07-16 01:08:05 +04:00
|
|
|
if (activeScrolledRoot != aActiveScrolledRoot)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerState state = i->GetLayerState(aBuilder, aManager);
|
|
|
|
if (state == LAYER_ACTIVE)
|
|
|
|
return PR_FALSE;
|
|
|
|
if (state == LAYER_NONE) {
|
|
|
|
nsDisplayList* list = i->GetList();
|
|
|
|
if (list && !ChildrenCanBeInactive(aBuilder, aManager, *list, aActiveScrolledRoot))
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect nsDisplayWrapList::GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder)
|
2010-10-11 04:58:20 +04:00
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect bounds;
|
2010-10-11 04:58:20 +04:00
|
|
|
for (nsDisplayItem* i = mList.GetBottom(); i; i = i->GetAbove()) {
|
2011-01-03 04:48:09 +03:00
|
|
|
bounds.UnionRect(bounds, i->GetComponentAlphaBounds(aBuilder));
|
2010-10-11 04:58:20 +04:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return bounds;
|
2010-10-11 04:58:20 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
static nsresult
|
|
|
|
WrapDisplayList(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
2010-08-13 13:55:54 +04:00
|
|
|
if (!aList->GetTop())
|
2006-01-26 05:29:17 +03: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);
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayOpacity::nsDisplayOpacity(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
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
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplayOpacity::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aForceTransparentSurface) {
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
// We are never opaque, if our opacity was < 1 then we wouldn't have
|
|
|
|
// been created.
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsRegion();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
// nsDisplayOpacity uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayOpacity::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2010-05-21 07:20:48 +04:00
|
|
|
nsRefPtr<Layer> layer = aBuilder->LayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
|
|
|
aContainerParameters, nsnull);
|
2010-03-01 10:56:19 +03:00
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2010-03-10 23:55:05 +03:00
|
|
|
layer->SetOpacity(mFrame->GetStyleDisplay()->mOpacity);
|
2010-03-01 10:56:19 +03:00
|
|
|
return layer.forget();
|
|
|
|
}
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager) {
|
2011-06-22 16:11:28 +04:00
|
|
|
if (mFrame->AreLayersMarkedActive(nsChangeHint_UpdateOpacityLayer))
|
2010-07-16 01:08:06 +04:00
|
|
|
return LAYER_ACTIVE;
|
2010-07-16 01:08:05 +04:00
|
|
|
nsIFrame* activeScrolledRoot =
|
2010-08-08 22:49:06 +04:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(mFrame, nsnull);
|
2010-07-16 01:08:05 +04:00
|
|
|
return !ChildrenCanBeInactive(aBuilder, aManager, mList, activeScrolledRoot)
|
|
|
|
? LAYER_ACTIVE : LAYER_INACTIVE;
|
|
|
|
}
|
|
|
|
|
2011-05-13 20:40:46 +04:00
|
|
|
PRBool
|
|
|
|
nsDisplayOpacity::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2006-01-26 05:29:17 +03: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.
|
2010-03-01 10:56:19 +03:00
|
|
|
nsRect bounds = GetBounds(aBuilder);
|
|
|
|
nsRegion visibleUnderChildren;
|
|
|
|
visibleUnderChildren.And(*aVisibleRegion, bounds);
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect allowExpansion;
|
|
|
|
allowExpansion.IntersectRect(bounds, aAllowVisibleRegionExpansion);
|
2010-03-01 10:56:19 +03:00
|
|
|
return
|
2011-01-28 01:58:50 +03:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren,
|
2011-05-13 20:40:46 +04:00
|
|
|
allowExpansion);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayOwnLayer::nsDisplayOwnLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
2010-07-16 01:08:03 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOwnLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOwnLayer::~nsDisplayOwnLayer() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOwnLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsDisplayOpacity uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayOwnLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2010-07-16 01:08:03 +04:00
|
|
|
nsRefPtr<Layer> layer = aBuilder->LayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
|
|
|
aContainerParameters, nsnull);
|
2010-07-16 01:08:03 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList,
|
|
|
|
nsIFrame* aForFrame,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame, aList)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame, aItem)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
2011-01-13 20:45:14 +03:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2011-01-14 01:17:40 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
2011-01-13 20:45:14 +03:00
|
|
|
#endif
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
2011-01-13 20:45:14 +03:00
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayScrollLayer::~nsDisplayScrollLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayScrollLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2011-01-13 20:45:14 +03:00
|
|
|
nsRefPtr<ContainerLayer> layer = aBuilder->LayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
|
|
|
aContainerParameters, nsnull);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
// Get the already set unique ID for scrolling this content remotely.
|
|
|
|
// Or, if not set, generate a new ID.
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIContent* content = mScrolledFrame->GetContent();
|
2011-01-13 20:45:14 +03:00
|
|
|
ViewID scrollId = nsLayoutUtils::FindIDFor(content);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
nsRect viewport = mScrollFrame->GetRect() -
|
|
|
|
mScrollFrame->GetPosition() +
|
|
|
|
aBuilder->ToReferenceFrame(mScrollFrame);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-03-10 00:35:27 +03:00
|
|
|
bool usingDisplayport = false;
|
|
|
|
nsRect displayport;
|
|
|
|
if (content) {
|
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
|
|
|
}
|
2011-05-02 05:53:01 +04:00
|
|
|
RecordFrameMetrics(mScrolledFrame, mScrollFrame, layer, mVisibleRect, viewport,
|
2011-06-22 16:11:28 +04:00
|
|
|
(usingDisplayport ? &displayport : nsnull), scrollId,
|
|
|
|
aContainerParameters);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayScrollLayer::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2011-01-13 20:45:14 +03:00
|
|
|
{
|
2011-03-10 00:35:27 +03:00
|
|
|
nsRect displayport;
|
2011-05-02 05:53:01 +04:00
|
|
|
if (nsLayoutUtils::GetDisplayPort(mScrolledFrame->GetContent(), &displayport)) {
|
2011-01-13 20:45:14 +03:00
|
|
|
// The visible region for the children may be much bigger than the hole we
|
|
|
|
// are viewing the children from, so that the compositor process has enough
|
|
|
|
// content to asynchronously pan while content is being refreshed.
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
nsRegion childVisibleRegion = displayport + aBuilder->ToReferenceFrame(mScrollFrame);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
nsRect boundedRect;
|
|
|
|
boundedRect.IntersectRect(childVisibleRegion.GetBounds(), mList.GetBounds(aBuilder));
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect allowExpansion;
|
|
|
|
allowExpansion.IntersectRect(allowExpansion, boundedRect);
|
2011-01-13 20:45:14 +03:00
|
|
|
PRBool visible = mList.ComputeVisibilityForSublist(
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder, &childVisibleRegion, boundedRect, allowExpansion);
|
2011-01-13 20:45:14 +03:00
|
|
|
mVisibleRect = boundedRect;
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
|
|
|
|
} else {
|
2011-05-02 05:53:01 +04:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager)
|
2011-04-29 21:15:44 +04:00
|
|
|
{
|
2011-05-02 05:53:01 +04:00
|
|
|
// Force this as a layer so we can scroll asynchronously.
|
|
|
|
// This causes incorrect rendering for rounded clips!
|
|
|
|
return LAYER_ACTIVE_FORCE;
|
2011-04-29 21:15:44 +04:00
|
|
|
}
|
2011-05-02 05:53:01 +04:00
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayScrollLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SCROLL_LAYER) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer* other = static_cast<nsDisplayScrollLayer*>(aItem);
|
|
|
|
if (other->mScrolledFrame != this->mScrolledFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Set(nsIFrame::ScrollLayerCount(),
|
|
|
|
reinterpret_cast<void*>(GetScrollLayerCount() - 1));
|
|
|
|
|
|
|
|
mList.AppendToBottom(&other->mList);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayScrollLayer::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return GetScrollLayerCount() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRWord
|
|
|
|
nsDisplayScrollLayer::GetScrollLayerCount()
|
|
|
|
{
|
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool hasCount = PR_FALSE;
|
|
|
|
PRWord result = reinterpret_cast<PRWord>(
|
|
|
|
props.Get(nsIFrame::ScrollLayerCount(), &hasCount));
|
|
|
|
// If this aborts, then the property was either not added before scroll
|
|
|
|
// layers were created or the property was deleted to early. If the latter,
|
|
|
|
// make sure that nsDisplayScrollInfoLayer is on the bottom of the list so
|
|
|
|
// that it is processed last.
|
|
|
|
NS_ABORT_IF_FALSE(hasCount, "nsDisplayScrollLayer should always be defined");
|
|
|
|
return result;
|
|
|
|
#else
|
|
|
|
return reinterpret_cast<PRWord>(props.Get(nsIFrame::ScrollLayerCount()));
|
2011-01-13 20:45:14 +03:00
|
|
|
#endif
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRWord
|
|
|
|
nsDisplayScrollLayer::RemoveScrollLayerCount()
|
|
|
|
{
|
|
|
|
PRWord result = GetScrollLayerCount();
|
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Remove(nsIFrame::ScrollLayerCount());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-04-12 00:53:01 +04:00
|
|
|
nsDisplayScrollInfoLayer::nsDisplayScrollInfoLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayScrollLayer(aBuilder, aScrolledFrame, aScrolledFrame, aScrollFrame)
|
2011-04-12 00:53:01 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollInfoLayer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayScrollInfoLayer::~nsDisplayScrollInfoLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollInfoLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollInfoLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
|
|
|
return LAYER_ACTIVE_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayScrollInfoLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDisplayScrollInfoLayer::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
// Layer metadata for a particular scroll frame needs to be unique. Only
|
|
|
|
// one nsDisplayScrollLayer (with rendered content) or one
|
|
|
|
// nsDisplayScrollInfoLayer (with only the metadata) should survive the
|
|
|
|
// visibility computation.
|
|
|
|
return RemoveScrollLayerCount() == 1;
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayClip::nsDisplayClip(nsDisplayListBuilder* aBuilder,
|
2010-09-09 19:21:46 +04:00
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem,
|
|
|
|
const nsRect& aRect)
|
2011-01-04 13:39:47 +03:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aItem) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2011-01-04 13:39:47 +03:00
|
|
|
mClip = SnapBounds(aBuilder->IsSnappingEnabled() && !aBuilder->IsInTransform(),
|
|
|
|
aBuilder->CurrentPresContext(), aRect);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayClip::nsDisplayClip(nsDisplayListBuilder* aBuilder,
|
2010-09-09 19:21:46 +04:00
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
const nsRect& aRect)
|
2011-01-04 13:39:47 +03:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
2011-01-04 13:39:47 +03:00
|
|
|
mClip = SnapBounds(aBuilder->IsSnappingEnabled() && !aBuilder->IsInTransform(),
|
|
|
|
aBuilder->CurrentPresContext(), aRect);
|
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,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-03-01 10:56:19 +03:00
|
|
|
NS_ERROR("nsDisplayClip should have been flattened away for painting");
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
PRBool nsDisplayClip::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2009-10-07 08:28:41 +04:00
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
|
|
|
|
nsRegion finalClipped(clipped);
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect allowExpansion;
|
|
|
|
allowExpansion.IntersectRect(mClip, aAllowVisibleRegionExpansion);
|
2009-10-07 08:28:41 +04:00
|
|
|
PRBool anyVisible =
|
2011-01-28 01:58:50 +03:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &finalClipped,
|
2011-05-13 20:40:46 +04:00
|
|
|
allowExpansion);
|
2009-10-07 08:28:41 +04:00
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(clipped, finalClipped);
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
2009-08-14 06:09:51 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
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);
|
2011-04-19 07:07:23 +04:00
|
|
|
if (!other->mClip.IsEqualInterior(mClip))
|
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)
|
2010-09-09 19:21:46 +04:00
|
|
|
nsDisplayClip(aBuilder, aItem->GetUnderlyingFrame(), aItem, mClip);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2010-09-09 19:21:46 +04:00
|
|
|
nsDisplayClipRoundedRect::nsDisplayClipRoundedRect(
|
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const nsRect& aRect, nscoord aRadii[8])
|
|
|
|
: nsDisplayClip(aBuilder, aFrame, aItem, aRect)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayClipRoundedRect);
|
|
|
|
memcpy(mRadii, aRadii, sizeof(mRadii));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayClipRoundedRect::nsDisplayClipRoundedRect(
|
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList,
|
|
|
|
const nsRect& aRect, nscoord aRadii[8])
|
|
|
|
: nsDisplayClip(aBuilder, aFrame, aList, aRect)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayClipRoundedRect);
|
|
|
|
memcpy(mRadii, aRadii, sizeof(mRadii));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayClipRoundedRect::~nsDisplayClipRoundedRect()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayClipRoundedRect);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
|
|
|
nsDisplayClipRoundedRect::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2010-10-19 21:02:25 +04:00
|
|
|
PRBool* aForceTransparentSurface)
|
2010-09-09 19:21:46 +04:00
|
|
|
{
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsRegion();
|
2010-09-09 19:21:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayClipRoundedRect::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect, HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
2010-10-11 22:03:12 +04:00
|
|
|
if (!RoundedRectIntersectsRect(mClip, mRadii, aRect)) {
|
|
|
|
// aRect doesn't intersect our border-radius curve.
|
|
|
|
|
|
|
|
// FIXME: This isn't quite sufficient for aRect having nontrivial
|
|
|
|
// size (which is the unusual case here), since it's possible that
|
|
|
|
// the part of aRect that intersects the the rounded rect isn't the
|
|
|
|
// part that intersects the items in mList.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-09 19:21:46 +04:00
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList*
|
|
|
|
nsDisplayClipRoundedRect::WrapWithClone(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
return new (aBuilder)
|
|
|
|
nsDisplayClipRoundedRect(aBuilder, aItem->GetUnderlyingFrame(), aItem,
|
|
|
|
mClip, mRadii);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayClipRoundedRect::ComputeVisibility(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-09-09 19:21:46 +04:00
|
|
|
{
|
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
|
2011-05-13 20:40:46 +04:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, &clipped, nsRect());
|
2010-09-09 19:21:46 +04:00
|
|
|
// FIXME: Remove a *conservative* opaque region from aVisibleRegion
|
|
|
|
// (like in nsDisplayClip::ComputeVisibility).
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayClipRoundedRect::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_CLIP_ROUNDED_RECT)
|
|
|
|
return PR_FALSE;
|
|
|
|
nsDisplayClipRoundedRect* other =
|
|
|
|
static_cast<nsDisplayClipRoundedRect*>(aItem);
|
2011-04-19 07:07:23 +04:00
|
|
|
if (!mClip.IsEqualInterior(other->mClip) ||
|
2010-12-24 23:37:03 +03:00
|
|
|
memcmp(mRadii, other->mRadii, sizeof(mRadii)) != 0)
|
2010-09-09 19:21:46 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
mList.AppendToBottom(&other->mList);
|
|
|
|
return PR_TRUE;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayZoom::nsDisplayZoom(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
2010-07-19 06:23:48 +04:00
|
|
|
PRInt32 aAPD, PRInt32 aParentAPD)
|
2010-08-13 14:01:13 +04:00
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList), mAPD(aAPD),
|
|
|
|
mParentAPD(aParentAPD) {
|
2010-07-19 06:23:48 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayZoom::~nsDisplayZoom() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRect nsDisplayZoom::GetBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
nsRect bounds = nsDisplayWrapList::GetBounds(aBuilder);
|
|
|
|
return bounds.ConvertAppUnitsRoundOut(mAPD, mParentAPD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayZoom::HitTest(nsDisplayListBuilder *aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState *aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
// A 1x1 rect indicates we are just hit testing a point, so pass down a 1x1
|
|
|
|
// rect as well instead of possibly rounding the width or height to zero.
|
|
|
|
if (aRect.width == 1 && aRect.height == 1) {
|
|
|
|
rect.MoveTo(aRect.TopLeft().ConvertAppUnits(mParentAPD, mAPD));
|
|
|
|
rect.width = rect.height = 1;
|
|
|
|
} else {
|
|
|
|
rect = aRect.ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
|
|
|
}
|
|
|
|
mList.HitTest(aBuilder, rect, aState, aOutFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayZoom::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2010-07-19 06:23:48 +04:00
|
|
|
{
|
|
|
|
mList.PaintForFrame(aBuilder, aCtx, mFrame, nsDisplayList::PAINT_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsDisplayZoom::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion *aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-19 06:23:48 +04:00
|
|
|
{
|
|
|
|
// Convert the passed in visible region to our appunits.
|
|
|
|
nsRegion visibleRegion =
|
|
|
|
aVisibleRegion->ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
|
|
|
nsRegion originalVisibleRegion = visibleRegion;
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
nsRect transformedVisibleRect =
|
|
|
|
mVisibleRect.ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect allowExpansion =
|
|
|
|
aAllowVisibleRegionExpansion.ConvertAppUnitsRoundIn(mParentAPD, mAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
PRBool retval =
|
2010-08-28 03:15:08 +04:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &visibleRegion,
|
2011-01-28 01:58:50 +03:00
|
|
|
transformedVisibleRect,
|
2011-05-13 20:40:46 +04:00
|
|
|
allowExpansion);
|
2010-07-19 06:23:48 +04:00
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
// removed = originalVisibleRegion - visibleRegion
|
|
|
|
removed.Sub(originalVisibleRegion, visibleRegion);
|
|
|
|
// Convert removed region to parent appunits.
|
|
|
|
removed = removed.ConvertAppUnitsRoundIn(mAPD, mParentAPD);
|
|
|
|
// aVisibleRegion = aVisibleRegion - removed (modulo any simplifications
|
|
|
|
// SubtractFromVisibleRegion does)
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
2010-07-19 06:23:48 +04:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-09-13 13:42:11 +04: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 12:47:02 +04:00
|
|
|
// correctly, since when the frames are initially being reflowed, their
|
2008-09-13 13:42:11 +04: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
|
|
|
|
|
2010-06-06 00:29:49 +04:00
|
|
|
/* Returns the delta specified by the -moz-transform-origin property.
|
2008-09-13 13:42:11 +04:00
|
|
|
* 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
|
2011-08-03 07:04:23 +04:00
|
|
|
gfxPoint3D GetDeltaToMozTransformOrigin(const nsIFrame* aFrame,
|
|
|
|
float aFactor,
|
|
|
|
const nsRect* aBoundsOverride)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
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. */
|
2011-08-03 07:04:23 +04:00
|
|
|
gfxPoint3D result;
|
|
|
|
gfxFloat* coords[3] = {&result.x, &result.y, &result.z};
|
2008-09-13 13:42:11 +04:00
|
|
|
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.
|
|
|
|
*/
|
2010-09-15 19:11:26 +04:00
|
|
|
const nsStyleCoord &coord = display->mTransformOrigin[index];
|
|
|
|
if (coord.GetUnit() == eStyleUnit_Calc) {
|
|
|
|
const nsStyleCoord::Calc *calc = coord.GetCalcValue();
|
2008-09-13 13:42:11 +04:00
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(*dimensions[index], aFactor) *
|
2010-09-15 19:11:26 +04:00
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aFactor);
|
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(*dimensions[index], aFactor) *
|
|
|
|
coord.GetPercentValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(coord.GetCoordValue(), aFactor);
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
2011-08-03 07:04:23 +04:00
|
|
|
|
|
|
|
*coords[2] = NSAppUnitsToFloatPixels(display->mTransformOrigin[2].GetCoordValue(), aFactor);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Adjust based on the origin of the rectangle. */
|
|
|
|
result.x += NSAppUnitsToFloatPixels(boundingRect.x, aFactor);
|
|
|
|
result.y += NSAppUnitsToFloatPixels(boundingRect.y, aFactor);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-08-03 07:04:24 +04:00
|
|
|
/* Returns the delta specified by the -moz-perspective-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 perspective origin.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
gfxPoint3D GetDeltaToMozPerspectiveOrigin(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-perspective-origin is a
|
|
|
|
* percentage, it's relative to the size of the frame. Otherwise, if it's
|
|
|
|
* a distance, it's already computed for us!
|
|
|
|
*/
|
|
|
|
|
|
|
|
//TODO: Should this be using our bounds or the parent's bounds?
|
|
|
|
// How do we handle aBoundsOverride in the latter case?
|
|
|
|
const nsStyleDisplay* display = aFrame->GetParent()->GetStyleDisplay();
|
|
|
|
nsRect boundingRect = (aBoundsOverride ? *aBoundsOverride :
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(aFrame));
|
|
|
|
|
|
|
|
/* Allows us to access named variables by index. */
|
|
|
|
gfxPoint3D result;
|
|
|
|
result.z = 0.0f;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
const nsStyleCoord &coord = display->mPerspectiveOrigin[index];
|
|
|
|
if (coord.GetUnit() == eStyleUnit_Calc) {
|
|
|
|
const nsStyleCoord::Calc *calc = coord.GetCalcValue();
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(*dimensions[index], aFactor) *
|
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aFactor);
|
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(*dimensions[index], aFactor) *
|
|
|
|
coord.GetPercentValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
|
|
|
*coords[index] = NSAppUnitsToFloatPixels(coord.GetCoordValue(), aFactor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An offset of (0,0) results in the perspective-origin being at the centre of the element,
|
|
|
|
* so include a shift of the centre point to (0,0).
|
|
|
|
*/
|
|
|
|
result.x -= NSAppUnitsToFloatPixels(boundingRect.width, aFactor)/2;
|
|
|
|
result.y -= NSAppUnitsToFloatPixels(boundingRect.height, aFactor)/2;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* 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.
|
|
|
|
*/
|
2011-07-23 02:28:51 +04:00
|
|
|
gfx3DMatrix
|
2008-09-13 13:42:11 +04:00
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin,
|
|
|
|
float aFactor,
|
2011-08-27 04:01:46 +04:00
|
|
|
const nsRect* aBoundsOverride,
|
|
|
|
nsIFrame** aOutAncestor)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Cannot get transform matrix for a null frame!");
|
2011-08-27 04:01:46 +04:00
|
|
|
|
|
|
|
if (aOutAncestor) {
|
|
|
|
*aOutAncestor = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Preserve-3d can cause frames without a transform to get an nsDisplayTransform created, we should
|
|
|
|
* use our parent's transform here.
|
|
|
|
*/
|
|
|
|
if (!aFrame->GetStyleDisplay()->HasTransform()) {
|
|
|
|
return GetResultingTransformMatrix(aFrame->GetParent(), aOrigin - aFrame->GetPosition(), aFactor, nsnull, aOutAncestor);
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Account for the -moz-transform-origin property by translating the
|
|
|
|
* coordinate space to the new origin.
|
|
|
|
*/
|
2011-08-03 07:04:23 +04:00
|
|
|
gfxPoint3D toMozOrigin = GetDeltaToMozTransformOrigin(aFrame, aFactor, aBoundsOverride);
|
2011-08-03 07:04:24 +04:00
|
|
|
gfxPoint3D toPerspectiveOrigin = GetDeltaToMozPerspectiveOrigin(aFrame, aFactor, aBoundsOverride);
|
2011-08-03 07:04:23 +04:00
|
|
|
gfxPoint3D newOrigin = gfxPoint3D(NSAppUnitsToFloatPixels(aOrigin.x, aFactor),
|
|
|
|
NSAppUnitsToFloatPixels(aOrigin.y, aFactor),
|
|
|
|
0.0f);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* 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. */
|
2011-07-23 02:28:07 +04:00
|
|
|
PRBool dummy;
|
2011-08-27 04:01:46 +04:00
|
|
|
gfx3DMatrix result;
|
|
|
|
/* Transformed frames always have a transform, or are preserving 3d (and might still have perspective!) */
|
|
|
|
if (disp->mSpecifiedTransform) {
|
|
|
|
result = nsStyleTransformMatrix::ReadTransforms(disp->mSpecifiedTransform,
|
|
|
|
aFrame->GetStyleContext(),
|
|
|
|
aFrame->PresContext(),
|
|
|
|
dummy, bounds, aFactor);
|
|
|
|
} else {
|
2011-09-05 02:25:35 +04:00
|
|
|
NS_ASSERTION(aFrame->GetStyleDisplay()->mTransformStyle == NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D,
|
|
|
|
"If we don't have a transform, then we must be at least attempting to preserve the transforms of our children");
|
2011-08-27 04:01:46 +04:00
|
|
|
}
|
2011-08-03 07:04:22 +04:00
|
|
|
|
|
|
|
const nsStyleDisplay* parentDisp = nsnull;
|
|
|
|
if (aFrame->GetParent()) {
|
|
|
|
parentDisp = aFrame->GetParent()->GetStyleDisplay();
|
|
|
|
}
|
|
|
|
if (nsLayoutUtils::Are3DTransformsEnabled() &&
|
|
|
|
parentDisp && parentDisp->mChildPerspective.GetUnit() == eStyleUnit_Coord &&
|
|
|
|
parentDisp->mChildPerspective.GetCoordValue() > 0.0) {
|
|
|
|
gfx3DMatrix perspective;
|
|
|
|
perspective._34 =
|
|
|
|
-1.0 / NSAppUnitsToFloatPixels(parentDisp->mChildPerspective.GetCoordValue(),
|
|
|
|
aFactor);
|
2011-08-03 07:04:24 +04:00
|
|
|
result = result * nsLayoutUtils::ChangeMatrixBasis(toPerspectiveOrigin, perspective);
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2011-08-27 04:01:46 +04:00
|
|
|
|
|
|
|
if (aFrame->Preserves3D() && nsLayoutUtils::Are3DTransformsEnabled()) {
|
|
|
|
// Include the transform set on our parent
|
|
|
|
NS_ASSERTION(aFrame->GetParent() &&
|
|
|
|
aFrame->GetParent()->IsTransformed() &&
|
|
|
|
aFrame->GetParent()->Preserves3DChildren(),
|
|
|
|
"Preserve3D mismatch!");
|
|
|
|
gfx3DMatrix parent = GetResultingTransformMatrix(aFrame->GetParent(), aOrigin - aFrame->GetPosition(),
|
|
|
|
aFactor, nsnull, aOutAncestor);
|
|
|
|
return nsLayoutUtils::ChangeMatrixBasis(newOrigin + toMozOrigin, result) * parent;
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
return nsLayoutUtils::ChangeMatrixBasis
|
2011-08-03 07:04:22 +04:00
|
|
|
(newOrigin + toMozOrigin, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfx3DMatrix&
|
|
|
|
nsDisplayTransform::GetTransform(float aFactor)
|
|
|
|
{
|
|
|
|
if (mTransform.IsIdentity() || mCachedFactor != aFactor) {
|
|
|
|
mTransform =
|
|
|
|
GetResultingTransformMatrix(mFrame, ToReferenceFrame(),
|
|
|
|
aFactor,
|
|
|
|
nsnull);
|
|
|
|
mCachedFactor = aFactor;
|
|
|
|
}
|
2011-07-23 02:28:07 +04:00
|
|
|
return mTransform;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2010-08-02 07:07:04 +04:00
|
|
|
already_AddRefed<Layer> nsDisplayTransform::BuildLayer(nsDisplayListBuilder *aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager *aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2011-07-23 02:28:51 +04:00
|
|
|
const gfx3DMatrix& newTransformMatrix =
|
2011-07-23 02:28:07 +04:00
|
|
|
GetTransform(mFrame->PresContext()->AppUnitsPerDevPixel());
|
2011-08-03 07:04:22 +04:00
|
|
|
|
|
|
|
if (newTransformMatrix.IsSingular() ||
|
|
|
|
(mFrame->GetStyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
|
|
|
newTransformMatrix.GetNormalVector().z <= 0.0)) {
|
2010-08-02 07:07:04 +04:00
|
|
|
return nsnull;
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2011-06-22 16:11:27 +04:00
|
|
|
return aBuilder->LayerBuilder()->
|
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, *mStoredList.GetList(),
|
2011-07-23 02:28:51 +04:00
|
|
|
aContainerParameters, &newTransformMatrix);
|
2010-08-02 07:07:04 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2010-08-02 07:07:04 +04:00
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayTransform::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager) {
|
2011-06-22 16:11:28 +04:00
|
|
|
if (mFrame->AreLayersMarkedActive(nsChangeHint_UpdateTransformLayer))
|
2010-08-02 07:07:04 +04:00
|
|
|
return LAYER_ACTIVE;
|
2011-08-03 07:04:20 +04:00
|
|
|
if (!GetTransform(mFrame->PresContext()->AppUnitsPerDevPixel()).Is2D())
|
|
|
|
return LAYER_ACTIVE;
|
2010-08-02 07:07:04 +04:00
|
|
|
nsIFrame* activeScrolledRoot =
|
2010-08-08 22:49:06 +04:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(mFrame, nsnull);
|
2010-08-02 07:07:04 +04:00
|
|
|
return !mStoredList.ChildrenCanBeInactive(aBuilder,
|
|
|
|
aManager,
|
|
|
|
*mStoredList.GetList(),
|
|
|
|
activeScrolledRoot)
|
|
|
|
? LAYER_ACTIVE : LAYER_INACTIVE;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
PRBool nsDisplayTransform::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion *aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2009-09-07 04:35:14 +04:00
|
|
|
/* As we do this, we need to be sure to
|
|
|
|
* untransform the visible rect, since we want everything that's painting to
|
2011-07-23 02:28:51 +04:00
|
|
|
* think that it's painting in its original rectangular coordinate space.
|
|
|
|
* If we can't untransform, take the entire overflow rect */
|
|
|
|
nsRect untransformedVisibleRect;
|
|
|
|
if (!UntransformRect(mVisibleRect,
|
|
|
|
mFrame,
|
|
|
|
aBuilder->ToReferenceFrame(mFrame),
|
|
|
|
&untransformedVisibleRect))
|
|
|
|
{
|
|
|
|
untransformedVisibleRect = mFrame->GetVisualOverflowRectRelativeToSelf() +
|
|
|
|
aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
nsRegion untransformedVisible = untransformedVisibleRect;
|
2011-09-07 04:20:35 +04:00
|
|
|
// Call RecomputeVisiblity instead of ComputeVisibility since
|
2010-08-28 03:15:08 +04:00
|
|
|
// nsDisplayItem::ComputeVisibility should only be called from
|
|
|
|
// nsDisplayList::ComputeVisibility (which sets mVisibleRect on the item)
|
|
|
|
mStoredList.RecomputeVisibility(aBuilder, &untransformedVisible);
|
2008-09-13 13:42:11 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HitTest does some fun stuff with matrix transforms to obtain the answer. */
|
2010-04-08 04:31:26 +04:00
|
|
|
void nsDisplayTransform::HitTest(nsDisplayListBuilder *aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState *aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
/* Here's how this works:
|
|
|
|
* 1. Get the matrix. If it's singular, abort (clearly we didn't hit
|
|
|
|
* anything).
|
|
|
|
* 2. Invert the matrix.
|
2010-04-08 04:31:26 +04:00
|
|
|
* 3. Use it to transform the rect into the correct space.
|
|
|
|
* 4. Pass that rect down through to the list's version of HitTest.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2011-07-23 02:28:51 +04:00
|
|
|
gfx3DMatrix matrix = GetTransform(factor);
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-08-03 07:04:22 +04:00
|
|
|
/* If the matrix is singular, or a hidden backface is shown, we didn't hit anything. */
|
|
|
|
if (matrix.IsSingular() ||
|
|
|
|
(mFrame->GetStyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
|
|
|
matrix.GetNormalVector().z <= 0.0)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Now, apply the transform and pass it down the channel. */
|
2010-04-08 04:31:26 +04:00
|
|
|
nsRect resultingRect;
|
|
|
|
if (aRect.width == 1 && aRect.height == 1) {
|
2011-09-08 15:15:00 +04:00
|
|
|
// Magic width/height indicating we're hit testing a point, not a rect
|
2011-08-03 07:04:21 +04:00
|
|
|
gfxPoint point = matrix.Inverse().ProjectPoint(
|
|
|
|
gfxPoint(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor)));
|
2010-04-08 04:31:26 +04:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(point.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(point.y), factor),
|
|
|
|
1, 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
gfxRect originalRect(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, factor));
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
gfxRect rect = matrix.Inverse().ProjectRectBounds(originalRect);;
|
2010-04-08 04:31:26 +04:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(rect.X()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Y()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Width()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Height()), factor));
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
printf("Frame: %p\n", dynamic_cast<void *>(mFrame));
|
2010-04-08 04:31:26 +04:00
|
|
|
printf(" Untransformed point: (%f, %f)\n", resultingRect.X(), resultingRect.Y());
|
|
|
|
PRUint32 originalFrameCount = aOutFrames.Length();
|
2008-09-13 13:42:11 +04:00
|
|
|
#endif
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
mStoredList.HitTest(aBuilder, resultingRect, aState, aOutFrames);
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
#ifdef DEBUG_HIT
|
2010-04-08 04:31:26 +04:00
|
|
|
if (originalFrameCount != aOutFrames.Length())
|
|
|
|
printf(" Hit! Time: %f, first frame: %p\n", static_cast<double>(clock()),
|
|
|
|
dynamic_cast<void *>(aOutFrames.ElementAt(0)));
|
2008-09-13 13:42:11 +04:00
|
|
|
printf("=== end of hit test ===\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The bounding rectangle for the object is the overflow rectangle translated
|
|
|
|
* by the reference point.
|
|
|
|
*/
|
|
|
|
nsRect nsDisplayTransform::GetBounds(nsDisplayListBuilder *aBuilder)
|
|
|
|
{
|
2011-01-07 04:38:22 +03:00
|
|
|
return TransformRect(mStoredList.GetBounds(aBuilder), mFrame, ToReferenceFrame());
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is opaque iff the transform consists solely of scales and
|
2010-11-27 02:31:08 +03:00
|
|
|
* translations and if the underlying content is opaque. Thus if the transform
|
2008-09-13 13:42:11 +04:00
|
|
|
* is of the form
|
|
|
|
*
|
|
|
|
* |a c e|
|
|
|
|
* |b d f|
|
|
|
|
* |0 0 1|
|
|
|
|
*
|
|
|
|
* We need b and c to be zero.
|
2010-11-27 02:31:08 +03:00
|
|
|
*
|
|
|
|
* We also need to check whether the underlying opaque content completely fills
|
|
|
|
* our visible rect. We use UntransformRect which expands to the axis-aligned
|
|
|
|
* bounding rect, but that's OK since if
|
|
|
|
* mStoredList.GetVisibleRect().Contains(untransformedVisible), then it
|
|
|
|
* certainly contains the actual (non-axis-aligned) untransformed rect.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplayTransform::GetOpaqueRegion(nsDisplayListBuilder *aBuilder,
|
|
|
|
PRBool* aForceTransparentSurface)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2011-07-23 02:28:51 +04:00
|
|
|
nsRect untransformedVisible;
|
|
|
|
if (!UntransformRect(mVisibleRect, mFrame, ToReferenceFrame(), &untransformedVisible)) {
|
|
|
|
return nsRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfx3DMatrix& matrix = GetTransform(nsPresContext::AppUnitsPerCSSPixel());
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
2011-07-23 02:28:51 +04:00
|
|
|
gfxMatrix matrix2d;
|
|
|
|
if (matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2011-01-03 04:48:09 +03:00
|
|
|
mStoredList.GetOpaqueRegion(aBuilder).Contains(untransformedVisible)) {
|
|
|
|
result = mVisibleRect;
|
|
|
|
}
|
|
|
|
return result;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is uniform if it fills the entire bounding rect and the
|
2011-01-03 04:48:09 +03:00
|
|
|
* wrapped list is uniform. See GetOpaqueRegion for discussion of why this
|
2008-09-13 13:42:11 +04:00
|
|
|
* works.
|
|
|
|
*/
|
2010-05-13 04:56:11 +04:00
|
|
|
PRBool nsDisplayTransform::IsUniform(nsDisplayListBuilder *aBuilder, nscolor* aColor)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2011-07-23 02:28:51 +04:00
|
|
|
nsRect untransformedVisible;
|
|
|
|
if (!UntransformRect(mVisibleRect, mFrame, ToReferenceFrame(), &untransformedVisible)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
const gfx3DMatrix& matrix = GetTransform(nsPresContext::AppUnitsPerCSSPixel());
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-07-23 02:28:51 +04:00
|
|
|
gfxMatrix matrix2d;
|
|
|
|
return matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2011-07-23 02:28:07 +04:00
|
|
|
mStoredList.GetVisibleRect().Contains(untransformedVisible) &&
|
|
|
|
mStoredList.IsUniform(aBuilder, aColor);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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!");
|
|
|
|
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
return nsLayoutUtils::MatrixTransformRect
|
|
|
|
(aUntransformedBounds,
|
2011-02-25 01:55:23 +03:00
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect nsDisplayTransform::TransformRectOut(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!");
|
|
|
|
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
return nsLayoutUtils::MatrixTransformRectOut
|
|
|
|
(aUntransformedBounds,
|
2008-09-13 13:42:11 +04:00
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
2011-07-23 02:28:51 +04:00
|
|
|
PRBool nsDisplayTransform::UntransformRect(const nsRect &aUntransformedBounds,
|
2008-09-13 13:42:11 +04:00
|
|
|
const nsIFrame* aFrame,
|
2011-07-23 02:28:51 +04:00
|
|
|
const nsPoint &aOrigin,
|
|
|
|
nsRect* aOutRect)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
|
|
|
|
/* Grab the matrix. If the transform is degenerate, just hand back the
|
|
|
|
* empty rect.
|
|
|
|
*/
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2011-07-23 02:28:51 +04:00
|
|
|
gfx3DMatrix matrix = GetResultingTransformMatrix(aFrame, aOrigin, factor, nsnull);
|
2011-08-03 07:04:21 +04:00
|
|
|
if (matrix.IsSingular())
|
2011-07-23 02:28:51 +04:00
|
|
|
return PR_FALSE;
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
gfxRect result(NSAppUnitsToFloatPixels(aUntransformedBounds.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.height, factor));
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* We want to untransform the matrix, so invert the transformation first! */
|
2011-08-03 07:04:21 +04:00
|
|
|
result = matrix.Inverse().ProjectRectBounds(result);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2011-08-16 07:44:22 +04:00
|
|
|
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(result, factor);
|
2011-07-23 02:28:51 +04:00
|
|
|
|
|
|
|
return PR_TRUE;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplaySVGEffects::nsDisplaySVGEffects(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList), mEffectsFrame(aFrame),
|
2010-10-07 08:25:47 +04:00
|
|
|
mBounds(aFrame->GetVisualOverflowRectRelativeToSelf())
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplaySVGEffects::~nsDisplaySVGEffects()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplaySVGEffects::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
PRBool* aForceTransparentSurface)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsRegion();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2010-04-08 04:31:26 +04:00
|
|
|
nsPoint rectCenter(aRect.x + aRect.width / 2, aRect.y + aRect.height / 2);
|
|
|
|
if (nsSVGIntegrationUtils::HitTestFrameForEffects(mEffectsFrame,
|
|
|
|
rectCenter - aBuilder->ToReferenceFrame(mEffectsFrame))) {
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplaySVGEffects::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(aCtx,
|
2009-09-07 04:35:14 +04:00
|
|
|
mEffectsFrame, mVisibleRect, aBuilder, &mList);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
PRBool nsDisplaySVGEffects::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2009-10-07 08:28:41 +04: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);
|
2010-08-28 03:15:08 +04:00
|
|
|
nsRect r;
|
|
|
|
r.IntersectRect(dirtyRect, mList.GetBounds(aBuilder));
|
2011-05-13 20:40:46 +04:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &childrenVisible, r, nsRect());
|
2009-09-07 04:35:14 +04:00
|
|
|
return PR_TRUE;
|
2008-09-11 04:24:16 +04: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;
|
|
|
|
}
|
2011-06-22 22:11:48 +04:00
|
|
|
|
|
|
|
nsDisplayForcePaintOnScroll::nsDisplayForcePaintOnScroll(
|
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayForcePaintOnScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayForcePaintOnScroll::~nsDisplayForcePaintOnScroll() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayForcePaintOnScroll);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PRBool nsDisplayForcePaintOnScroll::IsVaryingRelativeToMovingFrame(
|
|
|
|
nsDisplayListBuilder* aBuilder, nsIFrame* aFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|