Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 647 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); | 647 EXPECT_TRUE(menu->IsEnabledAt(1 /* Separator */)); |
| 648 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); | 648 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(2 /* CUT */)); |
| 649 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); | 649 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(3 /* COPY */)); |
| 650 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), | 650 EXPECT_NE(GetClipboardText(ui::CLIPBOARD_TYPE_COPY_PASTE).empty(), |
| 651 menu->IsEnabledAt(4 /* PASTE */)); | 651 menu->IsEnabledAt(4 /* PASTE */)); |
| 652 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); | 652 EXPECT_EQ(textfield_has_selection, menu->IsEnabledAt(5 /* DELETE */)); |
| 653 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); | 653 EXPECT_TRUE(menu->IsEnabledAt(6 /* Separator */)); |
| 654 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); | 654 EXPECT_TRUE(menu->IsEnabledAt(7 /* SELECT ALL */)); |
| 655 } | 655 } |
| 656 | 656 |
| 657 void PressLeftMouseButton(int extra_flags) { | 657 void PressMouseButton(int mouse_button_flags, int extra_flags) { |
|
tapted
2016/12/19 06:49:16
int -> ui::EventFlags ?
karandeepb
2016/12/19 07:05:43
Done.
| |
| 658 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, | 658 ui::MouseEvent press(ui::ET_MOUSE_PRESSED, mouse_position_, mouse_position_, |
| 659 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 659 ui::EventTimeForNow(), mouse_button_flags, |
| 660 ui::EF_LEFT_MOUSE_BUTTON | extra_flags); | 660 mouse_button_flags | extra_flags); |
| 661 textfield_->OnMousePressed(click); | 661 textfield_->OnMousePressed(press); |
| 662 } | 662 } |
| 663 | 663 |
| 664 void PressLeftMouseButton() { | 664 void ReleaseMouseButton(int mouse_button_flags) { |
|
tapted
2016/12/19 06:49:16
int -> ui::EventFlags
karandeepb
2016/12/19 07:05:43
Done.
| |
| 665 PressLeftMouseButton(0); | 665 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, mouse_position_, |
| 666 mouse_position_, ui::EventTimeForNow(), | |
| 667 mouse_button_flags, mouse_button_flags); | |
| 668 textfield_->OnMouseReleased(release); | |
| 669 } | |
| 670 | |
| 671 void PressLeftMouseButton(int extra_flags = 0) { | |
| 672 PressMouseButton(ui::EF_LEFT_MOUSE_BUTTON, extra_flags); | |
| 666 } | 673 } |
| 667 | 674 |
| 668 void ReleaseLeftMouseButton() { | 675 void ReleaseLeftMouseButton() { |
| 669 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, mouse_position_, | 676 ReleaseMouseButton(ui::EF_LEFT_MOUSE_BUTTON); |
| 670 mouse_position_, ui::EventTimeForNow(), | |
| 671 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | |
| 672 textfield_->OnMouseReleased(release); | |
| 673 } | 677 } |
| 674 | 678 |
| 675 void ClickLeftMouseButton(int extra_flags) { | 679 void ClickLeftMouseButton(int extra_flags = 0) { |
| 676 PressLeftMouseButton(extra_flags); | 680 PressLeftMouseButton(extra_flags); |
| 677 ReleaseLeftMouseButton(); | 681 ReleaseLeftMouseButton(); |
| 678 } | 682 } |
| 679 | 683 |
| 680 void ClickLeftMouseButton() { | 684 void ClickRightMouseButton() { |
| 681 ClickLeftMouseButton(0); | 685 PressMouseButton(ui::EF_RIGHT_MOUSE_BUTTON, 0); |
| 686 ReleaseMouseButton(ui::EF_RIGHT_MOUSE_BUTTON); | |
| 682 } | 687 } |
| 683 | 688 |
| 684 void DragMouseTo(const gfx::Point& where) { | 689 void DragMouseTo(const gfx::Point& where) { |
| 685 mouse_position_ = where; | 690 mouse_position_ = where; |
| 686 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, where, where, | 691 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, where, where, |
| 687 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); | 692 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0); |
| 688 textfield_->OnMouseDragged(drag); | 693 textfield_->OnMouseDragged(drag); |
| 689 } | 694 } |
| 690 | 695 |
| 691 // Textfield does not listen to OnMouseMoved, so this function does not send | 696 // Textfield does not listen to OnMouseMoved, so this function does not send |
| (...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1446 | 1451 |
| 1447 // Test for triple click. | 1452 // Test for triple click. |
| 1448 ClickLeftMouseButton(); | 1453 ClickLeftMouseButton(); |
| 1449 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); | 1454 EXPECT_STR_EQ("hello world", textfield_->GetSelectedText()); |
| 1450 | 1455 |
| 1451 // Another click should reset back to double click. | 1456 // Another click should reset back to double click. |
| 1452 ClickLeftMouseButton(); | 1457 ClickLeftMouseButton(); |
| 1453 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1458 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1454 } | 1459 } |
| 1455 | 1460 |
| 1461 // Tests text selection behavior on a right click. | |
| 1462 TEST_F(TextfieldTest, SelectWordOnRightClick) { | |
| 1463 InitTextfield(); | |
| 1464 textfield_->SetText(ASCIIToUTF16("hello world")); | |
| 1465 | |
| 1466 // Verify right clicking within the selection does not alter the selection. | |
| 1467 textfield_->SelectRange(gfx::Range(1, 5)); | |
| 1468 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); | |
| 1469 MoveMouseTo(gfx::Point(GetCursorPositionX(3), 0)); | |
| 1470 ClickRightMouseButton(); | |
| 1471 EXPECT_STR_EQ("ello", textfield_->GetSelectedText()); | |
| 1472 | |
| 1473 // Verify right clicking outside the selection, selects the word under the | |
| 1474 // cursor on platforms where this is expected. | |
| 1475 MoveMouseTo(gfx::Point(GetCursorPositionX(8), 0)); | |
| 1476 const char* expected_right_click = | |
| 1477 PlatformStyle::kSelectWordOnRightClick ? "world" : "ello"; | |
| 1478 ClickRightMouseButton(); | |
| 1479 EXPECT_STR_EQ(expected_right_click, textfield_->GetSelectedText()); | |
| 1480 } | |
| 1481 | |
| 1456 TEST_F(TextfieldTest, DragToSelect) { | 1482 TEST_F(TextfieldTest, DragToSelect) { |
| 1457 InitTextfield(); | 1483 InitTextfield(); |
| 1458 textfield_->SetText(ASCIIToUTF16("hello world")); | 1484 textfield_->SetText(ASCIIToUTF16("hello world")); |
| 1459 const int kStart = GetCursorPositionX(5); | 1485 const int kStart = GetCursorPositionX(5); |
| 1460 const int kEnd = 500; | 1486 const int kEnd = 500; |
| 1461 gfx::Point start_point(kStart, 0); | 1487 gfx::Point start_point(kStart, 0); |
| 1462 gfx::Point end_point(kEnd, 0); | 1488 gfx::Point end_point(kEnd, 0); |
| 1463 | 1489 |
| 1464 MoveMouseTo(start_point); | 1490 MoveMouseTo(start_point); |
| 1465 PressLeftMouseButton(); | 1491 PressLeftMouseButton(); |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3003 ui::AXNodeData node_data_protected; | 3029 ui::AXNodeData node_data_protected; |
| 3004 node_data_protected.state = 0; | 3030 node_data_protected.state = 0; |
| 3005 textfield_->GetAccessibleNodeData(&node_data_protected); | 3031 textfield_->GetAccessibleNodeData(&node_data_protected); |
| 3006 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3032 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
| 3007 EXPECT_EQ(ASCIIToUTF16("********"), | 3033 EXPECT_EQ(ASCIIToUTF16("********"), |
| 3008 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3034 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
| 3009 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3035 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 3010 } | 3036 } |
| 3011 | 3037 |
| 3012 } // namespace views | 3038 } // namespace views |
| OLD | NEW |