Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "ui/aura/client/focus_client.h" | |
| 13 #include "ui/aura/env.h" | |
| 14 #include "ui/aura/window.h" | |
| 15 #include "ui/aura/window_tree_host.h" | |
| 16 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/ui_base_paths.h" | 13 #include "ui/base/ui_base_paths.h" |
| 18 #include "ui/base/ui_base_switches.h" | 14 #include "ui/base/ui_base_switches.h" |
| 19 #include "ui/events/event_processor.h" | 15 #include "ui/events/event_processor.h" |
| 20 #include "ui/events/test/event_generator.h" | 16 #include "ui/events/test/event_generator.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 22 #include "ui/gl/gl_surface.h" | 18 #include "ui/gl/gl_surface.h" |
| 23 #include "ui/views/controls/textfield/textfield.h" | 19 #include "ui/views/controls/textfield/textfield.h" |
| 24 #include "ui/views/controls/textfield/textfield_test_api.h" | 20 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 25 #include "ui/views/test/widget_test.h" | 21 #include "ui/views/test/widget_test.h" |
| 26 #include "ui/views/touchui/touch_selection_controller_impl.h" | 22 #include "ui/views/touchui/touch_selection_controller_impl.h" |
| 27 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 28 #include "ui/views/window/dialog_delegate.h" | 24 #include "ui/views/window/dialog_delegate.h" |
| 29 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
| 30 | 26 |
| 31 #if !defined(OS_CHROMEOS) | 27 #if defined(OS_WIN) |
| 28 #include "ui/aura/window.h" | |
| 29 #include "ui/aura/window_tree_host.h" | |
| 32 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 30 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 33 #endif | |
| 34 | |
| 35 #if defined(OS_WIN) | |
| 36 #include "ui/views/win/hwnd_util.h" | 31 #include "ui/views/win/hwnd_util.h" |
| 37 #endif | 32 #endif |
| 38 | 33 |
| 39 namespace views { | 34 namespace views { |
| 40 namespace test { | 35 namespace test { |
| 41 | 36 |
| 42 namespace { | 37 namespace { |
| 43 | 38 |
| 44 // A View that closes the Widget and exits the current message-loop when it | 39 // A View that closes the Widget and exits the current message-loop when it |
| 45 // receives a mouse-release event. | 40 // receives a mouse-release event. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); | 163 ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); |
| 169 WidgetTest::SetUp(); | 164 WidgetTest::SetUp(); |
| 170 } | 165 } |
| 171 | 166 |
| 172 protected: | 167 protected: |
| 173 static void ShowQuickMenuImmediately( | 168 static void ShowQuickMenuImmediately( |
| 174 TouchSelectionControllerImpl* controller) { | 169 TouchSelectionControllerImpl* controller) { |
| 175 DCHECK(controller); | 170 DCHECK(controller); |
| 176 if (controller->context_menu_timer_.IsRunning()) { | 171 if (controller->context_menu_timer_.IsRunning()) { |
| 177 controller->context_menu_timer_.Stop(); | 172 controller->context_menu_timer_.Stop(); |
| 173 // TODO(tapted): Enable this when porting ui/views/touchui to Mac. | |
| 174 #if !defined(OS_MACOSX) | |
| 178 controller->ContextMenuTimerFired(); | 175 controller->ContextMenuTimerFired(); |
| 176 #endif | |
|
tapted
2014/08/05 13:42:26
This is to avoid a link error, and is all that str
| |
| 179 } | 177 } |
| 180 } | 178 } |
| 181 | 179 |
| 182 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { | 180 static bool IsQuickMenuVisible(TouchSelectionControllerImpl* controller) { |
| 183 DCHECK(controller); | 181 DCHECK(controller); |
| 184 return controller->context_menu_ && controller->context_menu_->visible(); | 182 return controller->context_menu_ && controller->context_menu_->visible(); |
| 185 } | 183 } |
| 186 }; | 184 }; |
| 187 | 185 |
| 188 #if defined(OS_WIN) | 186 #if defined(OS_WIN) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 | 240 |
| 243 // Now set focus back to widget 1 and expect the active window to be its | 241 // Now set focus back to widget 1 and expect the active window to be its |
| 244 // window. | 242 // window. |
| 245 contents_view1->RequestFocus(); | 243 contents_view1->RequestFocus(); |
| 246 ::SetActiveWindow( | 244 ::SetActiveWindow( |
| 247 root_window1->GetHost()->GetAcceleratedWidget()); | 245 root_window1->GetHost()->GetAcceleratedWidget()); |
| 248 EXPECT_EQ(activation_client2->GetActiveWindow(), | 246 EXPECT_EQ(activation_client2->GetActiveWindow(), |
| 249 reinterpret_cast<aura::Window*>(NULL)); | 247 reinterpret_cast<aura::Window*>(NULL)); |
| 250 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); | 248 EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView()); |
| 251 } | 249 } |
| 252 #endif | 250 #endif // defined(OS_WIN) |
| 253 | 251 |
| 254 TEST_F(WidgetTestInteractive, CaptureAutoReset) { | 252 TEST_F(WidgetTestInteractive, CaptureAutoReset) { |
| 255 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); | 253 Widget* toplevel = CreateTopLevelFramelessPlatformWidget(); |
| 256 View* container = new View; | 254 View* container = new View; |
| 257 toplevel->SetContentsView(container); | 255 toplevel->SetContentsView(container); |
| 258 | 256 |
| 259 EXPECT_FALSE(toplevel->HasCapture()); | 257 EXPECT_FALSE(toplevel->HasCapture()); |
| 260 toplevel->SetCapture(NULL); | 258 toplevel->SetCapture(NULL); |
| 261 EXPECT_TRUE(toplevel->HasCapture()); | 259 EXPECT_TRUE(toplevel->HasCapture()); |
| 262 | 260 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 EXPECT_TRUE(::IsWindow(win32_native_window1)); | 623 EXPECT_TRUE(::IsWindow(win32_native_window1)); |
| 626 | 624 |
| 627 ::SendMessage(win32_native_window1, WM_NCACTIVATE, 1, 0); | 625 ::SendMessage(win32_native_window1, WM_NCACTIVATE, 1, 0); |
| 628 EXPECT_EQ(false, widget1.active()); | 626 EXPECT_EQ(false, widget1.active()); |
| 629 EXPECT_EQ(true, widget2.active()); | 627 EXPECT_EQ(true, widget2.active()); |
| 630 | 628 |
| 631 ::SetActiveWindow(win32_native_window1); | 629 ::SetActiveWindow(win32_native_window1); |
| 632 EXPECT_EQ(true, widget1.active()); | 630 EXPECT_EQ(true, widget1.active()); |
| 633 EXPECT_EQ(false, widget2.active()); | 631 EXPECT_EQ(false, widget2.active()); |
| 634 } | 632 } |
| 635 #endif | 633 #endif // defined(OS_WIN) |
| 636 | 634 |
| 637 #if !defined(OS_CHROMEOS) | 635 #if !defined(OS_CHROMEOS) |
| 638 // Provides functionality to create a window modal dialog. | 636 // Provides functionality to create a window modal dialog. |
| 639 class ModalDialogDelegate : public DialogDelegateView { | 637 class ModalDialogDelegate : public DialogDelegateView { |
| 640 public: | 638 public: |
| 641 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} | 639 explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {} |
| 642 virtual ~ModalDialogDelegate() {} | 640 virtual ~ModalDialogDelegate() {} |
| 643 | 641 |
| 644 // WidgetDelegate overrides. | 642 // WidgetDelegate overrides. |
| 645 virtual ui::ModalType GetModalType() const OVERRIDE { | 643 virtual ui::ModalType GetModalType() const OVERRIDE { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 656 // created and destroyed. When it is destroyed it should focus the owner window. | 654 // created and destroyed. When it is destroyed it should focus the owner window. |
| 657 TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) { | 655 TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) { |
| 658 // Create a top level widget. | 656 // Create a top level widget. |
| 659 Widget top_level_widget; | 657 Widget top_level_widget; |
| 660 Widget::InitParams init_params = | 658 Widget::InitParams init_params = |
| 661 CreateParams(Widget::InitParams::TYPE_WINDOW); | 659 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 662 init_params.show_state = ui::SHOW_STATE_NORMAL; | 660 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 663 gfx::Rect initial_bounds(0, 0, 500, 500); | 661 gfx::Rect initial_bounds(0, 0, 500, 500); |
| 664 init_params.bounds = initial_bounds; | 662 init_params.bounds = initial_bounds; |
| 665 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 663 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 666 init_params.native_widget = new DesktopNativeWidgetAura(&top_level_widget); | 664 init_params.native_widget = |
| 665 new PlatformDesktopNativeWidget(&top_level_widget); | |
| 667 top_level_widget.Init(init_params); | 666 top_level_widget.Init(init_params); |
| 668 top_level_widget.Show(); | 667 top_level_widget.Show(); |
| 669 | 668 |
| 670 aura::Window* top_level_window = top_level_widget.GetNativeWindow(); | 669 gfx::NativeWindow top_level_window = top_level_widget.GetNativeWindow(); |
| 671 EXPECT_EQ(top_level_window, aura::client::GetFocusClient( | 670 EXPECT_EQ(top_level_window, CurrentlyFocussedWindow(&top_level_widget)); |
| 672 top_level_window)->GetFocusedWindow()); | |
| 673 | 671 |
| 674 // Create a modal dialog. | 672 // Create a modal dialog. |
| 675 // This instance will be destroyed when the dialog is destroyed. | 673 // This instance will be destroyed when the dialog is destroyed. |
| 676 ModalDialogDelegate* dialog_delegate = | 674 ModalDialogDelegate* dialog_delegate = |
| 677 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); | 675 new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW); |
| 678 | 676 |
| 679 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 677 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 680 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); | 678 dialog_delegate, NULL, top_level_widget.GetNativeView()); |
| 681 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 679 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 682 modal_dialog_widget->Show(); | 680 modal_dialog_widget->Show(); |
| 683 aura::Window* dialog_window = modal_dialog_widget->GetNativeWindow(); | |
| 684 EXPECT_EQ(dialog_window, aura::client::GetFocusClient( | |
| 685 top_level_window)->GetFocusedWindow()); | |
| 686 | 681 |
| 682 gfx::NativeWindow dialog_window = modal_dialog_widget->GetNativeWindow(); | |
| 683 EXPECT_EQ(dialog_window, CurrentlyFocussedWindow(&top_level_widget)); | |
| 687 modal_dialog_widget->CloseNow(); | 684 modal_dialog_widget->CloseNow(); |
| 688 EXPECT_EQ(top_level_window, aura::client::GetFocusClient( | 685 EXPECT_EQ(top_level_window, CurrentlyFocussedWindow(&top_level_widget)); |
| 689 top_level_window)->GetFocusedWindow()); | 686 |
| 690 top_level_widget.CloseNow(); | 687 top_level_widget.CloseNow(); |
| 691 } | 688 } |
| 692 | 689 |
| 693 // Test that when opening a system-modal window, capture is released. | 690 // Test that when opening a system-modal window, capture is released. |
| 694 TEST_F(WidgetTestInteractive, SystemModalWindowReleasesCapture) { | 691 TEST_F(WidgetTestInteractive, SystemModalWindowReleasesCapture) { |
| 695 // Create a top level widget. | 692 // Create a top level widget. |
| 696 Widget top_level_widget; | 693 Widget top_level_widget; |
| 697 Widget::InitParams init_params = | 694 Widget::InitParams init_params = |
| 698 CreateParams(Widget::InitParams::TYPE_WINDOW); | 695 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 699 init_params.show_state = ui::SHOW_STATE_NORMAL; | 696 init_params.show_state = ui::SHOW_STATE_NORMAL; |
| 700 gfx::Rect initial_bounds(0, 0, 500, 500); | 697 gfx::Rect initial_bounds(0, 0, 500, 500); |
| 701 init_params.bounds = initial_bounds; | 698 init_params.bounds = initial_bounds; |
| 702 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 699 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 703 init_params.native_widget = new DesktopNativeWidgetAura(&top_level_widget); | 700 init_params.native_widget = |
| 701 new PlatformDesktopNativeWidget(&top_level_widget); | |
| 704 top_level_widget.Init(init_params); | 702 top_level_widget.Init(init_params); |
| 705 top_level_widget.Show(); | 703 top_level_widget.Show(); |
| 706 | 704 |
| 707 aura::Window* top_level_window = top_level_widget.GetNativeWindow(); | 705 gfx::NativeWindow top_level_window = top_level_widget.GetNativeWindow(); |
| 708 EXPECT_EQ(top_level_window, aura::client::GetFocusClient( | 706 EXPECT_EQ(top_level_window, CurrentlyFocussedWindow(&top_level_widget)); |
| 709 top_level_window)->GetFocusedWindow()); | |
| 710 | 707 |
| 711 EXPECT_FALSE(top_level_window->HasCapture()); | 708 EXPECT_FALSE(top_level_widget.HasCapture()); |
| 712 top_level_window->SetCapture(); | 709 top_level_widget.SetCapture(NULL); |
| 713 EXPECT_TRUE(top_level_window->HasCapture()); | 710 EXPECT_TRUE(top_level_widget.HasCapture()); |
| 714 | 711 |
| 715 // Create a modal dialog. | 712 // Create a modal dialog. |
| 716 ModalDialogDelegate* dialog_delegate = | 713 ModalDialogDelegate* dialog_delegate = |
| 717 new ModalDialogDelegate(ui::MODAL_TYPE_SYSTEM); | 714 new ModalDialogDelegate(ui::MODAL_TYPE_SYSTEM); |
| 718 | 715 |
| 719 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( | 716 Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget( |
| 720 dialog_delegate, NULL, top_level_widget.GetNativeWindow()); | 717 dialog_delegate, NULL, top_level_widget.GetNativeView()); |
| 721 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); | 718 modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200)); |
| 722 modal_dialog_widget->Show(); | 719 modal_dialog_widget->Show(); |
| 723 | 720 |
| 724 EXPECT_FALSE(top_level_window->HasCapture()); | 721 EXPECT_FALSE(top_level_widget.HasCapture()); |
| 725 | 722 |
| 726 modal_dialog_widget->CloseNow(); | 723 modal_dialog_widget->CloseNow(); |
| 727 top_level_widget.CloseNow(); | 724 top_level_widget.CloseNow(); |
| 728 } | 725 } |
| 729 | 726 |
| 730 #endif | 727 #endif // !defined(OS_CHROMEOS) |
| 731 | 728 |
| 732 TEST_F(WidgetTestInteractive, CanActivateFlagIsHonored) { | 729 TEST_F(WidgetTestInteractive, CanActivateFlagIsHonored) { |
| 733 Widget widget; | 730 Widget widget; |
| 734 Widget::InitParams init_params = | 731 Widget::InitParams init_params = |
| 735 CreateParams(Widget::InitParams::TYPE_WINDOW); | 732 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 736 init_params.bounds = gfx::Rect(0, 0, 200, 200); | 733 init_params.bounds = gfx::Rect(0, 0, 200, 200); |
| 737 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 734 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 738 init_params.activatable = Widget::InitParams::ACTIVATABLE_NO; | 735 init_params.activatable = Widget::InitParams::ACTIVATABLE_NO; |
| 739 #if !defined(OS_CHROMEOS) | 736 #if !defined(OS_CHROMEOS) |
| 740 init_params.native_widget = new DesktopNativeWidgetAura(&widget); | 737 init_params.native_widget = new PlatformDesktopNativeWidget(&widget); |
| 741 #endif // !defined(OS_CHROMEOS) | 738 #endif // !defined(OS_CHROMEOS) |
| 742 widget.Init(init_params); | 739 widget.Init(init_params); |
| 743 | 740 |
| 744 widget.Show(); | 741 widget.Show(); |
| 745 EXPECT_FALSE(widget.IsActive()); | 742 EXPECT_FALSE(widget.IsActive()); |
| 746 } | 743 } |
| 747 | 744 |
| 748 // Test that touch selection quick menu is not activated when opened. | 745 // Test that touch selection quick menu is not activated when opened. |
| 749 TEST_F(WidgetTestInteractive, TouchSelectionQuickMenuIsNotActivated) { | 746 TEST_F(WidgetTestInteractive, TouchSelectionQuickMenuIsNotActivated) { |
| 750 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); | 747 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 764 textfield->SetText(base::ASCIIToUTF16("some text")); | 761 textfield->SetText(base::ASCIIToUTF16("some text")); |
| 765 widget.GetRootView()->AddChildView(textfield); | 762 widget.GetRootView()->AddChildView(textfield); |
| 766 | 763 |
| 767 widget.Show(); | 764 widget.Show(); |
| 768 textfield->RequestFocus(); | 765 textfield->RequestFocus(); |
| 769 textfield->SelectAll(true); | 766 textfield->SelectAll(true); |
| 770 TextfieldTestApi textfield_test_api(textfield); | 767 TextfieldTestApi textfield_test_api(textfield); |
| 771 | 768 |
| 772 RunPendingMessages(); | 769 RunPendingMessages(); |
| 773 | 770 |
| 774 ui::test::EventGenerator generator(widget.GetNativeView()->GetRootWindow()); | 771 ui::test::EventGenerator generator(widget.GetNativeWindow()); |
| 775 generator.GestureTapAt(gfx::Point(10, 10)); | 772 generator.GestureTapAt(gfx::Point(10, 10)); |
| 776 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( | 773 ShowQuickMenuImmediately(static_cast<TouchSelectionControllerImpl*>( |
| 777 textfield_test_api.touch_selection_controller())); | 774 textfield_test_api.touch_selection_controller())); |
| 778 | 775 |
| 779 EXPECT_TRUE(textfield->HasFocus()); | 776 EXPECT_TRUE(textfield->HasFocus()); |
| 780 EXPECT_TRUE(widget.IsActive()); | 777 EXPECT_TRUE(widget.IsActive()); |
| 781 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( | 778 EXPECT_TRUE(IsQuickMenuVisible(static_cast<TouchSelectionControllerImpl*>( |
| 782 textfield_test_api.touch_selection_controller()))); | 779 textfield_test_api.touch_selection_controller()))); |
| 783 } | 780 } |
| 784 | 781 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 EXPECT_FALSE(widget1.HasCapture()); | 864 EXPECT_FALSE(widget1.HasCapture()); |
| 868 EXPECT_FALSE(widget2.HasCapture()); | 865 EXPECT_FALSE(widget2.HasCapture()); |
| 869 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); | 866 EXPECT_TRUE(widget1.GetAndClearGotCaptureLost()); |
| 870 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); | 867 EXPECT_FALSE(widget2.GetAndClearGotCaptureLost()); |
| 871 } | 868 } |
| 872 | 869 |
| 873 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, | 870 NativeWidget* CreateNativeWidget(bool create_desktop_native_widget, |
| 874 Widget* widget) { | 871 Widget* widget) { |
| 875 #if !defined(OS_CHROMEOS) | 872 #if !defined(OS_CHROMEOS) |
| 876 if (create_desktop_native_widget) | 873 if (create_desktop_native_widget) |
| 877 return new DesktopNativeWidgetAura(widget); | 874 return new PlatformDesktopNativeWidget(widget); |
| 878 #endif | 875 #endif |
| 879 return NULL; | 876 return NULL; |
| 880 } | 877 } |
| 881 | 878 |
| 882 private: | 879 private: |
| 883 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); | 880 DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest); |
| 884 }; | 881 }; |
| 885 | 882 |
| 886 // See description in TestCapture(). | 883 // See description in TestCapture(). |
| 887 TEST_F(WidgetCaptureTest, Capture) { | 884 TEST_F(WidgetCaptureTest, Capture) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 912 widget.SetContentsView(contents_view); | 909 widget.SetContentsView(contents_view); |
| 913 | 910 |
| 914 mouse_view1->SetBounds(0, 0, 200, 400); | 911 mouse_view1->SetBounds(0, 0, 200, 400); |
| 915 mouse_view2->SetBounds(200, 0, 200, 400); | 912 mouse_view2->SetBounds(200, 0, 200, 400); |
| 916 | 913 |
| 917 // Setting capture should fail because |widget| is not visible. | 914 // Setting capture should fail because |widget| is not visible. |
| 918 widget.SetCapture(mouse_view1); | 915 widget.SetCapture(mouse_view1); |
| 919 EXPECT_FALSE(widget.HasCapture()); | 916 EXPECT_FALSE(widget.HasCapture()); |
| 920 | 917 |
| 921 widget.Show(); | 918 widget.Show(); |
| 922 ui::MouseEvent mouse_press_event(ui::ET_MOUSE_PRESSED, gfx::Point(300, 10), | 919 ui::test::EventGenerator generator(GetContext(), widget.GetNativeWindow()); |
| 923 gfx::Point(300, 10), ui::EF_NONE, ui::EF_NONE); | 920 generator.set_current_location(gfx::Point(300, 10)); |
| 924 ui::EventDispatchDetails details = widget.GetNativeWindow()->GetHost()-> | 921 generator.PressLeftButton(); |
| 925 event_processor()->OnEventFromSource(&mouse_press_event); | 922 |
| 926 ASSERT_FALSE(details.dispatcher_destroyed); | |
| 927 EXPECT_FALSE(mouse_view1->pressed()); | 923 EXPECT_FALSE(mouse_view1->pressed()); |
| 928 EXPECT_TRUE(mouse_view2->pressed()); | 924 EXPECT_TRUE(mouse_view2->pressed()); |
| 929 } | 925 } |
| 930 | 926 |
| 931 #if !defined(OS_CHROMEOS) | 927 #if !defined(OS_CHROMEOS) |
| 932 // Test that a synthetic mouse exit is sent to the widget which was handling | 928 // Test that a synthetic mouse exit is sent to the widget which was handling |
| 933 // mouse events when a different widget grabs capture. | 929 // mouse events when a different widget grabs capture. |
| 934 // TODO(pkotwicz): Make test pass on CrOS. | 930 // TODO(pkotwicz): Make test pass on CrOS. |
| 935 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { | 931 TEST_F(WidgetCaptureTest, MouseExitOnCaptureGrab) { |
| 936 Widget widget1; | 932 Widget widget1; |
| 937 Widget::InitParams params1 = | 933 Widget::InitParams params1 = |
| 938 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 934 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 939 params1.native_widget = CreateNativeWidget(true, &widget1); | 935 params1.native_widget = CreateNativeWidget(true, &widget1); |
| 940 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 936 params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 941 widget1.Init(params1); | 937 widget1.Init(params1); |
| 942 MouseView* mouse_view1 = new MouseView; | 938 MouseView* mouse_view1 = new MouseView; |
| 943 widget1.SetContentsView(mouse_view1); | 939 widget1.SetContentsView(mouse_view1); |
| 944 widget1.Show(); | 940 widget1.Show(); |
| 945 widget1.SetBounds(gfx::Rect(300, 300)); | 941 widget1.SetBounds(gfx::Rect(300, 300)); |
| 946 | 942 |
| 947 Widget widget2; | 943 Widget widget2; |
| 948 Widget::InitParams params2 = | 944 Widget::InitParams params2 = |
| 949 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 945 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 950 params2.native_widget = CreateNativeWidget(true, &widget2); | 946 params2.native_widget = CreateNativeWidget(true, &widget2); |
| 951 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 947 params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 952 widget2.Init(params2); | 948 widget2.Init(params2); |
| 953 widget2.Show(); | 949 widget2.Show(); |
| 954 widget2.SetBounds(gfx::Rect(400, 0, 300, 300)); | 950 widget2.SetBounds(gfx::Rect(400, 0, 300, 300)); |
| 955 | 951 |
| 956 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(100, 100), | 952 ui::test::EventGenerator generator(widget1.GetNativeWindow()); |
| 957 gfx::Point(100, 100), ui::EF_NONE, ui::EF_NONE); | 953 generator.set_current_location(gfx::Point(100, 100)); |
| 958 ui::EventDispatchDetails details = widget1.GetNativeWindow()->GetHost()-> | 954 generator.MoveMouseBy(0, 0); |
| 959 event_processor()->OnEventFromSource(&mouse_move_event); | 955 |
| 960 ASSERT_FALSE(details.dispatcher_destroyed); | |
| 961 EXPECT_EQ(1, mouse_view1->EnteredCalls()); | 956 EXPECT_EQ(1, mouse_view1->EnteredCalls()); |
| 962 EXPECT_EQ(0, mouse_view1->ExitedCalls()); | 957 EXPECT_EQ(0, mouse_view1->ExitedCalls()); |
| 963 | 958 |
| 964 widget2.SetCapture(NULL); | 959 widget2.SetCapture(NULL); |
| 965 EXPECT_EQ(0, mouse_view1->EnteredCalls()); | 960 EXPECT_EQ(0, mouse_view1->EnteredCalls()); |
| 966 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event | 961 // Grabbing native capture on Windows generates a ui::ET_MOUSE_EXITED event |
| 967 // in addition to the one generated by Chrome. | 962 // in addition to the one generated by Chrome. |
| 968 EXPECT_LT(0, mouse_view1->ExitedCalls()); | 963 EXPECT_LT(0, mouse_view1->ExitedCalls()); |
| 969 } | 964 } |
| 970 #endif | 965 #endif // !defined(OS_CHROMEOS) |
| 971 | 966 |
| 972 namespace { | 967 namespace { |
| 973 | 968 |
| 974 // Widget observer which grabs capture when the widget is activated. | 969 // Widget observer which grabs capture when the widget is activated. |
| 975 class CaptureOnActivationObserver : public WidgetObserver { | 970 class CaptureOnActivationObserver : public WidgetObserver { |
| 976 public: | 971 public: |
| 977 CaptureOnActivationObserver() { | 972 CaptureOnActivationObserver() { |
| 978 } | 973 } |
| 979 virtual ~CaptureOnActivationObserver() { | 974 virtual ~CaptureOnActivationObserver() { |
| 980 } | 975 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 999 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 994 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 1000 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); | 995 toplevel_params.native_widget = CreateNativeWidget(true, &toplevel); |
| 1001 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 996 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1002 toplevel.Init(toplevel_params); | 997 toplevel.Init(toplevel_params); |
| 1003 toplevel.Show(); | 998 toplevel.Show(); |
| 1004 | 999 |
| 1005 Widget* child = new Widget; | 1000 Widget* child = new Widget; |
| 1006 Widget::InitParams child_params = | 1001 Widget::InitParams child_params = |
| 1007 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 1002 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 1008 child_params.parent = toplevel.GetNativeView(); | 1003 child_params.parent = toplevel.GetNativeView(); |
| 1009 child_params.context = toplevel.GetNativeView(); | 1004 child_params.context = toplevel.GetNativeWindow(); |
| 1010 child->Init(child_params); | 1005 child->Init(child_params); |
| 1011 | 1006 |
| 1012 CaptureOnActivationObserver observer; | 1007 CaptureOnActivationObserver observer; |
| 1013 child->AddObserver(&observer); | 1008 child->AddObserver(&observer); |
| 1014 child->Show(); | 1009 child->Show(); |
| 1015 | 1010 |
| 1016 EXPECT_TRUE(child->HasCapture()); | 1011 EXPECT_TRUE(child->HasCapture()); |
| 1017 } | 1012 } |
| 1018 | 1013 |
| 1019 | 1014 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 // Send a mouse event to the RootWindow associated with |widget1|. Even though | 1071 // Send a mouse event to the RootWindow associated with |widget1|. Even though |
| 1077 // |widget2| has capture, |widget1| should still get the event. | 1072 // |widget2| has capture, |widget1| should still get the event. |
| 1078 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), | 1073 ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(), |
| 1079 ui::EF_NONE, ui::EF_NONE); | 1074 ui::EF_NONE, ui::EF_NONE); |
| 1080 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> | 1075 ui::EventDispatchDetails details = widget1.GetNativeWindow()-> |
| 1081 GetHost()->event_processor()->OnEventFromSource(&mouse_event); | 1076 GetHost()->event_processor()->OnEventFromSource(&mouse_event); |
| 1082 ASSERT_FALSE(details.dispatcher_destroyed); | 1077 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1083 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); | 1078 EXPECT_TRUE(widget1.GetAndClearGotMouseEvent()); |
| 1084 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); | 1079 EXPECT_FALSE(widget2.GetAndClearGotMouseEvent()); |
| 1085 } | 1080 } |
| 1086 #endif | 1081 #endif // defined(OS_WIN) |
| 1087 | 1082 |
| 1088 } // namespace test | 1083 } // namespace test |
| 1089 } // namespace views | 1084 } // namespace views |
| OLD | NEW |