diff --git a/ash/aura/wm_window_aura.cc b/ash/aura/wm_window_aura.cc index c52d0a948306f2..187ce852359a71 100644 --- a/ash/aura/wm_window_aura.cc +++ b/ash/aura/wm_window_aura.cc @@ -86,6 +86,9 @@ class BoundsSetter : public aura::LayoutManager { } // namespace +// static +bool WmWindowAura::default_use_empty_minimum_size_for_testing_ = false; + WmWindowAura::~WmWindowAura() { if (added_transient_observer_) ::wm::TransientWindowManager::Get(window_)->RemoveObserver(this); @@ -131,6 +134,13 @@ const aura::Window* WmWindowAura::GetAuraWindow(const WmWindow* wm_window) { : nullptr; } +bool WmWindowAura::ShouldUseExtendedHitRegion() const { + const WmWindow* parent = Get(window_->parent()); + return parent && + static_cast(parent) + ->children_use_extended_hit_region_; +} + void WmWindowAura::Destroy() { delete window_; // WARNING: this has been deleted. @@ -185,11 +195,6 @@ void WmWindowAura::SetAppType(int app_type) const { window_->SetProperty(aura::client::kAppType, app_type); } -bool WmWindowAura::IsBubble() { - views::Widget* widget = views::Widget::GetWidgetForNativeView(window_); - return widget->widget_delegate()->AsBubbleDialogDelegate() != nullptr; -} - ui::Layer* WmWindowAura::GetLayer() { return window_->layer(); } @@ -244,8 +249,9 @@ gfx::Rect WmWindowAura::ConvertRectFromScreen(const gfx::Rect& rect) const { } gfx::Size WmWindowAura::GetMinimumSize() const { - return window_->delegate() ? window_->delegate()->GetMinimumSize() - : gfx::Size(); + return window_->delegate() && !use_empty_minimum_size_for_testing_ + ? window_->delegate()->GetMinimumSize() + : gfx::Size(); } gfx::Size WmWindowAura::GetMaximumSize() const { @@ -694,7 +700,10 @@ void WmWindowAura::Show() { } views::Widget* WmWindowAura::GetInternalWidget() { - return views::Widget::GetWidgetForNativeView(window_); + return window_->GetProperty(kWidgetCreationTypeKey) == + WidgetCreationType::INTERNAL + ? views::Widget::GetWidgetForNativeView(window_) + : nullptr; } void WmWindowAura::CloseWidget() { @@ -785,6 +794,10 @@ void WmWindowAura::SnapToPixelBoundaryIfNecessary() { } void WmWindowAura::SetChildrenUseExtendedHitRegion() { + children_use_extended_hit_region_ = true; + if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) + return; + gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize); @@ -841,7 +854,9 @@ void WmWindowAura::RemoveLimitedPreTargetHandler(ui::EventHandler* handler) { WmWindowAura::WmWindowAura(aura::Window* window) : window_(window), // Mirrors that of aura::Window. - observers_(base::ObserverList::NOTIFY_EXISTING_ONLY) { + observers_(base::ObserverList::NOTIFY_EXISTING_ONLY), + use_empty_minimum_size_for_testing_( + default_use_empty_minimum_size_for_testing_) { window_->AddObserver(this); window_->SetProperty(kWmWindowKey, this); } diff --git a/ash/aura/wm_window_aura.h b/ash/aura/wm_window_aura.h index 953170977f4204..62ab8fe5bf1704 100644 --- a/ash/aura/wm_window_aura.h +++ b/ash/aura/wm_window_aura.h @@ -14,6 +14,8 @@ namespace ash { +class WmWindowAuraTestApi; + // WmWindowAura is tied to the life of the underlying aura::Window. Use the // static Get() function to obtain a WmWindowAura from an aura::Window. class ASH_EXPORT WmWindowAura : public WmWindow, @@ -45,6 +47,9 @@ class ASH_EXPORT WmWindowAura : public WmWindow, aura::Window* aura_window() { return window_; } const aura::Window* aura_window() const { return window_; } + // See description of |children_use_extended_hit_region_|. + bool ShouldUseExtendedHitRegion() const; + // WmWindow: void Destroy() override; const WmWindow* GetRootWindow() const override; @@ -60,7 +65,6 @@ class ASH_EXPORT WmWindowAura : public WmWindow, ui::wm::WindowType GetType() const override; int GetAppType() const override; void SetAppType(int app_type) const override; - bool IsBubble() override; ui::Layer* GetLayer() override; bool GetLayerTargetVisibility() override; bool GetLayerVisible() override; @@ -219,6 +223,8 @@ class ASH_EXPORT WmWindowAura : public WmWindow, aura::Window* transient) override; private: + friend class WmWindowAuraTestApi; + aura::Window* window_; base::ObserverList observers_; @@ -226,6 +232,16 @@ class ASH_EXPORT WmWindowAura : public WmWindow, bool added_transient_observer_ = false; base::ObserverList transient_observers_; + // If true child windows should get a slightly larger hit region to make + // resizing easier. + bool children_use_extended_hit_region_ = false; + + // Default value for |use_empty_minimum_size_for_testing_|. + static bool default_use_empty_minimum_size_for_testing_; + + // If true the minimum size is 0x0, default is minimum size comes from widget. + bool use_empty_minimum_size_for_testing_; + DISALLOW_COPY_AND_ASSIGN(WmWindowAura); }; diff --git a/ash/common/wm_window.h b/ash/common/wm_window.h index 6dbe40be28e53e..927863bbb22388 100644 --- a/ash/common/wm_window.h +++ b/ash/common/wm_window.h @@ -93,8 +93,6 @@ class ASH_EXPORT WmWindow { virtual int GetAppType() const = 0; virtual void SetAppType(int app_type) const = 0; - virtual bool IsBubble() = 0; - virtual ui::Layer* GetLayer() = 0; // TODO(sky): these are temporary until GetLayer() always returns non-null. diff --git a/ash/mus/BUILD.gn b/ash/mus/BUILD.gn index 893c2aed5d9f29..b921bc58af26f0 100644 --- a/ash/mus/BUILD.gn +++ b/ash/mus/BUILD.gn @@ -213,8 +213,6 @@ source_set("unittests") { "accelerators/accelerator_controller_unittest.cc", "app_launch_unittest.cc", "bridge/wm_shell_mus_test_api.h", - "bridge/wm_window_mus_test_api.cc", - "bridge/wm_window_mus_test_api.h", "root_window_controller_unittest.cc", "test/ash_test_impl_mus.cc", "test/ash_test_impl_mus.h", @@ -231,6 +229,7 @@ source_set("unittests") { "//ash", "//ash/common/test:test_support", "//ash/public/interfaces", + "//ash/test:test_support_without_content", "//base", "//base/test:test_config", "//base/test:test_support", diff --git a/ash/mus/bridge/wm_root_window_controller_mus.cc b/ash/mus/bridge/wm_root_window_controller_mus.cc index e0497d8c1ac2f6..eedb2eb1ef8736 100644 --- a/ash/mus/bridge/wm_root_window_controller_mus.cc +++ b/ash/mus/bridge/wm_root_window_controller_mus.cc @@ -14,7 +14,6 @@ #include "ui/aura/window.h" #include "ui/aura/window_property.h" #include "ui/display/display.h" -#include "ui/views/widget/native_widget_aura.h" #include "ui/views/widget/widget.h" DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::WmRootWindowControllerMus*); @@ -103,11 +102,6 @@ void WmRootWindowControllerMus::ConfigureWidgetInitParamsForContainer( WmWindowMus::Get(root_window_controller_->root()) ->GetChildByShellWindowId(shell_container_id)); DCHECK(init_params->parent); - views::NativeWidgetAura* native_widget_aura = - new views::NativeWidgetAura(widget); - init_params->native_widget = native_widget_aura; - WmWindowMus::Get(native_widget_aura->GetNativeView()) - ->set_widget(widget, WmWindowMus::WidgetCreationType::INTERNAL); } WmWindow* WmRootWindowControllerMus::FindEventTarget( diff --git a/ash/mus/bridge/wm_shell_mus.cc b/ash/mus/bridge/wm_shell_mus.cc index a07baf09d976d1..8794f8554a56ed 100644 --- a/ash/mus/bridge/wm_shell_mus.cc +++ b/ash/mus/bridge/wm_shell_mus.cc @@ -29,7 +29,6 @@ #include "ash/mus/keyboard_ui_mus.h" #include "ash/mus/root_window_controller.h" #include "ash/mus/window_manager.h" -#include "ash/public/cpp/shell_window_ids.h" #include "ash/shared/immersive_fullscreen_controller.h" #include "base/memory/ptr_util.h" #include "components/user_manager/user_info_impl.h" @@ -181,16 +180,6 @@ void WmShellMus::RemoveRootWindowController( root_window_controllers_.erase(iter); } -// static -WmWindowMus* WmShellMus::GetToplevelAncestor(aura::Window* window) { - while (window) { - if (IsActivationParent(window->parent())) - return WmWindowMus::Get(window); - window = window->parent(); - } - return nullptr; -} - WmRootWindowControllerMus* WmShellMus::GetRootWindowControllerWithDisplayId( int64_t id) { for (WmRootWindowControllerMus* root_window_controller : @@ -444,12 +433,6 @@ void WmShellMus::SetLaserPointerEnabled(bool enabled) { } #endif // defined(OS_CHROMEOS) -// static -bool WmShellMus::IsActivationParent(aura::Window* window) { - return window && IsActivatableShellWindowId( - WmWindowMus::Get(window)->GetShellWindowId()); -} - // TODO: support OnAttemptToReactivateWindow, http://crbug.com/615114. // TODO: Nuke and let client code use ActivationChangeObserver directly. void WmShellMus::OnWindowActivated(ActivationReason reason, diff --git a/ash/mus/bridge/wm_shell_mus.h b/ash/mus/bridge/wm_shell_mus.h index fc86876193060f..43ec36fa35c082 100644 --- a/ash/mus/bridge/wm_shell_mus.h +++ b/ash/mus/bridge/wm_shell_mus.h @@ -32,7 +32,6 @@ class ImmersiveHandlerFactoryMus; class WindowManager; class WmRootWindowControllerMus; class WmShellMusTestApi; -class WmWindowMus; // WmShell implementation for mus. class WmShellMus : public WmShell, @@ -48,10 +47,6 @@ class WmShellMus : public WmShell, void AddRootWindowController(WmRootWindowControllerMus* controller); void RemoveRootWindowController(WmRootWindowControllerMus* controller); - // Returns the ancestor of |window| (including |window|) that is considered - // toplevel. |window| may be null. - static WmWindowMus* GetToplevelAncestor(aura::Window* window); - WmRootWindowControllerMus* GetRootWindowControllerWithDisplayId(int64_t id); AcceleratorControllerDelegateMus* accelerator_controller_delegate() { @@ -123,9 +118,6 @@ class WmShellMus : public WmShell, private: friend class WmShellMusTestApi; - // Returns true if |window| is a window that can have active children. - static bool IsActivationParent(aura::Window* window); - // aura::client::ActivationChangeObserver: void OnWindowActivated(ActivationReason reason, aura::Window* gained_active, diff --git a/ash/mus/bridge/wm_window_mus.cc b/ash/mus/bridge/wm_window_mus.cc index a7cb95242a787c..ce4c457d6c873a 100644 --- a/ash/mus/bridge/wm_window_mus.cc +++ b/ash/mus/bridge/wm_window_mus.cc @@ -35,13 +35,7 @@ namespace ash { namespace mus { -// static -bool WmWindowMus::default_use_empty_minimum_size_for_testing_ = false; - -WmWindowMus::WmWindowMus(aura::Window* window) - : WmWindowAura(window), - use_empty_minimum_size_for_testing_( - default_use_empty_minimum_size_for_testing_) {} +WmWindowMus::WmWindowMus(aura::Window* window) : WmWindowAura(window) {} WmWindowMus::~WmWindowMus() {} @@ -68,19 +62,10 @@ const WmRootWindowControllerMus* WmWindowMus::GetRootWindowControllerMus() return WmRootWindowControllerMus::Get(aura_window()->GetRootWindow()); } -bool WmWindowMus::ShouldUseExtendedHitRegion() const { - const WmWindowMus* parent = Get(aura_window()->parent()); - return parent && parent->children_use_extended_hit_region_; -} - bool WmWindowMus::IsContainer() const { return GetShellWindowId() != kShellWindowId_Invalid; } -const WmWindow* WmWindowMus::GetRootWindow() const { - return Get(aura_window()->GetRootWindow()); -} - WmRootWindowController* WmWindowMus::GetRootWindowController() { return GetRootWindowControllerMus(); } @@ -89,52 +74,6 @@ WmShell* WmWindowMus::GetShell() const { return WmShellMus::Get(); } -bool WmWindowMus::IsBubble() { - return aura_window()->GetProperty(aura::client::kWindowTypeKey) == - ui::mojom::WindowType::BUBBLE; -} - -bool WmWindowMus::HasNonClientArea() { - return widget_ ? true : false; -} - -int WmWindowMus::GetNonClientComponent(const gfx::Point& location) { - return widget_ ? widget_->GetNonClientComponent(location) : HTNOWHERE; -} - -gfx::Size WmWindowMus::GetMinimumSize() const { - return widget_ && !use_empty_minimum_size_for_testing_ - ? widget_->GetMinimumSize() - : gfx::Size(); -} - -gfx::Size WmWindowMus::GetMaximumSize() const { - return widget_ ? widget_->GetMaximumSize() : gfx::Size(); -} - -gfx::Rect WmWindowMus::GetMinimizeAnimationTargetBoundsInScreen() const { - // TODO: need animation support: http://crbug.com/615087. - NOTIMPLEMENTED(); - return GetBoundsInScreen(); -} - -bool WmWindowMus::IsSystemModal() const { - NOTIMPLEMENTED(); - return false; -} - -bool WmWindowMus::GetBoolProperty(WmWindowProperty key) { - switch (key) { - case WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY: - return snap_children_to_pixel_boundary_; - - default: - break; - } - - return WmWindowAura::GetBoolProperty(key); -} - int WmWindowMus::GetIntProperty(WmWindowProperty key) { if (key == WmWindowProperty::SHELF_ITEM_TYPE) { if (aura_window()->GetProperty(kShelfItemTypeKey) != TYPE_UNDEFINED) @@ -147,16 +86,6 @@ int WmWindowMus::GetIntProperty(WmWindowProperty key) { return WmWindowAura::GetIntProperty(key); } -WmWindow* WmWindowMus::GetToplevelWindow() { - return WmShellMus::GetToplevelAncestor(aura_window()); -} - -WmWindow* WmWindowMus::GetToplevelWindowForFocus() { - // TODO(sky): resolve if we really need two notions of top-level. In the mus - // world they are the same. - return WmShellMus::GetToplevelAncestor(aura_window()); -} - // TODO(sky): investigate if needed. bool WmWindowMus::MoveToEventRoot(const ui::Event& event) { views::View* target = static_cast(event.target()); @@ -191,22 +120,16 @@ void WmWindowMus::SetPinned(bool trusted) { NOTIMPLEMENTED(); } -views::Widget* WmWindowMus::GetInternalWidget() { - // Don't return the window frame widget for an embedded client window. - if (widget_creation_type_ == WidgetCreationType::FOR_CLIENT) - return nullptr; - - return widget_; -} - void WmWindowMus::CloseWidget() { - DCHECK(widget_); + views::Widget* widget = views::Widget::GetWidgetForNativeView(aura_window()); + DCHECK(widget); // Allow the client to service the close request for remote widgets. - if (widget_creation_type_ == WidgetCreationType::FOR_CLIENT) { + if (aura_window()->GetProperty(kWidgetCreationTypeKey) == + WidgetCreationType::FOR_CLIENT) { WmShellMus::Get()->window_manager()->window_manager_client()->RequestClose( aura_window()); } else { - widget_->Close(); + widget->Close(); } } @@ -214,7 +137,10 @@ void WmWindowMus::CloseWidget() { bool WmWindowMus::CanActivate() const { // TODO(sky): this isn't quite right. Should key off CanFocus(), which is not // replicated. - return WmWindowAura::CanActivate() && widget_ != nullptr; + // TODO(sky): fix const cast (most likely remove this override entirely). + return WmWindowAura::CanActivate() && + views::Widget::GetWidgetForNativeView( + const_cast(aura_window())) != nullptr; } void WmWindowMus::ShowResizeShadow(int component) { @@ -240,29 +166,6 @@ void WmWindowMus::SetBoundsInScreenBehaviorForChildren( child_bounds_in_screen_behavior_ = behavior; } -void WmWindowMus::SetSnapsChildrenToPhysicalPixelBoundary() { - if (snap_children_to_pixel_boundary_) - return; - - snap_children_to_pixel_boundary_ = true; - for (auto& observer : observers()) { - observer.OnWindowPropertyChanged( - this, WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY); - } -} - -void WmWindowMus::SnapToPixelBoundaryIfNecessary() { - WmWindowMus* parent = Get(aura_window()->parent()); - if (parent && parent->snap_children_to_pixel_boundary_) { - // TODO: implement snap to pixel: http://crbug.com/615554. - NOTIMPLEMENTED(); - } -} - -void WmWindowMus::SetChildrenUseExtendedHitRegion() { - children_use_extended_hit_region_ = true; -} - void WmWindowMus::AddLimitedPreTargetHandler(ui::EventHandler* handler) { DCHECK(WmShellMus::Get()->window_tree_client()->WasCreatedByThisClient( aura::WindowMus::Get(aura_window()))); diff --git a/ash/mus/bridge/wm_window_mus.h b/ash/mus/bridge/wm_window_mus.h index 4b88c5ff4126cc..3a910d97746d03 100644 --- a/ash/mus/bridge/wm_window_mus.h +++ b/ash/mus/bridge/wm_window_mus.h @@ -22,7 +22,6 @@ namespace ash { namespace mus { class WmRootWindowControllerMus; -class WmWindowMusTestApi; // WmWindow implementation for mus. // @@ -30,22 +29,6 @@ class WmWindowMusTestApi; // as an owned property). class WmWindowMus : public WmWindowAura { public: - // Indicates the source of the widget creation. - enum class WidgetCreationType { - // The widget was created internally, and not at the request of a client. - // For example, overview mode creates a number of widgets. These widgets are - // created with a type of INTERNAL. - INTERNAL, - - // The widget was created for a client. In other words there is a client - // embedded in the aura::Window. For example, when Chrome creates a new - // browser window the window manager is asked to create the aura::Window. - // The window manager creates an aura::Window and a views::Widget to show - // the non-client frame decorations. In this case the creation type is - // FOR_CLIENT. - FOR_CLIENT, - }; - explicit WmWindowMus(aura::Window* window); // NOTE: this class is owned by the corresponding window. You shouldn't delete // TODO(sky): friend deleter and make private. @@ -60,13 +43,6 @@ class WmWindowMus : public WmWindowAura { static WmWindowMus* Get(views::Widget* widget); - // Sets the widget associated with the window. The widget is used to query - // state, such as min/max size. The widget is not owned by the WmWindowMus. - void set_widget(views::Widget* widget, WidgetCreationType type) { - widget_ = widget; - widget_creation_type_ = type; - } - WmRootWindowControllerMus* GetRootWindowControllerMus() { return const_cast( const_cast(this)->GetRootWindowControllerMus()); @@ -80,32 +56,17 @@ class WmWindowMus : public WmWindowAura { return static_cast(window); } - // See description of |children_use_extended_hit_region_|. - bool ShouldUseExtendedHitRegion() const; - // Returns true if this window is considered a shell window container. bool IsContainer() const; // WmWindow: - const WmWindow* GetRootWindow() const override; WmRootWindowController* GetRootWindowController() override; WmShell* GetShell() const override; - bool IsBubble() override; - bool HasNonClientArea() override; - int GetNonClientComponent(const gfx::Point& location) override; - gfx::Size GetMinimumSize() const override; - gfx::Size GetMaximumSize() const override; - gfx::Rect GetMinimizeAnimationTargetBoundsInScreen() const override; - bool IsSystemModal() const override; - bool GetBoolProperty(WmWindowProperty key) override; int GetIntProperty(WmWindowProperty key) override; - WmWindow* GetToplevelWindow() override; - WmWindow* GetToplevelWindowForFocus() override; bool MoveToEventRoot(const ui::Event& event) override; void SetBoundsInScreen(const gfx::Rect& bounds_in_screen, const display::Display& dst_display) override; void SetPinned(bool trusted) override; - views::Widget* GetInternalWidget() override; void CloseWidget() override; bool CanActivate() const override; void ShowResizeShadow(int component) override; @@ -114,30 +75,9 @@ class WmWindowMus : public WmWindowAura { ImmersiveFullscreenController* immersive_fullscreen_controller) override; void SetBoundsInScreenBehaviorForChildren( BoundsInScreenBehavior behavior) override; - void SetSnapsChildrenToPhysicalPixelBoundary() override; - void SnapToPixelBoundaryIfNecessary() override; - void SetChildrenUseExtendedHitRegion() override; void AddLimitedPreTargetHandler(ui::EventHandler* handler) override; private: - friend class WmWindowMusTestApi; - - views::Widget* widget_ = nullptr; - - WidgetCreationType widget_creation_type_ = WidgetCreationType::INTERNAL; - - bool snap_children_to_pixel_boundary_ = false; - - // If true child windows should get a slightly larger hit region to make - // resizing easier. - bool children_use_extended_hit_region_ = false; - - // Default value for |use_empty_minimum_size_for_testing_|. - static bool default_use_empty_minimum_size_for_testing_; - - // If true the minimum size is 0x0, default is minimum size comes from widget. - bool use_empty_minimum_size_for_testing_ = false; - BoundsInScreenBehavior child_bounds_in_screen_behavior_ = BoundsInScreenBehavior::USE_LOCAL_COORDINATES; diff --git a/ash/mus/bridge/wm_window_mus_test_api.cc b/ash/mus/bridge/wm_window_mus_test_api.cc deleted file mode 100644 index d6396b7a2b5fc8..00000000000000 --- a/ash/mus/bridge/wm_window_mus_test_api.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ash/mus/bridge/wm_window_mus_test_api.h" - -namespace ash { -namespace mus { - -// static -int WmWindowMusTestApi::GlobalMinimumSizeLock::instance_count_ = 0; - -WmWindowMusTestApi::GlobalMinimumSizeLock::GlobalMinimumSizeLock() { - if (instance_count_ == 0) - WmWindowMusTestApi::SetDefaultUseEmptyMinimumSizeForTesting(true); - instance_count_++; -} - -WmWindowMusTestApi::GlobalMinimumSizeLock::~GlobalMinimumSizeLock() { - DCHECK_GT(instance_count_, 0); - instance_count_--; - if (instance_count_ == 0) - WmWindowMusTestApi::SetDefaultUseEmptyMinimumSizeForTesting(false); -} - -// static -void WmWindowMusTestApi::SetDefaultUseEmptyMinimumSizeForTesting(bool value) { - WmWindowMus::default_use_empty_minimum_size_for_testing_ = value; -} - -} // namespace mus -} // namespace ash diff --git a/ash/mus/non_client_frame_controller.cc b/ash/mus/non_client_frame_controller.cc index af31cec668f1e3..58cdbf84ec832a 100644 --- a/ash/mus/non_client_frame_controller.cc +++ b/ash/mus/non_client_frame_controller.cc @@ -23,6 +23,7 @@ #include "ash/mus/window_manager.h" #include "ash/mus/window_properties.h" #include "ash/shared/immersive_fullscreen_controller_delegate.h" +#include "ash/wm/window_properties.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" @@ -307,8 +308,7 @@ NonClientFrameController::NonClientFrameController( widget_, window_manager_client_, ShouldRemoveStandardFrame(*properties), ShouldEnableImmersive(*properties)); window_ = native_widget->GetNativeView(); - WmWindowMus* wm_window = WmWindowMus::Get(window_); - wm_window->set_widget(widget_, WmWindowMus::WidgetCreationType::FOR_CLIENT); + window_->SetProperty(kWidgetCreationTypeKey, WidgetCreationType::FOR_CLIENT); window_->AddObserver(this); params.native_widget = native_widget; aura::SetWindowType(window_, window_type); @@ -329,6 +329,7 @@ NonClientFrameController::NonClientFrameController( const int shadow_inset = Shadow::GetInteriorInsetForStyle(Shadow::STYLE_ACTIVE); + WmWindowMus* wm_window = WmWindowMus::Get(window_); const gfx::Insets extended_hit_region = wm_window->ShouldUseExtendedHitRegion() ? GetExtendedHitRegion() : gfx::Insets(); diff --git a/ash/mus/test/wm_test_base.cc b/ash/mus/test/wm_test_base.cc index e247c8834c875b..71795527ebb40a 100644 --- a/ash/mus/test/wm_test_base.cc +++ b/ash/mus/test/wm_test_base.cc @@ -7,11 +7,11 @@ #include #include -#include "ash/mus/bridge/wm_window_mus_test_api.h" #include "ash/mus/root_window_controller.h" #include "ash/mus/test/wm_test_helper.h" #include "ash/mus/window_manager.h" #include "ash/mus/window_manager_application.h" +#include "ash/test/wm_window_aura_test_api.h" #include "base/memory/ptr_util.h" #include "services/ui/public/cpp/property_type_converters.h" #include "ui/aura/mus/property_converter.h" @@ -162,7 +162,7 @@ void WmTestBase::SetUp() { ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); // Most tests expect a minimum size of 0x0. minimum_size_lock_ = - base::MakeUnique(); + base::MakeUnique(); test_helper_.reset(new WmTestHelper); test_helper_->Init(); } diff --git a/ash/mus/test/wm_test_base.h b/ash/mus/test/wm_test_base.h index 7f750502ea53a7..24e2c620cc29cd 100644 --- a/ash/mus/test/wm_test_base.h +++ b/ash/mus/test/wm_test_base.h @@ -8,7 +8,7 @@ #include #include -#include "ash/mus/bridge/wm_window_mus_test_api.h" +#include "ash/test/wm_window_aura_test_api.h" #include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/display.h" @@ -85,7 +85,8 @@ class WmTestBase : public testing::Test { bool setup_called_ = false; bool teardown_called_ = false; std::unique_ptr zero_duration_mode_; - std::unique_ptr minimum_size_lock_; + std::unique_ptr + minimum_size_lock_; std::unique_ptr test_helper_; DISALLOW_COPY_AND_ASSIGN(WmTestBase); diff --git a/ash/test/BUILD.gn b/ash/test/BUILD.gn index a7baad01a99389..1d81b709a4f78d 100644 --- a/ash/test/BUILD.gn +++ b/ash/test/BUILD.gn @@ -134,6 +134,8 @@ static_library("test_support_common") { "ui_controls_factory_ash.h", "user_metrics_recorder_test_api.cc", "user_metrics_recorder_test_api.h", + "wm_window_aura_test_api.cc", + "wm_window_aura_test_api.h", ] configs += [ "//build/config:precompiled_headers" ] diff --git a/ash/test/wm_window_aura_test_api.cc b/ash/test/wm_window_aura_test_api.cc new file mode 100644 index 00000000000000..835f1b1671198d --- /dev/null +++ b/ash/test/wm_window_aura_test_api.cc @@ -0,0 +1,30 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/test/wm_window_aura_test_api.h" + +namespace ash { + +// static +int WmWindowAuraTestApi::GlobalMinimumSizeLock::instance_count_ = 0; + +WmWindowAuraTestApi::GlobalMinimumSizeLock::GlobalMinimumSizeLock() { + if (instance_count_ == 0) + WmWindowAuraTestApi::SetDefaultUseEmptyMinimumSizeForTesting(true); + instance_count_++; +} + +WmWindowAuraTestApi::GlobalMinimumSizeLock::~GlobalMinimumSizeLock() { + DCHECK_GT(instance_count_, 0); + instance_count_--; + if (instance_count_ == 0) + WmWindowAuraTestApi::SetDefaultUseEmptyMinimumSizeForTesting(false); +} + +// static +void WmWindowAuraTestApi::SetDefaultUseEmptyMinimumSizeForTesting(bool value) { + WmWindowAura::default_use_empty_minimum_size_for_testing_ = value; +} + +} // namespace ash diff --git a/ash/mus/bridge/wm_window_mus_test_api.h b/ash/test/wm_window_aura_test_api.h similarity index 63% rename from ash/mus/bridge/wm_window_mus_test_api.h rename to ash/test/wm_window_aura_test_api.h index b346d84c0dcd2e..aeacd8b4e45dc5 100644 --- a/ash/mus/bridge/wm_window_mus_test_api.h +++ b/ash/test/wm_window_aura_test_api.h @@ -2,15 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ASH_MUS_BRIDGE_WM_WINDOW_MUS_TEST_API_H_ -#define ASH_MUS_BRIDGE_WM_WINDOW_MUS_TEST_API_H_ +#ifndef ASH_TEST_WM_WINDOW_AURA_TEST_API_H_ +#define ASH_TEST_WM_WINDOW_AURA_TEST_API_H_ -#include "ash/mus/bridge/wm_window_mus.h" +#include "ash/aura/wm_window_aura.h" namespace ash { -namespace mus { -class WmWindowMusTestApi { +class WmWindowAuraTestApi { public: // Used by tests to set the default value of // |WmWindowMus::default_use_empty_minimum_size_for_testing_|. This is needed @@ -28,10 +27,10 @@ class WmWindowMusTestApi { DISALLOW_COPY_AND_ASSIGN(GlobalMinimumSizeLock); }; - explicit WmWindowMusTestApi(WmWindow* window) - : WmWindowMusTestApi(WmWindowMus::AsWmWindowMus(window)) {} - explicit WmWindowMusTestApi(WmWindowMus* window) : window_(window) {} - ~WmWindowMusTestApi() {} + explicit WmWindowAuraTestApi(WmWindow* window) + : WmWindowAuraTestApi(static_cast(window)) {} + explicit WmWindowAuraTestApi(WmWindowAura* window) : window_(window) {} + ~WmWindowAuraTestApi() {} void set_use_empty_minimum_size(bool value) { window_->use_empty_minimum_size_for_testing_ = true; @@ -40,12 +39,11 @@ class WmWindowMusTestApi { private: static void SetDefaultUseEmptyMinimumSizeForTesting(bool value); - WmWindowMus* window_; + WmWindowAura* window_; - DISALLOW_COPY_AND_ASSIGN(WmWindowMusTestApi); + DISALLOW_COPY_AND_ASSIGN(WmWindowAuraTestApi); }; -} // namespace mus } // namespace ash -#endif // ASH_MUS_BRIDGE_WM_WINDOW_MUS_TEST_API_H_ +#endif // ASH_TEST_WM_WINDOW_AURA_TEST_API_H_ diff --git a/ash/wm/window_properties.cc b/ash/wm/window_properties.cc index acc7202686f3a0..e4d4c3e4b51518 100644 --- a/ash/wm/window_properties.cc +++ b/ash/wm/window_properties.cc @@ -8,6 +8,7 @@ #include "ui/aura/window_property.h" DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WindowState*); +DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ASH_EXPORT, ash::WidgetCreationType); namespace ash { @@ -29,6 +30,10 @@ DEFINE_WINDOW_PROPERTY_KEY(bool, kSnapChildrenToPixelBoundary, false); DEFINE_WINDOW_PROPERTY_KEY(bool, kUsesScreenCoordinatesKey, false); +DEFINE_WINDOW_PROPERTY_KEY(WidgetCreationType, + kWidgetCreationTypeKey, + WidgetCreationType::INTERNAL); + DEFINE_OWNED_WINDOW_PROPERTY_KEY(wm::WindowState, kWindowStateKey, NULL); } // namespace ash diff --git a/ash/wm/window_properties.h b/ash/wm/window_properties.h index 3ec15c05c9b5d2..e4cf4dbf13bdb7 100644 --- a/ash/wm/window_properties.h +++ b/ash/wm/window_properties.h @@ -22,6 +22,22 @@ namespace wm { class WindowState; } // namespace wm +// Used with kWidgetCreationType to indicate source of the widget creation. +enum class WidgetCreationType { + // The widget was created internally, and not at the request of a client. + // For example, overview mode creates a number of widgets. These widgets are + // created with a type of INTERNAL. This is the default. + INTERNAL, + + // The widget was created for a client. In other words there is a client + // embedded in the aura::Window. For example, when Chrome creates a new + // browser window the window manager is asked to create the aura::Window. + // The window manager creates an aura::Window and a views::Widget to show + // the non-client frame decorations. In this case the creation type is + // FOR_CLIENT. + FOR_CLIENT, +}; + // Shell-specific window property keys; some keys are exported for use in tests. // Alphabetical sort. @@ -58,6 +74,9 @@ extern const aura::WindowProperty* const kSnapChildrenToPixelBoundary; // Property to tell if the container uses the screen coordinates. extern const aura::WindowProperty* const kUsesScreenCoordinatesKey; +ASH_EXPORT extern const aura::WindowProperty* const + kWidgetCreationTypeKey; + // A property key to store WindowState in the window. The window state // is owned by the window. extern const aura::WindowProperty* const kWindowStateKey; diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 419ed47c64eaea..e493ea209646fa 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -22,6 +22,7 @@ #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/window_parenting_client.h" #include "ui/aura/env.h" +#include "ui/aura/mus/property_utils.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_observer.h" @@ -141,7 +142,9 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { ownership_ = params.ownership; RegisterNativeWidgetForWindow(this, window_); - window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); + // MusClient has assertions that ui::mojom::WindowType matches + // views::Widget::InitParams::Type. + aura::SetWindowType(window_, static_cast(params.type)); window_->SetProperty(aura::client::kShowStateKey, params.show_state); if (params.type == Widget::InitParams::TYPE_BUBBLE) aura::client::SetHideOnDeactivate(window_, true);