| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/touch_selection/touch_selection_controller.h" | 5 #include "ui/touch_selection/touch_selection_controller.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 selection_start_ = base; | 88 selection_start_ = base; |
| 89 selection_end_ = extent; | 89 selection_end_ = extent; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { | 92 void MoveRangeSelectionExtent(const gfx::PointF& extent) override { |
| 93 selection_moved_ = true; | 93 selection_moved_ = true; |
| 94 selection_end_ = extent; | 94 selection_end_ = extent; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void OnSelectionEvent(SelectionEventType event, | 97 void OnSelectionEvent(SelectionEventType event) override { |
| 98 const gfx::PointF& end_position) override { | |
| 99 events_.push_back(event); | 98 events_.push_back(event); |
| 100 last_event_start_ = end_position; | 99 last_event_start_ = controller_->GetStartPosition(); |
| 100 last_event_end_ = controller_->GetEndPosition(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { | 103 scoped_ptr<TouchHandleDrawable> CreateDrawable() override { |
| 104 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_)); | 104 return make_scoped_ptr(new MockTouchHandleDrawable(&dragging_enabled_)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void AllowShowingOnTapForEmptyEditable() { | 107 void AllowShowingOnTapForEmptyEditable() { |
| 108 bool show_on_tap_for_empty_editable = true; | 108 bool show_on_tap_for_empty_editable = true; |
| 109 controller_.reset(new TouchSelectionController( | 109 controller_.reset(new TouchSelectionController( |
| 110 this, | 110 this, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 bool GetAndResetSelectionPointsSwapped() { | 174 bool GetAndResetSelectionPointsSwapped() { |
| 175 bool swapped = selection_points_swapped_; | 175 bool swapped = selection_points_swapped_; |
| 176 selection_points_swapped_ = false; | 176 selection_points_swapped_ = false; |
| 177 return swapped; | 177 return swapped; |
| 178 } | 178 } |
| 179 | 179 |
| 180 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } | 180 const gfx::PointF& GetLastCaretPosition() const { return caret_position_; } |
| 181 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } | 181 const gfx::PointF& GetLastSelectionStart() const { return selection_start_; } |
| 182 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } | 182 const gfx::PointF& GetLastSelectionEnd() const { return selection_end_; } |
| 183 const gfx::PointF& GetLastEventAnchor() const { return last_event_start_; } | 183 const gfx::PointF& GetLastEventStart() const { return last_event_start_; } |
| 184 const gfx::PointF& GetLastEventEnd() const { return last_event_end_; } |
| 184 | 185 |
| 185 std::vector<SelectionEventType> GetAndResetEvents() { | 186 std::vector<SelectionEventType> GetAndResetEvents() { |
| 186 std::vector<SelectionEventType> events; | 187 std::vector<SelectionEventType> events; |
| 187 events.swap(events_); | 188 events.swap(events_); |
| 188 return events; | 189 return events; |
| 189 } | 190 } |
| 190 | 191 |
| 191 TouchSelectionController& controller() { return *controller_; } | 192 TouchSelectionController& controller() { return *controller_; } |
| 192 | 193 |
| 193 private: | 194 private: |
| 194 gfx::PointF last_event_start_; | 195 gfx::PointF last_event_start_; |
| 196 gfx::PointF last_event_end_; |
| 195 gfx::PointF caret_position_; | 197 gfx::PointF caret_position_; |
| 196 gfx::PointF selection_start_; | 198 gfx::PointF selection_start_; |
| 197 gfx::PointF selection_end_; | 199 gfx::PointF selection_end_; |
| 198 std::vector<SelectionEventType> events_; | 200 std::vector<SelectionEventType> events_; |
| 199 bool caret_moved_; | 201 bool caret_moved_; |
| 200 bool selection_moved_; | 202 bool selection_moved_; |
| 201 bool selection_points_swapped_; | 203 bool selection_points_swapped_; |
| 202 bool needs_animate_; | 204 bool needs_animate_; |
| 203 bool animation_enabled_; | 205 bool animation_enabled_; |
| 204 bool dragging_enabled_; | 206 bool dragging_enabled_; |
| 205 scoped_ptr<TouchSelectionController> controller_; | 207 scoped_ptr<TouchSelectionController> controller_; |
| 206 }; | 208 }; |
| 207 | 209 |
| 208 TEST_F(TouchSelectionControllerTest, InsertionBasic) { | 210 TEST_F(TouchSelectionControllerTest, InsertionBasic) { |
| 209 gfx::RectF insertion_rect(5, 5, 0, 10); | 211 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 210 bool visible = true; | 212 bool visible = true; |
| 211 | 213 |
| 212 // Insertion events are ignored until automatic showing is enabled. | 214 // Insertion events are ignored until automatic showing is enabled. |
| 213 ChangeInsertion(insertion_rect, visible); | 215 ChangeInsertion(insertion_rect, visible); |
| 214 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 216 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 215 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 217 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 216 controller().OnTapEvent(); | 218 controller().OnTapEvent(); |
| 217 | 219 |
| 218 // Insertion events are ignored until the selection region is marked editable. | 220 // Insertion events are ignored until the selection region is marked editable. |
| 219 ChangeInsertion(insertion_rect, visible); | 221 ChangeInsertion(insertion_rect, visible); |
| 220 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 222 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 221 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 223 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 222 | 224 |
| 223 controller().OnTapEvent(); | 225 controller().OnTapEvent(); |
| 224 controller().OnSelectionEditable(true); | 226 controller().OnSelectionEditable(true); |
| 225 ChangeInsertion(insertion_rect, visible); | 227 ChangeInsertion(insertion_rect, visible); |
| 226 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 228 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 227 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 229 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 228 | 230 |
| 229 insertion_rect.Offset(1, 0); | 231 insertion_rect.Offset(1, 0); |
| 230 ChangeInsertion(insertion_rect, visible); | 232 ChangeInsertion(insertion_rect, visible); |
| 231 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); | 233 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); |
| 232 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 234 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 233 | 235 |
| 234 insertion_rect.Offset(0, 1); | 236 insertion_rect.Offset(0, 1); |
| 235 ChangeInsertion(insertion_rect, visible); | 237 ChangeInsertion(insertion_rect, visible); |
| 236 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); | 238 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); |
| 237 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 239 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 238 | 240 |
| 239 ClearInsertion(); | 241 ClearInsertion(); |
| 240 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); | 242 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); |
| 241 } | 243 } |
| 242 | 244 |
| 243 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { | 245 TEST_F(TouchSelectionControllerTest, InsertionClearedWhenNoLongerEditable) { |
| 244 gfx::RectF insertion_rect(5, 5, 0, 10); | 246 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 245 bool visible = true; | 247 bool visible = true; |
| 246 controller().OnTapEvent(); | 248 controller().OnTapEvent(); |
| 247 controller().OnSelectionEditable(true); | 249 controller().OnSelectionEditable(true); |
| 248 | 250 |
| 249 ChangeInsertion(insertion_rect, visible); | 251 ChangeInsertion(insertion_rect, visible); |
| 250 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 252 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 251 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 253 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 252 | 254 |
| 253 controller().OnSelectionEditable(false); | 255 controller().OnSelectionEditable(false); |
| 254 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); | 256 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); |
| 255 } | 257 } |
| 256 | 258 |
| 257 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { | 259 TEST_F(TouchSelectionControllerTest, InsertionWithNoShowOnTapForEmptyEditable) { |
| 258 gfx::RectF insertion_rect(5, 5, 0, 10); | 260 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 259 bool visible = true; | 261 bool visible = true; |
| 260 controller().OnSelectionEditable(true); | 262 controller().OnSelectionEditable(true); |
| 261 | 263 |
| 262 // Taps on an empty editable region should be ignored if the controller is | 264 // Taps on an empty editable region should be ignored if the controller is |
| 263 // created with |show_on_tap_for_empty_editable| set to false. | 265 // created with |show_on_tap_for_empty_editable| set to false. |
| 264 controller().OnTapEvent(); | 266 controller().OnTapEvent(); |
| 265 controller().OnSelectionEmpty(true); | 267 controller().OnSelectionEmpty(true); |
| 266 ChangeInsertion(insertion_rect, visible); | 268 ChangeInsertion(insertion_rect, visible); |
| 267 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 269 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 268 | 270 |
| 269 // Once the region becomes non-empty, taps should show the insertion handle. | 271 // Once the region becomes non-empty, taps should show the insertion handle. |
| 270 controller().OnTapEvent(); | 272 controller().OnTapEvent(); |
| 271 controller().OnSelectionEmpty(false); | 273 controller().OnSelectionEmpty(false); |
| 272 ChangeInsertion(insertion_rect, visible); | 274 ChangeInsertion(insertion_rect, visible); |
| 273 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 275 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 274 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 276 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 275 | 277 |
| 276 // Reset the selection. | 278 // Reset the selection. |
| 277 controller().HideAndDisallowShowingAutomatically(); | 279 controller().HideAndDisallowShowingAutomatically(); |
| 278 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); | 280 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); |
| 279 | 281 |
| 280 // Long-pressing should show the handle even if the editable region is empty. | 282 // Long-pressing should show the handle even if the editable region is empty. |
| 281 insertion_rect.Offset(2, -2); | 283 insertion_rect.Offset(2, -2); |
| 282 controller().OnLongPressEvent(); | 284 controller().OnLongPressEvent(); |
| 283 controller().OnSelectionEmpty(true); | 285 controller().OnSelectionEmpty(true); |
| 284 ChangeInsertion(insertion_rect, visible); | 286 ChangeInsertion(insertion_rect, visible); |
| 285 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 287 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 286 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 288 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 287 | 289 |
| 288 // Single Tap on an empty edit field should clear insertion handle. | 290 // Single Tap on an empty edit field should clear insertion handle. |
| 289 controller().OnTapEvent(); | 291 controller().OnTapEvent(); |
| 290 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); | 292 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); |
| 291 } | 293 } |
| 292 | 294 |
| 293 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) { | 295 TEST_F(TouchSelectionControllerTest, InsertionWithShowOnTapForEmptyEditable) { |
| 294 AllowShowingOnTapForEmptyEditable(); | 296 AllowShowingOnTapForEmptyEditable(); |
| 295 | 297 |
| 296 gfx::RectF insertion_rect(5, 5, 0, 10); | 298 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 297 bool visible = true; | 299 bool visible = true; |
| 298 controller().OnSelectionEditable(true); | 300 controller().OnSelectionEditable(true); |
| 299 | 301 |
| 300 // Taps on an empty editable region should show the insertion handle if the | 302 // Taps on an empty editable region should show the insertion handle if the |
| 301 // controller is created with |show_on_tap_for_empty_editable| set to true. | 303 // controller is created with |show_on_tap_for_empty_editable| set to true. |
| 302 controller().OnTapEvent(); | 304 controller().OnTapEvent(); |
| 303 controller().OnSelectionEmpty(true); | 305 controller().OnSelectionEmpty(true); |
| 304 ChangeInsertion(insertion_rect, visible); | 306 ChangeInsertion(insertion_rect, visible); |
| 305 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 307 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 306 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 308 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 307 | 309 |
| 308 // Additional taps should not hide the insertion handle in this case. | 310 // Additional taps should not hide the insertion handle in this case. |
| 309 controller().OnTapEvent(); | 311 controller().OnTapEvent(); |
| 310 ChangeInsertion(insertion_rect, visible); | 312 ChangeInsertion(insertion_rect, visible); |
| 311 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 313 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 312 } | 314 } |
| 313 | 315 |
| 314 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { | 316 TEST_F(TouchSelectionControllerTest, InsertionAppearsAfterTapFollowingTyping) { |
| 315 gfx::RectF insertion_rect(5, 5, 0, 10); | 317 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 316 bool visible = true; | 318 bool visible = true; |
| 317 | 319 |
| 318 // Simulate the user tapping an empty text field. | 320 // Simulate the user tapping an empty text field. |
| 319 controller().OnTapEvent(); | 321 controller().OnTapEvent(); |
| 320 controller().OnSelectionEditable(true); | 322 controller().OnSelectionEditable(true); |
| 321 controller().OnSelectionEmpty(true); | 323 controller().OnSelectionEmpty(true); |
| 322 ChangeInsertion(insertion_rect, visible); | 324 ChangeInsertion(insertion_rect, visible); |
| 323 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 325 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 324 | 326 |
| 325 // Simulate the cursor moving while a user is typing. | 327 // Simulate the cursor moving while a user is typing. |
| 326 insertion_rect.Offset(10, 0); | 328 insertion_rect.Offset(10, 0); |
| 327 controller().OnSelectionEmpty(false); | 329 controller().OnSelectionEmpty(false); |
| 328 ChangeInsertion(insertion_rect, visible); | 330 ChangeInsertion(insertion_rect, visible); |
| 329 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 331 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 330 | 332 |
| 331 // If the user taps the *same* position as the cursor at the end of the text | 333 // If the user taps the *same* position as the cursor at the end of the text |
| 332 // entry, the handle should appear. | 334 // entry, the handle should appear. |
| 333 controller().OnTapEvent(); | 335 controller().OnTapEvent(); |
| 334 ChangeInsertion(insertion_rect, visible); | 336 ChangeInsertion(insertion_rect, visible); |
| 335 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 337 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 336 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 338 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 337 } | 339 } |
| 338 | 340 |
| 339 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { | 341 TEST_F(TouchSelectionControllerTest, InsertionToSelectionTransition) { |
| 340 controller().OnLongPressEvent(); | 342 controller().OnLongPressEvent(); |
| 341 controller().OnSelectionEditable(true); | 343 controller().OnSelectionEditable(true); |
| 342 | 344 |
| 343 gfx::RectF start_rect(5, 5, 0, 10); | 345 gfx::RectF start_rect(5, 5, 0, 10); |
| 344 gfx::RectF end_rect(50, 5, 0, 10); | 346 gfx::RectF end_rect(50, 5, 0, 10); |
| 345 bool visible = true; | 347 bool visible = true; |
| 346 | 348 |
| 347 ChangeInsertion(start_rect, visible); | 349 ChangeInsertion(start_rect, visible); |
| 348 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 350 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 349 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 351 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 350 | 352 |
| 351 ChangeSelection(start_rect, visible, end_rect, visible); | 353 ChangeSelection(start_rect, visible, end_rect, visible); |
| 352 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED, | 354 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED, |
| 353 SELECTION_SHOWN)); | 355 SELECTION_SHOWN)); |
| 354 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 356 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 355 | 357 |
| 356 ChangeInsertion(end_rect, visible); | 358 ChangeInsertion(end_rect, visible); |
| 357 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED, | 359 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED, |
| 358 INSERTION_SHOWN)); | 360 INSERTION_SHOWN)); |
| 359 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); | 361 EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart()); |
| 360 | 362 |
| 361 controller().HideAndDisallowShowingAutomatically(); | 363 controller().HideAndDisallowShowingAutomatically(); |
| 362 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); | 364 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_CLEARED)); |
| 363 | 365 |
| 364 controller().OnTapEvent(); | 366 controller().OnTapEvent(); |
| 365 ChangeInsertion(end_rect, visible); | 367 ChangeInsertion(end_rect, visible); |
| 366 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 368 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 367 EXPECT_EQ(end_rect.bottom_left(), GetLastEventAnchor()); | 369 EXPECT_EQ(end_rect.bottom_left(), GetLastEventStart()); |
| 368 } | 370 } |
| 369 | 371 |
| 370 TEST_F(TouchSelectionControllerTest, InsertionDragged) { | 372 TEST_F(TouchSelectionControllerTest, InsertionDragged) { |
| 371 base::TimeTicks event_time = base::TimeTicks::Now(); | 373 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 372 controller().OnTapEvent(); | 374 controller().OnTapEvent(); |
| 373 controller().OnSelectionEditable(true); | 375 controller().OnSelectionEditable(true); |
| 374 | 376 |
| 375 // The touch sequence should not be handled if insertion is not active. | 377 // The touch sequence should not be handled if insertion is not active. |
| 376 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 378 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 377 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 379 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 378 | 380 |
| 379 float line_height = 10.f; | 381 float line_height = 10.f; |
| 380 gfx::RectF start_rect(10, 0, 0, line_height); | 382 gfx::RectF start_rect(10, 0, 0, line_height); |
| 381 bool visible = true; | 383 bool visible = true; |
| 382 ChangeInsertion(start_rect, visible); | 384 ChangeInsertion(start_rect, visible); |
| 383 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 385 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 384 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 386 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 385 | 387 |
| 386 // The touch sequence should be handled only if the drawable reports a hit. | 388 // The touch sequence should be handled only if the drawable reports a hit. |
| 387 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 389 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 388 SetDraggingEnabled(true); | 390 SetDraggingEnabled(true); |
| 389 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 391 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 390 EXPECT_FALSE(GetAndResetCaretMoved()); | 392 EXPECT_FALSE(GetAndResetCaretMoved()); |
| 391 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); | 393 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); |
| 392 | 394 |
| 393 // The MoveCaret() result should reflect the movement. | 395 // The MoveCaret() result should reflect the movement. |
| 394 // The reported position is offset from the center of |start_rect|. | 396 // The reported position is offset from the center of |start_rect|. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { | 495 TEST_F(TouchSelectionControllerTest, InsertionNotResetByRepeatedTapOrPress) { |
| 494 base::TimeTicks event_time = base::TimeTicks::Now(); | 496 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 495 controller().OnTapEvent(); | 497 controller().OnTapEvent(); |
| 496 controller().OnSelectionEditable(true); | 498 controller().OnSelectionEditable(true); |
| 497 SetDraggingEnabled(true); | 499 SetDraggingEnabled(true); |
| 498 | 500 |
| 499 gfx::RectF anchor_rect(10, 0, 0, 10); | 501 gfx::RectF anchor_rect(10, 0, 0, 10); |
| 500 bool visible = true; | 502 bool visible = true; |
| 501 ChangeInsertion(anchor_rect, visible); | 503 ChangeInsertion(anchor_rect, visible); |
| 502 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 504 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 503 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 505 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 504 | 506 |
| 505 // Tapping again shouldn't reset the active insertion point. | 507 // Tapping again shouldn't reset the active insertion point. |
| 506 controller().OnTapEvent(); | 508 controller().OnTapEvent(); |
| 507 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 509 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 508 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 510 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 509 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); | 511 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); |
| 510 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 512 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 511 | 513 |
| 512 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 514 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 513 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 515 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 514 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, | 516 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, |
| 515 INSERTION_DRAG_STOPPED)); | 517 INSERTION_DRAG_STOPPED)); |
| 516 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 518 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 517 | 519 |
| 518 anchor_rect.Offset(5, 15); | 520 anchor_rect.Offset(5, 15); |
| 519 ChangeInsertion(anchor_rect, visible); | 521 ChangeInsertion(anchor_rect, visible); |
| 520 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); | 522 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_MOVED)); |
| 521 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 523 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 522 | 524 |
| 523 // Pressing shouldn't reset the active insertion point. | 525 // Pressing shouldn't reset the active insertion point. |
| 524 controller().OnLongPressEvent(); | 526 controller().OnLongPressEvent(); |
| 525 controller().OnSelectionEmpty(true); | 527 controller().OnSelectionEmpty(true); |
| 526 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 528 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 527 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 529 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 528 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); | 530 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED)); |
| 529 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 531 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 530 | 532 |
| 531 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); | 533 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0); |
| 532 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 534 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 533 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, | 535 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_TAPPED, |
| 534 INSERTION_DRAG_STOPPED)); | 536 INSERTION_DRAG_STOPPED)); |
| 535 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventAnchor()); | 537 EXPECT_EQ(anchor_rect.bottom_left(), GetLastEventStart()); |
| 536 } | 538 } |
| 537 | 539 |
| 538 TEST_F(TouchSelectionControllerTest, SelectionBasic) { | 540 TEST_F(TouchSelectionControllerTest, SelectionBasic) { |
| 539 gfx::RectF start_rect(5, 5, 0, 10); | 541 gfx::RectF start_rect(5, 5, 0, 10); |
| 540 gfx::RectF end_rect(50, 5, 0, 10); | 542 gfx::RectF end_rect(50, 5, 0, 10); |
| 541 bool visible = true; | 543 bool visible = true; |
| 542 | 544 |
| 543 // Selection events are ignored until automatic showing is enabled. | 545 // Selection events are ignored until automatic showing is enabled. |
| 544 ChangeSelection(start_rect, visible, end_rect, visible); | 546 ChangeSelection(start_rect, visible, end_rect, visible); |
| 545 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 547 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 546 | 548 |
| 547 controller().OnLongPressEvent(); | 549 controller().OnLongPressEvent(); |
| 548 ChangeSelection(start_rect, visible, end_rect, visible); | 550 ChangeSelection(start_rect, visible, end_rect, visible); |
| 549 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 551 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 550 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 552 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 551 | 553 |
| 552 start_rect.Offset(1, 0); | 554 start_rect.Offset(1, 0); |
| 553 ChangeSelection(start_rect, visible, end_rect, visible); | 555 ChangeSelection(start_rect, visible, end_rect, visible); |
| 554 // Selection movement does not currently trigger a separate event. | 556 // Selection movement does not currently trigger a separate event. |
| 555 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 557 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
| 558 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 559 EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd()); |
| 556 | 560 |
| 557 ClearSelection(); | 561 ClearSelection(); |
| 558 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); | 562 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); |
| 559 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 563 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 560 } | 564 } |
| 561 | 565 |
| 562 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { | 566 TEST_F(TouchSelectionControllerTest, SelectionRepeatedLongPress) { |
| 563 gfx::RectF start_rect(5, 5, 0, 10); | 567 gfx::RectF start_rect(5, 5, 0, 10); |
| 564 gfx::RectF end_rect(50, 5, 0, 10); | 568 gfx::RectF end_rect(50, 5, 0, 10); |
| 565 bool visible = true; | 569 bool visible = true; |
| 566 | 570 |
| 567 controller().OnLongPressEvent(); | 571 controller().OnLongPressEvent(); |
| 568 ChangeSelection(start_rect, visible, end_rect, visible); | 572 ChangeSelection(start_rect, visible, end_rect, visible); |
| 569 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 573 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 570 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 574 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 575 EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd()); |
| 571 | 576 |
| 572 // A long press triggering a new selection should re-send the SELECTION_SHOWN | 577 // A long press triggering a new selection should re-send the SELECTION_SHOWN |
| 573 // event notification. | 578 // event notification. |
| 574 start_rect.Offset(10, 10); | 579 start_rect.Offset(10, 10); |
| 575 controller().OnLongPressEvent(); | 580 controller().OnLongPressEvent(); |
| 576 ChangeSelection(start_rect, visible, end_rect, visible); | 581 ChangeSelection(start_rect, visible, end_rect, visible); |
| 577 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 582 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 578 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 583 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 584 EXPECT_EQ(end_rect.bottom_left(), GetLastEventEnd()); |
| 579 } | 585 } |
| 580 | 586 |
| 581 TEST_F(TouchSelectionControllerTest, SelectionDragged) { | 587 TEST_F(TouchSelectionControllerTest, SelectionDragged) { |
| 582 base::TimeTicks event_time = base::TimeTicks::Now(); | 588 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 583 controller().OnLongPressEvent(); | 589 controller().OnLongPressEvent(); |
| 584 | 590 |
| 585 // The touch sequence should not be handled if selection is not active. | 591 // The touch sequence should not be handled if selection is not active. |
| 586 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); | 592 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0); |
| 587 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 593 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 588 | 594 |
| 589 float line_height = 10.f; | 595 float line_height = 10.f; |
| 590 gfx::RectF start_rect(0, 0, 0, line_height); | 596 gfx::RectF start_rect(0, 0, 0, line_height); |
| 591 gfx::RectF end_rect(50, 0, 0, line_height); | 597 gfx::RectF end_rect(50, 0, 0, line_height); |
| 592 bool visible = true; | 598 bool visible = true; |
| 593 ChangeSelection(start_rect, visible, end_rect, visible); | 599 ChangeSelection(start_rect, visible, end_rect, visible); |
| 594 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 600 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 595 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 601 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 596 | 602 |
| 597 // The touch sequence should be handled only if the drawable reports a hit. | 603 // The touch sequence should be handled only if the drawable reports a hit. |
| 598 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); | 604 EXPECT_FALSE(controller().WillHandleTouchEvent(event)); |
| 599 SetDraggingEnabled(true); | 605 SetDraggingEnabled(true); |
| 600 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 606 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 601 EXPECT_FALSE(GetAndResetSelectionMoved()); | 607 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 602 | 608 |
| 603 // The SelectBetweenCoordinates() result should reflect the movement. Note | 609 // The SelectBetweenCoordinates() result should reflect the movement. Note |
| 604 // that the start coordinate will always reflect the "fixed" handle's | 610 // that the start coordinate will always reflect the "fixed" handle's |
| 605 // position, in this case the position from |end_rect|. | 611 // position, in this case the position from |end_rect|. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { | 645 TEST_F(TouchSelectionControllerTest, SelectionDraggedWithOverlap) { |
| 640 base::TimeTicks event_time = base::TimeTicks::Now(); | 646 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 641 controller().OnLongPressEvent(); | 647 controller().OnLongPressEvent(); |
| 642 | 648 |
| 643 float line_height = 10.f; | 649 float line_height = 10.f; |
| 644 gfx::RectF start_rect(0, 0, 0, line_height); | 650 gfx::RectF start_rect(0, 0, 0, line_height); |
| 645 gfx::RectF end_rect(50, 0, 0, line_height); | 651 gfx::RectF end_rect(50, 0, 0, line_height); |
| 646 bool visible = true; | 652 bool visible = true; |
| 647 ChangeSelection(start_rect, visible, end_rect, visible); | 653 ChangeSelection(start_rect, visible, end_rect, visible); |
| 648 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 654 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 649 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 655 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 650 | 656 |
| 651 // The ACTION_DOWN should lock to the closest handle. | 657 // The ACTION_DOWN should lock to the closest handle. |
| 652 gfx::PointF end_offset = end_rect.CenterPoint(); | 658 gfx::PointF end_offset = end_rect.CenterPoint(); |
| 653 gfx::PointF fixed_offset = start_rect.CenterPoint(); | 659 gfx::PointF fixed_offset = start_rect.CenterPoint(); |
| 654 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; | 660 float touch_down_x = (end_offset.x() + fixed_offset.x()) / 2 + 1.f; |
| 655 MockMotionEvent event( | 661 MockMotionEvent event( |
| 656 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); | 662 MockMotionEvent::ACTION_DOWN, event_time, touch_down_x, 0); |
| 657 SetDraggingEnabled(true); | 663 SetDraggingEnabled(true); |
| 658 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 664 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 659 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); | 665 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 677 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { | 683 TEST_F(TouchSelectionControllerTest, SelectionDraggedToSwitchBaseAndExtent) { |
| 678 base::TimeTicks event_time = base::TimeTicks::Now(); | 684 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 679 controller().OnLongPressEvent(); | 685 controller().OnLongPressEvent(); |
| 680 | 686 |
| 681 float line_height = 10.f; | 687 float line_height = 10.f; |
| 682 gfx::RectF start_rect(50, line_height, 0, line_height); | 688 gfx::RectF start_rect(50, line_height, 0, line_height); |
| 683 gfx::RectF end_rect(100, line_height, 0, line_height); | 689 gfx::RectF end_rect(100, line_height, 0, line_height); |
| 684 bool visible = true; | 690 bool visible = true; |
| 685 ChangeSelection(start_rect, visible, end_rect, visible); | 691 ChangeSelection(start_rect, visible, end_rect, visible); |
| 686 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 692 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 687 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 693 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 688 | 694 |
| 689 SetDraggingEnabled(true); | 695 SetDraggingEnabled(true); |
| 690 | 696 |
| 691 // Move the extent, not triggering a swap of points. | 697 // Move the extent, not triggering a swap of points. |
| 692 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, | 698 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, |
| 693 end_rect.x(), end_rect.bottom()); | 699 end_rect.x(), end_rect.bottom()); |
| 694 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 700 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 695 EXPECT_FALSE(GetAndResetSelectionMoved()); | 701 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 696 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 702 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 697 | 703 |
| 698 gfx::PointF base_offset = start_rect.CenterPoint(); | 704 gfx::PointF base_offset = start_rect.CenterPoint(); |
| 699 gfx::PointF extent_offset = end_rect.CenterPoint(); | 705 gfx::PointF extent_offset = end_rect.CenterPoint(); |
| 700 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 706 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 701 end_rect.x(), end_rect.bottom() + 5); | 707 end_rect.x(), end_rect.bottom() + 5); |
| 702 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 708 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 703 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); | 709 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| 704 EXPECT_TRUE(GetAndResetSelectionMoved()); | 710 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 705 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 711 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 706 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 712 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 707 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 713 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 708 | 714 |
| 709 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 715 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 710 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 716 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 711 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); | 717 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); |
| 712 EXPECT_FALSE(GetAndResetSelectionMoved()); | 718 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 713 | 719 |
| 714 end_rect += gfx::Vector2dF(0, 5); | 720 end_rect += gfx::Vector2dF(0, 5); |
| 715 ChangeSelection(start_rect, visible, end_rect, visible); | 721 ChangeSelection(start_rect, visible, end_rect, visible); |
| 722 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
| 716 | 723 |
| 717 // Move the base, triggering a swap of points. | 724 // Move the base, triggering a swap of points. |
| 718 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 725 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 719 start_rect.x(), start_rect.bottom()); | 726 start_rect.x(), start_rect.bottom()); |
| 720 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 727 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 721 EXPECT_FALSE(GetAndResetSelectionMoved()); | 728 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 722 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); | 729 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); |
| 723 | 730 |
| 724 base_offset = end_rect.CenterPoint(); | 731 base_offset = end_rect.CenterPoint(); |
| 725 extent_offset = start_rect.CenterPoint(); | 732 extent_offset = start_rect.CenterPoint(); |
| 726 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 733 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 727 start_rect.x(), start_rect.bottom() + 5); | 734 start_rect.x(), start_rect.bottom() + 5); |
| 728 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 735 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 729 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); | 736 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| 730 EXPECT_TRUE(GetAndResetSelectionMoved()); | 737 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 731 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 738 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 732 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 739 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 733 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 740 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 734 | 741 |
| 735 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 742 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 736 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 743 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 737 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); | 744 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); |
| 738 EXPECT_FALSE(GetAndResetSelectionMoved()); | 745 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 739 | 746 |
| 740 start_rect += gfx::Vector2dF(0, 5); | 747 start_rect += gfx::Vector2dF(0, 5); |
| 741 ChangeSelection(start_rect, visible, end_rect, visible); | 748 ChangeSelection(start_rect, visible, end_rect, visible); |
| 749 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
| 742 | 750 |
| 743 // Move the same point again, not triggering a swap of points. | 751 // Move the same point again, not triggering a swap of points. |
| 744 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 752 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 745 start_rect.x(), start_rect.bottom()); | 753 start_rect.x(), start_rect.bottom()); |
| 746 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 754 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 747 EXPECT_FALSE(GetAndResetSelectionMoved()); | 755 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 748 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 756 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 749 | 757 |
| 750 base_offset = end_rect.CenterPoint(); | 758 base_offset = end_rect.CenterPoint(); |
| 751 extent_offset = start_rect.CenterPoint(); | 759 extent_offset = start_rect.CenterPoint(); |
| 752 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, | 760 event = MockMotionEvent(MockMotionEvent::ACTION_MOVE, event_time, |
| 753 start_rect.x(), start_rect.bottom() + 5); | 761 start_rect.x(), start_rect.bottom() + 5); |
| 754 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 762 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 755 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); | 763 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| 756 EXPECT_TRUE(GetAndResetSelectionMoved()); | 764 EXPECT_TRUE(GetAndResetSelectionMoved()); |
| 757 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); | 765 EXPECT_FALSE(GetAndResetSelectionPointsSwapped()); |
| 758 EXPECT_EQ(base_offset, GetLastSelectionStart()); | 766 EXPECT_EQ(base_offset, GetLastSelectionStart()); |
| 759 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); | 767 EXPECT_EQ(extent_offset + gfx::Vector2dF(0, 5), GetLastSelectionEnd()); |
| 760 | 768 |
| 761 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); | 769 event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 10, 5); |
| 762 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 770 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 763 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); | 771 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STOPPED)); |
| 764 EXPECT_FALSE(GetAndResetSelectionMoved()); | 772 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 765 | 773 |
| 766 start_rect += gfx::Vector2dF(0, 5); | 774 start_rect += gfx::Vector2dF(0, 5); |
| 767 ChangeSelection(start_rect, visible, end_rect, visible); | 775 ChangeSelection(start_rect, visible, end_rect, visible); |
| 776 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_MOVED)); |
| 768 | 777 |
| 769 // Move the base, triggering a swap of points. | 778 // Move the base, triggering a swap of points. |
| 770 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, | 779 event = MockMotionEvent(MockMotionEvent::ACTION_DOWN, event_time, |
| 771 end_rect.x(), end_rect.bottom()); | 780 end_rect.x(), end_rect.bottom()); |
| 772 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 781 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 773 EXPECT_FALSE(GetAndResetSelectionMoved()); | 782 EXPECT_FALSE(GetAndResetSelectionMoved()); |
| 774 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); | 783 EXPECT_TRUE(GetAndResetSelectionPointsSwapped()); |
| 775 | 784 |
| 776 base_offset = start_rect.CenterPoint(); | 785 base_offset = start_rect.CenterPoint(); |
| 777 extent_offset = end_rect.CenterPoint(); | 786 extent_offset = end_rect.CenterPoint(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 794 base::TimeTicks event_time = base::TimeTicks::Now(); | 803 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 795 controller().OnLongPressEvent(); | 804 controller().OnLongPressEvent(); |
| 796 | 805 |
| 797 float small_line_height = 1.f; | 806 float small_line_height = 1.f; |
| 798 float large_line_height = 50.f; | 807 float large_line_height = 50.f; |
| 799 gfx::RectF small_line_rect(0, 0, 0, small_line_height); | 808 gfx::RectF small_line_rect(0, 0, 0, small_line_height); |
| 800 gfx::RectF large_line_rect(50, 50, 0, large_line_height); | 809 gfx::RectF large_line_rect(50, 50, 0, large_line_height); |
| 801 bool visible = true; | 810 bool visible = true; |
| 802 ChangeSelection(small_line_rect, visible, large_line_rect, visible); | 811 ChangeSelection(small_line_rect, visible, large_line_rect, visible); |
| 803 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 812 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 804 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventAnchor()); | 813 EXPECT_EQ(small_line_rect.bottom_left(), GetLastEventStart()); |
| 805 | 814 |
| 806 // Start dragging the handle on the small line. | 815 // Start dragging the handle on the small line. |
| 807 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, | 816 MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, |
| 808 small_line_rect.x(), small_line_rect.y()); | 817 small_line_rect.x(), small_line_rect.y()); |
| 809 SetDraggingEnabled(true); | 818 SetDraggingEnabled(true); |
| 810 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); | 819 EXPECT_TRUE(controller().WillHandleTouchEvent(event)); |
| 811 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); | 820 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_DRAG_STARTED)); |
| 812 // The drag coordinate for large lines should be capped to a reasonable | 821 // The drag coordinate for large lines should be capped to a reasonable |
| 813 // offset, allowing seamless transition to neighboring lines with different | 822 // offset, allowing seamless transition to neighboring lines with different |
| 814 // sizes. The drag coordinate for small lines should have an offset | 823 // sizes. The drag coordinate for small lines should have an offset |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 gfx::RectF end_rect(50, 5, 0, 10); | 894 gfx::RectF end_rect(50, 5, 0, 10); |
| 886 bool visible = true; | 895 bool visible = true; |
| 887 | 896 |
| 888 controller().OnLongPressEvent(); | 897 controller().OnLongPressEvent(); |
| 889 ChangeSelection(start_rect, visible, end_rect, visible); | 898 ChangeSelection(start_rect, visible, end_rect, visible); |
| 890 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 899 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 891 | 900 |
| 892 // Selection should not be cleared if the selection bounds have not changed. | 901 // Selection should not be cleared if the selection bounds have not changed. |
| 893 controller().OnTapEvent(); | 902 controller().OnTapEvent(); |
| 894 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 903 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 895 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 904 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 896 | 905 |
| 897 controller().OnTapEvent(); | 906 controller().OnTapEvent(); |
| 898 ClearSelection(); | 907 ClearSelection(); |
| 899 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); | 908 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); |
| 900 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 909 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 901 } | 910 } |
| 902 | 911 |
| 903 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { | 912 TEST_F(TouchSelectionControllerTest, AllowShowingFromCurrentSelection) { |
| 904 gfx::RectF start_rect(5, 5, 0, 10); | 913 gfx::RectF start_rect(5, 5, 0, 10); |
| 905 gfx::RectF end_rect(50, 5, 0, 10); | 914 gfx::RectF end_rect(50, 5, 0, 10); |
| 906 bool visible = true; | 915 bool visible = true; |
| 907 | 916 |
| 908 // The selection should not be activated, as it wasn't yet allowed. | 917 // The selection should not be activated, as it wasn't yet allowed. |
| 909 ChangeSelection(start_rect, visible, end_rect, visible); | 918 ChangeSelection(start_rect, visible, end_rect, visible); |
| 910 EXPECT_EQ(gfx::PointF(), GetLastEventAnchor()); | 919 EXPECT_EQ(gfx::PointF(), GetLastEventStart()); |
| 911 | 920 |
| 912 // Now explicitly allow showing from the previously supplied bounds. | 921 // Now explicitly allow showing from the previously supplied bounds. |
| 913 controller().AllowShowingFromCurrentSelection(); | 922 controller().AllowShowingFromCurrentSelection(); |
| 914 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); | 923 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_SHOWN)); |
| 915 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 924 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 916 | 925 |
| 917 // Repeated calls to show from the current selection should be ignored. | 926 // Repeated calls to show from the current selection should be ignored. |
| 918 controller().AllowShowingFromCurrentSelection(); | 927 controller().AllowShowingFromCurrentSelection(); |
| 919 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 928 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 920 EXPECT_EQ(start_rect.bottom_left(), GetLastEventAnchor()); | 929 EXPECT_EQ(start_rect.bottom_left(), GetLastEventStart()); |
| 921 | 930 |
| 922 // Trying to show from an empty selection will have no result. | 931 // Trying to show from an empty selection will have no result. |
| 923 ClearSelection(); | 932 ClearSelection(); |
| 924 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); | 933 EXPECT_THAT(GetAndResetEvents(), ElementsAre(SELECTION_CLEARED)); |
| 925 controller().AllowShowingFromCurrentSelection(); | 934 controller().AllowShowingFromCurrentSelection(); |
| 926 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); | 935 EXPECT_THAT(GetAndResetEvents(), IsEmpty()); |
| 927 | 936 |
| 928 // Showing the insertion handle should also be supported. | 937 // Showing the insertion handle should also be supported. |
| 929 controller().OnSelectionEditable(true); | 938 controller().OnSelectionEditable(true); |
| 930 controller().OnSelectionEmpty(false); | 939 controller().OnSelectionEmpty(false); |
| 931 controller().HideAndDisallowShowingAutomatically(); | 940 controller().HideAndDisallowShowingAutomatically(); |
| 932 gfx::RectF insertion_rect(5, 5, 0, 10); | 941 gfx::RectF insertion_rect(5, 5, 0, 10); |
| 933 ChangeInsertion(insertion_rect, visible); | 942 ChangeInsertion(insertion_rect, visible); |
| 934 controller().AllowShowingFromCurrentSelection(); | 943 controller().AllowShowingFromCurrentSelection(); |
| 935 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); | 944 EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_SHOWN)); |
| 936 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventAnchor()); | 945 EXPECT_EQ(insertion_rect.bottom_left(), GetLastEventStart()); |
| 937 } | 946 } |
| 938 | 947 |
| 939 } // namespace ui | 948 } // namespace ui |
| OLD | NEW |