| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "apps/ui/views/app_window_frame_view.h" | 9 #include "apps/ui/views/app_window_frame_view.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 widget_->Show(); | 49 widget_->Show(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void TearDown() override { | 52 void TearDown() override { |
| 53 widget_.reset(); | 53 widget_.reset(); |
| 54 aura::test::AuraTestBase::TearDown(); | 54 aura::test::AuraTestBase::TearDown(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 private: | 57 private: |
| 58 views::WebView web_view_; | 58 views::WebView web_view_; |
| 59 scoped_ptr<views::Widget> widget_; | 59 std::unique_ptr<views::Widget> widget_; |
| 60 ChromeNativeAppWindowViewsAura app_window_; | 60 ChromeNativeAppWindowViewsAura app_window_; |
| 61 | 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(ShapedAppWindowTargeterTest); | 62 DISALLOW_COPY_AND_ASSIGN(ShapedAppWindowTargeterTest); |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 TEST_F(ShapedAppWindowTargeterTest, HitTestBasic) { | 65 TEST_F(ShapedAppWindowTargeterTest, HitTestBasic) { |
| 66 aura::Window* window = widget()->GetNativeWindow(); | 66 aura::Window* window = widget()->GetNativeWindow(); |
| 67 { | 67 { |
| 68 // Without any custom shapes, the event should be targeted correctly to the | 68 // Without any custom shapes, the event should be targeted correctly to the |
| 69 // window. | 69 // window. |
| 70 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), | 70 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), |
| 71 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, | 71 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, |
| 72 ui::EF_NONE); | 72 ui::EF_NONE); |
| 73 ui::EventDispatchDetails details = | 73 ui::EventDispatchDetails details = |
| 74 event_processor()->OnEventFromSource(&move); | 74 event_processor()->OnEventFromSource(&move); |
| 75 ASSERT_FALSE(details.dispatcher_destroyed); | 75 ASSERT_FALSE(details.dispatcher_destroyed); |
| 76 EXPECT_EQ(window, move.target()); | 76 EXPECT_EQ(window, move.target()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 scoped_ptr<SkRegion> region(new SkRegion); | 79 std::unique_ptr<SkRegion> region(new SkRegion); |
| 80 region->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op); | 80 region->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op); |
| 81 app_window()->UpdateShape(std::move(region)); | 81 app_window()->UpdateShape(std::move(region)); |
| 82 { | 82 { |
| 83 // With an empty custom shape, all events within the window should fall | 83 // With an empty custom shape, all events within the window should fall |
| 84 // through to the root window. | 84 // through to the root window. |
| 85 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), | 85 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), |
| 86 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, | 86 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, |
| 87 ui::EF_NONE); | 87 ui::EF_NONE); |
| 88 ui::EventDispatchDetails details = | 88 ui::EventDispatchDetails details = |
| 89 event_processor()->OnEventFromSource(&move); | 89 event_processor()->OnEventFromSource(&move); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 ASSERT_FALSE(details.dispatcher_destroyed); | 123 ASSERT_FALSE(details.dispatcher_destroyed); |
| 124 EXPECT_EQ(window, move2.target()); | 124 EXPECT_EQ(window, move2.target()); |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { | 128 TEST_F(ShapedAppWindowTargeterTest, HitTestOnlyForShapedWindow) { |
| 129 // Install a window-targeter on the root window that allows a window to | 129 // Install a window-targeter on the root window that allows a window to |
| 130 // receive events outside of its bounds. Verify that this window-targeter is | 130 // receive events outside of its bounds. Verify that this window-targeter is |
| 131 // active unless the window has a custom shape. | 131 // active unless the window has a custom shape. |
| 132 gfx::Insets inset(-30); | 132 gfx::Insets inset(-30); |
| 133 root_window()->SetEventTargeter(scoped_ptr<ui::EventTargeter>( | 133 root_window()->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( |
| 134 new wm::EasyResizeWindowTargeter(root_window(), inset, inset))); | 134 new wm::EasyResizeWindowTargeter(root_window(), inset, inset))); |
| 135 | 135 |
| 136 aura::Window* window = widget()->GetNativeWindow(); | 136 aura::Window* window = widget()->GetNativeWindow(); |
| 137 { | 137 { |
| 138 // Without any custom shapes, an event within the window bounds should be | 138 // Without any custom shapes, an event within the window bounds should be |
| 139 // targeted correctly to the window. | 139 // targeted correctly to the window. |
| 140 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), | 140 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(40, 40), |
| 141 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, | 141 gfx::Point(40, 40), ui::EventTimeForNow(), ui::EF_NONE, |
| 142 ui::EF_NONE); | 142 ui::EF_NONE); |
| 143 ui::EventDispatchDetails details = | 143 ui::EventDispatchDetails details = |
| 144 event_processor()->OnEventFromSource(&move); | 144 event_processor()->OnEventFromSource(&move); |
| 145 ASSERT_FALSE(details.dispatcher_destroyed); | 145 ASSERT_FALSE(details.dispatcher_destroyed); |
| 146 EXPECT_EQ(window, move.target()); | 146 EXPECT_EQ(window, move.target()); |
| 147 } | 147 } |
| 148 { | 148 { |
| 149 // Without any custom shapes, an event that falls just outside the window | 149 // Without any custom shapes, an event that falls just outside the window |
| 150 // bounds should also be targeted correctly to the window, because of the | 150 // bounds should also be targeted correctly to the window, because of the |
| 151 // targeter installed on the root-window. | 151 // targeter installed on the root-window. |
| 152 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 152 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 153 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, | 153 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, |
| 154 ui::EF_NONE); | 154 ui::EF_NONE); |
| 155 ui::EventDispatchDetails details = | 155 ui::EventDispatchDetails details = |
| 156 event_processor()->OnEventFromSource(&move); | 156 event_processor()->OnEventFromSource(&move); |
| 157 ASSERT_FALSE(details.dispatcher_destroyed); | 157 ASSERT_FALSE(details.dispatcher_destroyed); |
| 158 EXPECT_EQ(window, move.target()); | 158 EXPECT_EQ(window, move.target()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 scoped_ptr<SkRegion> region(new SkRegion); | 161 std::unique_ptr<SkRegion> region(new SkRegion); |
| 162 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); | 162 region->op(SkIRect::MakeXYWH(40, 0, 20, 100), SkRegion::kUnion_Op); |
| 163 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); | 163 region->op(SkIRect::MakeXYWH(0, 40, 100, 20), SkRegion::kUnion_Op); |
| 164 app_window()->UpdateShape(std::move(region)); | 164 app_window()->UpdateShape(std::move(region)); |
| 165 { | 165 { |
| 166 // With the custom shape, the events that don't fall within the custom shape | 166 // With the custom shape, the events that don't fall within the custom shape |
| 167 // will go through to the root window. | 167 // will go through to the root window. |
| 168 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 168 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 169 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, | 169 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, |
| 170 ui::EF_NONE); | 170 ui::EF_NONE); |
| 171 ui::EventDispatchDetails details = | 171 ui::EventDispatchDetails details = |
| 172 event_processor()->OnEventFromSource(&move); | 172 event_processor()->OnEventFromSource(&move); |
| 173 ASSERT_FALSE(details.dispatcher_destroyed); | 173 ASSERT_FALSE(details.dispatcher_destroyed); |
| 174 EXPECT_EQ(root_window(), move.target()); | 174 EXPECT_EQ(root_window(), move.target()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Remove the custom shape. This should restore the behaviour of targeting the | 177 // Remove the custom shape. This should restore the behaviour of targeting the |
| 178 // app window for events just outside its bounds. | 178 // app window for events just outside its bounds. |
| 179 app_window()->UpdateShape(scoped_ptr<SkRegion>()); | 179 app_window()->UpdateShape(std::unique_ptr<SkRegion>()); |
| 180 { | 180 { |
| 181 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 181 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 182 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, | 182 gfx::Point(10, 10), ui::EventTimeForNow(), ui::EF_NONE, |
| 183 ui::EF_NONE); | 183 ui::EF_NONE); |
| 184 ui::EventDispatchDetails details = | 184 ui::EventDispatchDetails details = |
| 185 event_processor()->OnEventFromSource(&move); | 185 event_processor()->OnEventFromSource(&move); |
| 186 ASSERT_FALSE(details.dispatcher_destroyed); | 186 ASSERT_FALSE(details.dispatcher_destroyed); |
| 187 EXPECT_EQ(window, move.target()); | 187 EXPECT_EQ(window, move.target()); |
| 188 } | 188 } |
| 189 } | 189 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 211 gfx::Point(32, 37), ui::EventTimeForNow(), ui::EF_NONE, | 211 gfx::Point(32, 37), ui::EventTimeForNow(), ui::EF_NONE, |
| 212 ui::EF_NONE); | 212 ui::EF_NONE); |
| 213 ui::EventDispatchDetails details = | 213 ui::EventDispatchDetails details = |
| 214 event_processor()->OnEventFromSource(&move); | 214 event_processor()->OnEventFromSource(&move); |
| 215 ASSERT_FALSE(details.dispatcher_destroyed); | 215 ASSERT_FALSE(details.dispatcher_destroyed); |
| 216 EXPECT_EQ(window, move.target()); | 216 EXPECT_EQ(window, move.target()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 #if !defined(OS_CHROMEOS) | 219 #if !defined(OS_CHROMEOS) |
| 220 // The non standard app frame has a easy resize targetter installed. | 220 // The non standard app frame has a easy resize targetter installed. |
| 221 scoped_ptr<views::NonClientFrameView> frame( | 221 std::unique_ptr<views::NonClientFrameView> frame( |
| 222 app_window_views()->CreateNonStandardAppFrame()); | 222 app_window_views()->CreateNonStandardAppFrame()); |
| 223 { | 223 { |
| 224 // Ensure that the window has an event targeter (there should be an | 224 // Ensure that the window has an event targeter (there should be an |
| 225 // EasyResizeWindowTargeter installed). | 225 // EasyResizeWindowTargeter installed). |
| 226 EXPECT_TRUE(static_cast<ui::EventTarget*>(window)->GetEventTargeter()); | 226 EXPECT_TRUE(static_cast<ui::EventTarget*>(window)->GetEventTargeter()); |
| 227 } | 227 } |
| 228 { | 228 { |
| 229 // An event in the center of the window should always have | 229 // An event in the center of the window should always have |
| 230 // |window| as its target. | 230 // |window| as its target. |
| 231 // TODO(mgiuca): This isn't really testing anything (note that it has the | 231 // TODO(mgiuca): This isn't really testing anything (note that it has the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 251 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(32, 37), | 251 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(32, 37), |
| 252 gfx::Point(32, 37), ui::EventTimeForNow(), ui::EF_NONE, | 252 gfx::Point(32, 37), ui::EventTimeForNow(), ui::EF_NONE, |
| 253 ui::EF_NONE); | 253 ui::EF_NONE); |
| 254 ui::EventDispatchDetails details = | 254 ui::EventDispatchDetails details = |
| 255 event_processor()->OnEventFromSource(&move); | 255 event_processor()->OnEventFromSource(&move); |
| 256 ASSERT_FALSE(details.dispatcher_destroyed); | 256 ASSERT_FALSE(details.dispatcher_destroyed); |
| 257 EXPECT_EQ(window, move.target()); | 257 EXPECT_EQ(window, move.target()); |
| 258 } | 258 } |
| 259 #endif // defined (OS_CHROMEOS) | 259 #endif // defined (OS_CHROMEOS) |
| 260 } | 260 } |
| OLD | NEW |