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

Side by Side Diff: ash/display/resolution_notification_controller.cc

Issue 2196923002: Make ash::DisplayMode more like ui::DisplayMode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/display/resolution_notification_controller.h" 5 #include "ash/display/resolution_notification_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/common/display/display_info.h" 9 #include "ash/common/display/display_info.h"
10 #include "ash/common/system/system_notifier.h" 10 #include "ash/common/system/system_notifier.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 // static 88 // static
89 const int ResolutionNotificationController::kTimeoutInSec = 15; 89 const int ResolutionNotificationController::kTimeoutInSec = 15;
90 90
91 // static 91 // static
92 const char ResolutionNotificationController::kNotificationId[] = 92 const char ResolutionNotificationController::kNotificationId[] =
93 "chrome://settings/display/resolution"; 93 "chrome://settings/display/resolution";
94 94
95 struct ResolutionNotificationController::ResolutionChangeInfo { 95 struct ResolutionNotificationController::ResolutionChangeInfo {
96 ResolutionChangeInfo(int64_t display_id, 96 ResolutionChangeInfo(int64_t display_id,
97 const DisplayMode& old_resolution, 97 const scoped_refptr<DisplayMode>& old_resolution,
98 const DisplayMode& new_resolution, 98 const scoped_refptr<DisplayMode>& new_resolution,
99 const base::Closure& accept_callback); 99 const base::Closure& accept_callback);
100 ~ResolutionChangeInfo(); 100 ~ResolutionChangeInfo();
101 101
102 // The id of the display where the resolution change happens. 102 // The id of the display where the resolution change happens.
103 int64_t display_id; 103 int64_t display_id;
104 104
105 // The resolution before the change. 105 // The resolution before the change.
106 DisplayMode old_resolution; 106 scoped_refptr<DisplayMode> old_resolution;
107 107
108 // The requested resolution. Note that this may be different from 108 // The requested resolution. Note that this may be different from
109 // |current_resolution| which is the actual resolution set. 109 // |current_resolution| which is the actual resolution set.
110 DisplayMode new_resolution; 110 scoped_refptr<DisplayMode> new_resolution;
111 111
112 // The actual resolution after the change. 112 // The actual resolution after the change.
113 DisplayMode current_resolution; 113 scoped_refptr<DisplayMode> current_resolution;
114 114
115 // The callback when accept is chosen. 115 // The callback when accept is chosen.
116 base::Closure accept_callback; 116 base::Closure accept_callback;
117 117
118 // The remaining timeout in seconds. 0 if the change does not time out. 118 // The remaining timeout in seconds. 0 if the change does not time out.
119 uint8_t timeout_count; 119 uint8_t timeout_count;
120 120
121 // The timer to invoke OnTimerTick() every second. This cannot be 121 // The timer to invoke OnTimerTick() every second. This cannot be
122 // OneShotTimer since the message contains text "automatically closed in xx 122 // OneShotTimer since the message contains text "automatically closed in xx
123 // seconds..." which has to be updated every second. 123 // seconds..." which has to be updated every second.
124 base::RepeatingTimer timer; 124 base::RepeatingTimer timer;
125 125
126 private: 126 private:
127 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo); 127 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo);
128 }; 128 };
129 129
130 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo( 130 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo(
131 int64_t display_id, 131 int64_t display_id,
132 const DisplayMode& old_resolution, 132 const scoped_refptr<DisplayMode>& old_resolution,
133 const DisplayMode& new_resolution, 133 const scoped_refptr<DisplayMode>& new_resolution,
134 const base::Closure& accept_callback) 134 const base::Closure& accept_callback)
135 : display_id(display_id), 135 : display_id(display_id),
136 old_resolution(old_resolution), 136 old_resolution(old_resolution),
137 new_resolution(new_resolution), 137 new_resolution(new_resolution),
138 accept_callback(accept_callback), 138 accept_callback(accept_callback),
139 timeout_count(0) { 139 timeout_count(0) {
140 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 140 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
141 if (!display::Display::HasInternalDisplay() && 141 if (!display::Display::HasInternalDisplay() &&
142 display_manager->num_connected_displays() == 1u) { 142 display_manager->num_connected_displays() == 1u) {
143 timeout_count = kTimeoutInSec; 143 timeout_count = kTimeoutInSec;
144 } 144 }
145 } 145 }
146 146
147 ResolutionNotificationController::ResolutionChangeInfo:: 147 ResolutionNotificationController::ResolutionChangeInfo::
148 ~ResolutionChangeInfo() {} 148 ~ResolutionChangeInfo() {
149 old_resolution = nullptr;
150 new_resolution = nullptr;
151 current_resolution = nullptr;
152 }
149 153
150 ResolutionNotificationController::ResolutionNotificationController() { 154 ResolutionNotificationController::ResolutionNotificationController() {
151 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 155 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
152 display::Screen::GetScreen()->AddObserver(this); 156 display::Screen::GetScreen()->AddObserver(this);
153 } 157 }
154 158
155 ResolutionNotificationController::~ResolutionNotificationController() { 159 ResolutionNotificationController::~ResolutionNotificationController() {
156 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 160 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
157 display::Screen::GetScreen()->RemoveObserver(this); 161 display::Screen::GetScreen()->RemoveObserver(this);
158 } 162 }
159 163
160 void ResolutionNotificationController::PrepareNotification( 164 void ResolutionNotificationController::PrepareNotification(
161 int64_t display_id, 165 int64_t display_id,
162 const DisplayMode& old_resolution, 166 const scoped_refptr<DisplayMode>& old_resolution,
163 const DisplayMode& new_resolution, 167 const scoped_refptr<DisplayMode>& new_resolution,
164 const base::Closure& accept_callback) { 168 const base::Closure& accept_callback) {
169 DCHECK(old_resolution);
170 DCHECK(new_resolution);
171
165 DCHECK(!display::Display::IsInternalDisplayId(display_id)); 172 DCHECK(!display::Display::IsInternalDisplayId(display_id));
166 // If multiple resolution changes are invoked for the same display, 173 // If multiple resolution changes are invoked for the same display,
167 // the original resolution for the first resolution change has to be used 174 // the original resolution for the first resolution change has to be used
168 // instead of the specified |old_resolution|. 175 // instead of the specified |old_resolution|.
169 DisplayMode original_resolution; 176 scoped_refptr<DisplayMode> original_resolution;
170 if (change_info_ && change_info_->display_id == display_id) { 177 if (change_info_ && change_info_->display_id == display_id) {
171 DCHECK(change_info_->new_resolution.size == old_resolution.size); 178 DCHECK(change_info_->new_resolution->size() == old_resolution->size());
172 original_resolution = change_info_->old_resolution; 179 original_resolution = change_info_->old_resolution;
173 } 180 }
174 181
175 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, 182 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution,
176 new_resolution, accept_callback)); 183 new_resolution, accept_callback));
177 if (!original_resolution.size.IsEmpty()) 184 if (original_resolution && !original_resolution->size().IsEmpty())
178 change_info_->old_resolution = original_resolution; 185 change_info_->old_resolution = original_resolution;
179 } 186 }
180 187
181 bool ResolutionNotificationController::DoesNotificationTimeout() { 188 bool ResolutionNotificationController::DoesNotificationTimeout() {
182 return change_info_ && change_info_->timeout_count > 0; 189 return change_info_ && change_info_->timeout_count > 0;
183 } 190 }
184 191
185 void ResolutionNotificationController::CreateOrUpdateNotification( 192 void ResolutionNotificationController::CreateOrUpdateNotification(
186 bool enable_spoken_feedback) { 193 bool enable_spoken_feedback) {
187 message_center::MessageCenter* message_center = 194 message_center::MessageCenter* message_center =
(...skipping 16 matching lines...) Expand all
204 } 211 }
205 data.buttons.push_back(message_center::ButtonInfo( 212 data.buttons.push_back(message_center::ButtonInfo(
206 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); 213 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT)));
207 214
208 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; 215 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback;
209 216
210 const base::string16 display_name = base::UTF8ToUTF16( 217 const base::string16 display_name = base::UTF8ToUTF16(
211 Shell::GetInstance()->display_manager()->GetDisplayNameForId( 218 Shell::GetInstance()->display_manager()->GetDisplayNameForId(
212 change_info_->display_id)); 219 change_info_->display_id));
213 const base::string16 message = 220 const base::string16 message =
214 (change_info_->new_resolution.size == 221 (change_info_->new_resolution->size() ==
215 change_info_->current_resolution.size) 222 change_info_->current_resolution->size())
216 ? l10n_util::GetStringFUTF16( 223 ? l10n_util::GetStringFUTF16(
217 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, display_name, 224 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, display_name,
218 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString())) 225 base::UTF8ToUTF16(
226 change_info_->new_resolution->size().ToString()))
219 : l10n_util::GetStringFUTF16( 227 : l10n_util::GetStringFUTF16(
220 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, 228 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED,
221 display_name, 229 display_name,
222 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString()),
223 base::UTF8ToUTF16( 230 base::UTF8ToUTF16(
224 change_info_->current_resolution.size.ToString())); 231 change_info_->new_resolution->size().ToString()),
232 base::UTF8ToUTF16(
233 change_info_->current_resolution->size().ToString()));
225 234
226 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 235 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
227 std::unique_ptr<Notification> notification(new Notification( 236 std::unique_ptr<Notification> notification(new Notification(
228 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message, 237 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message,
229 timeout_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), 238 timeout_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
230 base::string16() /* display_source */, GURL(), 239 base::string16() /* display_source */, GURL(),
231 message_center::NotifierId( 240 message_center::NotifierId(
232 message_center::NotifierId::SYSTEM_COMPONENT, 241 message_center::NotifierId::SYSTEM_COMPONENT,
233 system_notifier::kNotifierDisplayResolutionChange), 242 system_notifier::kNotifierDisplayResolutionChange),
234 data, new ResolutionChangeNotificationDelegate( 243 data, new ResolutionChangeNotificationDelegate(
(...skipping 25 matching lines...) Expand all
260 change_info_.reset(); 269 change_info_.reset();
261 callback.Run(); 270 callback.Run();
262 } 271 }
263 272
264 void ResolutionNotificationController::RevertResolutionChange() { 273 void ResolutionNotificationController::RevertResolutionChange() {
265 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, 274 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId,
266 false /* by_user */); 275 false /* by_user */);
267 if (!change_info_) 276 if (!change_info_)
268 return; 277 return;
269 int64_t display_id = change_info_->display_id; 278 int64_t display_id = change_info_->display_id;
270 DisplayMode old_resolution = change_info_->old_resolution; 279 scoped_refptr<DisplayMode> old_resolution = change_info_->old_resolution;
271 change_info_.reset(); 280 change_info_.reset();
272 Shell::GetInstance()->display_manager()->SetDisplayMode(display_id, 281 Shell::GetInstance()->display_manager()->SetDisplayMode(display_id,
273 old_resolution); 282 old_resolution);
274 } 283 }
275 284
276 void ResolutionNotificationController::OnDisplayAdded( 285 void ResolutionNotificationController::OnDisplayAdded(
277 const display::Display& new_display) {} 286 const display::Display& new_display) {}
278 287
279 void ResolutionNotificationController::OnDisplayRemoved( 288 void ResolutionNotificationController::OnDisplayRemoved(
280 const display::Display& old_display) { 289 const display::Display& old_display) {
(...skipping 17 matching lines...) Expand all
298 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, 307 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this,
299 &ResolutionNotificationController::OnTimerTick); 308 &ResolutionNotificationController::OnTimerTick);
300 } 309 }
301 } 310 }
302 311
303 void ResolutionNotificationController::SuppressTimerForTest() { 312 void ResolutionNotificationController::SuppressTimerForTest() {
304 g_use_timer = false; 313 g_use_timer = false;
305 } 314 }
306 315
307 } // namespace ash 316 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698