OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "ui/aura/client/screen_position_client.h" | 7 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/aura/test/test_cursor_client.h" | 8 #include "ui/aura/test/test_cursor_client.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 const int kMenuButtonWidth = 63; | 40 const int kMenuButtonWidth = 63; |
41 | 41 |
42 // Should match size of kMenuCommands array in touch_editing_menu. | 42 // Should match size of kMenuCommands array in touch_editing_menu. |
43 const int kMenuCommandCount = 3; | 43 const int kMenuCommandCount = 3; |
44 | 44 |
45 // For selection bounds |b1| and |b2| in a paragraph of text, returns -1 if |b1| | 45 // For selection bounds |b1| and |b2| in a paragraph of text, returns -1 if |b1| |
46 // is physically before |b2|, +1 if |b2| is before |b1|, and 0 if they are at | 46 // is physically before |b2|, +1 if |b2| is before |b1|, and 0 if they are at |
47 // the same location. | 47 // the same location. |
48 int CompareTextSelectionBounds(const ui::SelectionBound& b1, | 48 int CompareTextSelectionBounds(const ui::SelectionBound& b1, |
49 const ui::SelectionBound& b2) { | 49 const ui::SelectionBound& b2) { |
50 if ((b1.edge_top.y() < b2.edge_top.y()) || b1.edge_top.x() < b2.edge_top.x()) | 50 if (b1.edge_top().y() < b2.edge_top().y() || |
| 51 b1.edge_top().x() < b2.edge_top().x()) { |
51 return -1; | 52 return -1; |
52 else if (b1 == b2) | 53 } |
| 54 if (b1 == b2) |
53 return 0; | 55 return 0; |
54 else | 56 return 1; |
55 return 1; | |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 namespace views { | 61 namespace views { |
61 | 62 |
62 class TouchSelectionControllerImplTest : public ViewsTestBase { | 63 class TouchSelectionControllerImplTest : public ViewsTestBase { |
63 public: | 64 public: |
64 TouchSelectionControllerImplTest() | 65 TouchSelectionControllerImplTest() |
65 : textfield_widget_(nullptr), | 66 : textfield_widget_(nullptr), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 } else { | 253 } else { |
253 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; | 254 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; |
254 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; | 255 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; |
255 EXPECT_TRUE(IsCursorHandleVisible()); | 256 EXPECT_TRUE(IsCursorHandleVisible()); |
256 gfx::Rect cursor_bounds = GetCursorHandleBounds(); | 257 gfx::Rect cursor_bounds = GetCursorHandleBounds(); |
257 DCHECK(anchor == focus); | 258 DCHECK(anchor == focus); |
258 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; | 259 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; |
259 } | 260 } |
260 if (check_direction) { | 261 if (check_direction) { |
261 if (CompareTextSelectionBounds(anchor, focus) < 0) { | 262 if (CompareTextSelectionBounds(anchor, focus) < 0) { |
262 EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type) << from_str; | 263 EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type()) << from_str; |
263 EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type) << from_str; | 264 EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type()) << from_str; |
264 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { | 265 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { |
265 EXPECT_EQ(ui::SelectionBound::LEFT, focus.type) << from_str; | 266 EXPECT_EQ(ui::SelectionBound::LEFT, focus.type()) << from_str; |
266 EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type) << from_str; | 267 EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type()) << from_str; |
267 } else { | 268 } else { |
268 EXPECT_EQ(ui::SelectionBound::CENTER, focus.type) << from_str; | 269 EXPECT_EQ(ui::SelectionBound::CENTER, focus.type()) << from_str; |
269 EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type) << from_str; | 270 EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type()) << from_str; |
270 } | 271 } |
271 } | 272 } |
272 } | 273 } |
273 | 274 |
274 Widget* textfield_widget_; | 275 Widget* textfield_widget_; |
275 Widget* widget_; | 276 Widget* widget_; |
276 | 277 |
277 Textfield* textfield_; | 278 Textfield* textfield_; |
278 scoped_ptr<TextfieldTestApi> textfield_test_api_; | 279 scoped_ptr<TextfieldTestApi> textfield_test_api_; |
279 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; | 280 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 explicit TestTouchEditable(aura::Window* window) | 618 explicit TestTouchEditable(aura::Window* window) |
618 : window_(window) { | 619 : window_(window) { |
619 DCHECK(window); | 620 DCHECK(window); |
620 } | 621 } |
621 | 622 |
622 void set_bounds(const gfx::Rect& bounds) { | 623 void set_bounds(const gfx::Rect& bounds) { |
623 bounds_ = bounds; | 624 bounds_ = bounds; |
624 } | 625 } |
625 | 626 |
626 void set_cursor_rect(const gfx::Rect& cursor_rect) { | 627 void set_cursor_rect(const gfx::Rect& cursor_rect) { |
627 cursor_bound_.edge_top = cursor_rect.origin(); | 628 cursor_bound_.SetEdgeTop(cursor_rect.origin()); |
628 cursor_bound_.edge_bottom = cursor_rect.bottom_left(); | 629 cursor_bound_.SetEdgeBottom(cursor_rect.bottom_left()); |
629 cursor_bound_.type = ui::SelectionBound::Type::CENTER; | 630 cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); |
630 } | 631 } |
631 | 632 |
632 ~TestTouchEditable() override {} | 633 ~TestTouchEditable() override {} |
633 | 634 |
634 private: | 635 private: |
635 // Overridden from ui::TouchEditable. | 636 // Overridden from ui::TouchEditable. |
636 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { | 637 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { |
637 NOTREACHED(); | 638 NOTREACHED(); |
638 } | 639 } |
639 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } | 640 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 // Start touch editing; then press a key and ensure it deactivates touch | 889 // Start touch editing; then press a key and ensure it deactivates touch |
889 // selection. | 890 // selection. |
890 StartTouchEditing(); | 891 StartTouchEditing(); |
891 EXPECT_TRUE(GetSelectionController()); | 892 EXPECT_TRUE(GetSelectionController()); |
892 generator.PressKey(ui::VKEY_A, 0); | 893 generator.PressKey(ui::VKEY_A, 0); |
893 RunPendingMessages(); | 894 RunPendingMessages(); |
894 EXPECT_FALSE(GetSelectionController()); | 895 EXPECT_FALSE(GetSelectionController()); |
895 } | 896 } |
896 | 897 |
897 } // namespace views | 898 } // namespace views |
OLD | NEW |