2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* structures that represent things to be painted (ordered in z-order),
|
|
|
|
* used during painting and hit testing
|
|
|
|
*/
|
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "gfxContext.h"
|
2008-07-16 23:30:25 -07:00
|
|
|
#include "nsStyleStructInlines.h"
|
2008-09-13 02:42:11 -07:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
|
|
|
#include "gfxMatrix.h"
|
2008-09-10 17:24:16 -07:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2009-07-21 17:44:57 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2010-07-15 14:08:12 -07:00
|
|
|
#include "nsIScrollableFrame.h"
|
2010-07-24 02:35:29 -07:00
|
|
|
#include "nsThemeConstants.h"
|
2012-08-28 22:47:18 -07:00
|
|
|
#include "LayerTreeInvalidation.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-04-08 08:19:51 -07:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2010-02-28 23:56:19 -08:00
|
|
|
#include "BasicLayers.h"
|
2010-11-30 06:59:46 -08:00
|
|
|
#include "nsBoxFrame.h"
|
2011-04-08 09:35:16 -07:00
|
|
|
#include "nsViewportFrame.h"
|
2011-11-16 19:44:16 -08:00
|
|
|
#include "nsSVGEffects.h"
|
2012-07-20 11:12:29 -07:00
|
|
|
#include "nsSVGElement.h"
|
2011-11-16 19:44:16 -08:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2012-04-16 11:37:59 -07:00
|
|
|
#include "sampler.h"
|
2012-07-31 10:28:21 -07:00
|
|
|
#include "nsAnimationManager.h"
|
2012-07-31 10:28:22 -07:00
|
|
|
#include "nsTransitionManager.h"
|
2012-07-31 10:28:21 -07:00
|
|
|
#include "nsIViewManager.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "ImageLayers.h"
|
|
|
|
#include "ImageContainer.h"
|
2010-02-28 23:56:19 -08:00
|
|
|
|
2012-04-11 17:17:44 -07:00
|
|
|
#include "mozilla/StandardInteger.h"
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
using namespace mozilla;
|
2012-08-25 18:27:28 -07:00
|
|
|
using namespace mozilla::css;
|
2010-02-28 23:56:19 -08:00
|
|
|
using namespace mozilla::layers;
|
2011-01-13 09:45:14 -08:00
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2009-04-08 08:19:51 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
static void AddTransformFunctions(nsCSSValueList* aList,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsRect& aBounds,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
InfallibleTArray<TransformFunction>& aFunctions)
|
|
|
|
{
|
|
|
|
if (aList->mValue.GetUnit() == eCSSUnit_None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const nsCSSValueList* curr = aList; curr; curr = curr->mNext) {
|
|
|
|
const nsCSSValue& currElem = curr->mValue;
|
|
|
|
NS_ASSERTION(currElem.GetUnit() == eCSSUnit_Function,
|
|
|
|
"Stream should consist solely of functions!");
|
|
|
|
nsCSSValue::Array* array = currElem.GetArrayValue();
|
|
|
|
bool canStoreInRuleTree = true;
|
|
|
|
switch (nsStyleTransformMatrix::TransformFunctionOf(array)) {
|
|
|
|
case eCSSKeyword_rotatex:
|
|
|
|
{
|
|
|
|
double theta = array->Item(1).GetAngleValueInRadians();
|
|
|
|
aFunctions.AppendElement(RotationX(theta));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_rotatey:
|
|
|
|
{
|
|
|
|
double theta = array->Item(1).GetAngleValueInRadians();
|
|
|
|
aFunctions.AppendElement(RotationY(theta));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_rotatez:
|
|
|
|
{
|
|
|
|
double theta = array->Item(1).GetAngleValueInRadians();
|
|
|
|
aFunctions.AppendElement(RotationZ(theta));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_rotate:
|
|
|
|
{
|
|
|
|
double theta = array->Item(1).GetAngleValueInRadians();
|
|
|
|
aFunctions.AppendElement(Rotation(theta));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_rotate3d:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetFloatValue();
|
|
|
|
double y = array->Item(2).GetFloatValue();
|
|
|
|
double z = array->Item(3).GetFloatValue();
|
|
|
|
double theta = array->Item(4).GetAngleValueInRadians();
|
|
|
|
aFunctions.AppendElement(Rotation3D(x, y, z, theta));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_scalex:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(Scale(x, 1, 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_scaley:
|
|
|
|
{
|
|
|
|
double y = array->Item(1).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(Scale(1, y, 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_scalez:
|
|
|
|
{
|
|
|
|
double z = array->Item(1).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(Scale(1, 1, z));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_scale:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetFloatValue();
|
|
|
|
// scale(x) is shorthand for scale(x, x);
|
|
|
|
double y = array->Count() == 2 ? x : array->Item(2).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(Scale(x, y, 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_scale3d:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetFloatValue();
|
|
|
|
double y = array->Item(2).GetFloatValue();
|
|
|
|
double z = array->Item(3).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(Scale(x, y, z));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translatex:
|
|
|
|
{
|
|
|
|
double x = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Width(), aAppUnitsPerPixel);
|
|
|
|
aFunctions.AppendElement(Translation(x, 0, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translatey:
|
|
|
|
{
|
|
|
|
double y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Height(), aAppUnitsPerPixel);
|
|
|
|
aFunctions.AppendElement(Translation(0, y, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translatez:
|
|
|
|
{
|
|
|
|
double z = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
0, aAppUnitsPerPixel);
|
|
|
|
aFunctions.AppendElement(Translation(0, 0, z));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translate:
|
|
|
|
{
|
|
|
|
double x = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Width(), aAppUnitsPerPixel);
|
|
|
|
// translate(x) is shorthand for translate(x, 0)
|
|
|
|
double y = 0;
|
|
|
|
if (array->Count() == 3) {
|
|
|
|
y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(2), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Height(), aAppUnitsPerPixel);
|
|
|
|
}
|
|
|
|
aFunctions.AppendElement(Translation(x, y, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translate3d:
|
|
|
|
{
|
|
|
|
double x = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Width(), aAppUnitsPerPixel);
|
|
|
|
double y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(2), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
aBounds.Height(), aAppUnitsPerPixel);
|
|
|
|
double z = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(3), aContext, aPresContext, canStoreInRuleTree,
|
|
|
|
0, aAppUnitsPerPixel);
|
|
|
|
|
|
|
|
aFunctions.AppendElement(Translation(x, y, z));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_skewx:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(SkewX(x));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_skewy:
|
|
|
|
{
|
|
|
|
double y = array->Item(1).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(SkewY(y));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_matrix:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix;
|
|
|
|
matrix._11 = array->Item(1).GetFloatValue();
|
|
|
|
matrix._12 = array->Item(2).GetFloatValue();
|
|
|
|
matrix._13 = 0;
|
|
|
|
matrix._14 = array->Item(3).GetFloatValue();
|
|
|
|
matrix._21 = array->Item(4).GetFloatValue();
|
|
|
|
matrix._22 = array->Item(5).GetFloatValue();
|
|
|
|
matrix._23 = 0;
|
|
|
|
matrix._24 = array->Item(6).GetFloatValue();
|
|
|
|
matrix._31 = 0;
|
|
|
|
matrix._32 = 0;
|
|
|
|
matrix._33 = 1;
|
|
|
|
matrix._34 = 0;
|
|
|
|
matrix._41 = 0;
|
|
|
|
matrix._42 = 0;
|
|
|
|
matrix._43 = 0;
|
|
|
|
matrix._44 = 1;
|
|
|
|
aFunctions.AppendElement(TransformMatrix(matrix));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_matrix3d:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix;
|
|
|
|
matrix._11 = array->Item(1).GetFloatValue();
|
|
|
|
matrix._12 = array->Item(2).GetFloatValue();
|
|
|
|
matrix._13 = array->Item(3).GetFloatValue();
|
|
|
|
matrix._14 = array->Item(4).GetFloatValue();
|
|
|
|
matrix._21 = array->Item(5).GetFloatValue();
|
|
|
|
matrix._22 = array->Item(6).GetFloatValue();
|
|
|
|
matrix._23 = array->Item(7).GetFloatValue();
|
|
|
|
matrix._24 = array->Item(8).GetFloatValue();
|
|
|
|
matrix._31 = array->Item(9).GetFloatValue();
|
|
|
|
matrix._32 = array->Item(10).GetFloatValue();
|
|
|
|
matrix._33 = array->Item(11).GetFloatValue();
|
|
|
|
matrix._34 = array->Item(12).GetFloatValue();
|
|
|
|
matrix._41 = array->Item(13).GetFloatValue();
|
|
|
|
matrix._42 = array->Item(14).GetFloatValue();
|
|
|
|
matrix._43 = array->Item(15).GetFloatValue();
|
|
|
|
matrix._44 = array->Item(16).GetFloatValue();
|
|
|
|
aFunctions.AppendElement(TransformMatrix(matrix));
|
|
|
|
break;
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
case eCSSKeyword_interpolatematrix:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix;
|
|
|
|
nsStyleTransformMatrix::ProcessInterpolateMatrix(matrix, array,
|
|
|
|
aContext,
|
|
|
|
aPresContext,
|
|
|
|
canStoreInRuleTree,
|
|
|
|
aBounds,
|
|
|
|
aAppUnitsPerPixel);
|
|
|
|
aFunctions.AppendElement(TransformMatrix(matrix));
|
|
|
|
break;
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
case eCSSKeyword_perspective:
|
|
|
|
{
|
|
|
|
aFunctions.AppendElement(Perspective(array->Item(1).GetFloatValue()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("Function not handled yet!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static TimingFunction
|
|
|
|
ToTimingFunction(css::ComputedTimingFunction& aCTF)
|
|
|
|
{
|
|
|
|
if (aCTF.GetType() == nsTimingFunction::Function) {
|
|
|
|
const nsSMILKeySpline* spline = aCTF.GetFunction();
|
|
|
|
return TimingFunction(CubicBezierFunction(spline->X1(), spline->Y1(),
|
|
|
|
spline->X2(), spline->Y2()));
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t type = aCTF.GetType() == nsTimingFunction::StepStart ? 1 : 2;
|
2012-07-31 10:28:21 -07:00
|
|
|
return TimingFunction(StepFunction(aCTF.GetSteps(), type));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-31 10:28:22 -07:00
|
|
|
AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
|
|
|
|
ElementAnimation* ea, Layer* aLayer,
|
|
|
|
AnimationData& aData)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aLayer->AsContainerLayer(), "Should only animate ContainerLayer");
|
2012-07-31 10:28:22 -07:00
|
|
|
nsStyleContext* styleContext = aFrame->GetStyleContext();
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
nsRect bounds = nsDisplayTransform::GetFrameBoundsForTransform(aFrame);
|
2012-07-31 10:28:23 -07:00
|
|
|
float scale = presContext->AppUnitsPerDevPixel();
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-08-20 06:35:42 -07:00
|
|
|
TimeStamp startTime = ea->mStartTime;
|
|
|
|
TimeDuration duration = ea->mIterationDuration;
|
2012-07-31 10:28:22 -07:00
|
|
|
float iterations = ea->mIterationCount != NS_IEEEPositiveInfinity()
|
|
|
|
? ea->mIterationCount : -1;
|
2012-08-20 06:35:42 -07:00
|
|
|
int direction = ea->mDirection;
|
|
|
|
|
2012-08-20 21:06:47 -07:00
|
|
|
Animation* animation = aLayer->AddAnimation(startTime, duration,
|
|
|
|
iterations, direction,
|
|
|
|
aProperty, aData);
|
2012-08-20 06:35:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t propIdx = 0; propIdx < ea->mProperties.Length(); propIdx++) {
|
2012-07-31 10:28:22 -07:00
|
|
|
AnimationProperty* property = &ea->mProperties[propIdx];
|
|
|
|
|
|
|
|
if (aProperty != property->mProperty) {
|
2012-07-31 10:28:21 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t segIdx = 0; segIdx < property->mSegments.Length(); segIdx++) {
|
2012-07-31 10:28:22 -07:00
|
|
|
AnimationPropertySegment* segment = &property->mSegments[segIdx];
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-08-20 21:06:47 -07:00
|
|
|
AnimationSegment* animSegment = animation->segments().AppendElement();
|
2012-07-31 10:28:22 -07:00
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2012-08-20 06:35:42 -07:00
|
|
|
animSegment->startState() = InfallibleTArray<TransformFunction>();
|
|
|
|
animSegment->endState() = InfallibleTArray<TransformFunction>();
|
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
nsCSSValueList* list = segment->mFromValue.GetCSSValueListValue();
|
2012-08-20 06:35:42 -07:00
|
|
|
AddTransformFunctions(list, styleContext, presContext, bounds, scale,
|
|
|
|
animSegment->startState().get_ArrayOfTransformFunction());
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
list = segment->mToValue.GetCSSValueListValue();
|
2012-08-20 06:35:42 -07:00
|
|
|
AddTransformFunctions(list, styleContext, presContext, bounds, scale,
|
|
|
|
animSegment->endState().get_ArrayOfTransformFunction());
|
2012-07-31 10:28:22 -07:00
|
|
|
} else if (aProperty == eCSSProperty_opacity) {
|
2012-08-20 06:35:42 -07:00
|
|
|
animSegment->startState() = segment->mFromValue.GetFloatValue();
|
|
|
|
animSegment->endState() = segment->mToValue.GetFloatValue();
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
2012-08-20 06:35:42 -07:00
|
|
|
|
|
|
|
animSegment->startPortion() = segment->mFromKey;
|
|
|
|
animSegment->endPortion() = segment->mToKey;
|
|
|
|
animSegment->sampleFn() = ToTimingFunction(segment->mTimingFunction);
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-06 13:33:23 -07:00
|
|
|
AddAnimationsAndTransitionsToLayer(Layer* aLayer, nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem, nsCSSProperty aProperty)
|
2012-07-31 10:28:21 -07:00
|
|
|
{
|
2012-07-31 10:28:22 -07:00
|
|
|
aLayer->ClearAnimations();
|
|
|
|
|
|
|
|
nsIFrame* frame = aItem->GetUnderlyingFrame();
|
2012-08-06 13:33:23 -07:00
|
|
|
|
2012-09-19 16:14:07 -07:00
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
ElementTransitions* et =
|
2012-09-19 16:14:07 -07:00
|
|
|
nsTransitionManager::GetTransitionsForCompositor(content, aProperty);
|
2012-07-31 10:28:22 -07:00
|
|
|
|
|
|
|
ElementAnimations* ea =
|
2012-09-19 16:14:07 -07:00
|
|
|
nsAnimationManager::GetAnimationsForCompositor(content, aProperty);
|
2012-07-31 10:28:22 -07:00
|
|
|
|
|
|
|
if (!ea && !et) {
|
2012-07-31 10:28:21 -07:00
|
|
|
return;
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-08-06 13:33:23 -07:00
|
|
|
// If the frame is not prerendered, bail out. Layout will still perform the
|
|
|
|
// animation.
|
2012-08-22 23:05:27 -07:00
|
|
|
if (!aItem->CanUseAsyncAnimations(aBuilder)) {
|
2012-08-06 13:33:23 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
mozilla::TimeStamp currentTime =
|
|
|
|
frame->PresContext()->RefreshDriver()->MostRecentRefresh();
|
|
|
|
AnimationData data;
|
|
|
|
if (aProperty == eCSSProperty_transform) {
|
|
|
|
nsRect bounds = nsDisplayTransform::GetFrameBoundsForTransform(frame);
|
|
|
|
float scale = nsDeviceContext::AppUnitsPerCSSPixel();
|
|
|
|
gfxPoint3D offsetToTransformOrigin =
|
|
|
|
nsDisplayTransform::GetDeltaToMozTransformOrigin(frame, scale, &bounds);
|
|
|
|
gfxPoint3D offsetToPerspectiveOrigin =
|
|
|
|
nsDisplayTransform::GetDeltaToMozPerspectiveOrigin(frame, scale);
|
|
|
|
nscoord perspective = 0.0;
|
|
|
|
nsStyleContext* parentStyleContext = frame->GetStyleContext()->GetParent();
|
|
|
|
if (parentStyleContext) {
|
|
|
|
const nsStyleDisplay* disp = parentStyleContext->GetStyleDisplay();
|
|
|
|
if (disp && disp->mChildPerspective.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
perspective = disp->mChildPerspective.GetCoordValue();
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
|
|
|
nsPoint origin = aItem->ToReferenceFrame();
|
|
|
|
|
|
|
|
data = TransformData(origin, offsetToTransformOrigin,
|
|
|
|
offsetToPerspectiveOrigin, bounds, perspective);
|
|
|
|
} else if (aProperty == eCSSProperty_opacity) {
|
|
|
|
data = null_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (et) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t tranIdx = 0; tranIdx < et->mPropertyTransitions.Length(); tranIdx++) {
|
2012-07-31 10:28:22 -07:00
|
|
|
ElementPropertyTransition* pt = &et->mPropertyTransitions[tranIdx];
|
2012-08-21 18:48:47 -07:00
|
|
|
if (pt->mProperty != aProperty || !pt->IsRunningAt(currentTime)) {
|
2012-08-20 21:06:47 -07:00
|
|
|
continue;
|
|
|
|
}
|
2012-07-31 10:28:22 -07:00
|
|
|
|
|
|
|
ElementAnimation anim;
|
|
|
|
anim.mIterationCount = 1;
|
|
|
|
anim.mDirection = NS_STYLE_ANIMATION_DIRECTION_NORMAL;
|
|
|
|
anim.mFillMode = NS_STYLE_ANIMATION_FILL_MODE_NONE;
|
|
|
|
anim.mStartTime = pt->mStartTime;
|
|
|
|
anim.mIterationDuration = pt->mDuration;
|
|
|
|
|
|
|
|
AnimationProperty& prop = *anim.mProperties.AppendElement();
|
|
|
|
prop.mProperty = pt->mProperty;
|
|
|
|
|
|
|
|
AnimationPropertySegment& segment = *prop.mSegments.AppendElement();
|
|
|
|
segment.mFromKey = 0;
|
|
|
|
segment.mToKey = 1;
|
|
|
|
segment.mFromValue = pt->mStartValue;
|
|
|
|
segment.mToValue = pt->mEndValue;
|
|
|
|
segment.mTimingFunction = pt->mTimingFunction;
|
|
|
|
|
|
|
|
AddAnimationsForProperty(frame, aProperty, &anim,
|
|
|
|
aLayer, data);
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
aLayer->SetAnimationGeneration(et->mAnimationGeneration);
|
2012-07-31 10:28:22 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-07-31 10:28:22 -07:00
|
|
|
if (ea) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t animIdx = 0; animIdx < ea->mAnimations.Length(); animIdx++) {
|
2012-07-31 10:28:22 -07:00
|
|
|
ElementAnimation* anim = &ea->mAnimations[animIdx];
|
2012-08-20 21:06:47 -07:00
|
|
|
if (!(anim->HasAnimationOfProperty(aProperty) &&
|
2012-08-21 18:48:47 -07:00
|
|
|
anim->IsRunningAt(currentTime))) {
|
2012-07-31 10:28:22 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AddAnimationsForProperty(frame, aProperty, anim,
|
|
|
|
aLayer, data);
|
|
|
|
}
|
2012-12-11 13:12:43 -08:00
|
|
|
aLayer->SetAnimationGeneration(ea->mAnimationGeneration);
|
2012-07-31 10:28:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
|
2011-09-28 23:19:26 -07:00
|
|
|
Mode aMode, bool aBuildCaret)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mReferenceFrame(aReferenceFrame),
|
2012-07-30 07:20:58 -07:00
|
|
|
mIgnoreScrollFrame(nullptr),
|
|
|
|
mCurrentTableItem(nullptr),
|
|
|
|
mFinalTransparentRegion(nullptr),
|
2012-04-17 22:14:14 -07:00
|
|
|
mCachedOffsetFrame(aReferenceFrame),
|
2012-09-16 03:32:59 -07:00
|
|
|
mCachedReferenceFrame(aReferenceFrame),
|
2012-04-17 22:14:14 -07:00
|
|
|
mCachedOffset(0, 0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mGlassDisplayItem(nullptr),
|
2010-11-08 01:06:14 -08:00
|
|
|
mMode(aMode),
|
2010-12-04 01:58:39 -08:00
|
|
|
mBuildCaret(aBuildCaret),
|
2011-10-17 07:59:28 -07:00
|
|
|
mIgnoreSuppression(false),
|
|
|
|
mHadToIgnoreSuppression(false),
|
|
|
|
mIsAtRootOfPseudoStackingContext(false),
|
|
|
|
mIncludeAllOutOfFlows(false),
|
|
|
|
mSelectedFramesOnly(false),
|
|
|
|
mAccurateVisibleRegions(false),
|
2012-10-06 06:03:23 -07:00
|
|
|
mAllowMergingAndFlattening(true),
|
|
|
|
mWillComputePluginGeometry(false),
|
2011-10-17 07:59:28 -07:00
|
|
|
mInTransform(false),
|
|
|
|
mSyncDecodeImages(false),
|
|
|
|
mIsPaintingToWindow(false),
|
|
|
|
mHasDisplayPort(false),
|
2012-07-22 20:00:36 -07:00
|
|
|
mHasFixedItems(false),
|
2012-07-25 00:06:19 -07:00
|
|
|
mIsInFixedPosition(false),
|
2012-10-17 22:34:58 -07:00
|
|
|
mIsCompositingCheap(false),
|
|
|
|
mContainsPluginItem(false)
|
2011-04-08 09:35:16 -07:00
|
|
|
{
|
2010-06-21 09:21:41 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayListBuilder);
|
2010-07-19 18:29:25 -07:00
|
|
|
PL_InitArenaPool(&mPool, "displayListArena", 1024,
|
|
|
|
NS_MAX(NS_ALIGNMENT_OF(void*),NS_ALIGNMENT_OF(double))-1);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-03-30 14:11:41 -07:00
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPresShell *shell = pc->PresShell();
|
|
|
|
if (pc->IsRenderingOnlySelection()) {
|
|
|
|
nsCOMPtr<nsISelectionController> selcon(do_QueryInterface(shell));
|
|
|
|
if (selcon) {
|
|
|
|
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(mBoundingSelection));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:35:16 -07:00
|
|
|
if(mReferenceFrame->GetType() == nsGkAtoms::viewportFrame) {
|
|
|
|
ViewportFrame* viewportFrame = static_cast<ViewportFrame*>(mReferenceFrame);
|
2011-08-24 13:54:30 -07:00
|
|
|
if (!viewportFrame->GetChildList(nsIFrame::kFixedList).IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasFixedItems = true;
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 02:54:41 -08:00
|
|
|
nsCSSRendering::BeginFrameTreesLocked();
|
2010-07-15 14:08:10 -07:00
|
|
|
PR_STATIC_ASSERT(nsDisplayItem::TYPE_MAX < (1 << nsDisplayItem::TYPE_BITS));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MarkFrameForDisplay(nsIFrame* aFrame, nsIFrame* aStopAtFrame) {
|
|
|
|
for (nsIFrame* f = aFrame; f;
|
2012-06-08 05:22:25 -07:00
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(f)) {
|
2007-03-22 10:30:00 -07: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-09-28 23:19:26 -07:00
|
|
|
static bool IsFixedFrame(nsIFrame* aFrame)
|
2011-04-08 09:35:16 -07:00
|
|
|
{
|
|
|
|
return aFrame && aFrame->GetParent() && !aFrame->GetParent()->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-09-13 03:34:34 -07:00
|
|
|
bool
|
|
|
|
nsDisplayListBuilder::IsFixedItem(nsDisplayItem *aItem,
|
2012-09-12 17:32:53 -07:00
|
|
|
const nsIFrame** aActiveScrolledRoot,
|
|
|
|
const nsIFrame* aOverrideActiveScrolledRoot)
|
2011-04-08 09:35:16 -07:00
|
|
|
{
|
2012-09-12 17:32:53 -07:00
|
|
|
const nsIFrame* activeScrolledRoot = aOverrideActiveScrolledRoot;
|
2012-09-13 03:34:34 -07:00
|
|
|
if (!activeScrolledRoot) {
|
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_SCROLL_LAYER) {
|
|
|
|
nsDisplayScrollLayer* scrollLayerItem =
|
|
|
|
static_cast<nsDisplayScrollLayer*>(aItem);
|
|
|
|
activeScrolledRoot =
|
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(scrollLayerItem->GetScrolledFrame(),
|
2012-09-16 03:32:59 -07:00
|
|
|
FindReferenceFrameFor(scrollLayerItem->GetScrolledFrame()));
|
2012-09-13 03:34:34 -07:00
|
|
|
} else {
|
|
|
|
activeScrolledRoot = nsLayoutUtils::GetActiveScrolledRootFor(aItem, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aActiveScrolledRoot) {
|
|
|
|
*aActiveScrolledRoot = activeScrolledRoot;
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:35:16 -07:00
|
|
|
return activeScrolledRoot &&
|
2012-09-13 03:34:34 -07:00
|
|
|
!nsLayoutUtils::IsScrolledByRootContentDocumentDisplayportScrolling(activeScrolledRoot, this);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ForceVisiblityForFixedItem(nsDisplayListBuilder* aBuilder,
|
2011-11-09 14:47:23 -08:00
|
|
|
nsDisplayItem* aItem)
|
2011-04-08 09:35:16 -07:00
|
|
|
{
|
2011-05-09 01:40:09 -07:00
|
|
|
return aBuilder->GetDisplayPort() && aBuilder->GetHasFixedItems() &&
|
2012-09-13 03:34:34 -07:00
|
|
|
aBuilder->IsFixedItem(aItem);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
|
|
|
|
2011-05-13 06:21:59 -07:00
|
|
|
void nsDisplayListBuilder::SetDisplayPort(const nsRect& aDisplayPort)
|
|
|
|
{
|
|
|
|
static bool fixedPositionLayersEnabled = getenv("MOZ_ENABLE_FIXED_POSITION_LAYERS") != 0;
|
|
|
|
if (fixedPositionLayersEnabled) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasDisplayPort = true;
|
2011-05-13 06:21:59 -07:00
|
|
|
mDisplayPort = aDisplayPort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 09:35:16 -07:00
|
|
|
void nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay(nsIFrame* aDirtyFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect dirty = aDirtyRect - aFrame->GetOffsetTo(aDirtyFrame);
|
2010-10-06 21:25:47 -07:00
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRect();
|
2011-04-08 09:35:16 -07:00
|
|
|
|
|
|
|
if (mHasDisplayPort && IsFixedFrame(aFrame)) {
|
|
|
|
dirty = overflowRect;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!dirty.IntersectRect(dirty, overflowRect))
|
|
|
|
return;
|
2010-03-28 18:46:55 -07:00
|
|
|
aFrame->Properties().Set(nsDisplayListBuilder::OutOfFlowDirtyRectProperty(),
|
|
|
|
new nsRect(dirty));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
MarkFrameForDisplay(aFrame, aDirtyFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnmarkFrameForDisplay(nsIFrame* aFrame) {
|
2010-03-28 18:46:55 -07:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
presContext->PropertyTable()->
|
|
|
|
Delete(aFrame, nsDisplayListBuilder::OutOfFlowDirtyRectProperty());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
for (nsIFrame* f = aFrame; f;
|
2012-06-08 05:22:25 -07:00
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(f)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!(f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO))
|
|
|
|
return;
|
|
|
|
f->RemoveStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
static void RecordFrameMetrics(nsIFrame* aForFrame,
|
2011-05-01 18:53:01 -07:00
|
|
|
nsIFrame* aScrollFrame,
|
2011-01-13 09:45:14 -08:00
|
|
|
ContainerLayer* aRoot,
|
2011-06-22 05:11:28 -07:00
|
|
|
const nsRect& aVisibleRect,
|
|
|
|
const nsRect& aViewport,
|
2011-03-09 13:35:27 -08:00
|
|
|
nsRect* aDisplayPort,
|
2012-11-21 14:34:18 -08:00
|
|
|
nsRect* aCriticalDisplayPort,
|
2011-06-22 05:11:28 -07:00
|
|
|
ViewID aScrollId,
|
2012-08-21 21:37:06 -07:00
|
|
|
const nsDisplayItem::ContainerParameters& aContainerParameters,
|
|
|
|
bool aMayHaveTouchListeners) {
|
2011-01-13 09:45:14 -08:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-09-28 19:16:34 -07:00
|
|
|
float auPerCSSPixel = nsPresContext::AppUnitsPerCSSPixel();
|
2011-01-13 09:45:14 -08:00
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
nsIntRect visible = aVisibleRect.ScaleToNearestPixels(
|
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-13 09:45:14 -08:00
|
|
|
aRoot->SetVisibleRegion(nsIntRegion(visible));
|
|
|
|
|
|
|
|
FrameMetrics metrics;
|
|
|
|
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mViewport = mozilla::gfx::Rect(
|
|
|
|
NSAppUnitsToDoublePixels(aViewport.x, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aViewport.y, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aViewport.width, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aViewport.height, auPerDevPixel));
|
2011-06-22 05:11:28 -07:00
|
|
|
|
2011-03-09 13:35:27 -08:00
|
|
|
if (aDisplayPort) {
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mDisplayPort = mozilla::gfx::Rect(
|
|
|
|
NSAppUnitsToDoublePixels(aDisplayPort->x, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aDisplayPort->y, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aDisplayPort->width, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aDisplayPort->height, auPerDevPixel));
|
2012-11-21 14:34:18 -08:00
|
|
|
|
|
|
|
if (aCriticalDisplayPort) {
|
|
|
|
metrics.mCriticalDisplayPort = mozilla::gfx::Rect(
|
|
|
|
NSAppUnitsToDoublePixels(aCriticalDisplayPort->x, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aCriticalDisplayPort->y, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aCriticalDisplayPort->width, auPerDevPixel),
|
|
|
|
NSAppUnitsToDoublePixels(aCriticalDisplayPort->height, auPerDevPixel));
|
|
|
|
}
|
2011-01-13 09:45:14 -08:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIScrollableFrame* scrollableFrame = nullptr;
|
2011-05-01 18:53:01 -07:00
|
|
|
if (aScrollFrame)
|
|
|
|
scrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
2011-03-15 16:20:19 -07:00
|
|
|
|
|
|
|
if (scrollableFrame) {
|
2012-05-23 07:51:39 -07:00
|
|
|
nsRect contentBounds = scrollableFrame->GetScrollRange();
|
|
|
|
contentBounds.width += scrollableFrame->GetScrollPortRect().width;
|
|
|
|
contentBounds.height += scrollableFrame->GetScrollPortRect().height;
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mScrollableRect =
|
2012-07-31 10:28:21 -07:00
|
|
|
mozilla::gfx::Rect(nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.x),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.y),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.width),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.height));
|
2012-05-23 07:51:39 -07:00
|
|
|
metrics.mContentRect = contentBounds.ScaleToNearestPixels(
|
2011-06-22 05:11:28 -07:00
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2012-08-21 21:37:15 -07:00
|
|
|
nsPoint scrollPosition = scrollableFrame->GetScrollPosition();
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mScrollOffset = mozilla::gfx::Point(
|
|
|
|
NSAppUnitsToDoublePixels(scrollPosition.x, auPerCSSPixel),
|
|
|
|
NSAppUnitsToDoublePixels(scrollPosition.y, auPerCSSPixel));
|
2011-01-19 08:56:22 -08:00
|
|
|
}
|
|
|
|
else {
|
2012-05-23 07:51:39 -07:00
|
|
|
nsRect contentBounds = aForFrame->GetRect();
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mScrollableRect =
|
2012-07-31 10:28:21 -07:00
|
|
|
mozilla::gfx::Rect(nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.x),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.y),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.width),
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(contentBounds.height));
|
2012-05-23 07:51:39 -07:00
|
|
|
metrics.mContentRect = contentBounds.ScaleToNearestPixels(
|
2011-06-22 05:11:28 -07:00
|
|
|
aContainerParameters.mXScale, aContainerParameters.mYScale, auPerDevPixel);
|
2011-01-13 09:45:14 -08:00
|
|
|
}
|
|
|
|
|
2011-01-19 08:56:22 -08:00
|
|
|
metrics.mScrollId = aScrollId;
|
2012-04-24 19:48:33 -07:00
|
|
|
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
metrics.mResolution = gfxSize(presShell->GetXResolution(), presShell->GetYResolution());
|
|
|
|
|
2012-09-28 19:16:34 -07:00
|
|
|
metrics.mDevPixelsPerCSSPixel = auPerCSSPixel / auPerDevPixel;
|
|
|
|
|
2012-08-21 21:37:06 -07:00
|
|
|
metrics.mMayHaveTouchListeners = aMayHaveTouchListeners;
|
|
|
|
|
2012-10-11 22:46:24 -07:00
|
|
|
if (nsIWidget* widget = aForFrame->GetNearestWidget()) {
|
|
|
|
widget->GetBounds(metrics.mCompositionBounds);
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
aRoot->SetFrameMetrics(metrics);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayListBuilder::~nsDisplayListBuilder() {
|
2008-01-03 17:53:01 -08: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 04:34:14 -07:00
|
|
|
NS_ASSERTION(!mCurrentTableItem, "No table item should be active");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-19 02:54:41 -08:00
|
|
|
nsCSSRendering::EndFrameTreesLocked();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PL_FinishArenaPool(&mPool);
|
2010-06-21 09:21:41 -07:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayListBuilder);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2009-09-12 15:44:18 -07:00
|
|
|
nsDisplayListBuilder::GetBackgroundPaintFlags() {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = 0;
|
2009-09-12 15:44:18 -07:00
|
|
|
if (mSyncDecodeImages) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES;
|
|
|
|
}
|
2010-10-25 07:38:09 -07:00
|
|
|
if (mIsPaintingToWindow) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_TO_WINDOW;
|
|
|
|
}
|
2009-09-12 15:44:18 -07:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint64_t RegionArea(const nsRegion& aRegion)
|
2011-01-04 00:43:47 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t area = 0;
|
2011-01-04 00:43:47 -08:00
|
|
|
nsRegionRectIterator iter(aRegion);
|
|
|
|
const nsRect* r;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((r = iter.Next()) != nullptr) {
|
2012-08-22 08:56:38 -07:00
|
|
|
area += uint64_t(r->width)*r->height;
|
2011-01-04 00:43:47 -08:00
|
|
|
}
|
|
|
|
return area;
|
|
|
|
}
|
|
|
|
|
2009-08-13 19:09:51 -07:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRegion& aRegion)
|
2009-08-13 19:09:51 -07:00
|
|
|
{
|
2011-01-02 17:48:09 -08:00
|
|
|
if (aRegion.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2009-09-19 05:12:48 -07: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 00:43:47 -08:00
|
|
|
// Do let aVisibleRegion get more complex if by doing so we reduce its
|
|
|
|
// area by at least half.
|
2011-05-13 09:40:46 -07:00
|
|
|
if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15 ||
|
2011-01-04 00:43:47 -08:00
|
|
|
RegionArea(tmp) <= RegionArea(*aVisibleRegion)/2) {
|
2009-09-19 05:12:48 -07:00
|
|
|
*aVisibleRegion = tmp;
|
2009-08-13 19:09:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
nsCaret *
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayListBuilder::GetCaret() {
|
2010-03-28 16:21:11 -07:00
|
|
|
nsRefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
|
2007-03-22 10:30:00 -07:00
|
|
|
return caret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-03 17:53:01 -08:00
|
|
|
PresShellState* state = mPresShellStates.AppendElement();
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
state->mPresShell = aReferenceFrame->PresContext()->PresShell();
|
2012-07-30 07:20:58 -07:00
|
|
|
state->mCaretFrame = nullptr;
|
2008-01-03 17:53:01 -08:00
|
|
|
state->mFirstFrameMarkedForDisplay = mFramesMarkedForDisplay.Length();
|
|
|
|
|
2009-04-25 01:19:23 -07:00
|
|
|
state->mPresShell->UpdateCanvasBackground();
|
|
|
|
|
2010-05-12 17:56:08 -07:00
|
|
|
if (mIsPaintingToWindow) {
|
2011-01-27 13:53:10 -08:00
|
|
|
mReferenceFrame->AddPaintedPresShell(state->mPresShell);
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2010-05-12 17:56:08 -07:00
|
|
|
state->mPresShell->IncrementPaintCount();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool buildCaret = mBuildCaret;
|
2010-09-01 13:44:48 -07:00
|
|
|
if (mIgnoreSuppression || !state->mPresShell->IsPaintingSuppressed()) {
|
|
|
|
if (state->mPresShell->IsPaintingSuppressed()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHadToIgnoreSuppression = true;
|
2010-09-01 13:44:48 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
state->mIsBackgroundOnly = false;
|
2010-09-01 13:44:48 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
state->mIsBackgroundOnly = true;
|
|
|
|
buildCaret = false;
|
2010-09-01 13:44:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!buildCaret)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2010-03-28 16:21:11 -07:00
|
|
|
nsRefPtr<nsCaret> caret = state->mPresShell->GetCaret();
|
2008-01-03 17:53:01 -08:00
|
|
|
state->mCaretFrame = caret->GetCaretFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-03 17:53:01 -08:00
|
|
|
if (state->mCaretFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check if the dirty rect intersects with the caret's dirty rect.
|
|
|
|
nsRect caretRect =
|
2008-01-03 17:53:01 -08:00
|
|
|
caret->GetCaretRect() + state->mCaretFrame->GetOffsetTo(aReferenceFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (caretRect.Intersects(aDirtyRect)) {
|
|
|
|
// Okay, our rects intersect, let's mark the frame and all of its ancestors.
|
2008-01-03 17:53:01 -08:00
|
|
|
mFramesMarkedForDisplay.AppendElement(state->mCaretFrame);
|
2012-07-30 07:20:58 -07:00
|
|
|
MarkFrameForDisplay(state->mCaretFrame, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::LeavePresShell(nsIFrame* aReferenceFrame,
|
2009-04-25 01:19:23 -07:00
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-03 17:53:01 -08:00
|
|
|
if (CurrentPresShellState()->mPresShell != aReferenceFrame->PresContext()->PresShell()) {
|
|
|
|
// Must have not allocated a state for this presshell, presumably due
|
|
|
|
// to OOM.
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2008-01-03 17:53:01 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-03 17:53:01 -08:00
|
|
|
// Unmark and pop off the frames marked for display in this pres shell.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t firstFrameForShell = CurrentPresShellState()->mFirstFrameMarkedForDisplay;
|
|
|
|
for (uint32_t i = firstFrameForShell;
|
2008-01-03 17:53:01 -08:00
|
|
|
i < mFramesMarkedForDisplay.Length(); ++i) {
|
|
|
|
UnmarkFrameForDisplay(mFramesMarkedForDisplay[i]);
|
|
|
|
}
|
|
|
|
mFramesMarkedForDisplay.SetLength(firstFrameForShell);
|
|
|
|
mPresShellStates.SetLength(mPresShellStates.Length() - 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-28 05:51:09 -07:00
|
|
|
nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame,
|
|
|
|
const nsFrameList& aFrames,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsRect& aDirtyRect) {
|
2009-07-28 05:51:09 -07:00
|
|
|
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(e.get());
|
|
|
|
MarkOutOfFlowFrameForDisplay(aDirtyFrame, e.get(), aDirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-11 00:49:14 -07:00
|
|
|
void
|
2012-07-31 10:28:21 -07:00
|
|
|
nsDisplayListBuilder::MarkPreserve3DFramesForDisplayList(nsIFrame* aDirtyFrame, const nsRect& aDirtyRect)
|
2012-05-11 00:49:14 -07:00
|
|
|
{
|
|
|
|
nsAutoTArray<nsIFrame::ChildList,4> childListArray;
|
|
|
|
aDirtyFrame->GetChildLists(&childListArray);
|
|
|
|
nsIFrame::ChildListArrayIterator lists(childListArray);
|
|
|
|
for (; !lists.IsDone(); lists.Next()) {
|
|
|
|
nsFrameList::Enumerator childFrames(lists.CurrentList());
|
|
|
|
for (; !childFrames.AtEnd(); childFrames.Next()) {
|
|
|
|
nsIFrame *child = childFrames.get();
|
|
|
|
if (child->Preserves3D()) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(child);
|
|
|
|
nsRect dirty = aDirtyRect - child->GetOffsetTo(aDirtyFrame);
|
|
|
|
|
|
|
|
child->Properties().Set(nsDisplayListBuilder::Preserve3DDirtyRectProperty(),
|
|
|
|
new nsRect(dirty));
|
|
|
|
|
|
|
|
MarkFrameForDisplay(child, aDirtyFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void*
|
|
|
|
nsDisplayListBuilder::Allocate(size_t aSize) {
|
|
|
|
void *tmp;
|
|
|
|
PL_ARENA_ALLOCATE(tmp, &mPool, aSize);
|
2012-11-07 11:55:53 -08:00
|
|
|
if (!tmp) {
|
|
|
|
NS_RUNTIMEABORT("out of memory");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
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 12:31:39 -08:00
|
|
|
nsDisplayList::FlattenTo(nsTArray<nsDisplayItem*>* aElements) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayItem* item;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((item = RemoveBottom()) != nullptr) {
|
2010-07-15 14:07:49 -07:00
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_WRAP_LIST) {
|
2012-11-02 05:59:03 -07:00
|
|
|
item->GetSameCoordinateSystemChildren()->FlattenTo(aElements);
|
2007-03-22 10:30:00 -07:00
|
|
|
item->~nsDisplayItem();
|
|
|
|
} else {
|
|
|
|
aElements->AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-10 17:24:16 -07:00
|
|
|
nsRect
|
|
|
|
nsDisplayList::GetBounds(nsDisplayListBuilder* aBuilder) const {
|
|
|
|
nsRect bounds;
|
2012-07-30 07:20:58 -07:00
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nullptr; i = i->GetAbove()) {
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
bounds.UnionRect(bounds, i->GetBounds(aBuilder, &snap));
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-27 16:15:08 -07:00
|
|
|
nsDisplayList::ComputeVisibilityForRoot(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsDisplayList", "ComputeVisibilityForRoot");
|
2010-08-27 16:15:08 -07:00
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2012-10-24 22:32:25 -07:00
|
|
|
return ComputeVisibilityForSublist(aBuilder, nullptr, aVisibleRegion, r.GetBounds(), r.GetBounds());
|
2010-08-27 16:15:08 -07:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
static nsRegion
|
2012-05-02 21:29:05 -07:00
|
|
|
TreatAsOpaque(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder)
|
2010-11-08 01:06:14 -08:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
2012-05-02 21:29:05 -07:00
|
|
|
nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, &snap);
|
2010-11-08 01:06:14 -08:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
2012-11-02 05:59:03 -07:00
|
|
|
// Treat all leaf chrome items as opaque, unless their frames are opacity:0.
|
2011-05-22 17:28:47 -07:00
|
|
|
// 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.
|
2012-11-02 05:59:03 -07:00
|
|
|
// We treat leaf chrome items as opaque to ensure that they cover
|
|
|
|
// content plugins, for security reasons.
|
|
|
|
// Non-leaf chrome items don't render contents of their own so shouldn't
|
|
|
|
// be treated as opaque (and their bounds is just the union of their
|
|
|
|
// children, which might be a large area their contents don't really cover).
|
2010-11-08 01:06:14 -08:00
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
2012-11-02 05:59:03 -07:00
|
|
|
if (f && f->PresContext()->IsChrome() && !aItem->GetChildren() &&
|
|
|
|
f->GetStyleDisplay()->mOpacity != 0.0) {
|
2012-04-10 04:24:18 -07:00
|
|
|
opaque = aItem->GetBounds(aBuilder, &snap);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2010-11-08 01:06:14 -08:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
return opaque;
|
2010-11-08 01:06:14 -08:00
|
|
|
}
|
|
|
|
|
2011-11-09 14:47:23 -08:00
|
|
|
static nsRect
|
|
|
|
GetDisplayPortBounds(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
2011-05-09 01:40:09 -07:00
|
|
|
{
|
2011-11-09 14:47:23 -08:00
|
|
|
// GetDisplayPortBounds() rectangle is used in order to restrict fixed aItem's
|
|
|
|
// visible bounds. nsDisplayTransform bounds already take item's
|
|
|
|
// transform into account, so there is no need to apply it here one more time.
|
|
|
|
// Start TransformRectToBoundsInAncestor() calculations from aItem's frame
|
|
|
|
// parent in this case.
|
2011-05-09 01:40:09 -07:00
|
|
|
nsIFrame* frame = aItem->GetUnderlyingFrame();
|
2011-11-09 14:47:23 -08:00
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_TRANSFORM) {
|
|
|
|
frame = nsLayoutUtils::GetCrossDocParentFrame(frame);
|
2011-05-09 01:40:09 -07:00
|
|
|
}
|
|
|
|
|
2011-11-09 14:47:23 -08:00
|
|
|
const nsRect* displayport = aBuilder->GetDisplayPort();
|
2011-12-27 19:24:18 -08:00
|
|
|
nsRect result = nsLayoutUtils::TransformAncestorRectToFrame(
|
2011-11-09 14:47:23 -08:00
|
|
|
frame,
|
|
|
|
nsRect(0, 0, displayport->width, displayport->height),
|
2012-09-16 03:32:59 -07:00
|
|
|
aBuilder->FindReferenceFrameFor(frame));
|
2011-11-09 14:47:23 -08:00
|
|
|
result.MoveBy(aBuilder->ToReferenceFrame(frame));
|
|
|
|
return result;
|
2011-05-09 01:40:09 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-27 16:15:08 -07:00
|
|
|
nsDisplayList::ComputeVisibilityForSublist(nsDisplayListBuilder* aBuilder,
|
2012-10-24 22:32:25 -07:00
|
|
|
nsDisplayItem* aForItem,
|
2010-08-27 16:15:08 -07:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-01-27 14:58:50 -08:00
|
|
|
const nsRect& aListVisibleBounds,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
2010-08-27 16:15:08 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2011-04-18 20:07:23 -07:00
|
|
|
NS_ASSERTION(r.GetBounds().IsEqualInterior(aListVisibleBounds),
|
2010-08-27 16:15:08 -07:00
|
|
|
"bad aListVisibleBounds");
|
|
|
|
#endif
|
|
|
|
mVisibleRect = aListVisibleBounds;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool anyVisible = false;
|
2010-03-10 12:55:05 -08:00
|
|
|
|
2007-11-11 12:31:39 -08:00
|
|
|
nsAutoTArray<nsDisplayItem*, 512> elements;
|
2007-03-22 10:30:00 -07:00
|
|
|
FlattenTo(&elements);
|
2007-11-11 12:31:39 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool forceTransparentSurface = false;
|
2010-10-19 10:02:25 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = elements.Length() - 1; i >= 0; --i) {
|
2007-11-11 12:31:39 -08:00
|
|
|
nsDisplayItem* item = elements[i];
|
2012-07-30 07:20:58 -07:00
|
|
|
nsDisplayItem* belowItem = i < 1 ? nullptr : elements[i - 1];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
NS_ASSERTION(!aForItem ||
|
|
|
|
item->GetType() != nsDisplayItem::TYPE_TRANSFORM ||
|
|
|
|
item->GetUnderlyingFrame() != aForItem->GetUnderlyingFrame() ||
|
|
|
|
aForItem->ReferenceFrame() != aForItem->GetUnderlyingFrame(),
|
|
|
|
"If we have an nsDisplayTransform child (for the same frame),"
|
|
|
|
"then we shouldn't be our own reference frame!");
|
|
|
|
|
2012-11-02 05:59:03 -07:00
|
|
|
nsDisplayList* list = item->GetSameCoordinateSystemChildren();
|
2012-10-06 06:03:23 -07:00
|
|
|
if (aBuilder->AllowMergingAndFlattening()) {
|
|
|
|
if (belowItem && item->TryMerge(aBuilder, belowItem)) {
|
|
|
|
belowItem->~nsDisplayItem();
|
|
|
|
elements.ReplaceElementsAt(i - 1, 1, item);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRect bounds = item->GetBounds(aBuilder, &snap);
|
2009-09-06 17:35:14 -07:00
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2011-11-09 14:47:23 -08:00
|
|
|
if (ForceVisiblityForFixedItem(aBuilder, item)) {
|
|
|
|
itemVisible.And(GetDisplayPortBounds(aBuilder, item), bounds);
|
2011-05-09 01:40:09 -07:00
|
|
|
} else {
|
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
2011-05-09 01:40:09 -07:00
|
|
|
item->mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 09:35:16 -07:00
|
|
|
|
2011-05-13 09:40:46 -07:00
|
|
|
if (item->ComputeVisibility(aBuilder, aVisibleRegion, aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
anyVisible = true;
|
2012-05-02 21:29:05 -07:00
|
|
|
nsRegion opaque = TreatAsOpaque(item, aBuilder);
|
2011-01-02 17:48:09 -08:00
|
|
|
// Subtract opaque item from the visible region
|
2011-05-13 09:40:46 -07:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2012-05-02 21:29:05 -07:00
|
|
|
if (aBuilder->NeedToForceTransparentSurfaceForItem(item) ||
|
|
|
|
(list && list->NeedsTransparentSurface())) {
|
|
|
|
forceTransparentSurface = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-15 14:08:09 -07:00
|
|
|
AppendToBottom(item);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-08-13 19:09:51 -07:00
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
mIsOpaque = !aVisibleRegion->Intersects(mVisibleRect);
|
2010-10-19 10:02:25 -07:00
|
|
|
mForceTransparentSurface = forceTransparentSurface;
|
2009-09-06 17:35:14 -07:00
|
|
|
#ifdef DEBUG
|
2011-10-17 07:59:28 -07:00
|
|
|
mDidComputeVisibility = true;
|
2009-09-06 17:35:14 -07:00
|
|
|
#endif
|
2010-07-15 14:08:09 -07:00
|
|
|
return anyVisible;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-03-10 12:55:05 -08:00
|
|
|
void nsDisplayList::PaintRoot(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags) const {
|
2012-04-16 11:37:59 -07:00
|
|
|
SAMPLE_LABEL("nsDisplayList", "PaintRoot");
|
2012-09-16 03:32:59 -07:00
|
|
|
PaintForFrame(aBuilder, aCtx, aBuilder->RootReferenceFrame(), aFlags);
|
2010-03-10 12:55:05 -08:00
|
|
|
}
|
|
|
|
|
2010-02-28 23:56:19 -08: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 12:55:05 -08:00
|
|
|
void nsDisplayList::PaintForFrame(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx,
|
2010-03-10 12:55:05 -08:00
|
|
|
nsIFrame* aForFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags) const {
|
2009-09-06 17:35:14 -07:00
|
|
|
NS_ASSERTION(mDidComputeVisibility,
|
|
|
|
"Must call ComputeVisibility before calling Paint");
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
nsRefPtr<LayerManager> layerManager;
|
2012-08-28 22:48:41 -07:00
|
|
|
bool widgetTransaction = false;
|
2011-01-19 00:27:54 -08:00
|
|
|
bool allowRetaining = false;
|
|
|
|
bool doBeginTransaction = true;
|
2012-08-28 22:47:18 -07:00
|
|
|
nsIView *view = nullptr;
|
2010-03-01 00:03:49 -08:00
|
|
|
if (aFlags & PAINT_USE_WIDGET_LAYERS) {
|
2012-09-16 03:32:59 -07:00
|
|
|
nsIFrame* rootReferenceFrame = aBuilder->RootReferenceFrame();
|
2012-08-28 22:47:18 -07:00
|
|
|
view = rootReferenceFrame->GetView();
|
2012-09-16 03:32:59 -07:00
|
|
|
NS_ASSERTION(rootReferenceFrame == nsLayoutUtils::GetDisplayRootFrame(rootReferenceFrame),
|
2010-03-01 00:03:49 -08:00
|
|
|
"Reference frame must be a display root for us to use the layer manager");
|
2012-09-16 03:32:59 -07:00
|
|
|
nsIWidget* window = rootReferenceFrame->GetNearestWidget();
|
2010-03-01 00:03:49 -08:00
|
|
|
if (window) {
|
2010-10-15 03:34:29 -07:00
|
|
|
layerManager = window->GetLayerManager(&allowRetaining);
|
2011-01-19 00:27:54 -08:00
|
|
|
if (layerManager) {
|
|
|
|
doBeginTransaction = !(aFlags & PAINT_EXISTING_TRANSACTION);
|
2012-08-28 22:48:41 -07:00
|
|
|
widgetTransaction = true;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!layerManager) {
|
|
|
|
if (!aCtx) {
|
|
|
|
NS_WARNING("Nowhere to paint into");
|
|
|
|
return;
|
|
|
|
}
|
2010-07-15 14:08:10 -07:00
|
|
|
layerManager = new BasicLayerManager();
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
|
2012-10-23 04:01:23 -07:00
|
|
|
// Store the existing layer builder to reinstate it on return.
|
|
|
|
FrameLayerBuilder *oldBuilder = layerManager->GetLayerBuilder();
|
|
|
|
|
2012-07-17 10:03:51 -07:00
|
|
|
FrameLayerBuilder *layerBuilder = new FrameLayerBuilder();
|
2012-08-20 21:06:46 -07:00
|
|
|
layerBuilder->Init(aBuilder, layerManager);
|
2012-07-17 10:03:51 -07:00
|
|
|
|
2010-07-15 14:07:52 -07:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
2011-01-19 00:27:54 -08:00
|
|
|
if (doBeginTransaction) {
|
|
|
|
if (aCtx) {
|
|
|
|
layerManager->BeginTransactionWithTarget(aCtx->ThebesContext());
|
|
|
|
} else {
|
|
|
|
layerManager->BeginTransaction();
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 16:38:24 -07:00
|
|
|
if (widgetTransaction) {
|
2012-07-17 10:03:51 -07:00
|
|
|
layerBuilder->DidBeginRetainedLayerTransaction(layerManager);
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2010-02-28 23:56:19 -08:00
|
|
|
|
2011-06-22 05:11:27 -07:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
|
2012-08-28 22:47:18 -07:00
|
|
|
NotifySubDocInvalidationFunc computeInvalidFunc =
|
|
|
|
presContext->MayHavePaintEventListenerInSubDocument() ? nsPresContext::NotifySubDocInvalidation : 0;
|
|
|
|
bool computeInvalidRect = (computeInvalidFunc ||
|
2012-10-11 16:55:42 -07:00
|
|
|
!layerManager->IsCompositingCheap()) &&
|
2012-08-28 22:47:18 -07:00
|
|
|
widgetTransaction;
|
|
|
|
|
|
|
|
nsAutoPtr<LayerProperties> props(computeInvalidRect ?
|
|
|
|
LayerProperties::CloneFrom(layerManager->GetRoot()) :
|
|
|
|
nullptr);
|
|
|
|
|
2011-06-22 05:11:27 -07:00
|
|
|
nsDisplayItem::ContainerParameters containerParameters
|
|
|
|
(presShell->GetXResolution(), presShell->GetYResolution());
|
2012-07-17 10:03:51 -07:00
|
|
|
nsRefPtr<ContainerLayer> root = layerBuilder->
|
2012-07-30 07:20:58 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, layerManager, aForFrame, nullptr, *this,
|
|
|
|
containerParameters, nullptr);
|
2012-10-23 04:01:23 -07:00
|
|
|
|
2012-08-28 22:47:18 -07:00
|
|
|
if (widgetTransaction) {
|
|
|
|
aForFrame->ClearInvalidationStateBits();
|
|
|
|
}
|
2012-07-17 10:03:51 -07:00
|
|
|
|
|
|
|
if (!root) {
|
2012-10-23 04:01:23 -07:00
|
|
|
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);
|
2010-02-28 23:56:19 -08:00
|
|
|
return;
|
2012-07-17 10:03:51 -07:00
|
|
|
}
|
2011-06-22 05:11:27 -07:00
|
|
|
// Root is being scaled up by the X/Y resolution. Scale it back down.
|
2012-08-03 14:29:22 -07:00
|
|
|
root->SetPostScale(1.0f/containerParameters.mXScale,
|
|
|
|
1.0f/containerParameters.mYScale);
|
2010-09-03 13:10:46 -07:00
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
ViewID id = presContext->IsRootContentDocument() ? FrameMetrics::ROOT_SCROLL_ID
|
|
|
|
: FrameMetrics::NULL_SCROLL_ID;
|
2010-09-03 13:10:46 -07:00
|
|
|
|
2011-03-15 16:20:19 -07:00
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
2012-11-21 14:34:18 -08:00
|
|
|
nsRect displayport, criticalDisplayport;
|
2011-03-09 13:35:27 -08:00
|
|
|
bool usingDisplayport = false;
|
2012-11-21 14:34:18 -08:00
|
|
|
bool usingCriticalDisplayport = false;
|
2011-03-15 16:20:19 -07:00
|
|
|
if (rootScrollFrame) {
|
|
|
|
nsIContent* content = rootScrollFrame->GetContent();
|
|
|
|
if (content) {
|
2011-03-09 13:35:27 -08:00
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
2012-11-21 14:34:18 -08:00
|
|
|
usingCriticalDisplayport =
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(content, &criticalDisplayport);
|
2011-03-15 16:20:19 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-21 21:37:06 -07:00
|
|
|
|
|
|
|
bool mayHaveTouchListeners = false;
|
|
|
|
if (presShell) {
|
|
|
|
nsIDocument* document = presShell->GetDocument();
|
|
|
|
if (document) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> innerWin(document->GetInnerWindow());
|
|
|
|
if (innerWin) {
|
|
|
|
mayHaveTouchListeners = innerWin->HasTouchEventListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 19:16:34 -07:00
|
|
|
nsRect viewport(aBuilder->ToReferenceFrame(aForFrame), aForFrame->GetSize());
|
|
|
|
|
2011-03-09 13:35:27 -08:00
|
|
|
RecordFrameMetrics(aForFrame, rootScrollFrame,
|
2012-09-28 19:16:34 -07:00
|
|
|
root, mVisibleRect, viewport,
|
2012-11-21 14:34:18 -08:00
|
|
|
(usingDisplayport ? &displayport : nullptr),
|
|
|
|
(usingCriticalDisplayport ? &criticalDisplayport : nullptr),
|
|
|
|
id, containerParameters, mayHaveTouchListeners);
|
2011-10-23 01:57:47 -07:00
|
|
|
if (usingDisplayport &&
|
|
|
|
!(root->GetContentFlags() & Layer::CONTENT_OPAQUE)) {
|
|
|
|
// See bug 693938, attachment 567017
|
|
|
|
NS_WARNING("We don't support transparent content with displayports, force it to be opqaue");
|
|
|
|
root->SetContentFlags(Layer::CONTENT_OPAQUE);
|
|
|
|
}
|
2010-09-03 13:10:46 -07:00
|
|
|
|
2010-02-28 23:56:19 -08:00
|
|
|
layerManager->SetRoot(root);
|
2012-08-28 22:47:15 -07:00
|
|
|
layerBuilder->WillEndTransaction();
|
2012-07-22 20:00:36 -07:00
|
|
|
bool temp = aBuilder->SetIsCompositingCheap(layerManager->IsCompositingCheap());
|
2010-05-20 20:20:48 -07:00
|
|
|
layerManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer,
|
2012-08-13 03:10:10 -07:00
|
|
|
aBuilder, (aFlags & PAINT_NO_COMPOSITE) ? LayerManager::END_NO_COMPOSITE : LayerManager::END_DEFAULT);
|
2012-07-22 20:00:36 -07:00
|
|
|
aBuilder->SetIsCompositingCheap(temp);
|
2012-08-28 22:47:15 -07:00
|
|
|
layerBuilder->DidEndTransaction();
|
2010-02-28 23:56:19 -08:00
|
|
|
|
2012-11-12 10:31:15 -08:00
|
|
|
nsIntRegion invalid;
|
2012-08-28 22:47:18 -07:00
|
|
|
if (props) {
|
|
|
|
invalid = props->ComputeDifferences(root, computeInvalidFunc);
|
2012-08-28 22:48:43 -07:00
|
|
|
} else if (widgetTransaction) {
|
|
|
|
LayerProperties::ClearInvalidations(root);
|
2012-08-28 22:47:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (view) {
|
|
|
|
if (props) {
|
|
|
|
if (!invalid.IsEmpty()) {
|
2012-11-12 10:31:15 -08:00
|
|
|
nsIntRect bounds = invalid.GetBounds();
|
|
|
|
nsRect rect(presContext->DevPixelsToAppUnits(bounds.x),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.y),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.width),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.height));
|
2012-08-28 22:47:18 -07:00
|
|
|
view->GetViewManager()->InvalidateViewNoSuppression(view, rect);
|
2012-11-12 10:31:15 -08:00
|
|
|
presContext->NotifyInvalidation(bounds, 0);
|
2012-08-28 22:47:18 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
view->GetViewManager()->InvalidateView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:52 -07:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
2012-10-23 04:01:23 -07:00
|
|
|
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsDisplayList::Count() const {
|
|
|
|
uint32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsDisplayItem* i = GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem* nsDisplayList::RemoveBottom() {
|
|
|
|
nsDisplayItem* item = mSentinel.mAbove;
|
|
|
|
if (!item)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mSentinel.mAbove = item->mAbove;
|
|
|
|
if (item == mTop) {
|
|
|
|
// must have been the only item
|
|
|
|
mTop = &mSentinel;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
item->mAbove = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::DeleteAll() {
|
|
|
|
nsDisplayItem* item;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((item = RemoveBottom()) != nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
item->~nsDisplayItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-11-30 06:59:46 -08:00
|
|
|
GetMouseThrough(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame->IsBoxFrame())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-30 06:59:46 -08:00
|
|
|
|
|
|
|
const nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_ALWAYS) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-11-30 06:59:46 -08:00
|
|
|
} else if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_NEVER) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-30 06:59:46 -08:00
|
|
|
}
|
|
|
|
frame = frame->GetParentBox();
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-11-30 06:59:46 -08:00
|
|
|
}
|
|
|
|
|
2011-10-06 14:24:02 -07:00
|
|
|
// A list of frames, and their z depth. Used for sorting
|
|
|
|
// the results of hit testing.
|
|
|
|
struct FramesWithDepth
|
|
|
|
{
|
|
|
|
FramesWithDepth(float aDepth) :
|
|
|
|
mDepth(aDepth)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool operator<(const FramesWithDepth& aOther) const {
|
|
|
|
if (mDepth != aOther.mDepth) {
|
|
|
|
// We want to sort so that the shallowest item (highest depth value) is first
|
|
|
|
return mDepth > aOther.mDepth;
|
|
|
|
}
|
|
|
|
return this < &aOther;
|
|
|
|
}
|
|
|
|
bool operator==(const FramesWithDepth& aOther) const {
|
|
|
|
return this == &aOther;
|
|
|
|
}
|
|
|
|
|
|
|
|
float mDepth;
|
|
|
|
nsTArray<nsIFrame*> mFrames;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Sort the frames by depth and then moves all the contained frames to the destination
|
|
|
|
void FlushFramesArray(nsTArray<FramesWithDepth>& aSource, nsTArray<nsIFrame*>* aDest)
|
|
|
|
{
|
|
|
|
if (aSource.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aSource.Sort();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = aSource.Length();
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2011-10-06 14:24:02 -07:00
|
|
|
aDest->MoveElementsFrom(aSource[i].mFrames);
|
|
|
|
}
|
|
|
|
aSource.Clear();
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void nsDisplayList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
nsDisplayItem::HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames) const {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t itemBufferStart = aState->mItemBuffer.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayItem* item;
|
|
|
|
for (item = GetBottom(); item; item = item->GetAbove()) {
|
2008-01-03 18:08:29 -08:00
|
|
|
aState->mItemBuffer.AppendElement(item);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-06 14:24:02 -07:00
|
|
|
nsAutoTArray<FramesWithDepth, 16> temp;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = aState->mItemBuffer.Length() - 1; i >= itemBufferStart; --i) {
|
2008-01-03 18:08:29 -08:00
|
|
|
// 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);
|
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
if (aRect.Intersects(item->GetBounds(aBuilder, &snap))) {
|
2011-09-22 20:50:57 -07:00
|
|
|
nsAutoTArray<nsIFrame*, 16> outFrames;
|
2010-04-07 17:31:26 -07:00
|
|
|
item->HitTest(aBuilder, aRect, aState, &outFrames);
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
// For 3d transforms with preserve-3d we add hit frames into the temp list
|
2011-10-06 14:24:02 -07:00
|
|
|
// so we can sort them later, otherwise we add them directly to the output list.
|
|
|
|
nsTArray<nsIFrame*> *writeFrames = aOutFrames;
|
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_TRANSFORM &&
|
|
|
|
item->GetUnderlyingFrame()->Preserves3D()) {
|
2011-10-11 20:16:05 -07:00
|
|
|
if (outFrames.Length()) {
|
|
|
|
nsDisplayTransform *transform = static_cast<nsDisplayTransform*>(item);
|
|
|
|
nsPoint point = aRect.TopLeft();
|
|
|
|
// A 1x1 rect means a point, otherwise use the center of the rect
|
|
|
|
if (aRect.width != 1 || aRect.height != 1) {
|
|
|
|
point = aRect.Center();
|
|
|
|
}
|
|
|
|
temp.AppendElement(FramesWithDepth(transform->GetHitDepthAtPoint(point)));
|
|
|
|
writeFrames = &temp[temp.Length() - 1].mFrames;
|
2011-10-06 14:24:02 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-31 10:28:21 -07:00
|
|
|
// We may have just finished a run of consecutive preserve-3d transforms,
|
2011-10-06 14:24:02 -07:00
|
|
|
// so flush these into the destination array before processing our frame list.
|
|
|
|
FlushFramesArray(temp, aOutFrames);
|
|
|
|
}
|
2010-04-07 17:31:26 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t j = 0; j < outFrames.Length(); j++) {
|
2010-04-07 17:31:26 -07:00
|
|
|
nsIFrame *f = outFrames.ElementAt(j);
|
|
|
|
// Handle the XUL 'mousethrough' feature and 'pointer-events'.
|
2010-11-30 06:59:46 -08:00
|
|
|
if (!GetMouseThrough(f) &&
|
2012-11-02 03:42:59 -07:00
|
|
|
f->GetStyleVisibility()->GetEffectivePointerEvents(f) != NS_STYLE_POINTER_EVENTS_NONE) {
|
2011-10-06 14:24:02 -07:00
|
|
|
writeFrames->AppendElement(f);
|
2008-01-03 18:08:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-06 14:24:02 -07:00
|
|
|
// Clear any remaining preserve-3d transforms.
|
|
|
|
FlushFramesArray(temp, aOutFrames);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_ASSERTION(aState->mItemBuffer.Length() == uint32_t(itemBufferStart),
|
2008-01-03 18:08:29 -08:00
|
|
|
"How did we forget to pop some elements?");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void Sort(nsDisplayList* aList, int32_t aCount, nsDisplayList::SortLEQ aCmp,
|
2007-03-22 10:30:00 -07:00
|
|
|
void* aClosure) {
|
|
|
|
if (aCount < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsDisplayList list1;
|
|
|
|
nsDisplayList list2;
|
|
|
|
int i;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t half = aCount/2;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool sorted = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsDisplayItem* prev = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < aCount; ++i) {
|
|
|
|
nsDisplayItem* item = aList->RemoveBottom();
|
|
|
|
(i < half ? &list1 : &list2)->AppendToTop(item);
|
|
|
|
if (sorted && prev && !aCmp(prev, item, aClosure)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
sorted = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
prev = item;
|
|
|
|
}
|
|
|
|
if (sorted) {
|
|
|
|
aList->AppendToTop(&list1);
|
|
|
|
aList->AppendToTop(&list2);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsContentLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
2007-03-22 10:30:00 -07:00
|
|
|
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 00:08:04 -07:00
|
|
|
static_cast<nsIContent*>(aClosure)) <= 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsZOrderLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
2007-03-22 10:30:00 -07:00
|
|
|
void* aClosure) {
|
|
|
|
// These GetUnderlyingFrame calls return non-null because we're only used
|
2010-04-01 19:09:05 -07: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.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index1 = nsLayoutUtils::GetZIndex(aItem1->GetUnderlyingFrame());
|
|
|
|
int32_t index2 = nsLayoutUtils::GetZIndex(aItem2->GetUnderlyingFrame());
|
2012-07-23 08:20:11 -07:00
|
|
|
return index1 <= index2;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::ExplodeAnonymousChildLists(nsDisplayListBuilder* aBuilder) {
|
|
|
|
// See if there's anything to do
|
2011-09-28 23:19:26 -07:00
|
|
|
bool anyAnonymousItems = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayItem* i;
|
2012-07-30 07:20:58 -07:00
|
|
|
for (i = GetBottom(); i != nullptr; i = i->GetAbove()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!i->GetUnderlyingFrame()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
anyAnonymousItems = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!anyAnonymousItems)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsDisplayList tmp;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((i = RemoveBottom()) != nullptr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (i->GetUnderlyingFrame()) {
|
|
|
|
tmp.AppendToTop(i);
|
|
|
|
} else {
|
2012-11-02 05:59:03 -07:00
|
|
|
nsDisplayList* list = i->GetSameCoordinateSystemChildren();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(list, "leaf items can't be anonymous");
|
|
|
|
list->ExplodeAnonymousChildLists(aBuilder);
|
|
|
|
nsDisplayItem* j;
|
2012-07-30 07:20:58 -07:00
|
|
|
while ((j = list->RemoveBottom()) != nullptr) {
|
2007-07-08 00:08:04 -07:00
|
|
|
tmp.AppendToTop(static_cast<nsDisplayWrapList*>(i)->
|
2007-03-22 10:30:00 -07:00
|
|
|
WrapWithClone(aBuilder, j));
|
|
|
|
}
|
|
|
|
i->~nsDisplayItem();
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
AppendToTop(&tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByZOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
|
|
|
Sort(aBuilder, IsZOrderLEQ, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByContentOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
|
|
|
Sort(aBuilder, IsContentLEQ, aCommonAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::Sort(nsDisplayListBuilder* aBuilder,
|
|
|
|
SortLEQ aCmp, void* aClosure) {
|
|
|
|
ExplodeAnonymousChildLists(aBuilder);
|
|
|
|
::Sort(this, Count(), aCmp, aClosure);
|
|
|
|
}
|
|
|
|
|
2012-11-22 15:29:05 -08:00
|
|
|
/* static */ bool
|
|
|
|
nsDisplayItem::ForceActiveLayers()
|
|
|
|
{
|
|
|
|
static bool sForce = false;
|
|
|
|
static bool sForceCached = false;
|
|
|
|
|
|
|
|
if (!sForceCached) {
|
|
|
|
Preferences::AddBoolVarCache(&sForce, "layers.force-active", false);
|
|
|
|
sForceCached = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sForce;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayItem::RecomputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2011-11-09 14:47:23 -08:00
|
|
|
if (ForceVisiblityForFixedItem(aBuilder, this)) {
|
|
|
|
itemVisible.And(GetDisplayPortBounds(aBuilder, this), bounds);
|
2011-05-09 01:40:09 -07:00
|
|
|
} else {
|
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
2011-05-09 01:40:09 -07:00
|
|
|
mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 09:35:16 -07:00
|
|
|
|
2011-02-16 14:43:30 -08: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 09:40:46 -07:00
|
|
|
if (!ComputeVisibility(aBuilder, aVisibleRegion, nsRect()))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2012-05-02 21:29:05 -07:00
|
|
|
nsRegion opaque = TreatAsOpaque(this, aBuilder);
|
2011-01-04 00:45:24 -08:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
2011-05-12 07:59:09 -07:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplaySolidColor::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-05-12 07:59:09 -07:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = true;
|
|
|
|
return mBounds;
|
2011-05-12 07:59:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySolidColor::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
2009-04-25 01:19:23 -07:00
|
|
|
aCtx->SetColor(mColor);
|
2009-09-06 17:35:14 -07:00
|
|
|
aCtx->FillRect(mVisibleRect);
|
2009-04-25 01:19:23 -07:00
|
|
|
}
|
|
|
|
|
2010-07-24 02:35:29 -07:00
|
|
|
static void
|
2011-01-11 05:03:16 -08:00
|
|
|
RegisterThemeGeometry(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
2010-07-24 02:35:29 -07: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 05:03:16 -08:00
|
|
|
aBuilder->RegisterThemeGeometry(aFrame->GetStyleDisplay()->mAppearance,
|
|
|
|
borderBox.ToNearestPixels(aFrame->PresContext()->AppUnitsPerDevPixel()));
|
2010-07-24 02:35:29 -07:00
|
|
|
}
|
|
|
|
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::nsDisplayBackgroundImage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
uint32_t aLayer,
|
|
|
|
bool aIsThemed,
|
|
|
|
const nsStyleBackground* aBackgroundStyle)
|
2012-11-18 19:28:18 -08:00
|
|
|
: nsDisplayImageContainer(aBuilder, aFrame)
|
2012-11-07 20:08:40 -08:00
|
|
|
, mBackgroundStyle(aBackgroundStyle)
|
|
|
|
, mLayer(aLayer)
|
|
|
|
, mIsThemed(aIsThemed)
|
2012-09-13 03:34:23 -07:00
|
|
|
, mIsBottommostLayer(true)
|
2010-07-24 02:35:29 -07:00
|
|
|
{
|
2012-11-09 15:14:59 -08:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayBackgroundImage);
|
2010-07-24 02:35:29 -07:00
|
|
|
|
2011-04-08 09:35:16 -07:00
|
|
|
if (mIsThemed) {
|
2012-11-07 20:08:40 -08:00
|
|
|
const nsStyleDisplay* disp = mFrame->GetStyleDisplay();
|
|
|
|
mFrame->IsThemed(disp, &mThemeTransparency);
|
2011-04-08 09:35:16 -07:00
|
|
|
// Perform necessary RegisterThemeGeometry
|
|
|
|
if (disp->mAppearance == NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR ||
|
|
|
|
disp->mAppearance == NS_THEME_TOOLBAR) {
|
|
|
|
RegisterThemeGeometry(aBuilder, aFrame);
|
2012-05-02 21:29:05 -07:00
|
|
|
} else if (disp->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
|
|
|
|
disp->mAppearance == NS_THEME_WIN_GLASS) {
|
|
|
|
aBuilder->SetGlassDisplayItem(this);
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
2012-11-07 20:08:40 -08:00
|
|
|
} else if (mBackgroundStyle) {
|
2011-04-08 09:35:16 -07:00
|
|
|
// Set HasFixedItems if we construct a background-attachment:fixed item
|
2012-11-07 20:08:40 -08:00
|
|
|
if (mLayer != mBackgroundStyle->mImageCount - 1) {
|
|
|
|
mIsBottommostLayer = false;
|
|
|
|
}
|
2012-09-13 03:34:23 -07:00
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
// Check if this background layer is attachment-fixed
|
|
|
|
if (!mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty() &&
|
|
|
|
mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED) {
|
|
|
|
aBuilder->SetHasFixedItems();
|
2011-04-08 09:35:16 -07:00
|
|
|
}
|
2010-07-24 02:35:29 -07:00
|
|
|
}
|
2012-11-27 20:05:32 -08:00
|
|
|
|
|
|
|
mBounds = GetBoundsInternal();
|
2010-07-24 02:35:29 -07:00
|
|
|
}
|
|
|
|
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::~nsDisplayBackgroundImage()
|
2012-08-19 12:33:25 -07:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2012-11-09 15:14:59 -08:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayBackgroundImage);
|
2012-08-19 12:33:25 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-09-13 03:34:23 -07:00
|
|
|
/*static*/ nsresult
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList,
|
|
|
|
nsDisplayBackgroundImage** aBackground)
|
2012-09-13 03:34:23 -07:00
|
|
|
{
|
2012-10-24 22:32:25 -07:00
|
|
|
nsStyleContext* bgSC = nullptr;
|
2012-09-13 03:34:23 -07:00
|
|
|
const nsStyleBackground* bg = nullptr;
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2012-11-07 20:08:40 -08:00
|
|
|
bool isThemed = aFrame->IsThemed();
|
|
|
|
if (!isThemed &&
|
2012-09-13 03:34:23 -07:00
|
|
|
nsCSSRendering::FindBackground(presContext, aFrame, &bgSC)) {
|
|
|
|
bg = bgSC->GetStyleBackground();
|
|
|
|
}
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
bool drawBackgroundColor = false;
|
|
|
|
nscolor color;
|
|
|
|
if (!nsCSSRendering::IsCanvasFrame(aFrame) && bg) {
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
color =
|
|
|
|
nsCSSRendering::DetermineBackgroundColor(presContext, bgSC, aFrame,
|
|
|
|
drawBackgroundImage, drawBackgroundColor);
|
|
|
|
}
|
|
|
|
|
2012-11-28 23:39:36 -08:00
|
|
|
// Even if we don't actually have a background color to paint, we still need
|
|
|
|
// to create the item because it's used for hit testing.
|
|
|
|
aList->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayBackgroundColor(aBuilder, aFrame, bg,
|
|
|
|
drawBackgroundColor ? color : NS_RGBA(0, 0, 0, 0)));
|
2012-10-24 22:32:25 -07:00
|
|
|
|
2012-09-13 03:34:23 -07:00
|
|
|
// Passing bg == nullptr in this macro will result in one iteration with
|
|
|
|
// i = 0.
|
|
|
|
bool backgroundSet = !aBackground;
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage* bgItem =
|
|
|
|
new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, isThemed, bg);
|
2012-09-13 03:34:23 -07:00
|
|
|
nsresult rv = aList->AppendNewToTop(bgItem);
|
|
|
|
if (rv != NS_OK) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (!backgroundSet) {
|
|
|
|
*aBackground = bgItem;
|
|
|
|
backgroundSet = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-11 11:03:12 -07:00
|
|
|
// Helper for RoundedRectIntersectsRect.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-10-11 11:03:12 -07:00
|
|
|
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)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-10-11 11:03:12 -07:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-10-11 11:03:12 -07:00
|
|
|
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.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-10-11 11:03:12 -07:00
|
|
|
RoundedBorderIntersectsRect(nsIFrame* aFrame,
|
|
|
|
const nsPoint& aFrameToReferenceFrame,
|
|
|
|
const nsRect& aTestRect)
|
|
|
|
{
|
2011-01-04 02:40:02 -08:00
|
|
|
if (!nsRect(aFrameToReferenceFrame, aFrame->GetSize()).Intersects(aTestRect))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-04 02:40:02 -08:00
|
|
|
|
2010-10-11 11:03:12 -07:00
|
|
|
nscoord radii[8];
|
|
|
|
return !aFrame->GetBorderRadii(radii) ||
|
|
|
|
RoundedRectIntersectsRect(nsRect(aFrameToReferenceFrame,
|
|
|
|
aFrame->GetSize()),
|
|
|
|
radii, aTestRect);
|
|
|
|
}
|
|
|
|
|
2009-04-24 02:24:44 -07: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 11:03:12 -07:00
|
|
|
//
|
|
|
|
// See also RoundedRectIntersectsRect.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool RoundedRectContainsRect(const nsRect& aRoundedRect,
|
2012-11-14 17:35:18 -08:00
|
|
|
const nscoord aRadii[8],
|
|
|
|
const nsRect& aContainedRect) {
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(aRoundedRect, aRadii, aContainedRect);
|
|
|
|
return rgn.Contains(aContainedRect);
|
2009-04-24 02:24:44 -07:00
|
|
|
}
|
|
|
|
|
2012-07-22 20:00:36 -07:00
|
|
|
bool
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
|
2012-11-14 17:35:18 -08:00
|
|
|
const nsRect& aClipRect,
|
|
|
|
gfxRect* aDestRect)
|
2012-07-22 20:00:36 -07:00
|
|
|
{
|
2012-11-07 20:08:40 -08:00
|
|
|
if (mIsThemed || !mBackgroundStyle)
|
2012-07-22 20:00:36 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-11-09 21:42:10 -08:00
|
|
|
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-07-22 20:00:36 -07:00
|
|
|
|
|
|
|
if (layer.mAttachment != NS_STYLE_BG_ATTACHMENT_FIXED)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsBackgroundLayerState state =
|
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext,
|
|
|
|
mFrame,
|
|
|
|
flags,
|
|
|
|
borderArea,
|
|
|
|
aClipRect,
|
2012-11-09 21:42:10 -08:00
|
|
|
*mBackgroundStyle,
|
2012-07-22 20:00:36 -07:00
|
|
|
layer);
|
|
|
|
|
|
|
|
nsImageRenderer* imageRenderer = &state.mImageRenderer;
|
|
|
|
// We only care about images here, not gradients.
|
|
|
|
if (!imageRenderer->IsRasterImage())
|
|
|
|
return false;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-11-14 17:35:18 -08:00
|
|
|
*aDestRect = nsLayoutUtils::RectToGfxRect(state.mFillArea, appUnitsPerDevPixel);
|
2012-07-22 20:00:36 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-03 13:13:12 -07:00
|
|
|
bool
|
2012-11-27 18:34:45 -08:00
|
|
|
nsDisplayBackgroundImage::TryOptimizeToImageLayer(LayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aBuilder)
|
2012-05-03 13:13:12 -07:00
|
|
|
{
|
2012-11-07 20:08:40 -08:00
|
|
|
if (mIsThemed || !mBackgroundStyle)
|
2012-05-03 13:13:12 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-11-09 21:42:10 -08:00
|
|
|
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-05-03 13:13:12 -07:00
|
|
|
|
|
|
|
nsBackgroundLayerState state =
|
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext,
|
|
|
|
mFrame,
|
|
|
|
flags,
|
|
|
|
borderArea,
|
|
|
|
borderArea,
|
2012-11-09 21:42:10 -08:00
|
|
|
*mBackgroundStyle,
|
2012-05-03 13:13:12 -07:00
|
|
|
layer);
|
|
|
|
|
2012-05-21 10:47:40 -07:00
|
|
|
nsImageRenderer* imageRenderer = &state.mImageRenderer;
|
2012-05-03 13:13:12 -07:00
|
|
|
// We only care about images here, not gradients.
|
2012-11-18 19:28:18 -08:00
|
|
|
if (!imageRenderer->IsRasterImage())
|
2012-05-21 10:47:40 -07:00
|
|
|
return false;
|
|
|
|
|
2012-11-27 18:34:45 -08:00
|
|
|
nsRefPtr<ImageContainer> imageContainer = imageRenderer->GetContainer(aManager);
|
2012-05-21 10:47:40 -07:00
|
|
|
// Image is not ready to be made into a layer yet
|
|
|
|
if (!imageContainer)
|
2012-05-03 13:13:12 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We currently can't handle tiled or partial backgrounds.
|
|
|
|
if (!state.mDestArea.IsEqualEdges(state.mFillArea)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sub-pixel alignment is hard, lets punt on that.
|
|
|
|
if (state.mAnchor != nsPoint(0.0f, 0.0f)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-05-03 13:13:12 -07:00
|
|
|
mDestRect = nsLayoutUtils::RectToGfxRect(state.mDestArea, appUnitsPerDevPixel);
|
2012-05-21 10:47:40 -07:00
|
|
|
mImageContainer = imageContainer;
|
2012-05-03 13:13:12 -07:00
|
|
|
|
|
|
|
// Ok, we can turn this into a layer if needed.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-18 19:28:18 -08:00
|
|
|
already_AddRefed<ImageContainer>
|
2012-11-27 18:34:45 -08:00
|
|
|
nsDisplayBackgroundImage::GetContainer(LayerManager* aManager,
|
|
|
|
nsDisplayListBuilder *aBuilder)
|
2012-11-18 19:28:18 -08:00
|
|
|
{
|
2012-11-27 18:34:45 -08:00
|
|
|
if (!TryOptimizeToImageLayer(aManager, aBuilder)) {
|
2012-11-18 19:28:18 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ImageContainer> container = mImageContainer;
|
|
|
|
|
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
2012-05-03 13:13:12 -07:00
|
|
|
LayerState
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const FrameLayerBuilder::ContainerParameters& aParameters)
|
2012-05-03 13:13:12 -07:00
|
|
|
{
|
|
|
|
if (!aManager->IsCompositingCheap() ||
|
|
|
|
!nsLayoutUtils::GPUImageScalingEnabled() ||
|
2012-11-27 18:34:45 -08:00
|
|
|
!TryOptimizeToImageLayer(aManager, aBuilder)) {
|
2012-05-03 13:13:12 -07:00
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxSize imageSize = mImageContainer->GetCurrentSize();
|
|
|
|
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
|
|
|
|
|
|
|
|
gfxRect destRect = mDestRect;
|
|
|
|
|
|
|
|
destRect.width *= aParameters.mXScale;
|
|
|
|
destRect.height *= aParameters.mYScale;
|
|
|
|
|
|
|
|
// Calculate the scaling factor for the frame.
|
|
|
|
gfxSize scale = gfxSize(destRect.width / imageSize.width, destRect.height / imageSize.height);
|
|
|
|
|
|
|
|
// If we are not scaling at all, no point in separating this into a layer.
|
|
|
|
if (scale.width == 1.0f && scale.height == 1.0f) {
|
2012-11-27 18:34:45 -08:00
|
|
|
return LAYER_NONE;
|
2012-05-03 13:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the target size is pretty small, no point in using a layer.
|
|
|
|
if (destRect.width * destRect.height < 64 * 64) {
|
2012-11-27 18:34:45 -08:00
|
|
|
return LAYER_NONE;
|
2012-05-03 13:13:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
2012-05-03 13:13:12 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<ImageLayer> layer = aManager->CreateImageLayer();
|
|
|
|
layer->SetContainer(mImageContainer);
|
2012-11-18 19:28:18 -08:00
|
|
|
ConfigureLayer(layer, aParameters.mOffset);
|
2012-05-03 13:13:12 -07:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-18 19:28:18 -08:00
|
|
|
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
|
2012-05-03 13:13:12 -07:00
|
|
|
{
|
|
|
|
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
|
|
|
|
|
|
|
gfxIntSize imageSize = mImageContainer->GetCurrentSize();
|
|
|
|
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
|
|
|
|
|
|
|
|
gfxMatrix transform;
|
2012-11-18 19:28:18 -08:00
|
|
|
transform.Translate(mDestRect.TopLeft() + aOffset);
|
2012-05-03 13:13:12 -07:00
|
|
|
transform.Scale(mDestRect.width/imageSize.width,
|
|
|
|
mDestRect.height/imageSize.height);
|
2012-07-30 19:20:00 -07:00
|
|
|
aLayer->SetBaseTransform(gfx3DMatrix::From2D(transform));
|
2012-05-03 13:13:12 -07:00
|
|
|
aLayer->SetVisibleRegion(nsIntRect(0, 0, imageSize.width, imageSize.height));
|
|
|
|
}
|
|
|
|
|
2010-10-11 11:03:12 -07:00
|
|
|
void
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
2010-10-11 11:03:12 -07:00
|
|
|
{
|
2011-08-08 11:31:52 -07: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 11:03:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-15 14:08:06 -07:00
|
|
|
{
|
2011-01-27 14:58:50 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-27 14:58:50 -08:00
|
|
|
}
|
2010-07-15 14:08:09 -07:00
|
|
|
|
2010-07-15 14:08:06 -07: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.
|
2012-11-07 20:08:40 -08:00
|
|
|
return mIsThemed || mBackgroundStyle;
|
2010-07-15 14:08:06 -07:00
|
|
|
}
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
/* static */ nsRegion
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetInsideClipRegion(nsDisplayItem* aItem,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
uint8_t aClip, const nsRect& aRect,
|
|
|
|
bool* aSnap)
|
2011-01-02 17:48:09 -08:00
|
|
|
{
|
|
|
|
nsRegion result;
|
|
|
|
if (aRect.IsEmpty())
|
|
|
|
return result;
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
nsIFrame *frame = aItem->GetUnderlyingFrame();
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nscoord radii[8];
|
|
|
|
nsRect clipRect;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveRadii;
|
2011-01-02 17:48:09 -08:00
|
|
|
switch (aClip) {
|
|
|
|
case NS_STYLE_BG_CLIP_BORDER:
|
2012-10-24 22:32:25 -07:00
|
|
|
haveRadii = frame->GetBorderRadii(radii);
|
|
|
|
clipRect = nsRect(aItem->ToReferenceFrame(), frame->GetSize());
|
2011-01-02 17:48:09 -08:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_PADDING:
|
2012-10-24 22:32:25 -07:00
|
|
|
haveRadii = frame->GetPaddingBoxBorderRadii(radii);
|
|
|
|
clipRect = frame->GetPaddingRect() - frame->GetPosition() + aItem->ToReferenceFrame();
|
2011-01-02 17:48:09 -08:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_CONTENT:
|
2012-10-24 22:32:25 -07:00
|
|
|
haveRadii = frame->GetContentBoxBorderRadii(radii);
|
|
|
|
clipRect = frame->GetContentRect() - frame->GetPosition() + aItem->ToReferenceFrame();
|
2011-01-02 17:48:09 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown clip type");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveRadii) {
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
|
|
|
result = nsLayoutUtils::RoundedRectIntersectRect(clipRect, radii, aRect);
|
2011-01-02 17:48:09 -08:00
|
|
|
} else {
|
2012-05-09 12:53:15 -07:00
|
|
|
result = clipRect.Intersect(aRect);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) {
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion result;
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// theme background overrides any other background
|
2010-10-19 10:02:25 -07:00
|
|
|
if (mIsThemed) {
|
2011-01-02 17:48:09 -08:00
|
|
|
if (mThemeTransparency == nsITheme::eOpaque) {
|
2012-08-28 22:39:01 -07:00
|
|
|
result = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
|
|
|
return result;
|
2010-10-19 10:02:25 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle)
|
2011-01-02 17:48:09 -08:00
|
|
|
return result;
|
2012-11-07 20:08:40 -08:00
|
|
|
|
2009-04-08 08:19:51 -07:00
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = true;
|
|
|
|
|
2011-01-02 17:48:09 -08: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.
|
2012-11-07 20:08:40 -08:00
|
|
|
if (mBackgroundStyle->mBackgroundInlinePolicy == NS_STYLE_BG_INLINE_POLICY_EACH_BOX ||
|
2011-01-02 17:48:09 -08:00
|
|
|
(!mFrame->GetPrevContinuation() && !mFrame->GetNextContinuation())) {
|
2012-11-07 20:08:40 -08:00
|
|
|
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
|
2012-09-13 03:34:23 -07:00
|
|
|
if (layer.mImage.IsOpaque()) {
|
2012-10-24 22:32:25 -07:00
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2012-11-07 20:08:40 -08:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-09-13 03:34:23 -07:00
|
|
|
nsRect r = nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
|
2012-11-07 20:08:40 -08:00
|
|
|
borderBox, *mBackgroundStyle, layer);
|
|
|
|
result = GetInsideClipRegion(this, presContext, layer.mClip, r, aSnap);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2009-04-08 08:19:51 -07:00
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// theme background overrides any other background
|
2011-01-16 02:38:45 -08: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);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-01-16 02:38:45 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-16 02:38:45 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle) {
|
2010-05-12 17:56:11 -07:00
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-05-12 17:56:11 -07:00
|
|
|
}
|
2012-11-07 20:08:40 -08:00
|
|
|
if (mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty()) {
|
2012-10-24 22:32:25 -07:00
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-05-12 17:56:11 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-15 14:08:12 -07:00
|
|
|
// theme background overrides any other background and is never fixed
|
|
|
|
if (mIsThemed)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-15 14:08:12 -07:00
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle->HasFixedBackground())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 02:54:37 -07: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));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-08 07:05:32 -08:00
|
|
|
nsRect
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetPositioningArea()
|
2012-11-08 07:05:32 -08:00
|
|
|
{
|
|
|
|
if (!mBackgroundStyle) {
|
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
nsIFrame* attachedToFrame;
|
|
|
|
return nsCSSRendering::ComputeBackgroundPositioningArea(
|
|
|
|
mFrame->PresContext(), mFrame,
|
|
|
|
nsRect(ToReferenceFrame(), mFrame->GetSize()),
|
|
|
|
*mBackgroundStyle, mBackgroundStyle->mLayers[mLayer],
|
|
|
|
&attachedToFrame) + ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
bool
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::RenderingMightDependOnPositioningAreaSizeChange()
|
2012-08-28 22:39:01 -07:00
|
|
|
{
|
|
|
|
// theme background overrides any other background and we don't know what to do here
|
|
|
|
if (mIsThemed)
|
|
|
|
return true;
|
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle)
|
2012-08-28 22:39:01 -07:00
|
|
|
return false;
|
|
|
|
|
2012-11-08 07:05:32 -08:00
|
|
|
nscoord radii[8];
|
|
|
|
if (mFrame->GetBorderRadii(radii)) {
|
|
|
|
// A change in the size of the positioning area might change the position
|
|
|
|
// of the rounded corners.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-11-08 07:05:32 -08:00
|
|
|
if (layer.RenderingMightDependOnPositioningAreaSizeChange()) {
|
2012-10-24 22:32:25 -07:00
|
|
|
return true;
|
2012-08-28 22:39:01 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
static void CheckForBorderItem(nsDisplayItem *aItem, uint32_t& aFlags)
|
|
|
|
{
|
|
|
|
nsDisplayItem* nextItem = aItem->GetAbove();
|
|
|
|
while (nextItem && nextItem->GetType() == nsDisplayItem::TYPE_BACKGROUND) {
|
|
|
|
nextItem = nextItem->GetAbove();
|
|
|
|
}
|
|
|
|
if (nextItem &&
|
|
|
|
nextItem->GetUnderlyingFrame() == aItem->GetUnderlyingFrame() &&
|
|
|
|
nextItem->GetType() == nsDisplayItem::TYPE_BORDER) {
|
|
|
|
aFlags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx) {
|
2012-07-22 20:00:36 -07:00
|
|
|
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-10-24 22:32:25 -07:00
|
|
|
CheckForBorderItem(this, flags);
|
2007-03-30 14:11:41 -07:00
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-06 17:35:14 -07:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2012-09-13 03:34:23 -07:00
|
|
|
flags, nullptr, mLayer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-09 15:14:59 -08:00
|
|
|
void nsDisplayBackgroundImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
2012-08-28 22:39:01 -07:00
|
|
|
{
|
2012-11-08 07:05:32 -08:00
|
|
|
if (!mBackgroundStyle) {
|
2012-08-28 22:39:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-08 07:05:32 -08:00
|
|
|
const nsDisplayBackgroundGeometry* geometry = static_cast<const nsDisplayBackgroundGeometry*>(aGeometry);
|
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
bool snap;
|
2012-11-08 07:05:32 -08:00
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
nsRect positioningArea = GetPositioningArea();
|
|
|
|
if (positioningArea.TopLeft() != geometry->mPositioningArea.TopLeft() ||
|
|
|
|
(positioningArea.Size() != geometry->mPositioningArea.Size() &&
|
|
|
|
RenderingMightDependOnPositioningAreaSizeChange())) {
|
|
|
|
// Positioning area changed in a way that could cause everything to change,
|
|
|
|
// so invalidate everything (both old and new painting areas).
|
|
|
|
aInvalidRegion->Or(bounds, geometry->mBounds);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!bounds.IsEqualInterior(geometry->mBounds)) {
|
|
|
|
// Positioning area is unchanged, so invalidate just the change in the
|
|
|
|
// painting area.
|
|
|
|
aInvalidRegion->Xor(bounds, geometry->mBounds);
|
2012-08-28 22:39:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-17 21:26:38 -08:00
|
|
|
nsRect
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
2012-10-24 22:32:25 -07:00
|
|
|
*aSnap = true;
|
2012-11-27 20:05:32 -08:00
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayBackgroundImage::GetBoundsInternal() {
|
2011-01-04 02:39:47 -08:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
|
2010-08-23 02:30:08 -07:00
|
|
|
if (mIsThemed) {
|
2012-10-24 22:32:25 -07:00
|
|
|
nsRect r(nsPoint(0,0), mFrame->GetSize());
|
2010-08-23 02:30:08 -07:00
|
|
|
presContext->GetTheme()->
|
|
|
|
GetWidgetOverflow(presContext->DeviceContext(), mFrame,
|
|
|
|
mFrame->GetStyleDisplay()->mAppearance, &r);
|
2012-08-28 22:39:01 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Bug 748219
|
|
|
|
r.Inflate(mFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
#endif
|
2012-10-24 22:32:25 -07:00
|
|
|
|
|
|
|
return r + ToReferenceFrame();
|
2010-08-23 02:30:08 -07:00
|
|
|
}
|
2007-12-17 21:26:38 -08:00
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle) {
|
2012-10-24 22:32:25 -07:00
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2012-11-07 20:08:40 -08:00
|
|
|
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
|
2012-10-24 22:32:25 -07:00
|
|
|
return nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
|
2012-11-07 20:08:40 -08:00
|
|
|
borderBox, *mBackgroundStyle, layer);
|
2007-12-17 21:26:38 -08:00
|
|
|
}
|
|
|
|
|
2012-09-13 03:34:23 -07:00
|
|
|
uint32_t
|
2012-11-09 15:14:59 -08:00
|
|
|
nsDisplayBackgroundImage::GetPerFrameKey()
|
2012-09-13 03:34:23 -07:00
|
|
|
{
|
|
|
|
return (mLayer << nsDisplayItem::TYPE_BITS) |
|
|
|
|
nsDisplayItem::GetPerFrameKey();
|
|
|
|
}
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
void
|
|
|
|
nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
|
|
|
if (mColor == NS_RGBA(0, 0, 0, 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint offset = ToReferenceFrame();
|
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
|
|
|
CheckForBorderItem(this, flags);
|
|
|
|
nsCSSRendering::PaintBackgroundColor(mFrame->PresContext(), *aCtx, mFrame,
|
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsDisplayBackgroundColor::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap)
|
|
|
|
{
|
|
|
|
if (NS_GET_A(mColor) != 255) {
|
|
|
|
return nsRegion();
|
|
|
|
}
|
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
if (!mBackgroundStyle)
|
2012-10-24 22:32:25 -07:00
|
|
|
return nsRegion();
|
|
|
|
|
|
|
|
*aSnap = true;
|
|
|
|
|
2012-11-07 20:08:40 -08:00
|
|
|
const nsStyleBackground::Layer& bottomLayer = mBackgroundStyle->BottomLayer();
|
2012-10-24 22:32:25 -07:00
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2012-11-07 20:08:40 -08:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-11-09 15:14:59 -08:00
|
|
|
return nsDisplayBackgroundImage::GetInsideClipRegion(this, presContext, bottomLayer.mClip, borderBox, aSnap);
|
2012-10-24 22:32:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayBackgroundColor::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
|
|
|
|
{
|
|
|
|
*aColor = mColor;
|
2012-11-07 20:08:40 -08:00
|
|
|
|
|
|
|
if (!mBackgroundStyle)
|
2012-10-24 22:32:25 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return (!nsLayoutUtils::HasNonZeroCorner(mFrame->GetStyleBorder()->mBorderRadius) &&
|
2012-11-07 20:08:40 -08:00
|
|
|
mBackgroundStyle->BottomLayer().mClip == NS_STYLE_BG_CLIP_BORDER);
|
2012-10-24 22:32:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayBackgroundColor::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);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayOutline::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2010-11-16 18:20:25 -08:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// TODO join outlines together
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-30 14:11:41 -07:00
|
|
|
nsCSSRendering::PaintOutline(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-06 17:35:14 -07:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2008-08-06 03:33:18 -07:00
|
|
|
mFrame->GetStyleContext());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-09-06 17:35:14 -07:00
|
|
|
nsDisplayOutline::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-27 14:58:50 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-27 14:58:50 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsStyleOutline* outline = mFrame->GetStyleOutline();
|
2010-08-13 03:01:58 -07:00
|
|
|
nsRect borderBox(ToReferenceFrame(), mFrame->GetSize());
|
2009-10-06 21:28:41 -07:00
|
|
|
if (borderBox.Contains(aVisibleRegion->GetBounds()) &&
|
2008-09-30 22:50:52 -07:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(outline->mOutlineRadius)) {
|
2008-09-12 20:45:37 -07:00
|
|
|
if (outline->mOutlineOffset >= 0) {
|
2007-03-22 10:30:00 -07: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
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-10-11 11:03:12 -07: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);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2007-03-22 10:30:00 -07: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 03:01:58 -07:00
|
|
|
mCaret->PaintCaret(aBuilder, aCtx, mFrame, ToReferenceFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-09-06 17:35:14 -07:00
|
|
|
nsDisplayBorder::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-27 14:58:50 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-27 14:58:50 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-27 15:52:32 -07:00
|
|
|
nsRect paddingRect = mFrame->GetPaddingRect() - mFrame->GetPosition() +
|
2010-08-13 03:01:58 -07:00
|
|
|
ToReferenceFrame();
|
2008-07-16 23:30:25 -07:00
|
|
|
const nsStyleBorder *styleBorder;
|
2007-09-27 15:52:32 -07:00
|
|
|
if (paddingRect.Contains(aVisibleRegion->GetBounds()) &&
|
2008-07-16 23:30:25 -07:00
|
|
|
!(styleBorder = mFrame->GetStyleBorder())->IsBorderImageLoaded() &&
|
2008-09-30 22:50:52 -07:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(styleBorder->mBorderRadius)) {
|
2007-03-22 10:30:00 -07: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-16 23:30:25 -07: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).
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-28 22:39:01 -07:00
|
|
|
|
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayBorder::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayBorderGeometry(this, aBuilder);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
void
|
|
|
|
nsDisplayBorder::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsDisplayBorderGeometry* geometry = static_cast<const nsDisplayBorderGeometry*>(aGeometry);
|
|
|
|
bool snap;
|
|
|
|
if (!geometry->mBounds.IsEqualInterior(GetBounds(aBuilder, &snap)) ||
|
|
|
|
!geometry->mContentRect.IsEqualInterior(GetContentRect())) {
|
|
|
|
// We can probably get away with only invalidating the difference
|
|
|
|
// between the border and padding rects, but the XUL ui at least
|
|
|
|
// is apparently painting a background with this?
|
|
|
|
aInvalidRegion->Or(GetBounds(aBuilder, &snap), geometry->mBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-30 14:11:41 -07:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-06 17:35:14 -07:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2008-08-06 03:33:18 -07:00
|
|
|
mFrame->GetStyleContext(),
|
|
|
|
mFrame->GetSkipSides());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-04 02:39:47 -08:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayBorder::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-01-04 02:39:47 -08:00
|
|
|
{
|
2011-12-22 15:34:45 -08:00
|
|
|
nsRect borderBounds(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
borderBounds.Inflate(mFrame->GetStyleBorder()->GetImageOutset());
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = true;
|
|
|
|
return borderBounds;
|
2011-01-04 02:39:47 -08:00
|
|
|
}
|
|
|
|
|
2009-11-30 15:14:04 -08: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);
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2009-11-30 15:14:04 -08:00
|
|
|
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-18 20:07:23 -07:00
|
|
|
accumulated.SetEmpty();
|
2009-11-30 15:14:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
accumulated = *r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-07 17:57:47 -07:00
|
|
|
void
|
2009-02-10 00:45:13 -08:00
|
|
|
nsDisplayBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-11-30 15:14:04 -08:00
|
|
|
nsRect borderRect = nsRect(offset, mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
2012-05-08 15:10:02 -07:00
|
|
|
SAMPLE_LABEL("nsDisplayBoxShadowOuter", "Paint");
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2009-11-30 15:14:04 -08:00
|
|
|
aCtx->PushState();
|
2011-04-07 18:04:40 -07:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-11-30 15:14:04 -08:00
|
|
|
nsCSSRendering::PaintBoxShadowOuter(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
2008-07-07 17:57:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2012-12-11 12:36:54 -08:00
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayBoxShadowOuter::GetBoundsInternal() {
|
|
|
|
return nsLayoutUtils::GetBoxShadowRectForFrame(mFrame, mFrame->GetSize()) +
|
|
|
|
ToReferenceFrame();
|
2008-07-07 17:57:47 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-09-06 17:35:14 -07:00
|
|
|
nsDisplayBoxShadowOuter::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-27 14:58:50 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-27 14:58:50 -08:00
|
|
|
}
|
2009-01-29 23:03:46 -08:00
|
|
|
|
2009-11-30 15:14:04 -08:00
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint origin = ToReferenceFrame();
|
2009-10-06 21:28:41 -07:00
|
|
|
nsRect visibleBounds = aVisibleRegion->GetBounds();
|
2009-04-24 02:24:44 -07:00
|
|
|
nsRect frameRect(origin, mFrame->GetSize());
|
|
|
|
if (!frameRect.Contains(visibleBounds))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-04-24 02:24:44 -07:00
|
|
|
|
|
|
|
// 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];
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasBorderRadii = mFrame->GetBorderRadii(twipsRadii);
|
2009-04-24 02:24:44 -07:00
|
|
|
if (!hasBorderRadii)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-01-29 23:03:46 -08:00
|
|
|
|
2009-04-24 02:24:44 -07:00
|
|
|
return !RoundedRectContainsRect(frameRect, twipsRadii, visibleBounds);
|
2009-01-29 23:03:46 -08:00
|
|
|
}
|
|
|
|
|
2009-02-10 00:45:13 -08:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadowInner::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-11-30 15:14:04 -08:00
|
|
|
nsRect borderRect = nsRect(offset, mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
2012-05-08 15:10:02 -07:00
|
|
|
SAMPLE_LABEL("nsDisplayBoxShadowInner", "Paint");
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2009-11-30 15:14:04 -08:00
|
|
|
aCtx->PushState();
|
2011-04-07 18:04:40 -07:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-11-30 15:14:04 -08:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-11-30 15:14:04 -08:00
|
|
|
nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-27 14:58:50 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-27 14:58:50 -08:00
|
|
|
}
|
2009-11-30 15:14:04 -08:00
|
|
|
|
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-02-10 00:45:13 -08:00
|
|
|
}
|
|
|
|
|
2012-10-24 22:32:25 -07:00
|
|
|
nsIFrame *GetTransformRootFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
|
|
|
|
while (parent && parent->Preserves3DChildren()) {
|
|
|
|
parent = nsLayoutUtils::GetCrossDocParentFrame(parent);
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mList.AppendToTop(aList);
|
2012-04-18 19:40:43 -07:00
|
|
|
UpdateBounds(aBuilder);
|
2012-10-24 22:32:25 -07:00
|
|
|
|
|
|
|
if (!aFrame || !aFrame->IsTransformed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the frame is a preserve-3d parent, then we will create transforms
|
|
|
|
// inside this list afterwards (see WrapPreserve3DList in nsFrame.cpp).
|
|
|
|
// In this case we will always be outside of the transform, so share
|
|
|
|
// our parents reference frame.
|
|
|
|
if (aFrame->Preserves3DChildren()) {
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're a transformed frame, then we need to find out if we're inside
|
|
|
|
// the nsDisplayTransform or outside of it. Frames inside the transform
|
|
|
|
// need mReferenceFrame == mFrame, outside needs the next ancestor
|
|
|
|
// reference frame.
|
|
|
|
// If we're inside the transform, then the nsDisplayItem constructor
|
|
|
|
// will have done the right thing.
|
|
|
|
// If we're outside the transform, then we should have only one child
|
|
|
|
// (since nsDisplayTransform wraps all actual content), and that child
|
|
|
|
// will have the correct reference frame set (since nsDisplayTransform
|
|
|
|
// handles this explictly).
|
|
|
|
//
|
|
|
|
// Preserve-3d can cause us to have multiple nsDisplayTransform
|
|
|
|
// children.
|
|
|
|
nsDisplayItem *i = mList.GetBottom();
|
|
|
|
if (i && (!i->GetAbove() || i->GetType() == TYPE_TRANSFORM) &&
|
|
|
|
i->GetUnderlyingFrame() == mFrame) {
|
|
|
|
mReferenceFrame = i->ReferenceFrame();
|
|
|
|
mToReferenceFrame = i->ToReferenceFrame();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mList.AppendToTop(aItem);
|
2012-04-18 19:40:43 -07:00
|
|
|
UpdateBounds(aBuilder);
|
2012-10-24 22:32:25 -07:00
|
|
|
|
|
|
|
if (!aFrame || !aFrame->IsTransformed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame->Preserves3DChildren()) {
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See the previous nsDisplayWrapList constructor
|
|
|
|
if (aItem->GetUnderlyingFrame() == aFrame) {
|
|
|
|
mReferenceFrame = aItem->ReferenceFrame();
|
|
|
|
mToReferenceFrame = aItem->ToReferenceFrame();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
2012-04-17 22:14:14 -07:00
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem,
|
2012-09-16 03:32:59 -07:00
|
|
|
const nsIFrame* aReferenceFrame,
|
2012-04-17 22:14:14 -07:00
|
|
|
const nsPoint& aToReferenceFrame)
|
2012-09-16 03:32:59 -07:00
|
|
|
: nsDisplayItem(aBuilder, aFrame, aReferenceFrame, aToReferenceFrame) {
|
2012-04-17 22:14:14 -07:00
|
|
|
mList.AppendToTop(aItem);
|
|
|
|
mBounds = mList.GetBounds(aBuilder);
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void
|
|
|
|
nsDisplayWrapList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayWrapList::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2012-04-13 04:44:06 -07:00
|
|
|
return mBounds;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-09-06 17:35:14 -07:00
|
|
|
nsDisplayWrapList::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2012-10-24 22:32:25 -07:00
|
|
|
return mList.ComputeVisibilityForSublist(aBuilder, this, aVisibleRegion,
|
2011-01-27 14:58:50 -08:00
|
|
|
mVisibleRect,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion
|
|
|
|
nsDisplayWrapList::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap) {
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion result;
|
|
|
|
if (mList.IsOpaque()) {
|
2012-04-13 04:44:06 -07:00
|
|
|
// Everything within GetBounds that's visible is opaque.
|
2012-04-10 04:24:18 -07:00
|
|
|
result = GetBounds(aBuilder, aSnap);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayWrapList::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2011-10-17 07:59:28 -07:00
|
|
|
// We could try to do something but let's conservatively just return false.
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayWrapList::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
2010-08-13 02:54:37 -07:00
|
|
|
nsIFrame* aFrame) {
|
2008-04-10 20:46:37 -07:00
|
|
|
NS_WARNING("nsDisplayWrapList::IsVaryingRelativeToMovingFrame called unexpectedly");
|
2011-10-17 07:59:28 -07:00
|
|
|
// We could try to do something but let's conservatively just return true.
|
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayWrapList::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-02-28 23:56:19 -08:00
|
|
|
NS_ERROR("nsDisplayWrapList should have been flattened away for painting");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-13 22:26:29 -08:00
|
|
|
LayerState
|
|
|
|
nsDisplayWrapList::RequiredLayerStateForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters,
|
|
|
|
const nsDisplayList& aList,
|
|
|
|
nsIFrame* aActiveScrolledRoot) {
|
|
|
|
LayerState result = LAYER_INACTIVE;
|
2010-07-15 14:08:05 -07:00
|
|
|
for (nsDisplayItem* i = aList.GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
nsIFrame* f = i->GetUnderlyingFrame();
|
|
|
|
if (f) {
|
|
|
|
nsIFrame* activeScrolledRoot =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(f, nullptr);
|
2012-11-13 22:26:29 -08:00
|
|
|
if (activeScrolledRoot != aActiveScrolledRoot && result == LAYER_INACTIVE)
|
|
|
|
result = LAYER_ACTIVE;
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerState state = i->GetLayerState(aBuilder, aManager, aParameters);
|
2012-11-13 22:26:29 -08:00
|
|
|
if ((state == LAYER_ACTIVE || state == LAYER_ACTIVE_FORCE) && (state > result))
|
|
|
|
result = state;
|
2010-07-15 14:08:05 -07:00
|
|
|
if (state == LAYER_NONE) {
|
2012-11-02 05:59:03 -07:00
|
|
|
nsDisplayList* list = i->GetSameCoordinateSystemChildren();
|
2012-11-13 22:26:29 -08:00
|
|
|
if (list) {
|
|
|
|
LayerState childState = RequiredLayerStateForChildren(aBuilder, aManager, aParameters, *list, aActiveScrolledRoot);
|
|
|
|
if (childState > result) {
|
|
|
|
result = childState;
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
}
|
2012-11-13 22:26:29 -08:00
|
|
|
return result;
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect nsDisplayWrapList::GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder)
|
2010-10-10 17:58:20 -07:00
|
|
|
{
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect bounds;
|
2010-10-10 17:58:20 -07:00
|
|
|
for (nsDisplayItem* i = mList.GetBottom(); i; i = i->GetAbove()) {
|
2011-01-02 17:48:09 -08:00
|
|
|
bounds.UnionRect(bounds, i->GetComponentAlphaBounds(aBuilder));
|
2010-10-10 17:58:20 -07:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
return bounds;
|
2010-10-10 17:58:20 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
|
|
|
WrapDisplayList(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
2010-08-13 02:55:54 -07:00
|
|
|
if (!aList->GetTop())
|
2007-03-22 10:30:00 -07: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 03:01:13 -07:00
|
|
|
nsDisplayOpacity::nsDisplayOpacity(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOpacity::~nsDisplayOpacity() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOpacity);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion nsDisplayOpacity::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap) {
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// We are never opaque, if our opacity was < 1 then we wouldn't have
|
|
|
|
// been created.
|
2011-01-02 17:48:09 -08:00
|
|
|
return nsRegion();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-28 23:56:19 -08:00
|
|
|
// nsDisplayOpacity uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayOpacity::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 05:11:27 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2012-11-22 17:09:24 -08:00
|
|
|
if (mFrame->GetStyleDisplay()->mOpacity == 0 && mFrame->GetContent() &&
|
|
|
|
!nsLayoutUtils::HasAnimationsForCompositor(mFrame->GetContent(), eCSSProperty_opacity)) {
|
2012-11-14 14:43:29 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-20 21:06:46 -07:00
|
|
|
nsRefPtr<Layer> container = aManager->GetLayerBuilder()->
|
2011-06-22 05:11:27 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 07:20:58 -07:00
|
|
|
aContainerParameters, nullptr);
|
2012-07-31 10:28:21 -07:00
|
|
|
if (!container)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
container->SetOpacity(mFrame->GetStyleDisplay()->mOpacity);
|
2012-08-06 13:33:23 -07:00
|
|
|
AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, eCSSProperty_opacity);
|
2012-07-31 10:28:21 -07:00
|
|
|
return container.forget();
|
2010-02-28 23:56:19 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-26 13:10:48 -07:00
|
|
|
/**
|
|
|
|
* This doesn't take into account layer scaling --- the layer may be
|
|
|
|
* rendered at a higher (or lower) resolution, affecting the retained layer
|
|
|
|
* size --- but this should be good enough.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
IsItemTooSmallForActiveLayer(nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
nsIntRect visibleDevPixels = aItem->GetVisibleRect().ToOutsidePixels(
|
|
|
|
aItem->GetUnderlyingFrame()->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
static const int MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS = 16;
|
|
|
|
return visibleDevPixels.Size() <
|
|
|
|
nsIntSize(MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS, MIN_ACTIVE_LAYER_SIZE_DEV_PIXELS);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters) {
|
2011-10-26 13:10:48 -07:00
|
|
|
if (mFrame->AreLayersMarkedActive(nsChangeHint_UpdateOpacityLayer) &&
|
|
|
|
!IsItemTooSmallForActiveLayer(this))
|
2010-07-15 14:08:06 -07:00
|
|
|
return LAYER_ACTIVE;
|
2012-07-31 10:28:21 -07:00
|
|
|
if (mFrame->GetContent()) {
|
2012-07-31 10:28:22 -07:00
|
|
|
if (nsLayoutUtils::HasAnimationsForCompositor(mFrame->GetContent(),
|
|
|
|
eCSSProperty_opacity)) {
|
2012-07-31 10:28:21 -07:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:08:05 -07:00
|
|
|
nsIFrame* activeScrolledRoot =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(mFrame, nullptr);
|
2012-11-13 22:26:29 -08:00
|
|
|
return RequiredLayerStateForChildren(aBuilder, aManager, aParameters, mList, activeScrolledRoot);
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-13 09:40:46 -07:00
|
|
|
nsDisplayOpacity::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2007-03-22 10:30:00 -07: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.
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
2010-02-28 23:56:19 -08:00
|
|
|
nsRegion visibleUnderChildren;
|
|
|
|
visibleUnderChildren.And(*aVisibleRegion, bounds);
|
2012-05-09 12:53:15 -07:00
|
|
|
nsRect allowExpansion = bounds.Intersect(aAllowVisibleRegionExpansion);
|
2010-02-28 23:56:19 -08:00
|
|
|
return
|
2011-01-27 14:58:50 -08:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren,
|
2011-05-13 09:40:46 -07:00
|
|
|
allowExpansion);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayOpacity::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aItem->GetType() != TYPE_OPACITY)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-04-16 22:44:32 -07:00
|
|
|
MergeFromTrackingMergedFrames(static_cast<nsDisplayOpacity*>(aItem));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayOwnLayer::nsDisplayOwnLayer(nsDisplayListBuilder* aBuilder,
|
2012-08-28 22:47:18 -07:00
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
|
|
|
, mFlags(aFlags) {
|
2010-07-15 14:08:03 -07: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 05:11:27 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2012-08-20 21:06:46 -07:00
|
|
|
nsRefPtr<Layer> layer = aManager->GetLayerBuilder()->
|
2011-06-22 05:11:27 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 07:20:58 -07:00
|
|
|
aContainerParameters, nullptr);
|
2012-08-28 22:47:18 -07:00
|
|
|
|
|
|
|
if (mFlags & GENERATE_SUBDOC_INVALIDATIONS) {
|
|
|
|
ContainerLayerPresContext* pres = new ContainerLayerPresContext;
|
|
|
|
pres->mPresContext = mFrame->PresContext();
|
|
|
|
layer->SetUserData(&gNotifySubDocInvalidationData, pres);
|
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2012-06-27 08:43:57 -07:00
|
|
|
nsDisplayFixedPosition::nsDisplayFixedPosition(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
2012-07-25 00:06:19 -07:00
|
|
|
nsIFrame* aFixedPosFrame,
|
2012-06-27 08:43:57 -07:00
|
|
|
nsDisplayList* aList)
|
2012-07-25 00:06:19 -07:00
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList)
|
|
|
|
, mFixedPosFrame(aFixedPosFrame) {
|
2012-06-27 08:43:57 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayFixedPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayFixedPosition::~nsDisplayFixedPosition() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayFixedPosition);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayFixedPosition::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
|
|
|
nsRefPtr<Layer> layer =
|
|
|
|
nsDisplayOwnLayer::BuildLayer(aBuilder, aManager, aContainerParameters);
|
|
|
|
|
|
|
|
// Work out the anchor point for this fixed position layer. We assume that
|
|
|
|
// any positioning set (left/top/right/bottom) indicates that the
|
|
|
|
// corresponding side of its container should be the anchor point,
|
|
|
|
// defaulting to top-left.
|
2012-07-25 00:06:19 -07:00
|
|
|
nsIFrame* viewportFrame = mFixedPosFrame->GetParent();
|
2012-06-27 08:43:57 -07:00
|
|
|
nsPresContext *presContext = viewportFrame->PresContext();
|
|
|
|
|
|
|
|
// Fixed position frames are reflowed into the scroll-port size if one has
|
|
|
|
// been set.
|
|
|
|
nsSize containingBlockSize = viewportFrame->GetSize();
|
|
|
|
if (presContext->PresShell()->IsScrollPositionClampingScrollPortSizeSet()) {
|
|
|
|
containingBlockSize = presContext->PresShell()->
|
|
|
|
GetScrollPositionClampingScrollPortSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find out the rect of the viewport frame relative to the reference frame.
|
|
|
|
// This, in conjunction with the container scale, will correspond to the
|
|
|
|
// coordinate-space of the built layer.
|
|
|
|
float factor = presContext->AppUnitsPerDevPixel();
|
2012-09-16 03:32:59 -07:00
|
|
|
nsPoint origin = viewportFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2012-06-27 08:43:57 -07:00
|
|
|
gfxRect anchorRect(NSAppUnitsToFloatPixels(origin.x, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(origin.y, factor) *
|
|
|
|
aContainerParameters.mYScale,
|
|
|
|
NSAppUnitsToFloatPixels(containingBlockSize.width, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(containingBlockSize.height, factor) *
|
|
|
|
aContainerParameters.mYScale);
|
|
|
|
|
|
|
|
gfxPoint anchor(anchorRect.x, anchorRect.y);
|
|
|
|
|
2012-07-25 00:06:19 -07:00
|
|
|
const nsStylePosition* position = mFixedPosFrame->GetStylePosition();
|
2012-06-27 08:43:57 -07:00
|
|
|
if (position->mOffset.GetRightUnit() != eStyleUnit_Auto)
|
|
|
|
anchor.x = anchorRect.XMost();
|
|
|
|
if (position->mOffset.GetBottomUnit() != eStyleUnit_Auto)
|
|
|
|
anchor.y = anchorRect.YMost();
|
|
|
|
|
|
|
|
layer->SetFixedPositionAnchor(anchor);
|
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2012-08-10 01:36:33 -07:00
|
|
|
bool nsDisplayFixedPosition::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_FIXED_POSITION)
|
|
|
|
return false;
|
|
|
|
// Items with the same fixed position frame can be merged.
|
|
|
|
nsDisplayFixedPosition* other = static_cast<nsDisplayFixedPosition*>(aItem);
|
|
|
|
if (other->mFixedPosFrame != mFixedPosFrame)
|
|
|
|
return false;
|
|
|
|
MergeFromTrackingMergedFrames(other);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList,
|
|
|
|
nsIFrame* aForFrame,
|
2011-05-01 18:53:01 -07: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 09:45:14 -08:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2011-01-13 14:17:40 -08:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
2011-01-13 09:45:14 -08:00
|
|
|
#endif
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
2011-01-13 09:45:14 -08:00
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayScrollLayer::~nsDisplayScrollLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayScrollLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 05:11:27 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters) {
|
2012-08-20 21:06:46 -07:00
|
|
|
nsRefPtr<ContainerLayer> layer = aManager->GetLayerBuilder()->
|
2011-06-22 05:11:27 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 07:20:58 -07:00
|
|
|
aContainerParameters, nullptr);
|
2011-01-13 09:45:14 -08:00
|
|
|
|
|
|
|
// Get the already set unique ID for scrolling this content remotely.
|
|
|
|
// Or, if not set, generate a new ID.
|
2011-05-01 18:53:01 -07:00
|
|
|
nsIContent* content = mScrolledFrame->GetContent();
|
2011-01-13 09:45:14 -08:00
|
|
|
ViewID scrollId = nsLayoutUtils::FindIDFor(content);
|
2011-01-13 09:45:14 -08:00
|
|
|
|
2012-06-15 14:49:46 -07:00
|
|
|
nsRect viewport = mScrollFrame->GetRect() -
|
|
|
|
mScrollFrame->GetPosition() +
|
2012-09-16 03:32:59 -07:00
|
|
|
mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2011-01-13 09:45:14 -08:00
|
|
|
|
2011-03-09 13:35:27 -08:00
|
|
|
bool usingDisplayport = false;
|
2012-11-21 14:34:18 -08:00
|
|
|
bool usingCriticalDisplayport = false;
|
|
|
|
nsRect displayport, criticalDisplayport;
|
2012-06-15 14:49:46 -07:00
|
|
|
if (content) {
|
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
2012-11-21 14:34:18 -08:00
|
|
|
usingCriticalDisplayport =
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(content, &criticalDisplayport);
|
2012-06-15 14:49:46 -07:00
|
|
|
}
|
2011-05-01 18:53:01 -07:00
|
|
|
RecordFrameMetrics(mScrolledFrame, mScrollFrame, layer, mVisibleRect, viewport,
|
2012-11-21 14:34:18 -08:00
|
|
|
(usingDisplayport ? &displayport : nullptr),
|
|
|
|
(usingCriticalDisplayport ? &criticalDisplayport : nullptr),
|
|
|
|
scrollId, aContainerParameters, false);
|
2011-01-13 09:45:14 -08:00
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-01-13 09:45:14 -08:00
|
|
|
nsDisplayScrollLayer::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2011-01-13 09:45:14 -08:00
|
|
|
{
|
2011-03-09 13:35:27 -08:00
|
|
|
nsRect displayport;
|
2011-05-01 18:53:01 -07:00
|
|
|
if (nsLayoutUtils::GetDisplayPort(mScrolledFrame->GetContent(), &displayport)) {
|
2011-01-13 09:45:14 -08: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.
|
|
|
|
|
2012-09-16 03:32:59 -07:00
|
|
|
nsRegion childVisibleRegion = displayport + mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2011-01-13 09:45:14 -08:00
|
|
|
|
2012-05-09 12:53:15 -07:00
|
|
|
nsRect boundedRect =
|
|
|
|
childVisibleRegion.GetBounds().Intersect(mList.GetBounds(aBuilder));
|
|
|
|
nsRect allowExpansion = boundedRect.Intersect(aAllowVisibleRegionExpansion);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool visible = mList.ComputeVisibilityForSublist(
|
2012-10-24 22:32:25 -07:00
|
|
|
aBuilder, this, &childVisibleRegion, boundedRect, allowExpansion);
|
2011-01-13 09:45:14 -08:00
|
|
|
mVisibleRect = boundedRect;
|
|
|
|
|
|
|
|
return visible;
|
|
|
|
|
|
|
|
} else {
|
2011-05-01 18:53:01 -07:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion);
|
2011-01-13 09:45:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
2011-04-29 10:15:44 -07:00
|
|
|
{
|
2011-05-01 18:53:01 -07: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 10:15:44 -07:00
|
|
|
}
|
2011-05-01 18:53:01 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayScrollLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SCROLL_LAYER) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer* other = static_cast<nsDisplayScrollLayer*>(aItem);
|
|
|
|
if (other->mScrolledFrame != this->mScrolledFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2012-10-24 16:04:41 -07:00
|
|
|
NS_ASSERTION(other->mReferenceFrame == mReferenceFrame,
|
|
|
|
"Must have the same reference frame!");
|
|
|
|
|
2011-05-01 18:53:01 -07:00
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Set(nsIFrame::ScrollLayerCount(),
|
|
|
|
reinterpret_cast<void*>(GetScrollLayerCount() - 1));
|
|
|
|
|
2012-10-05 02:56:49 -07:00
|
|
|
// Swap frames with the other item before doing MergeFrom.
|
|
|
|
// XXX - This ensures that the frame associated with a scroll layer after
|
|
|
|
// merging is the first, rather than the last. This tends to change less,
|
|
|
|
// ensuring we're more likely to retain the associated gfx layer.
|
|
|
|
// See Bug 729534 and Bug 731641.
|
|
|
|
nsIFrame* tmp = mFrame;
|
|
|
|
mFrame = other->mFrame;
|
|
|
|
other->mFrame = tmp;
|
2012-04-16 22:44:32 -07:00
|
|
|
MergeFromTrackingMergedFrames(other);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayScrollLayer::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return GetScrollLayerCount() > 1;
|
|
|
|
}
|
|
|
|
|
2012-04-11 17:17:44 -07:00
|
|
|
intptr_t
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayScrollLayer::GetScrollLayerCount()
|
|
|
|
{
|
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasCount = false;
|
2012-04-11 17:17:44 -07:00
|
|
|
intptr_t result = reinterpret_cast<intptr_t>(
|
2011-05-01 18:53:01 -07:00
|
|
|
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
|
2012-04-11 17:17:44 -07:00
|
|
|
return reinterpret_cast<intptr_t>(props.Get(nsIFrame::ScrollLayerCount()));
|
2011-01-13 09:45:14 -08:00
|
|
|
#endif
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2012-04-11 17:17:44 -07:00
|
|
|
intptr_t
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayScrollLayer::RemoveScrollLayerCount()
|
|
|
|
{
|
2012-04-11 17:17:44 -07:00
|
|
|
intptr_t result = GetScrollLayerCount();
|
2011-05-01 18:53:01 -07:00
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Remove(nsIFrame::ScrollLayerCount());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-13 09:45:14 -08:00
|
|
|
|
2011-04-11 13:53:01 -07:00
|
|
|
nsDisplayScrollInfoLayer::nsDisplayScrollInfoLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-05-01 18:53:01 -07:00
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayScrollLayer(aBuilder, aScrolledFrame, aScrolledFrame, aScrollFrame)
|
2011-04-11 13:53:01 -07: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-01 18:53:01 -07:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollInfoLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
2011-05-01 18:53:01 -07:00
|
|
|
{
|
|
|
|
return LAYER_ACTIVE_EMPTY;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-01 18:53:01 -07:00
|
|
|
nsDisplayScrollInfoLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-05-01 18:53:01 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-05-01 18:53:01 -07:00
|
|
|
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
|
2012-07-31 10:28:21 -07:00
|
|
|
// visibility computation.
|
2011-05-01 18:53:01 -07:00
|
|
|
return RemoveScrollLayerCount() == 1;
|
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayClip::nsDisplayClip(nsDisplayListBuilder* aBuilder,
|
2010-09-09 08:21:46 -07:00
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem,
|
|
|
|
const nsRect& aRect)
|
2012-04-17 22:14:14 -07:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aItem,
|
2012-09-16 03:32:59 -07:00
|
|
|
aFrame == aItem->GetUnderlyingFrame() ? aItem->ReferenceFrame() : aBuilder->FindReferenceFrameFor(aFrame),
|
2012-04-17 22:14:14 -07:00
|
|
|
aFrame == aItem->GetUnderlyingFrame() ? aItem->ToReferenceFrame() : aBuilder->ToReferenceFrame(aFrame)),
|
|
|
|
mClip(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayClip::nsDisplayClip(nsDisplayListBuilder* aBuilder,
|
2010-09-09 08:21:46 -07:00
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
const nsRect& aRect)
|
2012-04-10 04:24:18 -07:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList), mClip(aRect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayClip);
|
|
|
|
}
|
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRect nsDisplayClip::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
nsRect r = nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
2012-04-13 04:44:05 -07:00
|
|
|
*aSnap = false;
|
2012-05-09 12:53:15 -07:00
|
|
|
return mClip.Intersect(r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayClip::~nsDisplayClip() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayClip);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void nsDisplayClip::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-02-28 23:56:19 -08:00
|
|
|
NS_ERROR("nsDisplayClip should have been flattened away for painting");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayClip::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2009-10-06 21:28:41 -07:00
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
|
|
|
|
nsRegion finalClipped(clipped);
|
2012-05-09 12:53:15 -07:00
|
|
|
nsRect allowExpansion = mClip.Intersect(aAllowVisibleRegionExpansion);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool anyVisible =
|
2011-01-27 14:58:50 -08:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &finalClipped,
|
2011-05-13 09:40:46 -07:00
|
|
|
allowExpansion);
|
2009-10-06 21:28:41 -07:00
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(clipped, finalClipped);
|
2011-05-13 09:40:46 -07:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
2009-08-13 19:09:51 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return anyVisible;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayClip::TryMerge(nsDisplayListBuilder* aBuilder,
|
2012-04-13 04:44:06 -07:00
|
|
|
nsDisplayItem* aItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aItem->GetType() != TYPE_CLIP)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-07-08 00:08:04 -07:00
|
|
|
nsDisplayClip* other = static_cast<nsDisplayClip*>(aItem);
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!other->mClip.IsEqualInterior(mClip))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-04-16 22:44:32 -07:00
|
|
|
// No need to track merged frames for clipping
|
2012-04-13 04:44:06 -07:00
|
|
|
MergeFrom(other);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList* nsDisplayClip::WrapWithClone(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
2008-04-18 02:21:21 -07:00
|
|
|
return new (aBuilder)
|
2010-09-09 08:21:46 -07:00
|
|
|
nsDisplayClip(aBuilder, aItem->GetUnderlyingFrame(), aItem, mClip);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2010-09-09 08:21:46 -07: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-02 17:48:09 -08:00
|
|
|
nsRegion
|
|
|
|
nsDisplayClipRoundedRect::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap)
|
2010-09-09 08:21:46 -07:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-01-02 17:48:09 -08:00
|
|
|
return nsRegion();
|
2010-09-09 08:21:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayClipRoundedRect::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect, HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
2010-10-11 11:03:12 -07: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 08:21:46 -07:00
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayWrapList*
|
|
|
|
nsDisplayClipRoundedRect::WrapWithClone(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem) {
|
|
|
|
return new (aBuilder)
|
|
|
|
nsDisplayClipRoundedRect(aBuilder, aItem->GetUnderlyingFrame(), aItem,
|
|
|
|
mClip, mRadii);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayClipRoundedRect::ComputeVisibility(
|
2010-09-09 08:21:46 -07:00
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-09-09 08:21:46 -07:00
|
|
|
{
|
|
|
|
nsRegion clipped;
|
|
|
|
clipped.And(*aVisibleRegion, mClip);
|
|
|
|
|
2011-05-13 09:40:46 -07:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, &clipped, nsRect());
|
2010-09-09 08:21:46 -07:00
|
|
|
// FIXME: Remove a *conservative* opaque region from aVisibleRegion
|
|
|
|
// (like in nsDisplayClip::ComputeVisibility).
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayClipRoundedRect::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
2010-09-09 08:21:46 -07:00
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_CLIP_ROUNDED_RECT)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-09-09 08:21:46 -07:00
|
|
|
nsDisplayClipRoundedRect* other =
|
|
|
|
static_cast<nsDisplayClipRoundedRect*>(aItem);
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!mClip.IsEqualInterior(other->mClip) ||
|
2010-12-24 12:37:03 -08:00
|
|
|
memcmp(mRadii, other->mRadii, sizeof(mRadii)) != 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-04-16 22:44:32 -07:00
|
|
|
// No need to track merged frames for clipping
|
2012-04-13 04:44:06 -07:00
|
|
|
MergeFrom(other);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayZoom::nsDisplayZoom(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
2012-08-28 22:47:18 -07:00
|
|
|
int32_t aAPD, int32_t aParentAPD,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList, aFlags)
|
|
|
|
, mAPD(aAPD), mParentAPD(aParentAPD) {
|
2010-07-18 19:23:48 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayZoom::~nsDisplayZoom() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRect nsDisplayZoom::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2010-07-18 19:23:48 -07:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRect bounds = nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
|
|
|
*aSnap = false;
|
2010-07-18 19:23:48 -07:00
|
|
|
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-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2010-07-18 19:23:48 -07:00
|
|
|
{
|
|
|
|
mList.PaintForFrame(aBuilder, aCtx, mFrame, nsDisplayList::PAINT_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayZoom::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRegion *aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-18 19:23:48 -07:00
|
|
|
{
|
|
|
|
// Convert the passed in visible region to our appunits.
|
|
|
|
nsRegion visibleRegion =
|
|
|
|
aVisibleRegion->ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
|
|
|
nsRegion originalVisibleRegion = visibleRegion;
|
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
nsRect transformedVisibleRect =
|
|
|
|
mVisibleRect.ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
2011-02-16 14:43:30 -08:00
|
|
|
nsRect allowExpansion =
|
|
|
|
aAllowVisibleRegionExpansion.ConvertAppUnitsRoundIn(mParentAPD, mAPD);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool retval =
|
2012-10-24 22:32:25 -07:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, this, &visibleRegion,
|
2011-01-27 14:58:50 -08:00
|
|
|
transformedVisibleRect,
|
2011-05-13 09:40:46 -07:00
|
|
|
allowExpansion);
|
2010-07-18 19:23:48 -07: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 09:40:46 -07:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
2010-07-18 19:23:48 -07:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-09-13 02:42:11 -07: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 01:47:02 -07:00
|
|
|
// correctly, since when the frames are initially being reflowed, their
|
2008-09-13 02:42:11 -07: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!");
|
2012-05-16 21:05:09 -07:00
|
|
|
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
|
|
|
// TODO: SVG needs to define what percentage translations resolve against.
|
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
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;
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
|
|
|
// TODO: SVG needs to define what percentage translations resolve against.
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
/* Iterate through the continuation list, unioning together all the
|
|
|
|
* bounding rects.
|
|
|
|
*/
|
|
|
|
for (const nsIFrame *currFrame = aFrame->GetFirstContinuation();
|
2012-07-30 07:20:58 -07:00
|
|
|
currFrame != nullptr;
|
2008-09-13 02:42:11 -07:00
|
|
|
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
|
|
|
|
|
2012-09-19 16:14:07 -07:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame,
|
|
|
|
nsDisplayList *aList, ComputeTransformFunction aTransformGetter,
|
|
|
|
uint32_t aIndex)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aList)
|
|
|
|
, mTransformGetter(aTransformGetter)
|
|
|
|
, mIndex(aIndex)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "Must have a frame!");
|
|
|
|
NS_ABORT_IF_FALSE(!aFrame->IsTransformed(), "Can't specify a transform getter for a transformed frame!");
|
|
|
|
}
|
|
|
|
|
2012-09-16 03:32:59 -07:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame,
|
|
|
|
nsDisplayList *aList, uint32_t aIndex)
|
2012-09-19 16:14:07 -07:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aList)
|
|
|
|
, mTransformGetter(nullptr)
|
|
|
|
, mIndex(aIndex)
|
2012-09-16 03:32:59 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "Must have a frame!");
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame,
|
|
|
|
nsDisplayItem *aItem, uint32_t aIndex)
|
2012-09-19 16:14:07 -07:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aItem)
|
|
|
|
, mTransformGetter(nullptr)
|
|
|
|
, mIndex(aIndex)
|
2012-09-16 03:32:59 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "Must have a frame!");
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
}
|
|
|
|
|
2010-06-05 13:29:49 -07:00
|
|
|
/* Returns the delta specified by the -moz-transform-origin property.
|
2008-09-13 02:42:11 -07:00
|
|
|
* This is a positive delta, meaning that it indicates the direction to move
|
2012-07-31 10:28:21 -07:00
|
|
|
* to get from (0, 0) of the frame to the transform origin. This function is
|
|
|
|
* called off the main thread.
|
2008-09-13 02:42:11 -07:00
|
|
|
*/
|
2012-07-31 10:28:21 -07:00
|
|
|
/* static */ gfxPoint3D
|
|
|
|
nsDisplayTransform::GetDeltaToMozTransformOrigin(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get delta for a null frame!");
|
2012-05-16 21:05:09 -07:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed(),
|
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* 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. */
|
2012-07-31 10:28:21 -07:00
|
|
|
float coords[3];
|
2008-09-13 02:42:11 -07:00
|
|
|
const nscoord* dimensions[2] =
|
|
|
|
{&boundingRect.width, &boundingRect.height};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint8_t index = 0; index < 2; ++index) {
|
2008-09-13 02:42:11 -07:00
|
|
|
/* If the -moz-transform-origin specifies a percentage, take the percentage
|
|
|
|
* of the size of the box.
|
|
|
|
*/
|
2010-09-15 08:11:26 -07:00
|
|
|
const nsStyleCoord &coord = display->mTransformOrigin[index];
|
|
|
|
if (coord.GetUnit() == eStyleUnit_Calc) {
|
|
|
|
const nsStyleCoord::Calc *calc = coord.GetCalcValue();
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[index] =
|
2012-02-16 22:08:33 -08:00
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
2010-09-15 08:11:26 -07:00
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[index] =
|
2012-02-16 22:08:33 -08:00
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
2010-09-15 08:11:26 -07:00
|
|
|
coord.GetPercentValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[index] =
|
2012-02-16 22:08:33 -08:00
|
|
|
NSAppUnitsToFloatPixels(coord.GetCoordValue(), aAppUnitsPerPixel);
|
2010-09-15 08:11:26 -07:00
|
|
|
}
|
2012-05-16 21:05:09 -07:00
|
|
|
if ((aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) &&
|
|
|
|
coord.GetUnit() != eStyleUnit_Percent) {
|
|
|
|
// <length> values represent offsets from the origin of the SVG element's
|
|
|
|
// user space, not the top left of its bounds, so we must adjust for that:
|
|
|
|
nscoord offset =
|
|
|
|
(index == 0) ? aFrame->GetPosition().x : aFrame->GetPosition().y;
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[index] -= NSAppUnitsToFloatPixels(offset, aAppUnitsPerPixel);
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
2011-08-02 20:04:23 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[2] = NSAppUnitsToFloatPixels(display->mTransformOrigin[2].GetCoordValue(),
|
|
|
|
aAppUnitsPerPixel);
|
2008-09-13 02:42:11 -07:00
|
|
|
/* Adjust based on the origin of the rectangle. */
|
2012-07-31 10:28:21 -07:00
|
|
|
coords[0] += NSAppUnitsToFloatPixels(boundingRect.x, aAppUnitsPerPixel);
|
|
|
|
coords[1] += NSAppUnitsToFloatPixels(boundingRect.y, aAppUnitsPerPixel);
|
2008-09-13 02:42:11 -07:00
|
|
|
|
2012-07-31 10:28:21 -07:00
|
|
|
return gfxPoint3D(coords[0], coords[1], coords[2]);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2011-08-02 20:04:24 -07:00
|
|
|
/* Returns the delta specified by the -moz-perspective-origin property.
|
|
|
|
* This is a positive delta, meaning that it indicates the direction to move
|
2012-07-31 10:28:21 -07:00
|
|
|
* to get from (0, 0) of the frame to the perspective origin. This function is
|
|
|
|
* called off the main thread.
|
2011-08-02 20:04:24 -07:00
|
|
|
*/
|
2012-07-31 10:28:21 -07:00
|
|
|
/* static */ gfxPoint3D
|
|
|
|
nsDisplayTransform::GetDeltaToMozPerspectiveOrigin(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel)
|
2011-08-02 20:04:24 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get delta for a null frame!");
|
2012-05-16 21:05:09 -07:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed(),
|
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2011-08-02 20:04:24 -07:00
|
|
|
|
|
|
|
/* 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?
|
2012-02-15 01:28:22 -08:00
|
|
|
nsIFrame* parent = aFrame->GetParentStyleContextFrame();
|
2012-09-17 15:34:21 -07:00
|
|
|
if (!parent) {
|
|
|
|
return gfxPoint3D();
|
|
|
|
}
|
2012-04-26 17:24:53 -07:00
|
|
|
const nsStyleDisplay* display = parent->GetStyleDisplay();
|
2012-03-11 19:04:25 -07:00
|
|
|
nsRect boundingRect = nsDisplayTransform::GetFrameBoundsForTransform(parent);
|
2011-08-02 20:04:24 -07:00
|
|
|
|
|
|
|
/* 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};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint8_t index = 0; index < 2; ++index) {
|
2011-08-02 20:04:24 -07:00
|
|
|
/* 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();
|
2012-02-16 22:08:33 -08:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
2011-08-02 20:04:24 -07:00
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
2012-02-16 22:08:33 -08:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
2011-08-02 20:04:24 -07:00
|
|
|
coord.GetPercentValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
2012-02-16 22:08:33 -08:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(coord.GetCoordValue(), aAppUnitsPerPixel);
|
2011-08-02 20:04:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 01:28:22 -08:00
|
|
|
nsPoint parentOffset = aFrame->GetOffsetTo(parent);
|
2012-02-16 22:08:33 -08:00
|
|
|
gfxPoint3D gfxOffset(
|
|
|
|
NSAppUnitsToFloatPixels(parentOffset.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(parentOffset.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
2012-02-15 01:28:22 -08:00
|
|
|
|
|
|
|
return result - gfxOffset;
|
2011-08-02 20:04:24 -07:00
|
|
|
}
|
|
|
|
|
2012-09-17 15:34:21 -07:00
|
|
|
nsDisplayTransform::FrameTransformProperties::FrameTransformProperties(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
, mTransformList(aFrame->GetStyleDisplay()->mSpecifiedTransform)
|
|
|
|
, mToMozOrigin(GetDeltaToMozTransformOrigin(aFrame, aAppUnitsPerPixel, aBoundsOverride))
|
|
|
|
, mToPerspectiveOrigin(GetDeltaToMozPerspectiveOrigin(aFrame, aAppUnitsPerPixel))
|
|
|
|
, mChildPerspective(0)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* parentDisp = nullptr;
|
|
|
|
nsStyleContext* parentStyleContext = aFrame->GetStyleContext()->GetParent();
|
|
|
|
if (parentStyleContext) {
|
|
|
|
parentDisp = parentStyleContext->GetStyleDisplay();
|
|
|
|
}
|
|
|
|
if (parentDisp && parentDisp->mChildPerspective.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
mChildPerspective = parentDisp->mChildPerspective.GetCoordValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07: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.
|
|
|
|
*/
|
2012-09-17 15:34:21 -07:00
|
|
|
gfx3DMatrix
|
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(const FrameTransformProperties& aProperties,
|
|
|
|
const nsPoint& aOrigin,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride,
|
|
|
|
nsIFrame** aOutAncestor)
|
|
|
|
{
|
|
|
|
return GetResultingTransformMatrixInternal(aProperties, aOrigin, aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride, aOutAncestor);
|
|
|
|
}
|
|
|
|
|
2011-07-22 15:28:51 -07:00
|
|
|
gfx3DMatrix
|
2008-09-13 02:42:11 -07:00
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(const nsIFrame* aFrame,
|
2012-07-31 10:28:21 -07:00
|
|
|
const nsPoint& aOrigin,
|
2012-02-16 22:08:33 -08:00
|
|
|
float aAppUnitsPerPixel,
|
2011-08-26 17:01:46 -07:00
|
|
|
const nsRect* aBoundsOverride,
|
|
|
|
nsIFrame** aOutAncestor)
|
2012-09-16 03:32:59 -07:00
|
|
|
{
|
2012-09-17 15:34:21 -07:00
|
|
|
FrameTransformProperties props(aFrame,
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride);
|
|
|
|
|
|
|
|
return GetResultingTransformMatrixInternal(props, aOrigin, aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride, aOutAncestor);
|
2012-09-16 03:32:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix
|
2012-09-17 15:34:21 -07:00
|
|
|
nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProperties& aProperties,
|
2012-09-16 03:32:59 -07:00
|
|
|
const nsPoint& aOrigin,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride,
|
2012-09-25 15:47:41 -07:00
|
|
|
nsIFrame** aOutAncestor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2012-09-17 15:34:21 -07:00
|
|
|
const nsIFrame *frame = aProperties.mFrame;
|
2011-08-26 17:01:46 -07:00
|
|
|
|
|
|
|
if (aOutAncestor) {
|
2012-09-17 15:34:21 -07:00
|
|
|
*aOutAncestor = nsLayoutUtils::GetCrossDocParentFrame(frame);
|
2011-08-26 17:01:46 -07:00
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
/* Account for the -moz-transform-origin property by translating the
|
|
|
|
* coordinate space to the new origin.
|
|
|
|
*/
|
2012-02-16 22:08:33 -08:00
|
|
|
gfxPoint3D newOrigin =
|
|
|
|
gfxPoint3D(NSAppUnitsToFloatPixels(aOrigin.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aOrigin.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* Get the underlying transform matrix. This requires us to get the
|
|
|
|
* bounds of the frame.
|
|
|
|
*/
|
|
|
|
nsRect bounds = (aBoundsOverride ? *aBoundsOverride :
|
2012-09-17 15:34:21 -07:00
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(frame));
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* Get the matrix, then change its basis to factor in the origin. */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dummy;
|
2011-08-26 17:01:46 -07:00
|
|
|
gfx3DMatrix result;
|
2012-05-16 21:05:09 -07:00
|
|
|
// Call IsSVGTransformed() regardless of the value of
|
|
|
|
// disp->mSpecifiedTransform, since we still need any transformFromSVGParent.
|
|
|
|
gfxMatrix svgTransform, transformFromSVGParent;
|
|
|
|
bool hasSVGTransforms =
|
2012-09-17 15:34:21 -07:00
|
|
|
frame && frame->IsSVGTransformed(&svgTransform, &transformFromSVGParent);
|
2011-08-26 17:01:46 -07:00
|
|
|
/* Transformed frames always have a transform, or are preserving 3d (and might still have perspective!) */
|
2012-09-17 15:34:21 -07:00
|
|
|
if (aProperties.mTransformList) {
|
|
|
|
result = nsStyleTransformMatrix::ReadTransforms(aProperties.mTransformList,
|
|
|
|
frame ? frame->GetStyleContext() : nullptr,
|
|
|
|
frame ? frame->PresContext() : nullptr,
|
2012-02-16 22:08:33 -08:00
|
|
|
dummy, bounds, aAppUnitsPerPixel);
|
2012-05-16 21:05:09 -07:00
|
|
|
} else if (hasSVGTransforms) {
|
2012-07-18 06:15:13 -07:00
|
|
|
// Correct the translation components for zoom:
|
2012-09-17 15:34:21 -07:00
|
|
|
float pixelsPerCSSPx = frame->PresContext()->AppUnitsPerCSSPixel() /
|
2012-07-18 06:15:13 -07:00
|
|
|
aAppUnitsPerPixel;
|
|
|
|
svgTransform.x0 *= pixelsPerCSSPx;
|
|
|
|
svgTransform.y0 *= pixelsPerCSSPx;
|
2012-05-16 21:05:09 -07:00
|
|
|
result = gfx3DMatrix::From2D(svgTransform);
|
2011-08-26 17:01:46 -07:00
|
|
|
}
|
2011-08-02 20:04:22 -07:00
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (hasSVGTransforms && !transformFromSVGParent.IsIdentity()) {
|
2012-07-18 06:15:13 -07:00
|
|
|
// Correct the translation components for zoom:
|
2012-09-17 15:34:21 -07:00
|
|
|
float pixelsPerCSSPx = frame->PresContext()->AppUnitsPerCSSPixel() /
|
2012-07-18 06:15:13 -07:00
|
|
|
aAppUnitsPerPixel;
|
|
|
|
transformFromSVGParent.x0 *= pixelsPerCSSPx;
|
|
|
|
transformFromSVGParent.y0 *= pixelsPerCSSPx;
|
2012-05-16 21:05:09 -07:00
|
|
|
result = result * gfx3DMatrix::From2D(transformFromSVGParent);
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:34:21 -07:00
|
|
|
if (nsLayoutUtils::Are3DTransformsEnabled() && aProperties.mChildPerspective > 0.0) {
|
2011-08-02 20:04:22 -07:00
|
|
|
gfx3DMatrix perspective;
|
|
|
|
perspective._34 =
|
2012-09-17 15:34:21 -07:00
|
|
|
-1.0 / NSAppUnitsToFloatPixels(aProperties.mChildPerspective, aAppUnitsPerPixel);
|
2011-10-30 17:38:46 -07:00
|
|
|
/* At the point when perspective is applied, we have been translated to the transform origin.
|
|
|
|
* The translation to the perspective origin is the difference between these values.
|
|
|
|
*/
|
2012-09-17 15:34:21 -07:00
|
|
|
result = result * nsLayoutUtils::ChangeMatrixBasis(aProperties.mToPerspectiveOrigin - aProperties.mToMozOrigin, perspective);
|
2011-08-02 20:04:22 -07:00
|
|
|
}
|
2011-08-26 17:01:46 -07:00
|
|
|
|
2012-09-16 03:32:59 -07:00
|
|
|
gfxPoint3D rounded(hasSVGTransforms ? newOrigin.x : NS_round(newOrigin.x),
|
|
|
|
hasSVGTransforms ? newOrigin.y : NS_round(newOrigin.y),
|
|
|
|
0);
|
2012-09-25 15:47:41 -07:00
|
|
|
|
2012-09-17 15:34:21 -07:00
|
|
|
if (frame && frame->Preserves3D() && nsLayoutUtils::Are3DTransformsEnabled()) {
|
2011-08-26 17:01:46 -07:00
|
|
|
// Include the transform set on our parent
|
2012-09-17 15:34:21 -07:00
|
|
|
NS_ASSERTION(frame->GetParent() &&
|
|
|
|
frame->GetParent()->IsTransformed() &&
|
|
|
|
frame->GetParent()->Preserves3DChildren(),
|
2011-08-26 17:01:46 -07:00
|
|
|
"Preserve3D mismatch!");
|
2012-09-17 15:34:21 -07:00
|
|
|
FrameTransformProperties props(frame->GetParent(),
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
nullptr);
|
2012-07-31 10:28:21 -07:00
|
|
|
gfx3DMatrix parent =
|
2012-09-17 15:34:21 -07:00
|
|
|
GetResultingTransformMatrixInternal(props,
|
|
|
|
aOrigin - frame->GetPosition(),
|
|
|
|
aAppUnitsPerPixel, nullptr, aOutAncestor);
|
|
|
|
return nsLayoutUtils::ChangeMatrixBasis(rounded + aProperties.mToMozOrigin, result) * parent;
|
2011-08-26 17:01:46 -07:00
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
return nsLayoutUtils::ChangeMatrixBasis
|
2012-09-17 15:34:21 -07:00
|
|
|
(rounded + aProperties.mToMozOrigin, result);
|
2011-08-02 20:04:22 -07:00
|
|
|
}
|
|
|
|
|
2011-12-18 13:57:35 -08:00
|
|
|
bool
|
2012-08-25 18:27:28 -07:00
|
|
|
nsDisplayOpacity::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (GetUnderlyingFrame()->AreLayersMarkedActive(nsChangeHint_UpdateOpacityLayer)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsLayoutUtils::IsAnimationLoggingEnabled()) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation disabled because frame was not marked active for opacity animation");
|
2012-08-25 21:14:31 -07:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
|
|
|
GetUnderlyingFrame()->GetContent());
|
2012-08-25 18:27:28 -07:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayTransform::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return ShouldPrerenderTransformedContent(aBuilder,
|
|
|
|
GetUnderlyingFrame(),
|
|
|
|
nsLayoutUtils::IsAnimationLoggingEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2011-12-18 13:57:35 -08:00
|
|
|
nsDisplayTransform::ShouldPrerenderTransformedContent(nsDisplayListBuilder* aBuilder,
|
2012-08-25 18:27:28 -07:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
bool aLogAnimations)
|
|
|
|
{
|
|
|
|
if (!aFrame->AreLayersMarkedActive(nsChangeHint_UpdateTransformLayer)) {
|
|
|
|
if (aLogAnimations) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation disabled because frame was not marked active for transform animation");
|
2012-08-25 21:14:31 -07:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
|
|
|
aFrame->GetContent());
|
2012-03-01 04:34:20 -08:00
|
|
|
}
|
2012-08-25 18:27:28 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-16 03:32:59 -07:00
|
|
|
nsSize refSize = aBuilder->RootReferenceFrame()->GetSize();
|
2012-08-25 18:27:28 -07:00
|
|
|
// Only prerender if the transformed frame's size is <= the
|
|
|
|
// reference frame size (~viewport), allowing a 1/8th fuzz factor
|
|
|
|
// for shadows, borders, etc.
|
|
|
|
refSize += nsSize(refSize.width / 8, refSize.height / 8);
|
|
|
|
nsSize frameSize = aFrame->GetVisualOverflowRectRelativeToSelf().Size();
|
|
|
|
if (frameSize <= refSize) {
|
|
|
|
// Bug 717521 - pre-render max 4096 x 4096 device pixels.
|
|
|
|
nscoord max = aFrame->PresContext()->DevPixelsToAppUnits(4096);
|
|
|
|
nsRect visual = aFrame->GetVisualOverflowRect();
|
|
|
|
if (visual.width <= max && visual.height <= max) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLogAnimations) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation disabled because frame size (");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(frameSize.width));
|
|
|
|
message.AppendLiteral(", ");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(frameSize.height));
|
|
|
|
message.AppendLiteral(") is bigger than the viewport (");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(refSize.width));
|
|
|
|
message.AppendLiteral(", ");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(refSize.height));
|
|
|
|
message.AppendLiteral(")");
|
2012-08-25 18:27:28 -07:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
|
|
|
aFrame->GetContent());
|
2012-02-05 08:34:10 -08:00
|
|
|
}
|
|
|
|
return false;
|
2011-12-18 13:57:35 -08:00
|
|
|
}
|
|
|
|
|
2011-10-11 20:16:06 -07:00
|
|
|
/* If the matrix is singular, or a hidden backface is shown, the frame won't be visible or hit. */
|
2012-07-31 10:28:21 -07:00
|
|
|
static bool IsFrameVisible(nsIFrame* aFrame, const gfx3DMatrix& aMatrix)
|
2011-10-11 20:16:06 -07:00
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aFrame->GetStyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
|
|
|
aMatrix.IsBackfaceVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-02 20:04:22 -07:00
|
|
|
const gfx3DMatrix&
|
2012-02-16 22:08:33 -08:00
|
|
|
nsDisplayTransform::GetTransform(float aAppUnitsPerPixel)
|
2011-08-02 20:04:22 -07:00
|
|
|
{
|
2012-02-16 22:08:33 -08:00
|
|
|
if (mTransform.IsIdentity() || mCachedAppUnitsPerPixel != aAppUnitsPerPixel) {
|
2012-09-25 15:47:41 -07:00
|
|
|
gfxPoint3D newOrigin =
|
|
|
|
gfxPoint3D(NSAppUnitsToFloatPixels(mToReferenceFrame.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(mToReferenceFrame.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
2012-09-19 16:14:07 -07:00
|
|
|
if (mTransformGetter) {
|
|
|
|
mTransform = mTransformGetter(mFrame, aAppUnitsPerPixel);
|
|
|
|
mTransform = nsLayoutUtils::ChangeMatrixBasis(newOrigin, mTransform);
|
|
|
|
} else {
|
|
|
|
mTransform =
|
|
|
|
GetResultingTransformMatrix(mFrame, ToReferenceFrame(),
|
|
|
|
aAppUnitsPerPixel);
|
2012-09-25 15:47:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shift the coorindates to be relative to our reference frame instead of relative to this frame.
|
|
|
|
* When we have preserve-3d, our reference frame is already guaranteed to be an ancestor of the
|
|
|
|
* preserve-3d chain, so we only need to do this once.
|
|
|
|
*/
|
|
|
|
bool hasSVGTransforms = mFrame->IsSVGTransformed();
|
|
|
|
gfxPoint3D rounded(hasSVGTransforms ? newOrigin.x : NS_round(newOrigin.x),
|
|
|
|
hasSVGTransforms ? newOrigin.y : NS_round(newOrigin.y),
|
|
|
|
0);
|
|
|
|
mTransform.Translate(rounded);
|
2012-09-19 16:14:07 -07:00
|
|
|
mCachedAppUnitsPerPixel = aAppUnitsPerPixel;
|
|
|
|
}
|
2011-08-02 20:04:22 -07:00
|
|
|
}
|
2011-07-22 15:28:07 -07:00
|
|
|
return mTransform;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2010-08-01 20:07:04 -07:00
|
|
|
already_AddRefed<Layer> nsDisplayTransform::BuildLayer(nsDisplayListBuilder *aBuilder,
|
2011-06-22 05:11:27 -07:00
|
|
|
LayerManager *aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2012-07-31 10:28:21 -07:00
|
|
|
const gfx3DMatrix& newTransformMatrix =
|
2011-07-22 15:28:07 -07:00
|
|
|
GetTransform(mFrame->PresContext()->AppUnitsPerDevPixel());
|
2011-08-02 20:04:22 -07:00
|
|
|
|
2011-10-11 20:16:06 -07:00
|
|
|
if (!IsFrameVisible(mFrame, newTransformMatrix)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-08-02 20:04:22 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
|
2012-08-20 21:06:46 -07:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2012-11-02 05:59:03 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, *mStoredList.GetChildren(),
|
2011-07-22 15:28:51 -07:00
|
|
|
aContainerParameters, &newTransformMatrix);
|
2011-10-06 14:23:18 -07:00
|
|
|
|
|
|
|
// Add the preserve-3d flag for this layer, BuildContainerLayerFor clears all flags,
|
|
|
|
// so we never need to explicitely unset this flag.
|
2011-11-16 19:45:44 -08:00
|
|
|
if (mFrame->Preserves3D() || mFrame->Preserves3DChildren()) {
|
2011-10-06 14:23:18 -07:00
|
|
|
container->SetContentFlags(container->GetContentFlags() | Layer::CONTENT_PRESERVE_3D);
|
2012-12-11 21:21:23 -08:00
|
|
|
} else {
|
|
|
|
container->SetContentFlags(container->GetContentFlags() & ~Layer::CONTENT_PRESERVE_3D);
|
2011-10-06 14:23:18 -07:00
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2012-08-06 13:33:23 -07:00
|
|
|
AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, eCSSProperty_transform);
|
2012-10-02 22:55:52 -07:00
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame, false)) {
|
|
|
|
container->SetUserData(nsIFrame::LayerIsPrerenderedDataKey(),
|
|
|
|
/*the value is irrelevant*/nullptr);
|
2012-12-11 21:21:23 -08:00
|
|
|
container->SetContentFlags(container->GetContentFlags() | Layer::CONTENT_MAY_CHANGE_TRANSFORM);
|
2012-10-02 22:55:52 -07:00
|
|
|
} else {
|
|
|
|
container->RemoveUserData(nsIFrame::LayerIsPrerenderedDataKey());
|
2012-12-11 21:21:23 -08:00
|
|
|
container->SetContentFlags(container->GetContentFlags() & ~Layer::CONTENT_MAY_CHANGE_TRANSFORM);
|
2012-10-02 22:55:52 -07:00
|
|
|
}
|
2011-10-06 14:23:18 -07:00
|
|
|
return container.forget();
|
2010-08-01 20:07:04 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07:00
|
|
|
|
2010-08-01 20:07:04 -07:00
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayTransform::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters) {
|
2012-11-13 22:26:29 -08:00
|
|
|
// If the transform is 3d, or the layer takes part in preserve-3d sorting
|
|
|
|
// then we *always* want this to be an active layer.
|
|
|
|
if (!GetTransform(mFrame->PresContext()->AppUnitsPerDevPixel()).Is2D() ||
|
|
|
|
mFrame->Preserves3D()) {
|
|
|
|
return LAYER_ACTIVE_FORCE;
|
|
|
|
}
|
2011-10-26 13:10:48 -07:00
|
|
|
// Here we check if the *post-transform* bounds of this item are big enough
|
|
|
|
// to justify an active layer.
|
|
|
|
if (mFrame->AreLayersMarkedActive(nsChangeHint_UpdateTransformLayer) &&
|
|
|
|
!IsItemTooSmallForActiveLayer(this))
|
2010-08-01 20:07:04 -07:00
|
|
|
return LAYER_ACTIVE;
|
2012-07-31 10:28:21 -07:00
|
|
|
if (mFrame->GetContent()) {
|
2012-07-31 10:28:22 -07:00
|
|
|
if (nsLayoutUtils::HasAnimationsForCompositor(mFrame->GetContent(),
|
|
|
|
eCSSProperty_transform)) {
|
2012-07-31 10:28:21 -07:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
2010-08-01 20:07:04 -07:00
|
|
|
nsIFrame* activeScrolledRoot =
|
2012-07-30 07:20:58 -07:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(mFrame, nullptr);
|
2012-11-13 22:26:29 -08:00
|
|
|
return mStoredList.RequiredLayerStateForChildren(aBuilder,
|
|
|
|
aManager,
|
|
|
|
aParameters,
|
|
|
|
*mStoredList.GetChildren(),
|
|
|
|
activeScrolledRoot);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayTransform::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion *aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2009-09-06 17:35:14 -07: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-22 15:28:51 -07:00
|
|
|
* think that it's painting in its original rectangular coordinate space.
|
|
|
|
* If we can't untransform, take the entire overflow rect */
|
|
|
|
nsRect untransformedVisibleRect;
|
2012-02-14 01:12:49 -08:00
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2011-12-18 13:57:35 -08:00
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame) ||
|
2012-02-14 01:12:49 -08:00
|
|
|
!UntransformRectMatrix(mVisibleRect,
|
|
|
|
GetTransform(factor),
|
|
|
|
factor,
|
2012-07-31 10:28:21 -07:00
|
|
|
&untransformedVisibleRect))
|
2011-07-22 15:28:51 -07:00
|
|
|
{
|
2012-09-16 03:32:59 -07:00
|
|
|
untransformedVisibleRect = mFrame->GetVisualOverflowRectRelativeToSelf();
|
2011-07-22 15:28:51 -07:00
|
|
|
}
|
|
|
|
nsRegion untransformedVisible = untransformedVisibleRect;
|
2011-09-06 17:20:35 -07:00
|
|
|
// Call RecomputeVisiblity instead of ComputeVisibility since
|
2010-08-27 16:15:08 -07:00
|
|
|
// nsDisplayItem::ComputeVisibility should only be called from
|
|
|
|
// nsDisplayList::ComputeVisibility (which sets mVisibleRect on the item)
|
|
|
|
mStoredList.RecomputeVisibility(aBuilder, &untransformedVisible);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HitTest does some fun stuff with matrix transforms to obtain the answer. */
|
2010-04-07 17:31:26 -07:00
|
|
|
void nsDisplayTransform::HitTest(nsDisplayListBuilder *aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState *aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-13 02:42:11 -07: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-07 17:31:26 -07: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 02:42:11 -07:00
|
|
|
*/
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2011-07-22 15:28:51 -07:00
|
|
|
gfx3DMatrix matrix = GetTransform(factor);
|
2011-07-22 15:28:07 -07:00
|
|
|
|
2011-10-11 20:16:06 -07:00
|
|
|
if (!IsFrameVisible(mFrame, matrix)) {
|
|
|
|
return;
|
2011-08-02 20:04:22 -07:00
|
|
|
}
|
2008-09-13 02:42:11 -07: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-07 17:31:26 -07:00
|
|
|
nsRect resultingRect;
|
|
|
|
if (aRect.width == 1 && aRect.height == 1) {
|
2011-09-08 04:15:00 -07:00
|
|
|
// Magic width/height indicating we're hit testing a point, not a rect
|
2011-08-02 20:04:21 -07:00
|
|
|
gfxPoint point = matrix.Inverse().ProjectPoint(
|
|
|
|
gfxPoint(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor)));
|
2010-04-07 17:31:26 -07: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-02 20:04:21 -07:00
|
|
|
gfxRect rect = matrix.Inverse().ProjectRectBounds(originalRect);;
|
2010-04-07 17:31:26 -07:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(rect.X()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Y()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Width()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Height()), factor));
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
printf("Frame: %p\n", dynamic_cast<void *>(mFrame));
|
2010-04-07 17:31:26 -07:00
|
|
|
printf(" Untransformed point: (%f, %f)\n", resultingRect.X(), resultingRect.Y());
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t originalFrameCount = aOutFrames.Length();
|
2008-09-13 02:42:11 -07:00
|
|
|
#endif
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
mStoredList.HitTest(aBuilder, resultingRect, aState, aOutFrames);
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
#ifdef DEBUG_HIT
|
2010-04-07 17:31:26 -07: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 02:42:11 -07:00
|
|
|
printf("=== end of hit test ===\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-06 14:24:02 -07:00
|
|
|
float
|
|
|
|
nsDisplayTransform::GetHitDepthAtPoint(const nsPoint& aPoint)
|
|
|
|
{
|
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
gfx3DMatrix matrix = GetTransform(factor);
|
|
|
|
|
2011-10-11 20:16:06 -07:00
|
|
|
NS_ASSERTION(IsFrameVisible(mFrame, matrix), "We can't have hit a frame that isn't visible!");
|
2012-07-31 10:28:21 -07:00
|
|
|
|
|
|
|
gfxPoint point =
|
2011-10-06 14:24:02 -07:00
|
|
|
matrix.Inverse().ProjectPoint(gfxPoint(NSAppUnitsToFloatPixels(aPoint.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, factor)));
|
|
|
|
|
|
|
|
gfxPoint3D transformed = matrix.Transform3D(gfxPoint3D(point.x, point.y, 0));
|
|
|
|
return transformed.z;
|
|
|
|
}
|
|
|
|
|
2008-09-13 02:42:11 -07:00
|
|
|
/* The bounding rectangle for the object is the overflow rectangle translated
|
|
|
|
* by the reference point.
|
|
|
|
*/
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRect nsDisplayTransform::GetBounds(nsDisplayListBuilder *aBuilder, bool* aSnap)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2012-02-09 01:39:30 -08:00
|
|
|
nsRect untransformedBounds =
|
|
|
|
ShouldPrerenderTransformedContent(aBuilder, mFrame) ?
|
2012-09-16 03:32:59 -07:00
|
|
|
mFrame->GetVisualOverflowRectRelativeToSelf() :
|
2012-04-10 04:24:18 -07:00
|
|
|
mStoredList.GetBounds(aBuilder, aSnap);
|
|
|
|
*aSnap = false;
|
2012-02-14 01:11:31 -08:00
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2012-02-09 01:39:30 -08:00
|
|
|
return nsLayoutUtils::MatrixTransformRect(untransformedBounds,
|
|
|
|
GetTransform(factor),
|
|
|
|
factor);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is opaque iff the transform consists solely of scales and
|
2010-11-26 15:31:08 -08:00
|
|
|
* translations and if the underlying content is opaque. Thus if the transform
|
2008-09-13 02:42:11 -07:00
|
|
|
* is of the form
|
|
|
|
*
|
|
|
|
* |a c e|
|
|
|
|
* |b d f|
|
|
|
|
* |0 0 1|
|
|
|
|
*
|
|
|
|
* We need b and c to be zero.
|
2010-11-26 15:31:08 -08: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 02:42:11 -07:00
|
|
|
*/
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion nsDisplayTransform::GetOpaqueRegion(nsDisplayListBuilder *aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-07-22 15:28:51 -07:00
|
|
|
nsRect untransformedVisible;
|
2012-02-14 01:12:49 -08:00
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
2012-10-02 22:55:50 -07:00
|
|
|
// If we're going to prerender all our content, pretend like we
|
|
|
|
// don't have opqaue content so that everything under us is rendered
|
|
|
|
// as well. That will increase graphics memory usage if our frame
|
|
|
|
// covers the entire window, but it allows our transform to be
|
|
|
|
// updated extremely cheaply, without invalidating any other
|
|
|
|
// content.
|
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame) ||
|
|
|
|
!UntransformRectMatrix(mVisibleRect, GetTransform(factor), factor, &untransformedVisible)) {
|
2011-07-22 15:28:51 -07:00
|
|
|
return nsRegion();
|
|
|
|
}
|
2012-07-31 10:28:21 -07:00
|
|
|
|
2011-07-22 15:28:51 -07:00
|
|
|
const gfx3DMatrix& matrix = GetTransform(nsPresContext::AppUnitsPerCSSPixel());
|
2012-04-10 04:24:18 -07:00
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion result;
|
2011-07-22 15:28:51 -07:00
|
|
|
gfxMatrix matrix2d;
|
2012-04-10 04:24:18 -07:00
|
|
|
bool tmpSnap;
|
2011-07-22 15:28:51 -07:00
|
|
|
if (matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2012-05-02 21:29:05 -07:00
|
|
|
mStoredList.GetOpaqueRegion(aBuilder, &tmpSnap).Contains(untransformedVisible)) {
|
2011-01-02 17:48:09 -08:00
|
|
|
result = mVisibleRect;
|
|
|
|
}
|
|
|
|
return result;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is uniform if it fills the entire bounding rect and the
|
2011-01-02 17:48:09 -08:00
|
|
|
* wrapped list is uniform. See GetOpaqueRegion for discussion of why this
|
2008-09-13 02:42:11 -07:00
|
|
|
* works.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayTransform::IsUniform(nsDisplayListBuilder *aBuilder, nscolor* aColor)
|
2008-09-13 02:42:11 -07:00
|
|
|
{
|
2011-07-22 15:28:51 -07:00
|
|
|
nsRect untransformedVisible;
|
2012-02-14 01:12:49 -08:00
|
|
|
float factor = nsPresContext::AppUnitsPerCSSPixel();
|
|
|
|
if (!UntransformRectMatrix(mVisibleRect, GetTransform(factor), factor, &untransformedVisible)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-07-22 15:28:51 -07:00
|
|
|
}
|
|
|
|
const gfx3DMatrix& matrix = GetTransform(nsPresContext::AppUnitsPerCSSPixel());
|
2011-07-22 15:28:07 -07:00
|
|
|
|
2011-07-22 15:28:51 -07:00
|
|
|
gfxMatrix matrix2d;
|
|
|
|
return matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2011-07-22 15:28:07 -07:00
|
|
|
mStoredList.GetVisibleRect().Contains(untransformedVisible) &&
|
|
|
|
mStoredList.IsUniform(aBuilder, aColor);
|
2008-09-13 02:42:11 -07: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
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-09-13 02:42:11 -07:00
|
|
|
nsDisplayTransform::TryMerge(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayItem *aItem)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-09-13 02:42:11 -07:00
|
|
|
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)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* Check to see that both frames are part of the same content. */
|
|
|
|
if (aItem->GetUnderlyingFrame()->GetContent() != mFrame->GetContent())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-09-13 02:42:11 -07:00
|
|
|
|
|
|
|
/* Now, move everything over to this frame and signal that
|
|
|
|
* we merged things!
|
|
|
|
*/
|
2012-04-13 04:44:06 -07:00
|
|
|
mStoredList.MergeFrom(&static_cast<nsDisplayTransform*>(aItem)->mStoredList);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#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-24 14:55:23 -08: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 02:42:11 -07:00
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
2012-02-14 01:12:49 -08:00
|
|
|
bool nsDisplayTransform::UntransformRectMatrix(const nsRect &aUntransformedBounds,
|
|
|
|
const gfx3DMatrix& aMatrix,
|
2012-02-16 22:08:33 -08:00
|
|
|
float aAppUnitsPerPixel,
|
2012-02-14 01:12:49 -08:00
|
|
|
nsRect *aOutRect)
|
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular())
|
|
|
|
return false;
|
|
|
|
|
2012-02-16 22:08:33 -08:00
|
|
|
gfxRect result(NSAppUnitsToFloatPixels(aUntransformedBounds.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.y, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.width, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.height, aAppUnitsPerPixel));
|
2012-02-14 01:12:49 -08:00
|
|
|
|
|
|
|
/* We want to untransform the matrix, so invert the transformation first! */
|
|
|
|
result = aMatrix.Inverse().ProjectRectBounds(result);
|
|
|
|
|
2012-02-16 22:08:33 -08:00
|
|
|
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(result, aAppUnitsPerPixel);
|
2012-02-14 01:12:49 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplayTransform::UntransformRect(const nsRect &aUntransformedBounds,
|
2008-09-13 02:42:11 -07:00
|
|
|
const nsIFrame* aFrame,
|
2011-07-22 15:28:51 -07:00
|
|
|
const nsPoint &aOrigin,
|
|
|
|
nsRect* aOutRect)
|
2008-09-13 02:42:11 -07: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();
|
2012-07-31 10:28:21 -07:00
|
|
|
gfx3DMatrix matrix = GetResultingTransformMatrix(aFrame, aOrigin, factor);
|
2011-08-02 20:04:21 -07:00
|
|
|
|
2012-02-14 01:12:49 -08:00
|
|
|
return UntransformRectMatrix(aUntransformedBounds, matrix, factor, aOutRect);
|
2008-09-13 02:42:11 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplaySVGEffects::nsDisplaySVGEffects(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
2012-04-17 22:12:53 -07:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList),
|
2012-04-13 04:44:06 -07:00
|
|
|
mEffectsBounds(aFrame->GetVisualOverflowRectRelativeToSelf())
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplaySVGEffects::~nsDisplaySVGEffects()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion nsDisplaySVGEffects::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-01-02 17:48:09 -08:00
|
|
|
return nsRegion();
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2010-04-07 17:31:26 -07:00
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
2010-04-07 17:31:26 -07:00
|
|
|
nsPoint rectCenter(aRect.x + aRect.width / 2, aRect.y + aRect.height / 2);
|
2012-04-17 22:12:53 -07:00
|
|
|
if (nsSVGIntegrationUtils::HitTestFrameForEffects(mFrame,
|
|
|
|
rectCenter - ToReferenceFrame())) {
|
2010-04-07 17:31:26 -07:00
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
|
|
|
}
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 10:03:51 -07:00
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::PaintAsLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(aCtx, mFrame,
|
|
|
|
mVisibleRect,
|
|
|
|
aBuilder, aManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerState
|
|
|
|
nsDisplaySVGEffects::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
|
|
|
{
|
|
|
|
return LAYER_SVG_EFFECTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplaySVGEffects::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2012-06-10 21:44:08 -07:00
|
|
|
{
|
2012-07-20 11:12:29 -07:00
|
|
|
const nsIContent* content = mFrame->GetContent();
|
|
|
|
bool hasSVGLayout = (mFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT);
|
|
|
|
if (hasSVGLayout) {
|
|
|
|
nsISVGChildFrame *svgChildFrame = do_QueryFrame(mFrame);
|
|
|
|
if (!svgChildFrame || !mFrame->GetContent()->IsSVG()) {
|
|
|
|
NS_ASSERTION(false, "why?");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
if (!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr; // The SVG spec says not to draw filters for this
|
2012-07-20 11:12:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 10:03:51 -07:00
|
|
|
float opacity = mFrame->GetStyleDisplay()->mOpacity;
|
|
|
|
if (opacity == 0.0f)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-17 10:03:51 -07:00
|
|
|
|
|
|
|
nsIFrame* firstFrame =
|
|
|
|
nsLayoutUtils::GetFirstContinuationOrSpecialSibling(mFrame);
|
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
|
|
|
bool isOK = true;
|
2012-07-18 07:28:53 -07:00
|
|
|
effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
effectProperties.GetMaskFrame(&isOK);
|
|
|
|
effectProperties.GetFilterFrame(&isOK);
|
2012-07-17 10:03:51 -07:00
|
|
|
|
|
|
|
if (!isOK) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-17 10:03:51 -07:00
|
|
|
}
|
|
|
|
|
2012-08-20 21:06:46 -07:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2012-07-17 10:03:51 -07:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 07:20:58 -07:00
|
|
|
aContainerParameters, nullptr);
|
2012-07-17 10:03:51 -07:00
|
|
|
|
|
|
|
return container.forget();
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplaySVGEffects::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2012-04-17 22:12:53 -07:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-10-06 21:28:41 -07:00
|
|
|
nsRect dirtyRect =
|
2012-04-17 22:12:53 -07:00
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(mFrame,
|
2009-10-06 21:28:41 -07:00
|
|
|
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);
|
2012-05-09 12:53:15 -07:00
|
|
|
nsRect r = dirtyRect.Intersect(mList.GetBounds(aBuilder));
|
2012-10-24 22:32:25 -07:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, this, &childrenVisible, r, nsRect());
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsDisplaySVGEffects::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
2008-09-10 17:24:16 -07:00
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SVG_EFFECTS)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-09-10 17:24:16 -07:00
|
|
|
// 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())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-09-10 17:24:16 -07:00
|
|
|
nsDisplaySVGEffects* other = static_cast<nsDisplaySVGEffects*>(aItem);
|
2012-04-16 22:44:32 -07:00
|
|
|
MergeFromTrackingMergedFrames(other);
|
2012-04-13 04:44:06 -07:00
|
|
|
mEffectsBounds.UnionRect(mEffectsBounds,
|
2012-04-17 22:12:53 -07:00
|
|
|
other->mEffectsBounds + other->mFrame->GetOffsetTo(mFrame));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-09-10 17:24:16 -07:00
|
|
|
}
|
2011-11-16 19:44:16 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::PrintEffects(FILE* aOutput)
|
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
2012-04-17 22:12:53 -07:00
|
|
|
nsLayoutUtils::GetFirstContinuationOrSpecialSibling(mFrame);
|
2011-11-16 19:44:16 -08:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
bool first = true;
|
|
|
|
fprintf(aOutput, " effects=(");
|
2012-04-17 22:12:53 -07:00
|
|
|
if (mFrame->GetStyleDisplay()->mOpacity != 1.0f) {
|
2011-11-16 19:44:16 -08:00
|
|
|
first = false;
|
2012-04-17 22:12:53 -07:00
|
|
|
fprintf(aOutput, "opacity(%f)", mFrame->GetStyleDisplay()->mOpacity);
|
2011-11-16 19:44:16 -08:00
|
|
|
}
|
|
|
|
if (clipPathFrame) {
|
|
|
|
if (!first) {
|
|
|
|
fprintf(aOutput, ", ");
|
|
|
|
}
|
|
|
|
fprintf(aOutput, "clip(%s)", clipPathFrame->IsTrivial() ? "trivial" : "non-trivial");
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (effectProperties.GetFilterFrame(&isOK)) {
|
|
|
|
if (!first) {
|
|
|
|
fprintf(aOutput, ", ");
|
|
|
|
}
|
|
|
|
fprintf(aOutput, "filter");
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (effectProperties.GetMaskFrame(&isOK)) {
|
|
|
|
if (!first) {
|
|
|
|
fprintf(aOutput, ", ");
|
|
|
|
}
|
|
|
|
fprintf(aOutput, "mask");
|
|
|
|
}
|
|
|
|
fprintf(aOutput, ")");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|