Bug 1612983 - Disable APZ only when AccessibleCaret's position is changed. r=botond

`mIsCaretPositionChanged` is used in `UpdateShouldDisableApz()` to
determine whether to disable APZ during scrolling or pinch-zooming.

Suppose the selection is on position:static elements. When
pinch-zooming, the zoom level is changed, but the position is not. We
split `PositionChangedResult::Changed` into two separate states, and set
`mIsCaretPositionChanged` only when the position is changed.

Differential Revision: https://phabricator.services.mozilla.com/D61516

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ting-Yu Lin 2020-02-07 22:31:40 +00:00
parent 06a73300ce
commit c508a968ca
4 changed files with 27 additions and 19 deletions

View File

@ -57,7 +57,8 @@ std::ostream& operator<<(
using PositionChangedResult = AccessibleCaret::PositionChangedResult;
switch (aResult) {
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::NotChanged);
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Changed);
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Position);
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Zoom);
AC_PROCESS_ENUM_TO_STREAM(PositionChangedResult::Invisible);
}
return aStream;
@ -259,10 +260,11 @@ AccessibleCaret::PositionChangedResult AccessibleCaret::SetPosition(
nsLayoutUtils::TransformRect(aFrame, CustomContentContainerFrame(),
imaginaryCaretRectInContainerFrame);
const float zoomLevel = GetZoomLevel();
const bool isSamePosition = imaginaryCaretRectInContainerFrame.IsEqualEdges(
mImaginaryCaretRectInContainerFrame);
const bool isSameZoomLevel = FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel);
if (imaginaryCaretRectInContainerFrame.IsEqualEdges(
mImaginaryCaretRectInContainerFrame) &&
FuzzyEqualsMultiplicative(zoomLevel, mZoomLevel)) {
if (isSamePosition && isSameZoomLevel) {
return PositionChangedResult::NotChanged;
}
@ -277,7 +279,8 @@ AccessibleCaret::PositionChangedResult AccessibleCaret::SetPosition(
SetCaretElementStyle(imaginaryCaretRectInContainerFrame, mZoomLevel);
return PositionChangedResult::Changed;
return isSamePosition ? PositionChangedResult::Zoom
: PositionChangedResult::Position;
}
nsIFrame* AccessibleCaret::CustomContentContainerFrame() const {

View File

@ -92,15 +92,18 @@ class AccessibleCaret {
(mAppearance != Appearance::NormalNotShown);
}
// This enumeration representing the result returned by SetPosition().
// This enum represents the result returned by SetPosition().
enum class PositionChangedResult : uint8_t {
// Position is not changed.
// Both position and the zoom level are not changed.
NotChanged,
// Position or zoom level is changed.
Changed,
// The position is changed. (The zoom level may or may not be changed.)
Position,
// Position is out of scroll port.
// Only the zoom level is changed. The position is *not* changed.
Zoom,
// The position is out of scroll port.
Invisible
};

View File

@ -248,7 +248,8 @@ void AccessibleCaretManager::UpdateCaretsForCursorMode(
switch (result) {
case PositionChangedResult::NotChanged:
case PositionChangedResult::Changed:
case PositionChangedResult::Position:
case PositionChangedResult::Zoom:
if (!aHints.contains(UpdateCaretsHint::RespectOldAppearance)) {
if (HasNonEmptyTextContent(GetEditingHostForFrame(frame))) {
mFirstCaret->SetAppearance(Appearance::Normal);
@ -283,7 +284,7 @@ void AccessibleCaretManager::UpdateCaretsForCursorMode(
mSecondCaret->SetAppearance(Appearance::None);
mIsCaretPositionChanged = (result == PositionChangedResult::Changed);
mIsCaretPositionChanged = (result == PositionChangedResult::Position);
if (!aHints.contains(UpdateCaretsHint::DispatchNoEvent) && !mActiveCaret) {
DispatchCaretStateChangedEvent(CaretChangedReason::Updateposition);
@ -314,7 +315,8 @@ void AccessibleCaretManager::UpdateCaretsForSelectionMode(
switch (result) {
case PositionChangedResult::NotChanged:
case PositionChangedResult::Changed:
case PositionChangedResult::Position:
case PositionChangedResult::Zoom:
if (!aHints.contains(UpdateCaretsHint::RespectOldAppearance)) {
aCaret->SetAppearance(Appearance::Normal);
}
@ -333,8 +335,8 @@ void AccessibleCaretManager::UpdateCaretsForSelectionMode(
updateSingleCaret(mSecondCaret.get(), endFrame, endOffset);
mIsCaretPositionChanged =
firstCaretResult == PositionChangedResult::Changed ||
secondCaretResult == PositionChangedResult::Changed;
firstCaretResult == PositionChangedResult::Position ||
secondCaretResult == PositionChangedResult::Position;
if (mIsCaretPositionChanged) {
// Flush layout to make the carets intersection correct.

View File

@ -117,10 +117,10 @@ class AccessibleCaretManagerTester : public ::testing::Test {
DefaultValue<PositionChangedResult>::Set(PositionChangedResult::NotChanged);
EXPECT_CALL(mManager.FirstCaret(), SetPosition(_, _))
.WillRepeatedly(Return(PositionChangedResult::Changed));
.WillRepeatedly(Return(PositionChangedResult::Position));
EXPECT_CALL(mManager.SecondCaret(), SetPosition(_, _))
.WillRepeatedly(Return(PositionChangedResult::Changed));
.WillRepeatedly(Return(PositionChangedResult::Position));
}
AccessibleCaret::Appearance FirstCaretAppearance() {
@ -585,7 +585,7 @@ MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
// After scroll ended, the caret is visible again.
EXPECT_CALL(mManager.FirstCaret(), SetPosition(_, _))
.WillRepeatedly(Return(PositionChangedResult::Changed));
.WillRepeatedly(Return(PositionChangedResult::Position));
EXPECT_CALL(mManager, DispatchCaretStateChangedEvent(
CaretChangedReason::Updateposition))
.Times(1);
@ -641,7 +641,7 @@ MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION {
// After scroll ended, the caret is visible again.
EXPECT_CALL(mManager.FirstCaret(), SetPosition(_, _))
.WillRepeatedly(Return(PositionChangedResult::Changed));
.WillRepeatedly(Return(PositionChangedResult::Position));
EXPECT_CALL(check, Call("scrollend2"));
}