diff --git a/layout/base/SelectionCarets.cpp b/layout/base/SelectionCarets.cpp index b29b4600cd5f..37434e236d5a 100644 --- a/layout/base/SelectionCarets.cpp +++ b/layout/base/SelectionCarets.cpp @@ -577,6 +577,7 @@ SelectionCarets::SelectWord() bool selectable; ptFrame->IsSelectable(&selectable, nullptr); if (!selectable) { + SELECTIONCARETS_LOG(" frame %p is not selectable", ptFrame); return NS_ERROR_FAILURE; } @@ -593,6 +594,17 @@ SelectionCarets::SelectWord() if (elt) { fm->SetFocus(elt, 0); } + + if (!nsContentUtils::HasNonEmptyTextContent( + editingHost, nsContentUtils::eRecurseIntoChildren)) { + SELECTIONCARETS_LOG("Select a editable content %p with empty text", + editingHost); + // Long tap on the content with empty text, no action for + // selectioncarets but need to dispatch the touchcarettap event + // to support the short cut mode + DispatchCustomEvent(NS_LITERAL_STRING("touchcarettap")); + return NS_OK; + } } else { nsIContent* focusedContent = GetFocusedContent(); if (focusedContent && focusedContent->GetTextEditorRootContent()) { @@ -1038,6 +1050,21 @@ SelectionCarets::GetSelectionBoundingRect(Selection* aSel) return res; } +void +SelectionCarets::DispatchCustomEvent(const nsAString& aEvent) +{ + SELECTIONCARETS_LOG("dispatch %s event", NS_ConvertUTF16toUTF8(aEvent).get()); + bool defaultActionEnabled = true; + nsIDocument* doc = mPresShell->GetDocument(); + MOZ_ASSERT(doc); + nsContentUtils::DispatchTrustedEvent(doc, + ToSupports(doc), + aEvent, + true, + false, + &defaultActionEnabled); +} + void SelectionCarets::DispatchSelectionStateChangedEvent(Selection* aSelection, SelectionState aState) diff --git a/layout/base/SelectionCarets.h b/layout/base/SelectionCarets.h index 36a984c7d5e8..be06daa3273f 100644 --- a/layout/base/SelectionCarets.h +++ b/layout/base/SelectionCarets.h @@ -207,6 +207,7 @@ private: dom::SelectionState aState); void DispatchSelectionStateChangedEvent(dom::Selection* aSelection, const dom::Sequence& aStates); + void DispatchCustomEvent(const nsAString& aEvent); nsRect GetSelectionBoundingRect(dom::Selection* aSel); /**