From 54e108f1efbc695a8da2f3ce33a44cff2eae4a36 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Thu, 27 Apr 2017 11:29:46 +0200 Subject: Fix emitting selectionChanged signal for non-user text selection change This fixes the case when the text selection is triggered by JavaScript. Text selection changes triggered by IME composition text replecement are ignored. Test has been added for mouse selection clipboard: non-user text selection should not update the clipboard. Pulls in Chromium changes: 3deea95 Update TextSelection for non-user initiated events Task-number: QTBUG-53134 Task-number: QTBUG-60381 Change-Id: Ib94f57a2aa61248fba75f595245fb388b9609b6c Reviewed-by: Allan Sandfeld Jensen --- src/3rdparty | 2 +- src/core/render_widget_host_view_qt.cpp | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/3rdparty b/src/3rdparty index dfaf15642..3deea958f 160000 --- a/src/3rdparty +++ b/src/3rdparty @@ -1 +1 @@ -Subproject commit dfaf1564283dcdd222be9717a1a5ad9389ec7f1b +Subproject commit 3deea958f1485b50940e7437c0a3b73ed29ee134 diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 4e98a1016..f90a44044 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -757,8 +757,12 @@ void RenderWidgetHostViewQt::OnTextSelectionChanged(content::TextInputManager *t Q_UNUSED(text_input_manager); Q_UNUSED(updated_view); + const content::TextInputManager::TextSelection *selection = GetTextInputManager()->GetTextSelection(updated_view); + if (!selection) + return; + #if defined(USE_X11) - if (!GetSelectedText().empty()) { + if (!GetSelectedText().empty() && selection->user_initiated()) { // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard. ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION); clipboard_writer.WriteText(GetSelectedText()); @@ -793,6 +797,18 @@ void RenderWidgetHostViewQt::selectionChanged() return; } + if (GetSelectedText().empty()) { + m_anchorPositionWithinSelection = m_cursorPosition; + m_cursorPositionWithinSelection = m_cursorPosition; + + if (!m_emptyPreviousSelection) { + m_emptyPreviousSelection = GetSelectedText().empty(); + m_adapterClient->selectionChanged(); + } + + return; + } + const content::TextInputManager::TextSelection *selection = text_input_manager_->GetTextSelection(); if (!selection) return; @@ -800,13 +816,6 @@ void RenderWidgetHostViewQt::selectionChanged() if (!selection->range().IsValid()) return; - // Avoid duplicate empty selectionChanged() signals - if (GetSelectedText().empty() && m_emptyPreviousSelection) { - m_anchorPositionWithinSelection = m_cursorPosition; - m_cursorPositionWithinSelection = m_cursorPosition; - return; - } - int newAnchorPositionWithinSelection = 0; int newCursorPositionWithinSelection = 0; -- cgit v1.2.3