Skip to content

Commit

Permalink
Removes/promotes functions from WmWindowMus to WmWindowAura
Browse files Browse the repository at this point in the history
The aura implementation for many of these can be used as is.

BUG=671246
TEST=none
R=jamescook@chromium.org

Review-Url: https://codereview.chromium.org/2613793002
Cr-Commit-Position: refs/heads/master@{#441689}
  • Loading branch information
sky authored and Commit bot committed Jan 5, 2017
1 parent 867f455 commit 307e358
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 264 deletions.
33 changes: 24 additions & 9 deletions ash/aura/wm_window_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<const WmWindowAura*>(parent)
->children_use_extended_hit_region_;
}

void WmWindowAura::Destroy() {
delete window_;
// WARNING: this has been deleted.
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<WmWindowObserver>::NOTIFY_EXISTING_ONLY) {
observers_(base::ObserverList<WmWindowObserver>::NOTIFY_EXISTING_ONLY),
use_empty_minimum_size_for_testing_(
default_use_empty_minimum_size_for_testing_) {
window_->AddObserver(this);
window_->SetProperty(kWmWindowKey, this);
}
Expand Down
18 changes: 17 additions & 1 deletion ash/aura/wm_window_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -219,13 +223,25 @@ class ASH_EXPORT WmWindowAura : public WmWindow,
aura::Window* transient) override;

private:
friend class WmWindowAuraTestApi;

aura::Window* window_;

base::ObserverList<WmWindowObserver> observers_;

bool added_transient_observer_ = false;
base::ObserverList<WmTransientWindowObserver> 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);
};

Expand Down
2 changes: 0 additions & 2 deletions ash/common/wm_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions ash/mus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
6 changes: 0 additions & 6 deletions ash/mus/bridge/wm_root_window_controller_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down Expand Up @@ -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(
Expand Down
17 changes: 0 additions & 17 deletions ash/mus/bridge/wm_shell_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 :
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions ash/mus/bridge/wm_shell_mus.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ImmersiveHandlerFactoryMus;
class WindowManager;
class WmRootWindowControllerMus;
class WmShellMusTestApi;
class WmWindowMus;

// WmShell implementation for mus.
class WmShellMus : public WmShell,
Expand All @@ -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() {
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 307e358

Please sign in to comment.