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

Side by Side Diff: ui/views/mus/screen_mus.cc

Issue 1639563003: Renames WindowManagerConfig to FrameDecorationValues and moves to Display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 11 months 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/mus/screen_mus.h" 5 #include "ui/views/mus/screen_mus.h"
6 6
7 // #include "components/mus/public/interfaces/window_manager_constants.mojom.h"
7 #include "mojo/converters/geometry/geometry_type_converters.h" 8 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "mojo/shell/public/cpp/application_connection.h" 9 #include "mojo/shell/public/cpp/application_connection.h"
9 #include "mojo/shell/public/cpp/application_impl.h" 10 #include "mojo/shell/public/cpp/application_impl.h"
10 #include "ui/gfx/display_finder.h" 11 #include "ui/gfx/display_finder.h"
11 #include "ui/gfx/display_observer.h" 12 #include "ui/gfx/display_observer.h"
13 #include "ui/views/mus/screen_mus_delegate.h"
14 #include "ui/views/mus/window_manager_frame_values.h"
12 15
13 namespace mojo { 16 namespace mojo {
14 17
15 template <> 18 template <>
16 struct TypeConverter<gfx::Display, mus::mojom::DisplayPtr> { 19 struct TypeConverter<gfx::Display, mus::mojom::DisplayPtr> {
17 static gfx::Display Convert(const mus::mojom::DisplayPtr& input) { 20 static gfx::Display Convert(const mus::mojom::DisplayPtr& input) {
18 gfx::Display result(input->id, input->bounds.To<gfx::Rect>()); 21 gfx::Display result(input->id, input->bounds.To<gfx::Rect>());
19 result.set_work_area(input->work_area.To<gfx::Rect>()); 22 result.set_work_area(input->work_area.To<gfx::Rect>());
20 result.set_device_scale_factor(input->device_pixel_ratio); 23 result.set_device_scale_factor(input->device_pixel_ratio);
21 switch (input->rotation) { 24 switch (input->rotation) {
(...skipping 18 matching lines...) Expand all
40 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE); 43 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE);
41 break; 44 break;
42 case mus::mojom::TouchSupport::UNAVAILABLE: 45 case mus::mojom::TouchSupport::UNAVAILABLE:
43 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNAVAILABLE); 46 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNAVAILABLE);
44 break; 47 break;
45 } 48 }
46 return result; 49 return result;
47 } 50 }
48 }; 51 };
49 52
53 template <>
54 struct TypeConverter<views::WindowManagerFrameValues,
55 mus::mojom::FrameDecorationValuesPtr> {
56 static views::WindowManagerFrameValues Convert(
57 const mus::mojom::FrameDecorationValuesPtr& input) {
58 views::WindowManagerFrameValues result;
59 result.normal_insets = input->normal_client_area_insets.To<gfx::Insets>();
60 result.maximized_insets =
61 input->maximized_client_area_insets.To<gfx::Insets>();
62 result.max_title_bar_button_width = input->max_title_bar_button_width;
63 return result;
64 }
65 };
66
50 } // namespace mojo 67 } // namespace mojo
51 68
52 namespace views { 69 namespace views {
53 70
54 ScreenMus::ScreenMus() 71 ScreenMus::ScreenMus(ScreenMusDelegate* delegate)
55 : primary_display_index_(0), display_manager_observer_binding_(this) {} 72 : delegate_(delegate),
73 primary_display_index_(0),
74 display_manager_observer_binding_(this) {}
56 75
57 ScreenMus::~ScreenMus() {} 76 ScreenMus::~ScreenMus() {}
58 77
59 void ScreenMus::Init(mojo::ApplicationImpl* app) { 78 void ScreenMus::Init(mojo::ApplicationImpl* app) {
60 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, this); 79 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, this);
61 80
62 app->ConnectToService("mojo:mus", &display_manager_); 81 app->ConnectToService("mojo:mus", &display_manager_);
63 82
64 display_manager_->AddObserver( 83 display_manager_->AddObserver(
65 display_manager_observer_binding_.CreateInterfacePtrAndBind()); 84 display_manager_observer_binding_.CreateInterfacePtrAndBind());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void ScreenMus::RemoveObserver(gfx::DisplayObserver* observer) { 188 void ScreenMus::RemoveObserver(gfx::DisplayObserver* observer) {
170 observers_.RemoveObserver(observer); 189 observers_.RemoveObserver(observer);
171 } 190 }
172 191
173 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) { 192 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) {
174 // This should only be called once from Init() before any observers have been 193 // This should only be called once from Init() before any observers have been
175 // added. 194 // added.
176 DCHECK(displays_.empty()); 195 DCHECK(displays_.empty());
177 displays_ = displays.To<std::vector<gfx::Display>>(); 196 displays_ = displays.To<std::vector<gfx::Display>>();
178 for (size_t i = 0; i < displays.size(); ++i) { 197 for (size_t i = 0; i < displays.size(); ++i) {
179 if (displays[i]->is_primary) 198 if (displays[i]->is_primary) {
180 primary_display_index_ = static_cast<int>(i); 199 primary_display_index_ = static_cast<int>(i);
200 // TODO(sky): Make WindowManagerFrameValues per display.
201 WindowManagerFrameValues frame_values =
202 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>();
203 WindowManagerFrameValues::SetInstance(frame_values);
204 }
181 } 205 }
182 } 206 }
183 207
184 void ScreenMus::OnDisplaysChanged( 208 void ScreenMus::OnDisplaysChanged(
185 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { 209 mojo::Array<mus::mojom::DisplayPtr> transport_displays) {
186 for (size_t i = 0; i < transport_displays.size(); ++i) { 210 for (size_t i = 0; i < transport_displays.size(); ++i) {
187 const bool is_primary = transport_displays[i]->is_primary; 211 const bool is_primary = transport_displays[i]->is_primary;
188 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary); 212 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary);
213 if (is_primary) {
214 WindowManagerFrameValues frame_values =
215 transport_displays[i]
216 ->frame_decoration_values.To<WindowManagerFrameValues>();
217 WindowManagerFrameValues::SetInstance(frame_values);
218 delegate_->OnWindowManagerFrameValuesChanged();
219 }
189 } 220 }
190 } 221 }
191 222
192 void ScreenMus::OnDisplayRemoved(int64_t id) { 223 void ScreenMus::OnDisplayRemoved(int64_t id) {
193 const int index = FindDisplayIndexById(id); 224 const int index = FindDisplayIndexById(id);
194 DCHECK_NE(-1, index); 225 DCHECK_NE(-1, index);
195 // Another display must become primary before the existing primary is 226 // Another display must become primary before the existing primary is
196 // removed. 227 // removed.
197 DCHECK_NE(index, primary_display_index_); 228 DCHECK_NE(index, primary_display_index_);
198 const gfx::Display display = displays_[index]; 229 const gfx::Display display = displays_[index];
199 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, 230 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_,
200 OnDisplayRemoved(display)); 231 OnDisplayRemoved(display));
201 } 232 }
202 233
203 } // namespace views 234 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698