| OLD | NEW |
| 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" | |
| 6 | 5 |
| 7 #include "base/callback.h" | 6 #include "base/callback.h" |
| 8 #include "base/macros.h" | 7 #include "base/macros.h" |
| 9 #include "services/ui/public/cpp/property_type_converters.h" | 8 #include "services/ui/public/cpp/property_type_converters.h" |
| 10 #include "services/ui/public/cpp/tests/window_tree_client_private.h" | 9 #include "services/ui/public/cpp/tests/window_tree_client_private.h" |
| 11 #include "services/ui/public/cpp/window.h" | 10 #include "services/ui/public/cpp/window.h" |
| 12 #include "services/ui/public/cpp/window_observer.h" | 11 #include "services/ui/public/cpp/window_observer.h" |
| 13 #include "services/ui/public/cpp/window_property.h" | 12 #include "services/ui/public/cpp/window_property.h" |
| 14 #include "services/ui/public/cpp/window_tree_client.h" | 13 #include "services/ui/public/cpp/window_tree_client.h" |
| 15 #include "services/ui/public/interfaces/window_manager.mojom.h" | 14 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 16 #include "services/ui/public/interfaces/window_tree.mojom.h" | 15 #include "services/ui/public/interfaces/window_tree.mojom.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 17 #include "third_party/skia/include/core/SkBitmap.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 21 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
| 22 #include "ui/events/test/test_event_handler.h" | 21 #include "ui/events/test/test_event_handler.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/path.h" | 24 #include "ui/gfx/path.h" |
| 26 #include "ui/gfx/skia_util.h" | 25 #include "ui/gfx/skia_util.h" |
| 27 #include "ui/views/controls/native/native_view_host.h" | 26 #include "ui/views/controls/native/native_view_host.h" |
| 27 #include "ui/views/mus/native_widget_mus.h" |
| 28 #include "ui/views/mus/window_manager_connection.h" | 28 #include "ui/views/mus/window_manager_connection.h" |
| 29 #include "ui/views/test/focus_manager_test.h" | 29 #include "ui/views/test/focus_manager_test.h" |
| 30 #include "ui/views/test/views_test_base.h" | 30 #include "ui/views/test/views_test_base.h" |
| 31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 32 #include "ui/views/widget/widget_delegate.h" | 32 #include "ui/views/widget/widget_delegate.h" |
| 33 #include "ui/views/widget/widget_observer.h" | 33 #include "ui/views/widget/widget_observer.h" |
| 34 #include "ui/wm/public/activation_client.h" | 34 #include "ui/wm/public/activation_client.h" |
| 35 | 35 |
| 36 using ui::mojom::EventResult; | 36 using ui::mojom::EventResult; |
| 37 | 37 |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 params.bounds = initial_bounds(); | 602 params.bounds = initial_bounds(); |
| 603 params.native_widget = new NativeWidgetMus( | 603 params.native_widget = new NativeWidgetMus( |
| 604 widget.get(), window, ui::mojom::CompositorFrameSinkType::DEFAULT); | 604 widget.get(), window, ui::mojom::CompositorFrameSinkType::DEFAULT); |
| 605 widget->Init(params); | 605 widget->Init(params); |
| 606 window->SetSharedProperty<int32_t>( | 606 window->SetSharedProperty<int32_t>( |
| 607 ui::mojom::WindowManager::kShowState_Property, | 607 ui::mojom::WindowManager::kShowState_Property, |
| 608 static_cast<uint32_t>(ui::mojom::ShowState::MAXIMIZED)); | 608 static_cast<uint32_t>(ui::mojom::ShowState::MAXIMIZED)); |
| 609 EXPECT_TRUE(widget->IsMaximized()); | 609 EXPECT_TRUE(widget->IsMaximized()); |
| 610 } | 610 } |
| 611 | 611 |
| 612 // This test is to ensure that when initializing a widget with InitParams.parent |
| 613 // set to another widget's aura::Window, the ui::Window of the former widget is |
| 614 // added as a child to the ui::Window of the latter widget. |
| 615 TEST_F(NativeWidgetMusTest, InitNativeWidgetParentsUIWindow) { |
| 616 ASSERT_TRUE(WindowManagerConnection::Exists()); |
| 617 |
| 618 ui::Window* parent_window = WindowManagerConnection::Get()->NewTopLevelWindow( |
| 619 std::map<std::string, std::vector<uint8_t>>()); |
| 620 std::unique_ptr<Widget> parent_widget(new Widget()); |
| 621 Widget::InitParams parent_params = |
| 622 CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 623 parent_params.name = "Parent Widget"; |
| 624 parent_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 625 parent_params.shadow_type = Widget::InitParams::SHADOW_TYPE_NONE; |
| 626 parent_params.opacity = Widget::InitParams::OPAQUE_WINDOW; |
| 627 parent_params.parent = nullptr; |
| 628 parent_params.bounds = initial_bounds(); |
| 629 parent_params.native_widget = |
| 630 new NativeWidgetMus(parent_widget.get(), parent_window, |
| 631 ui::mojom::CompositorFrameSinkType::DEFAULT); |
| 632 parent_widget->Init(parent_params); |
| 633 |
| 634 std::unique_ptr<Widget> child_widget(new Widget()); |
| 635 ui::Window* child_window = parent_window->window_tree()->NewWindow(); |
| 636 Widget::InitParams child_params = CreateParams(Widget::InitParams::TYPE_MENU); |
| 637 child_params.parent = parent_widget->GetNativeView(); |
| 638 child_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 639 child_params.name = "Child Widget"; |
| 640 child_params.native_widget = |
| 641 new NativeWidgetMus(child_widget.get(), child_window, |
| 642 ui::mojom::CompositorFrameSinkType::DEFAULT); |
| 643 child_widget->Init(child_params); |
| 644 |
| 645 EXPECT_EQ(child_window->parent(), parent_window); |
| 646 |
| 647 std::unique_ptr<Widget> not_child_widget(new Widget()); |
| 648 ui::Window* not_child_window = parent_window->window_tree()->NewWindow(); |
| 649 Widget::InitParams not_child_params = |
| 650 CreateParams(Widget::InitParams::TYPE_MENU); |
| 651 not_child_params.ownership = |
| 652 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 653 not_child_params.name = "Not Child Widget"; |
| 654 not_child_params.native_widget = |
| 655 new NativeWidgetMus(not_child_widget.get(), not_child_window, |
| 656 ui::mojom::CompositorFrameSinkType::DEFAULT); |
| 657 not_child_widget->Init(not_child_params); |
| 658 |
| 659 EXPECT_NE(not_child_window->parent(), parent_window); |
| 660 } |
| 661 |
| 612 } // namespace views | 662 } // namespace views |
| OLD | NEW |