Bug 1121468 - Show carets when long-pressing on selection highlight. r?roc
The blur event will hide the carets and produces a standalone selection
highlight without carets. When a user long-pressing on the highlight, we
should show carets for the original selection highlight instead of
select a new word.
The helper UpdateCaretsWithHapticFeedback() should only be needed when
long-pressing. It should suffice to live within SelectWordOrShortcut()
instead of being a member function.
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -451,16 +451,21 @@ AccessibleCaretManager::TapCaret(const n
}
return rv;
}
nsresult
AccessibleCaretManager::SelectWordOrShortcut(const nsPoint& aPoint)
{
+ auto UpdateCaretsWithHapticFeedback = [this] {
+ UpdateCarets();
+ ProvideHapticFeedback();
+ };
+
if (!mPresShell) {
return NS_ERROR_UNEXPECTED;
}
nsIFrame* rootFrame = mPresShell->GetRootFrame();
if (!rootFrame) {
return NS_ERROR_NOT_AVAILABLE;
}
@@ -483,18 +488,17 @@ AccessibleCaretManager::SelectWordOrShor
// Firstly check long press on an empty editable content.
Element* newFocusEditingHost = GetEditingHostForFrame(ptFrame);
if (focusableFrame && newFocusEditingHost &&
!HasNonEmptyTextContent(newFocusEditingHost)) {
ChangeFocusToOrClearOldFocus(focusableFrame);
// We need to update carets to get correct information before dispatching
// CaretStateChangedEvent.
- UpdateCarets();
- ProvideHapticFeedback();
+ UpdateCaretsWithHapticFeedback();
DispatchCaretStateChangedEvent(CaretChangedReason::Longpressonemptycontent);
return NS_OK;
}
bool selectable = false;
ptFrame->IsSelectable(&selectable, nullptr);
#ifdef DEBUG_FRAME_DUMP
@@ -509,23 +513,32 @@ AccessibleCaretManager::SelectWordOrShor
// Commit the composition string of the old editable focus element (if there
// is any) before changing the focus.
IMEStateManager::NotifyIME(widget::REQUEST_TO_COMMIT_COMPOSITION,
mPresShell->GetPresContext());
// ptFrame is selectable. Now change the focus.
ChangeFocusToOrClearOldFocus(focusableFrame);
+ if (GetCaretMode() == CaretMode::Selection &&
+ !mFirstCaret->IsLogicallyVisible() && !mSecondCaret->IsLogicallyVisible()) {
+ // We have a selection while both carets have Appearance::None because of
+ // previous operations like blur event. Just update carets on the selection
+ // without selecting a new word.
+ AC_LOG("%s: UpdateCarets() for current selection", __FUNCTION__);
+ UpdateCaretsWithHapticFeedback();
+ return NS_OK;
+ }
+
// Then try select a word under point.
nsPoint ptInFrame = aPoint;
nsLayoutUtils::TransformPoint(rootFrame, ptFrame, ptInFrame);
nsresult rv = SelectWord(ptFrame, ptInFrame);
- UpdateCarets();
- ProvideHapticFeedback();
+ UpdateCaretsWithHapticFeedback();
return rv;
}
void
AccessibleCaretManager::OnScrollStart()
{
AC_LOG("%s", __FUNCTION__);