Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/combobox/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 FocusManager* focus_manager = widget_->GetFocusManager(); | 226 FocusManager* focus_manager = widget_->GetFocusManager(); |
| 227 widget_->OnKeyEvent(&event); | 227 widget_->OnKeyEvent(&event); |
| 228 if (!event.handled() && focus_manager) | 228 if (!event.handled() && focus_manager) |
| 229 focus_manager->OnKeyEvent(event); | 229 focus_manager->OnKeyEvent(event); |
| 230 } | 230 } |
| 231 | 231 |
| 232 View* GetFocusedView() { | 232 View* GetFocusedView() { |
| 233 return widget_->GetFocusManager()->GetFocusedView(); | 233 return widget_->GetFocusManager()->GetFocusedView(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void PerformClick(const gfx::Point& point) { | 236 void PerformMousePress(const gfx::Point& point) { |
| 237 ui::MouseEvent pressed_event = ui::MouseEvent( | 237 ui::MouseEvent pressed_event = ui::MouseEvent( |
| 238 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), | 238 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
| 239 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 239 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 240 widget_->OnMouseEvent(&pressed_event); | 240 widget_->OnMouseEvent(&pressed_event); |
| 241 } | |
| 242 | |
| 243 void PerformMouseRelease(const gfx::Point& point) { | |
| 241 ui::MouseEvent released_event = ui::MouseEvent( | 244 ui::MouseEvent released_event = ui::MouseEvent( |
| 242 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), | 245 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), |
| 243 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 246 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 244 widget_->OnMouseEvent(&released_event); | 247 widget_->OnMouseEvent(&released_event); |
| 245 } | 248 } |
| 246 | 249 |
| 250 void PerformClick(const gfx::Point& point) { | |
| 251 PerformMousePress(point); | |
| 252 PerformMouseRelease(point); | |
| 253 } | |
| 254 | |
| 247 // We need widget to populate wrapper class. | 255 // We need widget to populate wrapper class. |
| 248 Widget* widget_; | 256 Widget* widget_; |
| 249 | 257 |
| 250 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. | 258 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. |
| 251 TestCombobox* combobox_; | 259 TestCombobox* combobox_; |
| 252 std::unique_ptr<ComboboxTestApi> test_api_; | 260 std::unique_ptr<ComboboxTestApi> test_api_; |
| 253 | 261 |
| 254 // Combobox does not take ownership of the model, hence it needs to be scoped. | 262 // Combobox does not take ownership of the model, hence it needs to be scoped. |
| 255 std::unique_ptr<TestComboboxModel> model_; | 263 std::unique_ptr<TestComboboxModel> model_; |
| 256 | 264 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 587 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 580 | 588 |
| 581 TestComboboxListener listener; | 589 TestComboboxListener listener; |
| 582 combobox_->set_listener(&listener); | 590 combobox_->set_listener(&listener); |
| 583 | 591 |
| 584 combobox_->Layout(); | 592 combobox_->Layout(); |
| 585 | 593 |
| 586 // Click the right side (arrow button). The menu is shown. | 594 // Click the right side (arrow button). The menu is shown. |
| 587 int menu_show_count = 0; | 595 int menu_show_count = 0; |
| 588 test_api_->InstallTestMenuRunner(&menu_show_count); | 596 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 597 gfx::Point right_point(combobox_->x() + combobox_->width() - 1, | |
|
tapted
2016/06/29 12:02:55
nit: const gfx::Point right_point
spqchan
2016/06/29 18:29:14
Done.
| |
| 598 combobox_->y() + combobox_->height() / 2); | |
| 599 | |
| 589 EXPECT_EQ(0, menu_show_count); | 600 EXPECT_EQ(0, menu_show_count); |
| 590 PerformClick(gfx::Point(combobox_->x() + combobox_->width() - 1, | 601 |
| 591 combobox_->y() + combobox_->height() / 2)); | 602 // Since the menu appears on a mouse press on Mac, we need to check between |
| 603 // the mouse press and release on that platform. | |
| 604 #if defined(OS_MACOSX) | |
|
tapted
2016/06/29 12:02:55
I'd structure this something like the following. T
spqchan
2016/06/29 18:29:14
Done.
| |
| 605 PerformMousePress(right_point); | |
| 592 EXPECT_FALSE(listener.on_perform_action_called()); | 606 EXPECT_FALSE(listener.on_perform_action_called()); |
| 607 PerformMouseRelease(right_point); | |
| 608 #else | |
| 609 PerformClick(right_point); | |
| 610 EXPECT_FALSE(listener.on_perform_action_called()); | |
| 611 #endif | |
| 612 | |
| 593 EXPECT_EQ(1, menu_show_count); | 613 EXPECT_EQ(1, menu_show_count); |
| 594 | 614 |
| 595 // Click the left side (text button). The click event is notified. | 615 // Click the left side (text button). The click event is notified. |
| 616 gfx::Point left_point( | |
|
tapted
2016/06/29 12:02:55
nit: const
spqchan
2016/06/29 18:29:14
Done.
| |
| 617 gfx::Point(combobox_->x() + 1, combobox_->y() + combobox_->height() / 2)); | |
| 596 test_api_->InstallTestMenuRunner(&menu_show_count); | 618 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 597 PerformClick(gfx::Point(combobox_->x() + 1, | 619 |
| 598 combobox_->y() + combobox_->height() / 2)); | 620 #if defined(OS_MACOSX) |
| 621 PerformMousePress(left_point); | |
| 599 EXPECT_TRUE(listener.on_perform_action_called()); | 622 EXPECT_TRUE(listener.on_perform_action_called()); |
| 623 PerformMouseRelease(left_point); | |
| 624 #else | |
| 625 PerformClick(left_point); | |
| 626 EXPECT_TRUE(listener.on_perform_action_called()); | |
| 627 #endif | |
| 628 | |
| 600 EXPECT_EQ(1, menu_show_count); // Unchanged. | 629 EXPECT_EQ(1, menu_show_count); // Unchanged. |
| 601 EXPECT_EQ(0, listener.perform_action_index()); | 630 EXPECT_EQ(0, listener.perform_action_index()); |
| 602 } | 631 } |
| 603 | 632 |
| 604 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { | 633 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { |
| 605 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 634 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 606 | 635 |
| 607 EXPECT_FALSE(combobox_->OnKeyPressed( | 636 EXPECT_FALSE(combobox_->OnKeyPressed( |
| 608 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 637 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
| 609 EXPECT_FALSE(combobox_->OnKeyPressed( | 638 EXPECT_FALSE(combobox_->OnKeyPressed( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 820 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 792 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 821 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 793 | 822 |
| 794 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 823 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 795 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 824 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 796 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 825 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 797 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 826 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 798 } | 827 } |
| 799 | 828 |
| 800 } // namespace views | 829 } // namespace views |
| OLD | NEW |