| 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/system/system_notifier.h" | 9 #include "ash/common/system/system_notifier.h" |
| 10 #include "ash/resources/grit/ash_resources.h" | 10 #include "ash/resources/grit/ash_resources.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 ResolutionNotificationController::ResolutionNotificationController() { | 155 ResolutionNotificationController::ResolutionNotificationController() { |
| 156 Shell::Get()->window_tree_host_manager()->AddObserver(this); | 156 Shell::Get()->window_tree_host_manager()->AddObserver(this); |
| 157 display::Screen::GetScreen()->AddObserver(this); | 157 display::Screen::GetScreen()->AddObserver(this); |
| 158 } | 158 } |
| 159 | 159 |
| 160 ResolutionNotificationController::~ResolutionNotificationController() { | 160 ResolutionNotificationController::~ResolutionNotificationController() { |
| 161 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); | 161 Shell::Get()->window_tree_host_manager()->RemoveObserver(this); |
| 162 display::Screen::GetScreen()->RemoveObserver(this); | 162 display::Screen::GetScreen()->RemoveObserver(this); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void ResolutionNotificationController::PrepareNotification( | 165 bool ResolutionNotificationController::PrepareNotificationAndSetDisplayMode( |
| 166 int64_t display_id, | 166 int64_t display_id, |
| 167 const scoped_refptr<display::ManagedDisplayMode>& old_resolution, | 167 const scoped_refptr<display::ManagedDisplayMode>& old_resolution, |
| 168 const scoped_refptr<display::ManagedDisplayMode>& new_resolution, | 168 const scoped_refptr<display::ManagedDisplayMode>& new_resolution, |
| 169 const base::Closure& accept_callback) { | 169 const base::Closure& accept_callback) { |
| 170 DCHECK(old_resolution); | 170 DCHECK(old_resolution); |
| 171 DCHECK(new_resolution); | 171 DCHECK(new_resolution); |
| 172 | 172 |
| 173 DCHECK(!display::Display::IsInternalDisplayId(display_id)); | 173 display::DisplayManager* const display_manager = |
| 174 Shell::Get()->display_manager(); |
| 175 if (display::Display::IsInternalDisplayId(display_id)) { |
| 176 // We don't show notifications to confirm/revert the resolution change in |
| 177 // the case of an internal display. |
| 178 return display_manager->SetDisplayMode(display_id, new_resolution); |
| 179 } |
| 180 |
| 174 // If multiple resolution changes are invoked for the same display, | 181 // If multiple resolution changes are invoked for the same display, |
| 175 // the original resolution for the first resolution change has to be used | 182 // the original resolution for the first resolution change has to be used |
| 176 // instead of the specified |old_resolution|. | 183 // instead of the specified |old_resolution|. |
| 177 scoped_refptr<display::ManagedDisplayMode> original_resolution; | 184 scoped_refptr<display::ManagedDisplayMode> original_resolution; |
| 178 if (change_info_ && change_info_->display_id == display_id) { | 185 if (change_info_ && change_info_->display_id == display_id) { |
| 179 DCHECK(change_info_->new_resolution->size() == old_resolution->size()); | 186 DCHECK(change_info_->new_resolution->size() == old_resolution->size()); |
| 180 original_resolution = change_info_->old_resolution; | 187 original_resolution = change_info_->old_resolution; |
| 181 } | 188 } |
| 182 | 189 |
| 183 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, | 190 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, |
| 184 new_resolution, accept_callback)); | 191 new_resolution, accept_callback)); |
| 185 if (original_resolution && !original_resolution->size().IsEmpty()) | 192 if (original_resolution && !original_resolution->size().IsEmpty()) |
| 186 change_info_->old_resolution = original_resolution; | 193 change_info_->old_resolution = original_resolution; |
| 194 |
| 195 if (!display_manager->SetDisplayMode(display_id, new_resolution)) { |
| 196 // Discard the prepared notification data since we failed to set the new |
| 197 // resolution. |
| 198 change_info_.reset(); |
| 199 return false; |
| 200 } |
| 201 |
| 202 return true; |
| 187 } | 203 } |
| 188 | 204 |
| 189 bool ResolutionNotificationController::DoesNotificationTimeout() { | 205 bool ResolutionNotificationController::DoesNotificationTimeout() { |
| 190 return change_info_ && change_info_->timeout_count > 0; | 206 return change_info_ && change_info_->timeout_count > 0; |
| 191 } | 207 } |
| 192 | 208 |
| 193 void ResolutionNotificationController::CreateOrUpdateNotification( | 209 void ResolutionNotificationController::CreateOrUpdateNotification( |
| 194 bool enable_spoken_feedback) { | 210 bool enable_spoken_feedback) { |
| 195 message_center::MessageCenter* message_center = | 211 message_center::MessageCenter* message_center = |
| 196 message_center::MessageCenter::Get(); | 212 message_center::MessageCenter::Get(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 change_info_->old_resolution; | 297 change_info_->old_resolution; |
| 282 change_info_.reset(); | 298 change_info_.reset(); |
| 283 Shell::Get()->display_manager()->SetDisplayMode(display_id, old_resolution); | 299 Shell::Get()->display_manager()->SetDisplayMode(display_id, old_resolution); |
| 284 } | 300 } |
| 285 | 301 |
| 286 void ResolutionNotificationController::OnDisplayAdded( | 302 void ResolutionNotificationController::OnDisplayAdded( |
| 287 const display::Display& new_display) {} | 303 const display::Display& new_display) {} |
| 288 | 304 |
| 289 void ResolutionNotificationController::OnDisplayRemoved( | 305 void ResolutionNotificationController::OnDisplayRemoved( |
| 290 const display::Display& old_display) { | 306 const display::Display& old_display) { |
| 291 if (change_info_ && change_info_->display_id == old_display.id()) | 307 if (change_info_ && change_info_->display_id == old_display.id()) { |
| 292 RevertResolutionChange(); | 308 message_center::MessageCenter::Get()->RemoveNotification( |
| 309 kNotificationId, false /* by_user */); |
| 310 } |
| 293 } | 311 } |
| 294 | 312 |
| 295 void ResolutionNotificationController::OnDisplayMetricsChanged( | 313 void ResolutionNotificationController::OnDisplayMetricsChanged( |
| 296 const display::Display&, | 314 const display::Display&, |
| 297 uint32_t) {} | 315 uint32_t) {} |
| 298 | 316 |
| 299 void ResolutionNotificationController::OnDisplayConfigurationChanged() { | 317 void ResolutionNotificationController::OnDisplayConfigurationChanged() { |
| 300 if (!change_info_) | 318 if (!change_info_) |
| 301 return; | 319 return; |
| 302 | 320 |
| 303 change_info_->current_resolution = | 321 change_info_->current_resolution = |
| 304 Shell::Get()->display_manager()->GetActiveModeForDisplayId( | 322 Shell::Get()->display_manager()->GetActiveModeForDisplayId( |
| 305 change_info_->display_id); | 323 change_info_->display_id); |
| 306 CreateOrUpdateNotification(true); | 324 CreateOrUpdateNotification(true); |
| 307 if (g_use_timer && change_info_->timeout_count > 0) { | 325 if (g_use_timer && change_info_->timeout_count > 0) { |
| 308 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, | 326 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, |
| 309 &ResolutionNotificationController::OnTimerTick); | 327 &ResolutionNotificationController::OnTimerTick); |
| 310 } | 328 } |
| 311 } | 329 } |
| 312 | 330 |
| 313 void ResolutionNotificationController::SuppressTimerForTest() { | 331 void ResolutionNotificationController::SuppressTimerForTest() { |
| 314 g_use_timer = false; | 332 g_use_timer = false; |
| 315 } | 333 } |
| 316 | 334 |
| 317 } // namespace ash | 335 } // namespace ash |
| OLD | NEW |