OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/mus/public/cpp/window.h" | |
6 #include "components/mus/public/cpp/window_manager_delegate.h" | |
7 #include "components/mus/public/cpp/window_tree_client.h" | |
8 #include "components/mus/public/cpp/window_tree_client_delegate.h" | |
9 #include "mojo/public/c/system/main.h" | |
10 #include "mojo/public/cpp/bindings/binding.h" | |
11 #include "services/shell/public/cpp/application_runner.h" | |
12 #include "services/shell/public/cpp/connector.h" | |
13 #include "services/shell/public/cpp/shell_client.h" | |
14 #include "ui/display/display.h" | |
15 #include "ui/display/mojo/display_type_converters.h" | |
16 | |
17 namespace mus { | |
18 namespace test { | |
19 | |
20 class TestWM : public shell::ShellClient, | |
21 public mus::WindowTreeClientDelegate, | |
22 public mus::WindowManagerDelegate { | |
23 public: | |
24 TestWM() {} | |
25 ~TestWM() override { delete window_tree_client_; } | |
26 | |
27 private: | |
28 // shell::ShellClient: | |
29 void Initialize(shell::Connector* connector, | |
30 const shell::Identity& identity, | |
31 uint32_t id) override { | |
32 window_tree_client_ = new mus::WindowTreeClient(this, this, nullptr); | |
33 window_tree_client_->ConnectAsWindowManager(connector); | |
34 } | |
35 bool AcceptConnection(shell::Connection* connection) override { | |
36 return true; | |
37 } | |
38 | |
39 // mus::WindowTreeClientDelegate: | |
40 void OnEmbed(mus::Window* root) override { | |
41 // WindowTreeClients configured as the window manager should never get | |
42 // OnEmbed(). | |
43 NOTREACHED(); | |
44 } | |
45 void OnDidDestroyClient(mus::WindowTreeClient* client) override { | |
46 window_tree_client_ = nullptr; | |
47 } | |
48 void OnEventObserved(const ui::Event& event, mus::Window* target) override { | |
49 // Don't care. | |
50 } | |
51 | |
52 // mus::WindowManagerDelegate: | |
53 void SetWindowManagerClient(mus::WindowManagerClient* client) override { | |
54 window_manager_client_ = client; | |
55 } | |
56 bool OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) override { | |
57 return true; | |
58 } | |
59 bool OnWmSetProperty( | |
60 mus::Window* window, | |
61 const std::string& name, | |
62 std::unique_ptr<std::vector<uint8_t>>* new_data) override { | |
63 return true; | |
64 } | |
65 mus::Window* OnWmCreateTopLevelWindow( | |
66 std::map<std::string, std::vector<uint8_t>>* properties) override { | |
67 mus::Window* window = root_->window_tree()->NewWindow(properties); | |
68 window->SetBounds(gfx::Rect(10, 10, 500, 500)); | |
69 root_->AddChild(window); | |
70 return window; | |
71 } | |
72 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, | |
73 bool janky) override { | |
74 // Don't care. | |
75 } | |
76 void OnWmNewDisplay(Window* window, | |
77 const display::Display& display) override { | |
78 // Only handles a single root. | |
79 DCHECK(!root_); | |
80 root_ = window; | |
81 DCHECK(window_manager_client_); | |
82 window_manager_client_->AddActivationParent(root_); | |
83 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = | |
84 mus::mojom::FrameDecorationValues::New(); | |
85 frame_decoration_values->max_title_bar_button_width = 0; | |
86 window_manager_client_->SetFrameDecorationValues( | |
87 std::move(frame_decoration_values)); | |
88 } | |
89 void OnAccelerator(uint32_t id, const ui::Event& event) override { | |
90 // Don't care. | |
91 } | |
92 | |
93 mus::Window* root_ = nullptr; | |
94 mus::WindowManagerClient* window_manager_client_ = nullptr; | |
95 // See WindowTreeClient for details on ownership. | |
96 mus::WindowTreeClient* window_tree_client_ = nullptr; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(TestWM); | |
99 }; | |
100 | |
101 } // namespace test | |
102 } // namespace mus | |
103 | |
104 MojoResult MojoMain(MojoHandle shell_handle) { | |
105 shell::ApplicationRunner runner(new mus::test::TestWM); | |
106 return runner.Run(shell_handle); | |
107 } | |
OLD | NEW |