Commit 821e8b94 authored by W. James MacLean's avatar W. James MacLean Committed by Commit Bot

Route Touch Selection ContextMenus on Android.

When the touch-selection context menu is re-shown after moving one of
the selection handles, it goes through RenderWidgetHostViewAndroid which
always sends the request to the mainframe renderer, which is incorrect
when the selection is inside an OOPIF.

This CL fixes it by having TouchSelectionControllerClientManagerAndroid
route the request to the manager's currently active client. If the
selection is in an OOPIF, then TouchSelectionControllerClientChildFrame
will handle it.

We still need to develop tests for touch handle movements & context
menus, both for OOPIFs and main frames.

Bug: 977215
Change-Id: I3649af49839778fea4462b35b1b11349e00edcc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2382227
Commit-Queue: James MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarMohsen Izadi <mohsen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804333}
parent c8387541
......@@ -14,6 +14,7 @@
#include "content/public/common/use_zoom_for_dsf_policy.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/pointer/touch_editing_controller.h"
#include "ui/base/ui_base_types.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/strings/grit/ui_strings.h"
......@@ -77,6 +78,13 @@ void TouchSelectionControllerClientChildFrame::UpdateSelectionBoundsIfNeeded(
}
}
void TouchSelectionControllerClientChildFrame::ShowTouchSelectionContextMenu(
const gfx::Point& location) {
// |location| should be in root-view coordinates, and RenderWidgetHostImpl
// will do the conversion to renderer coordinates.
rwhv_->host()->ShowContextMenuAtPoint(location, ui::MENU_SOURCE_TOUCH_HANDLE);
}
// Since an active touch selection in a child frame can have its screen position
// changed by a scroll in a containing frame (and thus without the child frame
// sending a new compositor frame), we must manually recompute the screen
......
......@@ -37,6 +37,7 @@ class CONTENT_EXPORT TouchSelectionControllerClientChildFrame
void UpdateSelectionBoundsIfNeeded(
const viz::Selection<gfx::SelectionBound>& selection,
float device_scale_factor);
void ShowTouchSelectionContextMenu(const gfx::Point& location) override;
private:
void TransformSelectionBoundsAndUpdate();
......
......@@ -96,6 +96,11 @@ void TouchSelectionControllerClientManagerAndroid::RemoveObserver(
observers_.RemoveObserver(observer);
}
void TouchSelectionControllerClientManagerAndroid::ShowContextMenu(
const gfx::Point& location) {
active_client_->ShowTouchSelectionContextMenu(location);
}
// TouchSelectionControllerClient implementation.
bool TouchSelectionControllerClientManagerAndroid::SupportsAnimation() const {
return rwhv_->SupportsAnimation();
......@@ -141,6 +146,11 @@ void TouchSelectionControllerClientManagerAndroid::DidScroll() {
// Nothing needs to be done here.
}
void TouchSelectionControllerClientManagerAndroid::
ShowTouchSelectionContextMenu(const gfx::Point& location) {
active_client_->ShowTouchSelectionContextMenu(location);
}
void TouchSelectionControllerClientManagerAndroid::
OnAggregatedHitTestRegionListUpdated(
const viz::FrameSinkId& frame_sink_id,
......
......@@ -45,6 +45,7 @@ class TouchSelectionControllerClientManagerAndroid
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void ShowContextMenu(const gfx::Point& location) override;
// TouchSelectionControllerClient implementation.
bool SupportsAnimation() const override;
......@@ -57,6 +58,7 @@ class TouchSelectionControllerClientManagerAndroid
void OnDragUpdate(const gfx::PointF& position) override;
std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
void DidScroll() override;
void ShowTouchSelectionContextMenu(const gfx::Point& location) override;
// viz::HitTestRegionObserver implementation.
void OnAggregatedHitTestRegionListUpdated(
......
......@@ -551,9 +551,9 @@ void RenderWidgetHostViewAndroid::ShowContextMenuAtTouchHandle(
const base::android::JavaParamRef<jobject>& obj,
jint x,
jint y) {
if (host()) {
host()->ShowContextMenuAtPoint(gfx::Point(x, y),
ui::MENU_SOURCE_TOUCH_HANDLE);
if (GetTouchSelectionControllerClientManager()) {
GetTouchSelectionControllerClientManager()->ShowContextMenu(
gfx::Point(x, y));
}
}
......@@ -1247,6 +1247,11 @@ RenderWidgetHostViewAndroid::CreateDrawable() {
void RenderWidgetHostViewAndroid::DidScroll() {}
void RenderWidgetHostViewAndroid::ShowTouchSelectionContextMenu(
const gfx::Point& location) {
host()->ShowContextMenuAtPoint(location, ui::MENU_SOURCE_TOUCH_HANDLE);
}
void RenderWidgetHostViewAndroid::SynchronousCopyContents(
const gfx::Rect& src_subrect_dip,
const gfx::Size& dst_size_in_pixel,
......
......@@ -223,6 +223,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid
void OnDragUpdate(const gfx::PointF& position) override;
std::unique_ptr<ui::TouchHandleDrawable> CreateDrawable() override;
void DidScroll() override;
void ShowTouchSelectionContextMenu(const gfx::Point& location) override;
// Non-virtual methods
void UpdateNativeViewTree(gfx::NativeView parent_native_view);
......
......@@ -9,6 +9,7 @@
#include "content/common/content_export.h"
namespace gfx {
class Point;
class SelectionBound;
}
......@@ -61,6 +62,9 @@ class CONTENT_EXPORT TouchSelectionControllerClientManager {
// monitor the manager's lifetime.
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Used to request the active client to show a context menu at |location|.
virtual void ShowContextMenu(const gfx::Point& location) {}
};
} // namespace content
......
......@@ -7,6 +7,7 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
......@@ -36,6 +37,7 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient {
virtual void OnDragUpdate(const gfx::PointF& position) = 0;
virtual std::unique_ptr<TouchHandleDrawable> CreateDrawable() = 0;
virtual void DidScroll() = 0;
virtual void ShowTouchSelectionContextMenu(const gfx::Point& location) {}
};
// Controller for manipulating text selection via touch input.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment