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
|
|
|
|
*/
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
2014-08-06 09:19:27 +04:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "gfxUtils.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-10-19 16:22:22 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#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"
|
2014-06-25 19:12:32 +04:00
|
|
|
#include "gfxPrefs.h"
|
2015-04-07 19:39:09 +03:00
|
|
|
#include "gfxVR.h"
|
2008-09-11 04:24:16 +04:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
2014-08-30 20:22:31 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2009-07-22 04:44:57 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2010-07-16 01:08:12 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2014-02-04 10:14:07 +04:00
|
|
|
#include "nsIFrameInlines.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"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-08-30 21:22:33 +04:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2014-12-22 03:35:41 +03:00
|
|
|
#include "mozilla/PendingPlayerTracker.h"
|
2013-09-16 05:06:52 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-08-25 19:09:39 +04:00
|
|
|
#include "mozilla/UniquePtr.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"
|
2014-04-03 02:46:38 +04:00
|
|
|
#include "UnitTransforms.h"
|
2014-05-22 06:36:26 +04:00
|
|
|
#include "LayersLogging.h"
|
2014-08-06 09:19:25 +04:00
|
|
|
#include "FrameLayerBuilder.h"
|
2015-03-07 01:26:59 +03:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-11-17 07:46:00 +03:00
|
|
|
#include "RestyleManager.h"
|
2014-08-06 09:19:27 +04:00
|
|
|
#include "nsCaret.h"
|
|
|
|
#include "nsISelection.h"
|
2012-04-12 04:17:44 +04:00
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount().
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
using namespace mozilla;
|
2010-03-01 10:56:19 +03:00
|
|
|
using namespace mozilla::layers;
|
2012-12-12 02:49:57 +04:00
|
|
|
using namespace mozilla::dom;
|
2014-05-29 01:43:39 +04:00
|
|
|
using namespace mozilla::layout;
|
2014-08-01 16:31:48 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2011-01-13 20:45:14 +03:00
|
|
|
typedef FrameMetrics::ViewID ViewID;
|
2009-04-08 19:19:51 +04:00
|
|
|
|
2014-07-23 01:01:50 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
static bool
|
|
|
|
SpammyLayoutWarningsEnabled()
|
|
|
|
{
|
|
|
|
static bool sValue = false;
|
|
|
|
static bool sValueInitialized = false;
|
|
|
|
|
|
|
|
if (!sValueInitialized) {
|
|
|
|
Preferences::GetBool("layout.spammy_warnings.enabled", &sValue);
|
|
|
|
sValueInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sValue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
static inline nsIFrame*
|
|
|
|
GetTransformRootFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
return nsLayoutUtils::GetTransformRootFrame(aFrame);
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:21 +04:00
|
|
|
static void AddTransformFunctions(nsCSSValueList* aList,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsRect& aBounds,
|
|
|
|
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,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Width());
|
2012-07-31 21:28:21 +04:00
|
|
|
aFunctions.AppendElement(Translation(x, 0, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translatey:
|
|
|
|
{
|
|
|
|
double y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Height());
|
2012-07-31 21:28:21 +04:00
|
|
|
aFunctions.AppendElement(Translation(0, y, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translatez:
|
|
|
|
{
|
|
|
|
double z = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
0);
|
2012-07-31 21:28:21 +04:00
|
|
|
aFunctions.AppendElement(Translation(0, 0, z));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translate:
|
|
|
|
{
|
|
|
|
double x = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Width());
|
2012-07-31 21:28:21 +04:00
|
|
|
// translate(x) is shorthand for translate(x, 0)
|
|
|
|
double y = 0;
|
|
|
|
if (array->Count() == 3) {
|
|
|
|
y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(2), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Height());
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
aFunctions.AppendElement(Translation(x, y, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eCSSKeyword_translate3d:
|
|
|
|
{
|
|
|
|
double x = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(1), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Width());
|
2012-07-31 21:28:21 +04:00
|
|
|
double y = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(2), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds.Height());
|
2012-07-31 21:28:21 +04:00
|
|
|
double z = nsStyleTransformMatrix::ProcessTranslatePart(
|
|
|
|
array->Item(3), aContext, aPresContext, canStoreInRuleTree,
|
2014-05-08 09:35:00 +04:00
|
|
|
0);
|
2012-07-31 21:28:21 +04:00
|
|
|
|
|
|
|
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:
|
|
|
|
{
|
2014-01-27 19:28:33 +04:00
|
|
|
gfx::Matrix4x4 matrix;
|
2012-07-31 21:28:21 +04:00
|
|
|
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:
|
|
|
|
{
|
2014-01-27 19:28:33 +04:00
|
|
|
gfx::Matrix4x4 matrix;
|
2012-07-31 21:28:21 +04:00
|
|
|
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,
|
2014-05-08 09:35:00 +04:00
|
|
|
aBounds);
|
2014-07-22 17:12:14 +04:00
|
|
|
aFunctions.AppendElement(TransformMatrix(gfx::ToMatrix4x4(matrix)));
|
2012-12-12 01:12:43 +04:00
|
|
|
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
|
2015-03-20 07:10:00 +03:00
|
|
|
ToTimingFunction(const ComputedTimingFunction& aCTF)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
|
|
|
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
|
2015-03-20 07:10:00 +03:00
|
|
|
AddAnimationForProperty(nsIFrame* aFrame, const AnimationProperty& aProperty,
|
2014-08-10 11:06:48 +04:00
|
|
|
AnimationPlayer* aPlayer, Layer* aLayer,
|
2014-04-03 09:57:28 +04:00
|
|
|
AnimationData& aData, bool aPending)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2014-08-10 11:06:49 +04:00
|
|
|
MOZ_ASSERT(aLayer->AsContainerLayer(), "Should only animate ContainerLayer");
|
|
|
|
MOZ_ASSERT(aPlayer->GetSource(),
|
|
|
|
"Should not be adding an animation for a player without"
|
|
|
|
" an animation");
|
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);
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-08-10 11:06:49 +04:00
|
|
|
layers::Animation* animation =
|
2014-04-03 09:57:28 +04:00
|
|
|
aPending ?
|
|
|
|
aLayer->AddAnimationForNextTransaction() :
|
|
|
|
aLayer->AddAnimation();
|
2012-08-20 17:35:42 +04:00
|
|
|
|
2014-08-10 11:06:50 +04:00
|
|
|
const AnimationTiming& timing = aPlayer->GetSource()->Timing();
|
2015-02-03 08:08:37 +03:00
|
|
|
Nullable<TimeDuration> startTime = aPlayer->GetCurrentOrPendingStartTime();
|
|
|
|
animation->startTime() = startTime.IsNull()
|
|
|
|
? TimeStamp()
|
|
|
|
: aPlayer->Timeline()->ToTimeStamp(
|
|
|
|
startTime.Value() + timing.mDelay);
|
2014-12-22 03:35:41 +03:00
|
|
|
animation->initialCurrentTime() = aPlayer->GetCurrentTime().Value()
|
|
|
|
- timing.mDelay;
|
2014-08-10 11:06:50 +04:00
|
|
|
animation->duration() = timing.mIterationDuration;
|
|
|
|
animation->iterationCount() = timing.mIterationCount;
|
|
|
|
animation->direction() = timing.mDirection;
|
2015-03-20 07:10:00 +03:00
|
|
|
animation->property() = aProperty.mProperty;
|
2014-03-05 08:13:21 +04:00
|
|
|
animation->data() = aData;
|
2012-08-20 17:35:42 +04:00
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
for (uint32_t segIdx = 0; segIdx < aProperty.mSegments.Length(); segIdx++) {
|
|
|
|
const AnimationPropertySegment& segment = aProperty.mSegments[segIdx];
|
2012-07-31 21:28:22 +04:00
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
AnimationSegment* animSegment = animation->segments().AppendElement();
|
|
|
|
if (aProperty.mProperty == eCSSProperty_transform) {
|
|
|
|
animSegment->startState() = InfallibleTArray<TransformFunction>();
|
|
|
|
animSegment->endState() = InfallibleTArray<TransformFunction>();
|
2012-08-20 17:35:42 +04:00
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
nsCSSValueSharedList* list =
|
|
|
|
segment.mFromValue.GetCSSValueSharedListValue();
|
|
|
|
AddTransformFunctions(list->mHead, styleContext, presContext, bounds,
|
|
|
|
animSegment->startState().get_ArrayOfTransformFunction());
|
2015-03-18 18:32:54 +03:00
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
list = segment.mToValue.GetCSSValueSharedListValue();
|
|
|
|
AddTransformFunctions(list->mHead, styleContext, presContext, bounds,
|
|
|
|
animSegment->endState().get_ArrayOfTransformFunction());
|
|
|
|
} else if (aProperty.mProperty == eCSSProperty_opacity) {
|
|
|
|
animSegment->startState() = segment.mFromValue.GetFloatValue();
|
|
|
|
animSegment->endState() = segment.mToValue.GetFloatValue();
|
2015-03-18 18:32:54 +03:00
|
|
|
}
|
2015-03-20 07:10:00 +03:00
|
|
|
|
|
|
|
animSegment->startPortion() = segment.mFromKey;
|
|
|
|
animSegment->endPortion() = segment.mToKey;
|
|
|
|
animSegment->sampleFn() = ToTimingFunction(segment.mTimingFunction);
|
2012-07-31 21:28:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 09:57:28 +04:00
|
|
|
static void
|
|
|
|
AddAnimationsForProperty(nsIFrame* aFrame, nsCSSProperty aProperty,
|
2014-08-10 11:06:48 +04:00
|
|
|
AnimationPlayerPtrArray& aPlayers,
|
2014-04-03 09:57:28 +04:00
|
|
|
Layer* aLayer, AnimationData& aData,
|
2015-03-20 07:10:00 +03:00
|
|
|
bool aPending)
|
|
|
|
{
|
2015-04-01 01:05:54 +03:00
|
|
|
MOZ_ASSERT(nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR),
|
|
|
|
"inconsistent property flags");
|
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
// Add from first to last (since last overrides)
|
2014-08-10 11:06:48 +04:00
|
|
|
for (size_t playerIdx = 0; playerIdx < aPlayers.Length(); playerIdx++) {
|
|
|
|
AnimationPlayer* player = aPlayers[playerIdx];
|
2015-03-27 12:01:00 +03:00
|
|
|
if (!player->IsPlaying()) {
|
2015-03-20 07:10:00 +03:00
|
|
|
continue;
|
|
|
|
}
|
2014-08-10 11:06:49 +04:00
|
|
|
dom::Animation* anim = player->GetSource();
|
2015-03-27 12:01:00 +03:00
|
|
|
MOZ_ASSERT(anim, "A playing player should have a source animation");
|
2015-03-20 07:10:00 +03:00
|
|
|
const AnimationProperty* property =
|
|
|
|
anim->GetAnimationOfProperty(aProperty);
|
|
|
|
if (!property) {
|
2015-03-18 17:35:30 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
// Note that if mWinsInCascade on property was false,
|
|
|
|
// GetAnimationOfProperty returns null instead.
|
|
|
|
// This is what we want, since if we have an animation or transition
|
|
|
|
// that isn't actually winning in the CSS cascade, we don't want to
|
|
|
|
// send it to the compositor.
|
|
|
|
// I believe that anything that changes mWinsInCascade should
|
|
|
|
// trigger this code again, either because of a restyle that changes
|
|
|
|
// the properties in question, or because of the main-thread style
|
|
|
|
// update that results when an animation stops being in effect.
|
|
|
|
MOZ_ASSERT(property->mWinsInCascade,
|
|
|
|
"GetAnimationOfProperty already tested mWinsInCascade");
|
2015-03-20 07:10:00 +03:00
|
|
|
|
2014-12-22 03:35:42 +03:00
|
|
|
// Don't add animations that are pending when their corresponding
|
|
|
|
// refresh driver is under test control. This is because any pending
|
|
|
|
// animations on layers will have their start time updated with the
|
|
|
|
// current timestamp but when the refresh driver is under test control
|
|
|
|
// its refresh times are unrelated to timestamp values.
|
|
|
|
//
|
|
|
|
// Instead we leave the animation running on the main thread and the
|
|
|
|
// next time the refresh driver is advanced it will trigger any pending
|
|
|
|
// animations.
|
|
|
|
if (player->PlayState() == AnimationPlayState::Pending) {
|
|
|
|
nsRefreshDriver* driver = player->Timeline()->GetRefreshDriver();
|
|
|
|
if (driver && driver->IsTestControllingRefreshesEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 07:10:00 +03:00
|
|
|
AddAnimationForProperty(aFrame, *property, player, aLayer, aData, aPending);
|
2014-10-20 08:55:46 +04:00
|
|
|
player->SetIsRunningOnCompositor();
|
2014-04-03 09:57:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
/* static */ void
|
|
|
|
nsDisplayListBuilder::AddAnimationsAndTransitionsToLayer(Layer* aLayer,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsCSSProperty aProperty)
|
2012-07-31 21:28:21 +04:00
|
|
|
{
|
2015-04-01 01:05:54 +03:00
|
|
|
MOZ_ASSERT(nsCSSProps::PropHasFlags(aProperty,
|
|
|
|
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR),
|
|
|
|
"inconsistent property flags");
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
// This function can be called in two ways: from
|
|
|
|
// nsDisplay*::BuildLayer while constructing a layer (with all
|
|
|
|
// pointers non-null), or from RestyleManager's handling of
|
|
|
|
// UpdateOpacityLayer/UpdateTransformLayer hints.
|
|
|
|
MOZ_ASSERT(!aBuilder == !aItem,
|
|
|
|
"should only be called in two configurations, with both "
|
|
|
|
"aBuilder and aItem, or with neither");
|
|
|
|
MOZ_ASSERT(!aItem || aFrame == aItem->Frame(), "frame mismatch");
|
|
|
|
|
|
|
|
bool pending = !aBuilder;
|
|
|
|
|
|
|
|
if (pending) {
|
|
|
|
aLayer->ClearAnimationsForNextTransaction();
|
|
|
|
} else {
|
|
|
|
aLayer->ClearAnimations();
|
|
|
|
}
|
2012-08-07 00:33:23 +04:00
|
|
|
|
2014-11-17 07:46:00 +03:00
|
|
|
// Update the animation generation on the layer. We need to do this before
|
|
|
|
// any early returns since even if we don't add any animations to the
|
|
|
|
// layer, we still need to mark it as up-to-date with regards to animations.
|
|
|
|
// Otherwise, in RestyleManager we'll notice the discrepancy between the
|
|
|
|
// animation generation numbers and update the layer indefinitely.
|
|
|
|
uint64_t animationGeneration =
|
|
|
|
RestyleManager::GetMaxAnimationGenerationForFrame(aFrame);
|
|
|
|
aLayer->SetAnimationGeneration(animationGeneration);
|
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
nsIContent* content = aFrame->GetContent();
|
2012-09-20 03:14:07 +04:00
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* transitions =
|
2015-04-07 04:13:48 +03:00
|
|
|
nsTransitionManager::GetAnimationsForCompositor(content, aProperty);
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection* animations =
|
2015-04-07 04:13:48 +03:00
|
|
|
nsAnimationManager::GetAnimationsForCompositor(content, aProperty);
|
2012-07-31 21:28:22 +04:00
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
if (!animations && !transitions) {
|
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.
|
2014-03-05 08:13:21 +04:00
|
|
|
// Do this check only during layer construction; during updating the
|
|
|
|
// caller is required to check it appropriately.
|
|
|
|
if (aItem && !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.
|
2014-03-05 08:13:21 +04:00
|
|
|
aFrame->Properties().Set(nsIFrame::RefusedAsyncAnimation(),
|
2013-10-22 14:30:45 +04:00
|
|
|
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.
|
2014-03-05 08:13:21 +04:00
|
|
|
aFrame->SchedulePaint();
|
2012-08-07 00:33:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 21:28:22 +04:00
|
|
|
AnimationData data;
|
|
|
|
if (aProperty == eCSSProperty_transform) {
|
2014-03-05 08:13:21 +04:00
|
|
|
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
|
2012-07-31 21:28:22 +04:00
|
|
|
float scale = nsDeviceContext::AppUnitsPerCSSPixel();
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D offsetToTransformOrigin =
|
2014-03-05 08:13:21 +04:00
|
|
|
nsDisplayTransform::GetDeltaToTransformOrigin(aFrame, scale, &bounds);
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D offsetToPerspectiveOrigin =
|
2014-03-05 08:13:21 +04:00
|
|
|
nsDisplayTransform::GetDeltaToPerspectiveOrigin(aFrame, scale);
|
2012-07-31 21:28:22 +04:00
|
|
|
nscoord perspective = 0.0;
|
2014-03-05 08:13:21 +04:00
|
|
|
nsStyleContext* parentStyleContext = aFrame->StyleContext()->GetParent();
|
2012-07-31 21:28:22 +04:00
|
|
|
if (parentStyleContext) {
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleDisplay* disp = parentStyleContext->StyleDisplay();
|
|
|
|
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
|
|
|
}
|
2014-03-05 08:13:21 +04:00
|
|
|
nsPoint origin;
|
|
|
|
if (aItem) {
|
|
|
|
origin = aItem->ToReferenceFrame();
|
|
|
|
} else {
|
|
|
|
// transform display items used a reference frame computed from
|
|
|
|
// their GetTransformRootFrame().
|
|
|
|
nsIFrame* referenceFrame =
|
|
|
|
nsLayoutUtils::GetReferenceFrame(GetTransformRootFrame(aFrame));
|
|
|
|
origin = aFrame->GetOffsetToCrossDoc(referenceFrame);
|
|
|
|
}
|
2012-07-31 21:28:22 +04:00
|
|
|
|
|
|
|
data = TransformData(origin, offsetToTransformOrigin,
|
2013-02-13 01:00:54 +04:00
|
|
|
offsetToPerspectiveOrigin, bounds, perspective,
|
2014-03-05 08:13:21 +04:00
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel());
|
2012-07-31 21:28:22 +04:00
|
|
|
} else if (aProperty == eCSSProperty_opacity) {
|
|
|
|
data = null_t();
|
|
|
|
}
|
|
|
|
|
2015-04-01 01:05:55 +03:00
|
|
|
// When both are running, animations override transitions. We want
|
|
|
|
// to add the ones that override last.
|
2014-06-27 03:57:13 +04:00
|
|
|
if (transitions) {
|
2014-08-10 11:06:48 +04:00
|
|
|
AddAnimationsForProperty(aFrame, aProperty, transitions->mPlayers,
|
2014-04-03 09:57:28 +04:00
|
|
|
aLayer, data, pending);
|
2012-07-31 21:28:22 +04:00
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-06-27 03:57:13 +04:00
|
|
|
if (animations) {
|
2014-08-10 11:06:48 +04:00
|
|
|
AddAnimationsForProperty(aFrame, aProperty, animations->mPlayers,
|
2014-04-03 09:57:28 +04:00
|
|
|
aLayer, data, pending);
|
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),
|
2014-05-20 07:49:54 +04:00
|
|
|
mCurrentFrame(aReferenceFrame),
|
|
|
|
mCurrentReferenceFrame(aReferenceFrame),
|
2014-12-03 18:20:32 +03:00
|
|
|
mCurrentAnimatedGeometryRoot(nullptr),
|
2014-10-22 05:55:55 +04:00
|
|
|
mWillChangeBudgetCalculated(false),
|
2014-05-20 07:59:14 +04:00
|
|
|
mDirtyRect(-1,-1,-1,-1),
|
2012-07-30 18:20:58 +04:00
|
|
|
mGlassDisplayItem(nullptr),
|
2010-11-08 12:06:14 +03:00
|
|
|
mMode(aMode),
|
2014-04-12 03:39:22 +04:00
|
|
|
mCurrentScrollParentId(FrameMetrics::NULL_SCROLL_ID),
|
2014-06-04 23:18:20 +04:00
|
|
|
mCurrentScrollbarTarget(FrameMetrics::NULL_SCROLL_ID),
|
|
|
|
mCurrentScrollbarFlags(0),
|
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),
|
2015-02-09 21:24:51 +03:00
|
|
|
mIsInChromePresContext(false),
|
2011-10-17 18:59:28 +04:00
|
|
|
mSyncDecodeImages(false),
|
|
|
|
mIsPaintingToWindow(false),
|
2012-10-18 09:34:58 +04:00
|
|
|
mIsCompositingCheap(false),
|
2013-09-15 07:30:00 +04:00
|
|
|
mContainsPluginItem(false),
|
2015-02-11 00:28:07 +03:00
|
|
|
mAncestorHasApzAwareEventHandler(false),
|
2015-02-02 23:10:51 +03:00
|
|
|
mHaveScrollableDisplayPort(false),
|
2015-02-09 21:24:51 +03:00
|
|
|
mWindowDraggingAllowed(false),
|
2015-02-24 12:24:04 +03:00
|
|
|
mIsBuildingForPopup(nsLayoutUtils::IsPopup(aReferenceFrame)),
|
|
|
|
mForceLayerForScrollParent(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);
|
2014-12-03 18:20:32 +03:00
|
|
|
RecomputeCurrentAnimatedGeometryRoot();
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 13:49:27 +04:00
|
|
|
void nsDisplayListBuilder::SetContainsBlendMode(uint8_t aBlendMode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aBlendMode != NS_STYLE_BLEND_NORMAL);
|
|
|
|
gfxContext::GraphicsOperator op = nsCSSRendering::GetGFXBlendMode(aBlendMode);
|
|
|
|
mContainedBlendModes += gfx::CompositionOpForOp(op);
|
|
|
|
}
|
|
|
|
|
2014-08-20 19:24:39 +04:00
|
|
|
bool nsDisplayListBuilder::NeedToForceTransparentSurfaceForItem(nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
return aItem == mGlassDisplayItem || aItem->ClearsBackground();
|
|
|
|
}
|
|
|
|
|
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;
|
2015-02-20 21:55:28 +03:00
|
|
|
DisplayItemClip clip;
|
|
|
|
const DisplayItemClip* clipPtr = nullptr;
|
2014-07-24 07:10:44 +04:00
|
|
|
if (nsLayoutUtils::IsFixedPosFrameInDisplayPort(aFrame) &&
|
|
|
|
IsPaintingToWindow()) {
|
2013-09-27 10:01:15 +04:00
|
|
|
NS_ASSERTION(aDirtyFrame == aFrame->GetParent(), "Dirty frame should be viewport frame");
|
2014-03-03 05:49:39 +04:00
|
|
|
// position: fixed items are reflowed into and only drawn inside the
|
|
|
|
// viewport, or the scroll position clamping scrollport size, if one is
|
|
|
|
// set.
|
|
|
|
nsIPresShell* ps = aFrame->PresContext()->PresShell();
|
|
|
|
dirtyRectRelativeToDirtyFrame.MoveTo(0, 0);
|
|
|
|
if (ps->IsScrollPositionClampingScrollPortSizeSet()) {
|
|
|
|
dirtyRectRelativeToDirtyFrame.SizeTo(ps->GetScrollPositionClampingScrollPortSize());
|
|
|
|
} else {
|
|
|
|
dirtyRectRelativeToDirtyFrame.SizeTo(aDirtyFrame->GetSize());
|
|
|
|
}
|
2015-02-20 21:55:28 +03:00
|
|
|
|
|
|
|
// Always clip fixed items to the root scroll frame's scrollport, because
|
|
|
|
// we skip setting the clip in ScrollFrameHelper if we have a displayport.
|
|
|
|
nsIFrame* rootScroll = aFrame->PresContext()->PresShell()->GetRootScrollFrame();
|
|
|
|
if (rootScroll) {
|
|
|
|
nsIScrollableFrame* scrollable = do_QueryFrame(rootScroll);
|
|
|
|
|
|
|
|
nsRect clipRect = scrollable->GetScrollPortRect() + ToReferenceFrame(rootScroll);
|
|
|
|
nscoord radii[8];
|
|
|
|
bool haveRadii = rootScroll->GetPaddingBoxBorderRadii(radii);
|
|
|
|
clip.SetTo(clipRect, haveRadii ? radii : nullptr);
|
|
|
|
clipPtr = &clip;
|
|
|
|
}
|
2013-09-27 10:01:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2015-02-20 21:55:28 +03:00
|
|
|
|
|
|
|
// Combine clips if necessary
|
|
|
|
const DisplayItemClip* oldClip = mClipState.GetClipForContainingBlockDescendants();
|
|
|
|
if (clipPtr && oldClip) {
|
|
|
|
clip.IntersectWith(*oldClip);
|
|
|
|
} else if (oldClip) {
|
|
|
|
clipPtr = oldClip;
|
|
|
|
}
|
|
|
|
|
|
|
|
OutOfFlowDisplayData* data = clipPtr ? new OutOfFlowDisplayData(*clipPtr, dirty)
|
2013-06-18 13:15:39 +04:00
|
|
|
: 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
/* static */ FrameMetrics
|
|
|
|
nsDisplayScrollLayer::ComputeFrameMetrics(nsIFrame* aForFrame,
|
|
|
|
nsIFrame* aScrollFrame,
|
2015-02-13 04:49:10 +03:00
|
|
|
nsIContent* aContent,
|
2014-08-31 07:29:24 +04:00
|
|
|
const nsIFrame* aReferenceFrame,
|
|
|
|
Layer* aLayer,
|
|
|
|
ViewID aScrollParentId,
|
|
|
|
const nsRect& aViewport,
|
|
|
|
bool aIsRoot,
|
|
|
|
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();
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2014-04-22 01:09:30 +04:00
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
2011-01-13 20:45:14 +03:00
|
|
|
FrameMetrics metrics;
|
2014-08-23 07:18:56 +04:00
|
|
|
metrics.SetViewport(CSSRect::FromAppUnits(aViewport));
|
2014-07-09 02:01:02 +04:00
|
|
|
|
|
|
|
ViewID scrollId = FrameMetrics::NULL_SCROLL_ID;
|
2015-02-13 04:49:10 +03:00
|
|
|
if (aContent) {
|
|
|
|
scrollId = nsLayoutUtils::FindOrCreateIDFor(aContent);
|
2014-07-09 02:01:02 +04:00
|
|
|
nsRect dp;
|
2015-02-13 04:49:10 +03:00
|
|
|
if (nsLayoutUtils::GetDisplayPort(aContent, &dp)) {
|
2014-12-23 18:35:58 +03:00
|
|
|
metrics.SetDisplayPort(CSSRect::FromAppUnits(dp));
|
2014-08-31 07:29:24 +04:00
|
|
|
nsLayoutUtils::LogTestDataForPaint(aLayer->Manager(), scrollId, "displayport",
|
2014-12-23 18:35:58 +03:00
|
|
|
metrics.GetDisplayPort());
|
2014-07-09 02:01:02 +04:00
|
|
|
}
|
2015-02-13 04:49:10 +03:00
|
|
|
if (nsLayoutUtils::GetCriticalDisplayPort(aContent, &dp)) {
|
2014-12-30 22:07:57 +03:00
|
|
|
metrics.SetCriticalDisplayPort(CSSRect::FromAppUnits(dp));
|
2013-06-10 17:05:42 +04:00
|
|
|
}
|
2014-07-09 02:01:02 +04:00
|
|
|
DisplayPortMarginsPropertyData* marginsData =
|
2015-02-13 04:49:10 +03:00
|
|
|
static_cast<DisplayPortMarginsPropertyData*>(aContent->GetProperty(nsGkAtoms::DisplayPortMargins));
|
2014-07-09 02:01:02 +04:00
|
|
|
if (marginsData) {
|
|
|
|
metrics.SetDisplayPortMargins(marginsData->mMargins);
|
|
|
|
}
|
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
|
|
|
|
2014-12-27 20:48:27 +03:00
|
|
|
metrics.SetScrollableRect(CSSRect::FromAppUnits(
|
|
|
|
nsLayoutUtils::CalculateScrollableRectForFrame(scrollableFrame, aForFrame)));
|
2014-03-27 05:46:23 +04:00
|
|
|
|
2011-03-16 02:20:19 +03:00
|
|
|
if (scrollableFrame) {
|
2014-03-07 17:41:00 +04:00
|
|
|
nsPoint scrollPosition = scrollableFrame->GetScrollPosition();
|
2014-03-13 10:34:34 +04:00
|
|
|
metrics.SetScrollOffset(CSSPoint::FromAppUnits(scrollPosition));
|
2013-12-16 21:04:45 +04:00
|
|
|
|
2014-07-10 22:52:40 +04:00
|
|
|
nsPoint smoothScrollPosition = scrollableFrame->LastScrollDestination();
|
|
|
|
metrics.SetSmoothScrollOffset(CSSPoint::FromAppUnits(smoothScrollPosition));
|
|
|
|
|
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.
|
2014-07-10 22:52:40 +04:00
|
|
|
nsIAtom* lastScrollOrigin = scrollableFrame->LastScrollOrigin();
|
|
|
|
if (lastScrollOrigin && lastScrollOrigin != nsGkAtoms::apz) {
|
2014-02-06 02:43:20 +04:00
|
|
|
metrics.SetScrollOffsetUpdated(scrollableFrame->CurrentScrollGeneration());
|
|
|
|
}
|
2014-07-10 22:52:40 +04:00
|
|
|
nsIAtom* lastSmoothScrollOrigin = scrollableFrame->LastSmoothScrollOrigin();
|
|
|
|
if (lastSmoothScrollOrigin) {
|
|
|
|
metrics.SetSmoothScrollOffsetUpdated(scrollableFrame->CurrentScrollGeneration());
|
|
|
|
}
|
2014-11-18 07:56:18 +03:00
|
|
|
|
|
|
|
nsSize lineScrollAmount = scrollableFrame->GetLineScrollAmount();
|
|
|
|
LayoutDeviceIntSize lineScrollAmountInDevPixels =
|
|
|
|
LayoutDeviceIntSize::FromAppUnitsRounded(lineScrollAmount, presContext->AppUnitsPerDevPixel());
|
|
|
|
metrics.SetLineScrollAmount(lineScrollAmountInDevPixels);
|
2015-03-07 01:26:59 +03:00
|
|
|
|
2015-03-25 00:59:41 +03:00
|
|
|
nsSize pageScrollAmount = scrollableFrame->GetPageScrollAmount();
|
|
|
|
LayoutDeviceIntSize pageScrollAmountInDevPixels =
|
|
|
|
LayoutDeviceIntSize::FromAppUnitsRounded(pageScrollAmount, presContext->AppUnitsPerDevPixel());
|
|
|
|
metrics.SetPageScrollAmount(pageScrollAmountInDevPixels);
|
|
|
|
|
2015-03-07 01:26:59 +03:00
|
|
|
if (!aScrollFrame->GetParent() ||
|
|
|
|
EventStateManager::CanVerticallyScrollFrameWithWheel(aScrollFrame->GetParent()))
|
|
|
|
{
|
|
|
|
metrics.SetAllowVerticalScrollWithWheel();
|
|
|
|
}
|
2011-01-19 19:56:22 +03:00
|
|
|
}
|
2011-01-13 20:45:14 +03:00
|
|
|
|
2014-07-09 02:01:02 +04:00
|
|
|
metrics.SetScrollId(scrollId);
|
2014-08-24 03:09:10 +04:00
|
|
|
metrics.SetIsRoot(aIsRoot);
|
2014-08-28 06:13:39 +04:00
|
|
|
metrics.SetScrollParentId(aScrollParentId);
|
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.
|
|
|
|
if (aScrollFrame == presShell->GetRootScrollFrame()) {
|
2015-03-07 02:07:59 +03:00
|
|
|
metrics.SetPresShellResolution(presShell->GetResolution());
|
2013-08-30 21:11:01 +04:00
|
|
|
} else {
|
2015-01-17 00:15:52 +03:00
|
|
|
metrics.SetPresShellResolution(1.0f);
|
2012-12-12 02:49:57 +04:00
|
|
|
}
|
2014-10-24 23:49:38 +04:00
|
|
|
// The cumulative resolution is the resolution at which the scroll frame's
|
|
|
|
// content is actually rendered. It includes the pres shell resolutions of
|
|
|
|
// all the pres shells from here up to the root, as well as any css-driven
|
|
|
|
// resolution. We don't need to compute it as it's already stored in the
|
|
|
|
// container parameters.
|
2015-04-08 04:55:28 +03:00
|
|
|
metrics.SetCumulativeResolution(aContainerParameters.Scale());
|
2015-03-06 21:54:10 +03:00
|
|
|
|
|
|
|
LayoutDeviceToScreenScale2D resolutionToScreen(
|
|
|
|
presShell->GetCumulativeResolution()
|
|
|
|
* nsLayoutUtils::GetTransformToAncestorScale(aScrollFrame ? aScrollFrame : aForFrame));
|
2014-12-19 03:33:18 +03:00
|
|
|
metrics.SetExtraResolution(metrics.GetCumulativeResolution() / resolutionToScreen);
|
2013-09-06 02:26:59 +04:00
|
|
|
|
2014-12-18 01:14:05 +03:00
|
|
|
metrics.SetDevPixelsPerCSSPixel(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.
|
2014-11-10 22:35:11 +03:00
|
|
|
const LayerToParentLayerScale layerToParentLayerScale(1.0f);
|
2014-12-19 03:33:18 +03:00
|
|
|
metrics.SetZoom(metrics.GetCumulativeResolution() * metrics.GetDevPixelsPerCSSPixel()
|
2014-11-10 22:35:11 +03:00
|
|
|
* layerToParentLayerScale);
|
2013-08-30 21:11:01 +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());
|
2015-02-26 01:08:40 +03:00
|
|
|
if (scrollableFrame) {
|
|
|
|
// If we have a scrollable frame, restrict the composition bounds to its
|
|
|
|
// scroll port. The scroll port excludes the frame borders and the scroll
|
|
|
|
// bars, which we don't want to be part of the composition bounds.
|
|
|
|
nsRect scrollPort = scrollableFrame->GetScrollPortRect();
|
|
|
|
compositionBounds = nsRect(compositionBounds.TopLeft() + scrollPort.TopLeft(),
|
|
|
|
scrollPort.Size());
|
|
|
|
}
|
2014-07-29 22:50:48 +04:00
|
|
|
ParentLayerRect frameBounds = LayoutDeviceRect::FromAppUnits(compositionBounds, auPerDevPixel)
|
2014-12-19 03:33:18 +03:00
|
|
|
* metrics.GetCumulativeResolution()
|
2014-11-10 22:35:11 +03:00
|
|
|
* layerToParentLayerScale;
|
2014-07-29 22:50:48 +04:00
|
|
|
metrics.mCompositionBounds = frameBounds;
|
2014-05-05 08:18:18 +04:00
|
|
|
|
2015-02-26 01:08:40 +03:00
|
|
|
// For the root scroll frame of the root content document (RCD-RSF), the above calculation
|
2014-03-11 01:56:59 +04:00
|
|
|
// will yield the size of the viewport frame as the composition bounds, which
|
|
|
|
// doesn't actually correspond to what is visible when
|
|
|
|
// nsIDOMWindowUtils::setCSSViewport has been called to modify the visible area of
|
|
|
|
// the prescontext that the viewport frame is reflowed into. In that case if our
|
|
|
|
// document has a widget then the widget's bounds will correspond to what is
|
|
|
|
// visible. If we don't have a widget the root view's bounds correspond to what
|
|
|
|
// would be visible because they don't get modified by setCSSViewport.
|
2014-06-07 00:50:20 +04:00
|
|
|
bool isRootScrollFrame = aScrollFrame == presShell->GetRootScrollFrame();
|
|
|
|
bool isRootContentDocRootScrollFrame = isRootScrollFrame
|
|
|
|
&& presContext->IsRootContentDocument();
|
2013-09-11 01:47:14 +04:00
|
|
|
if (isRootContentDocRootScrollFrame) {
|
2014-03-11 01:56:59 +04:00
|
|
|
if (nsIFrame* rootFrame = presShell->GetRootFrame()) {
|
2014-07-29 22:50:48 +04:00
|
|
|
// On Android, we need to do things a bit differently to get things
|
|
|
|
// right (see bug 983208, bug 988882). We use the bounds of the nearest
|
|
|
|
// widget, but clamp the height to the frame bounds height. This clamping
|
|
|
|
// is done to get correct results for a page where the page is sized to
|
|
|
|
// the screen and thus the dynamic toolbar never disappears. In such a
|
|
|
|
// case, we want the composition bounds to exclude the toolbar height,
|
|
|
|
// but the widget bounds includes it. We don't currently have a good way
|
|
|
|
// of knowing about the toolbar height, but clamping to the frame bounds
|
|
|
|
// height gives the correct answer in the cases we care about.
|
2014-03-17 20:16:05 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2014-07-29 22:50:48 +04:00
|
|
|
nsIWidget* widget = rootFrame->GetNearestWidget();
|
2014-04-02 09:35:25 +04:00
|
|
|
#else
|
2014-07-29 22:50:48 +04:00
|
|
|
nsView* view = rootFrame->GetView();
|
|
|
|
nsIWidget* widget = view ? view->GetWidget() : nullptr;
|
2014-03-17 20:16:05 +04:00
|
|
|
#endif
|
2014-07-29 22:50:48 +04:00
|
|
|
if (widget) {
|
|
|
|
nsIntRect widgetBounds;
|
|
|
|
widget->GetBounds(widgetBounds);
|
2015-03-31 23:39:02 +03:00
|
|
|
widgetBounds.MoveTo(0,0);
|
2014-07-29 22:50:48 +04:00
|
|
|
metrics.mCompositionBounds = ParentLayerRect(ViewAs<ParentLayerPixel>(widgetBounds));
|
2014-04-02 09:35:25 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2014-07-29 22:50:48 +04:00
|
|
|
if (frameBounds.height < metrics.mCompositionBounds.height) {
|
|
|
|
metrics.mCompositionBounds.height = frameBounds.height;
|
|
|
|
}
|
2014-04-02 09:35:25 +04:00
|
|
|
#endif
|
2014-07-29 22:50:48 +04:00
|
|
|
} else {
|
2014-09-23 20:17:36 +04:00
|
|
|
LayoutDeviceIntSize contentSize;
|
|
|
|
if (nsLayoutUtils::GetContentViewerSize(presContext, contentSize)) {
|
2015-03-07 02:07:59 +03:00
|
|
|
LayoutDeviceToParentLayerScale scale;
|
2014-07-29 22:50:48 +04:00
|
|
|
if (presContext->GetParentPresContext()) {
|
2015-03-07 02:07:59 +03:00
|
|
|
float res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
|
|
|
|
scale = LayoutDeviceToParentLayerScale(res);
|
2014-07-29 22:50:48 +04:00
|
|
|
}
|
2014-09-23 20:17:36 +04:00
|
|
|
metrics.mCompositionBounds.SizeTo(contentSize * scale);
|
2014-03-11 01:56:59 +04:00
|
|
|
}
|
|
|
|
}
|
2013-09-11 01:47:14 +04:00
|
|
|
|
2015-02-26 01:08:40 +03:00
|
|
|
// Exclude any non-overlay scroll bars from the composition bounds.
|
|
|
|
// This is only done for the RCD-RSF case, because otherwise the scroll
|
|
|
|
// port size is used and that already excludes the scroll bars.
|
|
|
|
if (scrollableFrame && !LookAndFeel::GetInt(LookAndFeel::eIntID_UseOverlayScrollbars)) {
|
|
|
|
nsMargin sizes = scrollableFrame->GetActualScrollbarSizes();
|
|
|
|
// Scrollbars are not subject to scaling, so CSS pixels = layer pixels for them.
|
|
|
|
ParentLayerMargin boundMargins = CSSMargin::FromAppUnits(sizes) * CSSToParentLayerScale(1.0f);
|
|
|
|
metrics.mCompositionBounds.Deflate(boundMargins);
|
|
|
|
}
|
|
|
|
}
|
2013-08-23 00:18:11 +04:00
|
|
|
}
|
|
|
|
|
2014-03-27 03:24:25 +04:00
|
|
|
metrics.SetRootCompositionSize(
|
2014-04-04 18:13:09 +04:00
|
|
|
nsLayoutUtils::CalculateRootCompositionSize(aScrollFrame ? aScrollFrame : aForFrame,
|
|
|
|
isRootContentDocRootScrollFrame, metrics));
|
2014-03-27 03:24:25 +04:00
|
|
|
|
2014-06-25 19:12:32 +04:00
|
|
|
if (gfxPrefs::APZPrintTree()) {
|
2014-01-23 01:37:57 +04:00
|
|
|
if (nsIContent* content = frameForCompositionBoundsCalculation->GetContent()) {
|
|
|
|
nsAutoString contentDescription;
|
|
|
|
content->Describe(contentDescription);
|
2014-08-29 16:23:25 +04:00
|
|
|
metrics.SetContentDescription(NS_LossyConvertUTF16toASCII(contentDescription));
|
2014-01-23 01:37:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-17 03:00:50 +04:00
|
|
|
metrics.SetPresShellId(presShell->GetPresShellId());
|
2013-05-24 05:43:36 +04:00
|
|
|
|
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())) {
|
2014-06-26 03:16:27 +04:00
|
|
|
metrics.SetHasScrollgrab(true);
|
2013-09-23 23:09:48 +04:00
|
|
|
}
|
|
|
|
|
2014-08-29 16:23:25 +04:00
|
|
|
// Also compute and set the background color.
|
2014-06-07 00:50:20 +04:00
|
|
|
// This is needed for APZ overscrolling support.
|
|
|
|
if (aScrollFrame) {
|
2014-08-07 02:05:11 +04:00
|
|
|
if (isRootScrollFrame) {
|
2014-08-29 16:23:25 +04:00
|
|
|
metrics.SetBackgroundColor(presShell->GetCanvasBackground());
|
2014-08-07 02:05:11 +04:00
|
|
|
} else {
|
|
|
|
nsStyleContext* backgroundStyle;
|
|
|
|
if (nsCSSRendering::FindBackground(aScrollFrame, &backgroundStyle)) {
|
2014-08-29 16:23:25 +04:00
|
|
|
metrics.SetBackgroundColor(backgroundStyle->StyleBackground()->mBackgroundColor);
|
2014-08-07 02:05:11 +04:00
|
|
|
}
|
2014-06-07 00:50:20 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-29 16:23:25 +04:00
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
return metrics;
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
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
|
2015-02-03 18:52:51 +03:00
|
|
|
nsDisplayListBuilder::EnterPresShell(nsIFrame* aReferenceFrame,
|
|
|
|
bool aPointerEventsNoneDoc)
|
2014-09-06 08:16:34 +04:00
|
|
|
{
|
2008-01-04 04:53:01 +03:00
|
|
|
PresShellState* state = mPresShellStates.AppendElement();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-02-03 18:52:51 +03:00
|
|
|
bool pointerEventsNone = aPointerEventsNoneDoc;
|
|
|
|
if (IsInSubdocument()) {
|
|
|
|
pointerEventsNone |= mPresShellStates[mPresShellStates.Length() - 2].mInsidePointerEventsNoneDoc;
|
|
|
|
}
|
|
|
|
state->mInsidePointerEventsNoneDoc = pointerEventsNone;
|
|
|
|
|
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();
|
2014-08-06 09:19:28 +04:00
|
|
|
state->mCaretFrame = caret->GetPaintGeometry(&state->mCaretRect);
|
2008-01-04 04:53:01 +03:00
|
|
|
if (state->mCaretFrame) {
|
2014-08-06 09:19:28 +04:00
|
|
|
mFramesMarkedForDisplay.AppendElement(state->mCaretFrame);
|
|
|
|
MarkFrameForDisplay(state->mCaretFrame, nullptr);
|
2006-04-27 06:45:03 +04:00
|
|
|
}
|
2015-02-02 23:10:51 +03:00
|
|
|
|
|
|
|
nsPresContext* pc = aReferenceFrame->PresContext();
|
|
|
|
pc->GetDocShell()->GetWindowDraggingAllowed(&mWindowDraggingAllowed);
|
2015-02-09 21:24:51 +03:00
|
|
|
mIsInChromePresContext = pc->IsChrome();
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-06 08:16:34 +04:00
|
|
|
nsDisplayListBuilder::LeavePresShell(nsIFrame* aReferenceFrame)
|
|
|
|
{
|
2014-05-20 07:59:14 +04:00
|
|
|
NS_ASSERTION(CurrentPresShellState()->mPresShell ==
|
|
|
|
aReferenceFrame->PresContext()->PresShell(),
|
|
|
|
"Presshell mismatch");
|
2015-02-02 23:10:51 +03:00
|
|
|
|
2013-06-18 13:15:37 +04:00
|
|
|
ResetMarkedFramesForDisplayList();
|
|
|
|
mPresShellStates.SetLength(mPresShellStates.Length() - 1);
|
2015-02-02 23:10:51 +03:00
|
|
|
|
|
|
|
if (!mPresShellStates.IsEmpty()) {
|
|
|
|
nsPresContext* pc = CurrentPresContext();
|
|
|
|
pc->GetDocShell()->GetWindowDraggingAllowed(&mWindowDraggingAllowed);
|
2015-02-09 21:24:51 +03:00
|
|
|
mIsInChromePresContext = pc->IsChrome();
|
2015-02-02 23:10:51 +03:00
|
|
|
}
|
2013-06-18 13:15:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-04-22 00:46:03 +04:00
|
|
|
mFramesMarkedForDisplay.SetCapacity(mFramesMarkedForDisplay.Length() + aFrames.GetLength());
|
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*
|
2014-10-21 19:42:24 +04:00
|
|
|
nsDisplayListBuilder::Allocate(size_t aSize)
|
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
void *tmp;
|
|
|
|
PL_ARENA_ALLOCATE(tmp, &mPool, aSize);
|
2012-11-07 23:55:53 +04:00
|
|
|
if (!tmp) {
|
2014-10-21 19:42:24 +04:00
|
|
|
NS_ABORT_OOM(aSize);
|
2012-11-07 23:55:53 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-22 09:50:11 +04:00
|
|
|
const nsIFrame*
|
|
|
|
nsDisplayListBuilder::FindReferenceFrameFor(const nsIFrame *aFrame,
|
|
|
|
nsPoint* aOffset)
|
|
|
|
{
|
|
|
|
if (aFrame == mCurrentFrame) {
|
|
|
|
if (aOffset) {
|
|
|
|
*aOffset = mCurrentOffsetToReferenceFrame;
|
|
|
|
}
|
|
|
|
return mCurrentReferenceFrame;
|
|
|
|
}
|
|
|
|
for (const nsIFrame* f = aFrame; f; f = nsLayoutUtils::GetCrossDocParentFrame(f))
|
|
|
|
{
|
|
|
|
if (f == mReferenceFrame || f->IsTransformed()) {
|
|
|
|
if (aOffset) {
|
|
|
|
*aOffset = aFrame->GetOffsetToCrossDoc(f);
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aOffset) {
|
|
|
|
*aOffset = aFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
}
|
|
|
|
return mReferenceFrame;
|
|
|
|
}
|
|
|
|
|
2014-11-21 03:58:18 +03:00
|
|
|
// Sticky frames are active if their nearest scrollable frame is also active.
|
|
|
|
static bool
|
|
|
|
IsStickyFrameActive(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aFrame->StyleDisplay()->mPosition == NS_STYLE_POSITION_STICKY);
|
|
|
|
|
|
|
|
// Find the nearest scrollframe.
|
|
|
|
nsIFrame* cursor = aFrame;
|
|
|
|
nsIFrame* parent = aParent;
|
|
|
|
while (parent->GetType() != nsGkAtoms::scrollFrame) {
|
|
|
|
cursor = parent;
|
|
|
|
if ((parent = nsLayoutUtils::GetCrossDocParentFrame(cursor)) == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(parent);
|
|
|
|
return sf->IsScrollingActive(aBuilder) && sf->GetScrolledFrame() == cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayListBuilder::IsAnimatedGeometryRoot(nsIFrame* aFrame, nsIFrame** aParent)
|
|
|
|
{
|
|
|
|
if (nsLayoutUtils::IsPopup(aFrame))
|
|
|
|
return true;
|
|
|
|
if (ActiveLayerTracker::IsOffsetOrMarginStyleAnimated(aFrame))
|
|
|
|
return true;
|
|
|
|
if (!aFrame->GetParent() &&
|
|
|
|
nsLayoutUtils::ViewportHasDisplayPort(aFrame->PresContext())) {
|
|
|
|
// Viewport frames in a display port need to be animated geometry roots
|
|
|
|
// for background-attachment:fixed elements.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* parent = nsLayoutUtils::GetCrossDocParentFrame(aFrame);
|
|
|
|
if (!parent)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsIAtom* parentType = parent->GetType();
|
|
|
|
// Treat the slider thumb as being as an active scrolled root when it wants
|
|
|
|
// its own layer so that it can move without repainting.
|
|
|
|
if (parentType == nsGkAtoms::sliderFrame && nsLayoutUtils::IsScrollbarThumbLayerized(aFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrame->StyleDisplay()->mPosition == NS_STYLE_POSITION_STICKY &&
|
|
|
|
IsStickyFrameActive(this, aFrame, parent))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-08 03:42:40 +03:00
|
|
|
if (parentType == nsGkAtoms::scrollFrame) {
|
2014-11-21 03:58:18 +03:00
|
|
|
nsIScrollableFrame* sf = do_QueryFrame(parent);
|
|
|
|
if (sf->IsScrollingActive(this) && sf->GetScrolledFrame() == aFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed-pos frames are parented by the viewport frame, which has no parent.
|
|
|
|
if (nsLayoutUtils::IsFixedPosFrameInDisplayPort(aFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
*aParent = parent;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-30 17:40:01 +03:00
|
|
|
bool
|
|
|
|
nsDisplayListBuilder::GetCachedAnimatedGeometryRoot(const nsIFrame* aFrame,
|
|
|
|
const nsIFrame* aStopAtAncestor,
|
|
|
|
nsIFrame** aOutResult)
|
|
|
|
{
|
|
|
|
AnimatedGeometryRootLookup lookup(aFrame, aStopAtAncestor);
|
|
|
|
return mAnimatedGeometryRootCache.Get(lookup, aOutResult);
|
|
|
|
}
|
|
|
|
|
2014-11-21 03:58:18 +03:00
|
|
|
static nsIFrame*
|
|
|
|
ComputeAnimatedGeometryRootFor(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
2014-12-30 17:40:01 +03:00
|
|
|
const nsIFrame* aStopAtAncestor = nullptr,
|
|
|
|
bool aUseCache = false)
|
2014-11-21 03:58:18 +03:00
|
|
|
{
|
|
|
|
nsIFrame* cursor = aFrame;
|
|
|
|
while (cursor != aStopAtAncestor) {
|
2014-12-30 17:40:01 +03:00
|
|
|
if (aUseCache) {
|
|
|
|
nsIFrame* result;
|
|
|
|
if (aBuilder->GetCachedAnimatedGeometryRoot(cursor, aStopAtAncestor, &result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 03:58:18 +03:00
|
|
|
nsIFrame* next;
|
|
|
|
if (aBuilder->IsAnimatedGeometryRoot(cursor, &next))
|
|
|
|
return cursor;
|
|
|
|
cursor = next;
|
|
|
|
}
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsDisplayListBuilder::FindAnimatedGeometryRootFor(nsIFrame* aFrame, const nsIFrame* aStopAtAncestor)
|
|
|
|
{
|
|
|
|
if (aFrame == mCurrentFrame) {
|
|
|
|
return mCurrentAnimatedGeometryRoot;
|
|
|
|
}
|
2014-12-30 17:40:01 +03:00
|
|
|
|
|
|
|
nsIFrame* result = ComputeAnimatedGeometryRootFor(this, aFrame, aStopAtAncestor, true);
|
|
|
|
AnimatedGeometryRootLookup lookup(aFrame, aStopAtAncestor);
|
|
|
|
mAnimatedGeometryRootCache.Put(lookup, result);
|
|
|
|
return result;
|
2014-11-21 03:58:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayListBuilder::RecomputeCurrentAnimatedGeometryRoot()
|
|
|
|
{
|
|
|
|
mCurrentAnimatedGeometryRoot = ComputeAnimatedGeometryRootFor(this, const_cast<nsIFrame *>(mCurrentFrame));
|
2014-12-30 17:40:01 +03:00
|
|
|
AnimatedGeometryRootLookup lookup(mCurrentFrame, nullptr);
|
|
|
|
mAnimatedGeometryRootCache.Put(lookup, mCurrentAnimatedGeometryRoot);
|
2014-11-21 03:58:18 +03:00
|
|
|
}
|
|
|
|
|
2014-09-18 12:52:27 +04:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::AdjustWindowDraggingRegion(nsIFrame* aFrame)
|
|
|
|
{
|
2015-02-02 23:10:51 +03:00
|
|
|
if (!mWindowDraggingAllowed || !IsForPainting()) {
|
2014-09-18 12:52:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-23 21:07:51 +03:00
|
|
|
Matrix4x4 referenceFrameToRootReferenceFrame;
|
|
|
|
|
|
|
|
// The const_cast is for nsLayoutUtils::GetTransformToAncestor.
|
|
|
|
nsIFrame* referenceFrame = const_cast<nsIFrame*>(FindReferenceFrameFor(aFrame));
|
|
|
|
|
|
|
|
if (IsInTransform()) {
|
|
|
|
// Only support 2d rectilinear transforms. Transform support is needed for
|
|
|
|
// the horizontal flip transform that's applied to the urlbar textbox in
|
|
|
|
// RTL mode - it should be able to exclude itself from the draggable region.
|
|
|
|
referenceFrameToRootReferenceFrame =
|
|
|
|
nsLayoutUtils::GetTransformToAncestor(referenceFrame, mReferenceFrame);
|
|
|
|
Matrix referenceFrameToRootReferenceFrame2d;
|
|
|
|
if (!referenceFrameToRootReferenceFrame.Is2D(&referenceFrameToRootReferenceFrame2d) ||
|
|
|
|
!referenceFrameToRootReferenceFrame2d.IsRectilinear()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(referenceFrame == mReferenceFrame,
|
|
|
|
"referenceFrameToRootReferenceFrame needs to be adjusted");
|
|
|
|
}
|
|
|
|
|
2014-09-18 12:52:27 +04:00
|
|
|
// We do some basic visibility checking on the frame's border box here.
|
|
|
|
// We intersect it both with the current dirty rect and with the current
|
|
|
|
// clip. Either one is just a conservative approximation on its own, but
|
|
|
|
// their intersection luckily works well enough for our purposes, so that
|
|
|
|
// we don't have to do full-blown visibility computations.
|
|
|
|
// The most important case we need to handle is the scrolled-off tab:
|
|
|
|
// If the tab bar overflows, tab parts that are clipped by the scrollbox
|
|
|
|
// should not be allowed to interfere with the window dragging region. Using
|
|
|
|
// just the current DisplayItemClip is not enough to cover this case
|
|
|
|
// completely because clips are reset while building stacking context
|
|
|
|
// contents, so for example we'd fail to clip frames that have a clip path
|
|
|
|
// applied to them. But the current dirty rect doesn't get reset in that
|
|
|
|
// case, so we use it to make this case work.
|
|
|
|
nsRect borderBox = aFrame->GetRectRelativeToSelf().Intersect(mDirtyRect);
|
|
|
|
borderBox += ToReferenceFrame(aFrame);
|
|
|
|
const DisplayItemClip* clip = ClipState().GetCurrentCombinedClip(this);
|
|
|
|
if (clip) {
|
|
|
|
borderBox = clip->ApplyNonRoundedIntersection(borderBox);
|
|
|
|
}
|
|
|
|
if (!borderBox.IsEmpty()) {
|
2015-01-23 21:07:51 +03:00
|
|
|
LayoutDeviceRect devPixelBorderBox =
|
|
|
|
LayoutDevicePixel::FromAppUnits(borderBox, aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
LayoutDeviceRect transformedDevPixelBorderBox =
|
|
|
|
TransformTo<LayoutDevicePixel>(referenceFrameToRootReferenceFrame, devPixelBorderBox);
|
|
|
|
transformedDevPixelBorderBox.Round();
|
|
|
|
LayoutDeviceIntRect transformedDevPixelBorderBoxInt;
|
|
|
|
if (transformedDevPixelBorderBox.ToIntRect(&transformedDevPixelBorderBoxInt)) {
|
|
|
|
const nsStyleUserInterface* styleUI = aFrame->StyleUserInterface();
|
|
|
|
if (styleUI->mWindowDragging == NS_STYLE_WINDOW_DRAGGING_DRAG) {
|
|
|
|
mWindowDraggingRegion.OrWith(LayoutDevicePixel::ToUntyped(transformedDevPixelBorderBoxInt));
|
|
|
|
} else {
|
|
|
|
mWindowDraggingRegion.SubOut(LayoutDevicePixel::ToUntyped(transformedDevPixelBorderBoxInt));
|
|
|
|
}
|
2014-09-18 12:52:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 05:54:32 +04:00
|
|
|
void
|
|
|
|
nsDisplayListBuilder::AddToWillChangeBudget(nsIFrame* aFrame, const nsSize& aRect) {
|
2014-10-22 05:55:55 +04:00
|
|
|
// Make sure that we don't query the budget before the display list is fully
|
|
|
|
// built and that the will change budget is locked in.
|
2015-01-10 00:29:43 +03:00
|
|
|
NS_ASSERTION(!mWillChangeBudgetCalculated,
|
|
|
|
"Can't modify the budget once it's been used.");
|
2014-10-22 05:55:55 +04:00
|
|
|
|
2014-10-22 05:54:32 +04:00
|
|
|
DocumentWillChangeBudget budget;
|
|
|
|
|
|
|
|
nsPresContext* key = aFrame->PresContext();
|
|
|
|
if (mWillChangeBudget.Contains(key)) {
|
|
|
|
mWillChangeBudget.Get(key, &budget);
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's significant overhead for each layer created from Gecko
|
|
|
|
// (IPC+Shared Objects) and from the backend (like an OpenGL texture).
|
|
|
|
// Therefore we set a minimum cost threshold of a 64x64 area.
|
|
|
|
int minBudgetCost = 64 * 64;
|
|
|
|
|
|
|
|
budget.mBudget +=
|
|
|
|
std::max(minBudgetCost,
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.width) *
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(aRect.height));
|
|
|
|
|
|
|
|
mWillChangeBudget.Put(key, budget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayListBuilder::IsInWillChangeBudget(nsIFrame* aFrame) const {
|
2014-11-22 08:35:20 +03:00
|
|
|
uint32_t multiplier = 3;
|
|
|
|
|
2014-10-22 05:55:55 +04:00
|
|
|
mWillChangeBudgetCalculated = true;
|
|
|
|
|
2014-10-22 05:54:32 +04:00
|
|
|
nsPresContext* key = aFrame->PresContext();
|
|
|
|
if (!mWillChangeBudget.Contains(key)) {
|
2015-01-10 00:29:43 +03:00
|
|
|
NS_ASSERTION(false, "If we added nothing to our budget then this "
|
|
|
|
"shouldn't be called.");
|
2014-10-22 05:54:32 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DocumentWillChangeBudget budget;
|
|
|
|
mWillChangeBudget.Get(key, &budget);
|
|
|
|
|
|
|
|
nsRect area = aFrame->PresContext()->GetVisibleArea();
|
|
|
|
uint32_t budgetLimit = nsPresContext::AppUnitsToIntCSSPixels(area.width) *
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(area.height);
|
|
|
|
|
2014-11-22 08:35:20 +03:00
|
|
|
bool onBudget = budget.mBudget / multiplier < budgetLimit;
|
|
|
|
if (!onBudget) {
|
|
|
|
nsString usageStr;
|
|
|
|
usageStr.AppendInt(budget.mBudget);
|
|
|
|
|
|
|
|
nsString multiplierStr;
|
|
|
|
multiplierStr.AppendInt(multiplier);
|
|
|
|
|
|
|
|
nsString limitStr;
|
|
|
|
limitStr.AppendInt(budgetLimit);
|
|
|
|
|
|
|
|
const char16_t* params[] = { usageStr.get(), multiplierStr.get(), limitStr.get() };
|
|
|
|
key->Document()->WarnOnceAbout(nsIDocument::eWillChangeBudget, false,
|
|
|
|
params, ArrayLength(params));
|
|
|
|
}
|
|
|
|
return onBudget;
|
2014-10-22 05:54:32 +04:00
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2014-06-09 08:48:02 +04:00
|
|
|
static void
|
|
|
|
MoveListTo(nsDisplayList* aList, nsTArray<nsDisplayItem*>* aElements) {
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayItem* item;
|
2014-06-09 08:48:02 +04:00
|
|
|
while ((item = aList->RemoveBottom()) != nullptr) {
|
|
|
|
aElements->AppendElement(item);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-15 15:47:46 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayList::GetVisibleRect() const {
|
|
|
|
nsRect result;
|
|
|
|
for (nsDisplayItem* i = GetBottom(); i != nullptr; i = i->GetAbove()) {
|
|
|
|
result.UnionRect(result, i->GetVisibleRect());
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-28 03:15:08 +04:00
|
|
|
nsDisplayList::ComputeVisibilityForRoot(nsDisplayListBuilder* aBuilder,
|
2014-03-18 03:39:59 +04:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
nsIFrame* aDisplayPortFrame) {
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsDisplayList", "ComputeVisibilityForRoot",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
r.GetBounds(), aDisplayPortFrame);
|
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);
|
2014-12-11 11:37:02 +03:00
|
|
|
if (aBuilder->IsForPluginGeometry() &&
|
|
|
|
aItem->GetType() != nsDisplayItem::TYPE_LAYER_EVENT_REGIONS)
|
|
|
|
{
|
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,
|
2014-03-18 03:39:59 +04:00
|
|
|
nsIFrame* aDisplayPortFrame) {
|
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
|
|
|
|
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;
|
2014-06-09 08:48:02 +04:00
|
|
|
MoveListTo(this, &elements);
|
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];
|
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
|
|
|
|
2014-06-23 08:24:51 +04:00
|
|
|
if (item->ComputeVisibility(aBuilder, aVisibleRegion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
anyVisible = true;
|
2014-03-18 03:39:59 +04:00
|
|
|
|
2014-06-06 15:00:34 +04:00
|
|
|
nsRegion opaque = TreatAsOpaque(item, aBuilder);
|
2014-06-09 08:48:02 +04:00
|
|
|
// Subtract opaque item from the visible region
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, opaque);
|
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
|
|
|
|
2014-06-11 16:09:13 +04:00
|
|
|
mIsOpaque = !aVisibleRegion->Intersects(aListVisibleBounds);
|
2010-07-16 01:08:09 +04:00
|
|
|
return anyVisible;
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2014-12-22 03:35:41 +03:00
|
|
|
static bool
|
2015-03-27 09:56:45 +03:00
|
|
|
TriggerPendingAnimationsOnSubDocuments(nsIDocument* aDocument, void* aReadyTime)
|
2014-12-22 03:35:41 +03:00
|
|
|
{
|
|
|
|
PendingPlayerTracker* tracker = aDocument->GetPendingPlayerTracker();
|
|
|
|
if (tracker) {
|
|
|
|
nsIPresShell* shell = aDocument->GetShell();
|
|
|
|
// If paint-suppression is in effect then we haven't finished painting
|
|
|
|
// this document yet so we shouldn't start animations
|
|
|
|
if (!shell || !shell->IsPaintingSuppressed()) {
|
2015-01-09 01:57:58 +03:00
|
|
|
const TimeStamp& readyTime = *static_cast<TimeStamp*>(aReadyTime);
|
2015-03-27 09:56:45 +03:00
|
|
|
tracker->TriggerPendingPlayersOnNextTick(readyTime);
|
2014-12-22 03:35:41 +03:00
|
|
|
}
|
|
|
|
}
|
2015-03-27 09:56:45 +03:00
|
|
|
aDocument->EnumerateSubDocuments(TriggerPendingAnimationsOnSubDocuments,
|
2014-12-22 03:35:41 +03:00
|
|
|
aReadyTime);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-03-27 09:56:45 +03:00
|
|
|
TriggerPendingAnimations(nsIDocument* aDocument,
|
2014-12-22 03:35:41 +03:00
|
|
|
const TimeStamp& aReadyTime) {
|
|
|
|
MOZ_ASSERT(!aReadyTime.IsNull(),
|
|
|
|
"Animation ready time is not set. Perhaps we're using a layer"
|
|
|
|
" manager that doesn't update it");
|
2015-03-27 09:56:45 +03:00
|
|
|
TriggerPendingAnimationsOnSubDocuments(aDocument,
|
|
|
|
const_cast<TimeStamp*>(&aReadyTime));
|
2014-12-22 03:35:41 +03:00
|
|
|
}
|
|
|
|
|
2014-10-21 01:32:09 +04: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 PaintedLayers.
|
|
|
|
*/
|
2014-10-21 01:32:10 +04:00
|
|
|
already_AddRefed<LayerManager> nsDisplayList::PaintRoot(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx,
|
|
|
|
uint32_t aFlags) {
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsDisplayList", "PaintRoot",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
2010-03-10 23:55:05 +03:00
|
|
|
|
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");
|
2014-10-21 01:32:10 +04:00
|
|
|
return nullptr;
|
2010-03-01 11:03:49 +03:00
|
|
|
}
|
2014-06-19 22:22:17 +04:00
|
|
|
layerManager = new BasicLayerManager(BasicLayerManager::BLM_OFFSCREEN);
|
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
|
|
|
|
2014-01-30 09:41:17 +04:00
|
|
|
if (aFlags & PAINT_COMPRESSED) {
|
|
|
|
layerBuilder->SetLayerTreeCompressionMode();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-10-21 01:32:09 +04:00
|
|
|
nsIFrame* frame = aBuilder->RootReferenceFrame();
|
|
|
|
nsPresContext* presContext = frame->PresContext();
|
2011-06-22 16:11:27 +04:00
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
2015-03-02 14:01:58 +03:00
|
|
|
nsRootPresContext* rootPresContext = presContext->GetRootPresContext();
|
2011-06-22 16:11:27 +04:00
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
NotifySubDocInvalidationFunc computeInvalidFunc =
|
|
|
|
presContext->MayHavePaintEventListenerInSubDocument() ? nsPresContext::NotifySubDocInvalidation : 0;
|
|
|
|
bool computeInvalidRect = (computeInvalidFunc ||
|
2014-02-25 02:45:40 +04:00
|
|
|
(!layerManager->IsCompositingCheap() && layerManager->NeedsWidgetInvalidation())) &&
|
2012-08-29 09:47:18 +04:00
|
|
|
widgetTransaction;
|
|
|
|
|
2014-08-25 19:09:39 +04:00
|
|
|
UniquePtr<LayerProperties> props;
|
|
|
|
if (computeInvalidRect) {
|
|
|
|
props = Move(LayerProperties::CloneFrom(layerManager->GetRoot()));
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2013-09-27 10:01:16 +04:00
|
|
|
ContainerLayerParameters containerParameters
|
2015-03-07 02:07:59 +03:00
|
|
|
(presShell->GetResolution(), presShell->GetResolution());
|
2012-07-17 21:03:51 +04:00
|
|
|
nsRefPtr<ContainerLayer> root = layerBuilder->
|
2014-10-21 01:32:09 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, layerManager, frame, nullptr, this,
|
2012-07-30 18:20:58 +04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2012-07-17 21:03:51 +04:00
|
|
|
if (!root) {
|
2012-10-23 15:01:23 +04:00
|
|
|
layerManager->SetUserData(&gLayerManagerLayerBuilder, oldBuilder);
|
2014-10-21 01:32:10 +04:00
|
|
|
return nullptr;
|
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);
|
2015-01-03 04:06:14 +03:00
|
|
|
root->SetScaleToResolution(presShell->ScaleToResolution(),
|
|
|
|
containerParameters.mXScale);
|
2015-02-17 05:30:02 +03:00
|
|
|
if (aBuilder->IsBuildingLayerEventRegions() &&
|
|
|
|
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(presShell)) {
|
|
|
|
root->SetEventRegionsOverride(EventRegionsOverride::ForceDispatchToContent);
|
2015-02-25 21:36:19 +03:00
|
|
|
} else {
|
|
|
|
root->SetEventRegionsOverride(EventRegionsOverride::NoOverride);
|
2015-02-17 05:30:02 +03:00
|
|
|
}
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2015-02-13 04:49:10 +03:00
|
|
|
// If we're using containerless scrolling, there is still one case where we
|
|
|
|
// want the root container layer to have metrics. If the parent process is
|
|
|
|
// using XUL windows, there is no root scrollframe, and without explicitly
|
|
|
|
// creating metrics there will be no guaranteed top-level APZC.
|
|
|
|
if (gfxPrefs::LayoutUseContainersForRootFrames() ||
|
|
|
|
(XRE_IsParentProcess() && !presShell->GetRootScrollFrame()))
|
|
|
|
{
|
2014-12-18 02:37:28 +03:00
|
|
|
bool isRoot = presContext->IsRootContentDocument();
|
2010-09-04 00:10:46 +04:00
|
|
|
|
2015-02-16 08:22:56 +03:00
|
|
|
nsRect viewport(aBuilder->ToReferenceFrame(frame), frame->GetSize());
|
2015-02-13 04:49:10 +03:00
|
|
|
|
2015-02-13 04:49:10 +03:00
|
|
|
nsIFrame* scrollFrame = presShell->GetRootScrollFrame();
|
|
|
|
nsIContent* content = nullptr;
|
|
|
|
if (scrollFrame) {
|
|
|
|
content = scrollFrame->GetContent();
|
|
|
|
} else if (!gfxPrefs::LayoutUseContainersForRootFrames()) {
|
|
|
|
// If there is no root scroll frame, and we're using containerless
|
|
|
|
// scrolling, pick the document element instead.
|
|
|
|
content = document->GetDocumentElement();
|
|
|
|
}
|
|
|
|
|
2014-12-18 02:37:28 +03:00
|
|
|
root->SetFrameMetrics(
|
2015-02-13 04:49:10 +03:00
|
|
|
nsDisplayScrollLayer::ComputeFrameMetrics(frame,
|
|
|
|
presShell->GetRootScrollFrame(),
|
|
|
|
content,
|
2014-12-18 02:37:28 +03:00
|
|
|
aBuilder->FindReferenceFrameFor(frame),
|
|
|
|
root, FrameMetrics::NULL_SCROLL_ID, viewport,
|
2015-01-28 21:28:28 +03:00
|
|
|
isRoot, containerParameters));
|
2014-12-18 02:37:28 +03:00
|
|
|
}
|
2014-07-23 01:01:50 +04:00
|
|
|
|
|
|
|
// NS_WARNING is debug-only, so don't even bother checking the conditions in
|
|
|
|
// a release build.
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool usingDisplayport = false;
|
2014-12-18 02:37:28 +03:00
|
|
|
if (nsIFrame* rootScrollFrame = presShell->GetRootScrollFrame()) {
|
2014-07-23 01:01:50 +04:00
|
|
|
nsIContent* content = rootScrollFrame->GetContent();
|
|
|
|
if (content) {
|
|
|
|
usingDisplayport = nsLayoutUtils::GetDisplayPort(content, nullptr);
|
|
|
|
}
|
|
|
|
}
|
2011-10-23 12:57:47 +04:00
|
|
|
if (usingDisplayport &&
|
2014-07-23 01:01:50 +04:00
|
|
|
!(root->GetContentFlags() & Layer::CONTENT_OPAQUE) &&
|
|
|
|
SpammyLayoutWarningsEnabled()) {
|
2011-10-23 12:57:47 +04:00
|
|
|
// See bug 693938, attachment 567017
|
2014-02-09 09:28:04 +04:00
|
|
|
NS_WARNING("Transparent content with displayports can be expensive.");
|
2011-10-23 12:57:47 +04:00
|
|
|
}
|
2014-07-23 01:01:50 +04:00
|
|
|
#endif
|
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();
|
2014-07-23 10:03:24 +04:00
|
|
|
|
|
|
|
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())) {
|
2014-10-21 01:32:09 +04:00
|
|
|
frame->ClearInvalidationStateBits();
|
2014-07-23 10:03:24 +04:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 14:01:58 +03:00
|
|
|
// If this is the content process, we ship plugin geometry updates over with layer
|
|
|
|
// updates, so calculate that now before we call EndTransaction.
|
|
|
|
if (rootPresContext &&
|
|
|
|
aBuilder->WillComputePluginGeometry() &&
|
|
|
|
XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
rootPresContext->ComputePluginGeometryUpdates(aBuilder->RootReferenceFrame(), aBuilder, this);
|
|
|
|
rootPresContext->CollectPluginGeometryUpdates(layerManager);
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:43:39 +04:00
|
|
|
MaybeSetupTransactionIdAllocator(layerManager, view);
|
|
|
|
|
2014-09-26 21:06:08 +04:00
|
|
|
layerManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer,
|
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
|
|
|
|
2015-02-03 08:08:37 +03:00
|
|
|
if (document && widgetTransaction) {
|
2015-03-27 09:56:45 +03:00
|
|
|
TriggerPendingAnimations(document, layerManager->GetAnimationReadyTime());
|
2014-12-22 03:35:41 +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);
|
2014-10-21 01:32:10 +04:00
|
|
|
return layerManager.forget();
|
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
|
|
|
}
|
2014-05-25 02:20:41 +04:00
|
|
|
frame = nsBox::GetParentBox(frame);
|
2010-11-30 17:59:46 +03:00
|
|
|
}
|
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
|
|
|
|
{
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit FramesWithDepth(float aDepth) :
|
2011-10-07 01:24:02 +04:00
|
|
|
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();
|
|
|
|
}
|
2014-02-04 03:25:23 +04:00
|
|
|
temp.AppendElement(FramesWithDepth(transform->GetHitDepthAtPoint(aBuilder, point)));
|
2011-10-12 07:16:05 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
static bool IsCSSOrderLEQ(nsDisplayItem* aItem1, nsDisplayItem* aItem2, void*) {
|
|
|
|
nsIFrame* frame1 = aItem1->Frame();
|
|
|
|
nsIFrame* frame2 = aItem2->Frame();
|
|
|
|
int32_t order1 = frame1 ? frame1->StylePosition()->mOrder : 0;
|
|
|
|
int32_t order2 = frame2 ? frame2->StylePosition()->mOrder : 0;
|
|
|
|
return order1 <= order2;
|
|
|
|
}
|
|
|
|
|
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.
|
2014-03-20 06:12:46 +04:00
|
|
|
return aItem1->ZIndex() <= aItem2->ZIndex();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2015-03-28 23:50:35 +03:00
|
|
|
void nsDisplayList::SortByZOrder(nsDisplayListBuilder* aBuilder) {
|
|
|
|
Sort(aBuilder, IsZOrderLEQ, nullptr);
|
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
|
|
|
}
|
|
|
|
|
2015-03-26 21:57:39 +03:00
|
|
|
void nsDisplayList::SortByCSSOrder(nsDisplayListBuilder* aBuilder) {
|
|
|
|
Sort(aBuilder, IsCSSOrderLEQ, nullptr);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-07-22 09:50:11 +04:00
|
|
|
nsDisplayItem::nsDisplayItem(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
, mClip(aBuilder->ClipState().GetCurrentCombinedClip(aBuilder))
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
, mPainted(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
mReferenceFrame = aBuilder->FindReferenceFrameFor(aFrame, &mToReferenceFrame);
|
|
|
|
NS_ASSERTION(aBuilder->GetDirtyRect().width >= 0 ||
|
|
|
|
!aBuilder->IsForPainting(), "dirty rect not set");
|
|
|
|
// The dirty rect is for mCurrentFrame, so we have to use
|
|
|
|
// mCurrentOffsetToReferenceFrame
|
|
|
|
mVisibleRect = aBuilder->GetDirtyRect() +
|
|
|
|
aBuilder->GetCurrentFrameOffsetToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-20 06:12:46 +04:00
|
|
|
int32_t
|
|
|
|
nsDisplayItem::ZIndex() const
|
|
|
|
{
|
2015-03-12 06:21:01 +03:00
|
|
|
if (!mFrame->IsAbsPosContaininingBlock() && !mFrame->IsFlexOrGridItem())
|
2014-03-20 06:12:46 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
const nsStylePosition* position = mFrame->StylePosition();
|
|
|
|
if (position->mZIndex.GetUnit() == eStyleUnit_Integer)
|
|
|
|
return position->mZIndex.GetIntValue();
|
|
|
|
|
|
|
|
// sort the auto and 0 elements together
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:48:16 +04:00
|
|
|
bool
|
|
|
|
nsDisplayItem::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion)
|
2014-06-03 16:48:16 +04:00
|
|
|
{
|
|
|
|
return !mVisibleRect.IsEmpty() &&
|
|
|
|
!IsInvisibleInRect(aVisibleRegion->GetBounds());
|
|
|
|
}
|
|
|
|
|
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).
|
2014-06-23 08:24:51 +04:00
|
|
|
if (!ComputeVisibility(aBuilder, aVisibleRegion)) {
|
2014-06-20 09:24:31 +04:00
|
|
|
mVisibleRect = nsRect();
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2014-06-20 09:24:31 +04:00
|
|
|
}
|
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)
|
|
|
|
{
|
2014-10-19 16:22:22 +04:00
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
2014-10-22 15:29:06 +04:00
|
|
|
Rect rect =
|
|
|
|
NSRectToSnappedRect(mVisibleRect, appUnitsPerDevPixel, *drawTarget);
|
2014-10-19 16:22:22 +04:00
|
|
|
drawTarget->FillRect(rect, ColorPattern(ToDeviceColor(mColor)));
|
2009-04-25 12:19:23 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 02:07:08 +04:00
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplaySolidColor::WriteDebugInfo(std::stringstream& aStream)
|
2014-01-27 02:07:08 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
aStream << " (rgba "
|
|
|
|
<< (int)NS_GET_R(mColor) << ","
|
|
|
|
<< (int)NS_GET_G(mColor) << ","
|
|
|
|
<< (int)NS_GET_B(mColor) << ","
|
|
|
|
<< (int)NS_GET_A(mColor) << ")";
|
2014-01-27 02:07:08 +04:00
|
|
|
}
|
|
|
|
|
2010-07-24 13:35:29 +04:00
|
|
|
static void
|
2015-02-05 01:25:18 +03:00
|
|
|
RegisterThemeGeometry(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsITheme::ThemeGeometryType aType)
|
2010-07-24 13:35:29 +04:00
|
|
|
{
|
2015-02-09 21:24:51 +03:00
|
|
|
if (aBuilder->IsInRootChromeDocumentOrPopup() && !aBuilder->IsInTransform()) {
|
2014-09-18 12:52:27 +04:00
|
|
|
nsIFrame* displayRoot = nsLayoutUtils::GetDisplayRootFrame(aFrame);
|
|
|
|
nsRect borderBox(aFrame->GetOffsetTo(displayRoot), aFrame->GetSize());
|
2015-02-05 01:25:18 +03:00
|
|
|
aBuilder->RegisterThemeGeometry(aType,
|
2014-09-18 12:52:27 +04: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;
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:22:17 +04:00
|
|
|
/* static */ void
|
|
|
|
SetBackgroundClipRegion(DisplayListClipState::AutoSaveRestore& aClipState,
|
|
|
|
nsIFrame* aFrame, const nsPoint& aToReferenceFrame,
|
|
|
|
const nsStyleBackground::Layer& aLayer,
|
|
|
|
bool aWillPaintBorder)
|
|
|
|
{
|
|
|
|
nsRect borderBox = nsRect(aToReferenceFrame, aFrame->GetSize());
|
|
|
|
|
|
|
|
nsCSSRendering::BackgroundClipState clip;
|
|
|
|
nsCSSRendering::GetBackgroundClip(aLayer, aFrame, *aFrame->StyleBorder(),
|
|
|
|
borderBox, borderBox, aWillPaintBorder,
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
&clip);
|
|
|
|
|
|
|
|
if (clip.mHasAdditionalBGClipArea) {
|
|
|
|
aClipState.ClipContentDescendants(clip.mAdditionalBGClipArea, clip.mBGClipArea,
|
|
|
|
clip.mHasRoundedCorners ? clip.mRadii : nullptr);
|
|
|
|
} else {
|
|
|
|
aClipState.ClipContentDescendants(clip.mBGClipArea, clip.mHasRoundedCorners ? clip.mRadii : nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2015-01-20 12:42:29 +03:00
|
|
|
// Dummy initialisation to keep Valgrind/Memcheck happy.
|
|
|
|
// See bug 1122375 comment 1.
|
|
|
|
nscolor color = NS_RGBA(0,0,0,0);
|
2012-10-25 09:32:25 +04:00
|
|
|
if (!nsCSSRendering::IsCanvasFrame(aFrame) && bg) {
|
|
|
|
bool drawBackgroundImage;
|
|
|
|
color =
|
|
|
|
nsCSSRendering::DetermineBackgroundColor(presContext, bgSC, aFrame,
|
|
|
|
drawBackgroundImage, drawBackgroundColor);
|
|
|
|
}
|
|
|
|
|
2014-11-12 10:53:03 +03:00
|
|
|
const nsStyleBorder* borderStyle = aFrame->StyleBorder();
|
|
|
|
bool hasInsetShadow = borderStyle->mBoxShadow &&
|
|
|
|
borderStyle->mBoxShadow->HasShadowWithInset(true);
|
2014-07-23 09:22:17 +04:00
|
|
|
bool willPaintBorder = !isThemed && !hasInsetShadow &&
|
2014-11-12 10:53:03 +03:00
|
|
|
borderStyle->HasBorder();
|
2014-07-23 09:22:17 +04:00
|
|
|
|
|
|
|
nsPoint toRef = aBuilder->ToReferenceFrame(aFrame);
|
|
|
|
|
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()) {
|
2014-07-23 09:22:17 +04:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
|
|
|
if (bg && !aBuilder->IsForEventDelivery()) {
|
2014-11-12 10:53:03 +03:00
|
|
|
// Disable the will-paint-border optimization for background
|
|
|
|
// colors with no border-radius. Enabling it for background colors
|
|
|
|
// doesn't help much (there are no tiling issues) and clipping the
|
|
|
|
// background breaks detection of the element's border-box being
|
|
|
|
// opaque. For nonzero border-radius we still need it because we
|
|
|
|
// want to inset the background if possible to avoid antialiasing
|
|
|
|
// artifacts along the rounded corners.
|
|
|
|
bool useWillPaintBorderOptimization = willPaintBorder &&
|
|
|
|
nsLayoutUtils::HasNonZeroCorner(borderStyle->mBorderRadius);
|
2014-07-23 09:22:17 +04:00
|
|
|
SetBackgroundClipRegion(clipState, aFrame, toRef,
|
|
|
|
bg->BottomLayer(),
|
2014-11-12 10:53:03 +03:00
|
|
|
useWillPaintBorderOptimization);
|
2014-07-23 09:22:17 +04:00
|
|
|
}
|
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) {
|
2014-08-20 19:26:11 +04:00
|
|
|
nsITheme* theme = presContext->GetTheme();
|
2015-02-02 23:10:53 +03:00
|
|
|
if (theme->NeedToClearBackgroundBehindWidget(aFrame->StyleDisplay()->mAppearance) &&
|
2015-02-09 21:24:51 +03:00
|
|
|
aBuilder->IsInRootChromeDocumentOrPopup() && !aBuilder->IsInTransform()) {
|
2014-08-20 19:26:11 +04:00
|
|
|
bgItemList.AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayClearBackground(aBuilder, aFrame));
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:22:17 +04:00
|
|
|
DisplayListClipState::AutoSaveRestore clipState(aBuilder);
|
|
|
|
if (!aBuilder->IsForEventDelivery()) {
|
|
|
|
const nsStyleBackground::Layer& layer = bg->mLayers[i];
|
|
|
|
SetBackgroundClipRegion(clipState, aFrame, toRef,
|
|
|
|
layer, willPaintBorder);
|
|
|
|
}
|
|
|
|
|
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 =
|
2014-05-05 21:55:54 +04:00
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext, mFrame, flags,
|
|
|
|
borderArea, aClipRect, layer);
|
2012-07-23 07:00:36 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:25 +04:00
|
|
|
bool
|
|
|
|
nsDisplayBackgroundImage::ShouldFixToViewport(LayerManager* aManager)
|
|
|
|
{
|
|
|
|
// APZ doesn't (yet) know how to scroll the visible region for these type of
|
|
|
|
// items, so don't layerize them if it's enabled.
|
|
|
|
if (nsLayoutUtils::UsesAsyncScrolling() ||
|
|
|
|
(aManager && aManager->ShouldAvoidComponentAlphaLayers())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put background-attachment:fixed background images in their own
|
|
|
|
// compositing layer, unless we have APZ enabled
|
|
|
|
return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
|
|
|
|
!mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
|
|
|
|
}
|
|
|
|
|
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 =
|
2014-05-05 21:55:54 +04:00
|
|
|
nsCSSRendering::PrepareBackgroundLayer(presContext, mFrame, flags,
|
|
|
|
borderArea, borderArea, 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();
|
2015-04-08 04:55:28 +03:00
|
|
|
mDestRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(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
|
|
|
|
2015-04-08 04:55:28 +03:00
|
|
|
const LayerRect destLayerRect = mDestRect * aParameters.Scale();
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2013-05-30 17:50:50 +04:00
|
|
|
// Calculate the scaling factor for the frame.
|
2015-04-08 04:55:28 +03:00
|
|
|
const gfxSize scale = gfxSize(destLayerRect.width / imageSize.width,
|
|
|
|
destLayerRect.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.
|
2015-04-08 04:55:28 +03:00
|
|
|
if (destLayerRect.width * destLayerRect.height < 64 * 64) {
|
2013-05-30 17:50:50 +04:00
|
|
|
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);
|
2015-04-08 04:55:28 +03:00
|
|
|
ConfigureLayer(layer, aParameters);
|
2012-05-04 00:13:12 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-08 04:55:28 +03:00
|
|
|
nsDisplayBackgroundImage::ConfigureLayer(ImageLayer* aLayer,
|
|
|
|
const ContainerLayerParameters& aParameters)
|
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!");
|
2015-02-10 10:27:39 +03:00
|
|
|
if (imageSize.width > 0 && imageSize.height > 0) {
|
|
|
|
// We're actually using the ImageContainer. Let our frame know that it
|
|
|
|
// should consider itself to have painted successfully.
|
|
|
|
nsDisplayBackgroundGeometry::UpdateDrawResult(this, DrawResult::SUCCESS);
|
|
|
|
}
|
2012-05-04 00:13:12 +04:00
|
|
|
|
2015-04-08 04:55:28 +03:00
|
|
|
// XXX(seth): Right now we ignore aParameters.Scale() and
|
|
|
|
// aParameters.Offset(), because FrameLayerBuilder already applies
|
|
|
|
// aParameters.Scale() via the layer's post-transform, and
|
|
|
|
// aParameters.Offset() is always zero.
|
|
|
|
MOZ_ASSERT(aParameters.Offset() == LayerIntPoint(0,0));
|
|
|
|
|
|
|
|
const LayoutDevicePoint p = mDestRect.TopLeft();
|
2014-09-10 17:26:12 +04:00
|
|
|
Matrix transform = Matrix::Translation(p.x, p.y);
|
2014-09-10 21:29:35 +04:00
|
|
|
transform.PreScale(mDestRect.width / imageSize.width,
|
|
|
|
mDestRect.height / imageSize.height);
|
2014-01-27 19:28:33 +04:00
|
|
|
aLayer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
|
2012-05-04 00:13:12 +04:00
|
|
|
}
|
|
|
|
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion)
|
2010-07-16 01:08:06 +04:00
|
|
|
{
|
2014-06-23 08:24:51 +04:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion)) {
|
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
|
|
|
nsRect clipRect;
|
2014-05-05 12:27:38 +04:00
|
|
|
if (frame->GetType() == nsGkAtoms::canvasFrame) {
|
|
|
|
nsCanvasFrame* canvasFrame = static_cast<nsCanvasFrame*>(frame);
|
|
|
|
clipRect = canvasFrame->CanvasArea() + aItem->ToReferenceFrame();
|
|
|
|
} else {
|
|
|
|
switch (aClip) {
|
|
|
|
case NS_STYLE_BG_CLIP_BORDER:
|
|
|
|
clipRect = nsRect(aItem->ToReferenceFrame(), frame->GetSize());
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_PADDING:
|
|
|
|
clipRect = frame->GetPaddingRect() - frame->GetPosition() + aItem->ToReferenceFrame();
|
|
|
|
break;
|
|
|
|
case NS_STYLE_BG_CLIP_CONTENT:
|
2014-09-12 01:29:59 +04:00
|
|
|
clipRect = frame->GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2014-05-05 12:27:38 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown clip type");
|
|
|
|
return result;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:22:17 +04:00
|
|
|
return clipRect.Intersect(aRect);
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2014-05-05 21:55:54 +04:00
|
|
|
// For NS_STYLE_BOX_DECORATION_BREAK_SLICE, don't try to optimize here, since
|
2011-01-03 04:48:09 +03:00
|
|
|
// 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.
|
2014-05-05 21:55:54 +04:00
|
|
|
if (mFrame->StyleBorder()->mBoxDecorationBreak ==
|
|
|
|
NS_STYLE_BOX_DECORATION_BREAK_CLONE ||
|
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
|
|
|
}
|
|
|
|
|
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()),
|
2014-05-05 21:55:54 +04:00
|
|
|
mBackgroundStyle->mLayers[mLayer],
|
2012-11-08 19:05:32 +04:00
|
|
|
&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) {
|
2014-07-23 09:22:17 +04:00
|
|
|
PaintInternal(aBuilder, aCtx, mVisibleRect, &mBounds);
|
2012-12-13 05:15:55 +04:00
|
|
|
}
|
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
|
|
|
|
2015-02-10 10:27:39 +03:00
|
|
|
DrawResult result =
|
|
|
|
nsCSSRendering::PaintBackground(mFrame->PresContext(), *aCtx, mFrame,
|
|
|
|
aBounds,
|
|
|
|
nsRect(offset, mFrame->GetSize()),
|
|
|
|
flags, aClipRect, mLayer);
|
2012-12-13 05:15:55 +04:00
|
|
|
|
2015-02-10 10:27:39 +03:00
|
|
|
nsDisplayBackgroundGeometry::UpdateDrawResult(this, result);
|
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);
|
2014-04-24 06:56:15 +04:00
|
|
|
|
|
|
|
if (positioningArea.Size() != geometry->mPositioningArea.Size()) {
|
|
|
|
NotifyRenderingChanged();
|
|
|
|
}
|
2012-11-08 19:05:32 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-06-26 20:43:27 +04:00
|
|
|
if (aBuilder->ShouldSyncDecodeImages()) {
|
2015-02-10 10:27:39 +03:00
|
|
|
const nsStyleImage& image = mBackgroundStyle->mLayers[mLayer].mImage;
|
|
|
|
if (image.GetType() == eStyleImageType_Image &&
|
|
|
|
geometry->ShouldInvalidateToSyncDecodeImages()) {
|
2013-06-26 20:43:27 +04:00
|
|
|
aInvalidRegion->Or(*aInvalidRegion, bounds);
|
2014-04-24 06:56:15 +04:00
|
|
|
|
|
|
|
NotifyRenderingChanged();
|
2013-06-26 20:43:27 +04:00
|
|
|
}
|
|
|
|
}
|
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);
|
2014-04-24 06:56:15 +04:00
|
|
|
|
|
|
|
NotifyRenderingChanged();
|
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,
|
2014-05-05 21:55:54 +04:00
|
|
|
borderBox, clipRect, layer,
|
2013-06-04 08:49:03 +04:00
|
|
|
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
|
2015-02-05 01:25:18 +03:00
|
|
|
nsITheme* theme = mFrame->PresContext()->GetTheme();
|
|
|
|
nsITheme::ThemeGeometryType type =
|
|
|
|
theme->ThemeGeometryTypeForWidget(mFrame, disp->mAppearance);
|
|
|
|
if (type != nsITheme::eThemeGeometryTypeUnknown) {
|
|
|
|
RegisterThemeGeometry(aBuilder, aFrame, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disp->mAppearance == NS_THEME_WIN_BORDERLESS_GLASS ||
|
|
|
|
disp->mAppearance == NS_THEME_WIN_GLASS) {
|
|
|
|
aBuilder->SetGlassDisplayItem(this);
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds = GetBoundsInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayThemedBackground::~nsDisplayThemedBackground()
|
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayThemedBackground);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplayThemedBackground::WriteDebugInfo(std::stringstream& aStream)
|
2013-07-18 10:34:58 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
aStream << " (themed, appearance:" << (int)mAppearance << ")";
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-24 20:32:23 +04:00
|
|
|
bool
|
|
|
|
nsDisplayThemedBackground::ProvidesFontSmoothingBackgroundColor(nsDisplayListBuilder* aBuilder,
|
|
|
|
nscolor* aColor)
|
|
|
|
{
|
|
|
|
nsITheme* theme = mFrame->PresContext()->GetTheme();
|
|
|
|
return theme->WidgetProvidesFontSmoothingBackgroundColor(mFrame, mAppearance, aColor);
|
|
|
|
}
|
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayThemedBackground::GetPositioningArea()
|
|
|
|
{
|
|
|
|
return nsRect(ToReferenceFrame(), mFrame->GetSize());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplayThemedBackground::Paint(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRenderingContext* aCtx)
|
|
|
|
{
|
|
|
|
PaintInternal(aBuilder, aCtx, mVisibleRect, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-02-13 04:20:41 +04:00
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
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);
|
2014-03-17 12:42:48 +04:00
|
|
|
theme->DrawWidgetBackground(aCtx, mFrame, mAppearance, borderArea, drawing);
|
2013-07-18 10:34:58 +04:00
|
|
|
}
|
|
|
|
|
2013-09-27 19:24:32 +04:00
|
|
|
bool nsDisplayThemedBackground::IsWindowActive()
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates docState = mFrame->GetContent()->OwnerDoc()->GetDocumentState();
|
2013-09-27 19:24:32 +04:00
|
|
|
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);
|
|
|
|
return r + ToReferenceFrame();
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:04:09 +03:00
|
|
|
void
|
2014-06-14 19:10:45 +04:00
|
|
|
nsDisplayBackgroundColor::ApplyOpacity(nsDisplayListBuilder* aBuilder,
|
|
|
|
float aOpacity,
|
|
|
|
const DisplayItemClip* aClip)
|
|
|
|
{
|
2015-02-20 04:04:09 +03:00
|
|
|
NS_ASSERTION(CanApplyOpacity(), "ApplyOpacity should be allowed");
|
2014-06-14 19:10:45 +04:00
|
|
|
mColor.a = mColor.a * aOpacity;
|
|
|
|
if (aClip) {
|
|
|
|
IntersectClip(aBuilder, *aClip);
|
|
|
|
}
|
2015-02-20 04:04:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayBackgroundColor::CanApplyOpacity() const
|
|
|
|
{
|
2014-06-14 19:10:45 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
void
|
|
|
|
nsDisplayBackgroundColor::Paint(nsDisplayListBuilder* aBuilder,
|
2014-06-14 19:10:45 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2012-10-25 09:32:25 +04:00
|
|
|
{
|
2014-11-24 03:04:33 +03:00
|
|
|
DrawTarget& aDrawTarget = *aCtx->GetDrawTarget();
|
|
|
|
|
2012-10-25 09:32:25 +04:00
|
|
|
if (mColor == NS_RGBA(0, 0, 0, 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:22:17 +04:00
|
|
|
nsRect borderBox = nsRect(ToReferenceFrame(), mFrame->GetSize());
|
2014-07-23 09:23:38 +04:00
|
|
|
|
2014-11-24 03:04:33 +03:00
|
|
|
Rect rect = NSRectToSnappedRect(borderBox,
|
|
|
|
mFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
aDrawTarget);
|
|
|
|
ColorPattern color(ToDeviceColor(mColor));
|
|
|
|
aDrawTarget.FillRect(rect, color);
|
2012-10-25 09:32:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsDisplayBackgroundColor::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2014-06-14 19:10:45 +04:00
|
|
|
bool* aSnap)
|
2012-10-25 09:32:25 +04:00
|
|
|
{
|
2014-06-14 19:10:45 +04:00
|
|
|
if (mColor.a != 1) {
|
2012-10-25 09:32:25 +04:00
|
|
|
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
|
2014-06-14 19:10:45 +04:00
|
|
|
nsDisplayBackgroundColor::IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
|
2012-10-25 09:32:25 +04:00
|
|
|
{
|
2014-06-14 19:10:45 +04:00
|
|
|
*aColor = NS_RGBA_FROM_GFXRGBA(mColor);
|
2014-07-23 09:22:17 +04:00
|
|
|
return true;
|
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
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplayBackgroundColor::WriteDebugInfo(std::stringstream& aStream)
|
2014-01-27 02:07:08 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
aStream << " (rgba " << mColor.r << "," << mColor.g << ","
|
|
|
|
<< mColor.b << "," << mColor.a << ")";
|
2014-01-27 02:07:08 +04:00
|
|
|
}
|
|
|
|
|
2014-08-20 19:16:41 +04:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayClearBackground::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters)
|
|
|
|
{
|
|
|
|
nsRefPtr<ColorLayer> layer = static_cast<ColorLayer*>
|
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, this));
|
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateColorLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
layer->SetColor(NS_RGBA(0, 0, 0, 0));
|
|
|
|
layer->SetMixBlendMode(gfx::CompositionOp::OP_SOURCE);
|
|
|
|
|
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
layer->SetBounds(bounds.ToNearestPixels(appUnitsPerDevPixel)); // XXX Do we need to respect the parent layer's scale here?
|
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
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
|
2014-06-03 16:48:16 +04:00
|
|
|
nsDisplayOutline::IsInvisibleInRect(const nsRect& aRect)
|
|
|
|
{
|
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());
|
2014-06-03 16:48:16 +04:00
|
|
|
if (borderBox.Contains(aRect) &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(outline->mOutlineRadius)) {
|
2008-09-13 07:45:37 +04:00
|
|
|
if (outline->mOutlineOffset >= 0) {
|
2014-06-03 16:48:16 +04:00
|
|
|
// aRect is entirely inside the border-rect, and the outline isn't
|
|
|
|
// rendered inside the border-rect, so the outline is not visible.
|
|
|
|
return true;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:48:16 +04:00
|
|
|
return false;
|
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");
|
2015-02-03 18:52:51 +03:00
|
|
|
if (aBuilder->IsInsidePointerEventsNoneDoc()) {
|
|
|
|
// Somewhere up the parent document chain is a subdocument with pointer-
|
|
|
|
// events:none set on it (and without a mozpasspointerevents).
|
|
|
|
return;
|
|
|
|
}
|
2015-01-15 18:37:54 +03:00
|
|
|
if (!aFrame->GetParent()) {
|
|
|
|
MOZ_ASSERT(aFrame->GetType() == nsGkAtoms::viewportFrame);
|
|
|
|
nsSubDocumentFrame* subdoc = static_cast<nsSubDocumentFrame*>(
|
|
|
|
nsLayoutUtils::GetCrossDocParentFrame(aFrame));
|
|
|
|
if (subdoc && subdoc->PassPointerEventsToChildren()) {
|
|
|
|
// If this viewport frame is for a subdocument with
|
|
|
|
// mozpasspointerevents, then we don't want to add the viewport itself
|
|
|
|
// to the event regions. Instead we want to add only subframes.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint8_t pointerEvents = aFrame->StyleVisibility()->GetEffectivePointerEvents(aFrame);
|
2013-12-16 15:22:11 +04:00
|
|
|
if (pointerEvents == NS_STYLE_POINTER_EVENTS_NONE) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-25 23:26:48 +03:00
|
|
|
if (!aFrame->StyleVisibility()->IsVisible()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-16 15:22:11 +04:00
|
|
|
// XXX handle other pointerEvents values for SVG
|
2015-02-05 16:25:49 +03:00
|
|
|
|
2013-12-16 15:22:11 +04:00
|
|
|
// XXX Do something clever here for the common case where the border box
|
|
|
|
// is obviously entirely inside mHitRegion.
|
2015-02-05 16:25:49 +03:00
|
|
|
nsRect borderBox;
|
|
|
|
if (nsLayoutUtils::GetScrollableFrameFor(aFrame)) {
|
|
|
|
// If the frame is content of a scrollframe, then we need to pick up the
|
|
|
|
// area corresponding to the overflow rect as well. Otherwise the parts of
|
|
|
|
// the overflow that are not occupied by descendants get skipped and the
|
|
|
|
// APZ code sends touch events to the content underneath instead.
|
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1127773#c15.
|
|
|
|
borderBox = aFrame->GetScrollableOverflowRect();
|
|
|
|
} else {
|
|
|
|
borderBox = nsRect(nsPoint(0, 0), aFrame->GetSize());
|
|
|
|
}
|
|
|
|
borderBox += aBuilder->ToReferenceFrame(aFrame);
|
|
|
|
|
2013-12-16 15:22:11 +04:00
|
|
|
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);
|
|
|
|
}
|
2015-02-11 00:28:07 +03:00
|
|
|
if (aBuilder->GetAncestorHasApzAwareEventHandler()) {
|
2013-12-16 15:22:11 +04:00
|
|
|
mDispatchToContentHitRegion.Or(mDispatchToContentHitRegion, borderBox);
|
|
|
|
}
|
2015-03-24 16:13:24 +03:00
|
|
|
|
|
|
|
// Touch action region
|
|
|
|
|
|
|
|
uint32_t touchAction = nsLayoutUtils::GetTouchActionFromFrame(aFrame);
|
|
|
|
if (touchAction & NS_STYLE_TOUCH_ACTION_NONE) {
|
|
|
|
mNoActionRegion.Or(mNoActionRegion, borderBox);
|
|
|
|
} else {
|
|
|
|
if ((touchAction & NS_STYLE_TOUCH_ACTION_PAN_X)) {
|
|
|
|
mHorizontalPanRegion.Or(mHorizontalPanRegion, borderBox);
|
|
|
|
}
|
|
|
|
if ((touchAction & NS_STYLE_TOUCH_ACTION_PAN_Y)) {
|
|
|
|
mVerticalPanRegion.Or(mVerticalPanRegion, borderBox);
|
|
|
|
}
|
|
|
|
}
|
2013-12-16 15:22:11 +04:00
|
|
|
}
|
|
|
|
|
2014-11-20 07:24:15 +03:00
|
|
|
void
|
|
|
|
nsDisplayLayerEventRegions::AddInactiveScrollPort(const nsRect& aRect)
|
|
|
|
{
|
|
|
|
mDispatchToContentHitRegion.Or(mDispatchToContentHitRegion, aRect);
|
|
|
|
}
|
|
|
|
|
2014-11-25 16:45:20 +03:00
|
|
|
void
|
|
|
|
nsDisplayLayerEventRegions::WriteDebugInfo(std::stringstream& aStream)
|
|
|
|
{
|
|
|
|
if (!mHitRegion.IsEmpty()) {
|
|
|
|
AppendToString(aStream, mHitRegion, " (hitRegion ", ")");
|
|
|
|
}
|
|
|
|
if (!mMaybeHitRegion.IsEmpty()) {
|
|
|
|
AppendToString(aStream, mMaybeHitRegion, " (maybeHitRegion ", ")");
|
|
|
|
}
|
|
|
|
if (!mDispatchToContentHitRegion.IsEmpty()) {
|
|
|
|
AppendToString(aStream, mDispatchToContentHitRegion, " (dispatchToContentRegion ", ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-06 09:19:25 +04:00
|
|
|
nsDisplayCaret::nsDisplayCaret(nsDisplayListBuilder* aBuilder,
|
2014-08-06 09:19:28 +04:00
|
|
|
nsIFrame* aCaretFrame)
|
2014-08-06 09:19:25 +04:00
|
|
|
: nsDisplayItem(aBuilder, aCaretFrame)
|
2014-08-06 09:19:28 +04:00
|
|
|
, mCaret(aBuilder->GetCaret())
|
|
|
|
, mBounds(aBuilder->GetCaretRect() + ToReferenceFrame())
|
2014-08-06 09:19:25 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayCaret);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplayCaret::~nsDisplayCaret()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayCaret);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayCaret::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
2014-08-06 09:19:28 +04:00
|
|
|
*aSnap = true;
|
2014-08-06 09:19:25 +04:00
|
|
|
// The caret returns a rect in the coordinates of mFrame.
|
2014-08-06 09:19:28 +04:00
|
|
|
return mBounds;
|
2014-08-06 09:19:25 +04:00
|
|
|
}
|
|
|
|
|
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.
|
2014-10-29 20:07:11 +03:00
|
|
|
mCaret->PaintCaret(aBuilder, *aCtx->GetDrawTarget(), mFrame, ToReferenceFrame());
|
2006-04-18 03:16:46 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-03 16:48:16 +04:00
|
|
|
nsDisplayBorder::IsInvisibleInRect(const nsRect& aRect)
|
|
|
|
{
|
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;
|
2014-06-03 16:48:16 +04:00
|
|
|
if (paddingRect.Contains(aRect) &&
|
2013-02-17 01:51:02 +04:00
|
|
|
!(styleBorder = mFrame->StyleBorder())->IsBorderImageLoaded() &&
|
2008-10-01 09:50:52 +04:00
|
|
|
!nsLayoutUtils::HasNonZeroCorner(styleBorder->mBorderRadius)) {
|
2014-06-03 16:48:16 +04:00
|
|
|
// aRect is entirely inside the content rect, and no part
|
2006-09-20 01:58:52 +04:00
|
|
|
// 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).
|
2014-06-03 16:48:16 +04:00
|
|
|
return true;
|
2006-09-20 01:58:52 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 16:48:16 +04:00
|
|
|
return false;
|
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;
|
2014-03-03 19:37:08 +04:00
|
|
|
return CalculateBounds(*mFrame->StyleBorder());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayBorder::CalculateBounds(const nsStyleBorder& aStyleBorder)
|
|
|
|
{
|
2013-12-09 03:01:30 +04:00
|
|
|
nsRect borderBounds(ToReferenceFrame(), mFrame->GetSize());
|
2014-03-03 19:37:08 +04:00
|
|
|
if (aStyleBorder.IsBorderImageLoaded()) {
|
|
|
|
borderBounds.Inflate(aStyleBorder.GetImageOutset());
|
2013-12-09 03:01:30 +04:00
|
|
|
return borderBounds;
|
|
|
|
} else {
|
2014-03-03 19:37:08 +04:00
|
|
|
nsMargin border = aStyleBorder.GetComputedBorder();
|
2013-12-09 03:01:30 +04:00
|
|
|
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);
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsDisplayBoxShadowOuter", "Paint",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
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
|
|
|
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
|
|
|
}
|
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
|
2014-06-03 16:48:16 +04:00
|
|
|
nsDisplayBoxShadowOuter::IsInvisibleInRect(const nsRect& aRect)
|
|
|
|
{
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint origin = ToReferenceFrame();
|
2009-04-24 13:24:44 +04:00
|
|
|
nsRect frameRect(origin, mFrame->GetSize());
|
2014-06-03 16:48:16 +04:00
|
|
|
if (!frameRect.Contains(aRect))
|
|
|
|
return false;
|
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)
|
2014-06-03 16:48:16 +04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return RoundedRectContainsRect(frameRect, twipsRadii, aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayBoxShadowOuter::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2014-06-03 16:48:16 +04:00
|
|
|
}
|
2009-01-30 10:03:46 +03:00
|
|
|
|
2014-06-03 16:48:16 +04:00
|
|
|
// Store the actual visible region
|
|
|
|
mVisibleRegion.And(*aVisibleRegion, mVisibleRect);
|
|
|
|
return true;
|
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)
|
|
|
|
{
|
2014-07-21 17:59:10 +04:00
|
|
|
const nsDisplayBoxShadowOuterGeometry* geometry =
|
|
|
|
static_cast<const nsDisplayBoxShadowOuterGeometry*>(aGeometry);
|
2013-08-23 05:47:54 +04:00
|
|
|
bool snap;
|
|
|
|
if (!geometry->mBounds.IsEqualInterior(GetBounds(aBuilder, &snap)) ||
|
2014-07-21 17:59:10 +04:00
|
|
|
!geometry->mBorderRect.IsEqualInterior(GetBorderRect()) ||
|
|
|
|
mOpacity != geometry->mOpacity) {
|
2013-08-23 05:47:54 +04:00
|
|
|
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);
|
|
|
|
|
2014-05-24 01:12:29 +04:00
|
|
|
PROFILER_LABEL("nsDisplayBoxShadowInner", "Paint",
|
|
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
|
2014-10-20 13:55:48 +04:00
|
|
|
DrawTarget* drawTarget = aCtx->GetDrawTarget();
|
|
|
|
gfxContext* gfx = aCtx->ThebesContext();
|
|
|
|
int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < rects.Length(); ++i) {
|
2014-10-20 13:55:48 +04:00
|
|
|
gfx->Save();
|
2014-10-22 15:29:06 +04:00
|
|
|
gfx->Clip(NSRectToSnappedRect(rects[i], appUnitsPerDevPixel, *drawTarget));
|
2009-12-01 02:14:04 +03:00
|
|
|
nsCSSRendering::PaintBoxShadowInner(presContext, *aCtx, mFrame,
|
|
|
|
borderRect, rects[i]);
|
2014-10-20 13:55:48 +04:00
|
|
|
gfx->Restore();
|
2009-12-01 02:14:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-12-01 02:14:04 +03:00
|
|
|
nsDisplayBoxShadowInner::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion)) {
|
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
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
2014-03-20 06:12:46 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mOverrideZIndex(0)
|
2014-07-24 03:07:18 +04:00
|
|
|
, mHasZIndexOverride(false)
|
2014-03-20 06:12:46 +04:00
|
|
|
{
|
2014-06-09 08:48:01 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayWrapList);
|
|
|
|
|
2014-12-22 06:09:32 +03:00
|
|
|
mBaseVisibleRect = mVisibleRect;
|
|
|
|
|
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);
|
2014-06-09 08:47:59 +04:00
|
|
|
} else {
|
|
|
|
// If we're a transformed frame, then we need to find out if we're inside
|
|
|
|
// the nsDisplayTransform or outside of it. Frames inside the transform
|
|
|
|
// need mReferenceFrame == mFrame, outside needs the next ancestor
|
|
|
|
// reference frame.
|
|
|
|
// If we're inside the transform, then the nsDisplayItem constructor
|
|
|
|
// will have done the right thing.
|
|
|
|
// If we're outside the transform, then we should have only one child
|
|
|
|
// (since nsDisplayTransform wraps all actual content), and that child
|
|
|
|
// will have the correct reference frame set (since nsDisplayTransform
|
|
|
|
// handles this explictly).
|
|
|
|
//
|
|
|
|
// Preserve-3d can cause us to have multiple nsDisplayTransform
|
|
|
|
// children.
|
|
|
|
nsDisplayItem *i = mList.GetBottom();
|
|
|
|
if (i && (!i->GetAbove() || i->GetType() == TYPE_TRANSFORM) &&
|
|
|
|
i->Frame() == mFrame) {
|
|
|
|
mReferenceFrame = i->ReferenceFrame();
|
|
|
|
mToReferenceFrame = i->ToReferenceFrame();
|
|
|
|
}
|
2012-10-25 09:32:25 +04:00
|
|
|
}
|
2014-08-07 20:33:18 +04:00
|
|
|
mVisibleRect = aBuilder->GetDirtyRect() +
|
|
|
|
aBuilder->GetCurrentFrameOffsetToReferenceFrame();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayWrapList::nsDisplayWrapList(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayItem* aItem)
|
2014-03-20 06:12:46 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mOverrideZIndex(0)
|
2014-07-24 03:07:18 +04:00
|
|
|
, mHasZIndexOverride(false)
|
2014-03-20 06:12:46 +04:00
|
|
|
{
|
2014-06-09 08:48:01 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayWrapList);
|
|
|
|
|
2014-12-22 06:09:32 +03:00
|
|
|
mBaseVisibleRect = mVisibleRect;
|
|
|
|
|
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);
|
2014-06-09 08:47:59 +04:00
|
|
|
} else {
|
|
|
|
// See the previous nsDisplayWrapList constructor
|
|
|
|
if (aItem->Frame() == aFrame) {
|
|
|
|
mReferenceFrame = aItem->ReferenceFrame();
|
|
|
|
mToReferenceFrame = aItem->ToReferenceFrame();
|
|
|
|
}
|
2012-10-25 09:32:25 +04:00
|
|
|
}
|
2014-08-07 20:33:18 +04:00
|
|
|
mVisibleRect = aBuilder->GetDirtyRect() +
|
|
|
|
aBuilder->GetCurrentFrameOffsetToReferenceFrame();
|
2014-07-17 19:24:47 +04:00
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
nsDisplayWrapList::~nsDisplayWrapList() {
|
|
|
|
mList.DeleteAll();
|
2014-06-09 08:48:01 +04:00
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayWrapList);
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
mVisibleRect);
|
2013-03-04 13:56:02 +04:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-18 05:26:57 +04:00
|
|
|
/**
|
|
|
|
* Returns true if all descendant display items can be placed in the same
|
2014-09-26 21:06:08 +04:00
|
|
|
* PaintedLayer --- GetLayerState returns LAYER_INACTIVE or LAYER_NONE,
|
2014-02-18 05:26:57 +04:00
|
|
|
* and they all have the expected animated geometry root.
|
|
|
|
*/
|
2013-09-26 01:07:26 +04:00
|
|
|
static LayerState
|
2014-02-18 05:26:57 +04:00
|
|
|
RequiredLayerStateForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters,
|
|
|
|
const nsDisplayList& aList,
|
|
|
|
nsIFrame* aExpectedAnimatedGeometryRootForChildren)
|
2013-09-26 01:07:26 +04:00
|
|
|
{
|
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-09-26 01:07:26 +04:00
|
|
|
if (result == LAYER_INACTIVE &&
|
2014-08-05 07:25:00 +04:00
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(i, aBuilder, aManager) !=
|
2014-02-18 05:26:57 +04:00
|
|
|
aExpectedAnimatedGeometryRootForChildren) {
|
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 =
|
2014-02-18 05:26:57 +04:00
|
|
|
RequiredLayerStateForChildren(aBuilder, aManager, aParameters, *list,
|
|
|
|
aExpectedAnimatedGeometryRootForChildren);
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-08-11 06:59:02 +04:00
|
|
|
void
|
|
|
|
nsDisplayWrapList::SetVisibleRect(const nsRect& aRect)
|
|
|
|
{
|
|
|
|
mVisibleRect = aRect;
|
|
|
|
}
|
|
|
|
|
2014-11-24 04:03:49 +03:00
|
|
|
void
|
|
|
|
nsDisplayWrapList::SetReferenceFrame(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
mReferenceFrame = aFrame;
|
|
|
|
mToReferenceFrame = mFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
}
|
|
|
|
|
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)
|
2014-06-12 19:34:35 +04:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
|
|
|
, mOpacity(aFrame->StyleDisplay()->mOpacity) {
|
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;
|
2014-06-12 19:34:35 +04:00
|
|
|
// The only time where mOpacity == 1.0 should be when we have will-change.
|
|
|
|
// We could report this as opaque then but when the will-change value starts
|
|
|
|
// animating the element would become non opaque and could cause repaints.
|
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) {
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<Layer> container = aManager->GetLayerBuilder()->
|
2014-06-09 08:48:00 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
|
2015-02-25 19:47:22 +03:00
|
|
|
aContainerParameters, nullptr,
|
|
|
|
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR);
|
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
|
|
|
|
2014-06-12 19:34:35 +04:00
|
|
|
container->SetOpacity(mOpacity);
|
2014-03-05 08:13:21 +04:00
|
|
|
nsDisplayListBuilder::AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, mFrame,
|
|
|
|
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
|
2014-10-22 05:54:32 +04:00
|
|
|
nsDisplayOpacity::NeedsActiveLayer(nsDisplayListBuilder* aBuilder)
|
2013-11-18 13:32:09 +04:00
|
|
|
{
|
2014-10-22 05:54:32 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(aBuilder, 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;
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:04:09 +03:00
|
|
|
void
|
2014-06-12 19:34:35 +04:00
|
|
|
nsDisplayOpacity::ApplyOpacity(nsDisplayListBuilder* aBuilder,
|
|
|
|
float aOpacity,
|
|
|
|
const DisplayItemClip* aClip)
|
|
|
|
{
|
2015-02-20 04:04:09 +03:00
|
|
|
NS_ASSERTION(CanApplyOpacity(), "ApplyOpacity should be allowed");
|
2014-06-12 19:34:35 +04:00
|
|
|
mOpacity = mOpacity * aOpacity;
|
|
|
|
if (aClip) {
|
|
|
|
IntersectClip(aBuilder, *aClip);
|
|
|
|
}
|
2015-02-20 04:04:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayOpacity::CanApplyOpacity() const
|
|
|
|
{
|
2014-06-12 19:34:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:32:09 +04:00
|
|
|
bool
|
|
|
|
nsDisplayOpacity::ShouldFlattenAway(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2014-10-22 05:54:32 +04:00
|
|
|
if (NeedsActiveLayer(aBuilder))
|
2013-11-18 13:32:09 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
nsDisplayItem* child = mList.GetBottom();
|
2015-02-20 04:04:09 +03:00
|
|
|
// Only try folding our opacity down if we have at most three children
|
|
|
|
// that don't overlap and can all apply the opacity to themselves.
|
|
|
|
if (!child) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
struct {
|
|
|
|
nsDisplayItem* item;
|
|
|
|
nsRect bounds;
|
|
|
|
} children[3];
|
|
|
|
bool snap;
|
|
|
|
uint32_t numChildren = 0;
|
|
|
|
for (; numChildren < ArrayLength(children) && child; numChildren++, child = child->GetAbove()) {
|
|
|
|
if (!child->CanApplyOpacity()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
children[numChildren].item = child;
|
|
|
|
children[numChildren].bounds = child->GetBounds(aBuilder, &snap);
|
|
|
|
}
|
|
|
|
if (child) {
|
|
|
|
// we have a fourth (or more) child
|
2013-11-18 13:32:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:04:09 +03:00
|
|
|
for (uint32_t i = 0; i < numChildren; i++) {
|
|
|
|
for (uint32_t j = i+1; j < numChildren; j++) {
|
|
|
|
if (children[i].bounds.Intersects(children[j].bounds)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < numChildren; i++) {
|
|
|
|
children[i].item->ApplyOpacity(aBuilder, mOpacity, mClip);
|
|
|
|
}
|
|
|
|
return true;
|
2013-11-18 13:32:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem::LayerState
|
|
|
|
nsDisplayOpacity::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters) {
|
2014-10-22 05:54:32 +04:00
|
|
|
if (NeedsActiveLayer(aBuilder))
|
2013-11-18 13:32:09 +04:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
|
2014-02-18 05:26:57 +04:00
|
|
|
return RequiredLayerStateForChildren(aBuilder, aManager, aParameters, mList,
|
2014-08-05 07:25:00 +04:00
|
|
|
nsLayoutUtils::GetAnimatedGeometryRootFor(this, aBuilder, aManager));
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
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);
|
|
|
|
return
|
2014-06-23 08:24:51 +04:00
|
|
|
nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren);
|
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
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplayOpacity::WriteDebugInfo(std::stringstream& aStream)
|
2014-01-27 02:07:08 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
aStream << " (opacity " << mOpacity << ")";
|
2014-01-27 02:07:08 +04:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-05-09 13:49:27 +04:00
|
|
|
LayerState
|
|
|
|
nsDisplayMixBlendMode::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters)
|
|
|
|
{
|
|
|
|
gfxContext::GraphicsOperator op = nsCSSRendering::GetGFXBlendMode(mFrame->StyleDisplay()->mMixBlendMode);
|
|
|
|
if (aManager->SupportsMixBlendMode(gfx::CompositionOpForOp(op))) {
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
return LAYER_INACTIVE;
|
|
|
|
}
|
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
// 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()->
|
2014-06-09 08:48:00 +04:00
|
|
|
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
|
|
|
|
2014-02-12 19:07:46 +04:00
|
|
|
container->DeprecatedSetMixBlendMode(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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
2013-09-15 07:40:11 +04:00
|
|
|
// 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);
|
2014-06-23 08:24:51 +04:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, &visibleUnderChildren);
|
2013-09-15 07:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2014-05-09 13:49:27 +04:00
|
|
|
BlendModeSet& aContainedBlendModes)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
|
|
|
, mContainedBlendModes(aContainedBlendModes)
|
|
|
|
, mCanBeActive(true)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayBlendContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayBlendContainer::nsDisplayBlendContainer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList)
|
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
|
|
|
, mCanBeActive(false)
|
|
|
|
{
|
2013-09-15 07:30:00 +04:00
|
|
|
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()->
|
2014-06-09 08:48:00 +04:00
|
|
|
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,
|
2015-04-13 06:03:02 +03:00
|
|
|
uint32_t aFlags, ViewID aScrollTarget,
|
|
|
|
float aScrollbarThumbRatio)
|
2012-08-29 09:47:18 +04:00
|
|
|
: nsDisplayWrapList(aBuilder, aFrame, aList)
|
2013-12-10 07:14:53 +04:00
|
|
|
, mFlags(aFlags)
|
2015-04-13 06:03:02 +03:00
|
|
|
, mScrollTarget(aScrollTarget)
|
|
|
|
, mScrollbarThumbRatio(aScrollbarThumbRatio)
|
|
|
|
{
|
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,
|
2015-04-13 06:03:02 +03:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
2013-08-14 15:33:03 +04:00
|
|
|
nsRefPtr<ContainerLayer> layer = aManager->GetLayerBuilder()->
|
2014-06-09 08:48:00 +04:00
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
|
2015-02-25 19:47:22 +03:00
|
|
|
aContainerParameters, nullptr,
|
|
|
|
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR);
|
2013-12-10 07:14:53 +04:00
|
|
|
if (mFlags & VERTICAL_SCROLLBAR) {
|
2015-04-13 06:03:02 +03:00
|
|
|
layer->SetScrollbarData(mScrollTarget, Layer::ScrollDirection::VERTICAL, mScrollbarThumbRatio);
|
2013-12-10 07:14:53 +04:00
|
|
|
}
|
|
|
|
if (mFlags & HORIZONTAL_SCROLLBAR) {
|
2015-04-13 06:03:02 +03:00
|
|
|
layer->SetScrollbarData(mScrollTarget, Layer::ScrollDirection::HORIZONTAL, mScrollbarThumbRatio);
|
2013-12-10 07:14:53 +04:00
|
|
|
}
|
2015-01-14 10:55:17 +03:00
|
|
|
if (mFlags & SCROLLBAR_CONTAINER) {
|
|
|
|
layer->SetIsScrollbarContainer();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:01:53 +04:00
|
|
|
nsDisplaySubDocument::nsDisplaySubDocument(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
2014-04-12 03:39:22 +04:00
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList, aFlags)
|
|
|
|
, mScrollParentId(aBuilder->GetCurrentScrollParentId())
|
|
|
|
{
|
2014-02-28 02:01:53 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplaySubDocument);
|
2015-02-11 00:28:07 +03:00
|
|
|
mForceDispatchToContentRegion =
|
|
|
|
aBuilder->IsBuildingLayerEventRegions() &&
|
|
|
|
nsLayoutUtils::HasDocumentLevelListenersForApzAwareEvents(aFrame->PresContext()->PresShell());
|
2014-02-28 02:01:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsDisplaySubDocument::~nsDisplaySubDocument() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplaySubDocument);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplaySubDocument::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aContainerParameters) {
|
2014-08-08 01:12:01 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
|
|
|
|
ContainerLayerParameters params = aContainerParameters;
|
|
|
|
if ((mFlags & GENERATE_SCROLLABLE_LAYER) &&
|
|
|
|
rootScrollFrame->GetContent() &&
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(rootScrollFrame->GetContent(), nullptr)) {
|
|
|
|
params.mInLowPrecisionDisplayPort = true;
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:28:07 +03:00
|
|
|
nsRefPtr<Layer> layer = nsDisplayOwnLayer::BuildLayer(aBuilder, aManager, params);
|
2015-02-25 21:36:19 +03:00
|
|
|
layer->AsContainerLayer()->SetEventRegionsOverride(mForceDispatchToContentRegion
|
|
|
|
? EventRegionsOverride::ForceDispatchToContent
|
|
|
|
: EventRegionsOverride::NoOverride);
|
2015-02-11 00:28:07 +03:00
|
|
|
return layer.forget();
|
2014-08-31 07:29:24 +04:00
|
|
|
}
|
2014-02-28 02:01:53 +04:00
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
UniquePtr<FrameMetrics>
|
|
|
|
nsDisplaySubDocument::ComputeFrameMetrics(Layer* aLayer,
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
2014-02-28 02:01:53 +04:00
|
|
|
if (!(mFlags & GENERATE_SCROLLABLE_LAYER)) {
|
2014-08-31 07:29:24 +04:00
|
|
|
return UniquePtr<FrameMetrics>(nullptr);
|
2014-02-28 02:01:53 +04:00
|
|
|
}
|
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
nsPresContext* presContext = mFrame->PresContext();
|
|
|
|
nsIFrame* rootScrollFrame = presContext->PresShell()->GetRootScrollFrame();
|
|
|
|
bool isRootContentDocument = presContext->IsRootContentDocument();
|
2014-11-21 21:50:41 +03:00
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
2015-02-27 23:36:31 +03:00
|
|
|
ContainerLayerParameters params(
|
2015-03-07 02:07:59 +03:00
|
|
|
aContainerParameters.mXScale * presShell->GetResolution(),
|
|
|
|
aContainerParameters.mYScale * presShell->GetResolution(),
|
2015-02-27 23:36:31 +03:00
|
|
|
nsIntPoint(), aContainerParameters);
|
2014-08-31 07:29:24 +04:00
|
|
|
if ((mFlags & GENERATE_SCROLLABLE_LAYER) &&
|
|
|
|
rootScrollFrame->GetContent() &&
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(rootScrollFrame->GetContent(), nullptr)) {
|
|
|
|
params.mInLowPrecisionDisplayPort = true;
|
2014-09-02 02:20:13 +04:00
|
|
|
}
|
2014-08-31 07:29:24 +04:00
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
nsRect viewport = mFrame->GetRect() -
|
|
|
|
mFrame->GetPosition() +
|
|
|
|
mFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
|
|
|
|
|
|
|
return MakeUnique<FrameMetrics>(
|
2015-02-13 04:49:10 +03:00
|
|
|
nsDisplayScrollLayer::ComputeFrameMetrics(
|
|
|
|
mFrame, rootScrollFrame, rootScrollFrame->GetContent(), ReferenceFrame(),
|
|
|
|
aLayer, mScrollParentId, viewport,
|
|
|
|
isRootContentDocument, params));
|
2014-02-28 02:01:53 +04:00
|
|
|
}
|
|
|
|
|
2014-10-21 01:32:11 +04:00
|
|
|
static bool
|
|
|
|
UseDisplayPortForViewport(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsRect* aDisplayPort = nullptr)
|
|
|
|
{
|
|
|
|
return aBuilder->IsPaintingToWindow() &&
|
|
|
|
nsLayoutUtils::ViewportHasDisplayPort(aFrame->PresContext(), aDisplayPort);
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplaySubDocument::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
2014-10-21 01:32:11 +04:00
|
|
|
bool usingDisplayPort = UseDisplayPortForViewport(aBuilder, mFrame);
|
2014-02-28 02:01:54 +04:00
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
|
|
|
|
*aSnap = false;
|
|
|
|
return mFrame->GetRect() + aBuilder->ToReferenceFrame(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDisplayOwnLayer::GetBounds(aBuilder, aSnap);
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
bool
|
|
|
|
nsDisplaySubDocument::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion)
|
2014-02-28 02:01:54 +04:00
|
|
|
{
|
|
|
|
nsRect displayport;
|
2014-10-21 01:32:11 +04:00
|
|
|
bool usingDisplayPort = UseDisplayPortForViewport(aBuilder, mFrame, &displayport);
|
2014-02-28 02:01:54 +04:00
|
|
|
|
|
|
|
if (!(mFlags & GENERATE_SCROLLABLE_LAYER) || !usingDisplayPort) {
|
2014-06-23 08:24:51 +04:00
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, aVisibleRegion);
|
2014-02-28 02:01:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion childVisibleRegion;
|
|
|
|
// 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.
|
|
|
|
childVisibleRegion = displayport + mFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
|
|
|
|
|
|
|
nsRect boundedRect =
|
|
|
|
childVisibleRegion.GetBounds().Intersect(mList.GetBounds(aBuilder));
|
|
|
|
bool visible = mList.ComputeVisibilityForSublist(
|
2014-06-23 08:24:51 +04:00
|
|
|
aBuilder, &childVisibleRegion, boundedRect,
|
2014-03-18 03:39:59 +04:00
|
|
|
usingDisplayPort ? mFrame : nullptr);
|
2014-07-24 07:13:23 +04:00
|
|
|
|
|
|
|
// If APZ is enabled then 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.
|
2014-07-29 04:07:36 +04:00
|
|
|
if (!nsLayoutUtils::UsesAsyncScrolling()) {
|
2014-07-24 07:13:23 +04:00
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(bounds, childVisibleRegion);
|
|
|
|
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
|
|
|
}
|
2014-02-28 02:01:54 +04:00
|
|
|
|
|
|
|
return visible;
|
|
|
|
}
|
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
bool
|
|
|
|
nsDisplaySubDocument::ShouldBuildLayerEvenIfInvisible(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2014-10-21 01:32:11 +04:00
|
|
|
bool usingDisplayPort = UseDisplayPortForViewport(aBuilder, mFrame);
|
2014-02-28 02:01:54 +04:00
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDisplayOwnLayer::ShouldBuildLayerEvenIfInvisible(aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion
|
|
|
|
nsDisplaySubDocument::GetOpaqueRegion(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
2014-10-21 01:32:11 +04:00
|
|
|
bool usingDisplayPort = UseDisplayPortForViewport(aBuilder, mFrame);
|
2014-02-28 02:01:54 +04:00
|
|
|
|
2014-02-28 02:01:54 +04:00
|
|
|
if ((mFlags & GENERATE_SCROLLABLE_LAYER) && usingDisplayPort) {
|
|
|
|
*aSnap = false;
|
|
|
|
return nsRegion();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsDisplayOwnLayer::GetOpaqueRegion(aBuilder, aSnap);
|
|
|
|
}
|
|
|
|
|
2013-10-29 17:27:15 +04:00
|
|
|
nsDisplayResolution::nsDisplayResolution(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame, nsDisplayList* aList,
|
|
|
|
uint32_t aFlags)
|
2014-02-28 02:01:53 +04:00
|
|
|
: nsDisplaySubDocument(aBuilder, aFrame, aList, aFlags) {
|
2013-10-29 17:27:15 +04:00
|
|
|
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(
|
2015-03-07 02:07:59 +03:00
|
|
|
presShell->GetResolution(), presShell->GetResolution(), nsIntPoint(),
|
2013-10-29 17:27:15 +04:00
|
|
|
aContainerParameters);
|
|
|
|
|
2014-02-28 02:01:53 +04:00
|
|
|
nsRefPtr<Layer> layer = nsDisplaySubDocument::BuildLayer(
|
2013-10-29 17:27:15 +04:00
|
|
|
aBuilder, aManager, containerParameters);
|
2015-03-07 02:07:59 +03:00
|
|
|
layer->SetPostScale(1.0f / presShell->GetResolution(),
|
|
|
|
1.0f / presShell->GetResolution());
|
2015-01-03 04:06:14 +03:00
|
|
|
layer->AsContainerLayer()->SetScaleToResolution(
|
2015-03-07 02:07:59 +03:00
|
|
|
presShell->ScaleToResolution(), presShell->GetResolution());
|
2013-10-29 17:27:15 +04:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2013-09-13 05:56:57 +04:00
|
|
|
nsDisplayStickyPosition::nsDisplayStickyPosition(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList)
|
2013-09-27 10:02:03 +04:00
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList)
|
2014-01-04 09:14:27 +04:00
|
|
|
{
|
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-12-17 15:30:21 +04:00
|
|
|
nsLayoutUtils::SetFixedPositionLayerData(layer, scrollFrame,
|
|
|
|
nsRect(scrollFrame->GetOffsetToCrossDoc(ReferenceFrame()), scrollFrameSize),
|
2014-01-04 09:14:27 +04:00
|
|
|
mFrame, 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);
|
2014-01-04 09:14:27 +04:00
|
|
|
if (other->mFrame != mFrame)
|
2013-09-27 10:02:03 +04:00
|
|
|
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)
|
2014-04-12 03:39:22 +04:00
|
|
|
, mScrollParentId(aBuilder->GetCurrentScrollParentId())
|
2014-06-23 08:23:58 +04:00
|
|
|
, mDisplayPortContentsOpaque(false)
|
2011-05-02 05:53:01 +04:00
|
|
|
{
|
|
|
|
#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)
|
2014-04-12 03:39:22 +04:00
|
|
|
, mScrollParentId(aBuilder->GetCurrentScrollParentId())
|
2014-06-23 08:23:58 +04:00
|
|
|
, mDisplayPortContentsOpaque(false)
|
2011-05-02 05:53:01 +04:00
|
|
|
{
|
|
|
|
#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)
|
2014-04-12 03:39:22 +04:00
|
|
|
, mScrollParentId(aBuilder->GetCurrentScrollParentId())
|
2014-06-23 08:23:58 +04:00
|
|
|
, mDisplayPortContentsOpaque(false)
|
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);
|
|
|
|
}
|
|
|
|
|
2014-06-23 08:23:58 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayScrollLayer::GetScrolledContentRectToDraw(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRect* aDisplayPort)
|
|
|
|
{
|
|
|
|
if (aDisplayPort) {
|
|
|
|
// 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.
|
|
|
|
// XXX mScrollFrame seems wrong here; we should add the offset of the
|
|
|
|
// scrollport
|
|
|
|
return *aDisplayPort + mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
|
|
|
}
|
|
|
|
bool snap;
|
|
|
|
return GetBounds(aBuilder, &snap);
|
|
|
|
}
|
|
|
|
|
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,
|
2014-08-31 07:29:24 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
2014-08-08 01:12:01 +04:00
|
|
|
ContainerLayerParameters params = aContainerParameters;
|
|
|
|
if (mScrolledFrame->GetContent() &&
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(mScrolledFrame->GetContent(), nullptr)) {
|
2014-08-31 07:29:24 +04:00
|
|
|
params.mInLowPrecisionDisplayPort = true;
|
2014-08-08 01:12:01 +04:00
|
|
|
}
|
|
|
|
|
2014-06-23 08:23:58 +04:00
|
|
|
if (mList.IsOpaque()) {
|
|
|
|
nsRect displayport;
|
|
|
|
bool usingDisplayport =
|
|
|
|
nsLayoutUtils::GetDisplayPort(mScrolledFrame->GetContent(), &displayport);
|
|
|
|
mDisplayPortContentsOpaque = mList.GetBounds(aBuilder).Contains(
|
|
|
|
GetScrolledContentRectToDraw(aBuilder, usingDisplayport ? &displayport : nullptr));
|
|
|
|
} else {
|
|
|
|
mDisplayPortContentsOpaque = false;
|
|
|
|
}
|
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
return aManager->GetLayerBuilder()->
|
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
|
2015-02-25 19:47:22 +03:00
|
|
|
params, nullptr,
|
|
|
|
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR);
|
2011-01-13 20:45:14 +03:00
|
|
|
}
|
|
|
|
|
2014-08-31 07:29:24 +04:00
|
|
|
UniquePtr<FrameMetrics>
|
|
|
|
nsDisplayScrollLayer::ComputeFrameMetrics(Layer* aLayer,
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2014-06-23 08:23:58 +04:00
|
|
|
{
|
2014-08-31 07:29:24 +04:00
|
|
|
ContainerLayerParameters params = aContainerParameters;
|
|
|
|
if (mScrolledFrame->GetContent() &&
|
|
|
|
nsLayoutUtils::GetCriticalDisplayPort(mScrolledFrame->GetContent(), nullptr)) {
|
|
|
|
params.mInLowPrecisionDisplayPort = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect viewport = mScrollFrame->GetRect() -
|
|
|
|
mScrollFrame->GetPosition() +
|
|
|
|
mScrollFrame->GetOffsetToCrossDoc(ReferenceFrame());
|
|
|
|
|
|
|
|
return UniquePtr<FrameMetrics>(new FrameMetrics(
|
2015-02-13 04:49:10 +03:00
|
|
|
ComputeFrameMetrics(
|
|
|
|
mScrolledFrame, mScrollFrame, mScrollFrame->GetContent(),
|
|
|
|
ReferenceFrame(), aLayer,
|
|
|
|
mScrollParentId, viewport, false, params)));
|
2014-06-23 08:23:58 +04:00
|
|
|
}
|
|
|
|
|
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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion)
|
2011-01-13 20:45:14 +03:00
|
|
|
{
|
2014-07-24 07:11:30 +04:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
|
|
|
return nsDisplayWrapList::ComputeVisibility(aBuilder, aVisibleRegion);
|
|
|
|
}
|
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);
|
2014-06-23 08:23:58 +04:00
|
|
|
nsRect scrolledContentRect = GetScrolledContentRectToDraw(aBuilder,
|
|
|
|
usingDisplayPort ? &displayport : nullptr);
|
2013-12-18 09:02:56 +04:00
|
|
|
|
2014-06-23 08:23:58 +04:00
|
|
|
nsRect boundedRect = scrolledContentRect.Intersect(mList.GetBounds(aBuilder));
|
|
|
|
nsRegion childVisibleRegion = scrolledContentRect;
|
2013-12-18 09:02:56 +04:00
|
|
|
bool visible = mList.ComputeVisibilityForSublist(
|
2014-06-23 08:24:51 +04:00
|
|
|
aBuilder, &childVisibleRegion, boundedRect,
|
2014-03-18 03:39:59 +04:00
|
|
|
usingDisplayPort ? mScrollFrame : nullptr);
|
2014-07-24 07:13:23 +04:00
|
|
|
|
|
|
|
// If APZ is enabled then 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.
|
2014-07-29 04:07:36 +04:00
|
|
|
if (!nsLayoutUtils::UsesAsyncScrolling()) {
|
2014-07-24 07:13:23 +04:00
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(bounds, childVisibleRegion);
|
|
|
|
aBuilder->SubtractFromVisibleRegion(aVisibleRegion, removed);
|
|
|
|
}
|
2013-12-18 09:02:56 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-02-04 09:16:20 +04:00
|
|
|
// Check if we are going to clip an abs pos item that we don't contain.
|
|
|
|
// Root scroll frames clip all their descendants, so we don't need to worry
|
|
|
|
// about them.
|
|
|
|
bool
|
|
|
|
WouldCauseIncorrectClippingOnAbsPosItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayScrollLayer* aItem)
|
|
|
|
{
|
|
|
|
nsIFrame* scrollFrame = aItem->GetScrollFrame();
|
|
|
|
nsIPresShell* presShell = scrollFrame->PresContext()->PresShell();
|
|
|
|
if (scrollFrame == presShell->GetRootScrollFrame()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIFrame* scrolledFrame = aItem->GetScrolledFrame();
|
|
|
|
nsIFrame* frame = aItem->Frame();
|
|
|
|
if (frame == scrolledFrame || !frame->IsAbsolutelyPositioned() ||
|
|
|
|
nsLayoutUtils::IsAncestorFrameCrossDoc(scrollFrame, frame, presShell->GetRootFrame())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!aItem->GetClip().IsRectAffectedByClip(aItem->GetChildren()->GetBounds(aBuilder))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-02-04 09:16:20 +04:00
|
|
|
if (WouldCauseIncorrectClippingOnAbsPosItem(aBuilder, this) ||
|
|
|
|
WouldCauseIncorrectClippingOnAbsPosItem(aBuilder, other)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-02-04 09:16:20 +04:00
|
|
|
bool badAbsPosClip = WouldCauseIncorrectClippingOnAbsPosItem(aBuilder, this);
|
|
|
|
if (GetScrollLayerCount() > 1 || badAbsPosClip) {
|
2013-12-10 22:05:18 +04:00
|
|
|
// 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.
|
2014-02-04 09:16:20 +04:00
|
|
|
// But don't induce our clip on abs pos frames that we shouldn't be clipping.
|
|
|
|
if (!badAbsPosClip) {
|
|
|
|
PropagateClip(aBuilder, GetClip(), &mList);
|
|
|
|
}
|
2014-07-09 02:35:48 +04:00
|
|
|
|
|
|
|
// Output something so the failure can be noted.
|
|
|
|
nsresult status;
|
|
|
|
mScrolledFrame->GetContent()->GetProperty(nsGkAtoms::AsyncScrollLayerCreationFailed, &status);
|
|
|
|
if (status == NS_PROPTABLE_PROP_NOT_THERE) {
|
|
|
|
mScrolledFrame->GetContent()->SetProperty(nsGkAtoms::AsyncScrollLayerCreationFailed, nullptr);
|
|
|
|
if (badAbsPosClip) {
|
|
|
|
printf_stderr("Async scrollable layer creation failed: scroll layer would induce incorrent clipping to an abs pos item.\n");
|
|
|
|
} else {
|
|
|
|
printf_stderr("Async scrollable layer creation failed: scroll layer can't have scrollable and non-scrollable items interleaved.\n");
|
|
|
|
}
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
std::stringstream ss;
|
|
|
|
nsFrame::PrintDisplayItem(aBuilder, this, ss, true, false);
|
|
|
|
printf_stderr("%s\n", ss.str().c_str());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-10 22:05:18 +04:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-28 03:30:29 +04:00
|
|
|
if (mFrame != mScrolledFrame) {
|
|
|
|
mMergedFrames.AppendElement(mFrame);
|
|
|
|
mFrame = mScrolledFrame;
|
|
|
|
}
|
2013-12-10 22:05:18 +04:00
|
|
|
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.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(hasCount, "nsDisplayScrollLayer should always be defined");
|
2011-05-02 05:53:01 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-27 02:09:06 +04:00
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplayScrollLayer::WriteDebugInfo(std::stringstream& aStream)
|
2014-01-27 02:09:06 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
aStream << " (scrollframe " << mScrollFrame
|
|
|
|
<< " scrolledFrame " << mScrolledFrame << ")";
|
2014-01-27 02:09:06 +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)
|
2015-01-20 17:49:30 +03:00
|
|
|
, mHoisted(false)
|
2011-04-12 00:53:01 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayScrollInfoLayer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayScrollInfoLayer::~nsDisplayScrollInfoLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayScrollInfoLayer);
|
|
|
|
}
|
|
|
|
|
2013-12-18 09:02:56 +04:00
|
|
|
nsRect
|
|
|
|
nsDisplayScrollInfoLayer::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
|
|
|
return nsDisplayWrapList::GetBounds(aBuilder, aSnap);
|
|
|
|
}
|
|
|
|
|
2015-01-20 17:49:30 +03:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayScrollInfoLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
2015-03-10 16:29:19 +03:00
|
|
|
// In general for APZ with event-regions we no longer have a need for
|
|
|
|
// scrollinfo layers. However, in some cases, there might be content that
|
|
|
|
// cannot be layerized, and so needs to scroll synchronously. To handle those
|
|
|
|
// cases (which are indicated by setting mHoisted to true), we still want to
|
|
|
|
// generate scrollinfo layers.
|
|
|
|
return mHoisted
|
|
|
|
? nsDisplayScrollLayer::BuildLayer(aBuilder, aManager, aContainerParameters)
|
|
|
|
: nullptr;
|
2015-01-20 17:49:30 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-01-20 17:49:30 +03:00
|
|
|
// See comment in BuildLayer
|
2015-03-10 16:29:19 +03:00
|
|
|
return mHoisted
|
|
|
|
? LAYER_ACTIVE_EMPTY
|
|
|
|
: LAYER_NONE;
|
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::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)
|
2014-02-28 02:01:53 +04:00
|
|
|
: nsDisplaySubDocument(aBuilder, aFrame, aList, aFlags)
|
2012-08-29 09:47:18 +04:00
|
|
|
, 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
|
|
|
{
|
2014-03-07 03:40:31 +04:00
|
|
|
nsRect bounds = nsDisplaySubDocument::GetBounds(aBuilder, aSnap);
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2015-03-27 00:44:40 +03:00
|
|
|
return bounds.ScaleToOtherAppUnitsRoundOut(mAPD, mParentAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2015-03-27 00:44:40 +03:00
|
|
|
rect.MoveTo(aRect.TopLeft().ScaleToOtherAppUnits(mParentAPD, mAPD));
|
2010-07-19 06:23:48 +04:00
|
|
|
rect.width = rect.height = 1;
|
|
|
|
} else {
|
2015-03-27 00:44:40 +03:00
|
|
|
rect = aRect.ScaleToOtherAppUnitsRoundOut(mParentAPD, mAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
}
|
|
|
|
mList.HitTest(aBuilder, rect, aState, aOutFrames);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayZoom::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion *aVisibleRegion)
|
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);
|
2015-03-27 00:44:40 +03:00
|
|
|
visibleRegion = visibleRegion.ScaleToOtherAppUnitsRoundOut(mParentAPD, mAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
nsRegion originalVisibleRegion = visibleRegion;
|
|
|
|
|
2010-08-28 03:15:08 +04:00
|
|
|
nsRect transformedVisibleRect =
|
2015-03-27 00:44:40 +03:00
|
|
|
mVisibleRect.ScaleToOtherAppUnitsRoundOut(mParentAPD, mAPD);
|
2014-03-07 03:40:31 +04:00
|
|
|
bool retval;
|
|
|
|
// If we are to generate a scrollable layer we call
|
|
|
|
// nsDisplaySubDocument::ComputeVisibility to make the necessary adjustments
|
|
|
|
// for ComputeVisibility, it does all it's calculations in the child APD.
|
2014-10-21 01:32:11 +04:00
|
|
|
bool usingDisplayPort = UseDisplayPortForViewport(aBuilder, mFrame);
|
2014-03-07 03:40:31 +04:00
|
|
|
if (!(mFlags & GENERATE_SCROLLABLE_LAYER) || !usingDisplayPort) {
|
|
|
|
retval =
|
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &visibleRegion,
|
2014-06-23 08:24:51 +04:00
|
|
|
transformedVisibleRect);
|
2014-03-07 03:40:31 +04:00
|
|
|
} else {
|
|
|
|
retval =
|
2014-06-23 08:24:51 +04:00
|
|
|
nsDisplaySubDocument::ComputeVisibility(aBuilder, &visibleRegion);
|
2014-03-07 03:40:31 +04:00
|
|
|
}
|
2010-07-19 06:23:48 +04:00
|
|
|
|
|
|
|
nsRegion removed;
|
|
|
|
// removed = originalVisibleRegion - visibleRegion
|
|
|
|
removed.Sub(originalVisibleRegion, visibleRegion);
|
|
|
|
// Convert removed region to parent appunits.
|
2015-03-27 00:44:40 +03:00
|
|
|
removed = removed.ScaleToOtherAppUnitsRoundIn(mAPD, mParentAPD);
|
2010-07-19 06:23:48 +04:00
|
|
|
// 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
|
|
|
|
|
2014-07-15 15:47:46 +04:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame *aFrame, nsDisplayList *aList,
|
|
|
|
const nsRect& aChildrenVisibleRect,
|
|
|
|
ComputeTransformFunction aTransformGetter,
|
2012-09-20 03:14:07 +04:00
|
|
|
uint32_t aIndex)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aList)
|
|
|
|
, mTransformGetter(aTransformGetter)
|
2014-07-15 15:47:46 +04:00
|
|
|
, mChildrenVisibleRect(aChildrenVisibleRect)
|
2012-09-20 03:14:07 +04:00
|
|
|
, mIndex(aIndex)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame, "Must have a frame!");
|
|
|
|
MOZ_ASSERT(!aFrame->IsTransformed(), "Can't specify a transform getter for a transformed frame!");
|
2014-07-29 16:09:35 +04:00
|
|
|
Init(aBuilder);
|
2012-09-20 03:14:07 +04:00
|
|
|
}
|
|
|
|
|
2014-06-09 08:47:59 +04:00
|
|
|
void
|
|
|
|
nsDisplayTransform::SetReferenceFrameToAncestor(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
mReferenceFrame =
|
|
|
|
aBuilder->FindReferenceFrameFor(GetTransformRootFrame(mFrame));
|
|
|
|
mToReferenceFrame = mFrame->GetOffsetToCrossDoc(mReferenceFrame);
|
|
|
|
mVisibleRect = aBuilder->GetDirtyRect() + mToReferenceFrame;
|
|
|
|
}
|
|
|
|
|
2014-07-29 16:09:35 +04:00
|
|
|
void
|
|
|
|
nsDisplayTransform::Init(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
mStoredList.SetClip(aBuilder, DisplayItemClip::NoClip());
|
2014-08-11 06:59:02 +04:00
|
|
|
mStoredList.SetVisibleRect(mChildrenVisibleRect);
|
2014-10-22 05:55:55 +04:00
|
|
|
mMaybePrerender = ShouldPrerenderTransformedContent(aBuilder, mFrame);
|
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleDisplay* disp = mFrame->StyleDisplay();
|
|
|
|
if ((disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_TRANSFORM)) {
|
2014-10-22 05:55:55 +04:00
|
|
|
// We will only pre-render if this will-change is on budget.
|
|
|
|
mMaybePrerender = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMaybePrerender) {
|
2014-07-29 16:09:35 +04:00
|
|
|
bool snap;
|
|
|
|
mVisibleRect = GetBounds(aBuilder, &snap);
|
|
|
|
}
|
2014-07-29 16:09:35 +04:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:47:46 +04:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame *aFrame, nsDisplayList *aList,
|
|
|
|
const nsRect& aChildrenVisibleRect,
|
|
|
|
uint32_t aIndex)
|
2012-09-20 03:14:07 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aList)
|
|
|
|
, mTransformGetter(nullptr)
|
2014-07-15 15:47:46 +04:00
|
|
|
, mChildrenVisibleRect(aChildrenVisibleRect)
|
2012-09-20 03:14:07 +04:00
|
|
|
, mIndex(aIndex)
|
2012-09-16 14:32:59 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame, "Must have a frame!");
|
2014-06-09 08:47:59 +04:00
|
|
|
SetReferenceFrameToAncestor(aBuilder);
|
2014-07-29 16:09:35 +04:00
|
|
|
Init(aBuilder);
|
2012-09-16 14:32:59 +04:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:47:46 +04:00
|
|
|
nsDisplayTransform::nsDisplayTransform(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame *aFrame, nsDisplayItem *aItem,
|
|
|
|
const nsRect& aChildrenVisibleRect,
|
|
|
|
uint32_t aIndex)
|
2014-02-27 06:57:45 +04:00
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mStoredList(aBuilder, aFrame, aItem)
|
|
|
|
, mTransformGetter(nullptr)
|
2014-07-15 15:47:46 +04:00
|
|
|
, mChildrenVisibleRect(aChildrenVisibleRect)
|
2014-02-27 06:57:45 +04:00
|
|
|
, mIndex(aIndex)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayTransform);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aFrame, "Must have a frame!");
|
2014-06-09 08:47:59 +04:00
|
|
|
SetReferenceFrameToAncestor(aBuilder);
|
2014-07-29 16:09:35 +04:00
|
|
|
Init(aBuilder);
|
2014-02-27 06:57:45 +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
|
|
|
*/
|
2014-08-29 22:47:30 +04:00
|
|
|
/* static */ Point3D
|
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!");
|
2015-03-20 07:12:17 +03:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed() || aFrame->StyleDisplay()->BackfaceIsHidden(),
|
2012-05-17 08:05:09 +04:00
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2008-09-13 13:42:11 +04:00
|
|
|
|
2014-02-27 06:57:45 +04:00
|
|
|
if (!aFrame->IsTransformed()) {
|
2014-08-29 22:47:30 +04:00
|
|
|
return Point3D();
|
2014-02-27 06:57:45 +04:00
|
|
|
}
|
|
|
|
|
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!
|
|
|
|
*/
|
2015-03-20 07:12:17 +03: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.
|
|
|
|
*/
|
2015-03-20 07:12:17 +03: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 {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(coord.GetUnit() == eStyleUnit_Coord, "unexpected unit");
|
2013-11-11 06:23:56 +04:00
|
|
|
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
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
coords[2] = NSAppUnitsToFloatPixels(display->mTransformOrigin[2].GetCoordValue(),
|
2013-11-11 06:23:56 +04:00
|
|
|
aAppUnitsPerPixel);
|
|
|
|
/* Adjust based on the origin of the rectangle. */
|
|
|
|
coords[0] += NSAppUnitsToFloatPixels(boundingRect.x, aAppUnitsPerPixel);
|
|
|
|
coords[1] += NSAppUnitsToFloatPixels(boundingRect.y, aAppUnitsPerPixel);
|
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
return Point3D(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
|
|
|
*/
|
2014-08-29 22:47:30 +04:00
|
|
|
/* static */ Point3D
|
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!");
|
2015-03-20 07:12:17 +03:00
|
|
|
NS_PRECONDITION(aFrame->IsTransformed() || aFrame->StyleDisplay()->BackfaceIsHidden(),
|
2012-05-17 08:05:09 +04:00
|
|
|
"Shouldn't get a delta for an untransformed frame!");
|
2011-08-03 07:04:24 +04:00
|
|
|
|
2014-02-27 06:57:45 +04:00
|
|
|
if (!aFrame->IsTransformed()) {
|
2014-08-29 22:47:30 +04:00
|
|
|
return Point3D();
|
2014-02-27 06:57:45 +04:00
|
|
|
}
|
|
|
|
|
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?
|
2014-11-20 21:24:10 +03:00
|
|
|
nsIFrame* parent;
|
|
|
|
nsStyleContext* psc = aFrame->GetParentStyleContext(&parent);
|
|
|
|
if (!psc) {
|
2014-08-29 22:47:30 +04:00
|
|
|
return Point3D();
|
2012-09-18 02:34:21 +04:00
|
|
|
}
|
2014-11-20 21:24:10 +03:00
|
|
|
if (!parent) {
|
|
|
|
parent = aFrame->GetParent();
|
|
|
|
if (!parent) {
|
|
|
|
return Point3D();
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleDisplay* display = psc->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. */
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D result;
|
2011-08-03 07:04:24 +04:00
|
|
|
result.z = 0.0f;
|
2014-08-29 22:47:30 +04:00
|
|
|
gfx::Float* coords[2] = {&result.x, &result.y};
|
2011-08-03 07:04:24 +04:00
|
|
|
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.
|
|
|
|
*/
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleCoord &coord = display->mPerspectiveOrigin[index];
|
2011-08-03 07:04:24 +04:00
|
|
|
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 {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(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);
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D 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)
|
2015-03-20 07:12:17 +03: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)
|
|
|
|
{
|
2015-03-20 07:12:17 +03:00
|
|
|
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) {
|
2015-03-20 07:12:17 +03:00
|
|
|
parentDisp = parentStyleContext->StyleDisplay();
|
2012-09-18 02:34:21 +04:00
|
|
|
}
|
2015-03-20 07:12:17 +03:00
|
|
|
if (parentDisp && parentDisp->mChildPerspective.GetUnit() == eStyleUnit_Coord) {
|
|
|
|
mChildPerspective = parentDisp->mChildPerspective.GetCoordValue();
|
2012-09-18 02:34:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2014-05-13 15:37:55 +04:00
|
|
|
aBoundsOverride, aOutAncestor, false);
|
2012-09-18 02:34:21 +04:00
|
|
|
}
|
|
|
|
|
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,
|
2014-05-13 15:37:55 +04:00
|
|
|
nsIFrame** aOutAncestor,
|
|
|
|
bool aOffsetByOrigin)
|
2012-09-16 14:32:59 +04:00
|
|
|
{
|
2012-09-18 02:34:21 +04:00
|
|
|
FrameTransformProperties props(aFrame,
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride);
|
|
|
|
|
2014-05-13 15:37:55 +04:00
|
|
|
return GetResultingTransformMatrixInternal(props, aOrigin, aAppUnitsPerPixel,
|
|
|
|
aBoundsOverride, aOutAncestor,
|
|
|
|
aOffsetByOrigin);
|
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,
|
2014-05-13 15:37:55 +04:00
|
|
|
nsIFrame** aOutAncestor,
|
|
|
|
bool aOffsetByOrigin)
|
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
|
|
|
/* 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.
|
2014-08-01 16:31:48 +04:00
|
|
|
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.
|
|
|
|
*/
|
2014-07-23 02:05:13 +04:00
|
|
|
perspective.ChangeBasis(aProperties.mToPerspectiveOrigin - aProperties.mToTransformOrigin);
|
|
|
|
result = result * perspective;
|
2011-08-03 07:04:22 +04:00
|
|
|
}
|
2011-08-27 04:01:46 +04:00
|
|
|
|
2014-05-13 15:37:55 +04:00
|
|
|
/* Account for the -moz-transform-origin property by translating the
|
|
|
|
* coordinate space to the new origin.
|
|
|
|
*/
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D newOrigin =
|
|
|
|
Point3D(NSAppUnitsToFloatPixels(aOrigin.x, aAppUnitsPerPixel),
|
|
|
|
NSAppUnitsToFloatPixels(aOrigin.y, aAppUnitsPerPixel),
|
|
|
|
0.0f);
|
|
|
|
Point3D roundedOrigin(hasSVGTransforms ? newOrigin.x : NS_round(newOrigin.x),
|
|
|
|
hasSVGTransforms ? newOrigin.y : NS_round(newOrigin.y),
|
|
|
|
0);
|
|
|
|
Point3D offsetBetweenOrigins = roundedOrigin + aProperties.mToTransformOrigin;
|
2013-06-23 00:35:09 +04:00
|
|
|
|
|
|
|
if (frame && frame->Preserves3D()) {
|
2014-05-13 15:37:55 +04:00
|
|
|
// Include the transform set on our parent
|
|
|
|
NS_ASSERTION(frame->GetParent() &&
|
|
|
|
frame->GetParent()->IsTransformed() &&
|
|
|
|
frame->GetParent()->Preserves3DChildren(),
|
|
|
|
"Preserve3D mismatch!");
|
|
|
|
FrameTransformProperties props(frame->GetParent(),
|
|
|
|
aAppUnitsPerPixel,
|
|
|
|
nullptr);
|
2014-08-20 09:43:26 +04:00
|
|
|
|
|
|
|
// If this frame isn't transformed (but we exist for backface-visibility),
|
|
|
|
// then we're not a reference frame so no offset to origin will be added. Our
|
|
|
|
// parent transform however *is* the reference frame, so we pass true for
|
|
|
|
// aOffsetByOrigin to convert into the correct coordinate space.
|
2014-05-13 15:37:55 +04:00
|
|
|
gfx3DMatrix parent =
|
|
|
|
GetResultingTransformMatrixInternal(props,
|
|
|
|
aOrigin - frame->GetPosition(),
|
|
|
|
aAppUnitsPerPixel, nullptr,
|
2014-08-20 09:43:26 +04:00
|
|
|
aOutAncestor, !frame->IsTransformed());
|
2014-05-13 15:37:55 +04:00
|
|
|
|
|
|
|
if (aOffsetByOrigin) {
|
2015-02-02 02:12:14 +03:00
|
|
|
result.Translate(-aProperties.mToTransformOrigin);
|
|
|
|
result.TranslatePost(offsetBetweenOrigins);
|
|
|
|
} else {
|
|
|
|
result.ChangeBasis(offsetBetweenOrigins);
|
2014-05-13 15:37:55 +04:00
|
|
|
}
|
2015-02-02 02:12:14 +03:00
|
|
|
result = result * parent;
|
2014-05-13 15:37:55 +04:00
|
|
|
return result;
|
2011-08-27 04:01:46 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 15:37:55 +04:00
|
|
|
if (aOffsetByOrigin) {
|
|
|
|
// We can fold the final translation by roundedOrigin into the first matrix
|
|
|
|
// basis change translation. This is more stable against variation due to
|
|
|
|
// insufficient floating point precision than reversing the translation
|
|
|
|
// afterwards.
|
|
|
|
result.Translate(-aProperties.mToTransformOrigin);
|
|
|
|
result.TranslatePost(offsetBetweenOrigins);
|
|
|
|
} else {
|
2014-07-23 02:05:13 +04:00
|
|
|
result.ChangeBasis(offsetBetweenOrigins);
|
2014-05-13 15:37:55 +04:00
|
|
|
}
|
|
|
|
return 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)
|
|
|
|
{
|
2014-10-22 05:54:32 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(aBuilder, 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");
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::LogAsyncAnimationFailure(message,
|
|
|
|
Frame()->GetContent());
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-22 05:55:55 +04:00
|
|
|
bool
|
|
|
|
nsDisplayTransform::ShouldPrerender(nsDisplayListBuilder* aBuilder) {
|
|
|
|
if (!mMaybePrerender) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShouldPrerenderTransformedContent(aBuilder, mFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleDisplay* disp = mFrame->StyleDisplay();
|
|
|
|
if ((disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_TRANSFORM) &&
|
2014-10-22 05:55:55 +04:00
|
|
|
aBuilder->IsInWillChangeBudget(mFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
bool
|
|
|
|
nsDisplayTransform::CanUseAsyncAnimations(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
2014-10-22 05:55:55 +04:00
|
|
|
if (mMaybePrerender) {
|
|
|
|
// TODO We need to make sure that if we use async animation we actually
|
|
|
|
// pre-render even if we're out of will change budget.
|
2014-07-29 16:09:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
DebugOnly<bool> prerender = ShouldPrerenderTransformedContent(aBuilder, mFrame, true);
|
|
|
|
NS_ASSERTION(!prerender, "Something changed under us!");
|
|
|
|
return false;
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
2014-03-22 01:59:58 +04:00
|
|
|
// the ActiveLayerManager may not have been notified yet.
|
2014-10-22 05:55:55 +04:00
|
|
|
if (!ActiveLayerTracker::IsStyleMaybeAnimated(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");
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::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();
|
2014-06-24 04:12:52 +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.
|
2012-08-26 05:27:28 +04:00
|
|
|
refSize += nsSize(refSize.width / 8, refSize.height / 8);
|
2014-06-24 04:12:52 +04:00
|
|
|
nsSize frameSize = aFrame->GetVisualOverflowRectRelativeToSelf().Size();
|
2014-09-15 20:44:21 +04:00
|
|
|
nscoord maxInAppUnits = nscoord_MAX;
|
2014-06-24 04:12:52 +04:00
|
|
|
if (frameSize <= refSize) {
|
2014-09-15 20:44:21 +04:00
|
|
|
maxInAppUnits = aFrame->PresContext()->DevPixelsToAppUnits(4096);
|
2014-08-12 10:02:55 +04:00
|
|
|
nsRect visual = aFrame->GetVisualOverflowRect();
|
2014-09-15 20:44:21 +04:00
|
|
|
if (visual.width <= maxInAppUnits && visual.height <= maxInAppUnits) {
|
2014-08-12 10:02:55 +04:00
|
|
|
return true;
|
|
|
|
}
|
2012-08-26 05:27:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aLogAnimations) {
|
2014-09-15 20:44:21 +04:00
|
|
|
nsRect visual = aFrame->GetVisualOverflowRect();
|
|
|
|
|
2012-08-26 05:27:28 +04:00
|
|
|
nsCString message;
|
|
|
|
message.AppendLiteral("Performance warning: Async animation disabled because frame size (");
|
2014-06-24 04:12:52 +04:00
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(frameSize.width));
|
2012-08-26 05:27:28 +04:00
|
|
|
message.AppendLiteral(", ");
|
2014-06-24 04:12:52 +04:00
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(frameSize.height));
|
2012-08-26 05:27:28 +04:00
|
|
|
message.AppendLiteral(") is bigger than the viewport (");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(refSize.width));
|
|
|
|
message.AppendLiteral(", ");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(refSize.height));
|
2014-09-15 20:44:21 +04:00
|
|
|
message.AppendLiteral(") or the visual rectangle (");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(visual.width));
|
|
|
|
message.AppendLiteral(", ");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(visual.height));
|
|
|
|
message.AppendLiteral(") is larger than the max allowable value (");
|
|
|
|
message.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(maxInAppUnits));
|
2014-05-22 07:48:51 +04:00
|
|
|
message.Append(')');
|
2014-08-10 11:06:46 +04:00
|
|
|
AnimationPlayerCollection::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. */
|
2014-08-01 16:31:49 +04:00
|
|
|
static bool IsFrameVisible(nsIFrame* aFrame, const Matrix4x4& aMatrix)
|
2011-10-12 07:16:06 +04:00
|
|
|
{
|
|
|
|
if (aMatrix.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-20 07:12:17 +03:00
|
|
|
if (aFrame->StyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
2011-10-12 07:16:06 +04:00
|
|
|
aMatrix.IsBackfaceVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-01 16:31:48 +04:00
|
|
|
const Matrix4x4&
|
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();
|
2014-08-29 22:47:30 +04:00
|
|
|
Point3D newOrigin =
|
|
|
|
Point3D(NSAppUnitsToFloatPixels(mToReferenceFrame.x, scale),
|
|
|
|
NSAppUnitsToFloatPixels(mToReferenceFrame.y, scale),
|
|
|
|
0.0f);
|
2012-09-20 03:14:07 +04:00
|
|
|
if (mTransformGetter) {
|
2014-01-20 10:56:55 +04:00
|
|
|
mTransform = mTransformGetter(mFrame, scale);
|
2014-08-01 16:31:48 +04:00
|
|
|
mTransform.ChangeBasis(newOrigin.x, newOrigin.y, newOrigin.z);
|
2012-09-20 03:14:07 +04:00
|
|
|
} else {
|
2012-09-26 02:47:41 +04:00
|
|
|
/**
|
2014-05-13 15:37:55 +04:00
|
|
|
* Passing true as the final argument means that we want to shift the
|
|
|
|
* coordinates 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.
|
2012-09-26 02:47:41 +04:00
|
|
|
*/
|
2014-08-01 16:31:48 +04:00
|
|
|
mTransform = ToMatrix4x4(
|
2014-05-13 15:37:55 +04:00
|
|
|
GetResultingTransformMatrix(mFrame, ToReferenceFrame(), scale,
|
2014-08-20 09:43:26 +04:00
|
|
|
nullptr, nullptr, mFrame->IsTransformed()));
|
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)
|
|
|
|
{
|
2014-10-22 05:55:55 +04:00
|
|
|
return ShouldPrerender(aBuilder);
|
2013-03-19 17:08:29 +04:00
|
|
|
}
|
|
|
|
|
2010-08-02 07:07:04 +04:00
|
|
|
already_AddRefed<Layer> nsDisplayTransform::BuildLayer(nsDisplayListBuilder *aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager *aManager,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2008-09-13 13:42:11 +04:00
|
|
|
{
|
2014-08-01 16:31:49 +04:00
|
|
|
const Matrix4x4& newTransformMatrix = GetTransform();
|
2011-08-03 07:04:22 +04:00
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
if (mFrame->StyleDisplay()->mBackfaceVisibility == NS_STYLE_BACKFACE_VISIBILITY_HIDDEN &&
|
2013-03-21 06:33:00 +04:00
|
|
|
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
|
|
|
|
2014-10-22 05:55:55 +04:00
|
|
|
uint32_t flags = ShouldPrerender(aBuilder) ?
|
2013-12-07 22:33:09 +04:00
|
|
|
FrameLayerBuilder::CONTAINER_NOT_CLIPPED_BY_ANCESTORS : 0;
|
2015-02-25 19:47:22 +03:00
|
|
|
flags |= FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR;
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2014-06-09 08:48:00 +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
|
|
|
|
2014-03-05 08:13:21 +04:00
|
|
|
nsDisplayListBuilder::AddAnimationsAndTransitionsToLayer(container, aBuilder,
|
|
|
|
this, mFrame,
|
|
|
|
eCSSProperty_transform);
|
2014-10-22 05:55:55 +04:00
|
|
|
if (ShouldPrerender(aBuilder)) {
|
2012-10-03 09:55:52 +04:00
|
|
|
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.
|
2014-10-22 05:54:32 +04:00
|
|
|
if (ActiveLayerTracker::IsStyleAnimated(aBuilder, 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;
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 22:14:34 +04:00
|
|
|
|
2015-03-20 07:12:17 +03:00
|
|
|
const nsStyleDisplay* disp = mFrame->StyleDisplay();
|
|
|
|
if ((disp->mWillChangeBitField & NS_STYLE_WILL_CHANGE_TRANSFORM)) {
|
2013-11-22 22:14:34 +04:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2014-02-18 05:26:57 +04:00
|
|
|
// Expect the child display items to have this frame as their animated
|
|
|
|
// geometry root (since it will be their reference frame). If they have a
|
|
|
|
// different animated geometry root, we'll make this an active layer so the
|
|
|
|
// animation can be accelerated.
|
|
|
|
return RequiredLayerStateForChildren(aBuilder, aManager, aParameters,
|
|
|
|
*mStoredList.GetChildren(), Frame());
|
2008-09-13 13:42:11 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsDisplayTransform::ComputeVisibility(nsDisplayListBuilder *aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion *aVisibleRegion)
|
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-10-22 05:55:55 +04:00
|
|
|
if (ShouldPrerender(aBuilder) ||
|
2014-02-04 03:25:23 +04:00
|
|
|
!UntransformVisibleRect(aBuilder, &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-08-01 16:31:49 +04:00
|
|
|
Matrix4x4 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. */
|
2014-08-29 22:47:30 +04:00
|
|
|
matrix.Invert();
|
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
|
2014-08-29 22:47:30 +04:00
|
|
|
Point4D point = matrix.ProjectPoint(Point(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor)));
|
2014-07-08 08:55:42 +04:00
|
|
|
if (!point.HasPositiveWCoord()) {
|
2014-02-04 03:25:23 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-04-08 04:31:26 +04:00
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point point2d = point.As2DPoint();
|
2014-07-08 08:55:42 +04:00
|
|
|
|
|
|
|
resultingRect = nsRect(NSFloatPixelsToAppUnits(float(point2d.x), factor),
|
|
|
|
NSFloatPixelsToAppUnits(float(point2d.y), factor),
|
2010-04-08 04:31:26 +04:00
|
|
|
1, 1);
|
|
|
|
|
|
|
|
} else {
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect originalRect(NSAppUnitsToFloatPixels(aRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aRect.height, factor));
|
2010-04-08 04:31:26 +04:00
|
|
|
|
2014-07-08 08:55:42 +04:00
|
|
|
|
|
|
|
bool snap;
|
|
|
|
nsRect childBounds = mStoredList.GetBounds(aBuilder, &snap);
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect childGfxBounds(NSAppUnitsToFloatPixels(childBounds.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.height, factor));
|
2015-03-13 23:42:00 +03:00
|
|
|
|
|
|
|
Rect rect = matrix.ProjectRectBounds(originalRect, childGfxBounds);
|
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
|
|
|
|
2014-02-04 03:25:23 +04:00
|
|
|
if (resultingRect.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
2014-02-04 03:25:23 +04:00
|
|
|
nsDisplayTransform::GetHitDepthAtPoint(nsDisplayListBuilder* aBuilder, const nsPoint& aPoint)
|
2011-10-07 01:24:02 +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-08-01 16:31:49 +04:00
|
|
|
Matrix4x4 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
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Matrix4x4 inverse = matrix;
|
|
|
|
inverse.Invert();
|
|
|
|
Point4D point = inverse.ProjectPoint(Point(NSAppUnitsToFloatPixels(aPoint.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aPoint.y, factor)));
|
2014-07-08 08:55:42 +04:00
|
|
|
NS_ASSERTION(point.HasPositiveWCoord(), "Why are we trying to get the depth for a point we didn't hit?");
|
2014-02-04 03:25:23 +04:00
|
|
|
|
2014-08-29 22:47:30 +04:00
|
|
|
Point point2d = point.As2DPoint();
|
2011-10-07 01:24:02 +04:00
|
|
|
|
2014-08-01 16:31:49 +04:00
|
|
|
Point3D transformed = matrix * Point3D(point2d.x, point2d.y, 0);
|
2011-10-07 01:24:02 +04:00
|
|
|
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
|
|
|
{
|
2014-10-22 05:55:55 +04:00
|
|
|
nsRect untransformedBounds = MaybePrerender() ?
|
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-08-01 16:31:48 +04:00
|
|
|
To3DMatrix(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;
|
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.
|
2014-10-22 05:55:55 +04:00
|
|
|
if (MaybePrerender() ||
|
2014-02-04 03:25:23 +04:00
|
|
|
!UntransformVisibleRect(aBuilder, &untransformedVisible)) {
|
2011-07-23 02:28:51 +04:00
|
|
|
return nsRegion();
|
|
|
|
}
|
2012-07-31 21:28:21 +04:00
|
|
|
|
2014-08-01 16:31:48 +04:00
|
|
|
const Matrix4x4& matrix = GetTransform();
|
2012-04-10 15:24:18 +04:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
2014-08-01 16:31:48 +04:00
|
|
|
Matrix 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)) {
|
2014-06-09 08:47:59 +04:00
|
|
|
result = mVisibleRect.Intersect(GetBounds(aBuilder, &tmpSnap));
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
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-02-04 03:25:23 +04:00
|
|
|
if (!UntransformVisibleRect(aBuilder, &untransformedVisible)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-07-23 02:28:51 +04:00
|
|
|
}
|
2014-08-01 16:31:48 +04:00
|
|
|
const Matrix4x4& matrix = GetTransform();
|
2011-07-23 02:28:07 +04:00
|
|
|
|
2014-08-01 16:31:48 +04:00
|
|
|
Matrix matrix2d;
|
2011-07-23 02:28:51 +04:00
|
|
|
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!
|
|
|
|
*/
|
2014-06-09 08:47:59 +04:00
|
|
|
mStoredList.MergeFromTrackingMergedFrames(&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);
|
|
|
|
}
|
|
|
|
|
2014-04-23 17:26:52 +04:00
|
|
|
bool nsDisplayTransform::UntransformRect(const nsRect &aTransformedBounds,
|
|
|
|
const nsRect &aChildBounds,
|
|
|
|
const nsIFrame* aFrame,
|
|
|
|
const nsPoint &aOrigin,
|
|
|
|
nsRect *aOutRect)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "Can't take the transform based on a null frame!");
|
|
|
|
|
|
|
|
float factor = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
|
|
|
gfx3DMatrix transform = GetResultingTransformMatrix(aFrame, aOrigin, factor, nullptr);
|
|
|
|
if (transform.IsSingular()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect result(NSAppUnitsToFloatPixels(aTransformedBounds.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aTransformedBounds.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aTransformedBounds.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aTransformedBounds.height, factor));
|
2014-04-23 17:26:52 +04:00
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect childGfxBounds(NSAppUnitsToFloatPixels(aChildBounds.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aChildBounds.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aChildBounds.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(aChildBounds.height, factor));
|
2014-04-23 17:26:52 +04:00
|
|
|
|
2015-03-13 23:42:00 +03:00
|
|
|
result = ToMatrix4x4(transform.Inverse()).ProjectRectBounds(result, childGfxBounds);
|
2014-08-22 17:40:02 +04:00
|
|
|
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(ThebesRect(result), factor);
|
2014-04-23 17:26:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-04 03:25:23 +04:00
|
|
|
bool nsDisplayTransform::UntransformVisibleRect(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRect *aOutRect)
|
2012-02-14 13:12:49 +04:00
|
|
|
{
|
2014-08-01 16:31:48 +04:00
|
|
|
const gfx3DMatrix& matrix = To3DMatrix(GetTransform());
|
2014-02-04 03:25:22 +04:00
|
|
|
if (matrix.IsSingular())
|
2012-02-14 13:12:49 +04:00
|
|
|
return false;
|
|
|
|
|
2014-02-04 03:25:22 +04:00
|
|
|
// GetTransform always operates in dev pixels.
|
|
|
|
float factor = mFrame->PresContext()->AppUnitsPerDevPixel();
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect result(NSAppUnitsToFloatPixels(mVisibleRect.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(mVisibleRect.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(mVisibleRect.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(mVisibleRect.height, factor));
|
2012-02-14 13:12:49 +04:00
|
|
|
|
2014-02-04 03:25:23 +04:00
|
|
|
bool snap;
|
|
|
|
nsRect childBounds = mStoredList.GetBounds(aBuilder, &snap);
|
2014-08-22 17:40:02 +04:00
|
|
|
Rect childGfxBounds(NSAppUnitsToFloatPixels(childBounds.x, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.y, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.width, factor),
|
|
|
|
NSAppUnitsToFloatPixels(childBounds.height, factor));
|
2014-02-04 03:25:23 +04:00
|
|
|
|
2012-02-14 13:12:49 +04:00
|
|
|
/* We want to untransform the matrix, so invert the transformation first! */
|
2015-03-13 23:42:00 +03:00
|
|
|
result = ToMatrix4x4(matrix.Inverse()).ProjectRectBounds(result, childGfxBounds);
|
2012-02-14 13:12:49 +04:00
|
|
|
|
2014-08-22 17:40:02 +04:00
|
|
|
*aOutRect = nsLayoutUtils::RoundGfxRectToAppRect(ThebesRect(result), factor);
|
2012-02-14 13:12:49 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 06:36:26 +04:00
|
|
|
void
|
2014-11-25 16:45:19 +03:00
|
|
|
nsDisplayTransform::WriteDebugInfo(std::stringstream& aStream)
|
2014-05-22 06:36:26 +04:00
|
|
|
{
|
2014-11-25 16:45:19 +03:00
|
|
|
AppendToString(aStream, GetTransform());
|
2014-05-22 06:36:26 +04:00
|
|
|
}
|
|
|
|
|
2015-02-25 17:32:28 +03:00
|
|
|
nsDisplayItemGeometry*
|
|
|
|
nsCharClipDisplayItem::AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
return new nsCharClipGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCharClipDisplayItem::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsCharClipGeometry* geometry = static_cast<const nsCharClipGeometry*>(aGeometry);
|
|
|
|
|
|
|
|
bool snap;
|
|
|
|
nsRect newRect = geometry->mBounds;
|
|
|
|
nsRect oldRect = GetBounds(aBuilder, &snap);
|
|
|
|
if (mLeftEdge != geometry->mLeftEdge ||
|
|
|
|
mRightEdge != geometry->mRightEdge ||
|
|
|
|
!oldRect.IsEqualInterior(newRect) ||
|
|
|
|
!geometry->mBorderRect.IsEqualInterior(GetBorderRect())) {
|
|
|
|
aInvalidRegion->Or(oldRect, newRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2014-07-09 23:25:31 +04:00
|
|
|
nsDisplayVR::nsDisplayVR(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
|
|
|
nsDisplayList* aList, mozilla::gfx::VRHMDInfo* aHMD)
|
|
|
|
: nsDisplayOwnLayer(aBuilder, aFrame, aList)
|
|
|
|
, mHMD(aHMD)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsDisplayVR::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
|
|
|
{
|
|
|
|
ContainerLayerParameters newContainerParameters = aContainerParameters;
|
2015-02-25 19:47:22 +03:00
|
|
|
uint32_t flags = FrameLayerBuilder::CONTAINER_NOT_CLIPPED_BY_ANCESTORS |
|
|
|
|
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR;
|
2014-07-09 23:25:31 +04:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
|
|
|
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
|
|
|
|
newContainerParameters, nullptr, flags);
|
|
|
|
|
2014-07-09 23:26:18 +04:00
|
|
|
container->SetVRHMDInfo(mHMD);
|
2014-07-09 23:25:31 +04:00
|
|
|
container->SetUserData(nsIFrame::LayerIsPrerenderedDataKey(),
|
|
|
|
/*the value is irrelevant*/nullptr);
|
|
|
|
|
|
|
|
return container.forget();
|
|
|
|
}
|
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)
|
|
|
|
{
|
2014-10-31 23:08:54 +03:00
|
|
|
nsSVGIntegrationUtils::PaintFramesWithEffects(*aCtx->ThebesContext(), mFrame,
|
2012-07-17 21:03:51 +04:00
|
|
|
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);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!svgChildFrame || !mFrame->GetContent()->IsSVGElement()) {
|
2012-07-20 22:12:29 +04:00
|
|
|
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 =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(mFrame);
|
2012-07-17 21:03:51 +04:00
|
|
|
nsSVGEffects::EffectProperties effectProperties =
|
|
|
|
nsSVGEffects::GetEffectProperties(firstFrame);
|
|
|
|
|
2014-02-24 19:22:58 +04:00
|
|
|
bool isOK = effectProperties.HasNoFilterOrHasValidFilter();
|
2012-07-18 18:28:53 +04:00
|
|
|
effectProperties.GetClipPathFrame(&isOK);
|
|
|
|
effectProperties.GetMaskFrame(&isOK);
|
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;
|
2014-02-24 19:22:58 +04:00
|
|
|
if (effectProperties.HasValidFilter()) {
|
2014-01-10 07:03:24 +04:00
|
|
|
newContainerParameters.mDisableSubpixelAntialiasingInDescendants = true;
|
|
|
|
}
|
|
|
|
|
2012-08-21 08:06:46 +04:00
|
|
|
nsRefPtr<ContainerLayer> container = aManager->GetLayerBuilder()->
|
2014-06-09 08:48:00 +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,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion) {
|
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));
|
2014-06-23 08:24:51 +04:00
|
|
|
mList.ComputeVisibilityForSublist(aBuilder, &childrenVisible, r);
|
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
|
|
|
|
2014-08-30 20:22:31 +04:00
|
|
|
gfxRect
|
|
|
|
nsDisplaySVGEffects::BBoxInUserSpace() const
|
|
|
|
{
|
|
|
|
return nsSVGUtils::GetBBox(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxPoint
|
|
|
|
nsDisplaySVGEffects::UserSpaceOffset() const
|
|
|
|
{
|
|
|
|
return nsSVGUtils::FrameSpaceInCSSPxToUserSpaceOffset(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDisplaySVGEffects::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsDisplaySVGEffectsGeometry* geometry =
|
|
|
|
static_cast<const nsDisplaySVGEffectsGeometry*>(aGeometry);
|
|
|
|
bool snap;
|
|
|
|
nsRect bounds = GetBounds(aBuilder, &snap);
|
|
|
|
if (geometry->mFrameOffsetToReferenceFrame != ToReferenceFrame() ||
|
|
|
|
geometry->mUserSpaceOffset != UserSpaceOffset() ||
|
|
|
|
!geometry->mBBox.IsEqualInterior(BBoxInUserSpace())) {
|
|
|
|
// Filter and mask output can depend on the location of the frame's user
|
|
|
|
// space and on the frame's BBox. We need to invalidate if either of these
|
|
|
|
// change relative to the reference frame.
|
|
|
|
// Invalidations from our inactive layer manager are not enough to catch
|
|
|
|
// some of these cases because filters can produce output even if there's
|
|
|
|
// nothing in the filter input.
|
|
|
|
aInvalidRegion->Or(bounds, geometry->mBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 =
|
2014-02-07 05:45:31 +04:00
|
|
|
nsLayoutUtils::FirstContinuationOrIBSplitSibling(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;
|
|
|
|
}
|
2014-02-24 19:22:58 +04:00
|
|
|
if (effectProperties.HasValidFilter()) {
|
2011-11-17 07:44:16 +04:00
|
|
|
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
|
|
|
|
|