Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: ui/views/mus/native_widget_mus_unittest.cc

Issue 1991973003: mash: Preliminary support for widget hit test masks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/mus/native_widget_mus.h" 5 #include "ui/views/mus/native_widget_mus.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "components/mus/public/cpp/property_type_converters.h" 9 #include "components/mus/public/cpp/property_type_converters.h"
10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" 10 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h"
11 #include "components/mus/public/cpp/window.h" 11 #include "components/mus/public/cpp/window.h"
12 #include "components/mus/public/cpp/window_property.h" 12 #include "components/mus/public/cpp/window_property.h"
13 #include "components/mus/public/cpp/window_tree_connection.h" 13 #include "components/mus/public/cpp/window_tree_connection.h"
14 #include "components/mus/public/interfaces/window_manager.mojom.h" 14 #include "components/mus/public/interfaces/window_manager.mojom.h"
15 #include "components/mus/public/interfaces/window_tree.mojom.h" 15 #include "components/mus/public/interfaces/window_tree.mojom.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
18 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/events/event.h" 20 #include "ui/events/event.h"
21 #include "ui/events/test/test_event_handler.h" 21 #include "ui/events/test/test_event_handler.h"
22 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
23 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
24 #include "ui/gfx/path.h"
24 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
25 #include "ui/views/controls/native/native_view_host.h" 26 #include "ui/views/controls/native/native_view_host.h"
26 #include "ui/views/test/focus_manager_test.h" 27 #include "ui/views/test/focus_manager_test.h"
27 #include "ui/views/test/views_test_base.h" 28 #include "ui/views/test/views_test_base.h"
28 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
29 #include "ui/views/widget/widget_delegate.h" 30 #include "ui/views/widget/widget_delegate.h"
30 #include "ui/views/widget/widget_observer.h" 31 #include "ui/views/widget/widget_observer.h"
31 #include "ui/wm/public/activation_client.h" 32 #include "ui/wm/public/activation_client.h"
32 33
33 using mus::mojom::EventResult; 34 using mus::mojom::EventResult;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 115
115 // views::WidgetDelegate: 116 // views::WidgetDelegate:
116 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; } 117 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; }
117 118
118 private: 119 private:
119 gfx::ImageSkia app_icon_; 120 gfx::ImageSkia app_icon_;
120 121
121 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); 122 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
122 }; 123 };
123 124
125 class WidgetDelegateWithHitTestMask : public WidgetDelegateView {
126 public:
127 explicit WidgetDelegateWithHitTestMask(const gfx::Rect& mask_rect)
128 : mask_rect_(mask_rect) {}
129
130 ~WidgetDelegateWithHitTestMask() override {}
131
132 // views::WidgetDelegate:
133 bool WidgetHasHitTestMask() const override { return true; }
134 void GetWidgetHitTestMask(gfx::Path* mask) const override {
135 mask->addRect(gfx::RectToSkRect(mask_rect_));
136 }
137
138 private:
139 gfx::Rect mask_rect_;
140
141 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateWithHitTestMask);
142 };
143
124 } // namespace 144 } // namespace
125 145
126 class NativeWidgetMusTest : public ViewsTestBase { 146 class NativeWidgetMusTest : public ViewsTestBase {
127 public: 147 public:
128 NativeWidgetMusTest() {} 148 NativeWidgetMusTest() {}
129 ~NativeWidgetMusTest() override {} 149 ~NativeWidgetMusTest() override {}
130 150
131 // Creates a test widget. Takes ownership of |delegate|. 151 // Creates a test widget. Takes ownership of |delegate|.
132 std::unique_ptr<Widget> CreateWidget(TestWidgetDelegate* delegate) { 152 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) {
133 std::unique_ptr<Widget> widget(new Widget()); 153 std::unique_ptr<Widget> widget(new Widget());
134 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 154 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
135 params.delegate = delegate; 155 params.delegate = delegate;
136 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 156 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
137 params.bounds = gfx::Rect(10, 20, 100, 200); 157 params.bounds = gfx::Rect(10, 20, 100, 200);
138 widget->Init(params); 158 widget->Init(params);
139 return widget; 159 return widget;
140 } 160 }
141 161
142 int ack_callback_count() { return ack_callback_count_; } 162 int ack_callback_count() { return ack_callback_count_; }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 Widget widget; 310 Widget widget;
291 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 311 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
292 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 312 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
293 params.name = "MyWidget"; 313 params.name = "MyWidget";
294 widget.Init(params); 314 widget.Init(params);
295 mus::Window* window = 315 mus::Window* window =
296 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window(); 316 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window();
297 EXPECT_EQ("MyWidget", window->GetName()); 317 EXPECT_EQ("MyWidget", window->GetName());
298 } 318 }
299 319
320 // Tests that a Widget with a hit test mask propagates the mask to the
321 // mus::Window.
322 TEST_F(NativeWidgetMusTest, HitTestMask) {
323 gfx::Rect mask(5, 5, 10, 10);
324 std::unique_ptr<Widget> widget(
325 CreateWidget(new WidgetDelegateWithHitTestMask(mask)));
326
327 // The window has the mask.
328 mus::Window* window =
329 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
330 ASSERT_TRUE(window->hit_test_mask());
331 EXPECT_EQ(mask.ToString(), window->hit_test_mask()->ToString());
332 }
333
300 // Verifies changing the visibility of a child mus::Window doesn't change the 334 // Verifies changing the visibility of a child mus::Window doesn't change the
301 // visibility of the parent. 335 // visibility of the parent.
302 TEST_F(NativeWidgetMusTest, ChildVisibilityDoesntEffectParent) { 336 TEST_F(NativeWidgetMusTest, ChildVisibilityDoesntEffectParent) {
303 Widget widget; 337 Widget widget;
304 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 338 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
305 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 339 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
306 widget.Init(params); 340 widget.Init(params);
307 widget.Show(); 341 widget.Show();
308 mus::Window* window = 342 mus::Window* window =
309 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window(); 343 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 464
431 // The widget was deleted. 465 // The widget was deleted.
432 EXPECT_FALSE(widget.get()); 466 EXPECT_FALSE(widget.get());
433 467
434 // The test took ownership of the callback and called it. 468 // The test took ownership of the callback and called it.
435 EXPECT_FALSE(ack_callback); 469 EXPECT_FALSE(ack_callback);
436 EXPECT_EQ(1, ack_callback_count()); 470 EXPECT_EQ(1, ack_callback_count());
437 } 471 }
438 472
439 } // namespace views 473 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698