Bug 1349750 - Move the scroll track extents from AsyncDragMetrics to ScrollThumbData. r=kats

To conserve space in LayerAttributes, we only store the extents along the
relevant axis.

MozReview-Commit-ID: GAL8Oa2NOde

--HG--
extra : rebase_source : 9420d0fb36175e190cbff6e162fd41d8e5240c81
This commit is contained in:
Botond Ballo 2017-05-05 15:54:27 -04:00
parent bae009bd63
commit 9127b9d4f3
5 changed files with 33 additions and 27 deletions

View File

@ -1305,7 +1305,6 @@ struct ParamTraits<mozilla::layers::AsyncDragMetrics>
WriteParam(aMsg, aParam.mPresShellId);
WriteParam(aMsg, aParam.mDragStartSequenceNumber);
WriteParam(aMsg, aParam.mScrollbarDragOffset);
WriteParam(aMsg, aParam.mScrollTrack);
WriteParam(aMsg, aParam.mDirection);
}
@ -1315,7 +1314,6 @@ struct ParamTraits<mozilla::layers::AsyncDragMetrics>
ReadParam(aMsg, aIter, &aResult->mPresShellId) &&
ReadParam(aMsg, aIter, &aResult->mDragStartSequenceNumber) &&
ReadParam(aMsg, aIter, &aResult->mScrollbarDragOffset) &&
ReadParam(aMsg, aIter, &aResult->mScrollTrack) &&
ReadParam(aMsg, aIter, &aResult->mDirection));
}
};

View File

@ -27,11 +27,15 @@ struct ScrollThumbData {
ScrollThumbData(ScrollDirection aDirection,
float aThumbRatio,
CSSCoord aThumbLength,
bool aIsAsyncDraggable)
bool aIsAsyncDraggable,
CSSCoord aScrollTrackStart,
CSSCoord aScrollTrackLength)
: mDirection(aDirection)
, mThumbRatio(aThumbRatio)
, mThumbLength(aThumbLength)
, mIsAsyncDraggable(aIsAsyncDraggable)
, mScrollTrackStart(aScrollTrackStart)
, mScrollTrackLength(aScrollTrackLength)
{}
ScrollDirection mDirection;
@ -42,12 +46,16 @@ struct ScrollThumbData {
CSSCoord mThumbLength;
// Whether the scrollbar thumb can be dragged asynchronously.
bool mIsAsyncDraggable;
CSSCoord mScrollTrackStart;
CSSCoord mScrollTrackLength;
bool operator==(const ScrollThumbData& aOther) const {
return mDirection == aOther.mDirection &&
mThumbRatio == aOther.mThumbRatio &&
mThumbLength == aOther.mThumbLength &&
mIsAsyncDraggable == aOther.mIsAsyncDraggable;
mIsAsyncDraggable == aOther.mIsAsyncDraggable &&
mScrollTrackStart == aOther.mScrollTrackStart &&
mScrollTrackLength == aOther.mScrollTrackLength;
}
bool operator!=(const ScrollThumbData& aOther) const {
return !(*this == aOther);

View File

@ -41,13 +41,11 @@ public:
uint32_t aPresShellId,
uint64_t aDragStartSequenceNumber,
CSSCoord aScrollbarDragOffset,
const CSSRect& aScrollTrack,
DragDirection aDirection)
: mViewId(aViewId)
, mPresShellId(aPresShellId)
, mDragStartSequenceNumber(aDragStartSequenceNumber)
, mScrollbarDragOffset(aScrollbarDragOffset)
, mScrollTrack(aScrollTrack)
, mDirection(aDirection)
{}
@ -55,7 +53,6 @@ public:
uint32_t mPresShellId;
uint64_t mDragStartSequenceNumber;
CSSCoord mScrollbarDragOffset;
CSSRect mScrollTrack;
DragDirection mDirection;
};

View File

