Chromium Code Reviews| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 2088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2099 //////////////////////////////////////////////////////////////////////////////// | 2099 //////////////////////////////////////////////////////////////////////////////// |
| 2100 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 2100 bool TestView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 2101 accelerator_count_map_[accelerator]++; | 2101 accelerator_count_map_[accelerator]++; |
| 2102 return true; | 2102 return true; |
| 2103 } | 2103 } |
| 2104 | 2104 |
| 2105 // On non-ChromeOS aura there is extra logic to determine whether a view should | 2105 // On non-ChromeOS aura there is extra logic to determine whether a view should |
| 2106 // handle accelerators or not (see View::CanHandleAccelerators for details). | 2106 // handle accelerators or not (see View::CanHandleAccelerators for details). |
| 2107 // This test targets that extra logic, but should also work on other platforms. | 2107 // This test targets that extra logic, but should also work on other platforms. |
| 2108 TEST_F(ViewTest, HandleAccelerator) { | 2108 TEST_F(ViewTest, HandleAccelerator) { |
| 2109 EnableMacFakeWindowActivation(); | |
| 2109 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 2110 ui::Accelerator return_accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
| 2110 TestView* view = new TestView(); | 2111 TestView* view = new TestView(); |
| 2111 view->Reset(); | 2112 view->Reset(); |
| 2112 view->AddAccelerator(return_accelerator); | 2113 view->AddAccelerator(return_accelerator); |
| 2113 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); | 2114 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); |
| 2114 | 2115 |
| 2115 // Create a window and add the view as its child. | 2116 // Create a window and add the view as its child. |
| 2116 scoped_ptr<Widget> widget(new Widget); | 2117 scoped_ptr<Widget> widget(new Widget); |
| 2117 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 2118 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 2118 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 2119 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 2119 params.bounds = gfx::Rect(0, 0, 100, 100); | 2120 params.bounds = gfx::Rect(0, 0, 100, 100); |
| 2120 widget->Init(params); | 2121 widget->Init(params); |
| 2121 View* root = widget->GetRootView(); | 2122 View* root = widget->GetRootView(); |
| 2122 root->AddChildView(view); | 2123 root->AddChildView(view); |
| 2123 widget->Show(); | 2124 widget->Show(); |
| 2124 | 2125 |
| 2125 FocusManager* focus_manager = widget->GetFocusManager(); | 2126 FocusManager* focus_manager = widget->GetFocusManager(); |
| 2126 ASSERT_TRUE(focus_manager); | 2127 ASSERT_TRUE(focus_manager); |
| 2127 | 2128 |
| 2128 #if defined(USE_AURA) && !defined(OS_CHROMEOS) | 2129 #if defined(USE_AURA) && !defined(OS_CHROMEOS) |
| 2129 // When a non-child view is not active, it shouldn't handle accelerators. | 2130 // When a non-child view is not active, it shouldn't handle accelerators. |
| 2130 EXPECT_FALSE(widget->IsActive()); | 2131 EXPECT_FALSE(widget->IsActive()); |
| 2131 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); | 2132 EXPECT_FALSE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 2132 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); | 2133 EXPECT_EQ(0, view->accelerator_count_map_[return_accelerator]); |
| 2133 #endif | 2134 #endif |
| 2134 | 2135 |
| 2136 // TYPE_POPUP widgets default to non-activatable, so the Show() above wouldn't | |
| 2137 // have activated the Widget. First, allow activation. | |
| 2138 widget->widget_delegate()->set_can_activate(true); | |
|
tapted
2016/03/10 10:52:42
There's nothing in NativeWidgetAura::Activate that
| |
| 2139 | |
| 2135 // When a non-child view is active, it should handle accelerators. | 2140 // When a non-child view is active, it should handle accelerators. |
| 2136 view->accelerator_count_map_[return_accelerator] = 0; | 2141 view->accelerator_count_map_[return_accelerator] = 0; |
| 2137 widget->Activate(); | 2142 widget->Activate(); |
| 2138 EXPECT_TRUE(widget->IsActive()); | 2143 EXPECT_TRUE(widget->IsActive()); |
| 2139 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); | 2144 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); |
| 2140 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); | 2145 EXPECT_EQ(1, view->accelerator_count_map_[return_accelerator]); |
| 2141 | 2146 |
| 2142 // Add a child view associated with a child widget. | 2147 // Add a child view associated with a child widget. |
| 2143 TestView* child_view = new TestView(); | 2148 TestView* child_view = new TestView(); |
| 2144 child_view->Reset(); | 2149 child_view->Reset(); |
| (...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4560 widget.Init(params); | 4565 widget.Init(params); |
| 4561 | 4566 |
| 4562 AddViewWithChildLayer(widget.GetRootView()); | 4567 AddViewWithChildLayer(widget.GetRootView()); |
| 4563 ViewThatAddsViewInOnNativeThemeChanged* v = | 4568 ViewThatAddsViewInOnNativeThemeChanged* v = |
| 4564 new ViewThatAddsViewInOnNativeThemeChanged; | 4569 new ViewThatAddsViewInOnNativeThemeChanged; |
| 4565 widget.GetRootView()->AddChildView(v); | 4570 widget.GetRootView()->AddChildView(v); |
| 4566 EXPECT_TRUE(v->on_native_theme_changed_called()); | 4571 EXPECT_TRUE(v->on_native_theme_changed_called()); |
| 4567 } | 4572 } |
| 4568 | 4573 |
| 4569 } // namespace views | 4574 } // namespace views |
| OLD | NEW |