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