@ -926,9 +926,9 @@ nsEventStatus AsyncPanZoomController::HandleDragEvent(const MouseInput& aEvent,
CSSCoord mousePosition = GetAxisStart(aDragMetrics.mDirection, scrollbarPoint) -
aDragMetrics.mScrollbarDragOffset -
GetAxisStart(aDragMetrics.mDirection, cssCompositionBound) -
GetAxisStart(aDragMetrics.mDirection, aDragMetrics.mScrollTrack);
thumbData.mScrollTrackStart;
CSSCoord scrollMax = GetAxisLength(aDragMetrics.mDirection, aDragMetrics.mScrollTrack);
CSSCoord scrollMax = thumbData.mScrollTrackLength;
scrollMax -= thumbData.mThumbLength;
float scrollPercent = mousePosition / scrollMax;

View File

@ -361,10 +361,10 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
thumb->GetXULMargin(m);
thumbRect.Inflate(m);
nsRect crect;
GetXULClientRect(crect);
nsRect sliderTrack;
GetXULClientRect(sliderTrack);
if (crect.width < thumbRect.width || crect.height < thumbRect.height)
if (sliderTrack.width < thumbRect.width || sliderTrack.height < thumbRect.height)
return;
// If this scrollbar is the scrollbar of an actively scrolled scroll frame,
@ -394,6 +394,21 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
nsIFrame* scrollbarBox = GetScrollbar();
bool isAsyncDraggable = !UsesCustomScrollbarMediator(scrollbarBox);
nsPoint scrollPortOrigin;
if (nsIScrollableFrame* scrollFrame = do_QueryFrame(scrollbarBox->GetParent())) {
scrollPortOrigin = scrollFrame->GetScrollPortRect().TopLeft();
} else {
isAsyncDraggable = false;
}
// This rect is the range in which the scroll thumb can slide in.
sliderTrack = sliderTrack + GetRect().TopLeft() + scrollbarBox->GetPosition() -
scrollPortOrigin;
CSSCoord sliderTrackStart = NSAppUnitsToFloatPixels(
isHorizontal ? sliderTrack.x : sliderTrack.y, appUnitsPerCss);
CSSCoord sliderTrackLength = NSAppUnitsToFloatPixels(
isHorizontal ? sliderTrack.width : sliderTrack.height, appUnitsPerCss);
nsDisplayListBuilder::AutoContainerASRTracker contASRTracker(aBuilder);
nsDisplayListCollection tempLists;
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, tempLists);
@ -418,7 +433,9 @@ nsSliderFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
ScrollThumbData{scrollDirection,
GetThumbRatio(),
thumbLength,
isAsyncDraggable}));
isAsyncDraggable,
sliderTrackStart,
sliderTrackLength}));
return;
}
@ -1044,11 +1061,6 @@ nsSliderFrame::StartAPZDrag(WidgetGUIEvent* aEvent)
return;
}
nsIScrollableFrame* scrollFrameAsScrollable = do_QueryFrame(scrollFrame);
if (!scrollFrameAsScrollable) {
return;
}
// APZ dragging requires the scrollbar to be layerized, which doesn't
// happen for scroll info layers.
if (ScrollFrameWillBuildScrollInfoLayer(scrollFrame)) {
@ -1072,21 +1084,12 @@ nsSliderFrame::StartAPZDrag(WidgetGUIEvent* aEvent)
nsCOMPtr<nsIContent> scrollbar = GetContentOfBox(scrollbarBox);
nsRect sliderTrack;
GetXULClientRect(sliderTrack);
// This rect is the range in which the scroll thumb can slide in.
sliderTrack = sliderTrack + GetRect().TopLeft() + scrollbarBox->GetPosition() -
scrollFrameAsScrollable->GetScrollPortRect().TopLeft();
CSSRect sliderTrackCSS = CSSRect::FromAppUnits(sliderTrack);
nsIPresShell* shell = PresContext()->PresShell();
uint64_t inputblockId = InputAPZContext::GetInputBlockId();
uint32_t presShellId = shell->GetPresShellId();
AsyncDragMetrics dragMetrics(scrollTargetId, presShellId, inputblockId,
NSAppUnitsToFloatPixels(mDragStart,
float(AppUnitsPerCSSPixel())),
sliderTrackCSS,
isHorizontal ? AsyncDragMetrics::HORIZONTAL :
AsyncDragMetrics::VERTICAL);