Bug 1485063 Part 4 - Move preferences used in AccessibleCaretManager to StaticPrefList.h. r=mats

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ting-Yu Lin 2018-09-10 22:38:41 +00:00
Родитель b91559ddb2
Коммит afef0bf612
5 изменённых файлов: 82 добавлений и 112 удалений

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

@ -18,7 +18,7 @@
#include "mozilla/dom/TreeWalker.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs.h"
#include "nsCaret.h"
#include "nsContainerFrame.h"
#include "nsContentUtils.h"
@ -72,22 +72,6 @@ std::ostream& operator<<(std::ostream& aStream,
}
#undef AC_PROCESS_ENUM_TO_STREAM
/* static */ bool
AccessibleCaretManager::sCaretShownWhenLongTappingOnEmptyContent = false;
/* static */ bool
AccessibleCaretManager::sCaretsAlwaysTilt = false;
/* static */ int32_t
AccessibleCaretManager::sCaretsScriptUpdates =
AccessibleCaretManager::kScriptAlwaysHide;
/* static */ bool
AccessibleCaretManager::sCaretsAllowDraggingAcrossOtherCaret = true;
/* static */ bool
AccessibleCaretManager::sHapticFeedback = false;
/* static */ bool
AccessibleCaretManager::sExtendSelectionForPhoneNumber = false;
/* static */ bool
AccessibleCaretManager::sHideCaretsForMouseInput = true;
AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
: mPresShell(aPresShell)
{
@ -97,25 +81,6 @@ AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
mFirstCaret = MakeUnique<AccessibleCaret>(mPresShell);
mSecondCaret = MakeUnique<AccessibleCaret>(mPresShell);
static bool addedPrefs = false;
if (!addedPrefs) {
Preferences::AddBoolVarCache(&sCaretShownWhenLongTappingOnEmptyContent,
"layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content");
Preferences::AddBoolVarCache(&sCaretsAlwaysTilt,
"layout.accessiblecaret.always_tilt");
Preferences::AddIntVarCache(&sCaretsScriptUpdates,
"layout.accessiblecaret.script_change_update_mode");
Preferences::AddBoolVarCache(&sCaretsAllowDraggingAcrossOtherCaret,
"layout.accessiblecaret.allow_dragging_across_other_caret", true);
Preferences::AddBoolVarCache(&sHapticFeedback,
"layout.accessiblecaret.hapticfeedback");
Preferences::AddBoolVarCache(&sExtendSelectionForPhoneNumber,
"layout.accessiblecaret.extend_selection_for_phone_number");
Preferences::AddBoolVarCache(&sHideCaretsForMouseInput,
"layout.accessiblecaret.hide_carets_for_mouse_input");
addedPrefs = true;
}
}
AccessibleCaretManager::~AccessibleCaretManager()
@ -153,8 +118,10 @@ AccessibleCaretManager::OnSelectionChanged(nsIDocument* aDoc,
// Move the cursor by JavaScript or unknown internal call.
if (aReason == nsISelectionListener::NO_REASON) {
if (sCaretsScriptUpdates == kScriptAlwaysShow ||
(sCaretsScriptUpdates == kScriptUpdateVisible &&
auto mode = static_cast<ScriptUpdateMode>(
StaticPrefs::layout_accessiblecaret_script_change_update_mode());
if (mode == kScriptAlwaysShow ||
(mode == kScriptUpdateVisible &&
(mFirstCaret->IsLogicallyVisible() ||
mSecondCaret->IsLogicallyVisible()))) {
UpdateCarets();
@ -186,7 +153,7 @@ AccessibleCaretManager::OnSelectionChanged(nsIDocument* aDoc,
}
// For mouse input we don't want to show the carets.
if (sHideCaretsForMouseInput &&
if (StaticPrefs::layout_accessiblecaret_hide_carets_for_mouse_input() &&
mLastInputSource == MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
HideCarets();
return NS_OK;
@ -194,7 +161,7 @@ AccessibleCaretManager::OnSelectionChanged(nsIDocument* aDoc,
// When we want to hide the carets for mouse input, hide them for select
// all action fired by keyboard as well.
if (sHideCaretsForMouseInput &&
if (StaticPrefs::layout_accessiblecaret_hide_carets_for_mouse_input() &&
mLastInputSource == MouseEvent_Binding::MOZ_SOURCE_KEYBOARD &&
(aReason & nsISelectionListener::SELECTALL_REASON)) {
HideCarets();
@ -296,7 +263,7 @@ AccessibleCaretManager::UpdateCaretsForCursorMode(const UpdateCaretsHintSet& aHi
if (aHints == UpdateCaretsHint::Default) {
if (HasNonEmptyTextContent(GetEditingHostForFrame(frame))) {
mFirstCaret->SetAppearance(Appearance::Normal);
} else if (sCaretShownWhenLongTappingOnEmptyContent) {
} else if (StaticPrefs::layout_accessiblecaret_caret_shown_when_long_tapping_on_empty_content()) {
if (mFirstCaret->IsLogicallyVisible()) {
// Possible cases are: 1) SelectWordOrShortcut() sets the
// appearance to Normal. 2) When the caret is out of viewport and
@ -392,7 +359,7 @@ AccessibleCaretManager::UpdateCaretsForSelectionMode(const UpdateCaretsHintSet&
if (aHints == UpdateCaretsHint::Default) {
// Only check for tilt carets with default update hint. Otherwise we might
// override the appearance set by the caller.
if (sCaretsAlwaysTilt) {
if (StaticPrefs::layout_accessiblecaret_always_tilt()) {
UpdateCaretsForAlwaysTilt(startFrame, endFrame);
} else {
UpdateCaretsForOverlappingTilt();
@ -455,7 +422,7 @@ AccessibleCaretManager::UpdateCaretsForAlwaysTilt(nsIFrame* aStartFrame,
void
AccessibleCaretManager::ProvideHapticFeedback()
{
if (sHapticFeedback) {
if (StaticPrefs::layout_accessiblecaret_hapticfeedback()) {
nsCOMPtr<nsIHapticFeedback> haptic =
do_GetService("@mozilla.org/widget/hapticfeedback;1");
haptic->PerformSimpleAction(haptic->LongPress);
@ -592,7 +559,7 @@ AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint)
!HasNonEmptyTextContent(newFocusEditingHost)) {
ChangeFocusToOrClearOldFocus(focusableFrame);
if (sCaretShownWhenLongTappingOnEmptyContent) {
if (StaticPrefs::layout_accessiblecaret_caret_shown_when_long_tapping_on_empty_content()) {
mFirstCaret->SetAppearance(Appearance::Normal);
}
// We need to update carets to get correct information before dispatching
@ -670,7 +637,7 @@ AccessibleCaretManager::OnScrollEnd()
}
// For mouse input we don't want to show the carets.
if (sHideCaretsForMouseInput &&
if (StaticPrefs::layout_accessiblecaret_hide_carets_for_mouse_input() &&
mLastInputSource == MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
AC_LOG("%s: HideCarets()", __FUNCTION__);
HideCarets();
@ -880,7 +847,7 @@ AccessibleCaretManager::SelectWord(nsIFrame* aFrame, const nsPoint& aPoint) cons
ClearMaintainedSelection();
// Smart-select phone numbers if possible.
if (sExtendSelectionForPhoneNumber) {
if (StaticPrefs::layout_accessiblecaret_extend_selection_for_phone_number()) {
SelectMoreIfPhoneNumber();
}
@ -1157,7 +1124,7 @@ AccessibleCaretManager::RestrictCaretDraggingOffsets(
aOffsets.secondaryOffset = limit.mContentOffset;
};
if (!sCaretsAllowDraggingAcrossOtherCaret) {
if (!StaticPrefs::layout_accessiblecaret_allow_dragging_across_other_caret()) {
if ((mActiveCaret == mFirstCaret.get() && cmpToLimit == 1) ||
(mActiveCaret == mSecondCaret.get() && cmpToLimit == -1)) {
// The active caret's position is past the limit, which we don't allow
@ -1323,7 +1290,7 @@ AccessibleCaretManager::AdjustDragBoundary(const nsPoint& aPoint) const
}
if (GetCaretMode() == CaretMode::Selection &&
!sCaretsAllowDraggingAcrossOtherCaret) {
!StaticPrefs::layout_accessiblecaret_allow_dragging_across_other_caret()) {
// Bug 1068474: Adjust the Y-coordinate so that the carets won't be in tilt
// mode when a caret is being dragged surpass the other caret.
//

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

@ -331,20 +331,6 @@ protected:
// AppUnit.h.
static const int32_t kBoundaryAppUnits = 61;
// Preference to allow smarter selection of phone numbers,
// when user long presses text to start.
static bool sExtendSelectionForPhoneNumber;
// Preference to show caret in cursor mode when long tapping on an empty
// content. This also changes the default update behavior in cursor mode,
// which is based on the emptiness of the content, into something more
// heuristic. See UpdateCaretsForCursorMode() for the details.
static bool sCaretShownWhenLongTappingOnEmptyContent;
// Preference to make carets always tilt in selection mode. By default, the
// carets become tilt only when they are overlapping.
static bool sCaretsAlwaysTilt;
enum ScriptUpdateMode : int32_t {
// By default, always hide carets for selection changes due to JS calls.
kScriptAlwaysHide,
@ -354,22 +340,6 @@ protected:
// Always show carets for selection changes due to JS calls.
kScriptAlwaysShow
};
// Preference to indicate how to update carets for selection changes due to
// JS calls, as one of the ScriptUpdateMode constants.
static int32_t sCaretsScriptUpdates;
// Preference to allow one caret to be dragged across the other caret without
// any limitation. When set to false, one caret cannot be dragged across the
// other one.
static bool sCaretsAllowDraggingAcrossOtherCaret;
// AccessibleCaret pref for haptic feedback behaviour on longPress.
static bool sHapticFeedback;
// Preference to keep carets hidden when the selection is being manipulated
// by mouse input (as opposed to touch/pen/etc.).
static bool sHideCaretsForMouseInput;
};
std::ostream& operator<<(std::ostream& aStream,

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

@ -11,7 +11,8 @@
#include "AccessibleCaret.h"
#include "AccessibleCaretManager.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs.h"
using ::testing::DefaultValue;
using ::testing::Eq;
@ -53,8 +54,6 @@ public:
using CaretMode = AccessibleCaretManager::CaretMode;
using AccessibleCaretManager::UpdateCarets;
using AccessibleCaretManager::HideCarets;
using AccessibleCaretManager::sCaretShownWhenLongTappingOnEmptyContent;
using AccessibleCaretManager::sCaretsAlwaysTilt;
MockAccessibleCaretManager()
: AccessibleCaretManager(nullptr)
@ -434,9 +433,8 @@ TEST_F(AccessibleCaretManagerTester,
MOZ_CAN_RUN_SCRIPT
{
// Simulate Firefox Android preference.
AutoRestore<bool> saveCaretsAlwaysTilt(
MockAccessibleCaretManager::sCaretsAlwaysTilt);
MockAccessibleCaretManager::sCaretsAlwaysTilt = true;
bool oldPref = StaticPrefs::layout_accessiblecaret_always_tilt();
Preferences::SetBool("layout.accessiblecaret.always_tilt", true);
EXPECT_CALL(mManager, GetCaretMode())
.WillRepeatedly(Return(CaretMode::Selection));
@ -534,6 +532,8 @@ MOZ_CAN_RUN_SCRIPT
EXPECT_EQ(FirstCaretAppearance(), Appearance::Left);
EXPECT_EQ(SecondCaretAppearance(), Appearance::Right);
check.Call("scrollend2");
Preferences::SetBool("layout.accessiblecaret.always_tilt", oldPref);
}
TEST_F(AccessibleCaretManagerTester, TestScrollInCursorModeWhenLogicallyVisible)
@ -728,9 +728,8 @@ TEST_F(AccessibleCaretManagerTester,
MOZ_CAN_RUN_SCRIPT
{
// Simulate Firefox Android preference.
AutoRestore<bool> savesCaretShownWhenLongTappingOnEmptyContent(
MockAccessibleCaretManager::sCaretShownWhenLongTappingOnEmptyContent);
MockAccessibleCaretManager::sCaretShownWhenLongTappingOnEmptyContent = true;
bool oldPref = StaticPrefs::layout_accessiblecaret_caret_shown_when_long_tapping_on_empty_content();
Preferences::SetBool("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", true);
EXPECT_CALL(mManager, GetCaretMode())
.WillRepeatedly(Return(CaretMode::Cursor));
@ -816,6 +815,8 @@ MOZ_CAN_RUN_SCRIPT
mManager.OnScrollEnd();
EXPECT_EQ(FirstCaretAppearance(), Appearance::Normal);
check.Call("longtap scrollend3");
Preferences::SetBool("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", oldPref);
}
} // namespace mozilla

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

@ -465,6 +465,63 @@ VARCACHE_PREF(
bool, false
)
// By default, carets become tilt only when they are overlapping.
VARCACHE_PREF(
"layout.accessiblecaret.always_tilt",
layout_accessiblecaret_always_tilt,
bool, false
)
// Show caret in cursor mode when long tapping on an empty content. This
// also changes the default update behavior in cursor mode, which is based
// on the emptiness of the content, into something more heuristic. See
// AccessibleCaretManager::UpdateCaretsForCursorMode() for the details.
VARCACHE_PREF(
"layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content",
layout_accessiblecaret_caret_shown_when_long_tapping_on_empty_content,
bool, false
)
// 0 = by default, always hide carets for selection changes due to JS calls.
// 1 = update any visible carets for selection changes due to JS calls,
// but don't show carets if carets are hidden.
// 2 = always show carets for selection changes due to JS calls.
VARCACHE_PREF(
"layout.accessiblecaret.script_change_update_mode",
layout_accessiblecaret_script_change_update_mode,
int32_t, 0
)
// Allow one caret to be dragged across the other caret without any limitation.
// This matches the built-in convention for all desktop platforms.
VARCACHE_PREF(
"layout.accessiblecaret.allow_dragging_across_other_caret",
layout_accessiblecaret_allow_dragging_across_other_caret,
bool, true
)
// Optionally provide haptic feedback on long-press selection events.
VARCACHE_PREF(
"layout.accessiblecaret.hapticfeedback",
layout_accessiblecaret_hapticfeedback,
bool, false
)
// Smart phone-number selection on long-press is not enabled by default.
VARCACHE_PREF(
"layout.accessiblecaret.extend_selection_for_phone_number",
layout_accessiblecaret_extend_selection_for_phone_number,
bool, false
)
// Keep the accessible carets hidden when the user is using mouse input (as
// opposed to touch/pen/etc.).
VARCACHE_PREF(
"layout.accessiblecaret.hide_carets_for_mouse_input",
layout_accessiblecaret_hide_carets_for_mouse_input,
bool, true
)
// CSS attributes (width, height, margin-left) of the AccessibleCaret in CSS
// pixels.
VARCACHE_PREF(

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

@ -5514,31 +5514,6 @@ pref("plugins.flashBlock.enabled", false);
// Turn off Spatial navigation by default.
pref("snav.enabled", false);
// Show the caret when long tapping on an empty content.
pref("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", false);
// By default, carets become tilt only when they are overlapping.
pref("layout.accessiblecaret.always_tilt", false);
// 0 = by default, always hide carets for selection changes due to JS calls.
// 1 = update any visible carets for selection changes due to JS calls,
// but don't show carets if carets are hidden.
// 2 = always show carets for selection changes due to JS calls.
pref("layout.accessiblecaret.script_change_update_mode", 0);
// Allow one caret to be dragged across the other caret without any limitation.
// This matches the built-in convention for all desktop platforms.
pref("layout.accessiblecaret.allow_dragging_across_other_caret", true);
// Optionally provide haptic feedback on longPress selection events.
pref("layout.accessiblecaret.hapticfeedback", false);
// Smart phone-number selection on long-press is not enabled by default.
pref("layout.accessiblecaret.extend_selection_for_phone_number", false);
// Keep the accessible carets hidden when the user is using mouse input.
pref("layout.accessiblecaret.hide_carets_for_mouse_input", true);
// Wakelock is disabled by default.
pref("dom.wakelock.enabled", false);