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: */
|
2015-07-13 18:53:10 +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/. */
|
|
|
|
|
|
|
|
#include "FrameMetrics.h"
|
|
|
|
#include "gfxPrefs.h"
|
2017-10-19 03:13:19 +03:00
|
|
|
#include "nsStyleConsts.h"
|
2019-04-23 04:16:02 +03:00
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "mozilla/WritingModes.h"
|
2015-07-13 18:53:10 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2018-11-01 23:15:46 +03:00
|
|
|
const ScrollableLayerGuid::ViewID ScrollableLayerGuid::NULL_SCROLL_ID = 0;
|
2015-07-13 18:53:10 +03:00
|
|
|
|
2019-01-09 18:34:34 +03:00
|
|
|
void FrameMetrics::RecalculateLayoutViewportOffset() {
|
2018-06-08 00:01:36 +03:00
|
|
|
if (!mIsRootContent) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-09 18:34:34 +03:00
|
|
|
KeepLayoutViewportEnclosingVisualViewport(GetVisualViewport(),
|
2019-03-30 01:00:36 +03:00
|
|
|
mScrollableRect, mLayoutViewport);
|
2018-10-11 08:58:13 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void FrameMetrics::KeepLayoutViewportEnclosingVisualViewport(
|
2019-03-30 01:00:36 +03:00
|
|
|
const CSSRect& aVisualViewport, const CSSRect& aScrollableRect,
|
|
|
|
CSSRect& aLayoutViewport) {
|
2018-06-08 00:01:36 +03:00
|
|
|
// If the visual viewport is contained within the layout viewport, we don't
|
|
|
|
// need to make any adjustments, so we can exit early.
|
|
|
|
//
|
|
|
|
// Additionally, if the composition bounds changes (due to an orientation
|
2018-10-11 08:58:13 +03:00
|
|
|
// change, window resize, etc.), it may take a few frames for aLayoutViewport
|
2018-06-08 00:01:36 +03:00
|
|
|
// to update and during that time, the visual viewport may be larger than the
|
2018-07-22 08:59:37 +03:00
|
|
|
// layout viewport. In such situations, we take an early exit if the visual
|
|
|
|
// viewport contains the layout viewport.
|
2018-10-11 08:58:13 +03:00
|
|
|
if (aLayoutViewport.Contains(aVisualViewport) ||
|
|
|
|
aVisualViewport.Contains(aLayoutViewport)) {
|
2018-06-08 00:01:36 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-07-22 08:59:37 +03:00
|
|
|
|
|
|
|
// If visual viewport size is greater than the layout viewport, move the
|
|
|
|
// layout viewport such that it remains inside the visual viewport. Otherwise,
|
|
|
|
// move the layout viewport such that the visual viewport is contained
|
|
|
|
// inside the layout viewport.
|
2018-10-11 08:58:13 +03:00
|
|
|
if ((aLayoutViewport.Width() < aVisualViewport.Width() &&
|
|
|
|
!FuzzyEqualsMultiplicative(aLayoutViewport.Width(),
|
|
|
|
aVisualViewport.Width())) ||
|
|
|
|
(aLayoutViewport.Height() < aVisualViewport.Height() &&
|
|
|
|
!FuzzyEqualsMultiplicative(aLayoutViewport.Height(),
|
|
|
|
aVisualViewport.Height()))) {
|
|
|
|
if (aLayoutViewport.X() < aVisualViewport.X()) {
|
2018-07-22 08:59:37 +03:00
|
|
|
// layout viewport moves right
|
2018-10-11 08:58:13 +03:00
|
|
|
aLayoutViewport.MoveToX(aVisualViewport.X());
|
|
|
|
} else if (aVisualViewport.XMost() < aLayoutViewport.XMost()) {
|
2018-07-22 08:59:37 +03:00
|
|
|
// layout viewport moves left
|
2018-10-11 08:58:13 +03:00
|
|
|
aLayoutViewport.MoveByX(aVisualViewport.XMost() -
|
|
|
|
aLayoutViewport.XMost());
|
2018-07-22 08:59:37 +03:00
|
|
|
}
|
2018-10-11 08:58:13 +03:00
|
|
|
if (aLayoutViewport.Y() < aVisualViewport.Y()) {
|
2018-07-22 08:59:37 +03:00
|
|
|
// layout viewport moves down
|
2018-10-11 08:58:13 +03:00
|
|
|
aLayoutViewport.MoveToY(aVisualViewport.Y());
|
|
|
|
} else if (aVisualViewport.YMost() < aLayoutViewport.YMost()) {
|
2018-07-22 08:59:37 +03:00
|
|
|
// layout viewport moves up
|
2018-10-11 08:58:13 +03:00
|
|
|
aLayoutViewport.MoveByY(aVisualViewport.YMost() -
|
|
|
|
aLayoutViewport.YMost());
|
2018-07-22 08:59:37 +03:00
|
|
|
}
|
|
|
|
} else {
|
2018-10-11 08:58:13 +03:00
|
|
|
if (aVisualViewport.X() < aLayoutViewport.X()) {
|
|
|
|
aLayoutViewport.MoveToX(aVisualViewport.X());
|
|
|
|
} else if (aLayoutViewport.XMost() < aVisualViewport.XMost()) {
|
|
|
|
aLayoutViewport.MoveByX(aVisualViewport.XMost() -
|
|
|
|
aLayoutViewport.XMost());
|
2018-07-22 08:59:37 +03:00
|
|
|
}
|
2018-10-11 08:58:13 +03:00
|
|
|
if (aVisualViewport.Y() < aLayoutViewport.Y()) {
|
|
|
|
aLayoutViewport.MoveToY(aVisualViewport.Y());
|
|
|
|
} else if (aLayoutViewport.YMost() < aVisualViewport.YMost()) {
|
|
|
|
aLayoutViewport.MoveByY(aVisualViewport.YMost() -
|
|
|
|
aLayoutViewport.YMost());
|
2018-07-22 08:59:37 +03:00
|
|
|
}
|
|
|
|
}
|
2019-03-30 01:00:36 +03:00
|
|
|
|
|
|
|
// Regardless of any adjustment above, the layout viewport is not allowed
|
|
|
|
// to go outside the scrollable rect.
|
|
|
|
aLayoutViewport = aLayoutViewport.MoveInsideAndClamp(aScrollableRect);
|
2018-06-08 00:01:36 +03:00
|
|
|
}
|
|
|
|
|
2016-04-27 23:06:34 +03:00
|
|
|
void ScrollMetadata::SetUsesContainerScrolling(bool aValue) {
|
2015-07-13 18:53:10 +03:00
|
|
|
mUsesContainerScrolling = aValue;
|
|
|
|
}
|
|
|
|
|
2019-04-23 04:16:02 +03:00
|
|
|
void ScrollSnapInfo::InitializeScrollSnapType(WritingMode aWritingMode,
|
|
|
|
const nsStyleDisplay* aDisplay) {
|
|
|
|
if (aDisplay->mScrollSnapType.strictness == StyleScrollSnapStrictness::None) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScrollSnapTypeX = StyleScrollSnapStrictness::None;
|
|
|
|
mScrollSnapTypeY = StyleScrollSnapStrictness::None;
|
|
|
|
|
|
|
|
switch (aDisplay->mScrollSnapType.axis) {
|
|
|
|
case StyleScrollSnapAxis::X:
|
|
|
|
mScrollSnapTypeX = aDisplay->mScrollSnapType.strictness;
|
|
|
|
break;
|
|
|
|
case StyleScrollSnapAxis::Y:
|
|
|
|
mScrollSnapTypeY = aDisplay->mScrollSnapType.strictness;
|
|
|
|
break;
|
|
|
|
case StyleScrollSnapAxis::Block:
|
|
|
|
if (aWritingMode.IsVertical()) {
|
|
|
|
mScrollSnapTypeX = aDisplay->mScrollSnapType.strictness;
|
|
|
|
} else {
|
|
|
|
mScrollSnapTypeY = aDisplay->mScrollSnapType.strictness;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleScrollSnapAxis::Inline:
|
|
|
|
if (aWritingMode.IsVertical()) {
|
|
|
|
mScrollSnapTypeY = aDisplay->mScrollSnapType.strictness;
|
|
|
|
} else {
|
|
|
|
mScrollSnapTypeX = aDisplay->mScrollSnapType.strictness;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleScrollSnapAxis::Both:
|
|
|
|
mScrollSnapTypeX = aDisplay->mScrollSnapType.strictness;
|
|
|
|
mScrollSnapTypeY = aDisplay->mScrollSnapType.strictness;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 03:13:19 +03:00
|
|
|
static OverscrollBehavior ToOverscrollBehavior(
|
|
|
|
StyleOverscrollBehavior aBehavior) {
|
|
|
|
switch (aBehavior) {
|
|
|
|
case StyleOverscrollBehavior::Auto:
|
|
|
|
return OverscrollBehavior::Auto;
|
|
|
|
case StyleOverscrollBehavior::Contain:
|
|
|
|
return OverscrollBehavior::Contain;
|
|
|
|
case StyleOverscrollBehavior::None:
|
|
|
|
return OverscrollBehavior::None;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Invalid overscroll behavior");
|
|
|
|
return OverscrollBehavior::Auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
OverscrollBehaviorInfo OverscrollBehaviorInfo::FromStyleConstants(
|
|
|
|
StyleOverscrollBehavior aBehaviorX, StyleOverscrollBehavior aBehaviorY) {
|
|
|
|
OverscrollBehaviorInfo result;
|
|
|
|
result.mBehaviorX = ToOverscrollBehavior(aBehaviorX);
|
|
|
|
result.mBehaviorY = ToOverscrollBehavior(aBehaviorY);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-03-31 00:04:10 +03:00
|
|
|
StaticAutoPtr<const ScrollMetadata> ScrollMetadata::sNullMetadata;
|
2016-03-29 02:14:52 +03:00
|
|
|
|
|
|
|
} // namespace layers
|
2015-07-13 18:53:10 +03:00
|
|
|
} // namespace mozilla
|