Bug 1347047 Part 2 - Remove caret timeout control from AccessibleCaretManager.
The feature is controlled by pref layout.accessiblecaret.timeout_ms, and has been disabled in
bug 1268410.
It's time to remove relevant code from the tree.
MozReview-Commit-ID: LLu8RiQcTpm
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -93,18 +93,16 @@ AccessibleCaretManager::AccessibleCaretM
{
if (!mPresShell) {
return;
}
mFirstCaret = MakeUnique<AccessibleCaret>(mPresShell);
mSecondCaret = MakeUnique<AccessibleCaret>(mPresShell);
- mCaretTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
-
static bool addedPrefs = false;
if (!addedPrefs) {
Preferences::AddBoolVarCache(&sSelectionBarEnabled,
"layout.accessiblecaret.bar.enabled");
Preferences::AddBoolVarCache(&sCaretShownWhenLongTappingOnEmptyContent,
"layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content");
Preferences::AddBoolVarCache(&sCaretsAlwaysTilt,
"layout.accessiblecaret.always_tilt");
@@ -126,18 +124,16 @@ AccessibleCaretManager::AccessibleCaretM
AccessibleCaretManager::~AccessibleCaretManager()
{
}
void
AccessibleCaretManager::Terminate()
{
- CancelCaretTimeoutTimer();
- mCaretTimeoutTimer = nullptr;
mFirstCaret = nullptr;
mSecondCaret = nullptr;
mActiveCaret = nullptr;
mPresShell = nullptr;
}
nsresult
AccessibleCaretManager::OnSelectionChanged(nsIDOMDocument* aDoc,
@@ -214,17 +210,16 @@ AccessibleCaretManager::OnSelectionChang
void
AccessibleCaretManager::HideCarets()
{
if (mFirstCaret->IsLogicallyVisible() || mSecondCaret->IsLogicallyVisible()) {
AC_LOG("%s", __FUNCTION__);
mFirstCaret->SetAppearance(Appearance::None);
mSecondCaret->SetAppearance(Appearance::None);
DispatchCaretStateChangedEvent(CaretChangedReason::Visibilitychange);
- CancelCaretTimeoutTimer();
}
}
void
AccessibleCaretManager::UpdateCarets(UpdateCaretsHintSet aHint)
{
FlushLayout();
if (IsTerminated()) {
@@ -332,18 +327,16 @@ AccessibleCaretManager::UpdateCaretsForC
case PositionChangedResult::Invisible:
mFirstCaret->SetAppearance(Appearance::NormalNotShown);
break;
}
mFirstCaret->SetSelectionBarEnabled(false);
mSecondCaret->SetAppearance(Appearance::None);
- LaunchCaretTimeoutTimer();
-
if (!aHints.contains(UpdateCaretsHint::DispatchNoEvent) &&
!mActiveCaret) {
DispatchCaretStateChangedEvent(CaretChangedReason::Updateposition);
}
}
void
AccessibleCaretManager::UpdateCaretsForSelectionMode(UpdateCaretsHintSet aHints)
@@ -496,17 +489,16 @@ AccessibleCaretManager::PressCaret(const
SetSelectionDirection(eDirNext);
}
if (mActiveCaret) {
mOffsetYToCaretLogicalPosition =
mActiveCaret->LogicalPosition().y - aPoint.y;
SetSelectionDragState(true);
DispatchCaretStateChangedEvent(CaretChangedReason::Presscaret);
- CancelCaretTimeoutTimer();
rv = NS_OK;
}
return rv;
}
nsresult
AccessibleCaretManager::DragCaret(const nsPoint& aPoint)
@@ -523,17 +515,16 @@ AccessibleCaretManager::DragCaret(const
nsresult
AccessibleCaretManager::ReleaseCaret()
{
MOZ_ASSERT(mActiveCaret);
mActiveCaret = nullptr;
SetSelectionDragState(false);
DispatchCaretStateChangedEvent(CaretChangedReason::Releasecaret);
- LaunchCaretTimeoutTimer();
return NS_OK;
}
nsresult
AccessibleCaretManager::TapCaret(const nsPoint& aPoint)
{
MOZ_ASSERT(GetCaretMode() != CaretMode::None);
@@ -683,17 +674,17 @@ AccessibleCaretManager::OnScrollEnd()
if (!sCaretsAlwaysShowWhenScrolling) {
// Restore the appearance which is saved before the scrolling is started.
mFirstCaret->SetAppearance(mFirstCaretAppearanceOnScrollStart);
mSecondCaret->SetAppearance(mSecondCaretAppearanceOnScrollStart);
}
if (GetCaretMode() == CaretMode::Cursor) {
if (!mFirstCaret->IsLogicallyVisible()) {
- // If the caret is hidden (Appearance::None) due to timeout or blur, no
+ // If the caret is hidden (Appearance::None) due to blur, no
// need to update it.
return;
}
}
// For mouse input we don't want to show the carets.
if (sHideCaretsForMouseInput &&
mLastInputSource == nsIDOMMouseEvent::MOZ_SOURCE_MOUSE) {
@@ -1377,58 +1368,16 @@ AccessibleCaretManager::AdjustDragBounda
adjustedPoint.y = dragUpBoundaryY;
}
}
}
return adjustedPoint;
}
-uint32_t
-AccessibleCaretManager::CaretTimeoutMs() const
-{
- static bool added = false;
- static uint32_t caretTimeoutMs = 0;
-
- if (!added) {
- Preferences::AddUintVarCache(&caretTimeoutMs,
- "layout.accessiblecaret.timeout_ms");
- added = true;
- }
-
- return caretTimeoutMs;
-}
-
-void
-AccessibleCaretManager::LaunchCaretTimeoutTimer()
-{
- if (!mPresShell || !mCaretTimeoutTimer || CaretTimeoutMs() == 0 ||
- GetCaretMode() != CaretMode::Cursor || mActiveCaret) {
- return;
- }
-
- nsTimerCallbackFunc callback = [](nsITimer* aTimer, void* aClosure) {
- auto self = static_cast<AccessibleCaretManager*>(aClosure);
- if (self->GetCaretMode() == CaretMode::Cursor) {
- self->HideCarets();
- }
- };
-
- mCaretTimeoutTimer->InitWithFuncCallback(callback, this, CaretTimeoutMs(),
- nsITimer::TYPE_ONE_SHOT);
-}
-
-void
-AccessibleCaretManager::CancelCaretTimeoutTimer()
-{
- if (mCaretTimeoutTimer) {
- mCaretTimeoutTimer->Cancel();
- }
-}
-
void
AccessibleCaretManager::DispatchCaretStateChangedEvent(CaretChangedReason aReason) const
{
if (!mPresShell) {
return;
}
FlushLayout();
--- a/layout/base/AccessibleCaretManager.h
+++ b/layout/base/AccessibleCaretManager.h
@@ -123,17 +123,17 @@ protected:
friend std::ostream& operator<<(std::ostream& aStream,
const CaretMode& aCaretMode);
enum class UpdateCaretsHint : uint8_t {
// Update everything including appearance and position.
Default,
// Update everything while respecting the old appearance. For example, if
- // the caret in cursor mode is hidden due to timeout, do not change its
+ // the caret in cursor mode is hidden due to blur, do not change its
// appearance to Normal.
RespectOldAppearance,
// No CaretStateChangedEvent will be dispatched in the end of
// UpdateCarets().
DispatchNoEvent,
};
@@ -213,22 +213,16 @@ protected:
// @param aOffsets is the new position of the active caret, and it will be set
// to the `limit` when 1) sCaretsAllowDraggingAcrossOtherCaret is false and
// it's being dragged past the limit. 2) sCaretsAllowDraggingAcrossOtherCaret
// is true and the active caret's position is the same as the inactive's
// position.
// @return true if the aOffsets is suitable for changing the selection.
bool RestrictCaretDraggingOffsets(nsIFrame::ContentOffsets& aOffsets);
- // Timeout in milliseconds to hide the AccessibleCaret under cursor mode while
- // no one touches it.
- uint32_t CaretTimeoutMs() const;
- void LaunchCaretTimeoutTimer();
- void CancelCaretTimeoutTimer();
-
// ---------------------------------------------------------------------------
// The following functions are made virtual for stubbing or mocking in gtest.
//
// @return true if Terminate() had been called.
virtual bool IsTerminated() const { return !mPresShell; }
// Get caret mode based on current selection.
virtual CaretMode GetCaretMode() const;
@@ -275,20 +269,16 @@ protected:
// Second caret is used solely in selection mode, and is attached to selection
// highlight as the right caret.
UniquePtr<AccessibleCaret> mSecondCaret;
// The caret being pressed or dragged.
AccessibleCaret* mActiveCaret = nullptr;
- // The timer for hiding the caret in cursor mode after timeout behind the
- // preference "layout.accessiblecaret.timeout_ms".
- nsCOMPtr<nsITimer> mCaretTimeoutTimer;
-
// The caret mode since last update carets.
CaretMode mLastUpdateCaretMode = CaretMode::None;
// Store the appearance of the carets when calling OnScrollStart() so that it
// can be restored in OnScrollEnd().
AccessibleCaret::Appearance mFirstCaretAppearanceOnScrollStart =
AccessibleCaret::Appearance::None;
AccessibleCaret::Appearance mSecondCaretAppearanceOnScrollStart =