| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/web_contents/touch_editable_impl_aura.h" | 5 #include "content/browser/web_contents/touch_editable_impl_aura.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 rwhva_ = view; | 46 rwhva_ = view; |
| 47 rwhva_->set_touch_editing_client(this); | 47 rwhva_->set_touch_editing_client(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void TouchEditableImplAura::UpdateEditingController() { | 50 void TouchEditableImplAura::UpdateEditingController() { |
| 51 if (!rwhva_ || !rwhva_->HasFocus()) | 51 if (!rwhva_ || !rwhva_->HasFocus()) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE || | 54 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE || |
| 55 selection_anchor_rect_ != selection_focus_rect_) { | 55 selection_anchor_ != selection_focus_) { |
| 56 if (touch_selection_controller_) | 56 if (touch_selection_controller_) |
| 57 touch_selection_controller_->SelectionChanged(); | 57 touch_selection_controller_->SelectionChanged(); |
| 58 } else { | 58 } else { |
| 59 EndTouchEditing(false); | 59 EndTouchEditing(false); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 void TouchEditableImplAura::OverscrollStarted() { | 63 void TouchEditableImplAura::OverscrollStarted() { |
| 64 scrolls_in_progress_++; | 64 scrolls_in_progress_++; |
| 65 } | 65 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 89 if (touch_selection_controller_->IsHandleDragInProgress()) { | 89 if (touch_selection_controller_->IsHandleDragInProgress()) { |
| 90 touch_selection_controller_->SelectionChanged(); | 90 touch_selection_controller_->SelectionChanged(); |
| 91 } else { | 91 } else { |
| 92 selection_gesture_in_process_ = false; | 92 selection_gesture_in_process_ = false; |
| 93 touch_selection_controller_->HideHandles(quick); | 93 touch_selection_controller_->HideHandles(quick); |
| 94 touch_selection_controller_.reset(); | 94 touch_selection_controller_.reset(); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void TouchEditableImplAura::OnSelectionOrCursorChanged(const gfx::Rect& anchor, | 99 void TouchEditableImplAura::OnSelectionOrCursorChanged( |
| 100 const gfx::Rect& focus) { | 100 const ui::SelectionBound& anchor, |
| 101 selection_anchor_rect_ = anchor; | 101 const ui::SelectionBound& focus) { |
| 102 selection_focus_rect_ = focus; | 102 selection_anchor_ = anchor; |
| 103 selection_focus_ = focus; |
| 103 | 104 |
| 104 // If touch editing handles were not visible, we bring them up only if the | 105 // If touch editing handles were not visible, we bring them up only if the |
| 105 // current event is a gesture event, no scroll/fling/overscoll is in progress, | 106 // current event is a gesture event, no scroll/fling/overscoll is in progress, |
| 106 // and there is non-zero selection on the page | 107 // and there is non-zero selection on the page |
| 107 if (selection_gesture_in_process_ && !scrolls_in_progress_ && | 108 if (selection_gesture_in_process_ && !scrolls_in_progress_ && |
| 108 selection_anchor_rect_ != selection_focus_rect_) { | 109 selection_anchor_ != selection_focus_) { |
| 109 StartTouchEditing(); | 110 StartTouchEditing(); |
| 110 selection_gesture_in_process_ = false; | 111 selection_gesture_in_process_ = false; |
| 111 } | 112 } |
| 112 | 113 |
| 113 UpdateEditingController(); | 114 UpdateEditingController(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { | 117 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { |
| 117 text_input_type_ = type; | 118 text_input_type_ = type; |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool TouchEditableImplAura::HandleInputEvent(const ui::Event* event) { | 121 bool TouchEditableImplAura::HandleInputEvent(const ui::Event* event) { |
| 121 DCHECK(rwhva_); | 122 DCHECK(rwhva_); |
| 122 if (!event->IsGestureEvent()) { | 123 if (!event->IsGestureEvent()) { |
| 123 // Ignore all non-gesture events. Non-gesture events that can deactivate | 124 // Ignore all non-gesture events. Non-gesture events that can deactivate |
| 124 // touch editing are handled in TouchSelectionControllerImpl. | 125 // touch editing are handled in TouchSelectionControllerImpl. |
| 125 return false; | 126 return false; |
| 126 } | 127 } |
| 127 | 128 |
| 128 const ui::GestureEvent* gesture_event = | 129 const ui::GestureEvent* gesture_event = |
| 129 static_cast<const ui::GestureEvent*>(event); | 130 static_cast<const ui::GestureEvent*>(event); |
| 130 switch (event->type()) { | 131 switch (event->type()) { |
| 131 case ui::ET_GESTURE_TAP: | 132 case ui::ET_GESTURE_TAP: |
| 132 // When the user taps, we want to show touch editing handles if user | 133 // When the user taps, we want to show touch editing handles if user |
| 133 // tapped on selected text. | 134 // tapped on selected text. |
| 134 if (gesture_event->details().tap_count() == 1 && | 135 if (gesture_event->details().tap_count() == 1 && |
| 135 selection_anchor_rect_ != selection_focus_rect_) { | 136 selection_anchor_ != selection_focus_) { |
| 136 // UnionRects only works for rects with non-zero width. | 137 gfx::Rect selection_rect = |
| 137 gfx::Rect anchor(selection_anchor_rect_.origin(), | 138 ui::RectBetweenSelectionBounds(selection_anchor_, selection_focus_); |
| 138 gfx::Size(1, selection_anchor_rect_.height())); | |
| 139 gfx::Rect focus(selection_focus_rect_.origin(), | |
| 140 gfx::Size(1, selection_focus_rect_.height())); | |
| 141 gfx::Rect selection_rect = gfx::UnionRects(anchor, focus); | |
| 142 if (selection_rect.Contains(gesture_event->location())) { | 139 if (selection_rect.Contains(gesture_event->location())) { |
| 143 StartTouchEditing(); | 140 StartTouchEditing(); |
| 144 return true; | 141 return true; |
| 145 } | 142 } |
| 146 } | 143 } |
| 147 // For single taps, not inside selected region, we want to show handles | 144 // For single taps, not inside selected region, we want to show handles |
| 148 // only when the tap is on an already focused textfield. | 145 // only when the tap is on an already focused textfield. |
| 149 textfield_was_focused_on_tap_ = | 146 textfield_was_focused_on_tap_ = |
| 150 gesture_event->details().tap_count() == 1 && | 147 gesture_event->details().tap_count() == 1 && |
| 151 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | 148 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 205 |
| 209 void TouchEditableImplAura::MoveCaretTo(const gfx::Point& point) { | 206 void TouchEditableImplAura::MoveCaretTo(const gfx::Point& point) { |
| 210 if (!rwhva_) | 207 if (!rwhva_) |
| 211 return; | 208 return; |
| 212 | 209 |
| 213 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 210 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
| 214 rwhva_->GetRenderWidgetHost()); | 211 rwhva_->GetRenderWidgetHost()); |
| 215 host->MoveCaret(point); | 212 host->MoveCaret(point); |
| 216 } | 213 } |
| 217 | 214 |
| 218 void TouchEditableImplAura::GetSelectionEndPoints(gfx::Rect* p1, | 215 void TouchEditableImplAura::GetSelectionEndPoints(ui::SelectionBound* anchor, |
| 219 gfx::Rect* p2) { | 216 ui::SelectionBound* focus) { |
| 220 *p1 = selection_anchor_rect_; | 217 *anchor = selection_anchor_; |
| 221 *p2 = selection_focus_rect_; | 218 *focus = selection_focus_; |
| 222 } | 219 } |
| 223 | 220 |
| 224 gfx::Rect TouchEditableImplAura::GetBounds() { | 221 gfx::Rect TouchEditableImplAura::GetBounds() { |
| 225 return rwhva_ ? gfx::Rect(rwhva_->GetNativeView()->bounds().size()) : | 222 return rwhva_ ? gfx::Rect(rwhva_->GetNativeView()->bounds().size()) : |
| 226 gfx::Rect(); | 223 gfx::Rect(); |
| 227 } | 224 } |
| 228 | 225 |
| 229 gfx::NativeView TouchEditableImplAura::GetNativeView() const { | 226 gfx::NativeView TouchEditableImplAura::GetNativeView() const { |
| 230 return rwhva_ ? rwhva_->GetNativeView()->GetToplevelWindow() : NULL; | 227 return rwhva_ ? rwhva_->GetNativeView()->GetToplevelWindow() : NULL; |
| 231 } | 228 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 handles_hidden_due_to_scroll_(false), | 343 handles_hidden_due_to_scroll_(false), |
| 347 scrolls_in_progress_(0), | 344 scrolls_in_progress_(0), |
| 348 textfield_was_focused_on_tap_(false) { | 345 textfield_was_focused_on_tap_(false) { |
| 349 } | 346 } |
| 350 | 347 |
| 351 void TouchEditableImplAura::ScrollEnded() { | 348 void TouchEditableImplAura::ScrollEnded() { |
| 352 scrolls_in_progress_--; | 349 scrolls_in_progress_--; |
| 353 // If there is no scrolling left in progress, show selection handles if they | 350 // If there is no scrolling left in progress, show selection handles if they |
| 354 // were hidden due to scroll and there is a selection. | 351 // were hidden due to scroll and there is a selection. |
| 355 if (!scrolls_in_progress_ && handles_hidden_due_to_scroll_ && | 352 if (!scrolls_in_progress_ && handles_hidden_due_to_scroll_ && |
| 356 (selection_anchor_rect_ != selection_focus_rect_ || | 353 (selection_anchor_ != selection_focus_ || |
| 357 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { | 354 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { |
| 358 StartTouchEditing(); | 355 StartTouchEditing(); |
| 359 UpdateEditingController(); | 356 UpdateEditingController(); |
| 360 handles_hidden_due_to_scroll_ = false; | 357 handles_hidden_due_to_scroll_ = false; |
| 361 } | 358 } |
| 362 } | 359 } |
| 363 | 360 |
| 364 void TouchEditableImplAura::Cleanup() { | 361 void TouchEditableImplAura::Cleanup() { |
| 365 if (rwhva_) { | 362 if (rwhva_) { |
| 366 rwhva_->set_touch_editing_client(NULL); | 363 rwhva_->set_touch_editing_client(NULL); |
| 367 rwhva_ = NULL; | 364 rwhva_ = NULL; |
| 368 } | 365 } |
| 369 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; | 366 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; |
| 370 EndTouchEditing(true); | 367 EndTouchEditing(true); |
| 371 selection_gesture_in_process_ = false; | 368 selection_gesture_in_process_ = false; |
| 372 handles_hidden_due_to_scroll_ = false; | 369 handles_hidden_due_to_scroll_ = false; |
| 373 scrolls_in_progress_ = 0; | 370 scrolls_in_progress_ = 0; |
| 374 } | 371 } |
| 375 | 372 |
| 376 } // namespace content | 373 } // namespace content |
| OLD | NEW |