Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: mash/simple_wm/simple_wm.cc

Issue 2511233002: Add the beginning of a simple window manager that we'll support on Windows. (Closed)
Patch Set: . Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mash/simple_wm/simple_wm.h ('k') | ui/views/mus/aura_init.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "mash/simple_wm/simple_wm.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/display/screen_base.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/geometry/mojo/geometry.mojom.h"
12 #include "ui/views/controls/label.h"
13 #include "ui/views/mus/aura_init.h"
14 #include "ui/views/mus/mus_client.h"
15 #include "ui/views/widget/native_widget_aura.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h"
18 #include "ui/wm/core/default_activation_client.h"
19
20 namespace simple_wm {
21
22 namespace {
23
24 const int kNonClientTopHeight = 24;
25 const int kNonClientSize = 5;
26
27 } // namespace
28
29 class SimpleWM::FrameView : public views::WidgetDelegateView,
30 public aura::WindowObserver {
31 public:
32 explicit FrameView(aura::Window* client_window)
33 : client_window_(client_window) {
34 client_window_->AddObserver(this);
35 }
36 ~FrameView() override {}
37
38 private:
39 // views::WidgetDelegateView:
40 base::string16 GetWindowTitle() const override {
41 base::string16* title =
42 client_window_->GetProperty(aura::client::kTitleKey);
43 if (!title)
44 return base::UTF8ToUTF16("(Window)");
45 return *title;
46 }
47 void Layout() override {
48 // Client offsets are applied automatically by the window service.
49 gfx::Rect parent_bounds = GetWidget()->GetNativeWindow()->bounds();
50 parent_bounds.set_origin(gfx::Point());
51 client_window_->SetBounds(parent_bounds);
52 }
53
54 // aura::WindowObserver:
55 void OnWindowPropertyChanged(aura::Window* window, const void* key,
56 intptr_t old) override {
57 if (key == aura::client::kTitleKey)
58 GetWidget()->UpdateWindowTitle();
59 }
60
61 aura::Window* client_window_;
62
63 DISALLOW_COPY_AND_ASSIGN(FrameView);
64 };
65
66 SimpleWM::SimpleWM() {}
67
68 SimpleWM::~SimpleWM() {
69 // WindowTreeHost uses state from WindowTreeClient, so destroy it first.
70 window_tree_host_.reset();
71
72 // WindowTreeClient destruction may callback to us.
73 window_tree_client_.reset();
74
75 gpu_service_.reset();
76
77 display::Screen::SetScreenInstance(nullptr);
78 }
79
80 void SimpleWM::OnStart() {
81 CHECK(!started_);
82 started_ = true;
83 screen_ = base::MakeUnique<display::ScreenBase>();
84 display::Screen::SetScreenInstance(screen_.get());
85 aura_init_ = base::MakeUnique<views::AuraInit>(
86 context()->connector(), context()->identity(), "views_mus_resources.pak",
87 std::string(), nullptr, views::AuraInit::Mode::AURA_MUS_WINDOW_MANAGER);
88 gpu_service_ = ui::GpuService::Create(context()->connector(), nullptr);
89 compositor_context_factory_ =
90 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
91 aura::Env::GetInstance()->set_context_factory(
92 compositor_context_factory_.get());
93 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>(
94 context()->connector(), this, this);
95 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get());
96 window_tree_client_->ConnectAsWindowManager();
97 }
98
99 bool SimpleWM::OnConnect(
100 const service_manager::ServiceInfo& remote_info,
101 service_manager::InterfaceRegistry* registry) {
102 return true;
103 }
104
105 void SimpleWM::OnEmbed(
106 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
107 // WindowTreeClients configured as the window manager should never get
108 // OnEmbed().
109 NOTREACHED();
110 }
111
112 void SimpleWM::OnLostConnection(aura::WindowTreeClient* client) {
113 window_tree_host_.reset();
114 window_tree_client_.reset();
115 }
116
117 void SimpleWM::OnEmbedRootDestroyed(aura::Window* root) {
118 // WindowTreeClients configured as the window manager should never get
119 // OnEmbedRootDestroyed().
120 NOTREACHED();
121 }
122
123 void SimpleWM::OnPointerEventObserved(const ui::PointerEvent& event,
124 aura::Window* target) {
125 // Don't care.
126 }
127
128 aura::client::CaptureClient* SimpleWM::GetCaptureClient() {
129 return wm_state_.capture_controller();
130 }
131
132 aura::PropertyConverter* SimpleWM::GetPropertyConverter() {
133 return &property_converter_;
134 }
135
136 void SimpleWM::SetWindowManagerClient(
137 aura::WindowManagerClient* client) {
138 window_manager_client_ = client;
139 }
140
141 bool SimpleWM::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) {
142 FrameView* frame_view = GetFrameViewForClientWindow(window);
143 frame_view->GetWidget()->SetBounds(*bounds);
144 return true;
145 }
146
147 bool SimpleWM::OnWmSetProperty(
148 aura::Window* window,
149 const std::string& name,
150 std::unique_ptr<std::vector<uint8_t>>* new_data) {
151 return true;
152 }
153
154 aura::Window* SimpleWM::OnWmCreateTopLevelWindow(
155 ui::mojom::WindowType window_type,
156 std::map<std::string, std::vector<uint8_t>>* properties) {
157 aura::Window* client_window = new aura::Window(nullptr);
158 SetWindowType(client_window, window_type);
159 client_window->Init(ui::LAYER_NOT_DRAWN);
160
161 views::Widget* frame_widget = new views::Widget;
162 views::NativeWidgetAura* frame_native_widget =
163 new views::NativeWidgetAura(frame_widget, true);
164 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
165 FrameView* frame_view = new FrameView(client_window);
166 params.delegate = frame_view;
167 params.native_widget = frame_native_widget;
168 params.parent = root_;
169 params.bounds = gfx::Rect(10, 10, 500, 500);
170 frame_widget->Init(params);
171 frame_widget->Show();
172
173 frame_widget->GetNativeWindow()->AddChild(client_window);
174
175 client_window_to_frame_view_[client_window] = frame_view;
176 // TODO(beng): probably need to observe client_window from now on so we can
177 // clean up this map.
178
179 return client_window;
180 }
181
182 void SimpleWM::OnWmClientJankinessChanged(
183 const std::set<aura::Window*>& client_windows,
184 bool janky) {
185 // Don't care.
186 }
187
188 void SimpleWM::OnWmWillCreateDisplay(const display::Display& display) {
189 screen_->display_list().AddDisplay(display,
190 display::DisplayList::Type::PRIMARY);
191 }
192
193 void SimpleWM::OnWmNewDisplay(
194 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
195 const display::Display& display) {
196 // Only handles a single root.
197 DCHECK(!root_);
198 window_tree_host_ = std::move(window_tree_host);
199 window_tree_host_->InitCompositor();
200 root_ = window_tree_host_->window();
201 DCHECK(window_manager_client_);
202 window_manager_client_->AddActivationParent(root_);
203 ui::mojom::FrameDecorationValuesPtr frame_decoration_values =
204 ui::mojom::FrameDecorationValues::New();
205 frame_decoration_values->normal_client_area_insets.Set(
206 kNonClientTopHeight, kNonClientSize, kNonClientSize, kNonClientSize);
207 frame_decoration_values->max_title_bar_button_width = 0;
208 window_manager_client_->SetFrameDecorationValues(
209 std::move(frame_decoration_values));
210 new wm::DefaultActivationClient(root_);
211 aura::client::SetFocusClient(root_, &focus_client_);
212 }
213
214 void SimpleWM::OnWmDisplayRemoved(
215 aura::WindowTreeHostMus* window_tree_host) {
216 DCHECK_EQ(window_tree_host, window_tree_host_.get());
217 root_ = nullptr;
218 window_tree_host_.reset();
219 }
220
221 void SimpleWM::OnWmDisplayModified(const display::Display& display) {}
222
223 void SimpleWM::OnWmPerformMoveLoop(
224 aura::Window* window,
225 ui::mojom::MoveLoopSource source,
226 const gfx::Point& cursor_location,
227 const base::Callback<void(bool)>& on_done) {
228 // Don't care.
229 }
230
231 void SimpleWM::OnWmCancelMoveLoop(aura::Window* window) {}
232
233 void SimpleWM::OnWmSetClientArea(
234 aura::Window* window,
235 const gfx::Insets& insets,
236 const std::vector<gfx::Rect>& additional_client_areas) {}
237
238 SimpleWM::FrameView* SimpleWM::GetFrameViewForClientWindow(
239 aura::Window* client_window) {
240 auto it = client_window_to_frame_view_.find(client_window);
241 return it != client_window_to_frame_view_.end() ? it->second : nullptr;
242 }
243
244 } // namespace simple_wm
245
OLDNEW
« no previous file with comments | « mash/simple_wm/simple_wm.h ('k') | ui/views/mus/aura_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698