summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2018-06-07 09:58:31 +0200
committerPeter Varga <pvarga@inf.u-szeged.hu>2019-01-31 07:51:32 +0000
commit713cfd8a684b2fd4e1d4a74d19415c36c370adbb (patch)
tree72b4da49e1dd4d2f5176bd97d8c97a8ec4336fb2 /src/core
parent94d2cba36b8a1c3e02ca2abf16b11963fd1801d5 (diff)
Implement touch text selection for QQuickWebEngineView
Touch handle and touch selection menu are not implemented for widget. Task-number: QTBUG-59999 Change-Id: Ia492e58b83d3ad38cdf6877d468724c399f34367 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core_chromium.pri7
-rw-r--r--src/core/render_widget_host_view_qt.cpp96
-rw-r--r--src/core/render_widget_host_view_qt.h26
-rw-r--r--src/core/touch_handle_drawable_client.h60
-rw-r--r--src/core/touch_handle_drawable_qt.cpp211
-rw-r--r--src/core/touch_handle_drawable_qt.h87
-rw-r--r--src/core/touch_selection_controller_client_qt.cpp343
-rw-r--r--src/core/touch_selection_controller_client_qt.h116
-rw-r--r--src/core/touch_selection_menu_controller.cpp91
-rw-r--r--src/core/touch_selection_menu_controller.h76
-rw-r--r--src/core/web_contents_adapter_client.h5
-rw-r--r--src/core/web_contents_view_qt.cpp6
12 files changed, 1119 insertions, 5 deletions
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index 65ca793f9..3918dc0aa 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -117,6 +117,9 @@ SOURCES = \
resource_bundle_qt.cpp \
resource_context_qt.cpp \
service/service_qt.cpp \
+ touch_handle_drawable_qt.cpp \
+ touch_selection_controller_client_qt.cpp \
+ touch_selection_menu_controller.cpp \
type_conversion.cpp \
user_script.cpp \
visited_links_manager_qt.cpp \
@@ -218,6 +221,10 @@ HEADERS = \
request_controller.h \
resource_context_qt.h \
service/service_qt.h \
+ touch_handle_drawable_client.h \
+ touch_handle_drawable_qt.h \
+ touch_selection_controller_client_qt.h \
+ touch_selection_menu_controller.h \
type_conversion.h \
user_script.h \
visited_links_manager_qt.h \
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 66276ea6c..09b6a3eca 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -44,6 +44,9 @@
#include "compositor/compositor.h"
#include "qtwebenginecoreglobal_p.h"
#include "render_widget_host_view_qt_delegate.h"
+#include "touch_handle_drawable_client.h"
+#include "touch_selection_controller_client_qt.h"
+#include "touch_selection_menu_controller.h"
#include "type_conversion.h"
#include "web_contents_adapter_client.h"
#include "web_event_factory.h"
@@ -61,10 +64,13 @@
#include "third_party/blink/public/platform/web_cursor_info.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/event.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
#include "ui/events/gesture_detection/motion_event.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/image/image_skia.h"
+#include "ui/touch_selection/touch_selection_controller.h"
+
#if defined(USE_OZONE)
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#endif
@@ -278,6 +284,13 @@ RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget
if (host()->delegate() && host()->delegate()->GetInputEventRouter())
host()->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner(GetFrameSinkId(), this);
+
+ m_touchSelectionControllerClient.reset(new TouchSelectionControllerClientQt(this));
+ ui::TouchSelectionController::Config config;
+ config.max_tap_duration = base::TimeDelta::FromMilliseconds(ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
+ config.tap_slop = ui::GestureConfiguration::GetInstance()->max_touch_move_in_pixels_for_click();
+ config.enable_longpress_drag_selection = false;
+ m_touchSelectionController.reset(new ui::TouchSelectionController(m_touchSelectionControllerClient.get(), config));
}
RenderWidgetHostViewQt::~RenderWidgetHostViewQt()
@@ -286,6 +299,9 @@ RenderWidgetHostViewQt::~RenderWidgetHostViewQt()
if (text_input_manager_)
text_input_manager_->RemoveObserver(this);
+
+ m_touchSelectionController.reset();
+ m_touchSelectionControllerClient.reset();
}
void RenderWidgetHostViewQt::setDelegate(RenderWidgetHostViewQtDelegate* delegate)
@@ -880,7 +896,33 @@ void RenderWidgetHostViewQt::OnGestureEvent(const ui::GestureEventData& gesture)
return;
}
- host()->ForwardGestureEvent(ui::CreateWebGestureEventFromGestureEventData(gesture));
+ blink::WebGestureEvent event = ui::CreateWebGestureEventFromGestureEventData(gesture);
+
+ if (m_touchSelectionController && m_touchSelectionControllerClient) {
+ switch (event.GetType()) {
+ case blink::WebInputEvent::kGestureLongPress:
+ m_touchSelectionController->HandleLongPressEvent(event.TimeStamp(), event.PositionInWidget());
+ break;
+ case blink::WebInputEvent::kGestureTap:
+ m_touchSelectionController->HandleTapEvent(event.PositionInWidget(), event.data.tap.tap_count);
+ break;
+ case blink::WebInputEvent::kGestureScrollBegin:
+ m_touchSelectionControllerClient->onScrollBegin();
+ break;
+ case blink::WebInputEvent::kGestureScrollEnd:
+ m_touchSelectionControllerClient->onScrollEnd();
+ break;
+ default:
+ break;
+ }
+ }
+
+ host()->ForwardGestureEvent(event);
+}
+
+void RenderWidgetHostViewQt::DidStopFlinging()
+{
+ m_touchSelectionControllerClient->DidStopFlinging();
}
viz::ScopedSurfaceIdAllocator RenderWidgetHostViewQt::DidUpdateVisualProperties(const cc::RenderFrameMetadata &metadata)
@@ -1291,9 +1333,9 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
}
if (hasSelection) {
- content::RenderFrameHostImpl *frameHost = static_cast<content::RenderFrameHostImpl *>(getFocusedFrameHost());
- if (frameHost)
- frameHost->GetFrameInputHandler()->SetEditableSelectionOffsets(selectionRange.start(), selectionRange.end());
+ content::mojom::FrameInputHandler *frameInputHandler = getFrameInputHandler();
+ if (frameInputHandler)
+ frameInputHandler->SetEditableSelectionOffsets(selectionRange.start(), selectionRange.end());
}
int replacementLength = ev->replacementLength();
@@ -1451,11 +1493,35 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
eventTimestamp += m_eventsToNowDelta;
QList<QTouchEvent::TouchPoint> touchPoints = mapTouchPointIds(ev->touchPoints());
+ {
+ ui::MotionEvent::Action action;
+ switch (touchPoints[0].state()) {
+ case Qt::TouchPointPressed:
+ action = ui::MotionEvent::Action::DOWN;
+ break;
+ case Qt::TouchPointMoved:
+ action = ui::MotionEvent::Action::MOVE;
+ break;
+ case Qt::TouchPointReleased:
+ action = ui::MotionEvent::Action::UP;
+ break;
+ default:
+ action = ui::MotionEvent::Action::NONE;
+ break;
+ }
+
+ MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), dpiScale(), 0);
+ if (m_touchSelectionController->WillHandleTouchEvent(motionEvent)) {
+ ev->accept();
+ return;
+ }
+ }
switch (ev->type()) {
case QEvent::TouchBegin:
m_sendMotionActionDown = true;
m_touchMotionStarted = true;
+ m_touchSelectionControllerClient->onTouchDown();
break;
case QEvent::TouchUpdate:
m_touchMotionStarted = true;
@@ -1482,6 +1548,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
}
case QEvent::TouchEnd:
clearPreviousTouchMotionState();
+ m_touchSelectionControllerClient->onTouchUp();
break;
default:
break;
@@ -1632,6 +1699,15 @@ content::RenderFrameHost *RenderWidgetHostViewQt::getFocusedFrameHost()
return focusedFrame->current_frame_host();
}
+content::mojom::FrameInputHandler *RenderWidgetHostViewQt::getFrameInputHandler()
+{
+ content::RenderFrameHostImpl *frameHost = static_cast<content::RenderFrameHostImpl *>(getFocusedFrameHost());
+ if (!frameHost)
+ return nullptr;
+
+ return frameHost->GetFrameInputHandler();
+}
+
ui::TextInputType RenderWidgetHostViewQt::getTextInputType() const
{
if (text_input_manager_ && text_input_manager_->GetTextInputState())
@@ -1685,4 +1761,16 @@ void RenderWidgetHostViewQt::ResetFallbackToFirstNavigationSurface()
Q_UNIMPLEMENTED();
}
+void RenderWidgetHostViewQt::OnRenderFrameMetadataChangedAfterActivation()
+{
+ content::RenderWidgetHostViewBase::OnRenderFrameMetadataChangedAfterActivation();
+
+ const cc::RenderFrameMetadata &metadata = host()->render_frame_metadata_provider()->LastRenderFrameMetadata();
+ if (metadata.selection.start != m_selectionStart || metadata.selection.end != m_selectionEnd) {
+ m_selectionStart = metadata.selection.start;
+ m_selectionEnd = metadata.selection.end;
+ m_touchSelectionControllerClient->UpdateClientSelectionBounds(m_selectionStart, m_selectionEnd);
+ }
+}
+
} // namespace QtWebEngineCore
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 30a1550e9..4c63aaea7 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -65,11 +65,21 @@ QT_END_NAMESPACE
namespace content {
class RenderFrameHost;
class RenderWidgetHostImpl;
+namespace mojom {
+class FrameInputHandler;
+}
+}
+
+namespace ui {
+class TouchSelectionController;
}
namespace QtWebEngineCore {
class Compositor;
+class TouchHandleDrawableClient;
+class TouchSelectionControllerClientQt;
+class TouchSelectionMenuController;
struct MultipleMouseClickHelper
{
@@ -106,6 +116,7 @@ public:
RenderWidgetHostViewQtDelegate *delegate() { return m_delegate.get(); }
void setDelegate(RenderWidgetHostViewQtDelegate *delegate);
+ WebContentsAdapterClient *adapterClient() { return m_adapterClient; }
void setAdapterClient(WebContentsAdapterClient *adapterClient);
void InitAsChild(gfx::NativeView) override;
@@ -158,6 +169,7 @@ public:
void EnsureSurfaceSynchronizedForLayoutTest() override;
uint32_t GetCaptureSequenceNumber() const override;
void ResetFallbackToFirstNavigationSurface() override;
+ void DidStopFlinging() override;
// Overridden from ui::GestureProviderClient.
void OnGestureEvent(const ui::GestureEventData& gesture) override;
@@ -207,9 +219,17 @@ public:
LoadVisuallyCommittedState getLoadVisuallyCommittedState() const { return m_loadVisuallyCommittedState; }
void setLoadVisuallyCommittedState(LoadVisuallyCommittedState state) { m_loadVisuallyCommittedState = state; }
+ // Overridden from content::RenderFrameMetadataProvider::Observer
+ void OnRenderFrameMetadataChangedAfterActivation() override;
+
gfx::SizeF lastContentsSize() const { return m_lastContentsSize; }
gfx::Vector2dF lastScrollOffset() const { return m_lastScrollOffset; }
+ ui::TouchSelectionController *getTouchSelectionController() const { return m_touchSelectionController.get(); }
+ TouchSelectionControllerClientQt *getTouchSelectionControllerClient() const { return m_touchSelectionControllerClient.get(); }
+ content::mojom::FrameInputHandler *getFrameInputHandler();
+ ui::TextInputType getTextInputType() const;
+
private:
void processMotionEvent(const ui::MotionEvent &motionEvent);
void clearPreviousTouchMotionState();
@@ -221,7 +241,6 @@ private:
void selectionChanged();
content::RenderFrameHost *getFocusedFrameHost();
- ui::TextInputType getTextInputType() const;
ui::FilteredGestureProvider m_gestureProvider;
base::TimeDelta m_eventsToNowDelta;
@@ -264,6 +283,11 @@ private:
uint32_t m_latestCaptureSequenceNumber = 0u;
std::string m_editCommand;
+
+ std::unique_ptr<TouchSelectionControllerClientQt> m_touchSelectionControllerClient;
+ std::unique_ptr<ui::TouchSelectionController> m_touchSelectionController;
+ gfx::SelectionBound m_selectionStart;
+ gfx::SelectionBound m_selectionEnd;
};
} // namespace QtWebEngineCore
diff --git a/src/core/touch_handle_drawable_client.h b/src/core/touch_handle_drawable_client.h
new file mode 100644
index 000000000..42d907d75
--- /dev/null
+++ b/src/core/touch_handle_drawable_client.h
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOUCH_HANDLE_DRAWABLE_CLIENT_H
+#define TOUCH_HANDLE_DRAWABLE_CLIENT_H
+
+#include "qtwebenginecoreglobal_p.h"
+#include <QRect>
+
+namespace QtWebEngineCore {
+
+class QWEBENGINECORE_PRIVATE_EXPORT TouchHandleDrawableClient {
+public:
+ virtual ~TouchHandleDrawableClient() { }
+
+ virtual void setImage(int orientation) = 0;
+ virtual void setBounds(const QRect &bounds) = 0;
+ virtual void setVisible(bool visible) = 0;
+ virtual void setOpacity(float opacity) = 0;
+};
+
+} // namespace QtWebEngineCore
+
+#endif // TOUCH_HANDLE_DRAWABLE_CLIENT_H
diff --git a/src/core/touch_handle_drawable_qt.cpp b/src/core/touch_handle_drawable_qt.cpp
new file mode 100644
index 000000000..66b1cf40e
--- /dev/null
+++ b/src/core/touch_handle_drawable_qt.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE.Chromium file.
+
+// This implementation is based on chromium/ui/touch_selection/touch_handle_drawable_aura.cc
+
+#include "render_widget_host_view_qt.h"
+#include "touch_handle_drawable_client.h"
+#include "touch_handle_drawable_qt.h"
+#include "type_conversion.h"
+#include "web_contents_adapter_client.h"
+
+#include "ui/gfx/image/image.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/resources/grit/ui_resources.h"
+
+namespace QtWebEngineCore {
+
+namespace {
+// The distance by which a handle image is offset from the focal point (i.e.
+// text baseline) downwards.
+const int kSelectionHandleVerticalVisualOffset = 2;
+
+// The padding around the selection handle image can be used to extend the
+// handle window so that touch events near the selection handle image are
+// targeted to the selection handle window.
+const int kSelectionHandlePadding = 0;
+
+// Epsilon value used to compare float values to zero.
+const float kEpsilon = 1e-8f;
+
+// Returns the appropriate handle image based on the handle orientation.
+gfx::Image* GetHandleImage(ui::TouchHandleOrientation orientation)
+{
+ int resource_id = 0;
+ switch (orientation) {
+ case ui::TouchHandleOrientation::LEFT:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_LEFT;
+ break;
+ case ui::TouchHandleOrientation::CENTER:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_CENTER;
+ break;
+ case ui::TouchHandleOrientation::RIGHT:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_RIGHT;
+ break;
+ case ui::TouchHandleOrientation::UNDEFINED:
+ NOTREACHED() << "Invalid touch handle bound type.";
+ return nullptr;
+ };
+ return &ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id);
+}
+
+bool IsNearlyZero(float value)
+{
+ return std::abs(value) < kEpsilon;
+}
+
+} // namespace
+
+TouchHandleDrawableQt::TouchHandleDrawableQt(RenderWidgetHostViewQt *rwhv)
+ : m_rwhv(rwhv)
+ , m_enabled(false)
+ , m_alpha(0)
+ , m_orientation(ui::TouchHandleOrientation::UNDEFINED)
+{
+ QMap<int, QImage> images;
+ for (int orientation = 0; orientation < static_cast<int>(ui::TouchHandleOrientation::UNDEFINED); ++orientation) {
+ gfx::Image* image = GetHandleImage(static_cast<ui::TouchHandleOrientation>(orientation));
+ images.insert(orientation, toQImage(image->AsBitmap()));
+ }
+
+ Q_ASSERT(m_rwhv);
+ Q_ASSERT(m_rwhv->adapterClient());
+ m_client.reset(m_rwhv->adapterClient()->createTouchHandle(images));
+}
+
+TouchHandleDrawableQt::~TouchHandleDrawableQt()
+{
+}
+
+void TouchHandleDrawableQt::UpdateBounds()
+{
+ if (!m_client)
+ return;
+
+ gfx::RectF newBounds = m_relativeBounds;
+ newBounds.Offset(m_originPosition.x(), m_originPosition.y());
+ m_client->setBounds(toQt(gfx::ToEnclosingRect(newBounds)));
+}
+
+bool TouchHandleDrawableQt::IsVisible() const
+{
+ return m_enabled && !IsNearlyZero(m_alpha);
+}
+
+void TouchHandleDrawableQt::SetEnabled(bool enabled)
+{
+ if (!m_client)
+ return;
+
+ if (enabled == m_enabled)
+ return;
+
+ m_enabled = enabled;
+ m_client->setVisible(enabled);
+}
+
+void TouchHandleDrawableQt::SetOrientation(ui::TouchHandleOrientation orientation, bool mirror_vertical, bool mirror_horizontal)
+{
+ if (!m_client)
+ return;
+
+ // TODO: Implement adaptive handle orientation logic
+ DCHECK(!mirror_vertical);
+ DCHECK(!mirror_horizontal);
+
+ if (m_orientation == orientation)
+ return;
+ m_orientation = orientation;
+ gfx::Image* image = GetHandleImage(orientation);
+ m_client->setImage(static_cast<int>(orientation));
+
+ // Calculate the relative bounds.
+ gfx::Size image_size = image->Size();
+ int window_width = image_size.width() + 2 * kSelectionHandlePadding;
+ int window_height = image_size.height() + 2 * kSelectionHandlePadding;
+ m_relativeBounds =
+ gfx::RectF(-kSelectionHandlePadding,
+ kSelectionHandleVerticalVisualOffset - kSelectionHandlePadding,
+ window_width, window_height);
+ UpdateBounds();
+}
+
+void TouchHandleDrawableQt::SetOrigin(const gfx::PointF& position)
+{
+ m_originPosition = position;
+ UpdateBounds();
+}
+
+void TouchHandleDrawableQt::SetAlpha(float alpha)
+{
+ if (!m_client)
+ return;
+
+ if (alpha == m_alpha)
+ return;
+
+ m_alpha = alpha;
+ m_client->setOpacity(m_alpha);
+ m_client->setVisible(IsVisible());
+}
+
+gfx::RectF TouchHandleDrawableQt::GetVisibleBounds() const
+{
+ gfx::RectF bounds = m_relativeBounds;
+ bounds.Offset(m_originPosition.x(), m_originPosition.y());
+
+ gfx::RectF visibleBounds(bounds);
+ visibleBounds.Inset(kSelectionHandlePadding,
+ kSelectionHandlePadding + kSelectionHandleVerticalVisualOffset,
+ kSelectionHandlePadding,
+ kSelectionHandlePadding);
+ return visibleBounds;
+}
+
+float TouchHandleDrawableQt::GetDrawableHorizontalPaddingRatio() const
+{
+ // Qt does not have any transparent padding for its handle drawable.
+ return 0.0;
+}
+
+} // namespace QtWebEngineCore
diff --git a/src/core/touch_handle_drawable_qt.h b/src/core/touch_handle_drawable_qt.h
new file mode 100644
index 000000000..46fa217b7
--- /dev/null
+++ b/src/core/touch_handle_drawable_qt.h
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOUCH_HANDLE_DRAWABLE_QT_H
+#define TOUCH_HANDLE_DRAWABLE_QT_H
+
+#include "ui/touch_selection/touch_handle.h"
+#include "ui/touch_selection/touch_handle_orientation.h"
+
+#include <QtCore/QScopedPointer>
+
+namespace QtWebEngineCore {
+
+class RenderWidgetHostViewQt;
+class TouchHandleDrawableClient;
+
+class TouchHandleDrawableQt : public ui::TouchHandleDrawable
+{
+public:
+ explicit TouchHandleDrawableQt(RenderWidgetHostViewQt *rwhv);
+ ~TouchHandleDrawableQt() override;
+
+private:
+ void UpdateBounds();
+ bool IsVisible() const;
+
+ // ui::TouchHandleDrawable overrides
+ void SetEnabled(bool enabled) override;
+ void SetOrientation(ui::TouchHandleOrientation orientation,
+ bool mirror_vertical,
+ bool mirror_horizontal) override;
+ void SetOrigin(const gfx::PointF& position) override;
+ void SetAlpha(float alpha) override;
+ gfx::RectF GetVisibleBounds() const override;
+ float GetDrawableHorizontalPaddingRatio() const override;
+
+ RenderWidgetHostViewQt *m_rwhv;
+ QScopedPointer<TouchHandleDrawableClient> m_client;
+
+ bool m_enabled;
+ float m_alpha;
+ ui::TouchHandleOrientation m_orientation;
+ gfx::RectF m_relativeBounds;
+ gfx::PointF m_originPosition;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchHandleDrawableQt);
+};
+
+} // namespace QtWebEngineCore
+
+#endif // TOUCH_HANDLE_DRAWABLE_QT_H
diff --git a/src/core/touch_selection_controller_client_qt.cpp b/src/core/touch_selection_controller_client_qt.cpp
new file mode 100644
index 000000000..da3c78b8a
--- /dev/null
+++ b/src/core/touch_selection_controller_client_qt.cpp
@@ -0,0 +1,343 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "render_widget_host_view_qt.h"
+#include "touch_handle_drawable_qt.h"
+#include "touch_selection_controller_client_qt.h"
+#include "touch_selection_menu_controller.h"
+#include "type_conversion.h"
+#include "web_contents_adapter.h"
+#include "web_contents_adapter_client.h"
+
+#include "content/browser/frame_host/render_frame_host_impl.h"
+#include "content/browser/renderer_host/render_widget_host_impl.h"
+#include "ui/gfx/geometry/size_conversions.h"
+
+#include <QClipboard>
+#include <QGuiApplication>
+
+namespace QtWebEngineCore {
+
+TouchSelectionControllerClientQt::TouchSelectionControllerClientQt(RenderWidgetHostViewQt *rwhv)
+ : m_rwhv(rwhv)
+ , m_menuController(new TouchSelectionMenuController(this))
+ , m_menuShowing(false)
+ , m_menuRequested(false)
+ , m_touchDown(false)
+ , m_scrollInProgress(false)
+ , m_handleDragInProgress(false)
+{
+ Q_ASSERT(rwhv);
+}
+
+TouchSelectionControllerClientQt::~TouchSelectionControllerClientQt()
+{
+}
+
+bool TouchSelectionControllerClientQt::handleContextMenu(const content::ContextMenuParams& params)
+{
+ if ((params.source_type == ui::MENU_SOURCE_LONG_PRESS ||
+ params.source_type == ui::MENU_SOURCE_LONG_TAP) &&
+ params.is_editable && params.selection_text.empty()) {
+ m_menuRequested = true;
+ updateMenu();
+ return true;
+ }
+
+ const bool from_touch = params.source_type == ui::MENU_SOURCE_LONG_PRESS ||
+ params.source_type == ui::MENU_SOURCE_LONG_TAP ||
+ params.source_type == ui::MENU_SOURCE_TOUCH;
+ if (from_touch && !params.selection_text.empty())
+ return true;
+
+ GetTouchSelectionController()->HideAndDisallowShowingAutomatically();
+ return false;
+}
+
+void TouchSelectionControllerClientQt::onTouchDown()
+{
+ m_touchDown = true;
+ updateMenu();
+}
+
+void TouchSelectionControllerClientQt::onTouchUp()
+{
+ m_touchDown = false;
+ updateMenu();
+}
+
+void TouchSelectionControllerClientQt::onScrollBegin()
+{
+ m_scrollInProgress = true;
+ GetTouchSelectionController()->SetTemporarilyHidden(true);
+ updateMenu();
+}
+
+void TouchSelectionControllerClientQt::onScrollEnd()
+{
+ m_scrollInProgress = false;
+ GetTouchSelectionController()->SetTemporarilyHidden(false);
+ updateMenu();
+}
+
+bool TouchSelectionControllerClientQt::IsCommandIdEnabled(int command_id) const
+{
+ bool editable = m_rwhv->getTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
+ bool readable = m_rwhv->getTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD;
+ bool hasSelection = !m_rwhv->GetSelectedText().empty();
+
+ switch (command_id) {
+ case TouchSelectionMenuController::Cut:
+ return editable && readable && hasSelection;
+ case TouchSelectionMenuController::Copy:
+ return readable && hasSelection;
+ case TouchSelectionMenuController::Paste:
+ return editable && !QGuiApplication::clipboard()->text().isEmpty();
+ default:
+ return false;
+ }
+}
+
+void TouchSelectionControllerClientQt::ExecuteCommand(int command_id, int event_flags)
+{
+ Q_UNUSED(event_flags);
+ GetTouchSelectionController()->HideAndDisallowShowingAutomatically();
+
+ WebContentsAdapterClient *adapterClient = m_rwhv->adapterClient();
+ Q_ASSERT(adapterClient);
+ WebContentsAdapter *adapter = adapterClient->webContentsAdapter();
+ Q_ASSERT(adapter);
+
+ switch (command_id) {
+ case TouchSelectionMenuController::Cut:
+ adapter->cut();
+ break;
+ case TouchSelectionMenuController::Copy:
+ adapter->copy();
+ break;
+ case TouchSelectionMenuController::Paste:
+ adapter->paste();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+void TouchSelectionControllerClientQt::RunContextMenu()
+{
+ gfx::RectF anchorRect = GetTouchSelectionController()->GetRectBetweenBounds();
+ gfx::PointF anchorPoint = gfx::PointF(anchorRect.CenterPoint().x(), anchorRect.y());
+
+ content::RenderWidgetHostImpl *host = m_rwhv->host();
+ host->ShowContextMenuAtPoint(gfx::ToRoundedPoint(anchorPoint),
+ ui::MENU_SOURCE_TOUCH_EDIT_MENU);
+
+ // Hide selection handles after getting rect-between-bounds from touch
+ // selection controller; otherwise, rect would be empty and the above
+ // calculations would be invalid.
+ GetTouchSelectionController()->HideAndDisallowShowingAutomatically();
+}
+
+void TouchSelectionControllerClientQt::DidStopFlinging()
+{
+ onScrollEnd();
+}
+
+void TouchSelectionControllerClientQt::UpdateClientSelectionBounds(const gfx::SelectionBound& start,
+ const gfx::SelectionBound& end)
+{
+ UpdateClientSelectionBounds(start, end, this, this);
+}
+
+void TouchSelectionControllerClientQt::UpdateClientSelectionBounds(const gfx::SelectionBound& start,
+ const gfx::SelectionBound& end,
+ ui::TouchSelectionControllerClient* client,
+ ui::TouchSelectionMenuClient* menu_client)
+{
+ Q_UNUSED(client);
+ Q_UNUSED(menu_client);
+
+ GetTouchSelectionController()->OnSelectionBoundsChanged(start, end);
+}
+
+void TouchSelectionControllerClientQt::InvalidateClient(ui::TouchSelectionControllerClient* client)
+{
+ Q_UNUSED(client);
+}
+
+ui::TouchSelectionController* TouchSelectionControllerClientQt::GetTouchSelectionController()
+{
+ return m_rwhv->getTouchSelectionController();
+}
+
+void TouchSelectionControllerClientQt::AddObserver(Observer* observer)
+{
+ Q_UNUSED(observer);
+}
+
+void TouchSelectionControllerClientQt::RemoveObserver(Observer* observer)
+{
+ Q_UNUSED(observer);
+}
+
+bool TouchSelectionControllerClientQt::SupportsAnimation() const
+{
+ return false;
+}
+
+void TouchSelectionControllerClientQt::SetNeedsAnimate()
+{
+ NOTREACHED();
+}
+
+void TouchSelectionControllerClientQt::MoveCaret(const gfx::PointF& position)
+{
+ content::mojom::FrameInputHandler *frameInputHandler = m_rwhv->getFrameInputHandler();
+ if (!frameInputHandler)
+ return;
+
+ frameInputHandler->MoveCaret(gfx::ToRoundedPoint(position));
+}
+
+void TouchSelectionControllerClientQt::MoveRangeSelectionExtent(const gfx::PointF& extent)
+{
+ content::mojom::FrameInputHandler *frameInputHandler = m_rwhv->getFrameInputHandler();
+ if (!frameInputHandler)
+ return;
+
+ frameInputHandler->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent));
+}
+
+void TouchSelectionControllerClientQt::SelectBetweenCoordinates(const gfx::PointF& base, const gfx::PointF& extent)
+{
+ content::mojom::FrameInputHandler *frameInputHandler = m_rwhv->getFrameInputHandler();
+ if (!frameInputHandler)
+ return;
+
+ frameInputHandler->SelectRange(gfx::ToRoundedPoint(base), gfx::ToRoundedPoint(extent));
+}
+
+void TouchSelectionControllerClientQt::OnSelectionEvent(ui::SelectionEventType event)
+{
+ switch (event) {
+ case ui::SELECTION_HANDLES_SHOWN:
+ m_menuRequested = true;
+ break;
+ case ui::INSERTION_HANDLE_SHOWN:
+ break;
+ case ui::SELECTION_HANDLES_CLEARED:
+ case ui::INSERTION_HANDLE_CLEARED:
+ m_menuRequested = false;
+ break;
+ case ui::SELECTION_HANDLE_DRAG_STARTED:
+ case ui::INSERTION_HANDLE_DRAG_STARTED:
+ m_handleDragInProgress = true;
+ break;
+ case ui::SELECTION_HANDLE_DRAG_STOPPED:
+ case ui::INSERTION_HANDLE_DRAG_STOPPED:
+ m_handleDragInProgress = false;
+ break;
+ case ui::SELECTION_HANDLES_MOVED:
+ case ui::INSERTION_HANDLE_MOVED:
+ break;
+ case ui::INSERTION_HANDLE_TAPPED:
+ m_menuRequested = !m_menuRequested;
+ break;
+ }
+
+ updateMenu();
+}
+
+void TouchSelectionControllerClientQt::OnDragUpdate(const gfx::PointF& position)
+{
+ Q_UNUSED(position);
+}
+
+std::unique_ptr<ui::TouchHandleDrawable> TouchSelectionControllerClientQt::CreateDrawable()
+{
+ return std::unique_ptr<ui::TouchHandleDrawable>(new TouchHandleDrawableQt(m_rwhv));
+}
+
+void TouchSelectionControllerClientQt::DidScroll()
+{
+}
+
+void TouchSelectionControllerClientQt::showMenu()
+{
+ gfx::RectF rect = GetTouchSelectionController()->GetRectBetweenBounds();
+ gfx::PointF origin = rect.origin();
+ gfx::PointF bottom_right = rect.bottom_right();
+
+ gfx::Vector2dF diagonal = bottom_right - origin;
+ gfx::SizeF size(diagonal.x(), diagonal.y());
+ gfx::RectF anchor_rect(origin, size);
+
+ // Calculate maximum handle image size;
+ gfx::SizeF max_handle_size = GetTouchSelectionController()->GetStartHandleRect().size();
+ max_handle_size.SetToMax(GetTouchSelectionController()->GetEndHandleRect().size());
+
+ WebContentsAdapterClient *adapterClient = m_rwhv->adapterClient();
+ Q_ASSERT(adapterClient);
+ adapterClient->showTouchSelectionMenu(m_menuController.get(),
+ QRect(toQt(gfx::ToEnclosingRect(anchor_rect))),
+ QSize(toQt(gfx::ToRoundedSize(max_handle_size))));
+ m_menuShowing = true;
+}
+
+void TouchSelectionControllerClientQt::hideMenu()
+{
+ WebContentsAdapterClient *adapterClient = m_rwhv->adapterClient();
+ Q_ASSERT(adapterClient);
+ adapterClient->hideTouchSelectionMenu();
+ m_menuShowing = false;
+}
+
+void TouchSelectionControllerClientQt::updateMenu()
+{
+ if (m_menuShowing)
+ hideMenu();
+
+ if (m_menuRequested && !m_touchDown &&
+ !m_scrollInProgress && !m_handleDragInProgress) {
+ showMenu();
+ }
+}
+
+} // namespace QtWebEngineCore
diff --git a/src/core/touch_selection_controller_client_qt.h b/src/core/touch_selection_controller_client_qt.h
new file mode 100644
index 000000000..cdc45cac3
--- /dev/null
+++ b/src/core/touch_selection_controller_client_qt.h
@@ -0,0 +1,116 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOUCH_SELECTION_CONTROLLER_CLIENT_QT_H
+#define TOUCH_SELECTION_CONTROLLER_CLIENT_QT_H
+
+#include "content/public/browser/touch_selection_controller_client_manager.h"
+#include "content/public/common/context_menu_params.h"
+#include "ui/touch_selection/touch_selection_controller.h"
+#include "ui/touch_selection/touch_selection_menu_runner.h"
+
+#include <QtCore/QScopedPointer>
+
+namespace QtWebEngineCore {
+
+class RenderWidgetHostViewQt;
+class TouchSelectionMenuController;
+
+class TouchSelectionControllerClientQt
+ : public ui::TouchSelectionControllerClient
+ , public ui::TouchSelectionMenuClient
+ , public content::TouchSelectionControllerClientManager
+{
+public:
+ explicit TouchSelectionControllerClientQt(RenderWidgetHostViewQt *rwhv);
+ ~TouchSelectionControllerClientQt() override;
+
+ void UpdateClientSelectionBounds(const gfx::SelectionBound& start,
+ const gfx::SelectionBound& end);
+ bool handleContextMenu(const content::ContextMenuParams& params);
+ void onTouchDown();
+ void onTouchUp();
+ void onScrollBegin();
+ void onScrollEnd();
+
+ // ui::TouchSelectionMenuClient overrides
+ bool IsCommandIdEnabled(int command_id) const override;
+ void ExecuteCommand(int command_id, int event_flags) override;
+ void RunContextMenu() override;
+
+ // content::TouchSelectionControllerClientManager overrides
+ void DidStopFlinging() override;
+ void UpdateClientSelectionBounds(const gfx::SelectionBound& start,
+ const gfx::SelectionBound& end,
+ ui::TouchSelectionControllerClient* client,
+ ui::TouchSelectionMenuClient* menu_client) override;
+ void InvalidateClient(ui::TouchSelectionControllerClient* client) override;
+ ui::TouchSelectionController* GetTouchSelectionController() override;
+ void AddObserver(Observer* observer) override;
+ void RemoveObserver(Observer* observer) override;
+
+ // ui::TouchSelectionControllerClient overrides
+ bool SupportsAnimation() const override;
+ void SetNeedsAnimate() override;
+ void MoveCaret(const gfx::PointF& position) override;
+ void MoveRangeSelectionExtent(const gfx::PointF& extent) override;
+ void SelectBetweenCoordinates(const gfx::PointF& base, const gfx::PointF& extent) override;
+ void OnSelectionEvent(ui::SelectionEventType event) override;
+ void OnDragUpdate(const gfx::PointF& position) override;
+ std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
+ void DidScroll() override;
+
+private:
+ void showMenu();
+ void hideMenu();
+ void updateMenu();
+
+ RenderWidgetHostViewQt *m_rwhv;
+ QScopedPointer<TouchSelectionMenuController> m_menuController;
+
+ bool m_menuShowing;
+ bool m_menuRequested;
+ bool m_touchDown;
+ bool m_scrollInProgress;
+ bool m_handleDragInProgress;
+};
+
+} // namespace QtWebEngineCore
+
+#endif // TOUCH_SELECTION_CONTROLLER_CLIENT_QT_H
diff --git a/src/core/touch_selection_menu_controller.cpp b/src/core/touch_selection_menu_controller.cpp
new file mode 100644
index 000000000..cdec9a064
--- /dev/null
+++ b/src/core/touch_selection_menu_controller.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "touch_selection_controller_client_qt.h"
+#include "touch_selection_menu_controller.h"
+
+namespace QtWebEngineCore {
+
+TouchSelectionMenuController::TouchSelectionMenuController(TouchSelectionControllerClientQt *touchSelectionControllerClient)
+ : m_touchSelectionControllerClient(touchSelectionControllerClient)
+{
+}
+
+TouchSelectionMenuController::~TouchSelectionMenuController()
+{
+}
+
+int TouchSelectionMenuController::buttonCount()
+{
+ int buttonCount = 1;
+
+ for (int commandId = 0; commandId <= static_cast<int>(Paste); ++commandId) {
+ if (m_touchSelectionControllerClient->IsCommandIdEnabled(commandId))
+ buttonCount++;
+ }
+
+ return buttonCount;
+}
+
+bool TouchSelectionMenuController::isCommandEnabled(TouchSelectionCommand command)
+{
+ return m_touchSelectionControllerClient->IsCommandIdEnabled(static_cast<int>(command));
+}
+
+void TouchSelectionMenuController::cut()
+{
+ m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Cut), 0);
+}
+
+void TouchSelectionMenuController::copy()
+{
+ m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Copy), 0);
+}
+
+void TouchSelectionMenuController::paste()
+{
+ m_touchSelectionControllerClient->ExecuteCommand(static_cast<int>(Paste), 0);
+}
+
+void TouchSelectionMenuController::runContextMenu()
+{
+ return m_touchSelectionControllerClient->RunContextMenu();
+}
+
+} // namespace QtWebEngineCore
diff --git a/src/core/touch_selection_menu_controller.h b/src/core/touch_selection_menu_controller.h
new file mode 100644
index 000000000..fd61ae709
--- /dev/null
+++ b/src/core/touch_selection_menu_controller.h
@@ -0,0 +1,76 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef TOUCH_SELECTION_MENU_CONTROLLER_H
+#define TOUCH_SELECTION_MENU_CONTROLLER_H
+
+#include "qtwebenginecoreglobal_p.h"
+#include <QtCore/QObject>
+
+namespace QtWebEngineCore {
+
+class TouchSelectionControllerClientQt;
+
+class QWEBENGINECORE_PRIVATE_EXPORT TouchSelectionMenuController : public QObject {
+ Q_OBJECT
+public:
+ enum TouchSelectionCommand {
+ Cut,
+ Copy,
+ Paste
+ };
+
+ TouchSelectionMenuController(TouchSelectionControllerClientQt *touchSelectionControllerClient);
+ ~TouchSelectionMenuController();
+ int buttonCount();
+ bool isCommandEnabled(TouchSelectionCommand);
+
+public Q_SLOTS:
+ void cut();
+ void copy();
+ void paste();
+ void runContextMenu();
+
+private:
+ TouchSelectionControllerClientQt *m_touchSelectionControllerClient;
+};
+
+} // namespace QtWebEngineCore
+
+#endif // TOUCH_SELECTION_CONTROLLER_CLIENT_QT_H
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index f9d0c0781..4a36e77f9 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -82,6 +82,8 @@ class JavaScriptDialogController;
class RenderWidgetHostViewQt;
class RenderWidgetHostViewQtDelegate;
class RenderWidgetHostViewQtDelegateClient;
+class TouchHandleDrawableClient;
+class TouchSelectionMenuController;
class WebContentsAdapter;
class WebContentsDelegateQt;
class WebEngineSettings;
@@ -477,6 +479,9 @@ public:
virtual void printRequested() = 0;
virtual void widgetChanged(RenderWidgetHostViewQtDelegate *newWidget) = 0;
virtual void interceptRequest(QWebEngineUrlRequestInfo &) { }
+ virtual TouchHandleDrawableClient *createTouchHandle(const QMap<int, QImage> &images) = 0;
+ virtual void showTouchSelectionMenu(TouchSelectionMenuController *menuController, const QRect &bounds, const QSize &handleSize) = 0;
+ virtual void hideTouchSelectionMenu() = 0;
virtual ProfileAdapter *profileAdapter() = 0;
virtual WebContentsAdapter* webContentsAdapter() = 0;
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index f44668019..648e0fd8f 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -44,6 +44,7 @@
#include "render_widget_host_view_qt.h"
#include "render_widget_host_view_qt_delegate.h"
#include "render_widget_host_view_qt.h"
+#include "touch_selection_controller_client_qt.h"
#include "type_conversion.h"
#include "web_contents_adapter_client.h"
#include "web_contents_adapter.h"
@@ -189,6 +190,11 @@ static inline WebEngineContextMenuData fromParams(const content::ContextMenuPara
void WebContentsViewQt::ShowContextMenu(content::RenderFrameHost *, const content::ContextMenuParams &params)
{
+ if (auto rwhv = static_cast<RenderWidgetHostViewQt *>(m_webContents->GetRenderWidgetHostView())) {
+ if (rwhv && rwhv->getTouchSelectionControllerClient()->handleContextMenu(params))
+ return;
+ }
+
WebEngineContextMenuData contextMenuData(fromParams(params));
#if QT_CONFIG(webengine_spellchecker)
// Do not use params.spellcheck_enabled, since it is never