Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
index 71d03da56bd6c6ee4cda058a688a2aaca8a90626..e2a07c25284c004a6d67bf058a22cb510858ed16 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
@@ -27,6 +27,7 @@ |
#include "content/browser/renderer_host/compositor_resize_lock_aura.h" |
#include "content/browser/renderer_host/dip_util.h" |
#include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h" |
+#include "content/browser/renderer_host/input/ui_touch_selection_helper.h" |
#include "content/browser/renderer_host/input/web_input_event_util.h" |
#include "content/browser/renderer_host/overscroll_controller.h" |
#include "content/browser/renderer_host/render_view_host_delegate.h" |
@@ -74,6 +75,7 @@ |
#include "ui/gfx/geometry/size_conversions.h" |
#include "ui/gfx/screen.h" |
#include "ui/gfx/skia_util.h" |
+#include "ui/touch_selection/touch_selection_controller_aura.h" |
#include "ui/wm/public/activation_client.h" |
#include "ui/wm/public/scoped_tooltip_disabler.h" |
#include "ui/wm/public/tooltip_client.h" |
@@ -436,7 +438,6 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host, |
legacy_window_destroyed_(false), |
#endif |
has_snapped_to_boundary_(false), |
- touch_editing_client_(NULL), |
is_guest_view_hack_(is_guest_view_hack), |
weak_ptr_factory_(this) { |
if (!is_guest_view_hack_) |
@@ -781,6 +782,8 @@ void RenderWidgetHostViewAura::Focus() { |
void RenderWidgetHostViewAura::Blur() { |
window_->Blur(); |
+ if (selection_controller_) |
+ selection_controller_->HideAndDisallowShowingAutomatically(); |
} |
bool RenderWidgetHostViewAura::HasFocus() const { |
@@ -848,8 +851,10 @@ void RenderWidgetHostViewAura::TextInputTypeChanged( |
text_input_flags_ = flags; |
if (GetInputMethod()) |
GetInputMethod()->OnTextInputTypeChanged(this); |
- if (touch_editing_client_) |
- touch_editing_client_->OnTextInputTypeChanged(text_input_type_); |
+ if (selection_controller_) { |
+ const bool is_editable_node = type != ui::TEXT_INPUT_TYPE_NONE; |
+ selection_controller_->OnSelectionEditable(is_editable_node); |
+ } |
} |
} |
@@ -906,6 +911,9 @@ void RenderWidgetHostViewAura::SelectionChanged(const base::string16& text, |
const gfx::Range& range) { |
RenderWidgetHostViewBase::SelectionChanged(text, offset, range); |
+ if (selection_controller_) |
+ selection_controller_->OnSelectionEmpty(text.empty()); |
+ |
#if defined(USE_X11) && !defined(OS_CHROMEOS) |
if (text.empty() || range.is_empty()) |
return; |
@@ -930,47 +938,7 @@ gfx::Size RenderWidgetHostViewAura::GetRequestedRendererSize() const { |
void RenderWidgetHostViewAura::SelectionBoundsChanged( |
const ViewHostMsg_SelectionBounds_Params& params) { |
- ui::SelectionBound anchor_bound, focus_bound; |
- anchor_bound.SetEdge(params.anchor_rect.origin(), |
- params.anchor_rect.bottom_left()); |
- focus_bound.SetEdge(params.focus_rect.origin(), |
- params.focus_rect.bottom_left()); |
- |
- if (params.anchor_rect == params.focus_rect) { |
- anchor_bound.set_type(ui::SelectionBound::CENTER); |
- focus_bound.set_type(ui::SelectionBound::CENTER); |
- } else { |
- // Whether text is LTR at the anchor handle. |
- bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight; |
- // Whether text is LTR at the focus handle. |
- bool focus_LTR = params.focus_dir == blink::WebTextDirectionLeftToRight; |
- |
- if ((params.is_anchor_first && anchor_LTR) || |
- (!params.is_anchor_first && !anchor_LTR)) { |
- anchor_bound.set_type(ui::SelectionBound::LEFT); |
- } else { |
- anchor_bound.set_type(ui::SelectionBound::RIGHT); |
- } |
- if ((params.is_anchor_first && focus_LTR) || |
- (!params.is_anchor_first && !focus_LTR)) { |
- focus_bound.set_type(ui::SelectionBound::RIGHT); |
- } else { |
- focus_bound.set_type(ui::SelectionBound::LEFT); |
- } |
- } |
- |
- if (anchor_bound == selection_anchor_ && focus_bound == selection_focus_) |
- return; |
- |
- selection_anchor_ = anchor_bound; |
- selection_focus_ = focus_bound; |
- if (GetInputMethod()) |
- GetInputMethod()->OnCaretBoundsChanged(this); |
- |
- if (touch_editing_client_) { |
- touch_editing_client_->OnSelectionOrCursorChanged( |
- anchor_bound, focus_bound); |
- } |
+ NOTREACHED() << "Selection bounds should be routed through the compositor."; |
} |
void RenderWidgetHostViewAura::CopyFromCompositingSurface( |
@@ -1059,6 +1027,9 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
frame->delegated_frame_data.Pass(), |
frame->metadata.device_scale_factor, |
frame->metadata.latency_info); |
+ SelectionBoundsUpdated( |
+ ConvertSelectionBound(frame->metadata.selection_start), |
+ ConvertSelectionBound(frame->metadata.selection_end)); |
return; |
} |
@@ -1072,8 +1043,8 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
} |
void RenderWidgetHostViewAura::DidStopFlinging() { |
- if (touch_editing_client_) |
- touch_editing_client_->DidStopFlinging(); |
+ if (selection_controller_) |
+ selection_controller_->OnFlingCompleted(); |
} |
#if defined(OS_WIN) |
@@ -1153,9 +1124,6 @@ void RenderWidgetHostViewAura::WheelEventAck( |
void RenderWidgetHostViewAura::GestureEventAck( |
const blink::WebGestureEvent& event, |
InputEventAckState ack_result) { |
- if (touch_editing_client_) |
- touch_editing_client_->GestureEventAck(event.type); |
- |
if (overscroll_controller_) { |
overscroll_controller_->ReceivedEventACK( |
event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result)); |
@@ -1546,9 +1514,8 @@ gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen( |
} |
gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const { |
- gfx::Rect rect = |
- ui::RectBetweenSelectionBounds(selection_anchor_, selection_focus_); |
- return ConvertRectToScreen(rect); |
+ return ConvertRectToScreen(ui::RectBetweenSelectionBounds(selection_start_, |
+ selection_end_)); |
} |
bool RenderWidgetHostViewAura::GetCompositionCharacterBounds( |
@@ -1751,8 +1718,8 @@ bool RenderWidgetHostViewAura::CanFocus() { |
void RenderWidgetHostViewAura::OnCaptureLost() { |
host_->LostCapture(); |
- if (touch_editing_client_) |
- touch_editing_client_->EndTouchEditing(false); |
+ if (selection_controller_) |
+ selection_controller_->HideAndDisallowShowingAutomatically(); |
} |
void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) { |
@@ -1835,8 +1802,6 @@ void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const { |
void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent"); |
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
- return; |
if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) { |
popup_child_host_view_->OnKeyEvent(event); |
@@ -1883,9 +1848,6 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent"); |
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
- return; |
- |
if (mouse_locked_) { |
aura::client::CursorClient* cursor_client = |
aura::client::GetCursorClient(window_->GetRootWindow()); |
@@ -2024,8 +1986,6 @@ void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent"); |
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
- return; |
if (event->type() == ui::ET_SCROLL) { |
#if !defined(OS_WIN) |
@@ -2054,8 +2014,12 @@ void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) { |
void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { |
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent"); |
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
- return; |
+ |
+ if (selection_controller_) { |
+ selection_controller_->HandleTouchEvent(event); |
+ if (event->handled()) |
+ return; |
sadrul
2015/03/05 12:37:03
Have you considered making the selection controlle
mohsen
2015/03/06 23:10:08
Since selection controller was already a pre-targe
|
+ } |
// Update the touch event first. |
if (!pointer_state_.OnTouch(*event)) { |
@@ -2077,6 +2041,13 @@ void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) { |
void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { |
TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent"); |
+ |
+ if (selection_controller_) { |
+ selection_controller_->HandleGestureEvent(event); |
+ if (event->handled()) |
+ return; |
+ } |
+ |
if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN || |
event->type() == ui::ET_GESTURE_PINCH_UPDATE || |
event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) { |
@@ -2084,9 +2055,6 @@ void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) { |
return; |
} |
- if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event)) |
- return; |
- |
// Confirm existing composition text on TAP gesture, to make sure the input |
// caret won't be moved with an ongoing composition text. |
if (event->type() == ui::ET_GESTURE_TAP) |
@@ -2209,8 +2177,8 @@ void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus, |
DetachFromInputMethod(); |
host_->SetInputMethodActive(false); |
- if (touch_editing_client_) |
- touch_editing_client_->EndTouchEditing(false); |
+ if (selection_controller_) |
+ selection_controller_->HideAndDisallowShowingAutomatically(); |
if (overscroll_controller_) |
overscroll_controller_->Cancel(); |
@@ -2267,9 +2235,8 @@ void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host, |
// RenderWidgetHostViewAura, private: |
RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
- if (touch_editing_client_) |
- touch_editing_client_->OnViewDestroyed(); |
- |
+ selection_controller_.reset(); |
+ selection_controller_client_.reset(); |
delegated_frame_host_.reset(); |
window_observer_.reset(); |
if (window_->GetHost()) |
@@ -2419,6 +2386,14 @@ void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) { |
overscroll_controller_.reset(new OverscrollController()); |
} |
+void RenderWidgetHostViewAura::InitSelectionController( |
+ ui::TouchSelectionControllerAuraClient* selection_controller_client) { |
+ DCHECK(!selection_controller_client_); |
+ selection_controller_client_.reset(selection_controller_client); |
+ selection_controller_.reset( |
+ new ui::TouchSelectionControllerAura(selection_controller_client)); |
+} |
+ |
void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() { |
// The top left corner of our view in window coordinates might not land on a |
// device pixel boundary if we have a non-integer device scale. In that case, |
@@ -2451,10 +2426,6 @@ void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
window_->SetBounds(rect); |
host_->WasResized(); |
delegated_frame_host_->WasResized(); |
- if (touch_editing_client_) { |
- touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_, |
- selection_focus_); |
- } |
#if defined(OS_WIN) |
// Create the legacy dummy window which corresponds to the bounds of the |
// webcontents. This will be passed as the container window for windowless |
@@ -2598,6 +2569,22 @@ SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() { |
return kN32_SkColorType; |
} |
+void RenderWidgetHostViewAura::SelectionBoundsUpdated( |
+ const ui::SelectionBound& start, |
+ const ui::SelectionBound& end) { |
+ if (selection_start_ == start && selection_end_ == end) |
+ return; |
+ |
+ selection_start_ = start; |
+ selection_end_ = end; |
+ |
+ if (GetInputMethod()) |
+ GetInputMethod()->OnCaretBoundsChanged(this); |
+ |
+ if (selection_controller_) |
+ selection_controller_->OnSelectionBoundsUpdated(start, end); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// DelegatedFrameHost, public: |