| 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 public: | 603 public: |
| 604 explicit TestTouchEditable(aura::Window* window) | 604 explicit TestTouchEditable(aura::Window* window) |
| 605 : window_(window) { | 605 : window_(window) { |
| 606 DCHECK(window); | 606 DCHECK(window); |
| 607 } | 607 } |
| 608 | 608 |
| 609 void set_bounds(const gfx::Rect& bounds) { | 609 void set_bounds(const gfx::Rect& bounds) { |
| 610 bounds_ = bounds; | 610 bounds_ = bounds; |
| 611 } | 611 } |
| 612 | 612 |
| 613 void set_cursor_rect(const gfx::Rect& cursor_rect) { | 613 void set_cursor_rect(const gfx::RectF& cursor_rect) { |
| 614 cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); | 614 cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); |
| 615 cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); | 615 cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); |
| 616 } | 616 } |
| 617 | 617 |
| 618 ~TestTouchEditable() override {} | 618 ~TestTouchEditable() override {} |
| 619 | 619 |
| 620 private: | 620 private: |
| 621 // Overridden from ui::TouchEditable. | 621 // Overridden from ui::TouchEditable. |
| 622 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { | 622 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { |
| 623 NOTREACHED(); | 623 NOTREACHED(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 CreateWidget(); | 682 CreateWidget(); |
| 683 | 683 |
| 684 TestTouchEditable touch_editable(widget_->GetNativeView()); | 684 TestTouchEditable touch_editable(widget_->GetNativeView()); |
| 685 scoped_ptr<ui::TouchEditingControllerDeprecated> touch_selection_controller( | 685 scoped_ptr<ui::TouchEditingControllerDeprecated> touch_selection_controller( |
| 686 ui::TouchEditingControllerDeprecated::Create(&touch_editable)); | 686 ui::TouchEditingControllerDeprecated::Create(&touch_editable)); |
| 687 | 687 |
| 688 touch_editable.set_bounds(gfx::Rect(0, 0, 100, 20)); | 688 touch_editable.set_bounds(gfx::Rect(0, 0, 100, 20)); |
| 689 | 689 |
| 690 // Put the cursor completely inside the client bounds. Handle should be | 690 // Put the cursor completely inside the client bounds. Handle should be |
| 691 // visible. | 691 // visible. |
| 692 touch_editable.set_cursor_rect(gfx::Rect(2, 0, 1, 20)); | 692 touch_editable.set_cursor_rect(gfx::RectF(2.f, 0.f, 1.f, 20.f)); |
| 693 touch_selection_controller->SelectionChanged(); | 693 touch_selection_controller->SelectionChanged(); |
| 694 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); | 694 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); |
| 695 | 695 |
| 696 // Move the cursor up such that |kBarMinHeight| pixels are still in the client | 696 // Move the cursor up such that |kBarMinHeight| pixels are still in the client |
| 697 // bounds. Handle should still be visible. | 697 // bounds. Handle should still be visible. |
| 698 touch_editable.set_cursor_rect(gfx::Rect(2, kBarMinHeight - 20, 1, 20)); | 698 touch_editable.set_cursor_rect( |
| 699 gfx::RectF(2.f, kBarMinHeight - 20.f, 1.f, 20.f)); |
| 699 touch_selection_controller->SelectionChanged(); | 700 touch_selection_controller->SelectionChanged(); |
| 700 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); | 701 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); |
| 701 | 702 |
| 702 // Move the cursor up such that less than |kBarMinHeight| pixels are in the | 703 // Move the cursor up such that less than |kBarMinHeight| pixels are in the |
| 703 // client bounds. Handle should be hidden. | 704 // client bounds. Handle should be hidden. |
| 704 touch_editable.set_cursor_rect(gfx::Rect(2, kBarMinHeight - 20 - 1, 1, 20)); | 705 touch_editable.set_cursor_rect( |
| 706 gfx::RectF(2.f, kBarMinHeight - 20.f - 1.f, 1.f, 20.f)); |
| 705 touch_selection_controller->SelectionChanged(); | 707 touch_selection_controller->SelectionChanged(); |
| 706 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get())); | 708 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get())); |
| 707 | 709 |
| 708 // Move the Cursor down such that |kBarBottomAllowance| pixels are out of the | 710 // Move the Cursor down such that |kBarBottomAllowance| pixels are out of the |
| 709 // client bounds. Handle should be visible. | 711 // client bounds. Handle should be visible. |
| 710 touch_editable.set_cursor_rect(gfx::Rect(2, kBarBottomAllowance, 1, 20)); | 712 touch_editable.set_cursor_rect( |
| 713 gfx::RectF(2.f, kBarBottomAllowance, 1.f, 20.f)); |
| 711 touch_selection_controller->SelectionChanged(); | 714 touch_selection_controller->SelectionChanged(); |
| 712 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); | 715 EXPECT_TRUE(IsCursorHandleVisibleFor(touch_selection_controller.get())); |
| 713 | 716 |
| 714 // Move the cursor down such that more than |kBarBottomAllowance| pixels are | 717 // Move the cursor down such that more than |kBarBottomAllowance| pixels are |
| 715 // out of the client bounds. Handle should be hidden. | 718 // out of the client bounds. Handle should be hidden. |
| 716 touch_editable.set_cursor_rect(gfx::Rect(2, kBarBottomAllowance + 1, 1, 20)); | 719 touch_editable.set_cursor_rect( |
| 720 gfx::RectF(2.f, kBarBottomAllowance + 1.f, 1.f, 20.f)); |
| 717 touch_selection_controller->SelectionChanged(); | 721 touch_selection_controller->SelectionChanged(); |
| 718 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get())); | 722 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get())); |
| 719 | 723 |
| 720 touch_selection_controller.reset(); | 724 touch_selection_controller.reset(); |
| 721 } | 725 } |
| 722 | 726 |
| 723 TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) { | 727 TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) { |
| 724 ui::EventTarget* root = GetContext(); | 728 ui::EventTarget* root = GetContext(); |
| 725 ui::EventTargeter* targeter = root->GetEventTargeter(); | 729 ui::EventTargeter* targeter = root->GetEventTargeter(); |
| 726 | 730 |
| 727 // Create the first window containing a Views::Textfield. | 731 // Create the first window containing a Views::Textfield. |
| 728 CreateTextfield(); | 732 CreateTextfield(); |
| 729 aura::Window* window1 = textfield_widget_->GetNativeView(); | 733 aura::Window* window1 = textfield_widget_->GetNativeView(); |
| 730 | 734 |
| 731 // Start touch editing, check that the handle is above the first window, and | 735 // Start touch editing, check that the handle is above the first window, and |
| 732 // end touch editing. | 736 // end touch editing. |
| 733 StartTouchEditing(); | 737 StartTouchEditing(); |
| 734 gfx::Point test_point = GetCursorHandleDragPoint(); | 738 auto test_point = gfx::PointF(GetCursorHandleDragPoint()); |
| 735 ui::MouseEvent test_event1(ui::ET_MOUSE_MOVED, test_point, test_point, | 739 ui::MouseEvent test_event1(ui::ET_MOUSE_MOVED, test_point, test_point, |
| 736 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); | 740 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE); |
| 737 EXPECT_EQ(GetCursorHandleNativeView(), | 741 EXPECT_EQ(GetCursorHandleNativeView(), |
| 738 targeter->FindTargetForEvent(root, &test_event1)); | 742 targeter->FindTargetForEvent(root, &test_event1)); |
| 739 EndTouchEditing(); | 743 EndTouchEditing(); |
| 740 | 744 |
| 741 // Create the second (empty) window over the first one. | 745 // Create the second (empty) window over the first one. |
| 742 CreateWidget(); | 746 CreateWidget(); |
| 743 aura::Window* window2 = widget_->GetNativeView(); | 747 aura::Window* window2 = widget_->GetNativeView(); |
| 744 | 748 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // Start touch editing; then press a key and ensure it deactivates touch | 815 // Start touch editing; then press a key and ensure it deactivates touch |
| 812 // selection. | 816 // selection. |
| 813 StartTouchEditing(); | 817 StartTouchEditing(); |
| 814 EXPECT_TRUE(GetSelectionController()); | 818 EXPECT_TRUE(GetSelectionController()); |
| 815 generator.PressKey(ui::VKEY_A, 0); | 819 generator.PressKey(ui::VKEY_A, 0); |
| 816 RunPendingMessages(); | 820 RunPendingMessages(); |
| 817 EXPECT_FALSE(GetSelectionController()); | 821 EXPECT_FALSE(GetSelectionController()); |
| 818 } | 822 } |
| 819 | 823 |
| 820 } // namespace views | 824 } // namespace views |
| OLD | NEW |