Skip to content

Commit

Permalink
Adds WmLayoutManager and the aura wrapper AuraLayoutManagerAdapter
Browse files Browse the repository at this point in the history
No tests as ash_unittests is going to end up testing this by virtue
of converting some of the ash LayoutManagers to be WmLayoutManagers
and installing on aura::Windows.

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

Review URL: https://codereview.chromium.org/1894593002

Cr-Commit-Position: refs/heads/master@{#387686}
  • Loading branch information
sky authored and Commit bot committed Apr 15, 2016
1 parent decc15b commit d607862
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ash/ash.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@
'wm/ash_focus_rules.h',
'wm/ash_native_cursor_manager.cc',
'wm/ash_native_cursor_manager.h',
'wm/aura/aura_layout_manager_adapter.cc',
'wm/aura/aura_layout_manager_adapter.h',
'wm/aura/wm_root_window_controller_aura.cc',
'wm/aura/wm_root_window_controller_aura.h',
'wm/aura/wm_window_aura.cc',
Expand All @@ -531,6 +533,7 @@
'wm/boot_splash_screen_chromeos.h',
'wm/common/wm_event.cc',
'wm/common/wm_event.h',
'wm/common/wm_layout_manager.h',
'wm/common/wm_root_window_controller.h',
'wm/common/wm_screen_util.cc',
'wm/common/wm_screen_util.h',
Expand Down
51 changes: 51 additions & 0 deletions ash/wm/aura/aura_layout_manager_adapter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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/wm/aura/aura_layout_manager_adapter.h"

#include "ash/wm/aura/wm_window_aura.h"
#include "ash/wm/common/wm_layout_manager.h"

namespace ash {
namespace wm {

AuraLayoutManagerAdapter::AuraLayoutManagerAdapter(
std::unique_ptr<WmLayoutManager> wm_layout_manager)
: wm_layout_manager_(std::move(wm_layout_manager)) {}

AuraLayoutManagerAdapter::~AuraLayoutManagerAdapter() {}

void AuraLayoutManagerAdapter::OnWindowResized() {
wm_layout_manager_->OnWindowResized();
}

void AuraLayoutManagerAdapter::OnWindowAddedToLayout(aura::Window* child) {
wm_layout_manager_->OnWindowAddedToLayout(WmWindowAura::Get(child));
}

void AuraLayoutManagerAdapter::OnWillRemoveWindowFromLayout(
aura::Window* child) {
wm_layout_manager_->OnWillRemoveWindowFromLayout(WmWindowAura::Get(child));
}

void AuraLayoutManagerAdapter::OnWindowRemovedFromLayout(aura::Window* child) {
wm_layout_manager_->OnWindowRemovedFromLayout(WmWindowAura::Get(child));
}

void AuraLayoutManagerAdapter::OnChildWindowVisibilityChanged(
aura::Window* child,
bool visible) {
wm_layout_manager_->OnChildWindowVisibilityChanged(WmWindowAura::Get(child),
visible);
}

void AuraLayoutManagerAdapter::SetChildBounds(
aura::Window* child,
const gfx::Rect& requested_bounds) {
wm_layout_manager_->SetChildBounds(WmWindowAura::Get(child),
requested_bounds);
}

} // namespace wm
} // namespace ash
47 changes: 47 additions & 0 deletions ash/wm/aura/aura_layout_manager_adapter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

#ifndef ASH_WM_AURA_AURA_LAYOUT_MANAGER_ADAPTER_H_
#define ASH_WM_AURA_AURA_LAYOUT_MANAGER_ADAPTER_H_

#include <memory>

#include "ash/ash_export.h"
#include "base/macros.h"
#include "ui/aura/layout_manager.h"

namespace ash {
namespace wm {

class WmLayoutManager;

// AuraLayoutManagerAdapter is an aura::LayoutManager that calls to
// WmLayoutManager. Use it when you have a WmLayoutManager you want to use
// with an aura::Window.
class ASH_EXPORT AuraLayoutManagerAdapter : public aura::LayoutManager {
public:
explicit AuraLayoutManagerAdapter(
std::unique_ptr<WmLayoutManager> wm_layout_manager);
~AuraLayoutManagerAdapter() override;

// aura::LayoutManager:
void OnWindowResized() override;
void OnWindowAddedToLayout(aura::Window* child) override;
void OnWillRemoveWindowFromLayout(aura::Window* child) override;
void OnWindowRemovedFromLayout(aura::Window* child) override;
void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) override;
void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) override;

private:
std::unique_ptr<WmLayoutManager> wm_layout_manager_;

DISALLOW_COPY_AND_ASSIGN(AuraLayoutManagerAdapter);
};

} // namespace wm
} // namespace ash

#endif // ASH_WM_AURA_AURA_LAYOUT_MANAGER_ADAPTER_H_
57 changes: 57 additions & 0 deletions ash/wm/common/wm_layout_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.

#ifndef ASH_WM_COMMON_WM_LAYOUT_MANAGER_H_
#define ASH_WM_COMMON_WM_LAYOUT_MANAGER_H_

#include "ash/ash_export.h"

namespace gfx {
class Rect;
}

namespace ash {
namespace wm {

class WmWindow;

// Used to position the child WmWindows of a WmWindow. WmLayoutManager is called
// at key points in a WmWindows life cycle thats allow sthe WmLayoutManager to
// position or change child WmWindows.
class ASH_EXPORT WmLayoutManager {
public:
virtual ~WmLayoutManager() {}

// Invoked when the window the WmLayoutManager is associated with is resized.
virtual void OnWindowResized() = 0;

// Invoked when a window is added to the window the WmLayoutManager is
// associated with.
virtual void OnWindowAddedToLayout(WmWindow* child) = 0;

// Invoked prior to removing |child|.
virtual void OnWillRemoveWindowFromLayout(WmWindow* child) = 0;

// Invoked after removing |child|.
virtual void OnWindowRemovedFromLayout(WmWindow* child) = 0;

// Invoked when SetVisible() is invoked on |child|. |visible| is the value
// supplied to SetVisible(). If |visible| is true, child->IsVisible() may
// still return false. See description in aura::Window::IsVisible() for
// details.
virtual void OnChildWindowVisibilityChanged(WmWindow* child,
bool visibile) = 0;

// Invoked when WmWindow::SetBounds() is called on |child|. This allows the
// WmLayoutManager to modify the bounds as appropriate before processing the
// request, including ignoring the request. Implementation must call
// SetChildBoundsDirect() so that an infinite loop does not result.
virtual void SetChildBounds(WmWindow* child,
const gfx::Rect& requested_bounds) = 0;
};

} // namespace wm
} // namespace ash

#endif // ASH_WM_COMMON_WM_LAYOUT_MANAGER_H_

0 comments on commit d607862

Please sign in to comment.