2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-01-25 03:41:18 +03: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/. */
|
|
|
|
#ifndef mozilla_gfx_layers_LayerAttributes_h
|
|
|
|
#define mozilla_gfx_layers_LayerAttributes_h
|
|
|
|
|
2017-11-21 03:00:34 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-01-25 03:41:18 +03:00
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
|
2017-01-25 03:41:18 +03:00
|
|
|
namespace IPC {
|
|
|
|
template <typename T> struct ParamTraits;
|
|
|
|
} // namespace IPC
|
|
|
|
|
2017-01-25 03:41:18 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2017-05-10 21:02:15 +03:00
|
|
|
// Data stored for scroll thumb container layers.
|
|
|
|
struct ScrollThumbData {
|
|
|
|
ScrollThumbData()
|
2017-11-21 03:00:34 +03:00
|
|
|
: mThumbRatio(0.0f)
|
2017-05-05 23:17:06 +03:00
|
|
|
, mIsAsyncDraggable(false)
|
2017-05-04 03:37:14 +03:00
|
|
|
{}
|
|
|
|
ScrollThumbData(ScrollDirection aDirection,
|
|
|
|
float aThumbRatio,
|
2017-05-11 02:24:26 +03:00
|
|
|
CSSCoord aThumbStart,
|
2017-05-05 23:17:06 +03:00
|
|
|
CSSCoord aThumbLength,
|
2017-05-05 22:54:27 +03:00
|
|
|
bool aIsAsyncDraggable,
|
|
|
|
CSSCoord aScrollTrackStart,
|
|
|
|
CSSCoord aScrollTrackLength)
|
2017-11-21 03:00:34 +03:00
|
|
|
: mDirection(Some(aDirection))
|
2017-05-04 03:37:14 +03:00
|
|
|
, mThumbRatio(aThumbRatio)
|
2017-05-11 02:24:26 +03:00
|
|
|
, mThumbStart(aThumbStart)
|
2017-05-04 03:37:14 +03:00
|
|
|
, mThumbLength(aThumbLength)
|
2017-05-05 23:17:06 +03:00
|
|
|
, mIsAsyncDraggable(aIsAsyncDraggable)
|
2017-05-05 22:54:27 +03:00
|
|
|
, mScrollTrackStart(aScrollTrackStart)
|
|
|
|
, mScrollTrackLength(aScrollTrackLength)
|
2017-05-04 03:37:14 +03:00
|
|
|
{}
|
2017-05-10 21:02:15 +03:00
|
|
|
|
2017-11-21 03:00:34 +03:00
|
|
|
Maybe<ScrollDirection> mDirection;
|
2017-05-10 21:02:15 +03:00
|
|
|
// The scrollbar thumb ratio is the ratio of the thumb position (in the CSS
|
|
|
|
// pixels of the scrollframe's parent's space) to the scroll position (in the
|
|
|
|
// CSS pixels of the scrollframe's space).
|
|
|
|
float mThumbRatio;
|
2017-05-11 02:24:26 +03:00
|
|
|
CSSCoord mThumbStart;
|
2017-05-04 03:37:14 +03:00
|
|
|
CSSCoord mThumbLength;
|
2017-05-05 23:17:06 +03:00
|
|
|
// Whether the scrollbar thumb can be dragged asynchronously.
|
|
|
|
bool mIsAsyncDraggable;
|
2017-05-05 22:54:27 +03:00
|
|
|
CSSCoord mScrollTrackStart;
|
|
|
|
CSSCoord mScrollTrackLength;
|
2017-05-10 21:02:15 +03:00
|
|
|
|
|
|
|
bool operator==(const ScrollThumbData& aOther) const {
|
|
|
|
return mDirection == aOther.mDirection &&
|
2017-05-04 03:37:14 +03:00
|
|
|
mThumbRatio == aOther.mThumbRatio &&
|
2017-05-11 02:24:26 +03:00
|
|
|
mThumbStart == aOther.mThumbStart &&
|
2017-05-05 23:17:06 +03:00
|
|
|
mThumbLength == aOther.mThumbLength &&
|
2017-05-05 22:54:27 +03:00
|
|
|
mIsAsyncDraggable == aOther.mIsAsyncDraggable &&
|
|
|
|
mScrollTrackStart == aOther.mScrollTrackStart &&
|
|
|
|
mScrollTrackLength == aOther.mScrollTrackLength;
|
2017-05-10 21:02:15 +03:00
|
|
|
}
|
|
|
|
bool operator!=(const ScrollThumbData& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-25 03:41:18 +03:00
|
|
|
// Infrequently changing layer attributes that require no special
|
|
|
|
// serialization work.
|
|
|
|
class SimpleLayerAttributes final
|
|
|
|
{
|
2017-01-25 03:41:18 +03:00
|
|
|
friend struct IPC::ParamTraits<mozilla::layers::SimpleLayerAttributes>;
|
2017-01-25 03:41:18 +03:00
|
|
|
public:
|
|
|
|
SimpleLayerAttributes()
|
|
|
|
: mTransformIsPerspective(false),
|
|
|
|
mPostXScale(1.0f),
|
|
|
|
mPostYScale(1.0f),
|
|
|
|
mContentFlags(0),
|
|
|
|
mOpacity(1.0f),
|
|
|
|
mIsFixedPosition(false),
|
|
|
|
mScrollbarTargetContainerId(FrameMetrics::NULL_SCROLL_ID),
|
|
|
|
mMixBlendMode(gfx::CompositionOp::OP_OVER),
|
|
|
|
mForceIsolatedGroup(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setters.
|
|
|
|
// All set methods return true if values changed, false otherwise.
|
|
|
|
//
|
|
|
|
|
|
|
|
bool SetPostScale(float aXScale, float aYScale) {
|
|
|
|
if (mPostXScale == aXScale && mPostYScale == aYScale) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mPostXScale = aXScale;
|
|
|
|
mPostYScale = aYScale;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetContentFlags(uint32_t aFlags) {
|
|
|
|
if (aFlags == mContentFlags) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mContentFlags = aFlags;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetOpacity(float aOpacity) {
|
|
|
|
if (aOpacity == mOpacity) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mOpacity = aOpacity;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetIsFixedPosition(bool aFixedPosition) {
|
|
|
|
if (mIsFixedPosition == aFixedPosition) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mIsFixedPosition = aFixedPosition;
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-10 21:02:15 +03:00
|
|
|
bool SetScrollThumbData(FrameMetrics::ViewID aScrollId, const ScrollThumbData& aThumbData) {
|
2017-01-25 03:41:18 +03:00
|
|
|
if (mScrollbarTargetContainerId == aScrollId &&
|
2017-05-10 21:02:15 +03:00
|
|
|
mThumbData == aThumbData)
|
2017-01-25 03:41:18 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mScrollbarTargetContainerId = aScrollId;
|
2017-05-10 21:02:15 +03:00
|
|
|
mThumbData = aThumbData;
|
2017-01-25 03:41:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-25 00:23:05 +03:00
|
|
|
bool SetScrollbarContainer(FrameMetrics::ViewID aScrollId,
|
|
|
|
ScrollDirection aDirection) {
|
|
|
|
if (mScrollbarContainerDirection &&
|
|
|
|
*mScrollbarContainerDirection == aDirection &&
|
|
|
|
mScrollbarTargetContainerId == aScrollId) {
|
2017-01-25 03:41:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-25 00:23:05 +03:00
|
|
|
mScrollbarContainerDirection = Some(aDirection);
|
2017-02-16 01:40:03 +03:00
|
|
|
mScrollbarTargetContainerId = aScrollId;
|
2017-01-25 03:41:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetMixBlendMode(gfx::CompositionOp aMixBlendMode) {
|
|
|
|
if (mMixBlendMode == aMixBlendMode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mMixBlendMode = aMixBlendMode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetForceIsolatedGroup(bool aForceIsolatedGroup) {
|
|
|
|
if (mForceIsolatedGroup == aForceIsolatedGroup) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mForceIsolatedGroup = aForceIsolatedGroup;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetTransform(const gfx::Matrix4x4& aMatrix) {
|
|
|
|
if (mTransform == aMatrix) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mTransform = aMatrix;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetTransformIsPerspective(bool aIsPerspective) {
|
|
|
|
if (mTransformIsPerspective == aIsPerspective) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mTransformIsPerspective = aIsPerspective;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetScrolledClip(const Maybe<LayerClip>& aScrolledClip) {
|
|
|
|
if (mScrolledClip == aScrolledClip) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mScrolledClip = aScrolledClip;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool SetFixedPositionData(FrameMetrics::ViewID aScrollId,
|
|
|
|
const LayerPoint& aAnchor,
|
|
|
|
int32_t aSides)
|
|
|
|
{
|
|
|
|
if (mFixedPositionData &&
|
|
|
|
mFixedPositionData->mScrollId == aScrollId &&
|
|
|
|
mFixedPositionData->mAnchor == aAnchor &&
|
|
|
|
mFixedPositionData->mSides == aSides) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mFixedPositionData) {
|
|
|
|
mFixedPositionData.emplace();
|
|
|
|
}
|
|
|
|
mFixedPositionData->mScrollId = aScrollId;
|
|
|
|
mFixedPositionData->mAnchor = aAnchor;
|
|
|
|
mFixedPositionData->mSides = aSides;
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-06 02:08:18 +03:00
|
|
|
bool SetStickyPositionData(FrameMetrics::ViewID aScrollId,
|
|
|
|
LayerRectAbsolute aOuter, LayerRectAbsolute aInner)
|
2017-01-25 03:41:18 +03:00
|
|
|
{
|
|
|
|
if (mStickyPositionData &&
|
|
|
|
mStickyPositionData->mOuter.IsEqualEdges(aOuter) &&
|
|
|
|
mStickyPositionData->mInner.IsEqualEdges(aInner)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mStickyPositionData) {
|
|
|
|
mStickyPositionData.emplace();
|
|
|
|
}
|
|
|
|
mStickyPositionData->mScrollId = aScrollId;
|
|
|
|
mStickyPositionData->mOuter = aOuter;
|
|
|
|
mStickyPositionData->mInner = aInner;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-14 07:25:16 +03:00
|
|
|
// This returns true if scrolling info is equivalent for the purposes of
|
|
|
|
// APZ hit testing.
|
|
|
|
bool HitTestingInfoIsEqual(const SimpleLayerAttributes& aOther) const {
|
2017-11-25 00:23:05 +03:00
|
|
|
if (mScrollbarContainerDirection != aOther.mScrollbarContainerDirection) {
|
2017-04-14 07:25:16 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mScrollbarTargetContainerId != aOther.mScrollbarTargetContainerId) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-10 21:02:15 +03:00
|
|
|
if (mThumbData != aOther.mThumbData) {
|
2017-04-14 07:25:16 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (FixedPositionScrollContainerId() != aOther.FixedPositionScrollContainerId()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (mTransform != aOther.mTransform) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-25 03:41:18 +03:00
|
|
|
//
|
|
|
|
// Getters.
|
|
|
|
//
|
|
|
|
|
|
|
|
float PostXScale() const {
|
|
|
|
return mPostXScale;
|
|
|
|
}
|
|
|
|
float PostYScale() const {
|
|
|
|
return mPostYScale;
|
|
|
|
}
|
|
|
|
uint32_t ContentFlags() const {
|
|
|
|
return mContentFlags;
|
|
|
|
}
|
|
|
|
float Opacity() const {
|
|
|
|
return mOpacity;
|
|
|
|
}
|
|
|
|
bool IsFixedPosition() const {
|
|
|
|
return mIsFixedPosition;
|
|
|
|
}
|
|
|
|
FrameMetrics::ViewID ScrollbarTargetContainerId() const {
|
|
|
|
return mScrollbarTargetContainerId;
|
|
|
|
}
|
2017-05-10 21:02:15 +03:00
|
|
|
const ScrollThumbData& ThumbData() const {
|
|
|
|
return mThumbData;
|
2017-01-25 03:41:18 +03:00
|
|
|
}
|
2017-11-25 00:23:05 +03:00
|
|
|
Maybe<ScrollDirection> GetScrollbarContainerDirection() const {
|
|
|
|
return mScrollbarContainerDirection;
|
2017-01-25 03:41:18 +03:00
|
|
|
}
|
|
|
|
gfx::CompositionOp MixBlendMode() const {
|
|
|
|
return mMixBlendMode;
|
|
|
|
}
|
|
|
|
bool ForceIsolatedGroup() const {
|
|
|
|
return mForceIsolatedGroup;
|
|
|
|
}
|
|
|
|
const gfx::Matrix4x4& Transform() const {
|
|
|
|
return mTransform;
|
|
|
|
}
|
|
|
|
bool TransformIsPerspective() const {
|
|
|
|
return mTransformIsPerspective;
|
|
|
|
}
|
|
|
|
const Maybe<LayerClip>& ScrolledClip() const {
|
|
|
|
return mScrolledClip;
|
|
|
|
}
|
|
|
|
FrameMetrics::ViewID FixedPositionScrollContainerId() const {
|
|
|
|
return mFixedPositionData
|
|
|
|
? mFixedPositionData->mScrollId
|
|
|
|
: FrameMetrics::NULL_SCROLL_ID;
|
|
|
|
}
|
|
|
|
LayerPoint FixedPositionAnchor() const {
|
|
|
|
return mFixedPositionData ? mFixedPositionData->mAnchor : LayerPoint();
|
|
|
|
}
|
|
|
|
int32_t FixedPositionSides() const {
|
|
|
|
return mFixedPositionData ? mFixedPositionData->mSides : eSideBitsNone;
|
|
|
|
}
|
|
|
|
bool IsStickyPosition() const {
|
|
|
|
return !!mStickyPositionData;
|
|
|
|
}
|
|
|
|
FrameMetrics::ViewID StickyScrollContainerId() const {
|
|
|
|
return mStickyPositionData->mScrollId;
|
|
|
|
}
|
2018-03-06 02:08:18 +03:00
|
|
|
const LayerRectAbsolute& StickyScrollRangeOuter() const {
|
2017-01-25 03:41:18 +03:00
|
|
|
return mStickyPositionData->mOuter;
|
|
|
|
}
|
2018-03-06 02:08:18 +03:00
|
|
|
const LayerRectAbsolute& StickyScrollRangeInner() const {
|
2017-01-25 03:41:18 +03:00
|
|
|
return mStickyPositionData->mInner;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(const SimpleLayerAttributes& aOther) const {
|
2017-04-21 05:02:15 +03:00
|
|
|
return mTransform == aOther.mTransform &&
|
2017-01-25 03:41:18 +03:00
|
|
|
mTransformIsPerspective == aOther.mTransformIsPerspective &&
|
|
|
|
mScrolledClip == aOther.mScrolledClip &&
|
|
|
|
mPostXScale == aOther.mPostXScale &&
|
|
|
|
mPostYScale == aOther.mPostYScale &&
|
|
|
|
mContentFlags == aOther.mContentFlags &&
|
|
|
|
mOpacity == aOther.mOpacity &&
|
|
|
|
mIsFixedPosition == aOther.mIsFixedPosition &&
|
|
|
|
mScrollbarTargetContainerId == aOther.mScrollbarTargetContainerId &&
|
2017-05-10 21:02:15 +03:00
|
|
|
mThumbData == aOther.mThumbData &&
|
2017-11-25 00:23:05 +03:00
|
|
|
mScrollbarContainerDirection == aOther.mScrollbarContainerDirection &&
|
2017-01-25 03:41:18 +03:00
|
|
|
mMixBlendMode == aOther.mMixBlendMode &&
|
|
|
|
mForceIsolatedGroup == aOther.mForceIsolatedGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfx::Matrix4x4 mTransform;
|
|
|
|
bool mTransformIsPerspective;
|
|
|
|
Maybe<LayerClip> mScrolledClip;
|
|
|
|
float mPostXScale;
|
|
|
|
float mPostYScale;
|
|
|
|
uint32_t mContentFlags;
|
|
|
|
float mOpacity;
|
|
|
|
bool mIsFixedPosition;
|
|
|
|
uint64_t mScrollbarTargetContainerId;
|
2017-05-10 21:02:15 +03:00
|
|
|
ScrollThumbData mThumbData;
|
2017-11-25 00:23:05 +03:00
|
|
|
Maybe<ScrollDirection> mScrollbarContainerDirection;
|
2017-01-25 03:41:18 +03:00
|
|
|
gfx::CompositionOp mMixBlendMode;
|
|
|
|
bool mForceIsolatedGroup;
|
|
|
|
|
|
|
|
struct FixedPositionData {
|
|
|
|
FrameMetrics::ViewID mScrollId;
|
|
|
|
LayerPoint mAnchor;
|
|
|
|
int32_t mSides;
|
|
|
|
};
|
|
|
|
Maybe<FixedPositionData> mFixedPositionData;
|
|
|
|
|
|
|
|
struct StickyPositionData {
|
|
|
|
FrameMetrics::ViewID mScrollId;
|
2018-03-06 02:08:18 +03:00
|
|
|
LayerRectAbsolute mOuter;
|
|
|
|
LayerRectAbsolute mInner;
|
2017-01-25 03:41:18 +03:00
|
|
|
};
|
|
|
|
Maybe<StickyPositionData> mStickyPositionData;
|
|
|
|
|
|
|
|
// This class may only contain plain-old-data members that can be safely
|
|
|
|
// copied over IPC. Make sure to add new members to operator ==.
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_gfx_layers_LayerAttributes_h
|