summaryrefslogtreecommitdiffstats
path: root/mash/wm/window_manager_impl.cc
diff options
context:
space:
mode:
authorsadrul <sadrul@chromium.org>2015-11-30 15:30:48 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-30 23:31:31 +0000
commiteaa1be24985cd400134914461b05ab4e52e8ef01 (patch)
tree7d2bd104953d60618745ecceba4ba4ded306cfe8 /mash/wm/window_manager_impl.cc
parente28f8182df3ebb9eae725ffa1490fc51342a38e0 (diff)
downloadchromium_src-eaa1be24985cd400134914461b05ab4e52e8ef01.zip
chromium_src-eaa1be24985cd400134914461b05ab4e52e8ef01.tar.gz
chromium_src-eaa1be24985cd400134914461b05ab4e52e8ef01.tar.bz2
mash: Close a window if the app crashes.
BUG=none Review URL: https://codereview.chromium.org/1487453002 Cr-Commit-Position: refs/heads/master@{#362268}
Diffstat (limited to 'mash/wm/window_manager_impl.cc')
-rw-r--r--mash/wm/window_manager_impl.cc43
1 files changed, 35 insertions, 8 deletions
diff --git a/mash/wm/window_manager_impl.cc b/mash/wm/window_manager_impl.cc
index 761099f..1b15fc8 100644
--- a/mash/wm/window_manager_impl.cc
+++ b/mash/wm/window_manager_impl.cc
@@ -31,10 +31,12 @@ struct TypeConverter<const std::vector<uint8_t>, Array<uint8_t>> {
namespace mash {
namespace wm {
-WindowManagerImpl::WindowManagerImpl(WindowManagerApplication* state)
- : state_(state) {}
+WindowManagerImpl::WindowManagerImpl()
+ : state_(nullptr) {}
WindowManagerImpl::~WindowManagerImpl() {
+ if (!state_)
+ return;
mus::Window* parent =
state_->GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS);
if (!parent)
@@ -44,7 +46,16 @@ WindowManagerImpl::~WindowManagerImpl() {
child->RemoveObserver(this);
}
+void WindowManagerImpl::Initialize(WindowManagerApplication* state) {
+ DCHECK(state);
+ DCHECK(!state_);
+ state_ = state;
+ state_->GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS)
+ ->AddObserver(this);
+}
+
gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const {
+ DCHECK(state_);
int width, height;
const gfx::Size pref = GetWindowPreferredSize(window);
const mus::Window* root = state_->root();
@@ -62,12 +73,30 @@ gfx::Rect WindowManagerImpl::CalculateDefaultBounds(mus::Window* window) const {
}
gfx::Rect WindowManagerImpl::GetMaximizedWindowBounds() const {
+ DCHECK(state_);
return gfx::Rect(state_->root()->bounds().size());
}
+void WindowManagerImpl::OnTreeChanging(const TreeChangeParams& params) {
+ DCHECK(state_);
+ mus::Window* user_window_container =
+ state_->GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS);
+ if (params.receiver != user_window_container)
+ return;
+ if (params.old_parent == user_window_container)
+ params.target->RemoveObserver(this);
+ else if (params.new_parent == user_window_container)
+ params.target->AddObserver(this);
+}
+
+void WindowManagerImpl::OnWindowEmbeddedAppDisconnected(mus::Window* window) {
+ window->Destroy();
+}
+
void WindowManagerImpl::OpenWindow(
mus::mojom::WindowTreeClientPtr client,
mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
+ DCHECK(state_);
mus::Window* root = state_->root();
DCHECK(root);
@@ -76,7 +105,9 @@ void WindowManagerImpl::OpenWindow(
// TODO(sky): constrain to valid properties here.
mus::Window* child_window = root->connection()->NewWindow(&properties);
child_window->SetBounds(CalculateDefaultBounds(child_window));
- GetContainerForChild(child_window)->AddChild(child_window);
+
+ mojom::Container container = GetRequestedContainer(child_window);
+ state_->GetWindowForContainer(container)->AddChild(child_window);
child_window->Embed(client.Pass());
// NonClientFrameController deletes itself when |child_window| is destroyed.
@@ -87,6 +118,7 @@ void WindowManagerImpl::OpenWindow(
}
void WindowManagerImpl::GetConfig(const GetConfigCallback& callback) {
+ DCHECK(state_);
mus::mojom::WindowManagerConfigPtr config(
mus::mojom::WindowManagerConfig::New());
config->displays = mojo::Array<mus::mojom::DisplayPtr>::New(1);
@@ -128,10 +160,5 @@ bool WindowManagerImpl::OnWmSetProperty(
name == mus::mojom::WindowManager::kResizeBehavior_Property;
}
-mus::Window* WindowManagerImpl::GetContainerForChild(mus::Window* child) {
- mojom::Container container = GetRequestedContainer(child);
- return state_->GetWindowForContainer(container);
-}
-
} // namespace wm
} // namespace mash