| 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 "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" | 5 #include "chrome/browser/ui/views/apps/shaped_app_window_targeter.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" | 7 #include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h" |
| 8 #include "ui/aura/test/aura_test_base.h" | |
| 9 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 10 #include "ui/aura/window_event_dispatcher.h" | 9 #include "ui/aura/window_tree_host.h" |
| 10 #include "ui/events/event_processor.h" |
| 11 #include "ui/views/controls/webview/webview.h" | 11 #include "ui/views/controls/webview/webview.h" |
| 12 #include "ui/views/test/views_test_base.h" |
| 12 #include "ui/wm/core/easy_resize_window_targeter.h" | 13 #include "ui/wm/core/easy_resize_window_targeter.h" |
| 13 | 14 |
| 14 class ShapedAppWindowTargeterTest : public aura::test::AuraTestBase { | 15 class ShapedAppWindowTargeterTest : public views::ViewsTestBase { |
| 15 public: | 16 public: |
| 16 ShapedAppWindowTargeterTest() | 17 ShapedAppWindowTargeterTest() |
| 17 : web_view_(NULL) { | 18 : web_view_(NULL) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 virtual ~ShapedAppWindowTargeterTest() {} | 21 virtual ~ShapedAppWindowTargeterTest() {} |
| 21 | 22 |
| 22 views::Widget* widget() { return widget_.get(); } | 23 views::Widget* widget() { return widget_.get(); } |
| 23 | 24 |
| 24 apps::NativeAppWindow* app_window() { return &app_window_; } | 25 apps::NativeAppWindow* app_window() { return &app_window_; } |
| 25 ChromeNativeAppWindowViews* app_window_views() { return &app_window_; } | 26 ChromeNativeAppWindowViews* app_window_views() { return &app_window_; } |
| 26 | 27 |
| 27 protected: | 28 protected: |
| 28 virtual void SetUp() OVERRIDE { | 29 virtual void SetUp() OVERRIDE { |
| 29 aura::test::AuraTestBase::SetUp(); | 30 views::ViewsTestBase::SetUp(); |
| 30 widget_.reset(new views::Widget); | 31 widget_.reset(new views::Widget); |
| 31 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 32 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 32 params.remove_standard_frame = true; | 33 params.remove_standard_frame = true; |
| 33 params.bounds = gfx::Rect(30, 30, 100, 100); | 34 params.bounds = gfx::Rect(30, 30, 100, 100); |
| 34 params.context = root_window(); | 35 params.context = host()->window(); |
| 35 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 36 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 36 widget_->Init(params); | 37 widget_->Init(params); |
| 37 | 38 |
| 38 app_window_.set_web_view_for_testing(&web_view_); | 39 app_window_.set_web_view_for_testing(&web_view_); |
| 39 app_window_.set_window_for_testing(widget_.get()); | 40 app_window_.set_window_for_testing(widget_.get()); |
| 40 | 41 |
| 41 widget_->Show(); | 42 widget_->Show(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 virtual void TearDown() OVERRIDE { | 45 virtual void TearDown() OVERRIDE { |
| 45 widget_.reset(); | 46 widget_.reset(); |
| 46 aura::test::AuraTestBase::TearDown(); | 47 views::ViewsTestBase::TearDown(); |
| 47 } | 48 } |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 views::WebView web_view_; | 51 views::WebView web_view_; |
| 51 scoped_ptr<views::Widget> widget_; | 52 scoped_ptr<views::Widget> widget_; |
| 52 ChromeNativeAppWindowViews app_window_; | 53 ChromeNativeAppWindowViews app_window_; |
| 53 | 54 |
| 54 DISALLOW_COPY_AND_ASSIGN(ShapedAppWindowTargeterTest); | 55 DISALLOW_COPY_AND_ASSIGN(ShapedAppWindowTargeterTest); |
| 55 }; | 56 }; |
| 56 | 57 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 74 app_window()->UpdateShape(region.Pass()); | 75 app_window()->UpdateShape(region.Pass()); |
| 75 { | 76 { |
| 76 // With the custom shape, the events that don't fall within the custom shape | 77 // With the custom shape, the events that don't fall within the custom shape |
| 77 // will go through to the root window. | 78 // will go through to the root window. |
| 78 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 79 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 79 gfx::Point(40, 40), gfx::Point(40, 40), | 80 gfx::Point(40, 40), gfx::Point(40, 40), |
| 80 ui::EF_NONE, ui::EF_NONE); | 81 ui::EF_NONE, ui::EF_NONE); |
| 81 ui::EventDispatchDetails details = | 82 ui::EventDispatchDetails details = |
| 82 event_processor()->OnEventFromSource(&move); | 83 event_processor()->OnEventFromSource(&move); |
| 83 ASSERT_FALSE(details.dispatcher_destroyed); | 84 ASSERT_FALSE(details.dispatcher_destroyed); |
| 84 EXPECT_EQ(root_window(), move.target()); | 85 EXPECT_EQ(host()->window(), move.target()); |
| 85 | 86 |
| 86 // But events within the shape will still reach the window. | 87 // But events within the shape will still reach the window. |
| 87 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, | 88 ui::MouseEvent move2(ui::ET_MOUSE_MOVED, |
| 88 gfx::Point(80, 80), gfx::Point(80, 80), | 89 gfx::Point(80, 80), gfx::Point(80, 80), |
| 89 ui::EF_NONE, ui::EF_NONE); | 90 ui::EF_NONE, ui::EF_NONE); |
| 90 details = event_processor()->OnEventFromSource(&move2); | 91 details = event_processor()->OnEventFromSource(&move2); |
| 91 ASSERT_FALSE(details.dispatcher_destroyed); | 92 ASSERT_FALSE(details.dispatcher_destroyed); |
| 92 EXPECT_EQ(window, move2.target()); | 93 EXPECT_EQ(window, move2.target()); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { | 97 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { |
| 97 // Install a window-targeter on the root window that allows a window to | 98 // Install a window-targeter on the root window that allows a window to |
| 98 // receive events outside of its bounds. Verify that this window-targeter is | 99 // receive events outside of its bounds. Verify that this window-targeter is |
| 99 // active unless the window has a custom shape. | 100 // active unless the window has a custom shape. |
| 100 gfx::Insets inset(-30, -30, -30, -30); | 101 gfx::Insets inset(-30, -30, -30, -30); |
| 101 root_window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | 102 host()->window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>( |
| 102 new wm::EasyResizeWindowTargeter(root_window(), inset, inset))); | 103 new wm::EasyResizeWindowTargeter(host()->window(), inset, inset))); |
| 103 | 104 |
| 104 aura::Window* window = widget()->GetNativeWindow(); | 105 aura::Window* window = widget()->GetNativeWindow(); |
| 105 { | 106 { |
| 106 // Without any custom shapes, an event within the window bounds should be | 107 // Without any custom shapes, an event within the window bounds should be |
| 107 // targeted correctly to the window. | 108 // targeted correctly to the window. |
| 108 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 109 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 109 gfx::Point(40, 40), gfx::Point(40, 40), | 110 gfx::Point(40, 40), gfx::Point(40, 40), |
| 110 ui::EF_NONE, ui::EF_NONE); | 111 ui::EF_NONE, ui::EF_NONE); |
| 111 ui::EventDispatchDetails details = | 112 ui::EventDispatchDetails details = |
| 112 event_processor()->OnEventFromSource(&move); | 113 event_processor()->OnEventFromSource(&move); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 132 app_window()->UpdateShape(region.Pass()); | 133 app_window()->UpdateShape(region.Pass()); |
| 133 { | 134 { |
| 134 // With the custom shape, the events that don't fall within the custom shape | 135 // With the custom shape, the events that don't fall within the custom shape |
| 135 // will go through to the root window. | 136 // will go through to the root window. |
| 136 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 137 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 137 gfx::Point(10, 10), gfx::Point(10, 10), | 138 gfx::Point(10, 10), gfx::Point(10, 10), |
| 138 ui::EF_NONE, ui::EF_NONE); | 139 ui::EF_NONE, ui::EF_NONE); |
| 139 ui::EventDispatchDetails details = | 140 ui::EventDispatchDetails details = |
| 140 event_processor()->OnEventFromSource(&move); | 141 event_processor()->OnEventFromSource(&move); |
| 141 ASSERT_FALSE(details.dispatcher_destroyed); | 142 ASSERT_FALSE(details.dispatcher_destroyed); |
| 142 EXPECT_EQ(root_window(), move.target()); | 143 EXPECT_EQ(host()->window(), move.target()); |
| 143 } | 144 } |
| 144 | 145 |
| 145 // Remove the custom shape. This should restore the behaviour of targeting the | 146 // Remove the custom shape. This should restore the behaviour of targeting the |
| 146 // app window for events just outside its bounds. | 147 // app window for events just outside its bounds. |
| 147 app_window()->UpdateShape(scoped_ptr<SkRegion>()); | 148 app_window()->UpdateShape(scoped_ptr<SkRegion>()); |
| 148 { | 149 { |
| 149 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 150 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 150 gfx::Point(10, 10), gfx::Point(10, 10), | 151 gfx::Point(10, 10), gfx::Point(10, 10), |
| 151 ui::EF_NONE, ui::EF_NONE); | 152 ui::EF_NONE, ui::EF_NONE); |
| 152 ui::EventDispatchDetails details = | 153 ui::EventDispatchDetails details = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 gfx::Point(80, 80), gfx::Point(80, 80), | 195 gfx::Point(80, 80), gfx::Point(80, 80), |
| 195 ui::EF_NONE, ui::EF_NONE); | 196 ui::EF_NONE, ui::EF_NONE); |
| 196 ui::EventDispatchDetails details = | 197 ui::EventDispatchDetails details = |
| 197 event_processor()->OnEventFromSource(&move); | 198 event_processor()->OnEventFromSource(&move); |
| 198 ASSERT_FALSE(details.dispatcher_destroyed); | 199 ASSERT_FALSE(details.dispatcher_destroyed); |
| 199 EXPECT_EQ(window, move.target()); | 200 EXPECT_EQ(window, move.target()); |
| 200 } | 201 } |
| 201 { | 202 { |
| 202 // With an EasyResizeTargeter on the container, an event | 203 // With an EasyResizeTargeter on the container, an event |
| 203 // inside the window and within 5px of an edge should have | 204 // inside the window and within 5px of an edge should have |
| 204 // root_window() as its target. | 205 // host()->window() as its target. |
| 205 ui::MouseEvent move(ui::ET_MOUSE_MOVED, | 206 ui::MouseEvent move(ui::ET_MOUSE_MOVED, |
| 206 gfx::Point(32, 37), gfx::Point(32, 37), | 207 gfx::Point(32, 37), gfx::Point(32, 37), |
| 207 ui::EF_NONE, ui::EF_NONE); | 208 ui::EF_NONE, ui::EF_NONE); |
| 208 ui::EventDispatchDetails details = | 209 ui::EventDispatchDetails details = |
| 209 event_processor()->OnEventFromSource(&move); | 210 event_processor()->OnEventFromSource(&move); |
| 210 ASSERT_FALSE(details.dispatcher_destroyed); | 211 ASSERT_FALSE(details.dispatcher_destroyed); |
| 211 EXPECT_EQ(root_window(), move.target()); | 212 EXPECT_EQ(host()->window(), move.target()); |
| 212 } | 213 } |
| 213 } | 214 } |
| OLD | NEW |