2006-01-26 05:29:17 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2006-04-18 03:16:46 +04:00
|
|
|
* vim: set ts=2 sw=2 et tw=78:
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2006-01-26 05:29:17 +03:00
|
|
|
*/
|
|
|
|
|
2006-03-30 09:56:38 +04:00
|
|
|
/*
|
|
|
|
* structures that represent things to be painted (ordered in z-order),
|
|
|
|
* used during painting and hit testing
|
|
|
|
*/
|
|
|
|
|
2012-12-12 02:49:57 +04:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2013-04-24 22:42:40 +04:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
#include "nsCSSRendering.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsRegion.h"
|
2008-07-17 10:30:25 +04:00
|
|
|
#include "nsStyleStructInlines.h"
|
2008-09-13 13:42:11 +04:00
|
|
|
#include "nsStyleTransformMatrix.h"
|
|
|
|
#include "gfxMatrix.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2009-07-22 04:44:57 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2010-07-16 01:08:12 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2010-07-24 13:35:29 +04:00
|
|
|
#include "nsThemeConstants.h"
|
2012-08-29 09:47:18 +04:00
|
|
|
#include "LayerTreeInvalidation.h"
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2009-04-08 19:19:51 +04:00
|
|
|
#include "imgIContainer.h"
|
2010-03-01 10:56:19 +03:00
|
|
|
#include "BasicLayers.h"
|
2010-11-30 17:59:46 +03:00
|
|
|
#include "nsBoxFrame.h"
|
2011-04-08 20:35:16 +04:00
|
|
|
#include "nsViewportFrame.h"
|
2013-08-13 11:56:57 +04:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2011-11-17 07:44:16 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-07-20 22:12:29 +04:00
|
|
|
#include "nsSVGElement.h"
|
2011-11-17 07:44:16 +04:00
|
|
|
#include "nsSVGClipPathFrame.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-07-31 21:28:21 +04:00
|
|
|
#include "nsAnimationManager.h"
|
2012-07-31 21:28:22 +04:00
|
|
|
#include "nsTransitionManager.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "ImageLayers.h"
|
|
|
|
#include "ImageContainer.h"
|
2012-12-13 05:15:55 +04:00
|
|
|
#include "nsCanvasFrame.h"
|
2013-09-13 05:56:57 +04:00
|
|
|
#include "StickyScrollContainer.h"
|
2013-08-30 21:22:33 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-04 15:30:57 +04:00
|
|
|
#include "ActiveLayerTracker.h"
|
2013-09-23 23:09:48 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-01-27 02:07:08 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2012-04-12 04:17:44 +04:00
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
using namespace mozilla;
|
2012-08-26 05:27:28 +04:00
|
|
|
using namespace mozilla::css;
|
2010-03-01 10:56:19 +03:00
|
|
|
using namespace mozilla::layers;
|
2012-12-12 02:49:57 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-01-13 20:45:14 +03:00
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2012-07-31 21:28:21 +04: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:
|
|
|
|
{
|
2013-05-21 14:22:44 +04:00
|
|
|
double x = array->Item(1).GetAngleValueInRadians();
|
2012-07-31 21:28:21 +04:00
|
|
|
aFunctions.AppendElement(SkewX(x));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_skewy:
|
|
|
|
{
|
2013-05-21 14:22:44 +04:00
|
|
|
double y = array->Item(1).GetAngleValueInRadians();
|
2012-07-31 21:28:21 +04:00
|
|
|
aFunctions.AppendElement(SkewY(y));
|
|
|
|
break;
|
|
|
|
}
|
2013-05-21 14:22:44 +04:00
|
|
|
case eCSSKeyword_skew:
|
|
|
|
{
|
|
|
|
double x = array->Item(1).GetAngleValueInRadians();
|
|
|
|
// skew(x) is shorthand for skew(x, 0)
|
|
|
|
double y = 0;
|
|
|
|
if (array->Count() == 3) {
|
|
|
|
y = array->Item(2).GetAngleValueInRadians();
|
|
|
|
}
|
|
|
|
aFunctions.AppendElement(Skew(x, y));
|
|
|
|
break;
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
case eCSSKeyword_matrix:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix;
|
|
|
|
matrix._11 = array->Item(1).GetFloatValue();
|
|
|
|
matrix._12 = array->Item(2).GetFloatValue();
|
|
|
|
matrix._13 = 0;
|
2013-06-03 00:35:17 +04:00
|
|
|
matrix._14 = 0;
|
2013-05-31 22:06:56 +04:00
|
|
|
matrix._21 = array->Item(3).GetFloatValue();
|
|
|
|
matrix._22 = array->Item(4).GetFloatValue();
|
2012-07-31 21:28:21 +04:00
|
|
|
matrix._23 = 0;
|
2013-06-03 00:35:17 +04:00
|
|
|
matrix._24 = 0;
|
2012-07-31 21:28:21 +04:00
|
|
|
matrix._31 = 0;
|
|
|
|
matrix._32 = 0;
|
|
|
|
matrix._33 = 1;
|
|
|
|
matrix._34 = 0;
|
2013-06-03 00:35:17 +04:00
|
|
|
matrix._41 = array->Item(5).GetFloatValue();
|
|
|
|
matrix._42 = array->Item(6).GetFloatValue();
|
2012-07-31 21:28:21 +04:00
|
|
|
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-12 01:12:43 +04:00
|
|
|
case eCSSKeyword_interpolatematrix:
|
|
|
|
{
|
|
|
|
gfx3DMatrix matrix;
|
|
|
|
nsStyleTransformMatrix::ProcessInterpolateMatrix(matrix, array,
|
|
|
|
aContext,
|
|
|
|
aPresContext,
|
|
|
|
canStoreInRuleTree,
|
|
|
|
aBounds,
|
|
|
|
aAppUnitsPerPixel);
|
|
|
|
aFunctions.AppendElement(TransformMatrix(matrix));
|
|
|
|
break;
|
|
|
|
}
|
2012-07-31 21:28:21 +04: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 19:56:38 +04:00
|
|
|
uint32_t type = aCTF.GetType() == nsTimingFunction::StepStart ? 1 : 2;
|
2012-07-31 21:28:21 +04:00
|
|
|
return TimingFunction(StepFunction(aCTF.GetSteps(), type));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-31 21:28:22 +04:00
|
|
|
AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
|
|
|
|
ElementAnimation* ea, Layer* aLayer,
|
|
|
|
AnimationData& aData)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aLayer->AsContainerLayer(), "Should only animate ContainerLayer");
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* styleContext = aFrame->StyleContext();
|
2012-07-31 21:28:22 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
nsRect bounds = nsDisplayTransform::GetFrameBoundsForTransform(aFrame);
|
2013-02-13 01:00:54 +04:00
|
|
|
// all data passed directly to the compositor should be in css pixels
|
|
|
|
float scale = nsDeviceContext::AppUnitsPerCSSPixel();
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2013-01-11 09:14:51 +04:00
|
|
|
TimeStamp startTime = ea->mStartTime + ea->mDelay;
|
2012-08-20 17:35:42 +04:00
|
|
|
TimeDuration duration = ea->mIterationDuration;
|
2012-07-31 21:28:22 +04:00
|
|
|
float iterations = ea->mIterationCount != NS_IEEEPositiveInfinity()
|
|
|
|
? ea->mIterationCount : -1;
|
2012-08-20 17:35:42 +04:00
|
|
|
int direction = ea->mDirection;
|
|
|
|
|
2012-08-21 08:06:47 +04:00
|
|
|
Animation* animation = aLayer->AddAnimation(startTime, duration,
|
|
|
|
iterations, direction,
|
|
|
|
aProperty, aData);
|
2012-08-20 17:35:42 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t propIdx = 0; propIdx < ea->mProperties.Length(); propIdx++) {
|
2012-07-31 21:28:22 +04:00
|
|
|
AnimationProperty* property = &ea->mProperties[propIdx];
|
|
|
|
|
|
|
|
if (aProperty != property->mProperty) {
|
2012-07-31 21:28:21 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t segIdx = 0; segIdx < property->mSegments.Length(); segIdx++) {
|
2012-07-31 21:28:22 +04:00
|
|
|
AnimationPropertySegment* segment = &property->mSegments[segIdx];
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2012-08-21 08:06:47 +04:00
|
|
|
AnimationSegment* animSegment = animation->segments().AppendElement();
|
2012-07-31 21:28:22 +04:00
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2012-08-20 17:35:42 +04:00
|
|
|
animSegment->startState() = InfallibleTArray<TransformFunction>();
|
|
|
|
animSegment->endState() = InfallibleTArray<TransformFunction>();
|
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
nsCSSValueSharedList* list = segment->mFromValue.GetCSSValueSharedListValue();
|
|
|
|
AddTransformFunctions(list->mHead, styleContext, presContext, bounds, scale,
|
2012-08-20 17:35:42 +04:00
|
|
|
animSegment->startState().get_ArrayOfTransformFunction());
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2013-12-12 06:09:44 +04:00
|
|
|
list = segment->mToValue.GetCSSValueSharedListValue();
|
|
|
|
AddTransformFunctions(list->mHead, styleContext, presContext, bounds, scale,
|
2012-08-20 17:35:42 +04:00
|
|
|
animSegment->endState().get_ArrayOfTransformFunction());
|
2012-07-31 21:28:22 +04:00
|
|
|
} else if (aProperty == eCSSProperty_opacity) {
|
2012-08-20 17:35:42 +04:00
|
|
|
animSegment->startState() = segment->mFromValue.GetFloatValue();
|
|
|
|
animSegment->endState() = segment->mToValue.GetFloatValue();
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-08-20 17:35:42 +04:00
|
|
|
|
|
|
|
animSegment->startPortion() = segment->mFromKey;
|
|
|
|
animSegment->endPortion() = segment->mToKey;
|
|
|
|
animSegment->sampleFn() = ToTimingFunction(segment->mTimingFunction);
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-07 00:33:23 +04:00
|
|
|
AddAnimationsAndTransitionsToLayer(Layer* aLayer, nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem, nsCSSProperty aProperty)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2012-07-31 21:28:22 +04:00
|
|
|
aLayer->ClearAnimations();
|
|
|
|
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* frame = aItem->Frame();
|
2012-08-07 00:33:23 +04:00
|
|
|
|
2012-09-20 03:14:07 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
ElementTransitions* et =
|
2012-09-20 03:14:07 +04:00
|
|
|
nsTransitionManager::GetTransitionsForCompositor(content, aProperty);
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
|
|
ElementAnimations* ea =
|
2012-09-20 03:14:07 +04:00
|
|
|
nsAnimationManager::GetAnimationsForCompositor(content, aProperty);
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
|
|
if (!ea && !et) {
|
2012-07-31 21:28:21 +04:00
|
|
|
return;
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2013-10-22 14:30:45 +04:00
|
|
|
// If the frame is not prerendered, bail out.
|
2012-08-23 10:05:27 +04:00
|
|
|
if (!aItem->CanUseAsyncAnimations(aBuilder)) {
|
2013-10-22 14:30:45 +04:00
|
|
|
// AnimationManager or TransitionManager need to know that we refused to
|
|
|
|
// run this animation asynchronously so that they will not throttle the
|
|
|
|
// main thread animation.
|
|
|
|
frame->Properties().Set(nsIFrame::RefusedAsyncAnimation(),
|
|
|
|
reinterpret_cast<void*>(intptr_t(true)));
|
|
|
|
|
|
|
|
// We need to schedule another refresh driver run so that AnimationManager
|
|
|
|
// or TransitionManager get a chance to unthrottle the animation.
|
|
|
|
frame->SchedulePaint();
|
2012-08-07 00:33:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:22 +04:00
|
|
|
mozilla::TimeStamp currentTime =
|
|
|
|
frame->PresContext()->RefreshDriver()->MostRecentRefresh();
|
|
|
|
AnimationData data;
|
|
|
|
if (aProperty == eCSSProperty_transform) {
|
|
|
|
nsRect bounds = nsDisplayTransform::GetFrameBoundsForTransform(frame);
|
2013-02-13 01:00:54 +04:00
|
|
|
// all data passed directly to the compositor should be in css pixels
|
2012-07-31 21:28:22 +04:00
|
|
|
float scale = nsDeviceContext::AppUnitsPerCSSPixel();
|
|
|
|
gfxPoint3D offsetToTransformOrigin =
|
2013-10-24 16:46:00 +04:00
|
|
|
nsDisplayTransform::GetDeltaToTransformOrigin(frame, scale, &bounds);
|
2012-07-31 21:28:22 +04:00
|
|
|
gfxPoint3D offsetToPerspectiveOrigin =
|
2013-10-24 16:46:00 +04:00
|
|
|
nsDisplayTransform::GetDeltaToPerspectiveOrigin(frame, scale);
|
2012-07-31 21:28:22 +04:00
|
|
|
nscoord perspective = 0.0;
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* parentStyleContext = frame->StyleContext()->GetParent();
|
2012-07-31 21:28:22 +04:00
|
|
|
if (parentStyleContext) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* disp = parentStyleContext->StyleDisplay();
|
2012-07-31 21:28:22 +04:00
|
|
|
if (disp && disp->mChildPerspective.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
perspective = disp->mChildPerspective.GetCoordValue();
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
|
|
|
nsPoint origin = aItem->ToReferenceFrame();
|
|
|
|
|
|
|
|
data = TransformData(origin, offsetToTransformOrigin,
|
2013-02-13 01:00:54 +04:00
|
|
|
offsetToPerspectiveOrigin, bounds, perspective,
|
|
|
|
frame->PresContext()->AppUnitsPerDevPixel());
|
2012-07-31 21:28:22 +04:00
|
|
|
} else if (aProperty == eCSSProperty_opacity) {
|
|
|
|
data = null_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (et) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t tranIdx = 0; tranIdx < et->mPropertyTransitions.Length(); tranIdx++) {
|
2012-07-31 21:28:22 +04:00
|
|
|
ElementPropertyTransition* pt = &et->mPropertyTransitions[tranIdx];
|
2012-08-22 05:48:47 +04:00
|
|
|
if (pt->mProperty != aProperty || !pt->IsRunningAt(currentTime)) {
|
2012-08-21 08:06:47 +04:00
|
|
|
continue;
|
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
|
|
ElementAnimation anim;
|
|
|
|
anim.mIterationCount = 1;
|
|
|
|
anim.mDirection = NS_STYLE_ANIMATION_DIRECTION_NORMAL;
|
|
|
|
anim.mFillMode = NS_STYLE_ANIMATION_FILL_MODE_NONE;
|
2013-01-11 09:14:51 +04:00
|
|
|
// Transition mStartTime is end-of-delay; animation mStartTime
|
|
|
|
// is start-of-delay, so set delay here to 0.
|
2012-07-31 21:28:22 +04:00
|
|
|
anim.mStartTime = pt->mStartTime;
|
2013-01-11 09:14:51 +04:00
|
|
|
anim.mDelay = TimeDuration::FromMilliseconds(0);
|
2012-07-31 21:28:22 +04:00
|
|
|
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-23 08:52:13 +04:00
|
|
|
|
|
|
|
pt->mIsRunningOnCompositor = true;
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
2012-12-12 01:12:43 +04:00
|
|
|
aLayer->SetAnimationGeneration(et->mAnimationGeneration);
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2012-07-31 21:28:22 +04:00
|
|
|
if (ea) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t animIdx = 0; animIdx < ea->mAnimations.Length(); animIdx++) {
|
2012-07-31 21:28:22 +04:00
|
|
|
ElementAnimation* anim = &ea->mAnimations[animIdx];
|
2012-08-21 08:06:47 +04:00
|
|
|
if (!(anim->HasAnimationOfProperty(aProperty) &&
|
2012-08-22 05:48:47 +04:00
|
|
|
anim->IsRunningAt(currentTime))) {
|
2012-07-31 21:28:22 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
AddAnimationsForProperty(frame, aProperty, anim,
|
|
|
|
aLayer, data);
|
|
|
|
}
|
2012-12-12 01:12:43 +04:00
|
|
|
aLayer->SetAnimationGeneration(ea->mAnimationGeneration);
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListBuilder::nsDisplayListBuilder(nsIFrame* aReferenceFrame,
|
2011-09-29 10:19:26 +04:00
|
|
|
Mode aMode, bool aBuildCaret)
|
2006-01-26 05:29:17 +03:00
|
|
|
: mReferenceFrame(aReferenceFrame),
|
2012-07-30 18:20:58 +04:00
|
|
|
mIgnoreScrollFrame(nullptr),
|
2013-12-16 15:22:11 +04:00
|
|
|
mLayerEventRegions(nullptr),
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentTableItem(nullptr),
|
|
|
|
mFinalTransparentRegion(nullptr),
|
2012-04-18 09:14:14 +04:00
|
|
|
mCachedOffsetFrame(aReferenceFrame),
|
2012-09-16 14:32:59 +04:00
|
|
|
mCachedReferenceFrame(aReferenceFrame),
|
2012-04-18 09:14:14 +04:00
|
|
|
mCachedOffset(0, 0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mGlassDisplayItem(nullptr),
|
2010-11-08 12:06:14 +03:00
|
|
|
mMode(aMode),
|
2010-12-04 12:58:39 +03:00
|
|
|
mBuildCaret(aBuildCaret),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIgnoreSuppression(false),
|
|
|
|
mHadToIgnoreSuppression(false),
|
|
|
|
mIsAtRootOfPseudoStackingContext(false),
|
|
|
|
mIncludeAllOutOfFlows(false),
|
2013-12-18 09:37:24 +04:00
|
|
|
mDescendIntoSubdocuments(true),
|
2011-10-17 18:59:28 +04:00
|
|
|
mSelectedFramesOnly(false),
|
|
|
|
mAccurateVisibleRegions(false),
|
2012-10-06 17:03:23 +04:00
|
|
|
mAllowMergingAndFlattening(true),
|
|
|
|
mWillComputePluginGeometry(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mInTransform(false),
|
|
|
|
mSyncDecodeImages(false),
|
|
|
|
mIsPaintingToWindow(false),
|
2012-10-18 09:34:58 +04:00
|
|
|
mIsCompositingCheap(false),
|
2013-09-15 07:30:00 +04:00
|
|
|
mContainsPluginItem(false),
|
2013-12-16 15:22:11 +04:00
|
|
|
mContainsBlendMode(false),
|
|
|
|
mAncestorHasTouchEventHandler(false)
|
2011-04-08 20:35:16 +04:00
|
|
|
{
|
2010-06-21 20:21:41 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayListBuilder);
|
2010-07-20 05:29:25 +04:00
|
|
|
PL_InitArenaPool(&mPool, "displayListArena", 1024,
|
2013-01-15 16:22:03 +04:00
|
|
|
std::max(NS_ALIGNMENT_OF(void*),NS_ALIGNMENT_OF(double))-1);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
2006-01-26 05:29:17 +03:00
|
|
|
nsIPresShell *shell = pc->PresShell();
|
|
|
|
if (pc->IsRenderingOnlySelection()) {
|
|
|
|
nsCOMPtr<nsISelectionController> selcon(do_QueryInterface(shell));
|
|
|
|
if (selcon) {
|
|
|
|
selcon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(mBoundingSelection));
|
|
|
|
}
|
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2012-11-19 14:54:41 +04:00
|
|
|
nsCSSRendering::BeginFrameTreesLocked();
|
2010-07-16 01:08:10 +04:00
|
|
|
PR_STATIC_ASSERT(nsDisplayItem::TYPE_MAX < (1 << nsDisplayItem::TYPE_BITS));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
static void MarkFrameForDisplay(nsIFrame* aFrame, nsIFrame* aStopAtFrame) {
|
2006-10-19 05:47:47 +04:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
2012-06-08 16:22:25 +04:00
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(f)) {
|
2006-04-27 06:45:03 +04:00
|
|
|
if (f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO)
|
|
|
|
return;
|
|
|
|
f->AddStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
if (f == aStopAtFrame) {
|
|
|
|
// we've reached a frame that we know will be painted, so we can stop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 20:35:16 +04:00
|
|
|
void nsDisplayListBuilder::MarkOutOfFlowFrameForDisplay(nsIFrame* aDirtyFrame,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
2013-09-27 10:01:15 +04:00
|
|
|
nsRect dirtyRectRelativeToDirtyFrame = aDirtyRect;
|
|
|
|
nsRect displayPort;
|
|
|
|
if (nsLayoutUtils::IsFixedPosFrameInDisplayPort(aFrame, &displayPort)) {
|
|
|
|
NS_ASSERTION(aDirtyFrame == aFrame->GetParent(), "Dirty frame should be viewport frame");
|
|
|
|
dirtyRectRelativeToDirtyFrame = displayPort;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect dirty = dirtyRectRelativeToDirtyFrame - aFrame->GetOffsetTo(aDirtyFrame);
|
2010-10-07 08:25:47 +04:00
|
|
|
nsRect overflowRect = aFrame->GetVisualOverflowRect();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
2013-03-19 17:08:29 +04:00
|
|
|
if (aFrame->IsTransformed() &&
|
|
|
|
nsLayoutUtils::HasAnimationsForCompositor(aFrame->GetContent(),
|
|
|
|
eCSSProperty_transform)) {
|
|
|
|
/**
|
|
|
|
* Add a fuzz factor to the overflow rectangle so that elements only just
|
|
|
|
* out of view are pulled into the display list, so they can be
|
|
|
|
* prerendered if necessary.
|
|
|
|
*/
|
|
|
|
overflowRect.Inflate(nsPresContext::CSSPixelsToAppUnits(32));
|
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
if (!dirty.IntersectRect(dirty, overflowRect))
|
|
|
|
return;
|
2013-06-18 13:15:39 +04:00
|
|
|
const DisplayItemClip* clip = mClipState.GetClipForContainingBlockDescendants();
|
|
|
|
OutOfFlowDisplayData* data = clip ? new OutOfFlowDisplayData(*clip, dirty)
|
|
|
|
: new OutOfFlowDisplayData(dirty);
|
|
|
|
aFrame->Properties().Set(nsDisplayListBuilder::OutOfFlowDisplayDataProperty(), data);
|
2006-04-27 06:45:03 +04:00
|
|
|
|
|
|
|
MarkFrameForDisplay(aFrame, aDirtyFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnmarkFrameForDisplay(nsIFrame* aFrame) {
|
2010-03-29 05:46:55 +04:00
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
|
|
|
presContext->PropertyTable()->
|
2013-03-04 13:56:02 +04:00
|
|
|
Delete(aFrame, nsDisplayListBuilder::OutOfFlowDisplayDataProperty());
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
for (nsIFrame* f = aFrame; f;
|
2012-06-08 16:22:25 +04:00
|
|
|
f = nsLayoutUtils::GetParentOrPlaceholderFor(f)) {
|
2006-04-27 06:45:03 +04:00
|
|
|
if (!(f->GetStateBits() & NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO))
|
|
|
|
return;
|
|
|
|
f->RemoveStateBits(NS_FRAME_FORCE_DISPLAY_LIST_DESCEND_INTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-11 01:47:14 +04:00
|
|
|
static void AdjustForScrollBars(ScreenIntRect& aToAdjust, nsIScrollableFrame* aScrollableFrame) {
|
|
|
|
if (aScrollableFrame && !LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars)) {
|
|
|
|
nsMargin sizes = aScrollableFrame->GetActualScrollbarSizes();
|
|
|
|
// Scrollbars are not subject to scaling, so CSS pixels = screen pixels for them.
|
|
|
|
ScreenIntMargin boundMargins = RoundedToInt(CSSMargin::FromAppUnits(sizes) * CSSToScreenScale(1.0f));
|
|
|
|
aToAdjust.Deflate(boundMargins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
static void RecordFrameMetrics(nsIFrame* aForFrame,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrollFrame,
|
2013-09-06 02:36:07 +04:00
|
|
|
const nsIFrame* aReferenceFrame,
|
2011-01-13 20:45:14 +03:00
|
|
|
ContainerLayer* aRoot,
|
2011-06-22 16:11:28 +04:00
|
|
|
const nsRect& aVisibleRect,
|
|
|
|
const nsRect& aViewport,
|
2011-03-10 00:35:27 +03:00
|
|
|
nsRect* aDisplayPort,
|
2012-11-22 02:34:18 +04:00
|
|
|
nsRect* aCriticalDisplayPort,
|
2011-06-22 16:11:28 +04:00
|
|
|
ViewID aScrollId,
|
2013-11-09 04:07:00 +04:00
|
|
|
bool aIsRoot,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2011-01-13 20:45:14 +03:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2013-06-22 01:03:56 +04:00
|
|
|
LayoutDeviceToLayerScale resolution(aContainerParameters.mXScale, aContainerParameters.mYScale);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-06-22 16:11:28 +04:00
|
|
|
nsIntRect visible = aVisibleRect.ScaleToNearestPixels(
|
2013-06-22 01:03:56 +04:00
|
|
|
resolution.scale, resolution.scale, auPerDevPixel);
|
2013-07-02 19:16:05 +04:00
|
|
|
aRoot->SetVisibleRegion(visible);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
FrameMetrics metrics;
|
2013-06-10 17:05:43 +04:00
|
|
|
metrics.mViewport = CSSRect::FromAppUnits(aViewport);
|
2011-03-10 00:35:27 +03:00
|
|
|
if (aDisplayPort) {
|
2013-06-10 17:05:42 +04:00
|
|
|
metrics.mDisplayPort = CSSRect::FromAppUnits(*aDisplayPort);
|
|
|
|
if (aCriticalDisplayPort) {
|
|
|
|
metrics.mCriticalDisplayPort = CSSRect::FromAppUnits(*aCriticalDisplayPort);
|
|
|
|
}
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIScrollableFrame* scrollableFrame = nullptr;
|
2011-05-02 05:53:01 +04:00
|
|
|
if (aScrollFrame)
|
|
|
|
scrollableFrame = aScrollFrame->GetScrollTargetFrame();
|
2011-03-16 02:20:19 +03:00
|
|
|
|
|
|
|
if (scrollableFrame) {
|
2012-05-23 18:51:39 +04:00
|
|
|
nsRect contentBounds = scrollableFrame->GetScrollRange();
|
2013-11-27 03:46:47 +04:00
|
|
|
if (scrollableFrame->GetScrollbarStyles().mVertical == NS_STYLE_OVERFLOW_HIDDEN) {
|
2014-01-21 21:33:52 +04:00
|
|
|
metrics.SetDisableScrollingY(true);
|
2013-11-27 03:46:47 +04:00
|
|
|
}
|
|
|
|
if (scrollableFrame->GetScrollbarStyles().mHorizontal == NS_STYLE_OVERFLOW_HIDDEN) {
|
2014-01-21 21:33:52 +04:00
|
|
|
metrics.SetDisableScrollingX(true);
|
2013-11-27 03:46:47 +04:00
|
|
|
}
|
2012-05-23 18:51:39 +04:00
|
|
|
contentBounds.width += scrollableFrame->GetScrollPortRect().width;
|
|
|
|
contentBounds.height += scrollableFrame->GetScrollPortRect().height;
|
2013-06-03 17:52:44 +04:00
|
|
|
metrics.mScrollableRect = CSSRect::FromAppUnits(contentBounds);
|
2012-08-22 08:37:15 +04:00
|
|
|
nsPoint scrollPosition = scrollableFrame->GetScrollPosition();
|
2013-05-31 05:30:13 +04:00
|
|
|
metrics.mScrollOffset = CSSPoint::FromAppUnits(scrollPosition);
|
2013-12-16 21:04:45 +04:00
|
|
|
|
|
|
|
// If the frame was scrolled since the last layers update, and by
|
|
|
|
// something other than the APZ code, we want to tell the APZ to update
|
|
|
|
// its scroll offset.
|
|
|
|
nsIAtom* originOfLastScroll = scrollableFrame->OriginOfLastScroll();
|
|
|
|
metrics.mUpdateScrollOffset = (originOfLastScroll && originOfLastScroll != nsGkAtoms::apz);
|
|
|
|
scrollableFrame->ResetOriginOfLastScroll();
|
2011-01-19 19:56:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2012-05-23 18:51:39 +04:00
|
|
|
nsRect contentBounds = aForFrame->GetRect();
|
2013-06-03 17:52:44 +04:00
|
|
|
metrics.mScrollableRect = CSSRect::FromAppUnits(contentBounds);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2011-01-19 19:56:22 +03:00
|
|
|
metrics.mScrollId = aScrollId;
|
2013-11-09 04:07:00 +04:00
|
|
|
metrics.mIsRoot = aIsRoot;
|
2012-04-25 06:48:33 +04:00
|
|
|
|
2013-11-05 06:39:44 +04:00
|
|
|
// Only the root scrollable frame for a given presShell should pick up
|
|
|
|
// the presShell's resolution. All the other frames are 1.0.
|
2012-04-25 06:48:33 +04:00
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
2013-11-05 06:39:44 +04:00
|
|
|
if (aScrollFrame == presShell->GetRootScrollFrame()) {
|
2013-09-06 02:26:59 +04:00
|
|
|
metrics.mResolution = ParentLayerToLayerScale(presShell->GetXResolution(),
|
|
|
|
presShell->GetYResolution());
|
2013-08-30 21:11:01 +04:00
|
|
|
} else {
|
2013-09-06 02:26:59 +04:00
|
|
|
metrics.mResolution = ParentLayerToLayerScale(1.0f);
|
2012-12-12 02:49:57 +04:00
|
|
|
}
|
2013-09-06 02:26:59 +04:00
|
|
|
|
2013-11-05 06:39:44 +04:00
|
|
|
// For the cumulateive resolution, multiply the resolutions of all the
|
|
|
|
// presShells back up to the root
|
2013-09-06 02:26:59 +04:00
|
|
|
metrics.mCumulativeResolution = LayoutDeviceToLayerScale(1.0f);
|
|
|
|
nsIPresShell* curPresShell = presShell;
|
|
|
|
while (curPresShell != nullptr) {
|
|
|
|
ParentLayerToLayerScale presShellResolution(curPresShell->GetXResolution(),
|
|
|
|
curPresShell->GetYResolution());
|
|
|
|
metrics.mCumulativeResolution.scale *= presShellResolution.scale;
|
|
|
|
nsPresContext* parentContext = curPresShell->GetPresContext()->GetParentPresContext();
|
|
|
|
curPresShell = parentContext ? parentContext->GetPresShell() : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-06-22 01:03:56 +04:00
|
|
|
metrics.mDevPixelsPerCSSPixel = CSSToLayoutDeviceScale(
|
|
|
|
(float)nsPresContext::AppUnitsPerCSSPixel() / auPerDevPixel);
|
2012-09-29 06:16:34 +04:00
|
|
|
|
2013-08-30 21:22:33 +04:00
|
|
|
// Initially, AsyncPanZoomController should render the content to the screen
|
|
|
|
// at the painted resolution.
|
|
|
|
const LayerToScreenScale layerToScreenScale(1.0f);
|
2013-09-06 02:26:59 +04:00
|
|
|
metrics.mZoom = metrics.mCumulativeResolution * metrics.mDevPixelsPerCSSPixel
|
2013-08-30 21:22:33 +04:00
|
|
|
* layerToScreenScale;
|
2013-08-30 21:11:01 +04:00
|
|
|
|
2013-10-30 05:51:00 +04:00
|
|
|
if (presShell) {
|
|
|
|
nsIDocument* document = nullptr;
|
|
|
|
document = presShell->GetDocument();
|
|
|
|
if (document) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> innerWin(document->GetInnerWindow());
|
|
|
|
if (innerWin) {
|
|
|
|
metrics.mMayHaveTouchListeners = innerWin->HasTouchEventListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 08:37:06 +04:00
|
|
|
|
2013-09-06 02:36:07 +04:00
|
|
|
// Calculate the composition bounds as the size of the scroll frame and
|
|
|
|
// its origin relative to the reference frame.
|
|
|
|
// If aScrollFrame is null, we are in a document without a root scroll frame,
|
|
|
|
// so it's a xul document. In this case, use the size of the viewport frame.
|
|
|
|
nsIFrame* frameForCompositionBoundsCalculation = aScrollFrame ? aScrollFrame : aForFrame;
|
|
|
|
nsRect compositionBounds(frameForCompositionBoundsCalculation->GetOffsetToCrossDoc(aReferenceFrame),
|
|
|
|
frameForCompositionBoundsCalculation->GetSize());
|
|
|
|
metrics.mCompositionBounds = RoundedToInt(LayoutDeviceRect::FromAppUnits(compositionBounds, auPerDevPixel)
|
2013-09-06 02:26:59 +04:00
|
|
|
* metrics.mCumulativeResolution
|
2013-09-06 02:36:07 +04:00
|
|
|
* layerToScreenScale);
|
|
|
|
|
2013-09-11 01:47:14 +04:00
|
|
|
// For the root scroll frame of the root content document, clamp the
|
|
|
|
// composition bounds to the widget bounds. This is necessary because, if
|
|
|
|
// the page is zoomed in, the frame's size might be larger than the widget
|
|
|
|
// bounds, but we don't want the composition bounds to be.
|
|
|
|
bool useWidgetBounds = false;
|
2013-09-27 23:15:57 +04:00
|
|
|
bool isRootContentDocRootScrollFrame = presContext->IsRootContentDocument()
|
|
|
|
&& aScrollFrame == presShell->GetRootScrollFrame();
|
2013-09-11 01:47:14 +04:00
|
|
|
if (isRootContentDocRootScrollFrame) {
|
|
|
|
if (nsIWidget* widget = aForFrame->GetNearestWidget()) {
|
|
|
|
nsIntRect bounds;
|
|
|
|
widget->GetBounds(bounds);
|
|
|
|
ScreenIntRect screenBounds = ScreenIntRect::FromUnknownRect(mozilla::gfx::IntRect(
|
|
|
|
bounds.x, bounds.y, bounds.width, bounds.height));
|
|
|
|
AdjustForScrollBars(screenBounds, scrollableFrame);
|
2014-01-06 19:05:07 +04:00
|
|
|
metrics.mCompositionBounds = metrics.mCompositionBounds.ForceInside(screenBounds);
|
2013-09-11 01:47:14 +04:00
|
|
|
useWidgetBounds = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 02:36:07 +04:00
|
|
|
// Adjust composition bounds for the size of scroll bars.
|
2013-09-11 01:47:14 +04:00
|
|
|
// If the widget bounds were used to clamp the composition bounds,
|
|
|
|
// this adjustment was already made to the widget bounds.
|
|
|
|
if (!useWidgetBounds) {
|
|
|
|
AdjustForScrollBars(metrics.mCompositionBounds, scrollableFrame);
|
2013-08-23 00:18:11 +04:00
|
|
|
}
|
|
|
|
|
2013-05-24 05:43:36 +04:00
|
|
|
metrics.mPresShellId = presShell->GetPresShellId();
|
|
|
|
|
2013-09-23 23:09:48 +04:00
|
|
|
// If the scroll frame's content is marked 'scrollgrab', record this
|
2013-10-23 13:04:42 +04:00
|
|
|
// in the FrameMetrics so APZ knows to provide the scroll grabbing
|
2013-09-23 23:09:48 +04:00
|
|
|
// behaviour.
|
|
|
|
if (aScrollFrame && nsContentUtils::HasScrollgrab(aScrollFrame->GetContent())) {
|
|
|
|
metrics.mHasScrollgrab = true;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
aRoot->SetFrameMetrics(metrics);
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayListBuilder::~nsDisplayListBuilder() {
|
2008-01-04 04:53:01 +03:00
|
|
|
NS_ASSERTION(mFramesMarkedForDisplay.Length() == 0,
|
|
|
|
"All frames should have been unmarked");
|
|
|
|
NS_ASSERTION(mPresShellStates.Length() == 0,
|
|
|
|
"All presshells should have been exited");
|
2008-04-06 15:34:14 +04:00
|
|
|
NS_ASSERTION(!mCurrentTableItem, "No table item should be active");
|
2006-04-27 06:45:03 +04:00
|
|
|
|
2012-11-19 14:54:41 +04:00
|
|
|
nsCSSRendering::EndFrameTreesLocked();
|
|
|
|
|
2013-04-15 09:11:10 +04:00
|
|
|
for (uint32_t i = 0; i < mDisplayItemClipsToDestroy.Length(); ++i) {
|
|
|
|
mDisplayItemClipsToDestroy[i]->DisplayItemClip::~DisplayItemClip();
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
PL_FinishArenaPool(&mPool);
|
2010-06-21 20:21:41 +04:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayListBuilder);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2009-09-13 02:44:18 +04:00
|
|
|
nsDisplayListBuilder::GetBackgroundPaintFlags() {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = 0;
|
2009-09-13 02:44:18 +04:00
|
|
|
if (mSyncDecodeImages) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_SYNC_DECODE_IMAGES;
|
|
|
|
}
|
2010-10-25 18:38:09 +04:00
|
|
|
if (mIsPaintingToWindow) {
|
|
|
|
flags |= nsCSSRendering::PAINTBG_TO_WINDOW;
|
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2009-08-14 06:09:51 +04:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::SubtractFromVisibleRegion(nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRegion& aRegion)
|
2009-08-14 06:09:51 +04:00
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
if (aRegion.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2009-09-19 16:12:48 +04:00
|
|
|
nsRegion tmp;
|
|
|
|
tmp.Sub(*aVisibleRegion, aRegion);
|
|
|
|
// Don't let *aVisibleRegion get too complex, but don't let it fluff out
|
|
|
|
// to its bounds either, which can be very bad (see bug 516740).
|
2011-01-04 11:43:47 +03:00
|
|
|
// Do let aVisibleRegion get more complex if by doing so we reduce its
|
|
|
|
// area by at least half.
|
2011-05-13 20:40:46 +04:00
|
|
|
if (GetAccurateVisibleRegions() || tmp.GetNumRects() <= 15 ||
|
2013-07-30 20:22:43 +04:00
|
|
|
tmp.Area() <= aVisibleRegion->Area()/2) {
|
2009-09-19 16:12:48 +04:00
|
|
|
*aVisibleRegion = tmp;
|
2009-08-14 06:09:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 14:52:01 +04:00
|
|
|
nsCaret *
|
2006-04-18 03:16:46 +04:00
|
|
|
nsDisplayListBuilder::GetCaret() {
|
2010-03-29 03:21:11 +04:00
|
|
|
nsRefPtr<nsCaret> caret = CurrentPresShellState()->mPresShell->GetCaret();
|
2006-04-18 03:16:46 +04:00
|
|
|
return caret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-04 04:53:01 +03:00
|
|
|
PresShellState* state = mPresShellStates.AppendElement();
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
state->mPresShell = aReferenceFrame->PresContext()->PresShell();
|
2012-07-30 18:20:58 +04:00
|
|
|
state->mCaretFrame = nullptr;
|
2008-01-04 04:53:01 +03:00
|
|
|
state->mFirstFrameMarkedForDisplay = mFramesMarkedForDisplay.Length();
|
|
|
|
|
2009-04-25 12:19:23 +04:00
|
|
|
state->mPresShell->UpdateCanvasBackground();
|
|
|
|
|
2010-05-13 04:56:08 +04:00
|
|
|
if (mIsPaintingToWindow) {
|
2011-01-28 00:53:10 +03:00
|
|
|
mReferenceFrame->AddPaintedPresShell(state->mPresShell);
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2010-05-13 04:56:08 +04:00
|
|
|
state->mPresShell->IncrementPaintCount();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool buildCaret = mBuildCaret;
|
2010-09-02 00:44:48 +04:00
|
|
|
if (mIgnoreSuppression || !state->mPresShell->IsPaintingSuppressed()) {
|
|
|
|
if (state->mPresShell->IsPaintingSuppressed()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHadToIgnoreSuppression = true;
|
2010-09-02 00:44:48 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
state->mIsBackgroundOnly = false;
|
2010-09-02 00:44:48 +04:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
state->mIsBackgroundOnly = true;
|
|
|
|
buildCaret = false;
|
2010-09-02 00:44:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!buildCaret)
|
2006-04-18 03:16:46 +04:00
|
|
|
return;
|
|
|
|
|
2010-03-29 03:21:11 +04:00
|
|
|
nsRefPtr<nsCaret> caret = state->mPresShell->GetCaret();
|
2008-01-04 04:53:01 +03:00
|
|
|
state->mCaretFrame = caret->GetCaretFrame();
|
2013-05-07 22:48:59 +04:00
|
|
|
NS_ASSERTION(state->mCaretFrame == caret->GetCaretFrame(),
|
|
|
|
"GetCaretFrame() is unstable");
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2008-01-04 04:53:01 +03:00
|
|
|
if (state->mCaretFrame) {
|
2006-04-27 06:45:03 +04:00
|
|
|
// Check if the dirty rect intersects with the caret's dirty rect.
|
|
|
|
nsRect caretRect =
|
2008-01-04 04:53:01 +03:00
|
|
|
caret->GetCaretRect() + state->mCaretFrame->GetOffsetTo(aReferenceFrame);
|
2006-04-27 06:45:03 +04:00
|
|
|
if (caretRect.Intersects(aDirtyRect)) {
|
|
|
|
// Okay, our rects intersect, let's mark the frame and all of its ancestors.
|
2008-01-04 04:53:01 +03:00
|
|
|
mFramesMarkedForDisplay.AppendElement(state->mCaretFrame);
|
2012-07-30 18:20:58 +04:00
|
|
|
MarkFrameForDisplay(state->mCaretFrame, nullptr);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::LeavePresShell(nsIFrame* aReferenceFrame,
|
2009-04-25 12:19:23 +04:00
|
|
|
const nsRect& aDirtyRect) {
|
2008-01-04 04:53:01 +03:00
|
|
|
if (CurrentPresShellState()->mPresShell != aReferenceFrame->PresContext()->PresShell()) {
|
|
|
|
// Must have not allocated a state for this presshell, presumably due
|
|
|
|
// to OOM.
|
2006-04-18 03:16:46 +04:00
|
|
|
return;
|
2008-01-04 04:53:01 +03:00
|
|
|
}
|
2006-04-18 03:16:46 +04:00
|
|
|
|
2013-06-18 13:15:37 +04:00
|
|
|
ResetMarkedFramesForDisplayList();
|
|
|
|
mPresShellStates.SetLength(mPresShellStates.Length() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::ResetMarkedFramesForDisplayList()
|
|
|
|
{
|
2008-01-04 04:53:01 +03:00
|
|
|
// Unmark and pop off the frames marked for display in this pres shell.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t firstFrameForShell = CurrentPresShellState()->mFirstFrameMarkedForDisplay;
|
|
|
|
for (uint32_t i = firstFrameForShell;
|
2008-01-04 04:53:01 +03:00
|
|
|
i < mFramesMarkedForDisplay.Length(); ++i) {
|
|
|
|
UnmarkFrameForDisplay(mFramesMarkedForDisplay[i]);
|
|
|
|
}
|
|
|
|
mFramesMarkedForDisplay.SetLength(firstFrameForShell);
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:45:03 +04:00
|
|
|
void
|
2009-07-28 16:51:09 +04:00
|
|
|
nsDisplayListBuilder::MarkFramesForDisplayList(nsIFrame* aDirtyFrame,
|
|
|
|
const nsFrameList& aFrames,
|
2006-04-27 06:45:03 +04:00
|
|
|
const nsRect& aDirtyRect) {
|
2009-07-28 16:51:09 +04:00
|
|
|
for (nsFrameList::Enumerator e(aFrames); !e.AtEnd(); e.Next()) {
|
|
|
|
mFramesMarkedForDisplay.AppendElement(e.get());
|
|
|
|
MarkOutOfFlowFrameForDisplay(aDirtyFrame, e.get(), aDirtyRect);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-11 11:49:14 +04:00
|
|
|
void
|
2012-07-31 21:28:21 +04:00
|
|
|
nsDisplayListBuilder::MarkPreserve3DFramesForDisplayList(nsIFrame* aDirtyFrame, const nsRect& aDirtyRect)
|
2012-05-11 11:49:14 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void*
|
|
|
|
nsDisplayListBuilder::Allocate(size_t aSize) {
|
|
|
|
void *tmp;
|
|
|
|
PL_ARENA_ALLOCATE(tmp, &mPool, aSize);
|
2012-11-07 23:55:53 +04:00
|
|
|
if (!tmp) {
|
|
|
|
NS_RUNTIMEABORT("out of memory");
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2013-05-08 09:16:30 +04:00
|
|
|
const DisplayItemClip*
|
2013-04-15 09:11:10 +04:00
|
|
|
nsDisplayListBuilder::AllocateDisplayItemClip(const DisplayItemClip& aOriginal)
|
|
|
|
{
|
|
|
|
void* p = Allocate(sizeof(DisplayItemClip));
|
2013-05-08 09:16:30 +04:00
|
|
|
if (!aOriginal.GetRoundedRectCount()) {
|
|
|
|
memcpy(p, &aOriginal, sizeof(DisplayItemClip));
|
|
|
|
return static_cast<DisplayItemClip*>(p);
|
|
|
|
}
|
|
|
|
|
2013-04-15 09:11:10 +04:00
|
|
|
DisplayItemClip* c = new (p) DisplayItemClip(aOriginal);
|
|
|
|
mDisplayItemClipsToDestroy.AppendElement(c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void nsDisplayListSet::MoveTo(const nsDisplayListSet& aDestination) const
|
|
|
|
{
|
|
|
|
aDestination.BorderBackground()->AppendToTop(BorderBackground());
|
|
|
|
aDestination.BlockBorderBackgrounds()->AppendToTop(BlockBorderBackgrounds());
|
|
|
|
aDestination.Floats()->AppendToTop(Floats());
|
|
|
|
aDestination.Content()->AppendToTop(Content());
|
|
|
|
aDestination.PositionedDescendants()->AppendToTop(PositionedDescendants());
|
|
|
|
aDestination.Outlines()->AppendToTop(Outlines());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-11-11 23:31:39 +03:00
|
|
|
nsDisplayList::FlattenTo(nsTArray<nsDisplayItem*>* aElements) {
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayItem* item;
|
2012-07-30 18:20:58 +04:00
|
|
|
while ((item = RemoveBottom()) != nullptr) {
|
2010-07-16 01:07:49 +04:00
|
|
|
if (item->GetType() == nsDisplayItem::TYPE_WRAP_LIST) {
|
2012-11-02 16:59:03 +04:00
|
|
|
item->GetSameCoordinateSystemChildren()->FlattenTo(aElements);
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
} else {
|
|
|
|
aElements->AppendElement(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayList::GetBounds(nsDisplayListBuilder* aBuilder) const {
|
|
|
|
nsRect bounds;
|
2012-07-30 18:20:58 +04:00
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nullptr; i = i->GetAbove()) {
|
2013-03-04 13:56:02 +04:00
|
|
|
bounds.UnionRect(bounds, i->GetClippedBounds(aBuilder));
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-28 03:15:08 +04:00
|
|
|
nsDisplayList::ComputeVisibilityForRoot(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsDisplayList", "ComputeVisibilityForRoot");
|
2010-08-28 03:15:08 +04:00
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2013-03-04 13:56:02 +04:00
|
|
|
return ComputeVisibilityForSublist(aBuilder, aVisibleRegion,
|
|
|
|
r.GetBounds(), r.GetBounds());
|
2010-08-28 03:15:08 +04:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
static nsRegion
|
2012-05-03 08:29:05 +04:00
|
|
|
TreatAsOpaque(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder)
|
2010-11-08 12:06:14 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
bool snap;
|
2012-05-03 08:29:05 +04:00
|
|
|
nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, &snap);
|
2010-11-08 12:06:14 +03:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
2012-11-02 16:59:03 +04:00
|
|
|
// Treat all leaf chrome items as opaque, unless their frames are opacity:0.
|
2011-05-23 04:28:47 +04: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 16:59:03 +04: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).
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* f = aItem->Frame();
|
2013-04-19 16:01:41 +04:00
|
|
|
if (f->PresContext()->IsChrome() && !aItem->GetChildren() &&
|
2013-02-17 01:51:02 +04:00
|
|
|
f->StyleDisplay()->mOpacity != 0.0) {
|
2012-04-10 15:24:18 +04:00
|
|
|
opaque = aItem->GetBounds(aBuilder, &snap);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2010-11-08 12:06:14 +03:00
|
|
|
}
|
2013-03-04 13:56:02 +04:00
|
|
|
if (opaque.IsEmpty()) {
|
|
|
|
return opaque;
|
|
|
|
}
|
|
|
|
nsRegion opaqueClipped;
|
|
|
|
nsRegionRectIterator iter(opaque);
|
|
|
|
for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
|
|
|
|
opaqueClipped.Or(opaqueClipped, aItem->GetClip().ApproximateIntersectInward(*r));
|
|
|
|
}
|
|
|
|
return opaqueClipped;
|
2010-11-08 12:06:14 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-28 03:15:08 +04:00
|
|
|
nsDisplayList::ComputeVisibilityForSublist(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
2011-01-28 01:58:50 +03:00
|
|
|
const nsRect& aListVisibleBounds,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2010-08-28 03:15:08 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsRegion r;
|
|
|
|
r.And(*aVisibleRegion, GetBounds(aBuilder));
|
2011-04-19 07:07:23 +04:00
|
|
|
NS_ASSERTION(r.GetBounds().IsEqualInterior(aListVisibleBounds),
|
2010-08-28 03:15:08 +04:00
|
|
|
"bad aListVisibleBounds");
|
|
|
|
#endif
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
mVisibleRect = aListVisibleBounds;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool anyVisible = false;
|
2010-03-10 23:55:05 +03:00
|
|
|
|
2007-11-11 23:31:39 +03:00
|
|
|
nsAutoTArray<nsDisplayItem*, 512> elements;
|
2006-01-26 05:29:17 +03:00
|
|
|
FlattenTo(&elements);
|
2007-11-11 23:31:39 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forceTransparentSurface = false;
|
2010-10-19 21:02:25 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = elements.Length() - 1; i >= 0; --i) {
|
2007-11-11 23:31:39 +03:00
|
|
|
nsDisplayItem* item = elements[i];
|
2012-07-30 18:20:58 +04:00
|
|
|
nsDisplayItem* belowItem = i < 1 ? nullptr : elements[i - 1];
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2012-11-02 16:59:03 +04:00
|
|
|
nsDisplayList* list = item->GetSameCoordinateSystemChildren();
|
2012-10-06 17:03:23 +04: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-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRect bounds = item->GetClippedBounds(aBuilder);
|
2009-09-07 04:35:14 +04:00
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2013-09-27 10:01:16 +04:00
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-05-09 12:40:09 +04:00
|
|
|
item->mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
if (item->ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aAllowVisibleRegionExpansion.Intersect(bounds))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
anyVisible = true;
|
2012-05-03 08:29:05 +04:00
|
|
|
nsRegion opaque = TreatAsOpaque(item, aBuilder);
|
2011-01-03 04:48:09 +03:00
|
|
|
// Subtract opaque item from the visible region
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2012-05-03 08:29:05 +04:00
|
|
|
if (aBuilder->NeedToForceTransparentSurfaceForItem(item) ||
|
|
|
|
(list && list->NeedsTransparentSurface())) {
|
|
|
|
forceTransparentSurface = true;
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2010-07-16 01:08:09 +04:00
|
|
|
AppendToBottom(item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2009-08-14 06:09:51 +04:00
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
mIsOpaque = !aVisibleRegion->Intersects(mVisibleRect);
|
2010-10-19 21:02:25 +04:00
|
|
|
mForceTransparentSurface = forceTransparentSurface;
|
2009-09-07 04:35:14 +04:00
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
mDidComputeVisibility = true;
|
2009-09-07 04:35:14 +04:00
|
|
|
#endif
|
2010-07-16 01:08:09 +04:00
|
|
|
return anyVisible;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-03-10 23:55:05 +03:00
|
|
|
void nsDisplayList::PaintRoot(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) const {
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsDisplayList", "PaintRoot");
|
2012-09-16 14:32:59 +04:00
|
|
|
PaintForFrame(aBuilder, aCtx, aBuilder->RootReferenceFrame(), aFlags);
|
2010-03-10 23:55:05 +03:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
/**
|
|
|
|
* We paint by executing a layer manager transaction, constructing a
|
|
|
|
* single layer representing the display list, and then making it the
|
|
|
|
* root of the layer manager, drawing into the ThebesLayers.
|
|
|
|
*/
|
2010-03-10 23:55:05 +03:00
|
|
|
void nsDisplayList::PaintForFrame(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx,
|
2010-03-10 23:55:05 +03:00
|
|
|
nsIFrame* aForFrame,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) const {
|
2009-09-07 04:35:14 +04:00
|
|
|
NS_ASSERTION(mDidComputeVisibility,
|
|
|
|
"Must call ComputeVisibility before calling Paint");
|
|
|
|
|
2010-03-01 11:03:49 +03:00
|
|
|
nsRefPtr<LayerManager> layerManager;
|
2012-08-29 09:48:41 +04:00
|
|
|
bool widgetTransaction = false;
|
2011-01-19 11:27:54 +03:00
|
|
|
bool allowRetaining = false;
|
|
|
|
bool doBeginTransaction = true;
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView *view = nullptr;
|
2010-03-01 11:03:49 +03:00
|
|
|
if (aFlags & PAINT_USE_WIDGET_LAYERS) {
|
2012-09-16 14:32:59 +04:00
|
|
|
nsIFrame* rootReferenceFrame = aBuilder->RootReferenceFrame();
|
2012-08-29 09:47:18 +04:00
|
|
|
view = rootReferenceFrame->GetView();
|
2012-09-16 14:32:59 +04:00
|
|
|
NS_ASSERTION(rootReferenceFrame == nsLayoutUtils::GetDisplayRootFrame(rootReferenceFrame),
|
2010-03-01 11:03:49 +03:00
|
|
|
"Reference frame must be a display root for us to use the layer manager");
|
2012-09-16 14:32:59 +04:00
|
|
|
nsIWidget* window = rootReferenceFrame->GetNearestWidget();
|
2010-03-01 11:03:49 +03:00
|
|
|
if (window) {
|
2010-10-15 14:34:29 +04:00
|
|
|
layerManager = window->GetLayerManager(&allowRetaining);
|
2011-01-19 11:27:54 +03:00
|
|
|
if (layerManager) {
|
|
|
|
doBeginTransaction = !(aFlags & PAINT_EXISTING_TRANSACTION);
|
2012-08-29 09:48:41 +04:00
|
|
|
widgetTransaction = true;
|
2010-07-16 01:07:51 +04:00
|
|
|
}
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!layerManager) {
|
|
|
|
if (!aCtx) {
|
|
|
|
NS_WARNING("Nowhere to paint into");
|
|
|
|
return;
|
|
|
|
}
|
2010-07-16 01:08:10 +04:00
|
|
|
layerManager = new BasicLayerManager();
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
|
|
|
|
2012-10-23 15:01:23 +04:00
|
|
|
// Store the existing layer builder to reinstate it on return.
|
|
|
|
FrameLayerBuilder *oldBuilder = layerManager->GetLayerBuilder();
|
|
|
|
|
2012-07-17 21:03:51 +04:00
|
|
|
FrameLayerBuilder *layerBuilder = new FrameLayerBuilder();
|
2012-08-21 08:06:46 +04:00
|
|
|
layerBuilder->Init(aBuilder, layerManager);
|
2012-07-17 21:03:51 +04:00
|
|
|
|
2010-07-16 01:07:52 +04:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
2011-01-19 11:27:54 +03:00
|
|
|
if (doBeginTransaction) {
|
|
|
|
if (aCtx) {
|
|
|
|
layerManager->BeginTransactionWithTarget(aCtx->ThebesContext());
|
|
|
|
} else {
|
|
|
|
layerManager->BeginTransaction();
|
|
|
|
}
|
|
|
|
}
|
2012-10-12 03:38:24 +04:00
|
|
|
if (widgetTransaction) {
|
2012-07-17 21:03:51 +04:00
|
|
|
layerBuilder->DidBeginRetainedLayerTransaction(layerManager);
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2011-06-22 16:11:27 +04:00
|
|
|
nsPresContext* presContext = aForFrame->PresContext();
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
NotifySubDocInvalidationFunc computeInvalidFunc =
|
|
|
|
presContext->MayHavePaintEventListenerInSubDocument() ? nsPresContext::NotifySubDocInvalidation : 0;
|
|
|
|
bool computeInvalidRect = (computeInvalidFunc ||
|
2012-10-12 03:55:42 +04:00
|
|
|
!layerManager->IsCompositingCheap()) &&
|
2012-08-29 09:47:18 +04:00
|
|
|
widgetTransaction;
|
|
|
|
|
|
|
|
nsAutoPtr<LayerProperties> props(computeInvalidRect ?
|
|
|
|
LayerProperties::CloneFrom(layerManager->GetRoot()) :
|
|
|
|
nullptr);
|
|
|
|
|
2013-09-27 10:01:16 +04:00
|
|
|
ContainerLayerParameters containerParameters
|
2011-06-22 16:11:27 +04:00
|
|
|
(presShell->GetXResolution(), presShell->GetYResolution());
|
2012-07-17 21:03:51 +04:00
|
|
|
nsRefPtr<ContainerLayer> root = layerBuilder->
|
2012-07-30 18:20:58 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, layerManager, aForFrame, nullptr, *this,
|
|
|
|
containerParameters, nullptr);
|
2012-10-23 15:01:23 +04:00
|
|
|
|
2013-09-04 14:39:31 +04:00
|
|
|
nsIDocument* document = nullptr;
|
|
|
|
if (presShell) {
|
|
|
|
document = presShell->GetDocument();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetTransaction ||
|
|
|
|
// SVG-as-an-image docs don't paint as part of the retained layer tree,
|
|
|
|
// but they still need the invalidation state bits cleared in order for
|
|
|
|
// invalidation for CSS/SMIL animation to work properly.
|
|
|
|
(document && document->IsBeingUsedAsImage())) {
|
2012-08-29 09:47:18 +04:00
|
|
|
aForFrame->ClearInvalidationStateBits();
|
|
|
|
}
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
if (!root) {
|
2012-10-23 15:01:23 +04:00
|
|
|
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);
|
2010-03-01 10:56:19 +03:00
|
|
|
return;
|
2012-07-17 21:03:51 +04:00
|
|
|
}
|
2011-06-22 16:11:27 +04:00
|
|
|
// Root is being scaled up by the X/Y resolution. Scale it back down.
|
2012-08-04 01:29:22 +04:00
|
|
|
root->SetPostScale(1.0f/containerParameters.mXScale,
|
|
|
|
1.0f/containerParameters.mYScale);
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2013-11-09 04:07:00 +04:00
|
|
|
ViewID id = FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
bool isRoot = presContext->IsRootContentDocument();
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2011-03-16 02:20:19 +03:00
|
|
|
nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame();
|
2012-11-22 02:34:18 +04:00
|
|
|
nsRect displayport, criticalDisplayport;
|
2011-03-10 00:35:27 +03:00
|
|
|
bool usingDisplayport = false;
|
2012-11-22 02:34:18 +04:00
|
|
|
bool usingCriticalDisplayport = false;
|
2011-03-16 02:20:19 +03:00
|
|
|
if (rootScrollFrame) {
|
|
|
|
nsIContent* content = rootScrollFrame->GetContent();
|
|
|
|
if (content) {
|
2011-03-10 00:35:27 +03:00
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
2012-11-22 02:34:18 +04:00
|
|
|
usingCriticalDisplayport =
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(content, &criticalDisplayport);
|
2013-08-08 23:56:08 +04:00
|
|
|
|
2013-11-09 04:07:00 +04:00
|
|
|
// If this is the root content document, we want it to have a scroll id.
|
|
|
|
if (isRoot) {
|
|
|
|
id = nsLayoutUtils::FindOrCreateIDFor(content);
|
2013-08-08 23:56:08 +04:00
|
|
|
}
|
2011-03-16 02:20:19 +03:00
|
|
|
}
|
|
|
|
}
|
2012-08-22 08:37:06 +04:00
|
|
|
|
2012-09-29 06:16:34 +04:00
|
|
|
nsRect viewport(aBuilder->ToReferenceFrame(aForFrame), aForFrame->GetSize());
|
|
|
|
|
2011-03-10 00:35:27 +03:00
|
|
|
RecordFrameMetrics(aForFrame, rootScrollFrame,
|
2013-09-06 02:36:07 +04:00
|
|
|
aBuilder->FindReferenceFrameFor(aForFrame),
|
2012-09-29 06:16:34 +04:00
|
|
|
root, mVisibleRect, viewport,
|
2012-11-22 02:34:18 +04:00
|
|
|
(usingDisplayport ? &displayport : nullptr),
|
|
|
|
(usingCriticalDisplayport ? &criticalDisplayport : nullptr),
|
2013-11-09 04:07:00 +04:00
|
|
|
id, isRoot, containerParameters);
|
2011-10-23 12:57:47 +04: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-04 00:10:46 +04:00
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
layerManager->SetRoot(root);
|
2012-08-29 09:47:15 +04:00
|
|
|
layerBuilder->WillEndTransaction();
|
2012-07-23 07:00:36 +04:00
|
|
|
bool temp = aBuilder->SetIsCompositingCheap(layerManager->IsCompositingCheap());
|
2013-12-16 09:38:42 +04:00
|
|
|
LayerManager::EndTransactionFlags flags = LayerManager::END_DEFAULT;
|
|
|
|
if (layerManager->NeedsWidgetInvalidation()) {
|
2013-12-16 12:05:20 +04:00
|
|
|
if (aFlags & PAINT_NO_COMPOSITE) {
|
|
|
|
flags = LayerManager::END_NO_COMPOSITE;
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-16 09:38:42 +04:00
|
|
|
// Client layer managers never composite directly, so
|
|
|
|
// we don't need to worry about END_NO_COMPOSITE.
|
|
|
|
if (aBuilder->WillComputePluginGeometry()) {
|
|
|
|
flags = LayerManager::END_NO_REMOTE_COMPOSITE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
layerManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer,
|
2013-12-16 09:38:42 +04:00
|
|
|
aBuilder, flags);
|
2012-07-23 07:00:36 +04:00
|
|
|
aBuilder->SetIsCompositingCheap(temp);
|
2012-08-29 09:47:15 +04:00
|
|
|
layerBuilder->DidEndTransaction();
|
2010-03-01 10:56:19 +03:00
|
|
|
|
2012-11-12 22:31:15 +04:00
|
|
|
nsIntRegion invalid;
|
2012-08-29 09:47:18 +04:00
|
|
|
if (props) {
|
|
|
|
invalid = props->ComputeDifferences(root, computeInvalidFunc);
|
2012-08-29 09:48:43 +04:00
|
|
|
} else if (widgetTransaction) {
|
|
|
|
LayerProperties::ClearInvalidations(root);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 11:59:29 +04:00
|
|
|
bool shouldInvalidate = layerManager->NeedsWidgetInvalidation();
|
2012-08-29 09:47:18 +04:00
|
|
|
if (view) {
|
|
|
|
if (props) {
|
|
|
|
if (!invalid.IsEmpty()) {
|
2012-11-12 22:31:15 +04:00
|
|
|
nsIntRect bounds = invalid.GetBounds();
|
|
|
|
nsRect rect(presContext->DevPixelsToAppUnits(bounds.x),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.y),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.width),
|
|
|
|
presContext->DevPixelsToAppUnits(bounds.height));
|
2013-06-18 11:59:29 +04:00
|
|
|
if (shouldInvalidate) {
|
|
|
|
view->GetViewManager()->InvalidateViewNoSuppression(view, rect);
|
|
|
|
}
|
2012-11-12 22:31:15 +04:00
|
|
|
presContext->NotifyInvalidation(bounds, 0);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
2013-06-18 11:59:29 +04:00
|
|
|
} else if (shouldInvalidate) {
|
2012-08-29 09:47:18 +04:00
|
|
|
view->GetViewManager()->InvalidateView(view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:52 +04:00
|
|
|
if (aFlags & PAINT_FLUSH_LAYERS) {
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(layerManager);
|
|
|
|
}
|
|
|
|
|
2012-10-23 15:01:23 +04:00
|
|
|
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t nsDisplayList::Count() const {
|
|
|
|
uint32_t count = 0;
|
2006-01-26 05:29:17 +03:00
|
|
|
for (nsDisplayItem* i = GetBottom(); i; i = i->GetAbove()) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem* nsDisplayList::RemoveBottom() {
|
|
|
|
nsDisplayItem* item = mSentinel.mAbove;
|
|
|
|
if (!item)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-01-26 05:29:17 +03:00
|
|
|
mSentinel.mAbove = item->mAbove;
|
|
|
|
if (item == mTop) {
|
|
|
|
// must have been the only item
|
|
|
|
mTop = &mSentinel;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
item->mAbove = nullptr;
|
2006-01-26 05:29:17 +03:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::DeleteAll() {
|
|
|
|
nsDisplayItem* item;
|
2012-07-30 18:20:58 +04:00
|
|
|
while ((item = RemoveBottom()) != nullptr) {
|
2006-01-29 21:48:58 +03:00
|
|
|
item->~nsDisplayItem();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-11-30 17:59:46 +03:00
|
|
|
GetMouseThrough(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame->IsBoxFrame())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-11-30 17:59:46 +03:00
|
|
|
|
|
|
|
const nsIFrame* frame = aFrame;
|
|
|
|
while (frame) {
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_ALWAYS) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-11-30 17:59:46 +03:00
|
|
|
} else if (frame->GetStateBits() & NS_FRAME_MOUSE_THROUGH_NEVER) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-11-30 17:59:46 +03:00
|
|
|
}
|
|
|
|
frame = frame->GetParentBox();
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-11-30 17:59:46 +03:00
|
|
|
}
|
|
|
|
|
2013-08-13 11:56:57 +04:00
|
|
|
static bool
|
|
|
|
IsFrameReceivingPointerEvents(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsSubDocumentFrame* frame = do_QueryFrame(aFrame);
|
|
|
|
if (frame && frame->PassPointerEventsToChildren()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return NS_STYLE_POINTER_EVENTS_NONE !=
|
|
|
|
aFrame->StyleVisibility()->GetEffectivePointerEvents(aFrame);
|
|
|
|
}
|
|
|
|
|
2011-10-07 01:24:02 +04: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 19:56:38 +04:00
|
|
|
uint32_t length = aSource.Length();
|
|
|
|
for (uint32_t i = 0; i < length; i++) {
|
2011-10-07 01:24:02 +04:00
|
|
|
aDest->MoveElementsFrom(aSource[i].mFrames);
|
|
|
|
}
|
|
|
|
aSource.Clear();
|
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void nsDisplayList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
nsDisplayItem::HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames) const {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t itemBufferStart = aState->mItemBuffer.Length();
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayItem* item;
|
|
|
|
for (item = GetBottom(); item; item = item->GetAbove()) {
|
2008-01-04 05:08:29 +03:00
|
|
|
aState->mItemBuffer.AppendElement(item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2011-10-07 01:24:02 +04:00
|
|
|
nsAutoTArray<FramesWithDepth, 16> temp;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = aState->mItemBuffer.Length() - 1; i >= itemBufferStart; --i) {
|
2008-01-04 05:08:29 +03: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 15:24:18 +04:00
|
|
|
bool snap;
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRect r = item->GetBounds(aBuilder, &snap).Intersect(aRect);
|
|
|
|
if (item->GetClip().MayIntersect(r)) {
|
2011-09-23 07:50:57 +04:00
|
|
|
nsAutoTArray<nsIFrame*, 16> outFrames;
|
2010-04-08 04:31:26 +04:00
|
|
|
item->HitTest(aBuilder, aRect, aState, &outFrames);
|
2012-07-31 21:28:21 +04:00
|
|
|
|
|
|
|
// For 3d transforms with preserve-3d we add hit frames into the temp list
|
2011-10-07 01:24:02 +04: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 &&
|
2013-04-19 16:02:13 +04:00
|
|
|
item->Frame()->Preserves3D()) {
|
2011-10-12 07:16:05 +04: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-07 01:24:02 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-31 21:28:21 +04:00
|
|
|
// We may have just finished a run of consecutive preserve-3d transforms,
|
2011-10-07 01:24:02 +04:00
|
|
|
// so flush these into the destination array before processing our frame list.
|
|
|
|
FlushFramesArray(temp, aOutFrames);
|
|
|
|
}
|
2010-04-08 04:31:26 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = 0; j < outFrames.Length(); j++) {
|
2010-04-08 04:31:26 +04:00
|
|
|
nsIFrame *f = outFrames.ElementAt(j);
|
|
|
|
// Handle the XUL 'mousethrough' feature and 'pointer-events'.
|
2013-08-13 11:56:57 +04:00
|
|
|
if (!GetMouseThrough(f) && IsFrameReceivingPointerEvents(f)) {
|
2011-10-07 01:24:02 +04:00
|
|
|
writeFrames->AppendElement(f);
|
2008-01-04 05:08:29 +03:00
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 01:24:02 +04:00
|
|
|
// Clear any remaining preserve-3d transforms.
|
|
|
|
FlushFramesArray(temp, aOutFrames);
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_ASSERTION(aState->mItemBuffer.Length() == uint32_t(itemBufferStart),
|
2008-01-04 05:08:29 +03:00
|
|
|
"How did we forget to pop some elements?");
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static void Sort(nsDisplayList* aList, int32_t aCount, nsDisplayList::SortLEQ aCmp,
|
2006-04-18 02:16:24 +04:00
|
|
|
void* aClosure) {
|
2006-01-26 05:29:17 +03:00
|
|
|
if (aCount < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsDisplayList list1;
|
|
|
|
nsDisplayList list2;
|
|
|
|
int i;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t half = aCount/2;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool sorted = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsDisplayItem* prev = nullptr;
|
2006-01-26 05:29:17 +03: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 18:59:28 +04:00
|
|
|
sorted = false;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
prev = item;
|
|
|
|
}
|
|
|
|
if (sorted) {
|
|
|
|
aList->AppendToTop(&list1);
|
|
|
|
aList->AppendToTop(&list2);
|
|
|
|
return;
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2006-01-26 05:29:17 +03: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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 10:55:36 +04:00
|
|
|
static nsIContent* FindContentInDocument(nsDisplayItem* aItem, nsIDocument* aDoc) {
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* f = aItem->Frame();
|
2013-04-16 10:14:56 +04:00
|
|
|
while (f) {
|
|
|
|
nsPresContext* pc = f->PresContext();
|
|
|
|
if (pc->Document() == aDoc) {
|
|
|
|
return f->GetContent();
|
2013-04-05 12:30:34 +04:00
|
|
|
}
|
2013-04-16 10:14:56 +04:00
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(pc->PresShell()->GetRootFrame());
|
2013-04-05 12:30:34 +04:00
|
|
|
}
|
2013-04-16 10:14:56 +04:00
|
|
|
return nullptr;
|
2013-04-05 12:30:34 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsContentLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
2013-04-05 12:30:34 +04:00
|
|
|
void* aClosure) {
|
|
|
|
nsIContent* commonAncestor = static_cast<nsIContent*>(aClosure);
|
|
|
|
// It's possible that the nsIContent for aItem1 or aItem2 is in a subdocument
|
|
|
|
// of commonAncestor, because display items for subdocuments have been
|
|
|
|
// mixed into the same list. Ensure that we're looking at content
|
|
|
|
// in commonAncestor's document.
|
|
|
|
nsIDocument* commonAncestorDoc = commonAncestor->OwnerDoc();
|
2013-04-15 10:55:36 +04:00
|
|
|
nsIContent* content1 = FindContentInDocument(aItem1, commonAncestorDoc);
|
|
|
|
nsIContent* content2 = FindContentInDocument(aItem2, commonAncestorDoc);
|
2013-04-05 12:30:34 +04:00
|
|
|
if (!content1 || !content2) {
|
|
|
|
NS_ERROR("Document trees are mixed up!");
|
|
|
|
// Something weird going on
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return nsLayoutUtils::CompareTreePosition(content1, content2, commonAncestor) <= 0;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsZOrderLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2,
|
2013-04-05 12:30:34 +04:00
|
|
|
void* aClosure) {
|
2013-04-19 16:01:41 +04:00
|
|
|
// Note that we can't just take the difference of the two
|
2010-04-02 06:09:05 +04:00
|
|
|
// z-indices here, because that might overflow a 32-bit int.
|
2013-04-19 16:02:13 +04:00
|
|
|
int32_t index1 = nsLayoutUtils::GetZIndex(aItem1->Frame());
|
|
|
|
int32_t index2 = nsLayoutUtils::GetZIndex(aItem2->Frame());
|
2012-07-23 19:20:11 +04:00
|
|
|
return index1 <= index2;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByZOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 06:25:23 +04:00
|
|
|
Sort(aBuilder, IsZOrderLEQ, aCommonAncestor);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayList::SortByContentOrder(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIContent* aCommonAncestor) {
|
2006-04-27 06:25:23 +04:00
|
|
|
Sort(aBuilder, IsContentLEQ, aCommonAncestor);
|
2006-04-18 02:16:24 +04:00
|
|
|
}
|
|
|
|
|
2006-04-27 06:25:23 +04:00
|
|
|
void nsDisplayList::Sort(nsDisplayListBuilder* aBuilder,
|
|
|
|
SortLEQ aCmp, void* aClosure) {
|
2006-04-18 02:16:24 +04:00
|
|
|
::Sort(this, Count(), aCmp, aClosure);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:43:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayItem::AddInvalidRegionForSyncDecodeBackgroundImages(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
if (!nsCSSRendering::AreAllBackgroundImagesDecodedForFrame(mFrame)) {
|
|
|
|
bool snap;
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, GetBounds(aBuilder, &snap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 03:29:05 +04: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;
|
|
|
|
}
|
|
|
|
|
2013-07-17 00:17:18 +04:00
|
|
|
/* static */ int32_t
|
|
|
|
nsDisplayItem::MaxActiveLayers()
|
|
|
|
{
|
|
|
|
static int32_t sMaxLayers = false;
|
|
|
|
static bool sMaxLayersCached = false;
|
|
|
|
|
|
|
|
if (!sMaxLayersCached) {
|
|
|
|
Preferences::AddIntVarCache(&sMaxLayers, "layers.max-active", -1);
|
|
|
|
sMaxLayersCached = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sMaxLayers;
|
|
|
|
}
|
|
|
|
|
2012-11-23 03:29:05 +04:00
|
|
|
bool
|
|
|
|
nsDisplayItem::RecomputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion) {
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRect bounds = GetClippedBounds(aBuilder);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
|
|
nsRegion itemVisible;
|
2013-09-27 10:01:16 +04:00
|
|
|
itemVisible.And(*aVisibleRegion, bounds);
|
2011-05-09 12:40:09 +04:00
|
|
|
mVisibleRect = itemVisible.GetBounds();
|
2011-04-08 20:35:16 +04:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
// When we recompute visibility within layers we don't need to
|
|
|
|
// expand the visible region for content behind plugins (the plugin
|
|
|
|
// is not in the layer).
|
2011-05-13 20:40:46 +04:00
|
|
|
if (!ComputeVisibility(aBuilder, aVisibleRegion, nsRect()))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2012-05-03 08:29:05 +04:00
|
|
|
nsRegion opaque = TreatAsOpaque(this, aBuilder);
|
2011-01-04 11:45:24 +03:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 01:07:51 +04:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayItem::GetClippedBounds(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
bool snap;
|
|
|
|
nsRect r = GetBounds(aBuilder, &snap);
|
|
|
|
return GetClip().ApplyNonRoundedIntersection(r);
|
|
|
|
}
|
|
|
|
|
2011-05-12 18:59:09 +04:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplaySolidColor::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-05-12 18:59:09 +04:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = true;
|
|
|
|
return mBounds;
|
2011-05-12 18:59:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySolidColor::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
2009-04-25 12:19:23 +04:00
|
|
|
aCtx->SetColor(mColor);
|
2009-09-07 04:35:14 +04:00
|
|
|
aCtx->FillRect(mVisibleRect);
|
2009-04-25 12:19:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 02:07:08 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
|
|
|
nsDisplaySolidColor::WriteDebugInfo(nsACString& aTo)
|
|
|
|
{
|
|
|
|
aTo += nsPrintfCString("(rgba %d,%d,%d,%d)",
|
|
|
|
NS_GET_R(mColor), NS_GET_G(mColor),
|
|
|
|
NS_GET_B(mColor), NS_GET_A(mColor));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-24 13:35:29 +04:00
|
|
|
static void
|
2011-01-11 16:03:16 +03:00
|
|
|
RegisterThemeGeometry(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
2010-07-24 13:35:29 +04:00
|
|
|
{
|
|
|
|
nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
|
|
|
|
|
|
|
|
for (nsIFrame* f = aFrame; f; f = f->GetParent()) {
|
|
|
|
// Bail out if we're in a transformed subtree
|
|
|
|
if (f->IsTransformed())
|
|
|
|
return;
|
|
|
|
// Bail out if we're not in the displayRoot's document
|
|
|
|
if (!f->GetParent() && f != displayRoot)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect borderBox(aFrame->GetOffsetTo(displayRoot), aFrame->GetSize());
|
2013-02-17 01:51:02 +04:00
|
|
|
aBuilder->RegisterThemeGeometry(aFrame->StyleDisplay()->mAppearance,
|
2011-01-11 16:03:16 +03:00
|
|
|
borderBox.ToNearestPixels(aFrame->PresContext()->AppUnitsPerDevPixel()));
|
2010-07-24 13:35:29 +04:00
|
|
|
}
|
|
|
|
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::nsDisplayBackgroundImage(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
uint32_t aLayer,
|
|
|
|
const nsStyleBackground* aBackgroundStyle)
|
2012-11-19 07:28:18 +04:00
|
|
|
: nsDisplayImageContainer(aBuilder, aFrame)
|
2012-11-08 08:08:40 +04:00
|
|
|
, mBackgroundStyle(aBackgroundStyle)
|
|
|
|
, mLayer(aLayer)
|
2010-07-24 13:35:29 +04:00
|
|
|
{
|
2012-11-10 03:14:59 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayBackgroundImage);
|
2010-07-24 13:35:29 +04:00
|
|
|
|
2013-06-04 08:49:03 +04:00
|
|
|
mBounds = GetBoundsInternal(aBuilder);
|
2010-07-24 13:35:29 +04:00
|
|
|
}
|
|
|
|
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::~nsDisplayBackgroundImage()
|
2012-08-19 23:33:25 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2012-11-10 03:14:59 +04:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayBackgroundImage);
|
2012-08-19 23:33:25 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-08 07:47:31 +04:00
|
|
|
static nsStyleContext* GetBackgroundStyleContext(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsStyleContext *sc;
|
|
|
|
if (!nsCSSRendering::FindBackground(aFrame, &sc)) {
|
|
|
|
// We don't want to bail out if moz-appearance is set on a root
|
|
|
|
// node. If it has a parent content node, bail because it's not
|
|
|
|
// a root, other wise keep going in order to let the theme stuff
|
|
|
|
// draw the background. The canvas really should be drawing the
|
|
|
|
// bg, but there's no way to hook that up via css.
|
|
|
|
if (!aFrame->StyleDisplay()->mAppearance) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
if (!content || content->GetParent()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = aFrame->StyleContext();
|
|
|
|
}
|
|
|
|
return sc;
|
|
|
|
}
|
|
|
|
|
2013-07-24 11:38:55 +04:00
|
|
|
/*static*/ bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
2013-07-24 11:38:55 +04:00
|
|
|
nsDisplayList* aList)
|
2012-09-13 14:34:23 +04:00
|
|
|
{
|
2012-10-25 09:32:25 +04:00
|
|
|
nsStyleContext* bgSC = nullptr;
|
2012-09-13 14:34:23 +04:00
|
|
|
const nsStyleBackground* bg = nullptr;
|
|
|
|
nsPresContext* presContext = aFrame->PresContext();
|
2012-11-08 08:08:40 +04:00
|
|
|
bool isThemed = aFrame->IsThemed();
|
2013-05-08 07:47:31 +04:00
|
|
|
if (!isThemed) {
|
|
|
|
bgSC = GetBackgroundStyleContext(aFrame);
|
|
|
|
if (bgSC) {
|
|
|
|
bg = bgSC->StyleBackground();
|
|
|
|
}
|
2012-09-13 14:34:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
bool drawBackgroundColor = false;
|
|
|
|
nscolor color;
|
|
|
|
if (!nsCSSRendering::IsCanvasFrame(aFrame) && bg) {
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
color =
|
|
|
|
nsCSSRendering::DetermineBackgroundColor(presContext, bgSC, aFrame,
|
|
|
|
drawBackgroundImage, drawBackgroundColor);
|
|
|
|
}
|
|
|
|
|
2013-11-08 19:08:03 +04:00
|
|
|
// An auxiliary list is necessary in case we have background blending; if that
|
|
|
|
// is the case, background items need to be wrapped by a blend container to
|
|
|
|
// isolate blending to the background
|
|
|
|
nsDisplayList bgItemList;
|
2012-11-27 16:50:09 +04:00
|
|
|
// Even if we don't actually have a background color to paint, we may still need
|
|
|
|
// to create an item for hit testing.
|
|
|
|
if ((drawBackgroundColor && color != NS_RGBA(0,0,0,0)) ||
|
|
|
|
aBuilder->IsForEventDelivery()) {
|
2013-11-08 19:08:03 +04:00
|
|
|
bgItemList.AppendNewToTop(
|
2012-11-27 16:50:09 +04:00
|
|
|
new (aBuilder) nsDisplayBackgroundColor(aBuilder, aFrame, bg,
|
|
|
|
drawBackgroundColor ? color : NS_RGBA(0, 0, 0, 0)));
|
|
|
|
}
|
2012-12-14 02:16:14 +04:00
|
|
|
|
|
|
|
if (isThemed) {
|
2013-07-18 10:34:58 +04:00
|
|
|
nsDisplayThemedBackground* bgItem =
|
|
|
|
new (aBuilder) nsDisplayThemedBackground(aBuilder, aFrame);
|
2013-11-08 19:08:03 +04:00
|
|
|
bgItemList.AppendNewToTop(bgItem);
|
|
|
|
aList->AppendToTop(&bgItemList);
|
2013-07-24 11:38:55 +04:00
|
|
|
return true;
|
2012-12-14 02:16:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!bg) {
|
2013-11-08 19:08:03 +04:00
|
|
|
aList->AppendToTop(&bgItemList);
|
2013-07-24 11:38:55 +04:00
|
|
|
return false;
|
2012-12-14 02:16:14 +04:00
|
|
|
}
|
2012-10-25 09:32:25 +04:00
|
|
|
|
2013-11-08 19:08:03 +04:00
|
|
|
bool needBlendContainer = false;
|
|
|
|
|
2012-09-13 14:34:23 +04:00
|
|
|
// Passing bg == nullptr in this macro will result in one iteration with
|
|
|
|
// i = 0.
|
|
|
|
NS_FOR_VISIBLE_BACKGROUND_LAYERS_BACK_TO_FRONT(i, bg) {
|
2012-12-14 02:16:14 +04:00
|
|
|
if (bg->mLayers[i].mImage.IsEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-08 19:08:03 +04:00
|
|
|
|
|
|
|
if (bg->mLayers[i].mBlendMode != NS_STYLE_BLEND_NORMAL) {
|
|
|
|
needBlendContainer = true;
|
|
|
|
}
|
|
|
|
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage* bgItem =
|
2013-07-18 10:34:58 +04:00
|
|
|
new (aBuilder) nsDisplayBackgroundImage(aBuilder, aFrame, i, bg);
|
2013-11-08 19:08:03 +04:00
|
|
|
bgItemList.AppendNewToTop(bgItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needBlendContainer) {
|
|
|
|
bgItemList.AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayBlendContainer(aBuilder, aFrame, &bgItemList));
|
2012-09-13 14:34:23 +04:00
|
|
|
}
|
|
|
|
|
2013-11-08 19:08:03 +04:00
|
|
|
aList->AppendToTop(&bgItemList);
|
2013-07-24 11:38:55 +04:00
|
|
|
return false;
|
2012-09-13 14:34:23 +04:00
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
// 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-29 10:19:26 +04:00
|
|
|
static bool
|
2010-10-11 22:03:12 +04:00
|
|
|
RoundedBorderIntersectsRect(nsIFrame* aFrame,
|
|
|
|
const nsPoint& aFrameToReferenceFrame,
|
|
|
|
const nsRect& aTestRect)
|
|
|
|
{
|
2011-01-04 13:40:02 +03:00
|
|
|
if (!nsRect(aFrameToReferenceFrame, aFrame->GetSize()).Intersects(aTestRect))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-04 13:40:02 +03:00
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
nscoord radii[8];
|
|
|
|
return !aFrame->GetBorderRadii(radii) ||
|
2013-03-06 15:08:16 +04:00
|
|
|
nsLayoutUtils::RoundedRectIntersectsRect(nsRect(aFrameToReferenceFrame,
|
|
|
|
aFrame->GetSize()),
|
|
|
|
radii, aTestRect);
|
2010-10-11 22:03:12 +04:00
|
|
|
}
|
|
|
|
|
2009-04-24 13:24:44 +04:00
|
|
|
// Returns TRUE if aContainedRect is guaranteed to be contained in
|
|
|
|
// the rounded rect defined by aRoundedRect and aRadii. Complex cases are
|
|
|
|
// handled conservatively by returning FALSE in some situations where
|
|
|
|
// a more thorough analysis could return TRUE.
|
2010-10-11 22:03:12 +04:00
|
|
|
//
|
|
|
|
// See also RoundedRectIntersectsRect.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool RoundedRectContainsRect(const nsRect& aRoundedRect,
|
2012-11-15 05:35:18 +04:00
|
|
|
const nscoord aRadii[8],
|
|
|
|
const nsRect& aContainedRect) {
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(aRoundedRect, aRadii, aContainedRect);
|
|
|
|
return rgn.Contains(aContainedRect);
|
2009-04-24 13:24:44 +04:00
|
|
|
}
|
|
|
|
|
2012-07-23 07:00:36 +04:00
|
|
|
bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
|
2012-11-15 05:35:18 +04:00
|
|
|
const nsRect& aClipRect,
|
|
|
|
gfxRect* aDestRect)
|
2012-07-23 07:00:36 +04:00
|
|
|
{
|
2013-07-18 10:34:58 +04:00
|
|
|
if (!mBackgroundStyle)
|
2012-07-23 07:00:36 +04:00
|
|
|
return false;
|
|
|
|
|
2012-12-17 08:30:57 +04:00
|
|
|
if (mBackgroundStyle->mLayers.Length() != 1)
|
|
|
|
return false;
|
|
|
|
|
2012-07-23 07:00:36 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-11-10 09:42:10 +04:00
|
|
|
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-07-23 07:00:36 +04:00
|
|
|
|
|
|
|
if (layer.mAttachment != NS_STYLE_BG_ATTACHMENT_FIXED)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsBackgroundLayerState state =
|
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext,
|
|
|
|
mFrame,
|
|
|
|
flags,
|
|
|
|
borderArea,
|
|
|
|
aClipRect,
|
2012-11-10 09:42:10 +04:00
|
|
|
*mBackgroundStyle,
|
2012-07-23 07:00:36 +04:00
|
|
|
layer);
|
|
|
|
|
|
|
|
nsImageRenderer* imageRenderer = &state.mImageRenderer;
|
|
|
|
// We only care about images here, not gradients.
|
|
|
|
if (!imageRenderer->IsRasterImage())
|
|
|
|
return false;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-11-15 05:35:18 +04:00
|
|
|
*aDestRect = nsLayoutUtils::RectToGfxRect(state.mFillArea, appUnitsPerDevPixel);
|
2012-07-23 07:00:36 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-04 00:13:12 +04:00
|
|
|
bool
|
2012-11-28 06:34:45 +04:00
|
|
|
nsDisplayBackgroundImage::TryOptimizeToImageLayer(LayerManager* aManager,
|
|
|
|
nsDisplayListBuilder* aBuilder)
|
2012-05-04 00:13:12 +04:00
|
|
|
{
|
2013-07-18 10:34:58 +04:00
|
|
|
if (!mBackgroundStyle)
|
2012-05-04 00:13:12 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-11-10 09:42:10 +04:00
|
|
|
nsRect borderArea = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-02-28 12:49:30 +04:00
|
|
|
if (layer.mClip != NS_STYLE_BG_CLIP_BORDER) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nscoord radii[8];
|
|
|
|
if (mFrame->GetBorderRadii(radii)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-04 00:13:12 +04:00
|
|
|
nsBackgroundLayerState state =
|
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext,
|
|
|
|
mFrame,
|
|
|
|
flags,
|
|
|
|
borderArea,
|
|
|
|
borderArea,
|
2012-11-10 09:42:10 +04:00
|
|
|
*mBackgroundStyle,
|
2012-05-04 00:13:12 +04:00
|
|
|
layer);
|
|
|
|
|
2012-05-21 21:47:40 +04:00
|
|
|
nsImageRenderer* imageRenderer = &state.mImageRenderer;
|
2012-05-04 00:13:12 +04:00
|
|
|
// We only care about images here, not gradients.
|
2012-11-19 07:28:18 +04:00
|
|
|
if (!imageRenderer->IsRasterImage())
|
2012-05-21 21:47:40 +04:00
|
|
|
return false;
|
|
|
|
|
2012-11-28 06:34:45 +04:00
|
|
|
nsRefPtr<ImageContainer> imageContainer = imageRenderer->GetContainer(aManager);
|
2012-05-21 21:47:40 +04:00
|
|
|
// Image is not ready to be made into a layer yet
|
|
|
|
if (!imageContainer)
|
2012-05-04 00:13:12 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// We currently can't handle tiled or partial backgrounds.
|
|
|
|
if (!state.mDestArea.IsEqualEdges(state.mFillArea)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-10 04:08:41 +04:00
|
|
|
// XXX Ignoring state.mAnchor. ImageLayer drawing snaps mDestArea edges to
|
|
|
|
// layer pixel boundaries. This should be OK for now.
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2012-05-04 00:13:12 +04:00
|
|
|
mDestRect = nsLayoutUtils::RectToGfxRect(state.mDestArea, appUnitsPerDevPixel);
|
2012-05-21 21:47:40 +04:00
|
|
|
mImageContainer = imageContainer;
|
2012-05-04 00:13:12 +04:00
|
|
|
|
|
|
|
// Ok, we can turn this into a layer if needed.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-19 07:28:18 +04:00
|
|
|
already_AddRefed<ImageContainer>
|
2012-11-28 06:34:45 +04:00
|
|
|
nsDisplayBackgroundImage::GetContainer(LayerManager* aManager,
|
|
|
|
nsDisplayListBuilder *aBuilder)
|
2012-11-19 07:28:18 +04:00
|
|
|
{
|
2012-11-28 06:34:45 +04:00
|
|
|
if (!TryOptimizeToImageLayer(aManager, aBuilder)) {
|
2012-11-19 07:28:18 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ImageContainer> container = mImageContainer;
|
|
|
|
|
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
2012-05-04 00:13:12 +04:00
|
|
|
LayerState
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2012-05-04 00:13:12 +04:00
|
|
|
{
|
2013-06-03 18:57:06 +04:00
|
|
|
bool animated = false;
|
2013-07-18 10:34:58 +04:00
|
|
|
if (mBackgroundStyle) {
|
2013-06-03 18:57:06 +04:00
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
|
|
|
const nsStyleImage* image = &layer.mImage;
|
|
|
|
if (image->GetType() == eStyleImageType_Image) {
|
|
|
|
imgIRequest* imgreq = image->GetImageData();
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (NS_SUCCEEDED(imgreq->GetImage(getter_AddRefs(image))) && image) {
|
|
|
|
if (NS_FAILED(image->GetAnimated(&animated))) {
|
|
|
|
animated = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!animated ||
|
|
|
|
!nsLayoutUtils::AnimatedImageLayersEnabled()) {
|
2013-05-30 17:50:50 +04:00
|
|
|
if (!aManager->IsCompositingCheap() ||
|
|
|
|
!nsLayoutUtils::GPUImageScalingEnabled()) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2012-05-04 00:13:12 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:57:06 +04:00
|
|
|
if (!TryOptimizeToImageLayer(aManager, aBuilder)) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!animated) {
|
2013-12-13 21:32:02 +04:00
|
|
|
mozilla::gfx::IntSize imageSize = mImageContainer->GetCurrentSize();
|
2013-05-30 17:50:50 +04:00
|
|
|
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
gfxRect destRect = mDestRect;
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
destRect.width *= aParameters.mXScale;
|
|
|
|
destRect.height *= aParameters.mYScale;
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
// Calculate the scaling factor for the frame.
|
|
|
|
gfxSize scale = gfxSize(destRect.width / imageSize.width, destRect.height / imageSize.height);
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
// If we are not scaling at all, no point in separating this into a layer.
|
|
|
|
if (scale.width == 1.0f && scale.height == 1.0f) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
// If the target size is pretty small, no point in using a layer.
|
|
|
|
if (destRect.width * destRect.height < 64 * 64) {
|
|
|
|
return LAYER_NONE;
|
|
|
|
}
|
2012-05-04 00:13:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2012-05-04 00:13:12 +04:00
|
|
|
{
|
2013-05-30 06:42:28 +04:00
|
|
|
nsRefPtr<ImageLayer> layer = static_cast<ImageLayer*>
|
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, this));
|
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-05-04 00:13:12 +04:00
|
|
|
layer->SetContainer(mImageContainer);
|
2012-11-19 07:28:18 +04:00
|
|
|
ConfigureLayer(layer, aParameters.mOffset);
|
2012-05-04 00:13:12 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-19 07:28:18 +04:00
|
|
|
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset)
|
2012-05-04 00:13:12 +04:00
|
|
|
{
|
|
|
|
aLayer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(mFrame));
|
|
|
|
|
2013-12-13 21:32:02 +04:00
|
|
|
mozilla::gfx::IntSize imageSize = mImageContainer->GetCurrentSize();
|
2012-05-04 00:13:12 +04:00
|
|
|
NS_ASSERTION(imageSize.width != 0 && imageSize.height != 0, "Invalid image size!");
|
|
|
|
|
|
|
|
gfxMatrix transform;
|
2012-11-19 07:28:18 +04:00
|
|
|
transform.Translate(mDestRect.TopLeft() + aOffset);
|
2012-05-04 00:13:12 +04:00
|
|
|
transform.Scale(mDestRect.width/imageSize.width,
|
|
|
|
mDestRect.height/imageSize.height);
|
2012-07-31 06:20:00 +04:00
|
|
|
aLayer->SetBaseTransform(gfx3DMatrix::From2D(transform));
|
2012-05-04 00:13:12 +04:00
|
|
|
aLayer->SetVisibleRegion(nsIntRect(0, 0, imageSize.width, imageSize.height));
|
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
void
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
2010-10-11 22:03:12 +04:00
|
|
|
{
|
2013-07-18 10:34:58 +04:00
|
|
|
if (RoundedBorderIntersectsRect(mFrame, ToReferenceFrame(), aRect)) {
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
2010-10-11 22:03:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-16 01:08:06 +04:00
|
|
|
{
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2010-07-16 01:08:09 +04:00
|
|
|
|
2010-07-16 01:08:06 +04:00
|
|
|
// Return false if the background was propagated away from this
|
|
|
|
// frame. We don't want this display item to show up and confuse
|
|
|
|
// anything.
|
2013-07-18 10:34:58 +04:00
|
|
|
return mBackgroundStyle;
|
2010-07-16 01:08:06 +04:00
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
/* static */ nsRegion
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetInsideClipRegion(nsDisplayItem* aItem,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
uint8_t aClip, const nsRect& aRect,
|
|
|
|
bool* aSnap)
|
2011-01-03 04:48:09 +03:00
|
|
|
{
|
|
|
|
nsRegion result;
|
|
|
|
if (aRect.IsEmpty())
|
|
|
|
return result;
|
|
|
|
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame *frame = aItem->Frame();
|
2012-10-25 09:32:25 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nscoord radii[8];
|
|
|
|
nsRect clipRect;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveRadii;
|
2011-01-03 04:48:09 +03:00
|
|
|
switch (aClip) {
|
|
|
|
case NS_STYLE_BG_CLIP_BORDER:
|
2012-10-25 09:32:25 +04:00
|
|
|
haveRadii = frame->GetBorderRadii(radii);
|
|
|
|
clipRect = nsRect(aItem->ToReferenceFrame(), frame->GetSize());
|
2011-01-03 04:48:09 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_PADDING:
|
2012-10-25 09:32:25 +04:00
|
|
|
haveRadii = frame->GetPaddingBoxBorderRadii(radii);
|
|
|
|
clipRect = frame->GetPaddingRect() - frame->GetPosition() + aItem->ToReferenceFrame();
|
2011-01-03 04:48:09 +03:00
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_CONTENT:
|
2012-10-25 09:32:25 +04:00
|
|
|
haveRadii = frame->GetContentBoxBorderRadii(radii);
|
|
|
|
clipRect = frame->GetContentRect() - frame->GetPosition() + aItem->ToReferenceFrame();
|
2011-01-03 04:48:09 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown clip type");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (haveRadii) {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
|
|
|
result = nsLayoutUtils::RoundedRectIntersectRect(clipRect, radii, aRect);
|
2011-01-03 04:48:09 +03:00
|
|
|
} else {
|
2012-05-09 23:53:15 +04:00
|
|
|
result = clipRect.Intersect(aRect);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) {
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle)
|
2011-01-03 04:48:09 +03:00
|
|
|
return result;
|
2012-11-08 08:08:40 +04:00
|
|
|
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = true;
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
// For policies other than EACH_BOX, don't try to optimize here, since
|
|
|
|
// this could easily lead to O(N^2) behavior inside InlineBackgroundData,
|
|
|
|
// which expects frames to be sent to it in content order, not reverse
|
|
|
|
// content order which we'll produce here.
|
|
|
|
// Of course, if there's only one frame in the flow, it doesn't matter.
|
2012-11-08 08:08:40 +04:00
|
|
|
if (mBackgroundStyle->mBackgroundInlinePolicy == NS_STYLE_BG_INLINE_POLICY_EACH_BOX ||
|
2011-01-03 04:48:09 +03:00
|
|
|
(!mFrame->GetPrevContinuation() && !mFrame->GetNextContinuation())) {
|
2012-11-08 08:08:40 +04:00
|
|
|
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
|
2013-11-08 19:08:03 +04:00
|
|
|
if (layer.mImage.IsOpaque() && layer.mBlendMode == NS_STYLE_BLEND_NORMAL) {
|
2012-11-08 08:08:40 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2013-02-04 16:11:49 +04:00
|
|
|
result = GetInsideClipRegion(this, presContext, layer.mClip, mBounds, aSnap);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
return result;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle) {
|
2010-05-13 04:56:11 +04:00
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-05-13 04:56:11 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle->HasFixedBackground())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2010-08-13 13:54:37 +04:00
|
|
|
// If aFrame is mFrame or an ancestor in this document, and aFrame is
|
|
|
|
// not the viewport frame, then moving aFrame will move mFrame
|
|
|
|
// relative to the viewport, so our fixed-pos background will change.
|
|
|
|
return aFrame->GetParent() &&
|
|
|
|
(aFrame == mFrame ||
|
|
|
|
nsLayoutUtils::IsProperAncestorFrame(aFrame, mFrame));
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2012-11-08 19:05:32 +04:00
|
|
|
nsRect
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetPositioningArea()
|
2012-11-08 19:05:32 +04: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-29 09:39:01 +04:00
|
|
|
bool
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::RenderingMightDependOnPositioningAreaSizeChange()
|
2012-08-29 09:39:01 +04:00
|
|
|
{
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle)
|
2012-08-29 09:39:01 +04:00
|
|
|
return false;
|
|
|
|
|
2012-11-08 19:05:32 +04: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-08 08:08:40 +04:00
|
|
|
const nsStyleBackground::Layer &layer = mBackgroundStyle->mLayers[mLayer];
|
2012-11-08 19:05:32 +04:00
|
|
|
if (layer.RenderingMightDependOnPositioningAreaSizeChange()) {
|
2012-10-25 09:32:25 +04:00
|
|
|
return true;
|
2012-08-29 09:39:01 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04: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 &&
|
2013-04-19 16:02:13 +04:00
|
|
|
nextItem->Frame() == aItem->Frame() &&
|
2012-10-25 09:32:25 +04:00
|
|
|
nextItem->GetType() == nsDisplayItem::TYPE_BORDER) {
|
|
|
|
aFlags |= nsCSSRendering::PAINTBG_WILL_PAINT_BORDER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx) {
|
2012-12-13 05:15:55 +04:00
|
|
|
PaintInternal(aBuilder, aCtx, mVisibleRect, nullptr);
|
|
|
|
}
|
2012-07-23 07:00:36 +04:00
|
|
|
|
2012-12-13 05:15:55 +04:00
|
|
|
void
|
|
|
|
nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx, const nsRect& aBounds,
|
|
|
|
nsRect* aClipRect) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = aBuilder->GetBackgroundPaintFlags();
|
2012-10-25 09:32:25 +04:00
|
|
|
CheckForBorderItem(this, flags);
|
2012-12-13 05:15:55 +04:00
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
2012-12-13 05:15:55 +04:00
|
|
|
aBounds,
|
2009-09-07 04:35:14 +04:00
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2012-12-13 05:15:55 +04:00
|
|
|
flags, aClipRect, mLayer);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2012-11-10 03:14:59 +04:00
|
|
|
void nsDisplayBackgroundImage::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
2012-08-29 09:39:01 +04:00
|
|
|
{
|
2013-07-18 10:34:58 +04:00
|
|
|
if (!mBackgroundStyle) {
|
2012-08-29 09:39:01 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-08 19:05:32 +04:00
|
|
|
const nsDisplayBackgroundGeometry* geometry = static_cast<const nsDisplayBackgroundGeometry*>(aGeometry);
|
|
|
|
|
2012-08-29 09:39:01 +04:00
|
|
|
bool snap;
|
2012-11-08 19:05:32 +04: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;
|
|
|
|
}
|
2013-06-26 20:43:27 +04:00
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
if (mBackgroundStyle &&
|
|
|
|
!nsCSSRendering::IsBackgroundImageDecodedForStyleContextAndLayer(mBackgroundStyle, mLayer)) {
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, bounds);
|
|
|
|
}
|
|
|
|
}
|
2012-11-08 19:05:32 +04:00
|
|
|
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-29 09:39:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-18 08:26:38 +03:00
|
|
|
nsRect
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
2012-10-25 09:32:25 +04:00
|
|
|
*aSnap = true;
|
2012-11-28 08:05:32 +04:00
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2013-06-04 08:49:03 +04:00
|
|
|
nsDisplayBackgroundImage::GetBoundsInternal(nsDisplayListBuilder* aBuilder) {
|
2011-01-04 13:39:47 +03:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
|
2012-11-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle) {
|
2012-10-25 09:32:25 +04:00
|
|
|
return nsRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2013-02-04 16:11:49 +04:00
|
|
|
nsRect clipRect = borderBox;
|
|
|
|
if (mFrame->GetType() == nsGkAtoms::canvasFrame) {
|
|
|
|
nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
|
|
|
|
clipRect = frame->CanvasArea() + ToReferenceFrame();
|
|
|
|
}
|
2012-11-08 08:08:40 +04:00
|
|
|
const nsStyleBackground::Layer& layer = mBackgroundStyle->mLayers[mLayer];
|
2012-10-25 09:32:25 +04:00
|
|
|
return nsCSSRendering::GetBackgroundLayerRect(presContext, mFrame,
|
2013-06-04 08:49:03 +04:00
|
|
|
borderBox, clipRect,
|
|
|
|
*mBackgroundStyle, layer,
|
|
|
|
aBuilder->GetBackgroundPaintFlags());
|
2007-12-18 08:26:38 +03:00
|
|
|
}
|
|
|
|
|
2012-09-13 14:34:23 +04:00
|
|
|
uint32_t
|
2012-11-10 03:14:59 +04:00
|
|
|
nsDisplayBackgroundImage::GetPerFrameKey()
|
2012-09-13 14:34:23 +04:00
|
|
|
{
|
|
|
|
return (mLayer << nsDisplayItem::TYPE_BITS) |
|
|
|
|
nsDisplayItem::GetPerFrameKey();
|
|
|
|
}
|
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
nsDisplayThemedBackground::nsDisplayThemedBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayThemedBackground);
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp = mFrame->StyleDisplay();
|
|
|
|
mAppearance = disp->mAppearance;
|
|
|
|
mFrame->IsThemed(disp, &mThemeTransparency);
|
2013-06-13 01:42:00 +04:00
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
// Perform necessary RegisterThemeGeometry
|
2013-06-13 01:42:00 +04:00
|
|
|
switch (disp->mAppearance) {
|
|
|
|
case NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR:
|
|
|
|
case NS_THEME_TOOLBAR:
|
|
|
|
case NS_THEME_WINDOW_TITLEBAR:
|
|
|
|
case NS_THEME_WINDOW_BUTTON_BOX:
|
|
|
|
case NS_THEME_MOZ_MAC_FULLSCREEN_BUTTON:
|
|
|
|
RegisterThemeGeometry(aBuilder, aFrame);
|
|
|
|
break;
|
|
|
|
case NS_THEME_WIN_BORDERLESS_GLASS:
|
|
|
|
case NS_THEME_WIN_GLASS:
|
|
|
|
aBuilder->SetGlassDisplayItem(this);
|
|
|
|
break;
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds = GetBoundsInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayThemedBackground::~nsDisplayThemedBackground()
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayThemedBackground);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
2014-01-27 02:07:08 +04:00
|
|
|
nsDisplayThemedBackground::WriteDebugInfo(nsACString& aTo)
|
2013-07-18 10:34:58 +04:00
|
|
|
{
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += nsPrintfCString("(themed, appearance:%d) ", mAppearance);
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayThemedBackground::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
// Assume that any point in our border rect is a hit.
|
|
|
|
if (nsRect(ToReferenceFrame(), mFrame->GetSize()).Intersects(aRect)) {
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsDisplayThemedBackground::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) {
|
|
|
|
nsRegion result;
|
|
|
|
*aSnap = false;
|
|
|
|
|
|
|
|
if (mThemeTransparency == nsITheme::eOpaque) {
|
|
|
|
result = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayThemedBackground::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
|
|
|
if (mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
|
|
|
|
mAppearance == NS_THEME_WIN_GLASS) {
|
|
|
|
*aColor = NS_RGBA(0,0,0,0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayThemedBackground::GetPositioningArea()
|
|
|
|
{
|
|
|
|
return nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayThemedBackground::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
|
|
|
PaintInternal(aBuilder, aCtx, mVisibleRect, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayThemedBackground::PaintInternal(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx, const nsRect& aBounds,
|
|
|
|
nsRect* aClipRect)
|
|
|
|
{
|
|
|
|
// XXXzw this ignores aClipRect.
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsITheme *theme = presContext->GetTheme();
|
|
|
|
nsRect borderArea(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
nsRect drawing(borderArea);
|
|
|
|
theme->GetWidgetOverflow(presContext->DeviceContext(), mFrame, mAppearance,
|
|
|
|
&drawing);
|
|
|
|
drawing.IntersectRect(drawing, aBounds);
|
|
|
|
theme->DrawWidgetBackground(aCtx, mFrame, mAppearance, borderArea, drawing);
|
|
|
|
}
|
|
|
|
|
2013-09-27 19:24:32 +04:00
|
|
|
bool nsDisplayThemedBackground::IsWindowActive()
|
|
|
|
{
|
|
|
|
nsEventStates docState = mFrame->GetContent()->OwnerDoc()->GetDocumentState();
|
|
|
|
return !docState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE);
|
|
|
|
}
|
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
void nsDisplayThemedBackground::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsDisplayThemedBackgroundGeometry* geometry = static_cast<const nsDisplayThemedBackgroundGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
nsRect positioningArea = GetPositioningArea();
|
|
|
|
if (!positioningArea.IsEqualInterior(geometry->mPositioningArea)) {
|
|
|
|
// 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);
|
|
|
|
}
|
2013-09-27 19:24:32 +04:00
|
|
|
nsITheme* theme = mFrame->PresContext()->GetTheme();
|
|
|
|
if (theme->WidgetAppearanceDependsOnWindowFocus(mAppearance) &&
|
|
|
|
IsWindowActive() != geometry->mWindowIsActive) {
|
|
|
|
aInvalidRegion->Or(*aInvalidRegion, bounds);
|
|
|
|
}
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayThemedBackground::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = true;
|
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayThemedBackground::GetBoundsInternal() {
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
|
|
|
|
nsRect r(nsPoint(0,0), mFrame->GetSize());
|
|
|
|
presContext->GetTheme()->
|
|
|
|
GetWidgetOverflow(presContext->DeviceContext(), mFrame,
|
|
|
|
mFrame->StyleDisplay()->mAppearance, &r);
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Bug 748219
|
|
|
|
r.Inflate(mFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return r + ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04: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-08 08:08:40 +04:00
|
|
|
if (!mBackgroundStyle)
|
2012-10-25 09:32:25 +04:00
|
|
|
return nsRegion();
|
|
|
|
|
|
|
|
*aSnap = true;
|
|
|
|
|
2012-11-08 08:08:40 +04:00
|
|
|
const nsStyleBackground::Layer& bottomLayer = mBackgroundStyle->BottomLayer();
|
2012-10-25 09:32:25 +04:00
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2012-11-08 08:08:40 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
2012-11-10 03:14:59 +04:00
|
|
|
return nsDisplayBackgroundImage::GetInsideClipRegion(this, presContext, bottomLayer.mClip, borderBox, aSnap);
|
2012-10-25 09:32:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayBackgroundColor::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
|
|
|
|
{
|
|
|
|
*aColor = mColor;
|
2012-11-08 08:08:40 +04:00
|
|
|
|
|
|
|
if (!mBackgroundStyle)
|
2012-10-25 09:32:25 +04:00
|
|
|
return true;
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
return (!nsLayoutUtils::HasNonZeroCorner(mFrame->StyleBorder()->mBorderRadius) &&
|
2012-11-08 08:08:40 +04:00
|
|
|
mBackgroundStyle->BottomLayer().mClip == NS_STYLE_BG_CLIP_BORDER);
|
2012-10-25 09:32:25 +04: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);
|
|
|
|
}
|
|
|
|
|
2014-01-27 02:07:08 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
|
|
|
nsDisplayBackgroundColor::WriteDebugInfo(nsACString& aTo)
|
|
|
|
{
|
|
|
|
aTo += nsPrintfCString("(rgba %d,%d,%d,%d)",
|
|
|
|
NS_GET_R(mColor), NS_GET_G(mColor),
|
|
|
|
NS_GET_B(mColor), NS_GET_A(mColor));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayOutline::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2010-11-17 05:20:25 +03:00
|
|
|
return mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayOutline::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// TODO join outlines together
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintOutline(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2013-02-16 09:38:33 +04:00
|
|
|
mFrame->StyleContext());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayOutline::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2006-09-20 01:58:52 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleOutline* outline = mFrame->StyleOutline();
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect borderBox(ToReferenceFrame(), mFrame->GetSize());
|
2009-10-07 08:28:41 +04:00
|
|
|
if (borderBox.Contains(aVisibleRegion->GetBounds()) &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(outline->mOutlineRadius)) {
|
2008-09-13 07:45:37 +04:00
|
|
|
if (outline->mOutlineOffset >= 0) {
|
2006-09-20 01:58:52 +04:00
|
|
|
// the visible region is entirely inside the border-rect, and the outline
|
|
|
|
// isn't rendered inside the border-rect, so the outline is not visible
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
|
|
|
|
2010-10-11 22:03:12 +04:00
|
|
|
void
|
|
|
|
nsDisplayEventReceiver::HitTest(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
if (!RoundedBorderIntersectsRect(mFrame, ToReferenceFrame(), aRect)) {
|
|
|
|
// aRect doesn't intersect our border-radius curve.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
|
|
|
|
2013-12-16 15:22:11 +04:00
|
|
|
void
|
|
|
|
nsDisplayLayerEventRegions::AddFrame(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aBuilder->FindReferenceFrameFor(aFrame) == aBuilder->FindReferenceFrameFor(mFrame),
|
|
|
|
"Reference frame mismatch");
|
|
|
|
uint8_t pointerEvents = aFrame->StyleVisibility()->mPointerEvents;
|
|
|
|
if (pointerEvents == NS_STYLE_POINTER_EVENTS_NONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// XXX handle other pointerEvents values for SVG
|
|
|
|
// XXX Do something clever here for the common case where the border box
|
|
|
|
// is obviously entirely inside mHitRegion.
|
|
|
|
nsRect borderBox(aBuilder->ToReferenceFrame(aFrame), aFrame->GetSize());
|
|
|
|
const DisplayItemClip* clip = aBuilder->ClipState().GetCurrentCombinedClip(aBuilder);
|
|
|
|
bool borderBoxHasRoundedCorners =
|
|
|
|
nsLayoutUtils::HasNonZeroCorner(aFrame->StyleBorder()->mBorderRadius);
|
|
|
|
if (clip) {
|
|
|
|
borderBox = clip->ApplyNonRoundedIntersection(borderBox);
|
|
|
|
if (clip->GetRoundedRectCount() > 0) {
|
|
|
|
borderBoxHasRoundedCorners = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (borderBoxHasRoundedCorners ||
|
|
|
|
(aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT)) {
|
|
|
|
mMaybeHitRegion.Or(mMaybeHitRegion, borderBox);
|
|
|
|
} else {
|
|
|
|
mHitRegion.Or(mHitRegion, borderBox);
|
|
|
|
}
|
|
|
|
if (aBuilder->GetAncestorHasTouchEventHandler()) {
|
|
|
|
mDispatchToContentHitRegion.Or(mDispatchToContentHitRegion, borderBox);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-18 03:16:46 +04:00
|
|
|
void
|
|
|
|
nsDisplayCaret::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2006-04-18 03:16:46 +04:00
|
|
|
// Note: Because we exist, we know that the caret is visible, so we don't
|
|
|
|
// need to check for the caret's visibility.
|
2010-08-13 14:01:58 +04:00
|
|
|
mCaret->PaintCaret(aBuilder, aCtx, mFrame, ToReferenceFrame());
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayBorder::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2006-09-20 01:58:52 +04:00
|
|
|
|
2007-09-28 02:52:32 +04:00
|
|
|
nsRect paddingRect = mFrame->GetPaddingRect() - mFrame->GetPosition() +
|
2010-08-13 14:01:58 +04:00
|
|
|
ToReferenceFrame();
|
2008-07-17 10:30:25 +04:00
|
|
|
const nsStyleBorder *styleBorder;
|
2007-09-28 02:52:32 +04:00
|
|
|
if (paddingRect.Contains(aVisibleRegion->GetBounds()) &&
|
2013-02-17 01:51:02 +04:00
|
|
|
!(styleBorder = mFrame->StyleBorder())->IsBorderImageLoaded() &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(styleBorder->mBorderRadius)) {
|
2006-09-20 01:58:52 +04:00
|
|
|
// the visible region is entirely inside the content rect, and no part
|
|
|
|
// of the border is rendered inside the content rect, so we are not
|
|
|
|
// visible
|
2008-07-17 10:30:25 +04:00
|
|
|
// Skip this if there's a border-image (which draws a background
|
|
|
|
// too) or if there is a border-radius (which makes the border draw
|
|
|
|
// further in).
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
2012-08-29 09:39:01 +04:00
|
|
|
|
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsDisplayBorder::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsDisplayBorderGeometry(this, aBuilder);
|
|
|
|
}
|
2006-09-20 01:58:52 +04:00
|
|
|
|
2012-08-29 09:39:01 +04: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
void
|
|
|
|
nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2007-03-31 01:11:41 +04:00
|
|
|
nsCSSRendering::PaintBorder(mFrame->PresContext(), *aCtx, mFrame,
|
2009-09-07 04:35:14 +04:00
|
|
|
mVisibleRect,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
2013-02-16 09:38:33 +04:00
|
|
|
mFrame->StyleContext(),
|
2008-08-06 14:33:18 +04:00
|
|
|
mFrame->GetSkipSides());
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-01-04 13:39:47 +03:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayBorder::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-01-04 13:39:47 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = true;
|
2013-12-09 03:01:30 +04:00
|
|
|
const nsStyleBorder *styleBorder = mFrame->StyleBorder();
|
|
|
|
nsRect borderBounds(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
if (styleBorder->IsBorderImageLoaded()) {
|
|
|
|
borderBounds.Inflate(mFrame->StyleBorder()->GetImageOutset());
|
|
|
|
return borderBounds;
|
|
|
|
} else {
|
|
|
|
nsMargin border = styleBorder->GetComputedBorder();
|
|
|
|
nsRect result;
|
|
|
|
if (border.top > 0) {
|
|
|
|
result = nsRect(borderBounds.X(), borderBounds.Y(), borderBounds.Width(), border.top);
|
|
|
|
}
|
|
|
|
if (border.right > 0) {
|
|
|
|
result.UnionRect(result, nsRect(borderBounds.XMost() - border.right, borderBounds.Y(), border.right, borderBounds.Height()));
|
|
|
|
}
|
|
|
|
if (border.bottom > 0) {
|
|
|
|
result.UnionRect(result, nsRect(borderBounds.X(), borderBounds.YMost() - border.bottom, borderBounds.Width(), border.bottom));
|
|
|
|
}
|
|
|
|
if (border.left > 0) {
|
|
|
|
result.UnionRect(result, nsRect(borderBounds.X(), borderBounds.Y(), border.left, borderBounds.Height()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2011-01-04 13:39:47 +03:00
|
|
|
}
|
|
|
|
|
2009-12-01 02:14:04 +03:00
|
|
|
// Given a region, compute a conservative approximation to it as a list
|
|
|
|
// of rectangles that aren't vertically adjacent (i.e., vertically
|
|
|
|
// adjacent or overlapping rectangles are combined).
|
|
|
|
// Right now this is only approximate, some vertically overlapping rectangles
|
|
|
|
// aren't guaranteed to be combined.
|
|
|
|
static void
|
|
|
|
ComputeDisjointRectangles(const nsRegion& aRegion,
|
|
|
|
nsTArray<nsRect>* aRects) {
|
|
|
|
nscoord accumulationMargin = nsPresContext::CSSPixelsToAppUnits(25);
|
|
|
|
nsRect accumulated;
|
|
|
|
nsRegionRectIterator iter(aRegion);
|
2011-10-17 18:59:28 +04:00
|
|
|
while (true) {
|
2009-12-01 02:14:04 +03: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-19 07:07:23 +04:00
|
|
|
accumulated.SetEmpty();
|
2009-12-01 02:14:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!r)
|
|
|
|
break;
|
|
|
|
|
|
|
|
accumulated = *r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-08 04:57:47 +04:00
|
|
|
void
|
2009-02-10 11:45:13 +03:00
|
|
|
nsDisplayBoxShadowOuter::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2013-04-18 00:16:14 +04:00
|
|
|
nsRect borderRect = mFrame->VisualBorderRectRelativeToSelf() + offset;
|
2009-12-01 02:14:04 +03:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsDisplayBoxShadowOuter", "Paint");
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2009-12-01 02:14:04 +03:00
|
|
|
aCtx->PushState();
|
2011-04-08 05:04:40 +04:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-12-01 02:14:04 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowOuter(presContext, *aCtx, mFrame,
|
2013-11-18 13:32:09 +04:00
|
|
|
borderRect, rects[i], mOpacity);
|
2009-12-01 02:14:04 +03:00
|
|
|
aCtx->PopState();
|
|
|
|
}
|
2008-07-08 04:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayBoxShadowOuter::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2012-12-12 00:36:54 +04:00
|
|
|
return mBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayBoxShadowOuter::GetBoundsInternal() {
|
|
|
|
return nsLayoutUtils::GetBoxShadowRectForFrame(mFrame, mFrame->GetSize()) +
|
|
|
|
ToReferenceFrame();
|
2008-07-08 04:57:47 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayBoxShadowOuter::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2009-01-30 10:03:46 +03:00
|
|
|
|
2009-12-01 02:14:04 +03:00
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint origin = ToReferenceFrame();
|
2009-10-07 08:28:41 +04:00
|
|
|
nsRect visibleBounds = aVisibleRegion->GetBounds();
|
2009-04-24 13:24:44 +04:00
|
|
|
nsRect frameRect(origin, mFrame->GetSize());
|
|
|
|
if (!frameRect.Contains(visibleBounds))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-04-24 13:24:44 +04: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-29 10:19:26 +04:00
|
|
|
bool hasBorderRadii = mFrame->GetBorderRadii(twipsRadii);
|
2009-04-24 13:24:44 +04:00
|
|
|
if (!hasBorderRadii)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-30 10:03:46 +03:00
|
|
|
|
2009-04-24 13:24:44 +04:00
|
|
|
return !RoundedRectContainsRect(frameRect, twipsRadii, visibleBounds);
|
2009-01-30 10:03:46 +03:00
|
|
|
}
|
|
|
|
|
2013-08-23 05:47:54 +04:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadowOuter::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsDisplayItemGenericGeometry* geometry =
|
|
|
|
static_cast<const nsDisplayItemGenericGeometry*>(aGeometry);
|
|
|
|
bool snap;
|
|
|
|
if (!geometry->mBounds.IsEqualInterior(GetBounds(aBuilder, &snap)) ||
|
|
|
|
!geometry->mBorderRect.IsEqualInterior(GetBorderRect())) {
|
|
|
|
nsRegion oldShadow, newShadow;
|
|
|
|
nscoord dontCare[8];
|
|
|
|
bool hasBorderRadius = mFrame->GetBorderRadii(dontCare);
|
|
|
|
if (hasBorderRadius) {
|
|
|
|
// If we have rounded corners then we need to invalidate the frame area
|
|
|
|
// too since we paint into it.
|
|
|
|
oldShadow = geometry->mBounds;
|
|
|
|
newShadow = GetBounds(aBuilder, &snap);
|
|
|
|
} else {
|
|
|
|
oldShadow = oldShadow.Sub(geometry->mBounds, geometry->mBorderRect);
|
|
|
|
newShadow = newShadow.Sub(GetBounds(aBuilder, &snap), GetBorderRect());
|
|
|
|
}
|
|
|
|
aInvalidRegion->Or(oldShadow, newShadow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 11:45:13 +03:00
|
|
|
void
|
|
|
|
nsDisplayBoxShadowInner::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-12-01 02:14:04 +03:00
|
|
|
nsRect borderRect = nsRect(offset, mFrame->GetSize());
|
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsAutoTArray<nsRect,10> rects;
|
|
|
|
ComputeDisjointRectangles(mVisibleRegion, &rects);
|
|
|
|
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("nsDisplayBoxShadowInner", "Paint");
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2009-12-01 02:14:04 +03:00
|
|
|
aCtx->PushState();
|
2011-04-08 05:04:40 +04:00
|
|
|
aCtx->IntersectClip(rects[i]);
|
2009-12-01 02:14:04 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
|
|
|
aCtx->PopState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-12-01 02:14:04 +03:00
|
|
|
nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2011-01-28 01:58:50 +03:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
aAllowVisibleRegionExpansion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-28 01:58:50 +03:00
|
|
|
}
|
2009-12-01 02:14:04 +03:00
|
|
|
|
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-02-10 11:45:13 +03:00
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
nsIFrame *GetTransformRootFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
|
|
|
|
while (parent && parent->Preserves3DChildren()) {
|
|
|
|
parent = nsLayoutUtils::GetCrossDocParentFrame(parent);
|
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aList);
|
2012-04-19 06:40:43 +04:00
|
|
|
UpdateBounds(aBuilder);
|
2012-10-25 09:32:25 +04: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) &&
|
2013-04-19 16:02:13 +04:00
|
|
|
i->Frame() == mFrame) {
|
2012-10-25 09:32:25 +04:00
|
|
|
mReferenceFrame = i->ReferenceFrame();
|
|
|
|
mToReferenceFrame = i->ToReferenceFrame();
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2006-01-26 05:29:17 +03:00
|
|
|
mList.AppendToTop(aItem);
|
2012-04-19 06:40:43 +04:00
|
|
|
UpdateBounds(aBuilder);
|
2012-10-25 09:32:25 +04:00
|
|
|
|
|
|
|
if (!aFrame || !aFrame->IsTransformed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame->Preserves3DChildren()) {
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See the previous nsDisplayWrapList constructor
|
2013-04-19 16:02:13 +04:00
|
|
|
if (aItem->Frame() == aFrame) {
|
2012-10-25 09:32:25 +04:00
|
|
|
mReferenceFrame = aItem->ReferenceFrame();
|
|
|
|
mToReferenceFrame = aItem->ToReferenceFrame();
|
|
|
|
}
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
2012-04-18 09:14:14 +04:00
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem,
|
2012-09-16 14:32:59 +04:00
|
|
|
const nsIFrame* aReferenceFrame,
|
2012-04-18 09:14:14 +04:00
|
|
|
const nsPoint& aToReferenceFrame)
|
2012-09-16 14:32:59 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame, aReferenceFrame, aToReferenceFrame) {
|
2012-04-18 09:14:14 +04:00
|
|
|
mList.AppendToTop(aItem);
|
|
|
|
mBounds = mList.GetBounds(aBuilder);
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void
|
|
|
|
nsDisplayWrapList::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) {
|
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayWrapList::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
|
|
|
*aSnap = false;
|
2012-04-13 15:44:06 +04:00
|
|
|
return mBounds;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-09-07 04:35:14 +04:00
|
|
|
nsDisplayWrapList::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2013-03-04 13:56:02 +04:00
|
|
|
// Convert the passed in visible region to our appunits.
|
|
|
|
nsRegion visibleRegion;
|
|
|
|
// mVisibleRect has been clipped to GetClippedBounds
|
|
|
|
visibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
nsRegion originalVisibleRegion = visibleRegion;
|
|
|
|
|
|
|
|
bool retval =
|
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &visibleRegion,
|
|
|
|
mVisibleRect,
|
|
|
|
aAllowVisibleRegionExpansion);
|
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
// removed = originalVisibleRegion - visibleRegion
|
|
|
|
removed.Sub(originalVisibleRegion, visibleRegion);
|
|
|
|
// aVisibleRegion = aVisibleRegion - removed (modulo any simplifications
|
|
|
|
// SubtractFromVisibleRegion does)
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
|
|
|
|
|
|
|
return retval;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
|
|
|
nsDisplayWrapList::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap) {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
|
|
|
if (mList.IsOpaque()) {
|
2012-04-13 15:44:06 +04:00
|
|
|
// Everything within GetBounds that's visible is opaque.
|
2012-04-10 15:24:18 +04:00
|
|
|
result = GetBounds(aBuilder, aSnap);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayWrapList::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// We could try to do something but let's conservatively just return false.
|
|
|
|
return false;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayWrapList::IsVaryingRelativeToMovingFrame(nsDisplayListBuilder* aBuilder,
|
2010-08-13 13:54:37 +04:00
|
|
|
nsIFrame* aFrame) {
|
2008-04-11 07:46:37 +04:00
|
|
|
NS_WARNING("nsDisplayWrapList::IsVaryingRelativeToMovingFrame called unexpectedly");
|
2011-10-17 18:59:28 +04:00
|
|
|
// We could try to do something but let's conservatively just return true.
|
|
|
|
return true;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsDisplayWrapList::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx) {
|
2010-03-01 10:56:19 +03:00
|
|
|
NS_ERROR("nsDisplayWrapList should have been flattened away for painting");
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2013-09-26 01:07:26 +04:00
|
|
|
static LayerState
|
|
|
|
RequiredLayerStateForChildrenInternal(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters,
|
2013-09-26 01:07:26 +04:00
|
|
|
const nsDisplayList& aList,
|
|
|
|
nsIFrame* aAnimatedGeometryRoot)
|
|
|
|
{
|
2012-11-14 10:26:29 +04:00
|
|
|
LayerState result = LAYER_INACTIVE;
|
2010-07-16 01:08:05 +04:00
|
|
|
for (nsDisplayItem* i = aList.GetBottom(); i; i = i->GetAbove()) {
|
2013-04-19 16:02:13 +04:00
|
|
|
nsIFrame* f = i->Frame();
|
2013-09-26 01:07:26 +04:00
|
|
|
if (result == LAYER_INACTIVE &&
|
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(f) != aAnimatedGeometryRoot) {
|
2013-04-19 16:01:41 +04:00
|
|
|
result = LAYER_ACTIVE;
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerState state = i->GetLayerState(aBuilder, aManager, aParameters);
|
2013-09-26 01:07:26 +04:00
|
|
|
if ((state == LAYER_ACTIVE || state == LAYER_ACTIVE_FORCE) &&
|
|
|
|
state > result) {
|
2012-11-14 10:26:29 +04:00
|
|
|
result = state;
|
2013-09-26 01:07:26 +04:00
|
|
|
}
|
2013-11-27 01:30:20 +04:00
|
|
|
if (state == LAYER_ACTIVE_EMPTY && state > result) {
|
|
|
|
result = LAYER_ACTIVE_FORCE;
|
|
|
|
}
|
2010-07-16 01:08:05 +04:00
|
|
|
if (state == LAYER_NONE) {
|
2012-11-02 16:59:03 +04:00
|
|
|
nsDisplayList* list = i->GetSameCoordinateSystemChildren();
|
2012-11-14 10:26:29 +04:00
|
|
|
if (list) {
|
2013-09-26 01:07:26 +04:00
|
|
|
LayerState childState =
|
|
|
|
RequiredLayerStateForChildrenInternal(aBuilder, aManager, aParameters, *list,
|
|
|
|
aAnimatedGeometryRoot);
|
2012-11-14 10:26:29 +04:00
|
|
|
if (childState > result) {
|
|
|
|
result = childState;
|
|
|
|
}
|
|
|
|
}
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
|
|
|
}
|
2012-11-14 10:26:29 +04:00
|
|
|
return result;
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
|
|
|
|
2013-09-26 01:07:26 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayWrapList::RequiredLayerStateForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters,
|
2013-09-26 01:07:26 +04:00
|
|
|
const nsDisplayList& aList,
|
|
|
|
nsIFrame* aItemFrame)
|
|
|
|
{
|
|
|
|
return RequiredLayerStateForChildrenInternal(
|
|
|
|
aBuilder, aManager, aParameters, aList,
|
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(aItemFrame));
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect nsDisplayWrapList::GetComponentAlphaBounds(nsDisplayListBuilder* aBuilder)
|
2010-10-11 04:58:20 +04:00
|
|
|
{
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRect bounds;
|
2010-10-11 04:58:20 +04:00
|
|
|
for (nsDisplayItem* i = mList.GetBottom(); i; i = i->GetAbove()) {
|
2011-01-03 04:48:09 +03:00
|
|
|
bounds.UnionRect(bounds, i->GetComponentAlphaBounds(aBuilder));
|
2010-10-11 04:58:20 +04:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
return bounds;
|
2010-10-11 04:58:20 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
static nsresult
|
|
|
|
WrapDisplayList(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
2010-08-13 13:55:54 +04:00
|
|
|
if (!aList->GetTop())
|
2006-01-26 05:29:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
nsDisplayItem* item = aWrapper->WrapList(aBuilder, aFrame, aList);
|
|
|
|
if (!item)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
// aList was emptied
|
|
|
|
aList->AppendToTop(item);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
WrapEachDisplayItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList, nsDisplayWrapper* aWrapper) {
|
|
|
|
nsDisplayList newList;
|
|
|
|
nsDisplayItem* item;
|
|
|
|
while ((item = aList->RemoveBottom())) {
|
|
|
|
item = aWrapper->WrapItem(aBuilder, item);
|
|
|
|
if (!item)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
newList.AppendToTop(item);
|
|
|
|
}
|
|
|
|
// aList was emptied
|
|
|
|
aList->AppendToTop(&newList);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDisplayWrapper::WrapLists(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsDisplayListSet& aIn, const nsDisplayListSet& aOut)
|
|
|
|
{
|
|
|
|
nsresult rv = WrapListsInPlace(aBuilder, aFrame, aIn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (&aOut == &aIn)
|
|
|
|
return NS_OK;
|
|
|
|
aOut.BorderBackground()->AppendToTop(aIn.BorderBackground());
|
|
|
|
aOut.BlockBorderBackgrounds()->AppendToTop(aIn.BlockBorderBackgrounds());
|
|
|
|
aOut.Floats()->AppendToTop(aIn.Floats());
|
|
|
|
aOut.Content()->AppendToTop(aIn.Content());
|
|
|
|
aOut.PositionedDescendants()->AppendToTop(aIn.PositionedDescendants());
|
|
|
|
aOut.Outlines()->AppendToTop(aIn.Outlines());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDisplayWrapper::WrapListsInPlace(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
if (WrapBorderBackground()) {
|
|
|
|
// Our border-backgrounds are in-flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.BorderBackground(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// Our block border-backgrounds are in-flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.BlockBorderBackgrounds(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The floats are not in flow
|
|
|
|
rv = WrapEachDisplayItem(aBuilder, aLists.Floats(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Our child content is in flow
|
|
|
|
rv = WrapDisplayList(aBuilder, aFrame, aLists.Content(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The positioned descendants may not be in-flow
|
|
|
|
rv = WrapEachDisplayItem(aBuilder, aLists.PositionedDescendants(), this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// The outlines may not be in-flow
|
|
|
|
return WrapEachDisplayItem(aBuilder, aLists.Outlines(), this);
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayOpacity::nsDisplayOpacity(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOpacity::~nsDisplayOpacity() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOpacity);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
2006-01-29 21:48:58 +03:00
|
|
|
#endif
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplayOpacity::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap) {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2006-01-26 05:29:17 +03:00
|
|
|
// We are never opaque, if our opacity was < 1 then we wouldn't have
|
|
|
|
// been created.
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsRegion();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:19 +03:00
|
|
|
// nsDisplayOpacity uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayOpacity::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (mFrame->StyleDisplay()->mOpacity == 0 && mFrame->GetContent() &&
|
2013-09-04 15:30:57 +04:00
|
|
|
!nsLayoutUtils::HasAnimations(mFrame->GetContent(), eCSSProperty_opacity)) {
|
2012-11-15 02:43:29 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<Layer> container = aManager->GetLayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 18:20:58 +04:00
|
|
|
aContainerParameters, nullptr);
|
2012-07-31 21:28:21 +04:00
|
|
|
if (!container)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
container->SetOpacity(mFrame->StyleDisplay()->mOpacity);
|
2012-08-07 00:33:23 +04:00
|
|
|
AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, eCSSProperty_opacity);
|
2012-07-31 21:28:21 +04:00
|
|
|
return container.forget();
|
2010-03-01 10:56:19 +03:00
|
|
|
}
|
2006-02-16 02:21:12 +03:00
|
|
|
|
2011-10-27 00:10:48 +04: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(
|
2013-04-19 16:02:13 +04:00
|
|
|
aItem->Frame()->PresContext()->AppUnitsPerDevPixel());
|
2011-10-27 00:10:48 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:32:09 +04:00
|
|
|
bool
|
|
|
|
nsDisplayOpacity::NeedsActiveLayer()
|
|
|
|
{
|
2013-09-04 15:30:57 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(mFrame, eCSSProperty_opacity) &&
|
2011-10-27 00:10:48 +04:00
|
|
|
!IsItemTooSmallForActiveLayer(this))
|
2013-11-18 13:32:09 +04:00
|
|
|
return true;
|
2012-07-31 21:28:21 +04:00
|
|
|
if (mFrame->GetContent()) {
|
2012-07-31 21:28:22 +04:00
|
|
|
if (nsLayoutUtils::HasAnimationsForCompositor(mFrame->GetContent(),
|
|
|
|
eCSSProperty_opacity)) {
|
2013-11-18 13:32:09 +04:00
|
|
|
return true;
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
}
|
2013-11-18 13:32:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (NeedsActiveLayer())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsDisplayItem* child = mList.GetBottom();
|
|
|
|
// Only try folding our opacity down if we have a single
|
|
|
|
// child. We could potentially do this also if we had multiple
|
|
|
|
// children as long as they don't overlap.
|
|
|
|
if (!child || child->GetAbove()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return child->ApplyOpacity(mFrame->StyleDisplay()->mOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters) {
|
|
|
|
if (NeedsActiveLayer())
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
|
2013-09-26 01:07:26 +04:00
|
|
|
return RequiredLayerStateForChildren(aBuilder, aManager, aParameters, mList, mFrame);
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-13 20:40:46 +04:00
|
|
|
nsDisplayOpacity::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2006-01-26 05:29:17 +03:00
|
|
|
// Our children are translucent so we should not allow them to subtract
|
|
|
|
// area from aVisibleRegion. We do need to find out what is visible under
|
|
|
|
// our children in the temporary compositing buffer, because if our children
|
|
|
|
// paint our entire bounds opaquely then we don't need an alpha channel in
|
|
|
|
// the temporary compositing buffer.
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRect bounds = GetClippedBounds(aBuilder);
|
2010-03-01 10:56:19 +03:00
|
|
|
nsRegion visibleUnderChildren;
|
|
|
|
visibleUnderChildren.And(*aVisibleRegion, bounds);
|
2012-05-09 23:53:15 +04:00
|
|
|
nsRect allowExpansion = bounds.Intersect(aAllowVisibleRegionExpansion);
|
2010-03-01 10:56:19 +03:00
|
|
|
return
|
2011-01-28 01:58:50 +03:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren,
|
2011-05-13 20:40:46 +04:00
|
|
|
allowExpansion);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayOpacity::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
2006-01-26 05:29:17 +03:00
|
|
|
if (aItem->GetType() != TYPE_OPACITY)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-01-26 05:29:17 +03:00
|
|
|
// items for the same content element should be merged into a single
|
|
|
|
// compositing group
|
|
|
|
// aItem->GetUnderlyingFrame() returns non-null because it's nsDisplayOpacity
|
2013-04-19 16:02:13 +04:00
|
|
|
if (aItem->Frame()->GetContent() != mFrame->GetContent())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2013-03-04 13:56:02 +04:00
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
2012-04-17 09:44:32 +04:00
|
|
|
MergeFromTrackingMergedFrames(static_cast<nsDisplayOpacity*>(aItem));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-27 02:07:08 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
|
|
|
nsDisplayOpacity::WriteDebugInfo(nsACString& aTo)
|
|
|
|
{
|
|
|
|
aTo += nsPrintfCString("(opacity %f)", mFrame->StyleDisplay()->mOpacity);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
nsDisplayMixBlendMode::nsDisplayMixBlendMode(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayMixBlendMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayMixBlendMode::~nsDisplayMixBlendMode() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMixBlendMode);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRegion nsDisplayMixBlendMode::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) {
|
|
|
|
*aSnap = false;
|
|
|
|
// We are never considered opaque
|
|
|
|
return nsRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsDisplayMixBlendMode uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayMixBlendMode::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
|
|
|
ContainerLayerParameters newContainerParameters = aContainerParameters;
|
2013-09-16 03:48:14 +04:00
|
|
|
newContainerParameters.mDisableSubpixelAntialiasingInDescendants = true;
|
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
nsRefPtr<Layer> container = aManager->GetLayerBuilder()->
|
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2013-09-16 03:48:14 +04:00
|
|
|
newContainerParameters, nullptr);
|
2013-09-15 07:40:11 +04:00
|
|
|
if (!container) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-16 03:48:14 +04:00
|
|
|
|
2013-11-15 06:43:56 +04:00
|
|
|
container->SetMixBlendMode(nsCSSRendering::GetGFXBlendMode(mFrame->StyleDisplay()->mMixBlendMode));
|
2013-09-16 03:48:14 +04:00
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsDisplayMixBlendMode::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
|
|
|
// Our children are need their backdrop 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.
|
|
|
|
nsRect bounds = GetClippedBounds(aBuilder);
|
|
|
|
nsRegion visibleUnderChildren;
|
|
|
|
visibleUnderChildren.And(*aVisibleRegion, bounds);
|
|
|
|
nsRect allowExpansion = bounds.Intersect(aAllowVisibleRegionExpansion);
|
|
|
|
return
|
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren,
|
|
|
|
allowExpansion);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsDisplayMixBlendMode::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_MIX_BLEND_MODE)
|
|
|
|
return false;
|
|
|
|
// items for the same content element should be merged into a single
|
|
|
|
// compositing group
|
|
|
|
// aItem->GetUnderlyingFrame() returns non-null because it's nsDisplayOpacity
|
|
|
|
if (aItem->Frame()->GetContent() != mFrame->GetContent())
|
|
|
|
return false;
|
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
|
|
|
MergeFromTrackingMergedFrames(static_cast<nsDisplayMixBlendMode*>(aItem));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-15 07:30:00 +04:00
|
|
|
nsDisplayBlendContainer::nsDisplayBlendContainer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayBlendContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayBlendContainer::~nsDisplayBlendContainer() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayBlendContainer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsDisplayBlendContainer uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayBlendContainer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2013-10-22 16:31:00 +04:00
|
|
|
// turn off anti-aliasing in the parent stacking context because it changes
|
|
|
|
// how the group is initialized.
|
2013-09-27 10:01:16 +04:00
|
|
|
ContainerLayerParameters newContainerParameters = aContainerParameters;
|
2013-10-22 16:31:00 +04:00
|
|
|
newContainerParameters.mDisableSubpixelAntialiasingInDescendants = true;
|
|
|
|
|
2013-09-15 07:30:00 +04:00
|
|
|
nsRefPtr<Layer> container = aManager->GetLayerBuilder()->
|
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2013-10-22 16:31:00 +04:00
|
|
|
newContainerParameters, nullptr);
|
2013-09-15 07:30:00 +04:00
|
|
|
if (!container) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
container->SetForceIsolatedGroup(true);
|
|
|
|
return container.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsDisplayBlendContainer::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_BLEND_CONTAINER)
|
|
|
|
return false;
|
|
|
|
// items for the same content element should be merged into a single
|
|
|
|
// compositing group
|
|
|
|
// aItem->GetUnderlyingFrame() returns non-null because it's nsDisplayOpacity
|
|
|
|
if (aItem->Frame()->GetContent() != mFrame->GetContent())
|
|
|
|
return false;
|
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
|
|
|
MergeFromTrackingMergedFrames(static_cast<nsDisplayBlendContainer*>(aItem));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayOwnLayer::nsDisplayOwnLayer(nsDisplayListBuilder* aBuilder,
|
2012-08-29 09:47:18 +04:00
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
2013-12-10 07:14:53 +04:00
|
|
|
uint32_t aFlags, ViewID aScrollTarget)
|
2012-08-29 09:47:18 +04:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
2013-12-10 07:14:53 +04:00
|
|
|
, mFlags(aFlags)
|
|
|
|
, mScrollTarget(aScrollTarget) {
|
2010-07-16 01:08:03 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayOwnLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayOwnLayer::~nsDisplayOwnLayer() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayOwnLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsDisplayOpacity uses layers for rendering
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayOwnLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2013-08-14 15:33:03 +04:00
|
|
|
nsRefPtr<ContainerLayer> layer = aManager->GetLayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 18:20:58 +04:00
|
|
|
aContainerParameters, nullptr);
|
2013-12-10 07:14:53 +04:00
|
|
|
if (mFlags & VERTICAL_SCROLLBAR) {
|
|
|
|
layer->SetScrollbarData(mScrollTarget, Layer::ScrollDirection::VERTICAL);
|
|
|
|
}
|
|
|
|
if (mFlags & HORIZONTAL_SCROLLBAR) {
|
|
|
|
layer->SetScrollbarData(mScrollTarget, Layer::ScrollDirection::HORIZONTAL);
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
if (mFlags & GENERATE_SUBDOC_INVALIDATIONS) {
|
2013-08-14 15:33:03 +04:00
|
|
|
mFrame->PresContext()->SetNotifySubDocInvalidationData(layer);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
2010-07-16 01:08:03 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2013-10-29 17:27:15 +04:00
|
|
|
nsDisplayResolution::nsDisplayResolution(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList, aFlags) {
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayResolution);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayResolution::~nsDisplayResolution() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayResolution);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayResolution::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2013-10-29 17:27:15 +04:00
|
|
|
nsIPresShell* presShell = mFrame->PresContext()->PresShell();
|
2013-09-27 10:01:16 +04:00
|
|
|
ContainerLayerParameters containerParameters(
|
2013-10-29 17:27:15 +04:00
|
|
|
presShell->GetXResolution(), presShell->GetYResolution(), nsIntPoint(),
|
|
|
|
aContainerParameters);
|
|
|
|
|
|
|
|
nsRefPtr<Layer> layer = nsDisplayOwnLayer::BuildLayer(
|
|
|
|
aBuilder, aManager, containerParameters);
|
|
|
|
layer->SetPostScale(1.0f / presShell->GetXResolution(),
|
|
|
|
1.0f / presShell->GetYResolution());
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-13 05:56:57 +04:00
|
|
|
nsDisplayStickyPosition::nsDisplayStickyPosition(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsIFrame* aStickyPosFrame,
|
|
|
|
nsDisplayList* aList)
|
2013-09-27 10:02:03 +04:00
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList)
|
|
|
|
, mStickyPosFrame(aStickyPosFrame) {
|
2013-09-13 05:56:57 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayStickyPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayStickyPosition::~nsDisplayStickyPosition() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayStickyPosition);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayStickyPosition::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2013-09-13 05:56:57 +04:00
|
|
|
nsRefPtr<Layer> layer =
|
|
|
|
nsDisplayOwnLayer::BuildLayer(aBuilder, aManager, aContainerParameters);
|
|
|
|
|
|
|
|
StickyScrollContainer* stickyScrollContainer = StickyScrollContainer::
|
|
|
|
GetStickyScrollContainerForFrame(mFrame);
|
|
|
|
if (!stickyScrollContainer) {
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(stickyScrollContainer->ScrollFrame());
|
|
|
|
nsPresContext* presContext = scrollFrame->PresContext();
|
|
|
|
|
|
|
|
// Sticky position frames whose scroll frame is the root scroll frame are
|
|
|
|
// reflowed into the scroll-port size if one has been set.
|
|
|
|
nsSize scrollFrameSize = scrollFrame->GetSize();
|
|
|
|
if (scrollFrame == presContext->PresShell()->GetRootScrollFrame() &&
|
|
|
|
presContext->PresShell()->IsScrollPositionClampingScrollPortSizeSet()) {
|
|
|
|
scrollFrameSize = presContext->PresShell()->
|
|
|
|
GetScrollPositionClampingScrollPortSize();
|
|
|
|
}
|
|
|
|
|
2013-09-27 10:02:03 +04:00
|
|
|
nsLayoutUtils::SetFixedPositionLayerData(layer, scrollFrame, scrollFrameSize,
|
2013-12-12 16:33:02 +04:00
|
|
|
mStickyPosFrame,
|
|
|
|
presContext, aContainerParameters);
|
2013-09-13 05:56:57 +04:00
|
|
|
|
|
|
|
ViewID scrollId = nsLayoutUtils::FindOrCreateIDFor(
|
|
|
|
stickyScrollContainer->ScrollFrame()->GetScrolledFrame()->GetContent());
|
|
|
|
|
|
|
|
float factor = presContext->AppUnitsPerDevPixel();
|
|
|
|
nsRect outer;
|
|
|
|
nsRect inner;
|
|
|
|
stickyScrollContainer->GetScrollRanges(mFrame, &outer, &inner);
|
|
|
|
LayerRect stickyOuter(NSAppUnitsToFloatPixels(outer.x, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(outer.y, factor) *
|
|
|
|
aContainerParameters.mYScale,
|
|
|
|
NSAppUnitsToFloatPixels(outer.width, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(outer.height, factor) *
|
|
|
|
aContainerParameters.mYScale);
|
|
|
|
LayerRect stickyInner(NSAppUnitsToFloatPixels(inner.x, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(inner.y, factor) *
|
|
|
|
aContainerParameters.mYScale,
|
|
|
|
NSAppUnitsToFloatPixels(inner.width, factor) *
|
|
|
|
aContainerParameters.mXScale,
|
|
|
|
NSAppUnitsToFloatPixels(inner.height, factor) *
|
|
|
|
aContainerParameters.mYScale);
|
|
|
|
layer->SetStickyPositionData(scrollId, stickyOuter, stickyInner);
|
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-27 10:02:03 +04:00
|
|
|
bool nsDisplayStickyPosition::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem) {
|
|
|
|
if (aItem->GetType() != TYPE_STICKY_POSITION)
|
|
|
|
return false;
|
|
|
|
// Items with the same fixed position frame can be merged.
|
|
|
|
nsDisplayStickyPosition* other = static_cast<nsDisplayStickyPosition*>(aItem);
|
|
|
|
if (other->mStickyPosFrame != mStickyPosFrame)
|
|
|
|
return false;
|
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
|
|
|
MergeFromTrackingMergedFrames(other);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayList* aList,
|
|
|
|
nsIFrame* aForFrame,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame, aList)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame, aItem)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollLayer::nsDisplayScrollLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aForFrame,
|
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
|
|
|
: nsDisplayWrapList(aBuilder, aForFrame)
|
|
|
|
, mScrollFrame(aScrollFrame)
|
|
|
|
, mScrolledFrame(aScrolledFrame)
|
2011-01-13 20:45:14 +03:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2011-01-14 01:17:40 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollLayer);
|
2011-01-13 20:45:14 +03:00
|
|
|
#endif
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
NS_ASSERTION(mScrolledFrame && mScrolledFrame->GetContent(),
|
2011-01-13 20:45:14 +03:00
|
|
|
"Need a child frame with content");
|
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayScrollLayer::~nsDisplayScrollLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollLayer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-18 09:02:56 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayScrollLayer::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(mScrollFrame);
|
|
|
|
if (sf) {
|
|
|
|
*aSnap = false;
|
|
|
|
return sf->GetScrollPortRect() + aBuilder->ToReferenceFrame(mScrollFrame);
|
|
|
|
}
|
|
|
|
return nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
|
|
|
}
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayScrollLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<ContainerLayer> layer = aManager->GetLayerBuilder()->
|
2011-06-22 16:11:27 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2012-07-30 18:20:58 +04:00
|
|
|
aContainerParameters, nullptr);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
// Get the already set unique ID for scrolling this content remotely.
|
|
|
|
// Or, if not set, generate a new ID.
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIContent* content = mScrolledFrame->GetContent();
|
2013-08-08 23:56:08 +04:00
|
|
|
ViewID scrollId = nsLayoutUtils::FindOrCreateIDFor(content);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2012-06-16 01:49:46 +04:00
|
|
|
nsRect viewport = mScrollFrame->GetRect() -
|
|
|
|
mScrollFrame->GetPosition() +
|
2012-09-16 14:32:59 +04:00
|
|
|
mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2011-03-10 00:35:27 +03:00
|
|
|
bool usingDisplayport = false;
|
2012-11-22 02:34:18 +04:00
|
|
|
bool usingCriticalDisplayport = false;
|
|
|
|
nsRect displayport, criticalDisplayport;
|
2012-06-16 01:49:46 +04:00
|
|
|
if (content) {
|
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, &displayport);
|
2012-11-22 02:34:18 +04:00
|
|
|
usingCriticalDisplayport =
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(content, &criticalDisplayport);
|
2012-06-16 01:49:46 +04:00
|
|
|
}
|
2013-09-06 02:36:07 +04:00
|
|
|
RecordFrameMetrics(mScrolledFrame, mScrollFrame, ReferenceFrame(), layer,
|
2013-12-18 09:02:56 +04:00
|
|
|
mList.GetVisibleRect(), viewport,
|
2012-11-22 02:34:18 +04:00
|
|
|
(usingDisplayport ? &displayport : nullptr),
|
|
|
|
(usingCriticalDisplayport ? &criticalDisplayport : nullptr),
|
2013-11-09 04:07:00 +04:00
|
|
|
scrollId, false, aContainerParameters);
|
2011-01-13 20:45:14 +03:00
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2013-12-13 23:37:34 +04:00
|
|
|
bool
|
|
|
|
nsDisplayScrollLayer::ShouldBuildLayerEvenIfInvisible(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
if (nsLayoutUtils::GetDisplayPort(mScrolledFrame->GetContent(), nullptr)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDisplayWrapList::ShouldBuildLayerEvenIfInvisible(aBuilder);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-01-13 20:45:14 +03:00
|
|
|
nsDisplayScrollLayer::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2011-01-13 20:45:14 +03:00
|
|
|
{
|
2011-03-10 00:35:27 +03:00
|
|
|
nsRect displayport;
|
2013-12-18 09:02:56 +04:00
|
|
|
bool usingDisplayPort =
|
|
|
|
nsLayoutUtils::GetDisplayPort(mScrolledFrame->GetContent(), &displayport);
|
|
|
|
nsRegion childVisibleRegion;
|
|
|
|
if (usingDisplayPort) {
|
2011-01-13 20:45:14 +03:00
|
|
|
// The visible region for the children may be much bigger than the hole we
|
|
|
|
// are viewing the children from, so that the compositor process has enough
|
|
|
|
// content to asynchronously pan while content is being refreshed.
|
2013-12-18 09:02:56 +04:00
|
|
|
childVisibleRegion = displayport + mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
2011-01-13 20:45:14 +03:00
|
|
|
} else {
|
2013-12-18 09:02:56 +04:00
|
|
|
bool snap;
|
|
|
|
childVisibleRegion = GetBounds(aBuilder, &snap);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
2013-12-18 09:02:56 +04:00
|
|
|
|
|
|
|
nsRect boundedRect =
|
|
|
|
childVisibleRegion.GetBounds().Intersect(mList.GetBounds(aBuilder));
|
|
|
|
nsRect allowExpansion = boundedRect.Intersect(aAllowVisibleRegionExpansion);
|
|
|
|
bool visible = mList.ComputeVisibilityForSublist(
|
|
|
|
aBuilder, &childVisibleRegion, boundedRect, allowExpansion);
|
|
|
|
// We don't allow this computation to influence aVisibleRegion, on the
|
|
|
|
// assumption that the layer can be asynchronously scrolled so we'll
|
|
|
|
// definitely need all the content under it.
|
|
|
|
|
|
|
|
return visible;
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2011-04-29 21:15:44 +04:00
|
|
|
{
|
2011-05-02 05:53:01 +04:00
|
|
|
// Force this as a layer so we can scroll asynchronously.
|
|
|
|
// This causes incorrect rendering for rounded clips!
|
|
|
|
return LAYER_ACTIVE_FORCE;
|
2011-04-29 21:15:44 +04:00
|
|
|
}
|
2011-05-02 05:53:01 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayScrollLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SCROLL_LAYER) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
nsDisplayScrollLayer* other = static_cast<nsDisplayScrollLayer*>(aItem);
|
|
|
|
if (other->mScrolledFrame != this->mScrolledFrame) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
2013-03-04 13:56:02 +04:00
|
|
|
if (aItem->GetClip() != GetClip()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-02 05:53:01 +04:00
|
|
|
|
2012-10-25 03:04:41 +04:00
|
|
|
NS_ASSERTION(other->mReferenceFrame == mReferenceFrame,
|
|
|
|
"Must have the same reference frame!");
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Set(nsIFrame::ScrollLayerCount(),
|
|
|
|
reinterpret_cast<void*>(GetScrollLayerCount() - 1));
|
|
|
|
|
2012-10-05 13:56:49 +04: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-17 09:44:32 +04:00
|
|
|
MergeFromTrackingMergedFrames(other);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2013-12-10 22:05:18 +04:00
|
|
|
void
|
|
|
|
PropagateClip(nsDisplayListBuilder* aBuilder, const DisplayItemClip& aClip,
|
|
|
|
nsDisplayList* aList)
|
|
|
|
{
|
|
|
|
for (nsDisplayItem* i = aList->GetBottom(); i != nullptr; i = i->GetAbove()) {
|
|
|
|
DisplayItemClip clip(i->GetClip());
|
|
|
|
clip.IntersectWith(aClip);
|
|
|
|
i->SetClip(aBuilder, clip);
|
|
|
|
nsDisplayList* list = i->GetSameCoordinateSystemChildren();
|
|
|
|
if (list) {
|
|
|
|
PropagateClip(aBuilder, aClip, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayScrollLayer::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2013-12-10 22:05:18 +04:00
|
|
|
if (GetScrollLayerCount() > 1) {
|
|
|
|
// Propagate our clip to our children. The clip for the scroll frame is
|
|
|
|
// on this item, but not our child items so that they can draw non-visible
|
|
|
|
// parts of the display port. But if we are flattening we failed and can't
|
|
|
|
// draw the extra content, so it needs to be clipped.
|
|
|
|
PropagateClip(aBuilder, GetClip(), &mList);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2012-04-12 04:17:44 +04:00
|
|
|
intptr_t
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayScrollLayer::GetScrollLayerCount()
|
|
|
|
{
|
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
#ifdef DEBUG
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasCount = false;
|
2012-04-12 04:17:44 +04:00
|
|
|
intptr_t result = reinterpret_cast<intptr_t>(
|
2011-05-02 05:53:01 +04: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-12 04:17:44 +04:00
|
|
|
return reinterpret_cast<intptr_t>(props.Get(nsIFrame::ScrollLayerCount()));
|
2011-01-13 20:45:14 +03:00
|
|
|
#endif
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 00:53:01 +04:00
|
|
|
nsDisplayScrollInfoLayer::nsDisplayScrollInfoLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
2011-05-02 05:53:01 +04:00
|
|
|
nsIFrame* aScrolledFrame,
|
|
|
|
nsIFrame* aScrollFrame)
|
2013-07-02 19:16:05 +04:00
|
|
|
: nsDisplayScrollLayer(aBuilder, aScrollFrame, aScrolledFrame, aScrollFrame)
|
2011-04-12 00:53:01 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollInfoLayer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollInfoLayer::~nsDisplayScrollInfoLayer()
|
|
|
|
{
|
2013-10-22 02:47:26 +04:00
|
|
|
FrameProperties props = mScrolledFrame->Properties();
|
|
|
|
props.Remove(nsIFrame::ScrollLayerCount());
|
2011-04-12 00:53:01 +04:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollInfoLayer);
|
|
|
|
}
|
|
|
|
|
2013-12-18 09:02:56 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayScrollInfoLayer::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
|
|
|
return nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
|
|
|
}
|
|
|
|
|
2011-05-02 05:53:01 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayScrollInfoLayer::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2011-05-02 05:53:01 +04:00
|
|
|
{
|
|
|
|
return LAYER_ACTIVE_EMPTY;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-02 05:53:01 +04:00
|
|
|
nsDisplayScrollInfoLayer::TryMerge(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-02 05:53:01 +04: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 21:28:21 +04:00
|
|
|
// visibility computation.
|
2013-10-22 02:47:26 +04:00
|
|
|
return GetScrollLayerCount() == 1;
|
2011-05-02 05:53:01 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayZoom::nsDisplayZoom(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
2012-08-29 09:47:18 +04:00
|
|
|
int32_t aAPD, int32_t aParentAPD,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList, aFlags)
|
|
|
|
, mAPD(aAPD), mParentAPD(aParentAPD) {
|
2010-07-19 06:23:48 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayZoom::~nsDisplayZoom() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayZoom);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-10 15:24:18 +04:00
|
|
|
nsRect nsDisplayZoom::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2010-07-19 06:23:48 +04:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
nsRect bounds = nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
|
|
|
*aSnap = false;
|
2010-07-19 06:23:48 +04: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-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2010-07-19 06:23:48 +04:00
|
|
|
{
|
|
|
|
mList.PaintForFrame(aBuilder, aCtx, mFrame, nsDisplayList::PAINT_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayZoom::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2012-04-10 15:24:18 +04:00
|
|
|
nsRegion *aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-19 06:23:48 +04:00
|
|
|
{
|
|
|
|
// Convert the passed in visible region to our appunits.
|
2013-03-04 13:56:02 +04:00
|
|
|
nsRegion visibleRegion;
|
|
|
|
// mVisibleRect has been clipped to GetClippedBounds
|
|
|
|
visibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
visibleRegion = visibleRegion.ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
nsRegion originalVisibleRegion = visibleRegion;
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
nsRect transformedVisibleRect =
|
|
|
|
mVisibleRect.ConvertAppUnitsRoundOut(mParentAPD, mAPD);
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect allowExpansion =
|
|
|
|
aAllowVisibleRegionExpansion.ConvertAppUnitsRoundIn(mParentAPD, mAPD);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool retval =
|
2013-03-04 13:56:02 +04:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &visibleRegion,
|
2011-01-28 01:58:50 +03:00
|
|
|
transformedVisibleRect,
|
2011-05-13 20:40:46 +04:00
|
|
|
allowExpansion);
|
2010-07-19 06:23:48 +04:00
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
// removed = originalVisibleRegion - visibleRegion
|
|
|
|
removed.Sub(originalVisibleRegion, visibleRegion);
|
|
|
|
// Convert removed region to parent appunits.
|
|
|
|
removed = removed.ConvertAppUnitsRoundIn(mAPD, mParentAPD);
|
|
|
|
// aVisibleRegion = aVisibleRegion - removed (modulo any simplifications
|
|
|
|
// SubtractFromVisibleRegion does)
|
2011-05-13 20:40:46 +04:00
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
2010-07-19 06:23:48 +04:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// nsDisplayTransform Implementation
|
|
|
|
//
|
|
|
|
|
|
|
|
// Write #define UNIFIED_CONTINUATIONS here to have the transform property try
|
|
|
|
// to transform content with continuations as one unified block instead of
|
|
|
|
// several smaller ones. This is currently disabled because it doesn't work
|
2009-07-27 12:47:02 +04:00
|
|
|
// correctly, since when the frames are initially being reflowed, their
|
2008-09-13 13:42:11 +04:00
|
|
|
// continuations all compute their bounding rects independently of each other
|
|
|
|
// and consequently get the wrong value. Write #define DEBUG_HIT here to have
|
|
|
|
// the nsDisplayTransform class dump out a bunch of information about hit
|
|
|
|
// detection.
|
|
|
|
#undef UNIFIED_CONTINUATIONS
|
|
|
|
#undef DEBUG_HIT
|
|
|
|
|
|
|
|
/* Returns the bounds of a frame as defined for transforms. If
|
|
|
|
* UNIFIED_CONTINUATIONS is not defined, this is simply the frame's bounding
|
|
|
|
* rectangle, translated to the origin. Otherwise, returns the smallest
|
|
|
|
* rectangle containing a frame and all of its continuations. For example, if
|
|
|
|
* there is a <span> element with several continuations split over several
|
|
|
|
* lines, this function will return the rectangle containing all of those
|
|
|
|
* continuations. This rectangle is relative to the origin of the frame's local
|
|
|
|
* coordinate space.
|
|
|
|
*/
|
|
|
|
#ifndef UNIFIED_CONTINUATIONS
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get the bounds of a nonexistent frame!");
|
2012-05-17 08:05:09 +04:00
|
|
|
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
2013-11-11 06:23:56 +04:00
|
|
|
// TODO: SVG needs to define what percentage translations resolve against.
|
|
|
|
return nsRect();
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04: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 21:28:21 +04:00
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_SVG_LAYOUT) {
|
2013-11-11 06:23:56 +04:00
|
|
|
// TODO: SVG needs to define what percentage translations resolve against.
|
|
|
|
return result;
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Iterate through the continuation list, unioning together all the
|
|
|
|
* bounding rects.
|
|
|
|
*/
|
2013-09-25 15:42:34 +04:00
|
|
|
for (const nsIFrame *currFrame = aFrame->FirstContinuation();
|
2012-07-30 18:20:58 +04:00
|
|
|
currFrame != nullptr;
|
2008-09-13 13:42:11 +04: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-20 03:14:07 +04: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!");
|
2013-03-04 13:56:02 +04:00
|
|
|
mStoredList.SetClip(aBuilder, DisplayItemClip::NoClip());
|
2012-09-20 03:14:07 +04:00
|
|
|
}
|
|
|
|
|
2012-09-16 14:32:59 +04:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame,
|
|
|
|
nsDisplayList *aList, uint32_t aIndex)
|
2012-09-20 03:14:07 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aList)
|
|
|
|
, mTransformGetter(nullptr)
|
|
|
|
, mIndex(aIndex)
|
2012-09-16 14:32:59 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
|
|
|
NS_ABORT_IF_FALSE(aFrame, "Must have a frame!");
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(aFrame));
|
|
|
|
mToReferenceFrame = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
2013-03-04 13:56:02 +04:00
|
|
|
mStoredList.SetClip(aBuilder, DisplayItemClip::NoClip());
|
2012-09-16 14:32:59 +04:00
|
|
|
}
|
|
|
|
|
2010-06-06 00:29:49 +04:00
|
|
|
/* Returns the delta specified by the -moz-transform-origin property.
|
2008-09-13 13:42:11 +04:00
|
|
|
* This is a positive delta, meaning that it indicates the direction to move
|
2012-07-31 21:28:21 +04:00
|
|
|
* to get from (0, 0) of the frame to the transform origin. This function is
|
|
|
|
* called off the main thread.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2012-07-31 21:28:21 +04:00
|
|
|
/* static */ gfxPoint3D
|
2013-10-24 16:46:00 +04:00
|
|
|
nsDisplayTransform::GetDeltaToTransformOrigin(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get delta for a null frame!");
|
2012-05-17 08:05:09 +04:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed(),
|
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2008-09-13 13:42:11 +04: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!
|
|
|
|
*/
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* display = aFrame->StyleDisplay();
|
2013-11-11 06:23:56 +04:00
|
|
|
nsRect boundingRect = (aBoundsOverride ? *aBoundsOverride :
|
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(aFrame));
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Allows us to access named variables by index. */
|
2013-11-11 06:23:56 +04:00
|
|
|
float coords[3];
|
|
|
|
const nscoord* dimensions[2] =
|
|
|
|
{&boundingRect.width, &boundingRect.height};
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint8_t index = 0; index < 2; ++index) {
|
2008-09-13 13:42:11 +04:00
|
|
|
/* If the -moz-transform-origin specifies a percentage, take the percentage
|
|
|
|
* of the size of the box.
|
|
|
|
*/
|
2010-09-15 19:11:26 +04:00
|
|
|
const nsStyleCoord &coord = display->mTransformOrigin[index];
|
2013-11-11 06:23:56 +04:00
|
|
|
if (coord.GetUnit() == eStyleUnit_Calc) {
|
|
|
|
const nsStyleCoord::Calc *calc = coord.GetCalcValue();
|
|
|
|
coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
2012-07-31 21:28:21 +04:00
|
|
|
coords[index] =
|
2013-11-11 06:23:56 +04:00
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
|
|
|
coord.GetPercentValue();
|
2010-09-15 19:11:26 +04:00
|
|
|
} else {
|
2013-11-11 06:23:56 +04:00
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
|
|
|
coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(coord.GetCoordValue(), aAppUnitsPerPixel);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
coords[index] -= NSAppUnitsToFloatPixels(offset, aAppUnitsPerPixel);
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
2011-08-03 07:04:23 +04:00
|
|
|
|
2013-11-11 06:23:56 +04:00
|
|
|
coords[2] = NSAppUnitsToFloatPixels(display->mTransformOrigin[2].GetCoordValue(),
|
|
|
|
aAppUnitsPerPixel);
|
|
|
|
/* Adjust based on the origin of the rectangle. */
|
|
|
|
coords[0] += NSAppUnitsToFloatPixels(boundingRect.x, aAppUnitsPerPixel);
|
|
|
|
coords[1] += NSAppUnitsToFloatPixels(boundingRect.y, aAppUnitsPerPixel);
|
|
|
|
|
|
|
|
return gfxPoint3D(coords[0], coords[1], coords[2]);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-08-03 07:04:24 +04:00
|
|
|
/* Returns the delta specified by the -moz-perspective-origin property.
|
|
|
|
* This is a positive delta, meaning that it indicates the direction to move
|
2012-07-31 21:28:21 +04:00
|
|
|
* to get from (0, 0) of the frame to the perspective origin. This function is
|
|
|
|
* called off the main thread.
|
2011-08-03 07:04:24 +04:00
|
|
|
*/
|
2012-07-31 21:28:21 +04:00
|
|
|
/* static */ gfxPoint3D
|
2013-10-24 16:46:00 +04:00
|
|
|
nsDisplayTransform::GetDeltaToPerspectiveOrigin(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel)
|
2011-08-03 07:04:24 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't get delta for a null frame!");
|
2012-05-17 08:05:09 +04:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed(),
|
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2011-08-03 07:04:24 +04: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 13:28:22 +04:00
|
|
|
nsIFrame* parent = aFrame->GetParentStyleContextFrame();
|
2012-09-18 02:34:21 +04:00
|
|
|
if (!parent) {
|
|
|
|
return gfxPoint3D();
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleDisplay* display = parent->StyleDisplay();
|
2012-03-12 06:04:25 +04:00
|
|
|
nsRect boundingRect = nsDisplayTransform::GetFrameBoundsForTransform(parent);
|
2011-08-03 07:04:24 +04: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 19:56:38 +04:00
|
|
|
for (uint8_t index = 0; index < 2; ++index) {
|
2011-08-03 07:04:24 +04: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-17 10:08:33 +04:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
|
|
|
calc->mPercent +
|
|
|
|
NSAppUnitsToFloatPixels(calc->mLength, aAppUnitsPerPixel);
|
2011-08-03 07:04:24 +04:00
|
|
|
} else if (coord.GetUnit() == eStyleUnit_Percent) {
|
2012-02-17 10:08:33 +04:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(*dimensions[index], aAppUnitsPerPixel) *
|
2011-08-03 07:04:24 +04:00
|
|
|
coord.GetPercentValue();
|
|
|
|
} else {
|
|
|
|
NS_ABORT_IF_FALSE(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
2012-02-17 10:08:33 +04:00
|
|
|
*coords[index] =
|
|
|
|
NSAppUnitsToFloatPixels(coord.GetCoordValue(), aAppUnitsPerPixel);
|
2011-08-03 07:04:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-15 13:28:22 +04:00
|
|
|
nsPoint parentOffset = aFrame->GetOffsetTo(parent);
|
2012-02-17 10:08:33 +04:00
|
|
|
gfxPoint3D gfxOffset(
|
|
|
|
NSAppUnitsToFloatPixels(parentOffset.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(parentOffset.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
2012-02-15 13:28:22 +04:00
|
|
|
|
|
|
|
return result - gfxOffset;
|
2011-08-03 07:04:24 +04:00
|
|
|
}
|
|
|
|
|
2012-09-18 02:34:21 +04:00
|
|
|
nsDisplayTransform::FrameTransformProperties::FrameTransformProperties(const nsIFrame* aFrame,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
: mFrame(aFrame)
|
2013-02-17 01:51:02 +04:00
|
|
|
, mTransformList(aFrame->StyleDisplay()->mSpecifiedTransform)
|
2013-10-24 16:46:00 +04:00
|
|
|
, mToTransformOrigin(GetDeltaToTransformOrigin(aFrame, aAppUnitsPerPixel, aBoundsOverride))
|
2013-11-11 06:23:56 +04:00
|
|
|
, mToPerspectiveOrigin(GetDeltaToPerspectiveOrigin(aFrame, aAppUnitsPerPixel))
|
2012-09-18 02:34:21 +04:00
|
|
|
, mChildPerspective(0)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* parentDisp = nullptr;
|
2013-02-16 09:38:33 +04:00
|
|
|
nsStyleContext* parentStyleContext = aFrame->StyleContext()->GetParent();
|
2012-09-18 02:34:21 +04:00
|
|
|
if (parentStyleContext) {
|
2013-02-17 01:51:02 +04:00
|
|
|
parentDisp = parentStyleContext->StyleDisplay();
|
2012-09-18 02:34:21 +04:00
|
|
|
}
|
|
|
|
if (parentDisp && parentDisp->mChildPerspective.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
mChildPerspective = parentDisp->mChildPerspective.GetCoordValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Wraps up the -moz-transform matrix in a change-of-basis matrix pair that
|
|
|
|
* translates from local coordinate space to transform coordinate space, then
|
|
|
|
* hands it back.
|
|
|
|
*/
|
2012-09-18 02:34:21 +04: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-23 02:28:51 +04:00
|
|
|
gfx3DMatrix
|
2008-09-13 13:42:11 +04:00
|
|
|
nsDisplayTransform::GetResultingTransformMatrix(const nsIFrame* aFrame,
|
2012-07-31 21:28:21 +04:00
|
|
|
const nsPoint& aOrigin,
|
2012-02-17 10:08:33 +04:00
|
|
|
float aAppUnitsPerPixel,
|
2011-08-27 04:01:46 +04:00
|
|
|
const nsRect* aBoundsOverride,
|
|
|
|
nsIFrame** aOutAncestor)
|
2012-09-16 14:32:59 +04:00
|
|
|
{
|
2012-09-18 02:34:21 +04:00
|
|
|
FrameTransformProperties props(aFrame,
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride);
|
|
|
|
|
|
|
|
return GetResultingTransformMatrixInternal(props, aOrigin, aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride, aOutAncestor);
|
2012-09-16 14:32:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx3DMatrix
|
2012-09-18 02:34:21 +04:00
|
|
|
nsDisplayTransform::GetResultingTransformMatrixInternal(const FrameTransformProperties& aProperties,
|
2012-09-16 14:32:59 +04:00
|
|
|
const nsPoint& aOrigin,
|
|
|
|
float aAppUnitsPerPixel,
|
|
|
|
const nsRect* aBoundsOverride,
|
2012-09-26 02:47:41 +04:00
|
|
|
nsIFrame** aOutAncestor)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2012-09-18 02:34:21 +04:00
|
|
|
const nsIFrame *frame = aProperties.mFrame;
|
2011-08-27 04:01:46 +04:00
|
|
|
|
|
|
|
if (aOutAncestor) {
|
2012-09-18 02:34:21 +04:00
|
|
|
*aOutAncestor = nsLayoutUtils::GetCrossDocParentFrame(frame);
|
2011-08-27 04:01:46 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Account for the -moz-transform-origin property by translating the
|
|
|
|
* coordinate space to the new origin.
|
|
|
|
*/
|
2012-02-17 10:08:33 +04:00
|
|
|
gfxPoint3D newOrigin =
|
|
|
|
gfxPoint3D(NSAppUnitsToFloatPixels(aOrigin.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aOrigin.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Get the underlying transform matrix. This requires us to get the
|
|
|
|
* bounds of the frame.
|
|
|
|
*/
|
|
|
|
nsRect bounds = (aBoundsOverride ? *aBoundsOverride :
|
2012-09-18 02:34:21 +04:00
|
|
|
nsDisplayTransform::GetFrameBoundsForTransform(frame));
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Get the matrix, then change its basis to factor in the origin. */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2011-08-27 04:01:46 +04:00
|
|
|
gfx3DMatrix result;
|
2012-05-17 08:05:09 +04:00
|
|
|
// Call IsSVGTransformed() regardless of the value of
|
|
|
|
// disp->mSpecifiedTransform, since we still need any transformFromSVGParent.
|
2013-12-30 03:35:53 +04:00
|
|
|
mozilla::gfx::Matrix svgTransform, transformFromSVGParent;
|
2012-05-17 08:05:09 +04:00
|
|
|
bool hasSVGTransforms =
|
2012-09-18 02:34:21 +04:00
|
|
|
frame && frame->IsSVGTransformed(&svgTransform, &transformFromSVGParent);
|
2011-08-27 04:01:46 +04:00
|
|
|
/* Transformed frames always have a transform, or are preserving 3d (and might still have perspective!) */
|
2012-09-18 02:34:21 +04:00
|
|
|
if (aProperties.mTransformList) {
|
2013-12-12 06:09:44 +04:00
|
|
|
result = nsStyleTransformMatrix::ReadTransforms(aProperties.mTransformList->mHead,
|
2013-02-16 09:38:33 +04:00
|
|
|
frame ? frame->StyleContext() : nullptr,
|
2012-09-18 02:34:21 +04:00
|
|
|
frame ? frame->PresContext() : nullptr,
|
2012-02-17 10:08:33 +04:00
|
|
|
dummy, bounds, aAppUnitsPerPixel);
|
2012-05-17 08:05:09 +04:00
|
|
|
} else if (hasSVGTransforms) {
|
2012-07-18 17:15:13 +04:00
|
|
|
// Correct the translation components for zoom:
|
2012-09-18 02:34:21 +04:00
|
|
|
float pixelsPerCSSPx = frame->PresContext()->AppUnitsPerCSSPixel() /
|
2012-07-18 17:15:13 +04:00
|
|
|
aAppUnitsPerPixel;
|
2013-12-30 03:35:53 +04:00
|
|
|
svgTransform._31 *= pixelsPerCSSPx;
|
|
|
|
svgTransform._32 *= pixelsPerCSSPx;
|
|
|
|
result = gfx3DMatrix::From2D(ThebesMatrix(svgTransform));
|
2011-08-27 04:01:46 +04:00
|
|
|
}
|
2011-08-03 07:04:22 +04:00
|
|
|
|
2012-05-17 08:05:09 +04:00
|
|
|
if (hasSVGTransforms && !transformFromSVGParent.IsIdentity()) {
|
2012-07-18 17:15:13 +04:00
|
|
|
// Correct the translation components for zoom:
|
2012-09-18 02:34:21 +04:00
|
|
|
float pixelsPerCSSPx = frame->PresContext()->AppUnitsPerCSSPixel() /
|
2012-07-18 17:15:13 +04:00
|
|
|
aAppUnitsPerPixel;
|
2013-12-30 03:35:53 +04:00
|
|
|
transformFromSVGParent._31 *= pixelsPerCSSPx;
|
|
|
|
transformFromSVGParent._32 *= pixelsPerCSSPx;
|
|
|
|
result = result * gfx3DMatrix::From2D(ThebesMatrix(transformFromSVGParent));
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
2013-06-23 00:35:09 +04:00
|
|
|
if (aProperties.mChildPerspective > 0.0) {
|
2011-08-03 07:04:22 +04:00
|
|
|
gfx3DMatrix perspective;
|
|
|
|
perspective._34 =
|
2012-09-18 02:34:21 +04:00
|
|
|
-1.0 / NSAppUnitsToFloatPixels(aProperties.mChildPerspective, aAppUnitsPerPixel);
|
2011-10-31 04:38:46 +04: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.
|
|
|
|
*/
|
2013-11-11 06:23:56 +04:00
|
|
|
result = result * nsLayoutUtils::ChangeMatrixBasis(aProperties.mToPerspectiveOrigin - aProperties.mToTransformOrigin, perspective);
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2011-08-27 04:01:46 +04:00
|
|
|
|
2013-06-23 00:35:09 +04:00
|
|
|
gfxPoint3D rounded(hasSVGTransforms ? newOrigin.x : NS_round(newOrigin.x),
|
|
|
|
hasSVGTransforms ? newOrigin.y : NS_round(newOrigin.y),
|
2012-09-16 14:32:59 +04:00
|
|
|
0);
|
2013-06-23 00:35:09 +04:00
|
|
|
|
|
|
|
if (frame && frame->Preserves3D()) {
|
2011-08-27 04:01:46 +04:00
|
|
|
// Include the transform set on our parent
|
2012-09-18 02:34:21 +04:00
|
|
|
NS_ASSERTION(frame->GetParent() &&
|
|
|
|
frame->GetParent()->IsTransformed() &&
|
|
|
|
frame->GetParent()->Preserves3DChildren(),
|
2011-08-27 04:01:46 +04:00
|
|
|
"Preserve3D mismatch!");
|
2012-09-18 02:34:21 +04:00
|
|
|
FrameTransformProperties props(frame->GetParent(),
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
nullptr);
|
2012-07-31 21:28:21 +04:00
|
|
|
gfx3DMatrix parent =
|
2012-09-18 02:34:21 +04:00
|
|
|
GetResultingTransformMatrixInternal(props,
|
|
|
|
aOrigin - frame->GetPosition(),
|
|
|
|
aAppUnitsPerPixel, nullptr, aOutAncestor);
|
2013-10-24 16:46:00 +04:00
|
|
|
return nsLayoutUtils::ChangeMatrixBasis(rounded + aProperties.mToTransformOrigin, result) * parent;
|
2011-08-27 04:01:46 +04:00
|
|
|
}
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
return nsLayoutUtils::ChangeMatrixBasis
|
2013-10-24 16:46:00 +04:00
|
|
|
(rounded + aProperties.mToTransformOrigin, result);
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
|
|
|
|
2011-12-19 01:57:35 +04:00
|
|
|
bool
|
2012-08-26 05:27:28 +04:00
|
|
|
nsDisplayOpacity::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2013-09-04 15:30:57 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(mFrame, eCSSProperty_opacity)) {
|
2012-08-26 05:27:28 +04:00
|
|
|
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-26 08:14:31 +04:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
2013-04-19 16:02:13 +04:00
|
|
|
Frame()->GetContent());
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayTransform::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return ShouldPrerenderTransformedContent(aBuilder,
|
2013-04-19 16:02:13 +04:00
|
|
|
Frame(),
|
2012-08-26 05:27:28 +04:00
|
|
|
nsLayoutUtils::IsAnimationLoggingEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2011-12-19 01:57:35 +04:00
|
|
|
nsDisplayTransform::ShouldPrerenderTransformedContent(nsDisplayListBuilder* aBuilder,
|
2012-08-26 05:27:28 +04:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
bool aLogAnimations)
|
|
|
|
{
|
2013-03-19 17:08:29 +04:00
|
|
|
// Elements whose transform has been modified recently, or which
|
|
|
|
// have a compositor-animated transform, can be prerendered. An element
|
|
|
|
// might have only just had its transform animated in which case
|
|
|
|
// nsChangeHint_UpdateTransformLayer will not be present yet.
|
2013-09-04 15:30:57 +04:00
|
|
|
if (!ActiveLayerTracker::IsStyleAnimated(aFrame, eCSSProperty_transform) &&
|
2013-03-19 17:08:29 +04:00
|
|
|
(!aFrame->GetContent() ||
|
|
|
|
!nsLayoutUtils::HasAnimationsForCompositor(aFrame->GetContent(),
|
|
|
|
eCSSProperty_transform))) {
|
2012-08-26 05:27:28 +04:00
|
|
|
if (aLogAnimations) {
|
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation disabled because frame was not marked active for transform animation");
|
2012-08-26 08:14:31 +04:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
|
|
|
aFrame->GetContent());
|
2012-03-01 16:34:20 +04:00
|
|
|
}
|
2012-08-26 05:27:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-16 14:32:59 +04:00
|
|
|
nsSize refSize = aBuilder->RootReferenceFrame()->GetSize();
|
2012-08-26 05:27:28 +04: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-26 05:27:28 +04:00
|
|
|
CommonElementAnimationData::LogAsyncAnimationFailure(message,
|
|
|
|
aFrame->GetContent());
|
2012-02-05 20:34:10 +04:00
|
|
|
}
|
|
|
|
return false;
|
2011-12-19 01:57:35 +04:00
|
|
|
}
|
|
|
|
|
2011-10-12 07:16:06 +04:00
|
|
|
/* If the matrix is singular, or a hidden backface is shown, the frame won't be visible or hit. */
|
2012-07-31 21:28:21 +04:00
|
|
|
static bool IsFrameVisible(nsIFrame* aFrame, const gfx3DMatrix& aMatrix)
|
2011-10-12 07:16:06 +04:00
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
if (aFrame->StyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
2011-10-12 07:16:06 +04:00
|
|
|
aMatrix.IsBackfaceVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-03 07:04:22 +04:00
|
|
|
const gfx3DMatrix&
|
2014-01-20 10:56:55 +04:00
|
|
|
nsDisplayTransform::GetTransform()
|
2011-08-03 07:04:22 +04:00
|
|
|
{
|
2014-01-20 10:56:55 +04:00
|
|
|
if (mTransform.IsIdentity()) {
|
|
|
|
float scale = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2012-09-26 02:47:41 +04:00
|
|
|
gfxPoint3D newOrigin =
|
2014-01-20 10:56:55 +04:00
|
|
|
gfxPoint3D(NSAppUnitsToFloatPixels(mToReferenceFrame.x, scale),
|
|
|
|
NSAppUnitsToFloatPixels(mToReferenceFrame.y, scale),
|
2012-09-26 02:47:41 +04:00
|
|
|
0.0f);
|
2012-09-20 03:14:07 +04:00
|
|
|
if (mTransformGetter) {
|
2014-01-20 10:56:55 +04:00
|
|
|
mTransform = mTransformGetter(mFrame, scale);
|
2012-09-20 03:14:07 +04:00
|
|
|
mTransform = nsLayoutUtils::ChangeMatrixBasis(newOrigin, mTransform);
|
|
|
|
} else {
|
|
|
|
mTransform =
|
2014-01-20 10:56:55 +04:00
|
|
|
GetResultingTransformMatrix(mFrame, ToReferenceFrame(), scale);
|
2012-09-26 02:47:41 +04: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-20 03:14:07 +04:00
|
|
|
}
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2011-07-23 02:28:07 +04:00
|
|
|
return mTransform;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 17:08:29 +04:00
|
|
|
bool
|
|
|
|
nsDisplayTransform::ShouldBuildLayerEvenIfInvisible(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return ShouldPrerenderTransformedContent(aBuilder, mFrame, false);
|
|
|
|
}
|
|
|
|
|
2010-08-02 07:07:04 +04:00
|
|
|
already_AddRefed<Layer> nsDisplayTransform::BuildLayer(nsDisplayListBuilder *aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager *aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2014-01-20 10:56:55 +04:00
|
|
|
const gfx3DMatrix& newTransformMatrix = GetTransform();
|
2011-08-03 07:04:22 +04:00
|
|
|
|
2013-03-21 06:33:00 +04:00
|
|
|
if (mFrame->StyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
|
|
|
newTransformMatrix.IsBackfaceVisible()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2013-12-07 22:33:09 +04:00
|
|
|
uint32_t flags = ShouldPrerenderTransformedContent(aBuilder, mFrame, false) ?
|
|
|
|
FrameLayerBuilder::CONTAINER_NOT_CLIPPED_BY_ANCESTORS : 0;
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2012-11-02 16:59:03 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, *mStoredList.GetChildren(),
|
2013-12-07 22:33:09 +04:00
|
|
|
aContainerParameters, &newTransformMatrix, flags);
|
2011-10-07 01:23:18 +04:00
|
|
|
|
2013-03-21 07:27:02 +04:00
|
|
|
if (!container) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-10-07 01:23:18 +04:00
|
|
|
// Add the preserve-3d flag for this layer, BuildContainerLayerFor clears all flags,
|
|
|
|
// so we never need to explicitely unset this flag.
|
2011-11-17 07:45:44 +04:00
|
|
|
if (mFrame->Preserves3D() || mFrame->Preserves3DChildren()) {
|
2011-10-07 01:23:18 +04:00
|
|
|
container->SetContentFlags(container->GetContentFlags() | Layer::CONTENT_PRESERVE_3D);
|
2012-12-12 09:21:23 +04:00
|
|
|
} else {
|
|
|
|
container->SetContentFlags(container->GetContentFlags() & ~Layer::CONTENT_PRESERVE_3D);
|
2011-10-07 01:23:18 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2012-08-07 00:33:23 +04:00
|
|
|
AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, eCSSProperty_transform);
|
2012-10-03 09:55:52 +04:00
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame, false)) {
|
|
|
|
container->SetUserData(nsIFrame::LayerIsPrerenderedDataKey(),
|
|
|
|
/*the value is irrelevant*/nullptr);
|
2012-12-12 09:21:23 +04:00
|
|
|
container->SetContentFlags(container->GetContentFlags() | Layer::CONTENT_MAY_CHANGE_TRANSFORM);
|
2012-10-03 09:55:52 +04:00
|
|
|
} else {
|
|
|
|
container->RemoveUserData(nsIFrame::LayerIsPrerenderedDataKey());
|
2012-12-12 09:21:23 +04:00
|
|
|
container->SetContentFlags(container->GetContentFlags() & ~Layer::CONTENT_MAY_CHANGE_TRANSFORM);
|
2012-10-03 09:55:52 +04:00
|
|
|
}
|
2011-10-07 01:23:18 +04:00
|
|
|
return container.forget();
|
2010-08-02 07:07:04 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2010-08-02 07:07:04 +04:00
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayTransform::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters) {
|
2012-11-14 10:26:29 +04: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.
|
2014-01-20 10:56:55 +04:00
|
|
|
if (!GetTransform().Is2D() || mFrame->Preserves3D()) {
|
2012-11-14 10:26:29 +04:00
|
|
|
return LAYER_ACTIVE_FORCE;
|
|
|
|
}
|
2011-10-27 00:10:48 +04:00
|
|
|
// Here we check if the *post-transform* bounds of this item are big enough
|
|
|
|
// to justify an active layer.
|
2013-09-04 15:30:57 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(mFrame, eCSSProperty_transform) &&
|
2011-10-27 00:10:48 +04:00
|
|
|
!IsItemTooSmallForActiveLayer(this))
|
2010-08-02 07:07:04 +04:00
|
|
|
return LAYER_ACTIVE;
|
2012-07-31 21:28:21 +04:00
|
|
|
if (mFrame->GetContent()) {
|
2012-07-31 21:28:22 +04:00
|
|
|
if (nsLayoutUtils::HasAnimationsForCompositor(mFrame->GetContent(),
|
|
|
|
eCSSProperty_transform)) {
|
2012-07-31 21:28:21 +04:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
2012-11-14 10:26:29 +04:00
|
|
|
return mStoredList.RequiredLayerStateForChildren(aBuilder,
|
|
|
|
aManager,
|
|
|
|
aParameters,
|
|
|
|
*mStoredList.GetChildren(),
|
2013-09-26 01:07:26 +04:00
|
|
|
mFrame);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayTransform::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion *aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2009-09-07 04:35:14 +04:00
|
|
|
/* As we do this, we need to be sure to
|
|
|
|
* untransform the visible rect, since we want everything that's painting to
|
2011-07-23 02:28:51 +04:00
|
|
|
* think that it's painting in its original rectangular coordinate space.
|
|
|
|
* If we can't untransform, take the entire overflow rect */
|
|
|
|
nsRect untransformedVisibleRect;
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2011-12-19 01:57:35 +04:00
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame) ||
|
2012-02-14 13:12:49 +04:00
|
|
|
!UntransformRectMatrix(mVisibleRect,
|
2014-01-20 10:56:55 +04:00
|
|
|
GetTransform(),
|
2012-02-14 13:12:49 +04:00
|
|
|
factor,
|
2012-07-31 21:28:21 +04:00
|
|
|
&untransformedVisibleRect))
|
2011-07-23 02:28:51 +04:00
|
|
|
{
|
2012-09-16 14:32:59 +04:00
|
|
|
untransformedVisibleRect = mFrame->GetVisualOverflowRectRelativeToSelf();
|
2011-07-23 02:28:51 +04:00
|
|
|
}
|
|
|
|
nsRegion untransformedVisible = untransformedVisibleRect;
|
2011-09-07 04:20:35 +04:00
|
|
|
// Call RecomputeVisiblity instead of ComputeVisibility since
|
2010-08-28 03:15:08 +04:00
|
|
|
// nsDisplayItem::ComputeVisibility should only be called from
|
|
|
|
// nsDisplayList::ComputeVisibility (which sets mVisibleRect on the item)
|
|
|
|
mStoredList.RecomputeVisibility(aBuilder, &untransformedVisible);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* HitTest does some fun stuff with matrix transforms to obtain the answer. */
|
2010-04-08 04:31:26 +04:00
|
|
|
void nsDisplayTransform::HitTest(nsDisplayListBuilder *aBuilder,
|
|
|
|
const nsRect& aRect,
|
|
|
|
HitTestState *aState,
|
|
|
|
nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
/* Here's how this works:
|
|
|
|
* 1. Get the matrix. If it's singular, abort (clearly we didn't hit
|
|
|
|
* anything).
|
|
|
|
* 2. Invert the matrix.
|
2010-04-08 04:31:26 +04:00
|
|
|
* 3. Use it to transform the rect into the correct space.
|
|
|
|
* 4. Pass that rect down through to the list's version of HitTest.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-01-20 10:56:55 +04:00
|
|
|
gfx3DMatrix matrix = GetTransform();
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-10-12 07:16:06 +04:00
|
|
|
if (!IsFrameVisible(mFrame, matrix)) {
|
|
|
|
return;
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* We want to go from transformed-space to regular space.
|
|
|
|
* Thus we have to invert the matrix, which normally does
|
|
|
|
* the reverse operation (e.g. regular->transformed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Now, apply the transform and pass it down the channel. */
|
2010-04-08 04:31:26 +04:00
|
|
|
nsRect resultingRect;
|
|
|
|
if (aRect.width == 1 && aRect.height == 1) {
|
2011-09-08 15:15:00 +04:00
|
|
|
// Magic width/height indicating we're hit testing a point, not a rect
|
2011-08-03 07:04:21 +04:00
|
|
|
gfxPoint point = matrix.Inverse().ProjectPoint(
|
|
|
|
gfxPoint(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor)));
|
2010-04-08 04:31:26 +04:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(point.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(point.y), factor),
|
|
|
|
1, 1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
gfxRect originalRect(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, factor));
|
|
|
|
|
2011-08-03 07:04:21 +04:00
|
|
|
gfxRect rect = matrix.Inverse().ProjectRectBounds(originalRect);;
|
2010-04-08 04:31:26 +04:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(rect.X()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Y()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Width()), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(rect.Height()), factor));
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_HIT
|
|
|
|
printf("Frame: %p\n", dynamic_cast<void *>(mFrame));
|
2010-04-08 04:31:26 +04:00
|
|
|
printf(" Untransformed point: (%f, %f)\n", resultingRect.X(), resultingRect.Y());
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t originalFrameCount = aOutFrames.Length();
|
2008-09-13 13:42:11 +04:00
|
|
|
#endif
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
mStoredList.HitTest(aBuilder, resultingRect, aState, aOutFrames);
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
#ifdef DEBUG_HIT
|
2010-04-08 04:31:26 +04:00
|
|
|
if (originalFrameCount != aOutFrames.Length())
|
|
|
|
printf(" Hit! Time: %f, first frame: %p\n", static_cast<double>(clock()),
|
|
|
|
dynamic_cast<void *>(aOutFrames.ElementAt(0)));
|
2008-09-13 13:42:11 +04:00
|
|
|
printf("=== end of hit test ===\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-10-07 01:24:02 +04:00
|
|
|
float
|
|
|
|
nsDisplayTransform::GetHitDepthAtPoint(const nsPoint& aPoint)
|
|
|
|
{
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-01-20 10:56:55 +04:00
|
|
|
gfx3DMatrix matrix = GetTransform();
|
2011-10-07 01:24:02 +04:00
|
|
|
|
2011-10-12 07:16:06 +04:00
|
|
|
NS_ASSERTION(IsFrameVisible(mFrame, matrix), "We can't have hit a frame that isn't visible!");
|
2012-07-31 21:28:21 +04:00
|
|
|
|
|
|
|
gfxPoint point =
|
2011-10-07 01:24:02 +04: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 13:42:11 +04:00
|
|
|
/* The bounding rectangle for the object is the overflow rectangle translated
|
|
|
|
* by the reference point.
|
|
|
|
*/
|
2012-04-10 15:24:18 +04:00
|
|
|
nsRect nsDisplayTransform::GetBounds(nsDisplayListBuilder *aBuilder, bool* aSnap)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2012-02-09 13:39:30 +04:00
|
|
|
nsRect untransformedBounds =
|
|
|
|
ShouldPrerenderTransformedContent(aBuilder, mFrame) ?
|
2012-09-16 14:32:59 +04:00
|
|
|
mFrame->GetVisualOverflowRectRelativeToSelf() :
|
2012-04-10 15:24:18 +04:00
|
|
|
mStoredList.GetBounds(aBuilder, aSnap);
|
|
|
|
*aSnap = false;
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2012-02-09 13:39:30 +04:00
|
|
|
return nsLayoutUtils::MatrixTransformRect(untransformedBounds,
|
2014-01-20 10:56:55 +04:00
|
|
|
GetTransform(),
|
2012-02-09 13:39:30 +04:00
|
|
|
factor);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is opaque iff the transform consists solely of scales and
|
2010-11-27 02:31:08 +03:00
|
|
|
* translations and if the underlying content is opaque. Thus if the transform
|
2008-09-13 13:42:11 +04:00
|
|
|
* is of the form
|
|
|
|
*
|
|
|
|
* |a c e|
|
|
|
|
* |b d f|
|
|
|
|
* |0 0 1|
|
|
|
|
*
|
|
|
|
* We need b and c to be zero.
|
2010-11-27 02:31:08 +03:00
|
|
|
*
|
|
|
|
* We also need to check whether the underlying opaque content completely fills
|
|
|
|
* our visible rect. We use UntransformRect which expands to the axis-aligned
|
|
|
|
* bounding rect, but that's OK since if
|
|
|
|
* mStoredList.GetVisibleRect().Contains(untransformedVisible), then it
|
|
|
|
* certainly contains the actual (non-axis-aligned) untransformed rect.
|
2008-09-13 13:42:11 +04:00
|
|
|
*/
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplayTransform::GetOpaqueRegion(nsDisplayListBuilder *aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-07-23 02:28:51 +04:00
|
|
|
nsRect untransformedVisible;
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2012-10-03 09:55:50 +04: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) ||
|
2014-01-20 10:56:55 +04:00
|
|
|
!UntransformRectMatrix(mVisibleRect, GetTransform(), factor, &untransformedVisible)) {
|
2011-07-23 02:28:51 +04:00
|
|
|
return nsRegion();
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-01-20 10:56:55 +04:00
|
|
|
const gfx3DMatrix& matrix = GetTransform();
|
2012-04-10 15:24:18 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
2011-07-23 02:28:51 +04:00
|
|
|
gfxMatrix matrix2d;
|
2012-04-10 15:24:18 +04:00
|
|
|
bool tmpSnap;
|
2011-07-23 02:28:51 +04:00
|
|
|
if (matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2012-05-03 08:29:05 +04:00
|
|
|
mStoredList.GetOpaqueRegion(aBuilder, &tmpSnap).Contains(untransformedVisible)) {
|
2011-01-03 04:48:09 +03:00
|
|
|
result = mVisibleRect;
|
|
|
|
}
|
|
|
|
return result;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The transform is uniform if it fills the entire bounding rect and the
|
2011-01-03 04:48:09 +03:00
|
|
|
* wrapped list is uniform. See GetOpaqueRegion for discussion of why this
|
2008-09-13 13:42:11 +04:00
|
|
|
* works.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayTransform::IsUniform(nsDisplayListBuilder *aBuilder, nscolor* aColor)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2011-07-23 02:28:51 +04:00
|
|
|
nsRect untransformedVisible;
|
2014-01-20 10:56:55 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-01-20 10:56:55 +04:00
|
|
|
if (!UntransformRectMatrix(mVisibleRect, GetTransform(), factor, &untransformedVisible)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-07-23 02:28:51 +04:00
|
|
|
}
|
2014-01-20 10:56:55 +04:00
|
|
|
const gfx3DMatrix& matrix = GetTransform();
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2011-07-23 02:28:51 +04:00
|
|
|
gfxMatrix matrix2d;
|
|
|
|
return matrix.Is2D(&matrix2d) &&
|
|
|
|
matrix2d.PreservesAxisAlignedRectangles() &&
|
2011-07-23 02:28:07 +04:00
|
|
|
mStoredList.GetVisibleRect().Contains(untransformedVisible) &&
|
|
|
|
mStoredList.IsUniform(aBuilder, aColor);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If UNIFIED_CONTINUATIONS is defined, we can merge two display lists that
|
|
|
|
* share the same underlying content. Otherwise, doing so results in graphical
|
|
|
|
* glitches.
|
|
|
|
*/
|
|
|
|
#ifndef UNIFIED_CONTINUATIONS
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-13 13:42:11 +04:00
|
|
|
nsDisplayTransform::TryMerge(nsDisplayListBuilder *aBuilder,
|
|
|
|
nsDisplayItem *aItem)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-09-13 13:42:11 +04: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 18:59:28 +04:00
|
|
|
return false;
|
2008-09-13 13:42:11 +04:00
|
|
|
|
|
|
|
/* Check to see that both frames are part of the same content. */
|
2013-04-19 16:02:13 +04:00
|
|
|
if (aItem->Frame()->GetContent() != mFrame->GetContent())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
|
|
|
|
2008-09-13 13:42:11 +04:00
|
|
|
/* Now, move everything over to this frame and signal that
|
|
|
|
* we merged things!
|
|
|
|
*/
|
2012-04-13 15:44:06 +04:00
|
|
|
mStoredList.MergeFrom(&static_cast<nsDisplayTransform*>(aItem)->mStoredList);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-13 13:42:11 +04: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!");
|
|
|
|
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2008-09-13 13:42:11 +04:00
|
|
|
return nsLayoutUtils::MatrixTransformRect
|
|
|
|
(aUntransformedBounds,
|
2011-02-25 01:55:23 +03:00
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect nsDisplayTransform::TransformRectOut(const nsRect &aUntransformedBounds,
|
|
|
|
const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin,
|
|
|
|
const nsRect* aBoundsOverride)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2011-02-25 01:55:23 +03:00
|
|
|
return nsLayoutUtils::MatrixTransformRectOut
|
|
|
|
(aUntransformedBounds,
|
2008-09-13 13:42:11 +04:00
|
|
|
GetResultingTransformMatrix(aFrame, aOrigin, factor, aBoundsOverride),
|
|
|
|
factor);
|
|
|
|
}
|
|
|
|
|
2012-02-14 13:12:49 +04:00
|
|
|
bool nsDisplayTransform::UntransformRectMatrix(const nsRect &aUntransformedBounds,
|
|
|
|
const gfx3DMatrix& aMatrix,
|
2012-02-17 10:08:33 +04:00
|
|
|
float aAppUnitsPerPixel,
|
2012-02-14 13:12:49 +04:00
|
|
|
nsRect *aOutRect)
|
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular())
|
|
|
|
return false;
|
|
|
|
|
2012-02-17 10:08:33 +04:00
|
|
|
gfxRect result(NSAppUnitsToFloatPixels(aUntransformedBounds.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.y, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.width, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aUntransformedBounds.height, aAppUnitsPerPixel));
|
2012-02-14 13:12:49 +04:00
|
|
|
|
|
|
|
/* We want to untransform the matrix, so invert the transformation first! */
|
|
|
|
result = aMatrix.Inverse().ProjectRectBounds(result);
|
|
|
|
|
2012-02-17 10:08:33 +04:00
|
|
|
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(result, aAppUnitsPerPixel);
|
2012-02-14 13:12:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayTransform::UntransformRect(const nsRect &aUntransformedBounds,
|
2008-09-13 13:42:11 +04:00
|
|
|
const nsIFrame* aFrame,
|
2011-07-23 02:28:51 +04:00
|
|
|
const nsPoint &aOrigin,
|
|
|
|
nsRect* aOutRect)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
|
|
|
|
/* Grab the matrix. If the transform is degenerate, just hand back the
|
|
|
|
* empty rect.
|
|
|
|
*/
|
2014-01-20 03:30:36 +04:00
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
2012-07-31 21:28:21 +04:00
|
|
|
gfx3DMatrix matrix = GetResultingTransformMatrix(aFrame, aOrigin, factor);
|
2011-08-03 07:04:21 +04:00
|
|
|
|
2012-02-14 13:12:49 +04:00
|
|
|
return UntransformRectMatrix(aUntransformedBounds, matrix, factor, aOutRect);
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplaySVGEffects::nsDisplaySVGEffects(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
2012-04-18 09:12:53 +04:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList),
|
2012-04-13 15:44:06 +04:00
|
|
|
mEffectsBounds(aFrame->GetVisualOverflowRectRelativeToSelf())
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplaySVGEffects::~nsDisplaySVGEffects()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySVGEffects);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion nsDisplaySVGEffects::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-01-03 04:48:09 +03:00
|
|
|
return nsRegion();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2010-04-08 04:31:26 +04:00
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2010-04-08 04:31:26 +04:00
|
|
|
nsPoint rectCenter(aRect.x + aRect.width / 2, aRect.y + aRect.height / 2);
|
2012-04-18 09:12:53 +04:00
|
|
|
if (nsSVGIntegrationUtils::HitTestFrameForEffects(mFrame,
|
|
|
|
rectCenter - ToReferenceFrame())) {
|
2010-04-08 04:31:26 +04:00
|
|
|
mList.HitTest(aBuilder, aRect, aState, aOutFrames);
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2012-07-17 21:03:51 +04:00
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::PaintAsLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(aCtx, mFrame,
|
|
|
|
mVisibleRect,
|
|
|
|
aBuilder, aManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerState
|
|
|
|
nsDisplaySVGEffects::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aParameters)
|
2012-07-17 21:03:51 +04:00
|
|
|
{
|
|
|
|
return LAYER_SVG_EFFECTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplaySVGEffects::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2012-06-11 08:44:08 +04:00
|
|
|
{
|
2012-07-20 22:12:29 +04: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 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
if (!static_cast<const nsSVGElement*>(content)->HasValidDimensions()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr; // The SVG spec says not to draw filters for this
|
2012-07-20 22:12:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
float opacity = mFrame->StyleDisplay()->mOpacity;
|
2012-07-17 21:03:51 +04:00
|
|
|
if (opacity == 0.0f)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
nsIFrame* firstFrame =
|
2013-09-25 15:42:34 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrSpecialSibling(mFrame);
|
2012-07-17 21:03:51 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
|
|
|
bool isOK = true;
|
2012-07-18 18:28:53 +04:00
|
|
|
effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
effectProperties.GetMaskFrame(&isOK);
|
2014-01-10 07:03:24 +04:00
|
|
|
bool hasFilter = effectProperties.GetFilterFrame(&isOK) != nullptr;
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
if (!isOK) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-17 21:03:51 +04:00
|
|
|
}
|
|
|
|
|
2014-01-10 07:03:24 +04:00
|
|
|
ContainerLayerParameters newContainerParameters = aContainerParameters;
|
|
|
|
if (hasFilter) {
|
|
|
|
newContainerParameters.mDisableSubpixelAntialiasingInDescendants = true;
|
|
|
|
}
|
|
|
|
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2012-07-17 21:03:51 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, mList,
|
2014-01-10 07:03:24 +04:00
|
|
|
newContainerParameters, nullptr);
|
2012-07-17 21:03:51 +04:00
|
|
|
|
|
|
|
return container.forget();
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplaySVGEffects::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-28 01:58:50 +03:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 20:40:46 +04:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) {
|
2012-04-18 09:12:53 +04:00
|
|
|
nsPoint offset = ToReferenceFrame();
|
2009-10-07 08:28:41 +04:00
|
|
|
nsRect dirtyRect =
|
2012-04-18 09:12:53 +04:00
|
|
|
nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(mFrame,
|
2009-10-07 08:28:41 +04: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 23:53:15 +04:00
|
|
|
nsRect r = dirtyRect.Intersect(mList.GetBounds(aBuilder));
|
2013-03-04 13:56:02 +04:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &childrenVisible, r, nsRect());
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplaySVGEffects::TryMerge(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem)
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
if (aItem->GetType() != TYPE_SVG_EFFECTS)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-11 04:24:16 +04:00
|
|
|
// items for the same content element should be merged into a single
|
|
|
|
// compositing group
|
|
|
|
// aItem->GetUnderlyingFrame() returns non-null because it's nsDisplaySVGEffects
|
2013-04-19 16:02:13 +04:00
|
|
|
if (aItem->Frame()->GetContent() != mFrame->GetContent())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2013-03-04 13:56:02 +04:00
|
|
|
if (aItem->GetClip() != GetClip())
|
|
|
|
return false;
|
2008-09-11 04:24:16 +04:00
|
|
|
nsDisplaySVGEffects* other = static_cast<nsDisplaySVGEffects*>(aItem);
|
2012-04-17 09:44:32 +04:00
|
|
|
MergeFromTrackingMergedFrames(other);
|
2012-04-13 15:44:06 +04:00
|
|
|
mEffectsBounds.UnionRect(mEffectsBounds,
|
2012-04-18 09:12:53 +04:00
|
|
|
other->mEffectsBounds + other->mFrame->GetOffsetTo(mFrame));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
2011-11-17 07:44:16 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
void
|
2014-01-27 02:07:08 +04:00
|
|
|
nsDisplaySVGEffects::PrintEffects(nsACString& aTo)
|
2011-11-17 07:44:16 +04:00
|
|
|
{
|
|
|
|
nsIFrame* firstFrame =
|
2013-09-25 15:42:34 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrSpecialSibling(mFrame);
|
2011-11-17 07:44:16 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
bool isOK = true;
|
|
|
|
nsSVGClipPathFrame *clipPathFrame = effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
bool first = true;
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += " effects=(";
|
2013-02-17 01:51:02 +04:00
|
|
|
if (mFrame->StyleDisplay()->mOpacity != 1.0f) {
|
2011-11-17 07:44:16 +04:00
|
|
|
first = false;
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += nsPrintfCString("opacity(%f)", mFrame->StyleDisplay()->mOpacity);
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
|
|
|
if (clipPathFrame) {
|
|
|
|
if (!first) {
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += ", ";
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += nsPrintfCString("clip(%s)", clipPathFrame->IsTrivial() ? "trivial" : "non-trivial");
|
2011-11-17 07:44:16 +04:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (effectProperties.GetFilterFrame(&isOK)) {
|
|
|
|
if (!first) {
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += ", ";
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += "filter";
|
2011-11-17 07:44:16 +04:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
if (effectProperties.GetMaskFrame(&isOK)) {
|
|
|
|
if (!first) {
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += ", ";
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += "mask";
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
2014-01-27 02:07:08 +04:00
|
|
|
aTo += ")";
|
2011-11-17 07:44:16 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|