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

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: add bug link for SkPath conversion 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
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/window.h" 10 #include "components/mus/public/cpp/window.h"
11 #include "components/mus/public/cpp/window_property.h" 11 #include "components/mus/public/cpp/window_property.h"
12 #include "components/mus/public/cpp/window_tree_connection.h" 12 #include "components/mus/public/cpp/window_tree_connection.h"
13 #include "components/mus/public/interfaces/window_manager.mojom.h" 13 #include "components/mus/public/interfaces/window_manager.mojom.h"
14 #include "components/mus/public/interfaces/window_tree.mojom.h" 14 #include "components/mus/public/interfaces/window_tree.mojom.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/events/event.h" 19 #include "ui/events/event.h"
20 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/gfx/path.h"
22 #include "ui/gfx/skia_util.h" 23 #include "ui/gfx/skia_util.h"
23 #include "ui/views/controls/native/native_view_host.h" 24 #include "ui/views/controls/native/native_view_host.h"
24 #include "ui/views/test/focus_manager_test.h" 25 #include "ui/views/test/focus_manager_test.h"
25 #include "ui/views/test/views_test_base.h" 26 #include "ui/views/test/views_test_base.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h" 28 #include "ui/views/widget/widget_delegate.h"
28 #include "ui/views/widget/widget_observer.h" 29 #include "ui/views/widget/widget_observer.h"
29 #include "ui/wm/public/activation_client.h" 30 #include "ui/wm/public/activation_client.h"
30 31
31 using mus::mojom::EventResult; 32 using mus::mojom::EventResult;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 // views::WidgetDelegate: 114 // views::WidgetDelegate:
114 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; } 115 gfx::ImageSkia GetWindowAppIcon() override { return app_icon_; }
115 116
116 private: 117 private:
117 gfx::ImageSkia app_icon_; 118 gfx::ImageSkia app_icon_;
118 119
119 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); 120 DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
120 }; 121 };
121 122
123 class WidgetDelegateWithHitTestMask : public WidgetDelegateView {
124 public:
125 explicit WidgetDelegateWithHitTestMask(const gfx::Rect& mask_rect)
126 : mask_rect_(mask_rect) {}
127
128 ~WidgetDelegateWithHitTestMask() override {}
129
130 // views::WidgetDelegate:
131 bool WidgetHasHitTestMask() const override { return true; }
132 void GetWidgetHitTestMask(gfx::Path* mask) const override {
133 mask->addRect(gfx::RectToSkRect(mask_rect_));
134 }
135
136 private:
137 gfx::Rect mask_rect_;
138
139 DISALLOW_COPY_AND_ASSIGN(WidgetDelegateWithHitTestMask);
140 };
141
122 } // namespace 142 } // namespace
123 143
124 class NativeWidgetMusTest : public ViewsTestBase { 144 class NativeWidgetMusTest : public ViewsTestBase {
125 public: 145 public:
126 NativeWidgetMusTest() {} 146 NativeWidgetMusTest() {}
127 ~NativeWidgetMusTest() override {} 147 ~NativeWidgetMusTest() override {}
128 148
129 // Creates a test widget. Takes ownership of |delegate|. 149 // Creates a test widget. Takes ownership of |delegate|.
130 std::unique_ptr<Widget> CreateWidget(TestWidgetDelegate* delegate) { 150 std::unique_ptr<Widget> CreateWidget(WidgetDelegate* delegate) {
131 std::unique_ptr<Widget> widget(new Widget()); 151 std::unique_ptr<Widget> widget(new Widget());
132 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 152 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
133 params.delegate = delegate; 153 params.delegate = delegate;
134 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 154 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
135 params.bounds = gfx::Rect(10, 20, 100, 200); 155 params.bounds = gfx::Rect(10, 20, 100, 200);
136 widget->Init(params); 156 widget->Init(params);
137 return widget; 157 return widget;
138 } 158 }
139 159
140 int ack_callback_count() { return ack_callback_count_; } 160 int ack_callback_count() { return ack_callback_count_; }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 Widget widget; 308 Widget widget;
289 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 309 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
290 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 310 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
291 params.name = "MyWidget"; 311 params.name = "MyWidget";
292 widget.Init(params); 312 widget.Init(params);
293 mus::Window* window = 313 mus::Window* window =
294 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window(); 314 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window();
295 EXPECT_EQ("MyWidget", window->GetName()); 315 EXPECT_EQ("MyWidget", window->GetName());
296 } 316 }
297 317
318 // Tests that a Widget with a hit test mask propagates the mask to the
319 // mus::Window.
320 TEST_F(NativeWidgetMusTest, HitTestMask) {
321 gfx::Rect mask(5, 5, 10, 10);
322 std::unique_ptr<Widget> widget(
323 CreateWidget(new WidgetDelegateWithHitTestMask(mask)));
324
325 // The window has the mask.
326 mus::Window* window =
327 static_cast<NativeWidgetMus*>(widget->native_widget_private())->window();
328 EXPECT_EQ(mask.ToString(), window->hit_test_mask().ToString());
329 }
330
298 // Verifies changing the visibility of a child mus::Window doesn't change the 331 // Verifies changing the visibility of a child mus::Window doesn't change the
299 // visibility of the parent. 332 // visibility of the parent.
300 TEST_F(NativeWidgetMusTest, ChildVisibilityDoesntEffectParent) { 333 TEST_F(NativeWidgetMusTest, ChildVisibilityDoesntEffectParent) {
301 Widget widget; 334 Widget widget;
302 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 335 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
303 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 336 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
304 widget.Init(params); 337 widget.Init(params);
305 widget.Show(); 338 widget.Show();
306 mus::Window* window = 339 mus::Window* window =
307 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window(); 340 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 442
410 // The widget was deleted. 443 // The widget was deleted.
411 EXPECT_FALSE(widget.get()); 444 EXPECT_FALSE(widget.get());
412 445
413 // The test took ownership of the callback and called it. 446 // The test took ownership of the callback and called it.
414 EXPECT_FALSE(ack_callback); 447 EXPECT_FALSE(ack_callback);
415 EXPECT_EQ(1, ack_callback_count()); 448 EXPECT_EQ(1, ack_callback_count());
416 } 449 }
417 450
418 } // namespace views 451 } // namespace views
OLDNEW
« ui/views/mus/native_widget_mus.cc ('K') | « 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