blob: 65681c93ec82b0ff7cb38acecfe5b63cb6715791 (
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/view.h"
#include "components/mus/public/cpp/view_tree_connection.h"
namespace {
mus::Id GetViewIdForContainer(mus::ViewTreeConnection* 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::View* root = state_->root();
DCHECK(root);
mus::Id container_view_id = GetViewIdForContainer(root->connection(),
Container::USER_WINDOWS);
mus::View* container_view = root->GetChildById(container_view_id);
const int width = (root->bounds().width - 240);
const int height = (root->bounds().height - 240);
mus::View* child_view = root->connection()->CreateView();
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_view->SetBounds(bounds);
container_view->AddChild(child_view);
child_view->Embed(client.Pass());
state_->IncrementWindowCount();
}
void WindowManagerImpl::CenterWindow(uint32_t view_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());
}
|