Bug 1349750 - Group scroll thumb-related information in Layer into a ScrollThumbData structure. r=kats

The patch also renames Layer::SetScrollbarData() to Layer::SetScrollThumbData()
for clarity.

MozReview-Commit-ID: DVwJ3DMl3Zs

--HG--
extra : rebase_source : 7b2bfccf1351c82bb16296635e69d5488c87a50f
This commit is contained in:
Botond Ballo 2017-05-10 14:02:15 -04:00
Родитель 4b4e7d2ae0
Коммит 6c0eea50b3
10 изменённых файлов: 73 добавлений и 49 удалений

Просмотреть файл

@ -17,6 +17,28 @@ template <typename T> struct ParamTraits;
namespace mozilla {
namespace layers {
// Data stored for scroll thumb container layers.
struct ScrollThumbData {
ScrollThumbData()
: mDirection(ScrollDirection::NONE), mThumbRatio(0.0f) {}
ScrollThumbData(ScrollDirection aDirection, float aThumbRatio)
: mDirection(aDirection), mThumbRatio(aThumbRatio) {}
ScrollDirection mDirection;
// 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;
bool operator==(const ScrollThumbData& aOther) const {
return mDirection == aOther.mDirection &&
mThumbRatio == aOther.mThumbRatio;
}
bool operator!=(const ScrollThumbData& aOther) const {
return !(*this == aOther);
}
};
// Infrequently changing layer attributes that require no special
// serialization work.
class SimpleLayerAttributes final
@ -31,8 +53,6 @@ public:
mOpacity(1.0f),
mIsFixedPosition(false),
mScrollbarTargetContainerId(FrameMetrics::NULL_SCROLL_ID),
mScrollbarDirection(ScrollDirection::NONE),
mScrollbarThumbRatio(0.0f),
mIsScrollbarContainer(false),
mMixBlendMode(gfx::CompositionOp::OP_OVER),
mForceIsolatedGroup(false)
@ -73,16 +93,14 @@ public:
mIsFixedPosition = aFixedPosition;
return true;
}
bool SetScrollbarData(FrameMetrics::ViewID aScrollId, ScrollDirection aDir, float aThumbRatio) {
bool SetScrollThumbData(FrameMetrics::ViewID aScrollId, const ScrollThumbData& aThumbData) {
if (mScrollbarTargetContainerId == aScrollId &&
mScrollbarDirection == aDir &&
mScrollbarThumbRatio == aThumbRatio)
mThumbData == aThumbData)
{
return false;
}
mScrollbarTargetContainerId = aScrollId;
mScrollbarDirection = aDir;
mScrollbarThumbRatio = aThumbRatio;
mThumbData = aThumbData;
return true;
}
bool SetIsScrollbarContainer(FrameMetrics::ViewID aScrollId) {
@ -172,7 +190,7 @@ public:
if (mScrollbarTargetContainerId != aOther.mScrollbarTargetContainerId) {
return false;
}
if (mScrollbarDirection != aOther.mScrollbarDirection) {
if (mThumbData != aOther.mThumbData) {
return false;
}
if (FixedPositionScrollContainerId() != aOther.FixedPositionScrollContainerId()) {
@ -206,11 +224,8 @@ public:
FrameMetrics::ViewID ScrollbarTargetContainerId() const {
return mScrollbarTargetContainerId;
}
ScrollDirection ScrollbarDirection() const {
return mScrollbarDirection;
}
float ScrollbarThumbRatio() const {
return mScrollbarThumbRatio;
const ScrollThumbData& ThumbData() const {
return mThumbData;
}
float IsScrollbarContainer() const {
return mIsScrollbarContainer;
@ -264,8 +279,7 @@ public:
mOpacity == aOther.mOpacity &&
mIsFixedPosition == aOther.mIsFixedPosition &&
mScrollbarTargetContainerId == aOther.mScrollbarTargetContainerId &&
mScrollbarDirection == aOther.mScrollbarDirection &&
mScrollbarThumbRatio == aOther.mScrollbarThumbRatio &&
mThumbData == aOther.mThumbData &&
mIsScrollbarContainer == aOther.mIsScrollbarContainer &&
mMixBlendMode == aOther.mMixBlendMode &&
mForceIsolatedGroup == aOther.mForceIsolatedGroup;
@ -281,11 +295,7 @@ private:
float mOpacity;
bool mIsFixedPosition;
uint64_t mScrollbarTargetContainerId;
ScrollDirection mScrollbarDirection;
// 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 mScrollbarThumbRatio;
ScrollThumbData mThumbData;
bool mIsScrollbarContainer;
gfx::CompositionOp mMixBlendMode;
bool mForceIsolatedGroup;

Просмотреть файл

@ -413,7 +413,7 @@ public:
{
MOZ_ASSERT(IsValid());
return mLayer->GetScrollbarDirection();
return mLayer->GetScrollThumbData().mDirection;
}
FrameMetrics::ViewID GetScrollbarTargetContainerId() const

Просмотреть файл

@ -1889,10 +1889,11 @@ Layer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
if (IsScrollbarContainer()) {
aStream << " [scrollbar]";
}
if (GetScrollbarDirection() == ScrollDirection::VERTICAL) {
ScrollDirection thumbDirection = GetScrollThumbData().mDirection;
if (thumbDirection == ScrollDirection::VERTICAL) {
aStream << nsPrintfCString(" [vscrollbar=%" PRIu64 "]", GetScrollbarTargetContainerId()).get();
}
if (GetScrollbarDirection() == ScrollDirection::HORIZONTAL) {
if (thumbDirection == ScrollDirection::HORIZONTAL) {
aStream << nsPrintfCString(" [hscrollbar=%" PRIu64 "]", GetScrollbarTargetContainerId()).get();
}
if (GetIsFixedPosition()) {
@ -2038,8 +2039,9 @@ Layer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
// Component alpha
layer->set_calpha(static_cast<bool>(GetContentFlags() & CONTENT_COMPONENT_ALPHA));
// Vertical or horizontal bar
if (GetScrollbarDirection() != ScrollDirection::NONE) {
layer->set_direct(GetScrollbarDirection() == ScrollDirection::VERTICAL ?
ScrollDirection thumbDirection = GetScrollThumbData().mDirection;
if (thumbDirection != ScrollDirection::NONE) {
layer->set_direct(thumbDirection == ScrollDirection::VERTICAL ?
LayersPacket::Layer::VERTICAL :
LayersPacket::Layer::HORIZONTAL);
layer->set_barid(GetScrollbarTargetContainerId());

Просмотреть файл

@ -1288,12 +1288,13 @@ public:
/**
* CONSTRUCTION PHASE ONLY
* If a layer is a scrollbar layer, |aScrollId| holds the scroll identifier
* of the scrollable content that the scrollbar is for.
* If a layer is a scroll thumb container layer, set the scroll identifier
* of the scroll frame scrolled by the thumb, and other data related to the
* thumb.
*/
void SetScrollbarData(FrameMetrics::ViewID aScrollId, ScrollDirection aDir, float aThumbRatio)
void SetScrollThumbData(FrameMetrics::ViewID aScrollId, const ScrollThumbData& aThumbData)
{
if (mSimpleAttrs.SetScrollbarData(aScrollId, aDir, aThumbRatio)) {
if (mSimpleAttrs.SetScrollThumbData(aScrollId, aThumbData)) {
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ScrollbarData", this));
MutatedSimple();
}
@ -1367,8 +1368,7 @@ public:
const LayerRect& GetStickyScrollRangeOuter() { return mSimpleAttrs.StickyScrollRangeOuter(); }
const LayerRect& GetStickyScrollRangeInner() { return mSimpleAttrs.StickyScrollRangeInner(); }
FrameMetrics::ViewID GetScrollbarTargetContainerId() { return mSimpleAttrs.ScrollbarTargetContainerId(); }
ScrollDirection GetScrollbarDirection() { return mSimpleAttrs.ScrollbarDirection(); }
float GetScrollbarThumbRatio() { return mSimpleAttrs.ScrollbarThumbRatio(); }
const ScrollThumbData& GetScrollThumbData() const { return mSimpleAttrs.ThumbData(); }
bool IsScrollbarContainer() { return mSimpleAttrs.IsScrollbarContainer(); }
Layer* GetMaskLayer() const { return mMaskLayer; }
void CheckCanary() const { mCanary.Check(); }

Просмотреть файл

@ -804,7 +804,7 @@ MoveScrollbarForLayerMargin(Layer* aRoot, FrameMetrics::ViewID aRootScrollId,
// adjustment on the layer tree.
Layer* scrollbar = BreadthFirstSearch<ReverseIterator>(aRoot,
[aRootScrollId](Layer* aNode) {
return (aNode->GetScrollbarDirection() == ScrollDirection::HORIZONTAL &&
return (aNode->GetScrollThumbData().mDirection == ScrollDirection::HORIZONTAL &&
aNode->GetScrollbarTargetContainerId() == aRootScrollId);
});
if (scrollbar) {
@ -1080,7 +1080,7 @@ AsyncCompositionManager::ApplyAsyncContentTransformToTree(Layer *aLayer,
ExpandRootClipRect(layer, fixedLayerMargins);
if (layer->GetScrollbarDirection() != ScrollDirection::NONE) {
if (layer->GetScrollThumbData().mDirection != ScrollDirection::NONE) {
ApplyAsyncTransformToScrollbar(layer);
}
});
@ -1128,7 +1128,8 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
// on the painted content, we need to adjust it based on asyncTransform so that
// it reflects what the user is actually seeing now.
AsyncTransformComponentMatrix scrollbarTransform;
if (aScrollbar->GetScrollbarDirection() == ScrollDirection::VERTICAL) {
const ScrollThumbData& thumbData = aScrollbar->GetScrollThumbData();
if (thumbData.mDirection == ScrollDirection::VERTICAL) {
const ParentLayerCoord asyncScrollY = asyncTransform._42;
const float asyncZoomY = asyncTransform._22;
@ -1143,7 +1144,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
// Here we convert the scrollbar thumb ratio into a true unitless ratio by
// dividing out the conversion factor from the scrollframe's parent's space
// to the scrollframe's space.
const float ratio = aScrollbar->GetScrollbarThumbRatio() /
const float ratio = thumbData.mThumbRatio /
(metrics.GetPresShellResolution() * asyncZoomY);
// The scroll thumb needs to be translated in opposite direction of the
// async scroll. This is because scrolling down, which translates the layer
@ -1180,7 +1181,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
scrollbarTransform.PostScale(1.f, yScale, 1.f);
scrollbarTransform.PostTranslate(0, yTranslation, 0);
}
if (aScrollbar->GetScrollbarDirection() == ScrollDirection::HORIZONTAL) {
if (thumbData.mDirection == ScrollDirection::HORIZONTAL) {
// See detailed comments under the VERTICAL case.
const ParentLayerCoord asyncScrollX = asyncTransform._41;
@ -1190,7 +1191,7 @@ ApplyAsyncTransformToScrollbarForContent(Layer* aScrollbar,
const CSSToParentLayerScale effectiveZoom(metrics.GetZoom().xScale * asyncZoomX);
const float ratio = aScrollbar->GetScrollbarThumbRatio() /
const float ratio = thumbData.mThumbRatio /
(metrics.GetPresShellResolution() * asyncZoomX);
ParentLayerCoord xTranslation = -asyncScrollX * ratio;

Просмотреть файл

@ -43,7 +43,7 @@ WebRenderLayerScrollData::Initialize(WebRenderScrollData& aOwner,
mEventRegionsOverride = aLayer->AsContainerLayer()
? aLayer->AsContainerLayer()->GetEventRegionsOverride()
: EventRegionsOverride::NoOverride;
mScrollbarDirection = aLayer->GetScrollbarDirection();
mScrollbarDirection = aLayer->GetScrollThumbData().mDirection;
mScrollbarTargetContainerId = aLayer->GetScrollbarTargetContainerId();
mScrollThumbLength = mScrollbarDirection == ScrollDirection::VERTICAL
? aLayer->GetVisibleRegion().GetBounds().height

Просмотреть файл

@ -2792,7 +2792,7 @@ nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder* aBuilder,
new (aBuilder) nsDisplayOwnLayer(aBuilder, this, &resultList,
aBuilder->CurrentActiveScrolledRoot(), 0,
mozilla::layers::FrameMetrics::NULL_SCROLL_ID,
0.0f, /* aForceActive = */ false));
ScrollThumbData{}, /* aForceActive = */ false));
}
/* If we have sticky positioning, wrap it in a sticky position item.

Просмотреть файл

@ -6151,12 +6151,12 @@ nsDisplayOwnLayer::nsDisplayOwnLayer(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame, nsDisplayList* aList,
const ActiveScrolledRoot* aActiveScrolledRoot,
uint32_t aFlags, ViewID aScrollTarget,
float aScrollbarThumbRatio,
const ScrollThumbData& aThumbData,
bool aForceActive)
: nsDisplayWrapList(aBuilder, aFrame, aList, aActiveScrolledRoot)
, mFlags(aFlags)
, mScrollTarget(aScrollTarget)
, mScrollbarThumbRatio(aScrollbarThumbRatio)
, mThumbData(aThumbData)
, mForceActive(aForceActive)
{
MOZ_COUNT_CTOR(nsDisplayOwnLayer);
@ -6190,11 +6190,8 @@ nsDisplayOwnLayer::BuildLayer(nsDisplayListBuilder* aBuilder,
BuildContainerLayerFor(aBuilder, aManager, mFrame, this, &mList,
aContainerParameters, nullptr,
FrameLayerBuilder::CONTAINER_ALLOW_PULL_BACKGROUND_COLOR);
if (mFlags & VERTICAL_SCROLLBAR) {
layer->SetScrollbarData(mScrollTarget, ScrollDirection::VERTICAL, mScrollbarThumbRatio);
}
if (mFlags & HORIZONTAL_SCROLLBAR) {
layer->SetScrollbarData(mScrollTarget, ScrollDirection::HORIZONTAL, mScrollbarThumbRatio);
if (mThumbData.mDirection != ScrollDirection::NONE) {
layer->SetScrollThumbData(mScrollTarget, mThumbData);
}
if (mFlags & SCROLLBAR_CONTAINER) {
layer->SetIsScrollbarContainer(mScrollTarget);

Просмотреть файл

@ -35,6 +35,7 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/gfx/UserData.h"
#include "mozilla/layers/LayerAttributes.h"
#include "nsCSSRenderingBorders.h"
#include <stdint.h>
@ -4041,6 +4042,7 @@ private:
*/
class nsDisplayOwnLayer : public nsDisplayWrapList {
public:
typedef mozilla::layers::ScrollThumbData ScrollThumbData;
/**
* nsDisplayOwnLayer constructor flags
@ -4069,7 +4071,7 @@ public:
const ActiveScrolledRoot* aActiveScrolledRoot,
uint32_t aFlags = 0,
ViewID aScrollTarget = mozilla::layers::FrameMetrics::NULL_SCROLL_ID,
float aScrollbarThumbRatio = 0.0f,
const ScrollThumbData& aThumbData = ScrollThumbData{},
bool aForceActive = true);
#ifdef NS_BUILD_REFCNT_LOGGING
virtual ~nsDisplayOwnLayer();
@ -4094,7 +4096,11 @@ public:
protected:
uint32_t mFlags;
ViewID mScrollTarget;
float mScrollbarThumbRatio;
// If this nsDisplayOwnLayer represents a scroll thumb layer, mThumbData
// stores information about the scroll thumb. Otherwise, mThumbData will be
// default-constructed (in particular with mDirection == ScrollDirection::NONE)
// and can be ignored.
ScrollThumbData mThumbData;
bool mForceActive;
};

Просмотреть файл

@ -54,7 +54,9 @@ using namespace mozilla;
using mozilla::layers::APZCCallbackHelper;
using mozilla::layers::AsyncDragMetrics;
using mozilla::layers::InputAPZContext;
using mozilla::layers::ScrollDirection;
using mozilla::layers::ScrollInputMethod;
using mozilla::layers::ScrollThumbData;
bool nsSliderFrame::gMiddlePref = false;
int32_t nsSliderFrame::gSnapMultiplier;
@ -364,6 +366,12 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
nsLayoutUtils::SetScrollbarThumbLayerization(thumb, thumbGetsLayer);
if (thumbGetsLayer) {
MOZ_ASSERT((flags & nsDisplayOwnLayer::HORIZONTAL_SCROLLBAR) ||
(flags & nsDisplayOwnLayer::VERTICAL_SCROLLBAR));
ScrollDirection scrollDirection =
(flags & nsDisplayOwnLayer::HORIZONTAL_SCROLLBAR)
? ScrollDirection::HORIZONTAL
: ScrollDirection::VERTICAL;
nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
nsDisplayListCollection tempLists;
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, tempLists);
@ -385,7 +393,7 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
aLists.Content()->AppendNewToTop(new (aBuilder)
nsDisplayOwnLayer(aBuilder, this, &masterList, ownLayerASR,
flags, scrollTargetId,
GetThumbRatio()));
ScrollThumbData{scrollDirection, GetThumbRatio()}));
return;
}