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

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

Issue 2897303002: chromeos: Changes DisplayManagerObserver to have a single function (Closed)
Patch Set: fix compile Created 3 years, 6 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
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | ui/views/mus/screen_mus_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This has to be before any other includes, else default is picked up. 5 // This has to be before any other includes, else default is picked up.
6 // See base/logging for details on this. 6 // See base/logging for details on this.
7 #define NOTIMPLEMENTED_POLICY 5 7 #define NOTIMPLEMENTED_POLICY 5
8 8
9 #include "ui/views/mus/screen_mus.h" 9 #include "ui/views/mus/screen_mus.h"
10 10
11 #include "base/stl_util.h"
11 #include "services/service_manager/public/cpp/connector.h" 12 #include "services/service_manager/public/cpp/connector.h"
12 #include "services/ui/public/interfaces/constants.mojom.h" 13 #include "services/ui/public/interfaces/constants.mojom.h"
13 #include "ui/aura/env.h" 14 #include "ui/aura/env.h"
14 #include "ui/aura/mus/window_tree_host_mus.h" 15 #include "ui/aura/mus/window_tree_host_mus.h"
15 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
16 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/display/types/display_constants.h"
17 #include "ui/views/mus/screen_mus_delegate.h" 19 #include "ui/views/mus/screen_mus_delegate.h"
18 #include "ui/views/mus/window_manager_frame_values.h" 20 #include "ui/views/mus/window_manager_frame_values.h"
19 21
20 namespace mojo { 22 namespace mojo {
21 23
22 template <> 24 template <>
23 struct TypeConverter<views::WindowManagerFrameValues, 25 struct TypeConverter<views::WindowManagerFrameValues,
24 ui::mojom::FrameDecorationValuesPtr> { 26 ui::mojom::FrameDecorationValuesPtr> {
25 static views::WindowManagerFrameValues Convert( 27 static views::WindowManagerFrameValues Convert(
26 const ui::mojom::FrameDecorationValuesPtr& input) { 28 const ui::mojom::FrameDecorationValuesPtr& input) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 90
89 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { 91 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) {
90 return window && window->IsVisible() && 92 return window && window->IsVisible() &&
91 window->GetBoundsInScreen().Contains(GetCursorScreenPoint()); 93 window->GetBoundsInScreen().Contains(GetCursorScreenPoint());
92 } 94 }
93 95
94 aura::Window* ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) { 96 aura::Window* ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) {
95 return delegate_->GetWindowAtScreenPoint(point); 97 return delegate_->GetWindowAtScreenPoint(point);
96 } 98 }
97 99
98 void ScreenMus::OnDisplays(std::vector<ui::mojom::WsDisplayPtr> ws_displays, 100 void ScreenMus::OnDisplaysChanged(
99 int64_t primary_display_id, 101 std::vector<ui::mojom::WsDisplayPtr> ws_displays,
100 int64_t internal_display_id) { 102 int64_t primary_display_id,
101 // This should only be called once when ScreenMus is added as an observer. 103 int64_t internal_display_id) {
102 DCHECK(display_list().displays().empty()); 104 const bool primary_changed = primary_display_id != GetPrimaryDisplay().id();
103 105 int64_t handled_display_id = display::kInvalidDisplayId;
104 for (size_t i = 0; i < ws_displays.size(); ++i) { 106 const WindowManagerFrameValues initial_frame_values =
105 const display::Display& display = ws_displays[i]->display; 107 WindowManagerFrameValues::instance();
106 const bool is_primary = display.id() == primary_display_id;
107 display_list().AddDisplay(display,
108 is_primary ? Type::PRIMARY : Type::NOT_PRIMARY);
109 if (is_primary) {
110 // TODO(sky): Make WindowManagerFrameValues per display.
111 WindowManagerFrameValues frame_values =
112 ws_displays[i]
113 ->frame_decoration_values.To<WindowManagerFrameValues>();
114 WindowManagerFrameValues::SetInstance(frame_values);
115 }
116 }
117
118 DCHECK(display_list().GetPrimaryDisplayIterator() !=
119 display_list().displays().end());
120 108
121 if (internal_display_id != display::kInvalidDisplayId) 109 if (internal_display_id != display::kInvalidDisplayId)
122 display::Display::SetInternalDisplayId(internal_display_id); 110 display::Display::SetInternalDisplayId(internal_display_id);
123 111
124 DCHECK(!display_list().displays().empty()); 112 if (primary_changed) {
125 } 113 handled_display_id = primary_display_id;
114 for (auto& ws_display_ptr : ws_displays) {
115 if (ws_display_ptr->display.id() == primary_display_id) {
116 // TODO(sky): Make WindowManagerFrameValues per display.
117 WindowManagerFrameValues frame_values =
118 ws_display_ptr->frame_decoration_values
119 .To<WindowManagerFrameValues>();
120 WindowManagerFrameValues::SetInstance(frame_values);
126 121
127 void ScreenMus::OnDisplaysChanged( 122 const bool is_primary = true;
128 std::vector<ui::mojom::WsDisplayPtr> ws_displays) { 123 ProcessDisplayChanged(ws_display_ptr->display, is_primary);
129 for (size_t i = 0; i < ws_displays.size(); ++i) { 124 break;
130 const display::Display& display = ws_displays[i]->display; 125 }
131 const bool is_primary =
132 display.id() == display_list().GetPrimaryDisplayIterator()->id();
133 ProcessDisplayChanged(display, is_primary);
134 if (is_primary) {
135 WindowManagerFrameValues frame_values =
136 ws_displays[i]
137 ->frame_decoration_values.To<WindowManagerFrameValues>();
138 WindowManagerFrameValues::SetInstance(frame_values);
139 delegate_->OnWindowManagerFrameValuesChanged();
140 } 126 }
141 } 127 }
128
129 // Add new displays and update existing ones.
130 std::set<int64_t> display_ids;
131 for (auto& ws_display_ptr : ws_displays) {
132 display_ids.insert(ws_display_ptr->display.id());
133 if (handled_display_id == ws_display_ptr->display.id())
134 continue;
135
136 const bool is_primary = false;
137 ProcessDisplayChanged(ws_display_ptr->display, is_primary);
138 }
139
140 // Remove any displays no longer in |ws_displays|.
141 std::set<int64_t> existing_display_ids;
142 for (const auto& display : display_list().displays())
143 existing_display_ids.insert(display.id());
144 std::set<int64_t> removed_display_ids =
145 base::STLSetDifference<std::set<int64_t>>(existing_display_ids,
146 display_ids);
147 for (int64_t display_id : removed_display_ids) {
148 // TODO(kylechar): DisplayList would need to change to handle having no
149 // primary display.
150 if (display_id != GetPrimaryDisplay().id())
151 display_list().RemoveDisplay(display_id);
152 }
153
154 if (primary_changed &&
155 initial_frame_values != WindowManagerFrameValues::instance()) {
156 delegate_->OnWindowManagerFrameValuesChanged();
157 }
142 } 158 }
143 159
144 void ScreenMus::OnDisplayRemoved(int64_t display_id) {
145 display_list().RemoveDisplay(display_id);
146 }
147
148 void ScreenMus::OnPrimaryDisplayChanged(int64_t primary_display_id) {
149 // TODO(kylechar): DisplayList would need to change to handle having no
150 // primary display.
151 if (primary_display_id == display::kInvalidDisplayId)
152 return;
153
154 ProcessDisplayChanged(*display_list().FindDisplayById(primary_display_id),
155 true);
156 }
157
158 } // namespace views 160 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | ui/views/mus/screen_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698