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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE || | 55 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE || |
56 selection_anchor_ != selection_focus_) { | 56 selection_anchor_ != selection_focus_) { |
57 if (touch_selection_controller_) | 57 if (touch_selection_controller_) |
58 touch_selection_controller_->SelectionChanged(); | 58 touch_selection_controller_->SelectionChanged(); |
59 } else { | 59 } else { |
60 EndTouchEditing(false); | 60 EndTouchEditing(false); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void TouchEditableImplAura::OverscrollStarted() { | 64 void TouchEditableImplAura::OverscrollStarted() { |
65 scrolls_in_progress_++; | 65 overscroll_in_progress_ = true; |
66 } | 66 } |
67 | 67 |
68 void TouchEditableImplAura::OverscrollCompleted() { | 68 void TouchEditableImplAura::OverscrollCompleted() { |
69 ScrollEnded(); | 69 overscroll_in_progress_ = false; |
| 70 StartTouchEditingIfNecessary(); |
70 } | 71 } |
71 | 72 |
72 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
73 // TouchEditableImplAura, RenderWidgetHostViewAura::TouchEditingClient | 74 // TouchEditableImplAura, RenderWidgetHostViewAura::TouchEditingClient |
74 // implementation: | 75 // implementation: |
75 | 76 |
76 void TouchEditableImplAura::StartTouchEditing() { | 77 void TouchEditableImplAura::StartTouchEditing() { |
77 if (!rwhva_ || !rwhva_->HasFocus()) | 78 if (!rwhva_ || !rwhva_->HasFocus()) |
78 return; | 79 return; |
79 | 80 |
(...skipping 19 matching lines...) Expand all Loading... |
99 | 100 |
100 void TouchEditableImplAura::OnSelectionOrCursorChanged( | 101 void TouchEditableImplAura::OnSelectionOrCursorChanged( |
101 const ui::SelectionBound& anchor, | 102 const ui::SelectionBound& anchor, |
102 const ui::SelectionBound& focus) { | 103 const ui::SelectionBound& focus) { |
103 selection_anchor_ = anchor; | 104 selection_anchor_ = anchor; |
104 selection_focus_ = focus; | 105 selection_focus_ = focus; |
105 | 106 |
106 // If touch editing handles were not visible, we bring them up only if the | 107 // If touch editing handles were not visible, we bring them up only if the |
107 // current event is a gesture event, no scroll/fling/overscoll is in progress, | 108 // current event is a gesture event, no scroll/fling/overscoll is in progress, |
108 // and there is non-zero selection on the page | 109 // and there is non-zero selection on the page |
109 if (selection_gesture_in_process_ && !scrolls_in_progress_ && | 110 if (selection_gesture_in_process_ && !scroll_in_progress_ && |
110 selection_anchor_ != selection_focus_) { | 111 !overscroll_in_progress_ && selection_anchor_ != selection_focus_) { |
111 StartTouchEditing(); | 112 StartTouchEditing(); |
112 selection_gesture_in_process_ = false; | 113 selection_gesture_in_process_ = false; |
113 } | 114 } |
114 | 115 |
115 UpdateEditingController(); | 116 UpdateEditingController(); |
116 } | 117 } |
117 | 118 |
118 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { | 119 void TouchEditableImplAura::OnTextInputTypeChanged(ui::TextInputType type) { |
119 text_input_type_ = type; | 120 text_input_type_ = type; |
120 } | 121 } |
(...skipping 30 matching lines...) Expand all Loading... |
151 // For single taps, not inside selected region, we want to show handles | 152 // For single taps, not inside selected region, we want to show handles |
152 // only when the tap is on an already focused textfield. | 153 // only when the tap is on an already focused textfield. |
153 textfield_was_focused_on_tap_ = | 154 textfield_was_focused_on_tap_ = |
154 gesture_event->details().tap_count() == 1 && | 155 gesture_event->details().tap_count() == 1 && |
155 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | 156 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; |
156 break; | 157 break; |
157 case ui::ET_GESTURE_LONG_PRESS: | 158 case ui::ET_GESTURE_LONG_PRESS: |
158 selection_gesture_in_process_ = true; | 159 selection_gesture_in_process_ = true; |
159 break; | 160 break; |
160 case ui::ET_GESTURE_SCROLL_BEGIN: | 161 case ui::ET_GESTURE_SCROLL_BEGIN: |
161 scrolls_in_progress_++; | 162 scroll_in_progress_ = true;; |
162 // We need to hide selection handles during scroll (including fling and | 163 // We need to hide selection handles during scroll (including fling and |
163 // overscroll), but they should be re-activated after scrolling if: | 164 // overscroll), but they should be re-activated after scrolling if: |
164 // - an existing scroll decided that handles should be shown after | 165 // - an existing scroll decided that handles should be shown after |
165 // scrolling; or | 166 // scrolling; or |
166 // - the gesture in progress is going to end in selection; or | 167 // - the gesture in progress is going to end in selection; or |
167 // - selection handles are currently active. | 168 // - selection handles are currently active. |
168 handles_hidden_due_to_scroll_ = handles_hidden_due_to_scroll_ || | 169 handles_hidden_due_to_scroll_ = handles_hidden_due_to_scroll_ || |
169 selection_gesture_in_process_ || | 170 selection_gesture_in_process_ || |
170 touch_selection_controller_ != NULL; | 171 touch_selection_controller_ != NULL; |
171 selection_gesture_in_process_ = false; | 172 selection_gesture_in_process_ = false; |
172 EndTouchEditing(true); | 173 EndTouchEditing(true); |
173 break; | 174 break; |
174 case ui::ET_GESTURE_SCROLL_END: | 175 case ui::ET_GESTURE_SCROLL_END: |
175 ScrollEnded(); | 176 scroll_in_progress_ = false; |
| 177 StartTouchEditingIfNecessary(); |
176 break; | 178 break; |
177 default: | 179 default: |
178 break; | 180 break; |
179 } | 181 } |
180 return false; | 182 return false; |
181 } | 183 } |
182 | 184 |
183 void TouchEditableImplAura::GestureEventAck(int gesture_event_type) { | 185 void TouchEditableImplAura::GestureEventAck(int gesture_event_type) { |
184 DCHECK(rwhva_); | 186 DCHECK(rwhva_); |
185 if (gesture_event_type == blink::WebInputEvent::GestureTap && | 187 if (gesture_event_type == blink::WebInputEvent::GestureTap && |
186 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && | 188 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE && |
187 textfield_was_focused_on_tap_) { | 189 textfield_was_focused_on_tap_) { |
188 StartTouchEditing(); | 190 StartTouchEditing(); |
189 UpdateEditingController(); | 191 UpdateEditingController(); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 void TouchEditableImplAura::DidStopFlinging() { | 195 void TouchEditableImplAura::DidStopFlinging() { |
194 ScrollEnded(); | 196 scroll_in_progress_ = false; |
| 197 StartTouchEditingIfNecessary(); |
195 } | 198 } |
196 | 199 |
197 void TouchEditableImplAura::OnViewDestroyed() { | 200 void TouchEditableImplAura::OnViewDestroyed() { |
198 Cleanup(); | 201 Cleanup(); |
199 } | 202 } |
200 | 203 |
201 //////////////////////////////////////////////////////////////////////////////// | 204 //////////////////////////////////////////////////////////////////////////////// |
202 // TouchEditableImplAura, ui::TouchEditable implementation: | 205 // TouchEditableImplAura, ui::TouchEditable implementation: |
203 | 206 |
204 void TouchEditableImplAura::SelectRect(const gfx::Point& start, | 207 void TouchEditableImplAura::SelectRect(const gfx::Point& start, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 344 } |
342 | 345 |
343 //////////////////////////////////////////////////////////////////////////////// | 346 //////////////////////////////////////////////////////////////////////////////// |
344 // TouchEditableImplAura, private: | 347 // TouchEditableImplAura, private: |
345 | 348 |
346 TouchEditableImplAura::TouchEditableImplAura() | 349 TouchEditableImplAura::TouchEditableImplAura() |
347 : text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 350 : text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
348 rwhva_(NULL), | 351 rwhva_(NULL), |
349 selection_gesture_in_process_(false), | 352 selection_gesture_in_process_(false), |
350 handles_hidden_due_to_scroll_(false), | 353 handles_hidden_due_to_scroll_(false), |
351 scrolls_in_progress_(0), | 354 scroll_in_progress_(false), |
| 355 overscroll_in_progress_(false), |
352 textfield_was_focused_on_tap_(false) { | 356 textfield_was_focused_on_tap_(false) { |
353 } | 357 } |
354 | 358 |
355 void TouchEditableImplAura::ScrollEnded() { | 359 void TouchEditableImplAura::StartTouchEditingIfNecessary() { |
356 scrolls_in_progress_--; | |
357 // If there is no scrolling left in progress, show selection handles if they | 360 // If there is no scrolling left in progress, show selection handles if they |
358 // were hidden due to scroll and there is a selection. | 361 // were hidden due to scroll and there is a selection. |
359 if (!scrolls_in_progress_ && handles_hidden_due_to_scroll_ && | 362 if (!scroll_in_progress_ && !overscroll_in_progress_ && |
| 363 handles_hidden_due_to_scroll_ && |
360 (selection_anchor_ != selection_focus_ || | 364 (selection_anchor_ != selection_focus_ || |
361 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { | 365 text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)) { |
362 StartTouchEditing(); | 366 StartTouchEditing(); |
363 UpdateEditingController(); | 367 UpdateEditingController(); |
364 handles_hidden_due_to_scroll_ = false; | 368 handles_hidden_due_to_scroll_ = false; |
365 } | 369 } |
366 } | 370 } |
367 | 371 |
368 void TouchEditableImplAura::Cleanup() { | 372 void TouchEditableImplAura::Cleanup() { |
369 if (rwhva_) { | 373 if (rwhva_) { |
370 rwhva_->set_touch_editing_client(NULL); | 374 rwhva_->set_touch_editing_client(NULL); |
371 rwhva_ = NULL; | 375 rwhva_ = NULL; |
372 } | 376 } |
373 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; | 377 text_input_type_ = ui::TEXT_INPUT_TYPE_NONE; |
374 EndTouchEditing(true); | 378 EndTouchEditing(true); |
375 selection_gesture_in_process_ = false; | 379 selection_gesture_in_process_ = false; |
376 handles_hidden_due_to_scroll_ = false; | 380 handles_hidden_due_to_scroll_ = false; |
377 scrolls_in_progress_ = 0; | 381 scroll_in_progress_ = false; |
| 382 overscroll_in_progress_ = false; |
378 } | 383 } |
379 | 384 |
380 } // namespace content | 385 } // namespace content |
OLD | NEW |