Bug 1293483 - Keep the carets hidden when the user is using a mouse to modify the selection. r=TYLin

MozReview-Commit-ID: FJwODLk6XMS
This commit is contained in:
Kartikaya Gupta 2016-10-03 08:57:44 -04:00
parent 45cb9941ab
commit 8b51259dcd
5 changed files with 59 additions and 0 deletions

View File

@ -514,6 +514,16 @@ AccessibleCaretEventHub::HandleMouseEvent(WidgetMouseEvent* aEvent)
(mActiveTouchId == kInvalidTouchId ? kDefaultTouchId : mActiveTouchId);
nsPoint point = GetMouseEventPosition(aEvent);
if (aEvent->mMessage == eMouseDown ||
aEvent->mMessage == eMouseUp ||
aEvent->mMessage == eMouseClick ||
aEvent->mMessage == eMouseDoubleClick ||
aEvent->mMessage == eMouseLongTap) {
// Don't reset the source on mouse movement since that can
// happen anytime, even randomly during a touch sequence.
mManager->SetLastInputSource(aEvent->inputSource);
}
switch (aEvent->mMessage) {
case eMouseDown:
AC_LOGV("Before eMouseDown, state: %s", mState->Name());
@ -562,6 +572,8 @@ AccessibleCaretEventHub::HandleTouchEvent(WidgetTouchEvent* aEvent)
: mActiveTouchId);
nsPoint point = GetTouchEventPosition(aEvent, id);
mManager->SetLastInputSource(nsIDOMMouseEvent::MOZ_SOURCE_TOUCH);
switch (aEvent->mMessage) {
case eTouchStart:
AC_LOGV("Before eTouchStart, state: %s", mState->Name());
@ -596,6 +608,8 @@ AccessibleCaretEventHub::HandleTouchEvent(WidgetTouchEvent* aEvent)
nsEventStatus
AccessibleCaretEventHub::HandleKeyboardEvent(WidgetKeyboardEvent* aEvent)
{
mManager->SetLastInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
switch (aEvent->mMessage) {
case eKeyUp:
AC_LOGV("eKeyUp, state: %s", mState->Name());

View File

@ -83,6 +83,8 @@ AccessibleCaretManager::sCaretsAllowDraggingAcrossOtherCaret = true;
AccessibleCaretManager::sHapticFeedback = false;
/*static*/ bool
AccessibleCaretManager::sExtendSelectionForPhoneNumber = false;
/*static*/ bool
AccessibleCaretManager::sHideCaretsForMouseInput = true;
AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
: mPresShell(aPresShell)
@ -114,6 +116,8 @@ AccessibleCaretManager::AccessibleCaretManager(nsIPresShell* aPresShell)
"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;
}
}
@ -185,6 +189,13 @@ AccessibleCaretManager::OnSelectionChanged(nsIDOMDocument* aDoc,
return NS_OK;
}
// For mouse input we don't want to show the carets.
if (sHideCaretsForMouseInput &&
mLastInputSource == nsIDOMMouseEvent::MOZ_SOURCE_MOUSE) {
HideCarets();
return NS_OK;
}
UpdateCarets();
return NS_OK;
}
@ -672,6 +683,14 @@ AccessibleCaretManager::OnScrollEnd()
}
}
// For mouse input we don't want to show the carets.
if (sHideCaretsForMouseInput &&
mLastInputSource == nsIDOMMouseEvent::MOZ_SOURCE_MOUSE) {
AC_LOG("%s: HideCarets()", __FUNCTION__);
HideCarets();
return;
}
AC_LOG("%s: UpdateCarets()", __FUNCTION__);
UpdateCarets();
}
@ -725,6 +744,12 @@ AccessibleCaretManager::OnFrameReconstruction()
mSecondCaret->EnsureApzAware();
}
void
AccessibleCaretManager::SetLastInputSource(uint16_t aInputSource)
{
mLastInputSource = aInputSource;
}
Selection*
AccessibleCaretManager::GetSelection() const
{

View File

@ -10,6 +10,7 @@
#include "AccessibleCaret.h"
#include "nsCOMPtr.h"
#include "nsCoord.h"
#include "nsIDOMMouseEvent.h"
#include "nsIFrame.h"
#include "nsISelectionListener.h"
#include "mozilla/RefPtr.h"
@ -102,6 +103,10 @@ public:
// was reconstructed, resulting in the content elements getting cloned.
virtual void OnFrameReconstruction();
// Update the manager with the last input source that was observed. This
// is used in part to determine if the carets should be shown or hidden.
void SetLastInputSource(uint16_t aInputSource);
protected:
// This enum representing the number of AccessibleCarets on the screen.
enum class CaretMode : uint8_t {
@ -276,6 +281,12 @@ protected:
AccessibleCaret::Appearance mSecondCaretAppearanceOnScrollStart =
AccessibleCaret::Appearance::None;
// The last input source that the event hub saw. We use this to decide whether
// or not show the carets when the selection is updated, as we want to hide
// the carets for mouse-triggered selection changes but show them for other
// input types such as touch.
uint16_t mLastInputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
static const int32_t kAutoScrollTimerDelay = 30;
// Clicking on the boundary of input or textarea will move the caret to the
@ -319,6 +330,10 @@ protected:
// 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,

View File

@ -35,9 +35,11 @@ class AccessibleCaretCursorModeTestCase(MarionetteTestCase):
super(AccessibleCaretCursorModeTestCase, self).setUp()
self.caret_tested_pref = 'layout.accessiblecaret.enabled'
self.caret_timeout_ms_pref = 'layout.accessiblecaret.timeout_ms'
self.hide_carets_for_mouse = 'layout.accessiblecaret.hide_carets_for_mouse_input'
self.prefs = {
self.caret_tested_pref: True,
self.caret_timeout_ms_pref: 0,
self.hide_carets_for_mouse: False,
}
self.marionette.set_prefs(self.prefs)
self.actions = Actions(self.marionette)

View File

@ -5258,6 +5258,9 @@ 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);