blob: 256fa140e13827fd69aad8837c008449522afa00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright 2015 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 "components/mus/example/wm/window_manager_impl.h"
#include "components/mus/example/wm/container.h"
#include "components/mus/example/wm/window_manager_application.h"
#include "components/mus/public/cpp/types.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_tree_connection.h"
namespace {
mus::Id GetWindowIdForContainer(mus::WindowTreeConnection* connection,
Container container) {
return connection->GetConnectionId() << 16 | static_cast<uint16>(container);
}
} // namespace
WindowManagerImpl::WindowManagerImpl(
WindowManagerApplication* state,
mojo::InterfaceRequest<mus::mojom::WindowManager> request)
: state_(state),
binding_(this, request.Pass()) {
}
WindowManagerImpl::~WindowManagerImpl() {}
void WindowManagerImpl::OpenWindow(mojo::ViewTreeClientPtr client) {
mus::Window* root = state_->root();
DCHECK(root);
mus::Id container_window_id =
GetWindowIdForContainer(root->connection(), Container::USER_WINDOWS);
mus::Window* container_window = root->GetChildById(container_window_id);
const int width = (root->bounds().width - 240);
const int height = (root->bounds().height - 240);
mus::Window* child_window = root->connection()->CreateWindow();
mojo::Rect bounds;
bounds.x = 40 + (state_->window_count() % 4) * 40;
bounds.y = 40 + (state_->window_count() % 4) * 40;
bounds.width = width;
bounds.height = height;
child_window->SetBounds(bounds);
container_window->AddChild(child_window);
child_window->Embed(client.Pass());
state_->IncrementWindowCount();
}
void WindowManagerImpl::CenterWindow(uint32_t window_id, mojo::SizePtr size) {
// TODO(beng):
}
void WindowManagerImpl::GetDisplays(const GetDisplaysCallback& callback) {
mojo::Array<mus::mojom::DisplayPtr> displays(1);
displays[0] = mus::mojom::Display::New();
displays[0]->id = 2001;
displays[0]->bounds = mojo::Rect::New();
displays[0]->bounds->y = 0;
displays[0]->bounds->width = state_->root()->bounds().width;
displays[0]->bounds->height = state_->root()->bounds().width;
displays[0]->work_area = displays[0]->bounds.Clone();
displays[0]->device_pixel_ratio =
state_->root()->viewport_metrics().device_pixel_ratio;
callback.Run(displays.Pass());
}
|