diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/editing/suggestion')
3 files changed, 48 insertions, 21 deletions
diff --git a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.cc b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.cc index 75b21990cd5..748094ca5cf 100644 --- a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.cc +++ b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.cc @@ -152,8 +152,8 @@ SuggestionInfosWithNodeAndHighlightColor ComputeSuggestionInfos( Vector<TextSuggestionInfo>& suggestion_infos = suggestion_infos_with_node_and_highlight_color.suggestion_infos; - for (const std::pair<const Text*, DocumentMarker*>& node_marker_pair : - node_suggestion_marker_pairs_sorted_by_length) { + for (const std::pair<Member<const Text>, Member<DocumentMarker>>& + node_marker_pair : node_suggestion_marker_pairs_sorted_by_length) { if (node_marker_pair.first != suggestion_infos_with_node_and_highlight_color.text_node) continue; @@ -161,7 +161,7 @@ SuggestionInfosWithNodeAndHighlightColor ComputeSuggestionInfos( if (suggestion_infos.size() == max_number_of_suggestions) break; - const auto* marker = To<SuggestionMarker>(node_marker_pair.second); + const auto* marker = To<SuggestionMarker>(node_marker_pair.second.Get()); const Vector<String>& marker_suggestions = marker->Suggestions(); for (wtf_size_t suggestion_index = 0; suggestion_index < marker_suggestions.size(); ++suggestion_index) { @@ -197,7 +197,7 @@ TextSuggestionController::TextSuggestionController(LocalFrame& frame) void TextSuggestionController::DidAttachDocument(Document* document) { DCHECK(document); - SetContext(document); + SetExecutionContext(document->ToExecutionContext()); } bool TextSuggestionController::IsMenuOpen() const { @@ -206,8 +206,18 @@ bool TextSuggestionController::IsMenuOpen() const { void TextSuggestionController::HandlePotentialSuggestionTap( const PositionInFlatTree& caret_position) { + if (!IsAvailable()) { + // TODO(crbug.com/1054955): We should fix caller not to make this happens. + NOTREACHED(); + return; + } + if (GetFrame() != GetDocument().GetFrame()) { + // TODO(crbug.com/1054955): We should fix caller not to make this happens. + NOTREACHED(); + return; + } // TODO(crbug.com/779126): add support for suggestions in immersive mode. - if (GetDocument().GetSettings()->GetImmersiveModeEnabled()) + if (GetFrame().GetSettings()->GetImmersiveModeEnabled()) return; // It's theoretically possible, but extremely unlikely, that the user has @@ -243,7 +253,7 @@ void TextSuggestionController::HandlePotentialSuggestionTap( void TextSuggestionController::Trace(Visitor* visitor) { visitor->Trace(frame_); - DocumentShutdownObserver::Trace(visitor); + ExecutionContextLifecycleObserver::Trace(visitor); } void TextSuggestionController::ReplaceActiveSuggestionRange( @@ -420,6 +430,7 @@ void TextSuggestionController::ShowSpellCheckMenu( GetDocument().Markers().AddActiveSuggestionMarker( active_suggestion_range, SK_ColorTRANSPARENT, ui::mojom::ImeTextSpanThickness::kNone, + ui::mojom::ImeTextSpanUnderlineStyle::kSolid, SK_ColorTRANSPARENT, LayoutTheme::GetTheme().PlatformActiveSpellingMarkerHighlightColor()); Vector<String> suggestions; @@ -485,6 +496,7 @@ void TextSuggestionController::ShowSuggestionMenu( GetDocument().Markers().AddActiveSuggestionMarker( marker_range, SK_ColorTRANSPARENT, ui::mojom::ImeTextSpanThickness::kThin, + ui::mojom::ImeTextSpanUnderlineStyle::kSolid, SK_ColorTRANSPARENT, suggestion_infos_with_node_and_highlight_color.highlight_color); is_suggestion_menu_open_ = true; @@ -523,11 +535,11 @@ void TextSuggestionController::CallMojoShowTextSuggestionMenu( Document& TextSuggestionController::GetDocument() const { DCHECK(IsAvailable()); - return *LifecycleContext(); + return *Document::From(GetExecutionContext()); } bool TextSuggestionController::IsAvailable() const { - return LifecycleContext(); + return GetExecutionContext(); } LocalFrame& TextSuggestionController::GetFrame() const { @@ -612,7 +624,8 @@ void TextSuggestionController::ReplaceRangeWithText(const EphemeralRange& range, // available or not. // TODO(editing-dev): The use of UpdateStyleAndLayout // needs to be audited. See http://crbug.com/590369 for more details. - GetFrame().GetDocument()->UpdateStyleAndLayout(); + GetFrame().GetDocument()->UpdateStyleAndLayout( + DocumentUpdateReason::kSpellCheck); // Dispatch 'beforeinput'. Element* const target = FindEventTargetFrom( @@ -634,7 +647,8 @@ void TextSuggestionController::ReplaceRangeWithText(const EphemeralRange& range, // TODO(editing-dev): The use of UpdateStyleAndLayout // needs to be audited. See http://crbug.com/590369 for more details. - GetFrame().GetDocument()->UpdateStyleAndLayout(); + GetFrame().GetDocument()->UpdateStyleAndLayout( + DocumentUpdateReason::kSpellCheck); if (is_canceled) return; diff --git a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h index 61702afe3e0..29b70a243ef 100644 --- a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h +++ b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller.h @@ -10,9 +10,9 @@ #include "third_party/blink/public/mojom/input/input_host.mojom-blink.h" #include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/dom/document.h" -#include "third_party/blink/renderer/core/dom/document_shutdown_observer.h" #include "third_party/blink/renderer/core/editing/forward.h" #include "third_party/blink/renderer/core/editing/markers/document_marker.h" +#include "third_party/blink/renderer/core/execution_context/execution_context_lifecycle_observer.h" #include "third_party/blink/renderer/platform/heap/handle.h" namespace blink { @@ -27,7 +27,7 @@ struct TextSuggestionInfo; // suggestions. Android is currently the only platform that has such a menu. class CORE_EXPORT TextSuggestionController final : public GarbageCollected<TextSuggestionController>, - public DocumentShutdownObserver { + public ExecutionContextLifecycleObserver { USING_GARBAGE_COLLECTED_MIXIN(TextSuggestionController); public: @@ -46,6 +46,9 @@ class CORE_EXPORT TextSuggestionController final void OnSuggestionMenuClosed(); void SuggestionMenuTimeoutCallback(size_t max_number_of_suggestions); + // ExecutionContextLifecycleObserver methods: + void ContextDestroyed() override {} + void Trace(Visitor*) override; private: diff --git a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller_test.cc b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller_test.cc index 65ca6e7f00d..d2a6e5a1f8a 100644 --- a/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller_test.cc +++ b/chromium/third_party/blink/renderer/core/editing/suggestion/text_suggestion_controller_test.cc @@ -12,8 +12,10 @@ #include "third_party/blink/renderer/core/editing/spellcheck/spell_checker.h" #include "third_party/blink/renderer/core/editing/testing/editing_test_base.h" #include "third_party/blink/renderer/core/editing/visible_selection.h" +#include "third_party/blink/renderer/core/frame/local_dom_window.h" using ui::mojom::ImeTextSpanThickness; +using ui::mojom::ImeTextSpanUnderlineStyle; namespace blink { @@ -56,7 +58,8 @@ TEST_F(TextSuggestionControllerTest, ApplySpellCheckSuggestion) { GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 0), Position(text, 8)), Color::kBlack, - ImeTextSpanThickness::kThin, Color::kBlack); + ImeTextSpanThickness::kThin, ImeTextSpanUnderlineStyle::kSolid, + Color::kBlack, Color::kBlack); // Select immediately before misspelling GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -237,7 +240,8 @@ TEST_F(TextSuggestionControllerTest, DeleteActiveSuggestionRange_DeleteAtEnd) { // Mark "word2" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 6), Position(text, 11)), - Color::kTransparent, ImeTextSpanThickness::kThin, Color::kBlack); + Color::kTransparent, ImeTextSpanThickness::kThin, + ImeTextSpanUnderlineStyle::kSolid, Color::kBlack, Color::kBlack); // Select immediately before word2 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -263,7 +267,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word2" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 6), Position(text, 11)), - Color::kTransparent, ImeTextSpanThickness::kThin, Color::kBlack); + Color::kTransparent, ImeTextSpanThickness::kThin, + ImeTextSpanUnderlineStyle::kSolid, Color::kBlack, Color::kBlack); // Select immediately before word2 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -290,7 +295,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word1" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 0), Position(text, 5)), Color::kTransparent, - ImeTextSpanThickness::kThin, Color::kBlack); + ImeTextSpanThickness::kThin, ImeTextSpanUnderlineStyle::kSolid, + Color::kBlack, Color::kBlack); // Select immediately before word1 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -318,7 +324,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word1" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 0), Position(text, 5)), Color::kTransparent, - ImeTextSpanThickness::kThin, Color::kBlack); + ImeTextSpanThickness::kThin, ImeTextSpanUnderlineStyle::kSolid, + Color::kBlack, Color::kBlack); // Select immediately before word1 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -349,7 +356,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word2" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 5), Position(text, 10)), - Color::kTransparent, ImeTextSpanThickness::kThin, Color::kBlack); + Color::kTransparent, ImeTextSpanThickness::kThin, + ImeTextSpanUnderlineStyle::kSolid, Color::kBlack, Color::kBlack); // Select immediately before word2 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -375,7 +383,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word2" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 6), Position(text, 11)), - Color::kTransparent, ImeTextSpanThickness::kThin, Color::kBlack); + Color::kTransparent, ImeTextSpanThickness::kThin, + ImeTextSpanUnderlineStyle::kSolid, Color::kBlack, Color::kBlack); // Select immediately before word2 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -401,7 +410,8 @@ TEST_F(TextSuggestionControllerTest, // Mark "word1" as the active suggestion range GetDocument().Markers().AddActiveSuggestionMarker( EphemeralRange(Position(text, 0), Position(text, 5)), Color::kTransparent, - ImeTextSpanThickness::kThin, Color::kBlack); + ImeTextSpanThickness::kThin, ImeTextSpanUnderlineStyle::kSolid, + Color::kBlack, Color::kBlack); // Select immediately before word1 GetDocument().GetFrame()->Selection().SetSelectionAndEndTyping( SelectionInDOMTree::Builder() @@ -460,7 +470,7 @@ TEST_F(TextSuggestionControllerTest, TEST_F(TextSuggestionControllerTest, CallbackHappensAfterDocumentDestroyed) { LocalFrame& frame = *GetDocument().GetFrame(); - GetDocument().Shutdown(); + frame.DomWindow()->FrameDestroyed(); // Shouldn't crash frame.GetTextSuggestionController().SuggestionMenuTimeoutCallback(0); |