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

Side by Side Diff: services/ui/ws/user_display_manager.cc

Issue 2897303002: chromeos: Changes DisplayManagerObserver to have a single function (Closed)
Patch Set: fix compile Created 3 years, 7 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 | « services/ui/ws/user_display_manager.h ('k') | services/ui/ws/user_display_manager_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 #include "services/ui/ws/user_display_manager.h" 5 #include "services/ui/ws/user_display_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "services/ui/ws/user_display_manager_delegate.h" 9 #include "services/ui/ws/user_display_manager_delegate.h"
10 #include "ui/display/display.h" 10 #include "ui/display/display.h"
11 #include "ui/display/screen.h" 11 #include "ui/display/screen.h"
12 #include "ui/display/types/display_constants.h" 12 #include "ui/display/types/display_constants.h"
13 13
14 namespace ui { 14 namespace ui {
15 namespace ws { 15 namespace ws {
16 namespace { 16 namespace {
17 17
18 std::vector<mojom::WsDisplayPtr> CloneDisplays(
19 const std::vector<mojom::WsDisplayPtr>& input) {
20 std::vector<mojom::WsDisplayPtr> result;
21 result.reserve(input.size());
22 for (const auto& display : input) {
23 result.push_back(display.Clone());
24 }
25 return result;
26 }
27
28 int64_t GetInternalDisplayId() { 18 int64_t GetInternalDisplayId() {
29 if (!display::Display::HasInternalDisplay()) 19 if (!display::Display::HasInternalDisplay())
30 return display::kInvalidDisplayId; 20 return display::kInvalidDisplayId;
31 21
32 return display::Display::InternalDisplayId(); 22 return display::Display::InternalDisplayId();
33 } 23 }
34 24
35 } // namespace 25 } // namespace
36 26
37 UserDisplayManager::UserDisplayManager(UserDisplayManagerDelegate* delegate, 27 UserDisplayManager::UserDisplayManager(UserDisplayManagerDelegate* delegate,
38 const UserId& user_id) 28 const UserId& user_id)
39 : delegate_(delegate), 29 : delegate_(delegate),
40 user_id_(user_id), 30 user_id_(user_id),
41 got_valid_frame_decorations_( 31 got_valid_frame_decorations_(
42 delegate->GetFrameDecorationsForUser(user_id, nullptr)) {} 32 delegate->GetFrameDecorationsForUser(user_id, nullptr)) {}
43 33
44 UserDisplayManager::~UserDisplayManager() {} 34 UserDisplayManager::~UserDisplayManager() {}
45 35
46 void UserDisplayManager::OnFrameDecorationValuesChanged() { 36 void UserDisplayManager::OnFrameDecorationValuesChanged() {
47 if (!got_valid_frame_decorations_) { 37 got_valid_frame_decorations_ = true;
48 got_valid_frame_decorations_ = true; 38 CallOnDisplaysChangedIfNecessary();
49 display_manager_observers_.ForAllPtrs([this](
50 mojom::DisplayManagerObserver* observer) { CallOnDisplays(observer); });
51 return;
52 }
53
54 std::vector<mojom::WsDisplayPtr> displays = GetAllDisplays();
55 display_manager_observers_.ForAllPtrs(
56 [&displays](mojom::DisplayManagerObserver* observer) {
57 observer->OnDisplaysChanged(CloneDisplays(displays));
58 });
59 } 39 }
60 40
61 void UserDisplayManager::AddDisplayManagerBinding( 41 void UserDisplayManager::AddDisplayManagerBinding(
62 mojo::InterfaceRequest<mojom::DisplayManager> request) { 42 mojo::InterfaceRequest<mojom::DisplayManager> request) {
63 display_manager_bindings_.AddBinding(this, std::move(request)); 43 display_manager_bindings_.AddBinding(this, std::move(request));
64 } 44 }
65 45
66 void UserDisplayManager::OnDisplayUpdate(const display::Display& display) { 46 void UserDisplayManager::OnDisplayUpdated(const display::Display& display) {
67 if (!got_valid_frame_decorations_) 47 CallOnDisplaysChangedIfNecessary();
68 return;
69
70 std::vector<mojom::WsDisplayPtr> displays(1);
71 displays[0] = ToWsDisplayPtr(display);
72
73 display_manager_observers_.ForAllPtrs(
74 [&displays](mojom::DisplayManagerObserver* observer) {
75 observer->OnDisplaysChanged(CloneDisplays(displays));
76 });
77 } 48 }
78 49
79 void UserDisplayManager::OnWillDestroyDisplay(int64_t display_id) { 50 void UserDisplayManager::OnDisplayDestroyed(int64_t display_id) {
80 if (!got_valid_frame_decorations_) 51 CallOnDisplaysChangedIfNecessary();
81 return;
82
83 display_manager_observers_.ForAllPtrs(
84 [display_id](mojom::DisplayManagerObserver* observer) {
85 observer->OnDisplayRemoved(display_id);
86 });
87 } 52 }
88 53
89 void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) { 54 void UserDisplayManager::OnPrimaryDisplayChanged(int64_t primary_display_id) {
90 if (!got_valid_frame_decorations_) 55 CallOnDisplaysChangedIfNecessary();
91 return;
92
93 display_manager_observers_.ForAllPtrs(
94 [primary_display_id](mojom::DisplayManagerObserver* observer) {
95 observer->OnPrimaryDisplayChanged(primary_display_id);
96 });
97 } 56 }
98 57
99 void UserDisplayManager::AddObserver( 58 void UserDisplayManager::AddObserver(
100 mojom::DisplayManagerObserverPtr observer) { 59 mojom::DisplayManagerObserverPtr observer) {
101 mojom::DisplayManagerObserver* observer_impl = observer.get(); 60 mojom::DisplayManagerObserver* observer_impl = observer.get();
102 display_manager_observers_.AddPtr(std::move(observer)); 61 display_manager_observers_.AddPtr(std::move(observer));
103 OnObserverAdded(observer_impl); 62 OnObserverAdded(observer_impl);
104 } 63 }
105 64
106 void UserDisplayManager::OnObserverAdded( 65 void UserDisplayManager::OnObserverAdded(
107 mojom::DisplayManagerObserver* observer) { 66 mojom::DisplayManagerObserver* observer) {
108 // Many clients key off the frame decorations to size widgets. Wait for frame 67 // Many clients key off the frame decorations to size widgets. Wait for frame
109 // decorations before notifying so that we don't have to worry about clients 68 // decorations before notifying so that we don't have to worry about clients
110 // resizing appropriately. 69 // resizing appropriately.
111 if (!got_valid_frame_decorations_) 70 if (!ShouldCallOnDisplaysChanged())
112 return; 71 return;
113 72
114 CallOnDisplays(observer); 73 CallOnDisplaysChanged(observer);
115 } 74 }
116 75
117 mojom::WsDisplayPtr UserDisplayManager::ToWsDisplayPtr( 76 mojom::WsDisplayPtr UserDisplayManager::ToWsDisplayPtr(
118 const display::Display& display) { 77 const display::Display& display) {
119 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New(); 78 mojom::WsDisplayPtr ws_display = mojom::WsDisplay::New();
120 ws_display->display = display; 79 ws_display->display = display;
121 delegate_->GetFrameDecorationsForUser(user_id_, 80 delegate_->GetFrameDecorationsForUser(user_id_,
122 &ws_display->frame_decoration_values); 81 &ws_display->frame_decoration_values);
123 return ws_display; 82 return ws_display;
124 } 83 }
125 84
126 std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() { 85 std::vector<mojom::WsDisplayPtr> UserDisplayManager::GetAllDisplays() {
127 const auto& displays = display::Screen::GetScreen()->GetAllDisplays(); 86 const auto& displays = display::Screen::GetScreen()->GetAllDisplays();
128 87
129 std::vector<mojom::WsDisplayPtr> ws_display; 88 std::vector<mojom::WsDisplayPtr> ws_display;
130 ws_display.reserve(displays.size()); 89 ws_display.reserve(displays.size());
131 90
132 for (const auto& display : displays) 91 for (const auto& display : displays)
133 ws_display.push_back(ToWsDisplayPtr(display)); 92 ws_display.push_back(ToWsDisplayPtr(display));
134 93
135 return ws_display; 94 return ws_display;
136 } 95 }
137 96
138 void UserDisplayManager::CallOnDisplays( 97 bool UserDisplayManager::ShouldCallOnDisplaysChanged() const {
98 return got_valid_frame_decorations_ &&
99 !display::Screen::GetScreen()->GetAllDisplays().empty();
100 }
101
102 void UserDisplayManager::CallOnDisplaysChangedIfNecessary() {
103 if (!ShouldCallOnDisplaysChanged())
104 return;
105
106 display_manager_observers_.ForAllPtrs(
107 [this](mojom::DisplayManagerObserver* observer) {
108 CallOnDisplaysChanged(observer);
109 });
110 }
111
112 void UserDisplayManager::CallOnDisplaysChanged(
139 mojom::DisplayManagerObserver* observer) { 113 mojom::DisplayManagerObserver* observer) {
140 observer->OnDisplays(GetAllDisplays(), 114 observer->OnDisplaysChanged(
141 display::Screen::GetScreen()->GetPrimaryDisplay().id(), 115 GetAllDisplays(), display::Screen::GetScreen()->GetPrimaryDisplay().id(),
142 GetInternalDisplayId()); 116 GetInternalDisplayId());
143 } 117 }
144 118
145 } // namespace ws 119 } // namespace ws
146 } // namespace ui 120 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/user_display_manager.h ('k') | services/ui/ws/user_display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698