| 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 const gfx::Point right_point(combobox_->x() + combobox_->width() - 1, |
| 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 // On Mac, actions occur on mouse down. Otherwise mouse up. |
| 592 EXPECT_FALSE(listener.on_perform_action_called()); | 603 #if defined(OS_MACOSX) |
| 604 const int kActOnMouseDown = 1; |
| 605 #else |
| 606 const int kActOnMouseDown = 0; |
| 607 #endif |
| 608 |
| 609 PerformMousePress(right_point); |
| 610 EXPECT_EQ(kActOnMouseDown, menu_show_count); |
| 611 PerformMouseRelease(right_point); |
| 593 EXPECT_EQ(1, menu_show_count); | 612 EXPECT_EQ(1, menu_show_count); |
| 594 | 613 |
| 595 // Click the left side (text button). The click event is notified. | 614 // Click the left side (text button). The click event is notified. |
| 615 const gfx::Point left_point( |
| 616 gfx::Point(combobox_->x() + 1, combobox_->y() + combobox_->height() / 2)); |
| 596 test_api_->InstallTestMenuRunner(&menu_show_count); | 617 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 597 PerformClick(gfx::Point(combobox_->x() + 1, | 618 |
| 598 combobox_->y() + combobox_->height() / 2)); | 619 PerformMousePress(left_point); |
| 599 EXPECT_TRUE(listener.on_perform_action_called()); | 620 PerformMouseRelease(left_point); |
| 621 |
| 600 EXPECT_EQ(1, menu_show_count); // Unchanged. | 622 EXPECT_EQ(1, menu_show_count); // Unchanged. |
| 601 EXPECT_EQ(0, listener.perform_action_index()); | 623 EXPECT_EQ(0, listener.perform_action_index()); |
| 602 } | 624 } |
| 603 | 625 |
| 604 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { | 626 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { |
| 605 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 627 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 606 | 628 |
| 607 EXPECT_FALSE(combobox_->OnKeyPressed( | 629 EXPECT_FALSE(combobox_->OnKeyPressed( |
| 608 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 630 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
| 609 EXPECT_FALSE(combobox_->OnKeyPressed( | 631 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)); | 813 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 792 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 814 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 793 | 815 |
| 794 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 816 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 795 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 817 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 796 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 818 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 797 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 819 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 798 } | 820 } |
| 799 | 821 |
| 800 } // namespace views | 822 } // namespace views |
| OLD | NEW |