diff options
author | Peter Varga <pvarga@inf.u-szeged.hu> | 2017-04-27 11:23:55 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-12-13 16:45:31 +0100 |
commit | f69e3b7ed78363f6caf56c0a2eec900bde2bbcd1 (patch) | |
tree | 3b6e4e823144f35b79a8ec6c1ebe344bb60a97be /chromium/third_party | |
parent | 72d07669eb54a00bf8a11cda03c1c36b62c17829 (diff) | |
download | qtwebengine-chromium-f69e3b7ed78363f6caf56c0a2eec900bde2bbcd1.tar.gz |
Update TextSelection for non-user initiated events
This makes Chromium Content API to be able to notify about text
selection changes triggered by non-user events (eg. JavaScript, IME,
autofill).
Based on:
https://codereview.chromium.org/2903833002
Corresponding Chromium bug report:
https://bugs.chromium.org/p/chromium/issues/detail?id=671986
Change-Id: I86a7f203d789853199469b301facd06fe5ba54bd
Task-number: QTBUG-53134
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'chromium/third_party')
16 files changed, 47 insertions, 12 deletions
diff --git a/chromium/third_party/blink/public/mojom/frame/frame.mojom b/chromium/third_party/blink/public/mojom/frame/frame.mojom index f7b27a69da7..fdf74376972 100644 --- a/chromium/third_party/blink/public/mojom/frame/frame.mojom +++ b/chromium/third_party/blink/public/mojom/frame/frame.mojom @@ -419,7 +419,8 @@ interface LocalFrameHost { // std::u16string text in the document. TextSelectionChanged(mojo_base.mojom.BigString16 text, uint32 offset, - gfx.mojom.Range range); + gfx.mojom.Range range, + bool user_initiated); // Show a popup menu using native controls on Mac or Android. // The popup menu is hidden when the mojo channel is closed. diff --git a/chromium/third_party/blink/public/web/web_local_frame.h b/chromium/third_party/blink/public/web/web_local_frame.h index c2668fc11fe..ba78be2dace 100644 --- a/chromium/third_party/blink/public/web/web_local_frame.h +++ b/chromium/third_party/blink/public/web/web_local_frame.h @@ -502,7 +502,8 @@ class BLINK_EXPORT WebLocalFrame : public WebFrame { virtual void TextSelectionChanged(const WebString& selection_text, uint32_t offset, - const gfx::Range& range) = 0; + const gfx::Range& range, + bool user_initiated) = 0; // DEPRECATED: Use moveRangeSelection. virtual void SelectRange(const gfx::Point& base, diff --git a/chromium/third_party/blink/public/web/web_local_frame_client.h b/chromium/third_party/blink/public/web/web_local_frame_client.h index 433fb6583db..d61cc0056f4 100644 --- a/chromium/third_party/blink/public/web/web_local_frame_client.h +++ b/chromium/third_party/blink/public/web/web_local_frame_client.h @@ -700,7 +700,7 @@ class BLINK_EXPORT WebLocalFrameClient { // TextInputState may have changed call DidChangeSelection instead. // If the browser selection may not match the last synced // value, SyncCondition::kForced can be passed to force a sync. - virtual void SyncSelectionIfRequired(SyncCondition force_sync, bool is_empty_selection) {} + virtual void SyncSelectionIfRequired(SyncCondition force_sync, bool is_empty_selection, bool user_initiated) {} // TODO(https://crbug.com/787252): Remove the methods below and use the // Supplement mechanism. diff --git a/chromium/third_party/blink/public/web/web_widget.h b/chromium/third_party/blink/public/web/web_widget.h index 34730105cb8..98bbb198083 100644 --- a/chromium/third_party/blink/public/web/web_widget.h +++ b/chromium/third_party/blink/public/web/web_widget.h @@ -139,6 +139,8 @@ class WebWidget { // Set state that the widget is in the process of handling input events. virtual void SetHandlingInputEvent(bool handling) = 0; + virtual bool ImeCompositionReplacement() = 0; + // Process the input event, blocking until complete. virtual void ProcessInputEventSynchronouslyForTesting( const WebCoalescedInputEvent&) = 0; diff --git a/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.cc b/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.cc index 8608c6654c3..36bdab440b6 100644 --- a/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.cc +++ b/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.cc @@ -476,6 +476,10 @@ void WebPagePopupImpl::SetHandlingInputEvent(bool handling) { widget_base_->input_handler().set_handling_input_event(handling); } +bool WebPagePopupImpl::ImeCompositionReplacement() { + return widget_base_->input_handler().ime_composition_replacement(); +} + void WebPagePopupImpl::ProcessInputEventSynchronouslyForTesting( const WebCoalescedInputEvent& event) { widget_base_->input_handler().HandleInputEvent(event, nullptr, diff --git a/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.h b/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.h index 6a85448100e..3c3debd572d 100644 --- a/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.h +++ b/chromium/third_party/blink/renderer/core/exported/web_page_popup_impl.h @@ -179,6 +179,7 @@ class CORE_EXPORT WebPagePopupImpl final : public WebPagePopup, void SetCursor(const ui::Cursor& cursor) override; bool HandlingInputEvent() override; void SetHandlingInputEvent(bool handling) override; + bool ImeCompositionReplacement() override; void ProcessInputEventSynchronouslyForTesting( const WebCoalescedInputEvent&) override; void UpdateTextInputState() override; diff --git a/chromium/third_party/blink/renderer/core/frame/local_frame.cc b/chromium/third_party/blink/renderer/core/frame/local_frame.cc index 79bb5259e80..f5b84b6821f 100644 --- a/chromium/third_party/blink/renderer/core/frame/local_frame.cc +++ b/chromium/third_party/blink/renderer/core/frame/local_frame.cc @@ -1438,8 +1438,9 @@ String LocalFrame::SelectedTextForClipboard() const { void LocalFrame::TextSelectionChanged(const WTF::String& selection_text, uint32_t offset, - const gfx::Range& range) const { - GetLocalFrameHostRemote().TextSelectionChanged(selection_text, offset, range); + const gfx::Range& range, + bool user_initiated) const { + GetLocalFrameHostRemote().TextSelectionChanged(selection_text, offset, range, user_initiated); } PositionWithAffinity LocalFrame::PositionForPoint( diff --git a/chromium/third_party/blink/renderer/core/frame/local_frame.h b/chromium/third_party/blink/renderer/core/frame/local_frame.h index 4296d020d3f..fcb29bcadaa 100644 --- a/chromium/third_party/blink/renderer/core/frame/local_frame.h +++ b/chromium/third_party/blink/renderer/core/frame/local_frame.h @@ -403,7 +403,8 @@ class CORE_EXPORT LocalFrame final String SelectedTextForClipboard() const; void TextSelectionChanged(const WTF::String& selection_text, uint32_t offset, - const gfx::Range& range) const; + const gfx::Range& range, + bool user_initiated) const; PositionWithAffinityTemplate<EditingAlgorithm<NodeTraversal>> PositionForPoint(const PhysicalOffset& frame_point); diff --git a/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.cc b/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.cc index 2779b0a2347..d8c265a2c8b 100644 --- a/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.cc +++ b/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.cc @@ -2501,6 +2501,11 @@ void WebFrameWidgetImpl::SetHandlingInputEvent(bool handling) { widget_base_->input_handler().set_handling_input_event(handling); } +bool WebFrameWidgetImpl::ImeCompositionReplacement() +{ + return widget_base_->input_handler().ime_composition_replacement(); +} + void WebFrameWidgetImpl::ProcessInputEventSynchronouslyForTesting( const WebCoalescedInputEvent& event, WidgetBaseInputHandler::HandledEventCallback callback) { @@ -3777,7 +3782,8 @@ void WebFrameWidgetImpl::Replace(const String& word) { // If the resulting selection is not actually a change in selection, we do not // need to explicitly notify about the selection change. focused_frame->Client()->SyncSelectionIfRequired( - blink::SyncCondition::kNotForced); + blink::SyncCondition::kNotForced, false /* is_empty_selection */, + true /* user_initiated */); } void WebFrameWidgetImpl::ReplaceMisspelling(const String& word) { diff --git a/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.h b/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.h index 30e106d5b8d..d4e8fbca386 100644 --- a/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.h +++ b/chromium/third_party/blink/renderer/core/frame/web_frame_widget_impl.h @@ -379,6 +379,7 @@ class CORE_EXPORT WebFrameWidgetImpl void SetCursor(const ui::Cursor& cursor) override; bool HandlingInputEvent() override; void SetHandlingInputEvent(bool handling) override; + bool ImeCompositionReplacement() override; void ProcessInputEventSynchronouslyForTesting( const WebCoalescedInputEvent&) override; WebInputEventResult DispatchBufferedTouchEvents() override; diff --git a/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.cc b/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.cc index ca4280f1a9c..b4910a22e44 100644 --- a/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.cc +++ b/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.cc @@ -1457,8 +1457,9 @@ WebString WebLocalFrameImpl::SelectionAsMarkup() const { void WebLocalFrameImpl::TextSelectionChanged(const WebString& selection_text, uint32_t offset, - const gfx::Range& range) { - GetFrame()->TextSelectionChanged(selection_text, offset, range); + const gfx::Range& range, + bool user_initiated) { + GetFrame()->TextSelectionChanged(selection_text, offset, range, user_initiated); } bool WebLocalFrameImpl::SelectAroundCaret( diff --git a/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.h b/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.h index 314e2a869bc..c0cbaa8e69b 100644 --- a/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.h +++ b/chromium/third_party/blink/renderer/core/frame/web_local_frame_impl.h @@ -221,7 +221,8 @@ class CORE_EXPORT WebLocalFrameImpl final WebString SelectionAsMarkup() const override; void TextSelectionChanged(const WebString& selection_text, uint32_t offset, - const gfx::Range& range) override; + const gfx::Range& range, + bool) override; bool SelectAroundCaret(mojom::blink::SelectionGranularity granularity, bool should_show_handle, bool should_show_context_menu); diff --git a/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.cc b/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.cc index e1cdddf4c4b..562a88b5372 100644 --- a/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.cc +++ b/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.cc @@ -164,7 +164,8 @@ void FakeLocalFrameHost::FocusedElementChanged( void FakeLocalFrameHost::TextSelectionChanged(const WTF::String& text, uint32_t offset, - const gfx::Range& range) {} + const gfx::Range& range, + bool user_initiated) {} void FakeLocalFrameHost::ShowPopupMenu( mojo::PendingRemote<mojom::blink::PopupMenuClient> popup_client, const gfx::Rect& bounds, diff --git a/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.h b/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.h index 80b9d8f4659..a6da40fc95d 100644 --- a/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.h +++ b/chromium/third_party/blink/renderer/core/testing/fake_local_frame_host.h @@ -107,7 +107,8 @@ class FakeLocalFrameHost : public mojom::blink::LocalFrameHost { blink::mojom::FocusType focus_type) override; void TextSelectionChanged(const WTF::String& text, uint32_t offset, - const gfx::Range& range) override; + const gfx::Range& range, + bool user_initiated) override; void ShowPopupMenu( mojo::PendingRemote<mojom::blink::PopupMenuClient> popup_client, const gfx::Rect& bounds, diff --git a/chromium/third_party/blink/renderer/platform/widget/input/widget_base_input_handler.h b/chromium/third_party/blink/renderer/platform/widget/input/widget_base_input_handler.h index 4d47c0290f7..0e7e90cb5f1 100644 --- a/chromium/third_party/blink/renderer/platform/widget/input/widget_base_input_handler.h +++ b/chromium/third_party/blink/renderer/platform/widget/input/widget_base_input_handler.h @@ -90,6 +90,13 @@ class PLATFORM_EXPORT WidgetBaseInputHandler { // cursor. bool DidChangeCursor(const ui::Cursor& cursor); + bool ime_composition_replacement() const { + return ime_composition_replacement_; + } + void set_ime_composition_replacement(bool ime_composition_replacement) { + ime_composition_replacement_ = ime_composition_replacement; + } + private: class HandlingState; struct InjectScrollGestureParams { @@ -137,6 +144,10 @@ class PLATFORM_EXPORT WidgetBaseInputHandler { const bool supports_buffered_touch_ = false; + // Used to suppress notification about text selection changes triggered by + // IME composition when it replaces text. + bool ime_composition_replacement_ = false; + base::WeakPtrFactory<WidgetBaseInputHandler> weak_ptr_factory_{this}; }; diff --git a/chromium/third_party/blink/renderer/platform/widget/widget_base.cc b/chromium/third_party/blink/renderer/platform/widget/widget_base.cc index f779d8d0910..cab2ccd8a82 100644 --- a/chromium/third_party/blink/renderer/platform/widget/widget_base.cc +++ b/chromium/third_party/blink/renderer/platform/widget/widget_base.cc @@ -1346,6 +1346,7 @@ void WidgetBase::ImeSetComposition( } ImeEventGuard guard(weak_ptr_factory_.GetWeakPtr()); + input_handler_.set_ime_composition_replacement(replacement_range.IsValid()); if (!frame_widget->SetComposition(text, ime_text_spans, replacement_range, selection_start, selection_end)) { // If we failed to set the composition text, then we need to let the browser @@ -1356,6 +1357,7 @@ void WidgetBase::ImeSetComposition( host->ImeCancelComposition(); } } + input_handler_.set_ime_composition_replacement(false); UpdateCompositionInfo(false /* not an immediate request */); } |