| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // Should match kSelectionHandleBarMinHeight in touch_selection_controller. | 37 // Should match kSelectionHandleBarMinHeight in touch_selection_controller. |
| 38 const int kBarMinHeight = 5; | 38 const int kBarMinHeight = 5; |
| 39 | 39 |
| 40 // Should match kSelectionHandleBarBottomAllowance in | 40 // Should match kSelectionHandleBarBottomAllowance in |
| 41 // touch_selection_controller. | 41 // touch_selection_controller. |
| 42 const int kBarBottomAllowance = 3; | 42 const int kBarBottomAllowance = 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 gfx::SelectionBound& b1, |
| 48 const ui::SelectionBound& b2) { | 48 const gfx::SelectionBound& b2) { |
| 49 if (b1.edge_top().y() < b2.edge_top().y() || | 49 if (b1.edge_top().y() < b2.edge_top().y() || |
| 50 b1.edge_top().x() < b2.edge_top().x()) { | 50 b1.edge_top().x() < b2.edge_top().x()) { |
| 51 return -1; | 51 return -1; |
| 52 } | 52 } |
| 53 if (b1 == b2) | 53 if (b1 == b2) |
| 54 return 0; | 54 return 0; |
| 55 return 1; | 55 return 1; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 grip_location.x(), grip_location.y(), 0, time_stamp, details); | 174 grip_location.x(), grip_location.y(), 0, time_stamp, details); |
| 175 handle->OnGestureEvent(&scroll_end); | 175 handle->OnGestureEvent(&scroll_end); |
| 176 } | 176 } |
| 177 test_cursor_client_->EnableMouseEvents(); | 177 test_cursor_client_->EnableMouseEvents(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 gfx::NativeView GetCursorHandleNativeView() { | 180 gfx::NativeView GetCursorHandleNativeView() { |
| 181 return GetSelectionController()->GetCursorHandleNativeView(); | 181 return GetSelectionController()->GetCursorHandleNativeView(); |
| 182 } | 182 } |
| 183 | 183 |
| 184 ui::SelectionBound::Type GetSelectionHandle1Type() { | 184 gfx::SelectionBound::Type GetSelectionHandle1Type() { |
| 185 return GetSelectionController()->GetSelectionHandle1Type(); | 185 return GetSelectionController()->GetSelectionHandle1Type(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 gfx::Rect GetSelectionHandle1Bounds() { | 188 gfx::Rect GetSelectionHandle1Bounds() { |
| 189 return GetSelectionController()->GetSelectionHandle1Bounds(); | 189 return GetSelectionController()->GetSelectionHandle1Bounds(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 gfx::Rect GetSelectionHandle2Bounds() { | 192 gfx::Rect GetSelectionHandle2Bounds() { |
| 193 return GetSelectionController()->GetSelectionHandle2Bounds(); | 193 return GetSelectionController()->GetSelectionHandle2Bounds(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 gfx::Rect GetCursorHandleBounds() { | 196 gfx::Rect GetCursorHandleBounds() { |
| 197 return GetSelectionController()->GetCursorHandleBounds(); | 197 return GetSelectionController()->GetCursorHandleBounds(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 gfx::Rect GetExpectedHandleBounds(const ui::SelectionBound& bound) { | 200 gfx::Rect GetExpectedHandleBounds(const gfx::SelectionBound& bound) { |
| 201 return GetSelectionController()->GetExpectedHandleBounds(bound); | 201 return GetSelectionController()->GetExpectedHandleBounds(bound); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool IsSelectionHandle1Visible() { | 204 bool IsSelectionHandle1Visible() { |
| 205 return GetSelectionController()->IsSelectionHandle1Visible(); | 205 return GetSelectionController()->IsSelectionHandle1Visible(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool IsSelectionHandle2Visible() { | 208 bool IsSelectionHandle2Visible() { |
| 209 return GetSelectionController()->IsSelectionHandle2Visible(); | 209 return GetSelectionController()->IsSelectionHandle2Visible(); |
| 210 } | 210 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 228 | 228 |
| 229 // If textfield has selection, this verifies that the selection handles | 229 // If textfield has selection, this verifies that the selection handles |
| 230 // are visible, at the correct positions (at the end points of selection), and | 230 // are visible, at the correct positions (at the end points of selection), and |
| 231 // (if |check_direction| is set to true), that they have the correct | 231 // (if |check_direction| is set to true), that they have the correct |
| 232 // directionality. | 232 // directionality. |
| 233 // |cursor_at_selection_handle_1| is used to decide whether selection | 233 // |cursor_at_selection_handle_1| is used to decide whether selection |
| 234 // handle 1's position is matched against the start of selection or the end. | 234 // handle 1's position is matched against the start of selection or the end. |
| 235 void VerifyHandlePositions(bool cursor_at_selection_handle_1, | 235 void VerifyHandlePositions(bool cursor_at_selection_handle_1, |
| 236 bool check_direction, | 236 bool check_direction, |
| 237 const tracked_objects::Location& from_here) { | 237 const tracked_objects::Location& from_here) { |
| 238 ui::SelectionBound anchor, focus; | 238 gfx::SelectionBound anchor, focus; |
| 239 textfield_->GetSelectionEndPoints(&anchor, &focus); | 239 textfield_->GetSelectionEndPoints(&anchor, &focus); |
| 240 std::string from_str = from_here.ToString(); | 240 std::string from_str = from_here.ToString(); |
| 241 if (textfield_->HasSelection()) { | 241 if (textfield_->HasSelection()) { |
| 242 EXPECT_TRUE(IsSelectionHandle1Visible()) << from_str; | 242 EXPECT_TRUE(IsSelectionHandle1Visible()) << from_str; |
| 243 EXPECT_TRUE(IsSelectionHandle2Visible()) << from_str; | 243 EXPECT_TRUE(IsSelectionHandle2Visible()) << from_str; |
| 244 EXPECT_FALSE(IsCursorHandleVisible()); | 244 EXPECT_FALSE(IsCursorHandleVisible()); |
| 245 gfx::Rect sh1_bounds = GetSelectionHandle1Bounds(); | 245 gfx::Rect sh1_bounds = GetSelectionHandle1Bounds(); |
| 246 gfx::Rect sh2_bounds = GetSelectionHandle2Bounds(); | 246 gfx::Rect sh2_bounds = GetSelectionHandle2Bounds(); |
| 247 if (cursor_at_selection_handle_1) { | 247 if (cursor_at_selection_handle_1) { |
| 248 EXPECT_EQ(sh1_bounds, GetExpectedHandleBounds(focus)) << from_str; | 248 EXPECT_EQ(sh1_bounds, GetExpectedHandleBounds(focus)) << from_str; |
| 249 EXPECT_EQ(sh2_bounds, GetExpectedHandleBounds(anchor)) << from_str; | 249 EXPECT_EQ(sh2_bounds, GetExpectedHandleBounds(anchor)) << from_str; |
| 250 } else { | 250 } else { |
| 251 EXPECT_EQ(sh1_bounds, GetExpectedHandleBounds(anchor)) << from_str; | 251 EXPECT_EQ(sh1_bounds, GetExpectedHandleBounds(anchor)) << from_str; |
| 252 EXPECT_EQ(sh2_bounds, GetExpectedHandleBounds(focus)) << from_str; | 252 EXPECT_EQ(sh2_bounds, GetExpectedHandleBounds(focus)) << from_str; |
| 253 } | 253 } |
| 254 } else { | 254 } else { |
| 255 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; | 255 EXPECT_FALSE(IsSelectionHandle1Visible()) << from_str; |
| 256 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; | 256 EXPECT_FALSE(IsSelectionHandle2Visible()) << from_str; |
| 257 EXPECT_TRUE(IsCursorHandleVisible()); | 257 EXPECT_TRUE(IsCursorHandleVisible()); |
| 258 gfx::Rect cursor_bounds = GetCursorHandleBounds(); | 258 gfx::Rect cursor_bounds = GetCursorHandleBounds(); |
| 259 DCHECK(anchor == focus); | 259 DCHECK(anchor == focus); |
| 260 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; | 260 EXPECT_EQ(cursor_bounds, GetExpectedHandleBounds(anchor)) << from_str; |
| 261 } | 261 } |
| 262 if (check_direction) { | 262 if (check_direction) { |
| 263 if (CompareTextSelectionBounds(anchor, focus) < 0) { | 263 if (CompareTextSelectionBounds(anchor, focus) < 0) { |
| 264 EXPECT_EQ(ui::SelectionBound::LEFT, anchor.type()) << from_str; | 264 EXPECT_EQ(gfx::SelectionBound::LEFT, anchor.type()) << from_str; |
| 265 EXPECT_EQ(ui::SelectionBound::RIGHT, focus.type()) << from_str; | 265 EXPECT_EQ(gfx::SelectionBound::RIGHT, focus.type()) << from_str; |
| 266 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { | 266 } else if (CompareTextSelectionBounds(anchor, focus) > 0) { |
| 267 EXPECT_EQ(ui::SelectionBound::LEFT, focus.type()) << from_str; | 267 EXPECT_EQ(gfx::SelectionBound::LEFT, focus.type()) << from_str; |
| 268 EXPECT_EQ(ui::SelectionBound::RIGHT, anchor.type()) << from_str; | 268 EXPECT_EQ(gfx::SelectionBound::RIGHT, anchor.type()) << from_str; |
| 269 } else { | 269 } else { |
| 270 EXPECT_EQ(ui::SelectionBound::CENTER, focus.type()) << from_str; | 270 EXPECT_EQ(gfx::SelectionBound::CENTER, focus.type()) << from_str; |
| 271 EXPECT_EQ(ui::SelectionBound::CENTER, anchor.type()) << from_str; | 271 EXPECT_EQ(gfx::SelectionBound::CENTER, anchor.type()) << from_str; |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Sets up a textfield with a long text string such that it doesn't all fit | 276 // Sets up a textfield with a long text string such that it doesn't all fit |
| 277 // into the textfield. Then selects the text - the first handle is expected | 277 // into the textfield. Then selects the text - the first handle is expected |
| 278 // to be invisible. |selection_start| is the position of the first handle. | 278 // to be invisible. |selection_start| is the position of the first handle. |
| 279 void SetupSelectionInvisibleHandle(uint32_t selection_start) { | 279 void SetupSelectionInvisibleHandle(uint32_t selection_start) { |
| 280 // Create a textfield with lots of text in it. | 280 // Create a textfield with lots of text in it. |
| 281 CreateTextfield(); | 281 CreateTextfield(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 SetupSelectionInvisibleHandle(selection_start); | 596 SetupSelectionInvisibleHandle(selection_start); |
| 597 | 597 |
| 598 // Drag the handle until the selection shrinks such that the other handle | 598 // Drag the handle until the selection shrinks such that the other handle |
| 599 // becomes visible. | 599 // becomes visible. |
| 600 while (!IsSelectionHandle1Visible()) { | 600 while (!IsSelectionHandle1Visible()) { |
| 601 static const int drag_diff = -10; | 601 static const int drag_diff = -10; |
| 602 SimulateSelectionHandleDrag(gfx::Vector2d(drag_diff, 0), 2); | 602 SimulateSelectionHandleDrag(gfx::Vector2d(drag_diff, 0), 2); |
| 603 } | 603 } |
| 604 | 604 |
| 605 // Confirm that the exposed handle maintains the LEFT orientation | 605 // Confirm that the exposed handle maintains the LEFT orientation |
| 606 // (and does not reset to ui::SelectionBound::Type::CENTER). | 606 // (and does not reset to gfx::SelectionBound::Type::CENTER). |
| 607 EXPECT_EQ(ui::SelectionBound::Type::LEFT, GetSelectionHandle1Type()); | 607 EXPECT_EQ(gfx::SelectionBound::Type::LEFT, GetSelectionHandle1Type()); |
| 608 } | 608 } |
| 609 | 609 |
| 610 TEST_F(TouchSelectionControllerImplTest, | 610 TEST_F(TouchSelectionControllerImplTest, |
| 611 DoubleTapInTextfieldWithCursorHandleShouldSelectText) { | 611 DoubleTapInTextfieldWithCursorHandleShouldSelectText) { |
| 612 CreateTextfield(); | 612 CreateTextfield(); |
| 613 textfield_->SetText(ASCIIToUTF16("some text")); | 613 textfield_->SetText(ASCIIToUTF16("some text")); |
| 614 ui::test::EventGenerator generator( | 614 ui::test::EventGenerator generator( |
| 615 textfield_->GetWidget()->GetNativeView()->GetRootWindow()); | 615 textfield_->GetWidget()->GetNativeView()->GetRootWindow()); |
| 616 | 616 |
| 617 // Tap the textfield to invoke touch selection. | 617 // Tap the textfield to invoke touch selection. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 639 : window_(window) { | 639 : window_(window) { |
| 640 DCHECK(window); | 640 DCHECK(window); |
| 641 } | 641 } |
| 642 | 642 |
| 643 void set_bounds(const gfx::Rect& bounds) { | 643 void set_bounds(const gfx::Rect& bounds) { |
| 644 bounds_ = bounds; | 644 bounds_ = bounds; |
| 645 } | 645 } |
| 646 | 646 |
| 647 void set_cursor_rect(const gfx::RectF& cursor_rect) { | 647 void set_cursor_rect(const gfx::RectF& cursor_rect) { |
| 648 cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); | 648 cursor_bound_.SetEdge(cursor_rect.origin(), cursor_rect.bottom_left()); |
| 649 cursor_bound_.set_type(ui::SelectionBound::Type::CENTER); | 649 cursor_bound_.set_type(gfx::SelectionBound::Type::CENTER); |
| 650 } | 650 } |
| 651 | 651 |
| 652 ~TestTouchEditable() override {} | 652 ~TestTouchEditable() override {} |
| 653 | 653 |
| 654 private: | 654 private: |
| 655 // Overridden from ui::TouchEditable. | 655 // Overridden from ui::TouchEditable. |
| 656 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { | 656 void SelectRect(const gfx::Point& start, const gfx::Point& end) override { |
| 657 NOTREACHED(); | 657 NOTREACHED(); |
| 658 } | 658 } |
| 659 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } | 659 void MoveCaretTo(const gfx::Point& point) override { NOTREACHED(); } |
| 660 void GetSelectionEndPoints(ui::SelectionBound* anchor, | 660 void GetSelectionEndPoints(gfx::SelectionBound* anchor, |
| 661 ui::SelectionBound* focus) override { | 661 gfx::SelectionBound* focus) override { |
| 662 *anchor = *focus = cursor_bound_; | 662 *anchor = *focus = cursor_bound_; |
| 663 } | 663 } |
| 664 gfx::Rect GetBounds() override { return gfx::Rect(bounds_.size()); } | 664 gfx::Rect GetBounds() override { return gfx::Rect(bounds_.size()); } |
| 665 gfx::NativeView GetNativeView() const override { return window_; } | 665 gfx::NativeView GetNativeView() const override { return window_; } |
| 666 void ConvertPointToScreen(gfx::Point* point) override { | 666 void ConvertPointToScreen(gfx::Point* point) override { |
| 667 aura::client::ScreenPositionClient* screen_position_client = | 667 aura::client::ScreenPositionClient* screen_position_client = |
| 668 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | 668 aura::client::GetScreenPositionClient(window_->GetRootWindow()); |
| 669 if (screen_position_client) | 669 if (screen_position_client) |
| 670 screen_position_client->ConvertPointToScreen(window_, point); | 670 screen_position_client->ConvertPointToScreen(window_, point); |
| 671 } | 671 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 697 NOTREACHED(); | 697 NOTREACHED(); |
| 698 } | 698 } |
| 699 | 699 |
| 700 aura::Window* window_; | 700 aura::Window* window_; |
| 701 | 701 |
| 702 // Boundaries of the client view. | 702 // Boundaries of the client view. |
| 703 gfx::Rect bounds_; | 703 gfx::Rect bounds_; |
| 704 | 704 |
| 705 // Cursor position inside the client view. | 705 // Cursor position inside the client view. |
| 706 //gfx::Rect cursor_rect_; | 706 //gfx::Rect cursor_rect_; |
| 707 ui::SelectionBound cursor_bound_; | 707 gfx::SelectionBound cursor_bound_; |
| 708 | 708 |
| 709 DISALLOW_COPY_AND_ASSIGN(TestTouchEditable); | 709 DISALLOW_COPY_AND_ASSIGN(TestTouchEditable); |
| 710 }; | 710 }; |
| 711 | 711 |
| 712 // Tests if the touch editing handle is shown or hidden properly according to | 712 // Tests if the touch editing handle is shown or hidden properly according to |
| 713 // the cursor position relative to the client boundaries. | 713 // the cursor position relative to the client boundaries. |
| 714 TEST_F(TouchSelectionControllerImplTest, | 714 TEST_F(TouchSelectionControllerImplTest, |
| 715 VisibilityOfHandleRegardingClientBounds) { | 715 VisibilityOfHandleRegardingClientBounds) { |
| 716 CreateWidget(); | 716 CreateWidget(); |
| 717 | 717 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 // Start touch editing; then press a key and ensure it deactivates touch | 869 // Start touch editing; then press a key and ensure it deactivates touch |
| 870 // selection. | 870 // selection. |
| 871 StartTouchEditing(); | 871 StartTouchEditing(); |
| 872 EXPECT_TRUE(GetSelectionController()); | 872 EXPECT_TRUE(GetSelectionController()); |
| 873 generator.PressKey(ui::VKEY_A, 0); | 873 generator.PressKey(ui::VKEY_A, 0); |
| 874 RunPendingMessages(); | 874 RunPendingMessages(); |
| 875 EXPECT_FALSE(GetSelectionController()); | 875 EXPECT_FALSE(GetSelectionController()); |
| 876 } | 876 } |
| 877 | 877 |
| 878 } // namespace views | 878 } // namespace views |
| OLD | NEW |