summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorBalazs Egedi <egedib@inf.u-szeged.hu>2022-02-18 13:04:19 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2022-05-04 03:00:16 +0200
commit828ee197647a7462c10243c0261e7bced9bbcb65 (patch)
tree4c6bc198ea33a753e6af4efa736741ea10cea280 /src/core
parent57a38f05d9a0898bffa077a5caaf48fde370cb02 (diff)
Quick: Add support for replacing touch handles with delegates
Task-number: QTBUG-85043 Change-Id: I1c87aff352e07eb309d5ba8747b9e50a191d478e Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/api/qwebenginepage_p.h5
-rw-r--r--src/core/render_widget_host_view_qt.cpp17
-rw-r--r--src/core/render_widget_host_view_qt.h2
-rw-r--r--src/core/touch_handle_drawable_client.h4
-rw-r--r--src/core/touch_handle_drawable_qt.cpp74
-rw-r--r--src/core/touch_handle_drawable_qt.h9
-rw-r--r--src/core/touch_selection_controller_client_qt.cpp21
-rw-r--r--src/core/touch_selection_controller_client_qt.h3
-rw-r--r--src/core/web_contents_adapter.cpp8
-rw-r--r--src/core/web_contents_adapter.h1
-rw-r--r--src/core/web_contents_adapter_client.h4
11 files changed, 90 insertions, 58 deletions
diff --git a/src/core/api/qwebenginepage_p.h b/src/core/api/qwebenginepage_p.h
index 4862763aa..e82f22af9 100644
--- a/src/core/api/qwebenginepage_p.h
+++ b/src/core/api/qwebenginepage_p.h
@@ -64,7 +64,7 @@ namespace QtWebEngineCore {
class RenderWidgetHostViewQtDelegate;
class RenderWidgetHostViewQtDelegateWidget;
class RenderWidgetHostViewQtDelegateClient;
-class TouchHandleDrawableClient;
+class TouchHandleDrawableDelegate;
class TouchSelectionMenuController;
class WebContentsAdapter;
}
@@ -183,7 +183,8 @@ public:
bool isEnabled() const override;
void setToolTip(const QString &toolTipText) override;
void printRequested() override;
- QtWebEngineCore::TouchHandleDrawableClient *createTouchHandle(const QMap<int, QImage> &) override { return nullptr; }
+ QtWebEngineCore::TouchHandleDrawableDelegate *
+ createTouchHandleDelegate(const QMap<int, QImage> &) override { return nullptr; }
void showTouchSelectionMenu(QtWebEngineCore::TouchSelectionMenuController *, const QRect &, const QSize &) override { }
void hideTouchSelectionMenu() override { }
const QObject *holdingQObject() const override;
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index c56894983..572468bc8 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -226,11 +226,7 @@ RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget
m_cursorManager.reset(new content::CursorManager(this));
m_touchSelectionControllerClient.reset(new TouchSelectionControllerClientQt(this));
- ui::TouchSelectionController::Config config;
- config.max_tap_duration = base::Milliseconds(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));
+ resetTouchSelectionController();
host()->render_frame_metadata_provider()->AddObserver(this);
host()->render_frame_metadata_provider()->ReportAllFrameSubmissionsForTesting(true);
@@ -1071,6 +1067,17 @@ void RenderWidgetHostViewQt::synchronizeVisualProperties(const absl::optional<vi
host()->SynchronizeVisualProperties();
}
+void RenderWidgetHostViewQt::resetTouchSelectionController()
+{
+ Q_ASSERT(m_touchSelectionControllerClient);
+ m_touchSelectionControllerClient->resetControls();
+ ui::TouchSelectionController::Config config;
+ config.max_tap_duration = base::Milliseconds(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));
+}
+
std::unique_ptr<content::SyntheticGestureTarget> RenderWidgetHostViewQt::CreateSyntheticGestureTarget()
{
return nullptr;
diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h
index 5105d6621..e8da6785a 100644
--- a/src/core/render_widget_host_view_qt.h
+++ b/src/core/render_widget_host_view_qt.h
@@ -211,6 +211,8 @@ public:
void synchronizeVisualProperties(
const absl::optional<viz::LocalSurfaceId> &childSurfaceId);
+ void resetTouchSelectionController();
+
private:
friend class DelegatedFrameHostClientQt;
friend class WebContentsAccessibilityQt;
diff --git a/src/core/touch_handle_drawable_client.h b/src/core/touch_handle_drawable_client.h
index d7db78f02..168bf4afc 100644
--- a/src/core/touch_handle_drawable_client.h
+++ b/src/core/touch_handle_drawable_client.h
@@ -45,9 +45,9 @@
namespace QtWebEngineCore {
-class Q_WEBENGINECORE_PRIVATE_EXPORT TouchHandleDrawableClient {
+class Q_WEBENGINECORE_PRIVATE_EXPORT TouchHandleDrawableDelegate {
public:
- virtual ~TouchHandleDrawableClient() { }
+ virtual ~TouchHandleDrawableDelegate() { }
virtual void setImage(int orientation) = 0;
virtual void setBounds(const QRect &bounds) = 0;
diff --git a/src/core/touch_handle_drawable_qt.cpp b/src/core/touch_handle_drawable_qt.cpp
index 66b1cf40e..24171b272 100644
--- a/src/core/touch_handle_drawable_qt.cpp
+++ b/src/core/touch_handle_drawable_qt.cpp
@@ -49,7 +49,6 @@
#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"
@@ -68,27 +67,6 @@ 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;
@@ -96,21 +74,12 @@ bool IsNearlyZero(float value)
} // namespace
-TouchHandleDrawableQt::TouchHandleDrawableQt(RenderWidgetHostViewQt *rwhv)
- : m_rwhv(rwhv)
+TouchHandleDrawableQt::TouchHandleDrawableQt(TouchHandleDrawableDelegate *delegate)
+ : m_delegate(delegate)
, 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()
@@ -119,12 +88,12 @@ TouchHandleDrawableQt::~TouchHandleDrawableQt()
void TouchHandleDrawableQt::UpdateBounds()
{
- if (!m_client)
+ if (!m_delegate)
return;
gfx::RectF newBounds = m_relativeBounds;
newBounds.Offset(m_originPosition.x(), m_originPosition.y());
- m_client->setBounds(toQt(gfx::ToEnclosingRect(newBounds)));
+ m_delegate->setBounds(toQt(gfx::ToEnclosingRect(newBounds)));
}
bool TouchHandleDrawableQt::IsVisible() const
@@ -134,19 +103,19 @@ bool TouchHandleDrawableQt::IsVisible() const
void TouchHandleDrawableQt::SetEnabled(bool enabled)
{
- if (!m_client)
+ if (!m_delegate)
return;
if (enabled == m_enabled)
return;
m_enabled = enabled;
- m_client->setVisible(enabled);
+ m_delegate->setVisible(enabled);
}
void TouchHandleDrawableQt::SetOrientation(ui::TouchHandleOrientation orientation, bool mirror_vertical, bool mirror_horizontal)
{
- if (!m_client)
+ if (!m_delegate)
return;
// TODO: Implement adaptive handle orientation logic
@@ -157,7 +126,7 @@ void TouchHandleDrawableQt::SetOrientation(ui::TouchHandleOrientation orientatio
return;
m_orientation = orientation;
gfx::Image* image = GetHandleImage(orientation);
- m_client->setImage(static_cast<int>(orientation));
+ m_delegate->setImage(static_cast<int>(orientation));
// Calculate the relative bounds.
gfx::Size image_size = image->Size();
@@ -178,15 +147,15 @@ void TouchHandleDrawableQt::SetOrigin(const gfx::PointF& position)
void TouchHandleDrawableQt::SetAlpha(float alpha)
{
- if (!m_client)
+ if (!m_delegate)
return;
if (alpha == m_alpha)
return;
m_alpha = alpha;
- m_client->setOpacity(m_alpha);
- m_client->setVisible(IsVisible());
+ m_delegate->setOpacity(m_alpha);
+ m_delegate->setVisible(IsVisible());
}
gfx::RectF TouchHandleDrawableQt::GetVisibleBounds() const
@@ -208,4 +177,25 @@ float TouchHandleDrawableQt::GetDrawableHorizontalPaddingRatio() const
return 0.0;
}
+// Returns the appropriate handle image based on the handle orientation.
+gfx::Image *TouchHandleDrawableQt::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);
+}
+
} // namespace QtWebEngineCore
diff --git a/src/core/touch_handle_drawable_qt.h b/src/core/touch_handle_drawable_qt.h
index 580b56018..f81d1b978 100644
--- a/src/core/touch_handle_drawable_qt.h
+++ b/src/core/touch_handle_drawable_qt.h
@@ -42,19 +42,20 @@
#include "ui/touch_selection/touch_handle.h"
#include "ui/touch_selection/touch_handle_orientation.h"
+#include "ui/gfx/image/image.h"
#include <QtCore/QScopedPointer>
namespace QtWebEngineCore {
-class RenderWidgetHostViewQt;
-class TouchHandleDrawableClient;
+class TouchHandleDrawableDelegate;
class TouchHandleDrawableQt : public ui::TouchHandleDrawable
{
public:
- explicit TouchHandleDrawableQt(RenderWidgetHostViewQt *rwhv);
+ explicit TouchHandleDrawableQt(TouchHandleDrawableDelegate *delegate);
~TouchHandleDrawableQt() override;
+ static gfx::Image *GetHandleImage(ui::TouchHandleOrientation orientation);
private:
void UpdateBounds();
@@ -71,7 +72,7 @@ private:
float GetDrawableHorizontalPaddingRatio() const override;
RenderWidgetHostViewQt *m_rwhv;
- QScopedPointer<TouchHandleDrawableClient> m_client;
+ QScopedPointer<TouchHandleDrawableDelegate> m_delegate;
bool m_enabled;
float m_alpha;
diff --git a/src/core/touch_selection_controller_client_qt.cpp b/src/core/touch_selection_controller_client_qt.cpp
index 2e9f56a5f..b85d301f6 100644
--- a/src/core/touch_selection_controller_client_qt.cpp
+++ b/src/core/touch_selection_controller_client_qt.cpp
@@ -39,6 +39,7 @@
#include "render_widget_host_view_qt.h"
#include "touch_handle_drawable_qt.h"
+#include "touch_handle_drawable_client.h"
#include "touch_selection_controller_client_qt.h"
#include "touch_selection_menu_controller.h"
#include "type_conversion.h"
@@ -293,13 +294,31 @@ void TouchSelectionControllerClientQt::OnDragUpdate(const ui::TouchSelectionDrag
std::unique_ptr<ui::TouchHandleDrawable> TouchSelectionControllerClientQt::CreateDrawable()
{
- return std::unique_ptr<ui::TouchHandleDrawable>(new TouchHandleDrawableQt(m_rwhv));
+ Q_ASSERT(m_rwhv);
+ Q_ASSERT(m_rwhv->adapterClient());
+ QMap<int, QImage> images;
+ for (int orientation = 0; orientation < static_cast<int>(ui::TouchHandleOrientation::UNDEFINED);
+ ++orientation) {
+ gfx::Image *image = TouchHandleDrawableQt::GetHandleImage(
+ static_cast<ui::TouchHandleOrientation>(orientation));
+ images.insert(orientation, toQImage(image->AsBitmap()));
+ }
+ auto delegate = m_rwhv->adapterClient()->createTouchHandleDelegate(images);
+ return std::unique_ptr<ui::TouchHandleDrawable>(new TouchHandleDrawableQt(delegate));
}
void TouchSelectionControllerClientQt::DidScroll()
{
}
+void TouchSelectionControllerClientQt::resetControls()
+{
+ if (m_menuShowing) {
+ hideMenu();
+ GetTouchSelectionController()->HideAndDisallowShowingAutomatically();
+ }
+}
+
void TouchSelectionControllerClientQt::showMenu()
{
gfx::RectF rect = GetTouchSelectionController()->GetRectBetweenBounds();
diff --git a/src/core/touch_selection_controller_client_qt.h b/src/core/touch_selection_controller_client_qt.h
index 16d581ba8..a054824a6 100644
--- a/src/core/touch_selection_controller_client_qt.h
+++ b/src/core/touch_selection_controller_client_qt.h
@@ -51,6 +51,7 @@ namespace QtWebEngineCore {
class RenderWidgetHostViewQt;
class TouchSelectionMenuController;
+class TouchHandleDrawableDelegate;
class TouchSelectionControllerClientQt
: public ui::TouchSelectionControllerClient
@@ -98,6 +99,8 @@ public:
std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
void DidScroll() override;
+ void resetControls();
+
private:
void showMenu();
void hideMenu();
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index 6206d846f..45dfd1017 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -1787,6 +1787,14 @@ void WebContentsAdapter::resetSelection()
}
}
+void WebContentsAdapter::resetTouchSelectionController()
+{
+ CHECK_INITIALIZED();
+ unselect();
+ if (auto rwhv = static_cast<RenderWidgetHostViewQt *>(m_webContents->GetRenderWidgetHostView()))
+ rwhv->resetTouchSelectionController();
+}
+
WebContentsAdapterClient::RenderProcessTerminationStatus
WebContentsAdapterClient::renderProcessExitStatus(int terminationStatus) {
auto status = WebContentsAdapterClient::RenderProcessTerminationStatus(-1);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index 9066e7a72..612c4c585 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -236,6 +236,7 @@ public:
bool isFindTextInProgress() const;
bool hasFocusedFrame() const;
void resetSelection();
+ void resetTouchSelectionController();
// meant to be used within WebEngineCore only
void initialize(content::SiteInstance *site);
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index ddc371fa3..14745cbb9 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -88,7 +88,7 @@ class JavaScriptDialogController;
class RenderWidgetHostViewQt;
class RenderWidgetHostViewQtDelegate;
class RenderWidgetHostViewQtDelegateClient;
-class TouchHandleDrawableClient;
+class TouchHandleDrawableDelegate;
class TouchSelectionMenuController;
class WebContentsAdapter;
class WebContentsDelegateQt;
@@ -238,7 +238,7 @@ public:
virtual void setToolTip(const QString& toolTipText) = 0;
virtual ClientType clientType() = 0;
virtual void printRequested() = 0;
- virtual TouchHandleDrawableClient *createTouchHandle(const QMap<int, QImage> &images) = 0;
+ virtual TouchHandleDrawableDelegate * createTouchHandleDelegate(const QMap<int, QImage> &images) = 0;
virtual void showTouchSelectionMenu(TouchSelectionMenuController *menuController, const QRect &bounds, const QSize &handleSize) = 0;
virtual void hideTouchSelectionMenu() = 0;
virtual void findTextFinished(const QWebEngineFindTextResult &result) = 0;