OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 ResolutionNotificationController* controller_; | 49 ResolutionNotificationController* controller_; |
50 bool has_timeout_; | 50 bool has_timeout_; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeNotificationDelegate); | 52 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeNotificationDelegate); |
53 }; | 53 }; |
54 | 54 |
55 ResolutionChangeNotificationDelegate::ResolutionChangeNotificationDelegate( | 55 ResolutionChangeNotificationDelegate::ResolutionChangeNotificationDelegate( |
56 ResolutionNotificationController* controller, | 56 ResolutionNotificationController* controller, |
57 bool has_timeout) | 57 bool has_timeout) |
58 : controller_(controller), | 58 : controller_(controller), has_timeout_(has_timeout) { |
59 has_timeout_(has_timeout) { | |
60 DCHECK(controller_); | 59 DCHECK(controller_); |
61 } | 60 } |
62 | 61 |
63 ResolutionChangeNotificationDelegate::~ResolutionChangeNotificationDelegate() { | 62 ResolutionChangeNotificationDelegate::~ResolutionChangeNotificationDelegate() {} |
64 } | |
65 | 63 |
66 void ResolutionChangeNotificationDelegate::Close(bool by_user) { | 64 void ResolutionChangeNotificationDelegate::Close(bool by_user) { |
67 if (by_user) | 65 if (by_user) |
68 controller_->AcceptResolutionChange(false); | 66 controller_->AcceptResolutionChange(false); |
69 } | 67 } |
70 | 68 |
71 void ResolutionChangeNotificationDelegate::Click() { | 69 void ResolutionChangeNotificationDelegate::Click() { |
72 controller_->AcceptResolutionChange(true); | 70 controller_->AcceptResolutionChange(true); |
73 } | 71 } |
74 | 72 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 accept_callback(accept_callback), | 138 accept_callback(accept_callback), |
141 timeout_count(0) { | 139 timeout_count(0) { |
142 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 140 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
143 if (!display::Display::HasInternalDisplay() && | 141 if (!display::Display::HasInternalDisplay() && |
144 display_manager->num_connected_displays() == 1u) { | 142 display_manager->num_connected_displays() == 1u) { |
145 timeout_count = kTimeoutInSec; | 143 timeout_count = kTimeoutInSec; |
146 } | 144 } |
147 } | 145 } |
148 | 146 |
149 ResolutionNotificationController::ResolutionChangeInfo:: | 147 ResolutionNotificationController::ResolutionChangeInfo:: |
150 ~ResolutionChangeInfo() { | 148 ~ResolutionChangeInfo() {} |
151 } | |
152 | 149 |
153 ResolutionNotificationController::ResolutionNotificationController() { | 150 ResolutionNotificationController::ResolutionNotificationController() { |
154 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 151 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
155 display::Screen::GetScreen()->AddObserver(this); | 152 display::Screen::GetScreen()->AddObserver(this); |
156 } | 153 } |
157 | 154 |
158 ResolutionNotificationController::~ResolutionNotificationController() { | 155 ResolutionNotificationController::~ResolutionNotificationController() { |
159 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 156 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
160 display::Screen::GetScreen()->RemoveObserver(this); | 157 display::Screen::GetScreen()->RemoveObserver(this); |
161 } | 158 } |
162 | 159 |
163 void ResolutionNotificationController::PrepareNotification( | 160 void ResolutionNotificationController::PrepareNotification( |
164 int64_t display_id, | 161 int64_t display_id, |
165 const DisplayMode& old_resolution, | 162 const DisplayMode& old_resolution, |
166 const DisplayMode& new_resolution, | 163 const DisplayMode& new_resolution, |
167 const base::Closure& accept_callback) { | 164 const base::Closure& accept_callback) { |
168 DCHECK(!display::Display::IsInternalDisplayId(display_id)); | 165 DCHECK(!display::Display::IsInternalDisplayId(display_id)); |
169 // If multiple resolution changes are invoked for the same display, | 166 // If multiple resolution changes are invoked for the same display, |
170 // the original resolution for the first resolution change has to be used | 167 // the original resolution for the first resolution change has to be used |
171 // instead of the specified |old_resolution|. | 168 // instead of the specified |old_resolution|. |
172 DisplayMode original_resolution; | 169 DisplayMode original_resolution; |
173 if (change_info_ && change_info_->display_id == display_id) { | 170 if (change_info_ && change_info_->display_id == display_id) { |
174 DCHECK(change_info_->new_resolution.size == old_resolution.size); | 171 DCHECK(change_info_->new_resolution.size == old_resolution.size); |
175 original_resolution = change_info_->old_resolution; | 172 original_resolution = change_info_->old_resolution; |
176 } | 173 } |
177 | 174 |
178 change_info_.reset(new ResolutionChangeInfo( | 175 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, |
179 display_id, old_resolution, new_resolution, accept_callback)); | 176 new_resolution, accept_callback)); |
180 if (!original_resolution.size.IsEmpty()) | 177 if (!original_resolution.size.IsEmpty()) |
181 change_info_->old_resolution = original_resolution; | 178 change_info_->old_resolution = original_resolution; |
182 } | 179 } |
183 | 180 |
184 bool ResolutionNotificationController::DoesNotificationTimeout() { | 181 bool ResolutionNotificationController::DoesNotificationTimeout() { |
185 return change_info_ && change_info_->timeout_count > 0; | 182 return change_info_ && change_info_->timeout_count > 0; |
186 } | 183 } |
187 | 184 |
188 void ResolutionNotificationController::CreateOrUpdateNotification( | 185 void ResolutionNotificationController::CreateOrUpdateNotification( |
189 bool enable_spoken_feedback) { | 186 bool enable_spoken_feedback) { |
190 message_center::MessageCenter* message_center = | 187 message_center::MessageCenter* message_center = |
191 message_center::MessageCenter::Get(); | 188 message_center::MessageCenter::Get(); |
192 if (!change_info_) { | 189 if (!change_info_) { |
193 message_center->RemoveNotification(kNotificationId, false /* by_user */); | 190 message_center->RemoveNotification(kNotificationId, false /* by_user */); |
194 return; | 191 return; |
195 } | 192 } |
196 | 193 |
197 base::string16 timeout_message; | 194 base::string16 timeout_message; |
198 message_center::RichNotificationData data; | 195 message_center::RichNotificationData data; |
199 if (change_info_->timeout_count > 0) { | 196 if (change_info_->timeout_count > 0) { |
200 data.buttons.push_back(message_center::ButtonInfo( | 197 data.buttons.push_back(message_center::ButtonInfo( |
201 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_ACCEPT))); | 198 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_ACCEPT))); |
202 timeout_message = l10n_util::GetStringFUTF16( | 199 timeout_message = l10n_util::GetStringFUTF16( |
203 IDS_ASH_DISPLAY_RESOLUTION_TIMEOUT, | 200 IDS_ASH_DISPLAY_RESOLUTION_TIMEOUT, |
204 ui::TimeFormat::Simple( | 201 ui::TimeFormat::Simple( |
205 ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::LENGTH_LONG, | 202 ui::TimeFormat::FORMAT_DURATION, ui::TimeFormat::LENGTH_LONG, |
206 base::TimeDelta::FromSeconds(change_info_->timeout_count))); | 203 base::TimeDelta::FromSeconds(change_info_->timeout_count))); |
207 } | 204 } |
208 data.buttons.push_back(message_center::ButtonInfo( | 205 data.buttons.push_back(message_center::ButtonInfo( |
209 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); | 206 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); |
210 | 207 |
211 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; | 208 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; |
212 | 209 |
213 const base::string16 display_name = base::UTF8ToUTF16( | 210 const base::string16 display_name = base::UTF8ToUTF16( |
214 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 211 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
215 change_info_->display_id)); | 212 change_info_->display_id)); |
216 const base::string16 message = | 213 const base::string16 message = |
217 (change_info_->new_resolution.size == | 214 (change_info_->new_resolution.size == |
218 change_info_->current_resolution.size) ? | 215 change_info_->current_resolution.size) |
219 l10n_util::GetStringFUTF16( | 216 ? l10n_util::GetStringFUTF16( |
220 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 217 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, display_name, |
221 display_name, | 218 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString())) |
222 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString())) : | 219 : l10n_util::GetStringFUTF16( |
223 l10n_util::GetStringFUTF16( | 220 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, |
224 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, | 221 display_name, |
225 display_name, | 222 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString()), |
226 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString()), | 223 base::UTF8ToUTF16( |
227 base::UTF8ToUTF16(change_info_->current_resolution.size.ToString())); | 224 change_info_->current_resolution.size.ToString())); |
228 | 225 |
229 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 226 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
230 std::unique_ptr<Notification> notification(new Notification( | 227 std::unique_ptr<Notification> notification(new Notification( |
231 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message, | 228 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message, |
232 timeout_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 229 timeout_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
233 base::string16() /* display_source */, GURL(), | 230 base::string16() /* display_source */, GURL(), |
234 message_center::NotifierId( | 231 message_center::NotifierId( |
235 message_center::NotifierId::SYSTEM_COMPONENT, | 232 message_center::NotifierId::SYSTEM_COMPONENT, |
236 system_notifier::kNotifierDisplayResolutionChange), | 233 system_notifier::kNotifierDisplayResolutionChange), |
237 data, new ResolutionChangeNotificationDelegate( | 234 data, new ResolutionChangeNotificationDelegate( |
(...skipping 20 matching lines...) Expand all Loading... |
258 kNotificationId, false /* by_user */); | 255 kNotificationId, false /* by_user */); |
259 } | 256 } |
260 if (!change_info_) | 257 if (!change_info_) |
261 return; | 258 return; |
262 base::Closure callback = change_info_->accept_callback; | 259 base::Closure callback = change_info_->accept_callback; |
263 change_info_.reset(); | 260 change_info_.reset(); |
264 callback.Run(); | 261 callback.Run(); |
265 } | 262 } |
266 | 263 |
267 void ResolutionNotificationController::RevertResolutionChange() { | 264 void ResolutionNotificationController::RevertResolutionChange() { |
268 message_center::MessageCenter::Get()->RemoveNotification( | 265 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, |
269 kNotificationId, false /* by_user */); | 266 false /* by_user */); |
270 if (!change_info_) | 267 if (!change_info_) |
271 return; | 268 return; |
272 int64_t display_id = change_info_->display_id; | 269 int64_t display_id = change_info_->display_id; |
273 DisplayMode old_resolution = change_info_->old_resolution; | 270 DisplayMode old_resolution = change_info_->old_resolution; |
274 change_info_.reset(); | 271 change_info_.reset(); |
275 Shell::GetInstance()->display_manager()->SetDisplayMode( | 272 Shell::GetInstance()->display_manager()->SetDisplayMode(display_id, |
276 display_id, old_resolution); | 273 old_resolution); |
277 } | 274 } |
278 | 275 |
279 void ResolutionNotificationController::OnDisplayAdded( | 276 void ResolutionNotificationController::OnDisplayAdded( |
280 const display::Display& new_display) {} | 277 const display::Display& new_display) {} |
281 | 278 |
282 void ResolutionNotificationController::OnDisplayRemoved( | 279 void ResolutionNotificationController::OnDisplayRemoved( |
283 const display::Display& old_display) { | 280 const display::Display& old_display) { |
284 if (change_info_ && change_info_->display_id == old_display.id()) | 281 if (change_info_ && change_info_->display_id == old_display.id()) |
285 RevertResolutionChange(); | 282 RevertResolutionChange(); |
286 } | 283 } |
287 | 284 |
288 void ResolutionNotificationController::OnDisplayMetricsChanged( | 285 void ResolutionNotificationController::OnDisplayMetricsChanged( |
289 const display::Display&, | 286 const display::Display&, |
290 uint32_t) {} | 287 uint32_t) {} |
291 | 288 |
292 void ResolutionNotificationController::OnDisplayConfigurationChanged() { | 289 void ResolutionNotificationController::OnDisplayConfigurationChanged() { |
293 if (!change_info_) | 290 if (!change_info_) |
294 return; | 291 return; |
295 | 292 |
296 change_info_->current_resolution = Shell::GetInstance()->display_manager()-> | 293 change_info_->current_resolution = |
297 GetActiveModeForDisplayId(change_info_->display_id); | 294 Shell::GetInstance()->display_manager()->GetActiveModeForDisplayId( |
| 295 change_info_->display_id); |
298 CreateOrUpdateNotification(true); | 296 CreateOrUpdateNotification(true); |
299 if (g_use_timer && change_info_->timeout_count > 0) { | 297 if (g_use_timer && change_info_->timeout_count > 0) { |
300 change_info_->timer.Start(FROM_HERE, | 298 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, |
301 base::TimeDelta::FromSeconds(1), | |
302 this, | |
303 &ResolutionNotificationController::OnTimerTick); | 299 &ResolutionNotificationController::OnTimerTick); |
304 } | 300 } |
305 } | 301 } |
306 | 302 |
307 void ResolutionNotificationController::SuppressTimerForTest() { | 303 void ResolutionNotificationController::SuppressTimerForTest() { |
308 g_use_timer = false; | 304 g_use_timer = false; |
309 } | 305 } |
310 | 306 |
311 } // namespace ash | 307 } // namespace ash |
OLD | NEW |