| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_rect_ != selection_focus_rect_) { |
| 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 overscroll_in_progress_ = true; | 64 scrolls_in_progress_++; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TouchEditableImplAura::OverscrollCompleted() { | 67 void TouchEditableImplAura::OverscrollCompleted() { |
| 68 // We might receive multiple OverscrollStarted() and OverscrollCompleted() | 68 ScrollEnded(); |
| 69 // during the same scroll session (for example, when the scroll direction | |
| 70 // changes). We want to show the handles only when: | |
| 71 // 1. Overscroll has completed | |
| 72 // 2. Scrolling session is over, i.e. we have received ET_GESTURE_SCROLL_END. | |
| 73 // 3. If we had hidden the handles when scrolling started | |
| 74 // 4. If there is still a need to show handles (there is a non-empty selection | |
| 75 // or non-NONE |text_input_type_|) | |
| 76 if (overscroll_in_progress_ && !scroll_in_progress_ && | |
| 77 handles_hidden_due_to_scroll_ && | |
| 78 (selection_anchor_rect_ != selection_focus_rect_ || | |
| 79 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { | |
| 80 StartTouchEditing(); | |
| 81 UpdateEditingController(); | |
| 82 } | |
| 83 overscroll_in_progress_ = false; | |
| 84 } | 69 } |
| 85 | 70 |
| 86 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
| 87 // TouchEditableImplAura, RenderWidgetHostViewAura::TouchEditingClient | 72 // TouchEditableImplAura, RenderWidgetHostViewAura::TouchEditingClient |
| 88 // implementation: | 73 // implementation: |
| 89 | 74 |
| 90 void TouchEditableImplAura::StartTouchEditing() { | 75 void TouchEditableImplAura::StartTouchEditing() { |
| 91 if (!rwhva_ || !rwhva_->HasFocus()) | 76 if (!rwhva_ || !rwhva_->HasFocus()) |
| 92 return; | 77 return; |
| 93 | 78 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 touch_selection_controller_.reset(); | 94 touch_selection_controller_.reset(); |
| 110 } | 95 } |
| 111 } | 96 } |
| 112 } | 97 } |
| 113 | 98 |
| 114 void TouchEditableImplAura::OnSelectionOrCursorChanged(const gfx::Rect& anchor, | 99 void TouchEditableImplAura::OnSelectionOrCursorChanged(const gfx::Rect& anchor, |
| 115 const gfx::Rect& focus) { | 100 const gfx::Rect& focus) { |
| 116 selection_anchor_rect_ = anchor; | 101 selection_anchor_rect_ = anchor; |
| 117 selection_focus_rect_ = focus; | 102 selection_focus_rect_ = focus; |
| 118 | 103 |
| 119 // If touch editing handles were not visible, we bring them up only if | 104 // If touch editing handles were not visible, we bring them up only if the |
| 120 // there is non-zero selection on the page. And the current event is a | 105 // current event is a gesture event, no scroll/fling/overscoll is in progress, |
| 121 // gesture event (we dont want to show handles if the user is selecting | 106 // and there is non-zero selection on the page |
| 122 // using mouse or keyboard). | 107 if (selection_gesture_in_process_ && !scrolls_in_progress_ && |
| 123 if (selection_gesture_in_process_ && !scroll_in_progress_ && | |
| 124 !overscroll_in_progress_ && | |
| 125 selection_anchor_rect_ != selection_focus_rect_) { | 108 selection_anchor_rect_ != selection_focus_rect_) { |
| 126 StartTouchEditing(); | 109 StartTouchEditing(); |
| 127 selection_gesture_in_process_ = false; | 110 selection_gesture_in_process_ = false; |
| 128 } | 111 } |
| 129 | 112 |
| 130 UpdateEditingController(); | 113 UpdateEditingController(); |
| 131 } | 114 } |
| 132 | 115 |
| 133 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { | 116 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { |
| 134 text_input_type_ = type; | 117 text_input_type_ = type; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 156 gfx::Rect focus(selection_focus_rect_.origin(), | 139 gfx::Rect focus(selection_focus_rect_.origin(), |
| 157 gfx::Size(1, selection_focus_rect_.height())); | 140 gfx::Size(1, selection_focus_rect_.height())); |
| 158 gfx::Rect selection_rect = gfx::UnionRects(anchor, focus); | 141 gfx::Rect selection_rect = gfx::UnionRects(anchor, focus); |
| 159 if (selection_rect.Contains(gesture_event->location())) { | 142 if (selection_rect.Contains(gesture_event->location())) { |
| 160 StartTouchEditing(); | 143 StartTouchEditing(); |
| 161 return true; | 144 return true; |
| 162 } | 145 } |
| 163 } | 146 } |
| 164 // For single taps, not inside selected region, we want to show handles | 147 // For single taps, not inside selected region, we want to show handles |
| 165 // only when the tap is on an already focused textfield. | 148 // only when the tap is on an already focused textfield. |
| 166 textfield_was_focused_on_tap_ = false; | 149 textfield_was_focused_on_tap_ = |
| 167 if (gesture_event->details().tap_count() == 1 && | 150 gesture_event->details().tap_count() == 1 && |
| 168 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) | 151 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; |
| 169 textfield_was_focused_on_tap_ = true; | |
| 170 break; | 152 break; |
| 171 case ui::ET_GESTURE_LONG_PRESS: | 153 case ui::ET_GESTURE_LONG_PRESS: |
| 172 selection_gesture_in_process_ = true; | 154 selection_gesture_in_process_ = true; |
| 173 break; | 155 break; |
| 174 case ui::ET_GESTURE_SCROLL_BEGIN: | 156 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 175 // If selection handles are currently visible, we want to get them back up | 157 scrolls_in_progress_++; |
| 176 // when scrolling ends. So we set |handles_hidden_due_to_scroll_| so that | 158 // We need to hide selection handles during scroll (including fling and |
| 177 // we can re-start touch editing on scroll end gesture. | 159 // overscroll), but they should be re-activated after scrolling if: |
| 178 scroll_in_progress_ = true; | 160 // - an existing scroll decided that handles should be shown after |
| 179 handles_hidden_due_to_scroll_ = false; | 161 // scrolling; or |
| 180 if (touch_selection_controller_) | 162 // - the gesture in progress is going to end in selection; or |
| 181 handles_hidden_due_to_scroll_ = true; | 163 // - selection handles are currently active. |
| 164 handles_hidden_due_to_scroll_ = handles_hidden_due_to_scroll_ || |
| 165 selection_gesture_in_process_ || |
| 166 touch_selection_controller_ != NULL; |
| 167 selection_gesture_in_process_ = false; |
| 182 EndTouchEditing(true); | 168 EndTouchEditing(true); |
| 183 break; | 169 break; |
| 184 case ui::ET_GESTURE_SCROLL_END: | 170 case ui::ET_GESTURE_SCROLL_END: |
| 185 // Scroll has ended, but we might still be in overscroll animation. | 171 ScrollEnded(); |
| 186 if (handles_hidden_due_to_scroll_ && !overscroll_in_progress_ && | |
| 187 (selection_anchor_rect_ != selection_focus_rect_ || | |
| 188 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { | |
| 189 StartTouchEditing(); | |
| 190 UpdateEditingController(); | |
| 191 } | |
| 192 // fall through to reset |scroll_in_progress_|. | |
| 193 case ui::ET_SCROLL_FLING_START: | |
| 194 selection_gesture_in_process_ = false; | |
| 195 scroll_in_progress_ = false; | |
| 196 break; | 172 break; |
| 197 default: | 173 default: |
| 198 break; | 174 break; |
| 199 } | 175 } |
| 200 return false; | 176 return false; |
| 201 } | 177 } |
| 202 | 178 |
| 203 void TouchEditableImplAura::GestureEventAck(int gesture_event_type) { | 179 void TouchEditableImplAura::GestureEventAck(int gesture_event_type) { |
| 204 DCHECK(rwhva_); | 180 DCHECK(rwhva_); |
| 205 if (gesture_event_type == blink::WebInputEvent::GestureTap && | 181 if (gesture_event_type == blink::WebInputEvent::GestureTap && |
| 206 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && | 182 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && |
| 207 textfield_was_focused_on_tap_) { | 183 textfield_was_focused_on_tap_) { |
| 208 StartTouchEditing(); | 184 StartTouchEditing(); |
| 209 UpdateEditingController(); | 185 UpdateEditingController(); |
| 210 } | 186 } |
| 211 } | 187 } |
| 212 | 188 |
| 189 void TouchEditableImplAura::DidStopFlinging() { |
| 190 ScrollEnded(); |
| 191 } |
| 192 |
| 213 void TouchEditableImplAura::OnViewDestroyed() { | 193 void TouchEditableImplAura::OnViewDestroyed() { |
| 214 Cleanup(); | 194 Cleanup(); |
| 215 } | 195 } |
| 216 | 196 |
| 217 //////////////////////////////////////////////////////////////////////////////// | 197 //////////////////////////////////////////////////////////////////////////////// |
| 218 // TouchEditableImplAura, ui::TouchEditable implementation: | 198 // TouchEditableImplAura, ui::TouchEditable implementation: |
| 219 | 199 |
| 220 void TouchEditableImplAura::SelectRect(const gfx::Point& start, | 200 void TouchEditableImplAura::SelectRect(const gfx::Point& start, |
| 221 const gfx::Point& end) { | 201 const gfx::Point& end) { |
| 222 RenderWidgetHost* host = rwhva_->GetRenderWidgetHost(); | 202 RenderWidgetHost* host = rwhva_->GetRenderWidgetHost(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 337 } |
| 358 | 338 |
| 359 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 360 // TouchEditableImplAura, private: | 340 // TouchEditableImplAura, private: |
| 361 | 341 |
| 362 TouchEditableImplAura::TouchEditableImplAura() | 342 TouchEditableImplAura::TouchEditableImplAura() |
| 363 : text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 343 : text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 364 rwhva_(NULL), | 344 rwhva_(NULL), |
| 365 selection_gesture_in_process_(false), | 345 selection_gesture_in_process_(false), |
| 366 handles_hidden_due_to_scroll_(false), | 346 handles_hidden_due_to_scroll_(false), |
| 367 scroll_in_progress_(false), | 347 scrolls_in_progress_(0), |
| 368 overscroll_in_progress_(false), | |
| 369 textfield_was_focused_on_tap_(false) { | 348 textfield_was_focused_on_tap_(false) { |
| 370 } | 349 } |
| 371 | 350 |
| 351 void TouchEditableImplAura::ScrollEnded() { |
| 352 scrolls_in_progress_--; |
| 353 // If there is no scrolling left in progress, show selection handles if they |
| 354 // were hidden due to scroll and there is a selection. |
| 355 if (!scrolls_in_progress_ && handles_hidden_due_to_scroll_ && |
| 356 (selection_anchor_rect_ != selection_focus_rect_ || |
| 357 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { |
| 358 StartTouchEditing(); |
| 359 UpdateEditingController(); |
| 360 handles_hidden_due_to_scroll_ = false; |
| 361 } |
| 362 } |
| 363 |
| 372 void TouchEditableImplAura::Cleanup() { | 364 void TouchEditableImplAura::Cleanup() { |
| 373 if (rwhva_) { | 365 if (rwhva_) { |
| 374 rwhva_->set_touch_editing_client(NULL); | 366 rwhva_->set_touch_editing_client(NULL); |
| 375 rwhva_ = NULL; | 367 rwhva_ = NULL; |
| 376 } | 368 } |
| 377 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; | 369 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; |
| 378 EndTouchEditing(true); | 370 EndTouchEditing(true); |
| 379 selection_gesture_in_process_ = false; | 371 selection_gesture_in_process_ = false; |
| 380 handles_hidden_due_to_scroll_ = false; | 372 handles_hidden_due_to_scroll_ = false; |
| 381 scroll_in_progress_ = false; | 373 scrolls_in_progress_ = 0; |
| 382 overscroll_in_progress_ = false; | |
| 383 } | 374 } |
| 384 | 375 |
| 385 } // namespace content | 376 } // namespace content |
| OLD | NEW |