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 28 matching lines...) Expand all Loading... |
39 const int kMenuButtonWidth = 63; | 39 const int kMenuButtonWidth = 63; |
40 | 40 |
41 // Should match size of kMenuCommands array in touch_editing_menu. | 41 // Should match size of kMenuCommands array in touch_editing_menu. |
42 const int kMenuCommandCount = 3; | 42 const int kMenuCommandCount = 3; |
43 | 43 |
44 // For selection bounds |b1| and |b2| in a paragraph of text, returns -1 if |b1| | 44 // For selection bounds |b1| and |b2| in a paragraph of text, returns -1 if |b1| |
45 // is physically before |b2|, +1 if |b2| is before |b1|, and 0 if they are at | 45 // is physically before |b2|, +1 if |b2| is before |b1|, and 0 if they are at |
46 // the same location. | 46 // the same location. |
47 int CompareTextSelectionBounds(const ui::SelectionBound& b1, | 47 int CompareTextSelectionBounds(const ui::SelectionBound& b1, |
48 const ui::SelectionBound& b2) { | 48 const ui::SelectionBound& b2) { |
49 if ((b1.edge_top.y() < b2.edge_top.y()) || b1.edge_top.x() < b2.edge_top.x()) | 49 if (b1.edge_top().y() < b2.edge_top().y() || |
| 50 b1.edge_top().x() < b2.edge_top().x()) { |
50 return -1; | 51 return -1; |
51 else if (b1 == b2) | 52 } |
| 53 if (b1 == b2) |
52 return 0; | 54 return 0; |
53 else | 55 return 1; |
54 return 1; | |
55 } | 56 } |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 namespace views { | 60 namespace views { |
60 | 61 |
61 class TouchSelectionControllerImplTest : public ViewsTestBase { | 62 class TouchSelectionControllerImplTest : public ViewsTestBase { |
62 public: | 63 public: |
63 TouchSelectionControllerImplTest() | 64 TouchSelectionControllerImplTest() |
64 : textfield_widget_(nullptr), | 65 : textfield_widget_(nullptr), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } else { | 252 } else { |
252 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; | 253 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; |
253 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; | 254 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; |
254 EXPECT_TRUE(IsCursorHandleVisible()); | 255 EXPECT_TRUE(IsCursorHandleVisible()); |
255 gfx::Rect cursor_bounds = GetCursorHandleBounds(); | 256 gfx::Rect cursor_bounds = GetCursorHandleBounds(); |
256 DCHECK(anchor == focus); | 257 DCHECK(anchor == focus); |
257 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; | 258 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; |
258 } | 259 } |
259 if (check_direction) { | 260 if (check_direction) { |
260 if (CompareTextSelectionBounds(anchor, focus) < 0) { | 261 if (CompareTextSelectionBounds(anchor, focus) < 0) { |
261 EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type) << from_str; | 262 EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type()) << from_str; |
262 EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type) << from_str; | 263 EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type()) << from_str; |
263 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { | 264 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { |
264 EXPECT_EQ(ui::SelectionBound::LEFT, focus.type) << from_str; | 265 EXPECT_EQ(ui::SelectionBound::LEFT, focus.type()) << from_str; |
265 EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type) << from_str; | 266 EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type()) << from_str; |
266 } else { | 267 } else { |
267 EXPECT_EQ(ui::SelectionBound::CENTER, focus.type) << from_str; | 268 EXPECT_EQ(ui::SelectionBound::CENTER, focus.type()) << from_str; |
268 EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type) << from_str; | 269 EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type()) << from_str; |
269 } | 270 } |
270 } | 271 } |
271 } | 272 } |
272 | 273 |
273 Widget* textfield_widget_; | 274 Widget* textfield_widget_; |
274 Widget* widget_; | 275 Widget* widget_; |
275 | 276 |
276 Textfield* textfield_; | 277 Textfield* textfield_; |
277 scoped_ptr<TextfieldTestApi> textfield_test_api_; | 278 scoped_ptr<TextfieldTestApi> textfield_test_api_; |
278 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; | 279 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 explicit TestTouchEditable(aura::Window* window) | 607 explicit TestTouchEditable(aura::Window* window) |
607 : window_(window) { | 608 : window_(window) { |
608 DCHECK(window); | 609 DCHECK(window); |
609 } | 610 } |
610 | 611 |
611 void set_bounds(const gfx::Rect& bounds) { | 612 void set_bounds(const gfx::Rect& bounds) { |
612 bounds_ = bounds; | 613 bounds_ = bounds; |
613 } | 614 } |
614 | 615 |
615 void set_cursor_rect(const gfx::Rect& cursor_rect) { | 616 void set_cursor_rect(const gfx::Rect& cursor_rect) { |
616 cursor_bound_.edge_top = cursor_rect.origin(); | 617 cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); |
617 cursor_bound_.edge_bottom = cursor_rect.bottom_left(); | 618 cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); |
618 cursor_bound_.type = ui::SelectionBound::Type::CENTER; | |
619 } | 619 } |
620 | 620 |
621 ~TestTouchEditable() override {} | 621 ~TestTouchEditable() override {} |
622 | 622 |
623 private: | 623 private: |
624 // Overridden from ui::TouchEditable. | 624 // Overridden from ui::TouchEditable. |
625 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { | 625 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { |
626 NOTREACHED(); | 626 NOTREACHED(); |
627 } | 627 } |
628 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } | 628 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 // Start touch editing; then press a key and ensure it deactivates touch | 877 // Start touch editing; then press a key and ensure it deactivates touch |
878 // selection. | 878 // selection. |
879 StartTouchEditing(); | 879 StartTouchEditing(); |
880 EXPECT_TRUE(GetSelectionController()); | 880 EXPECT_TRUE(GetSelectionController()); |
881 generator.PressKey(ui::VKEY_A, 0); | 881 generator.PressKey(ui::VKEY_A, 0); |
882 RunPendingMessages(); | 882 RunPendingMessages(); |
883 EXPECT_FALSE(GetSelectionController()); | 883 EXPECT_FALSE(GetSelectionController()); |
884 } | 884 } |
885 | 885 |
886 } // namespace views | 886 } // namespace views |
OLD | NEW |