| 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/display/display_info.h" | 9 #include "ash/display/display_info.h" |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/system/system_notifier.h" | 12 #include "ash/system/system_notifier.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
| 15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/l10n/time_format.h" | 17 #include "ui/base/l10n/time_format.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/display.h" | 19 #include "ui/display/display.h" |
| 20 #include "ui/gfx/screen.h" | 20 #include "ui/display/screen.h" |
| 21 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
| 22 #include "ui/message_center/notification.h" | 22 #include "ui/message_center/notification.h" |
| 23 #include "ui/message_center/notification_delegate.h" | 23 #include "ui/message_center/notification_delegate.h" |
| 24 | 24 |
| 25 using message_center::Notification; | 25 using message_center::Notification; |
| 26 | 26 |
| 27 namespace ash { | 27 namespace ash { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool g_use_timer = true; | 30 bool g_use_timer = true; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 int64_t display_id, | 133 int64_t display_id, |
| 134 const DisplayMode& old_resolution, | 134 const DisplayMode& old_resolution, |
| 135 const DisplayMode& new_resolution, | 135 const DisplayMode& new_resolution, |
| 136 const base::Closure& accept_callback) | 136 const base::Closure& accept_callback) |
| 137 : display_id(display_id), | 137 : display_id(display_id), |
| 138 old_resolution(old_resolution), | 138 old_resolution(old_resolution), |
| 139 new_resolution(new_resolution), | 139 new_resolution(new_resolution), |
| 140 accept_callback(accept_callback), | 140 accept_callback(accept_callback), |
| 141 timeout_count(0) { | 141 timeout_count(0) { |
| 142 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 142 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 143 if (!gfx::Display::HasInternalDisplay() && | 143 if (!display::Display::HasInternalDisplay() && |
| 144 display_manager->num_connected_displays() == 1u) { | 144 display_manager->num_connected_displays() == 1u) { |
| 145 timeout_count = kTimeoutInSec; | 145 timeout_count = kTimeoutInSec; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 ResolutionNotificationController::ResolutionChangeInfo:: | 149 ResolutionNotificationController::ResolutionChangeInfo:: |
| 150 ~ResolutionChangeInfo() { | 150 ~ResolutionChangeInfo() { |
| 151 } | 151 } |
| 152 | 152 |
| 153 ResolutionNotificationController::ResolutionNotificationController() { | 153 ResolutionNotificationController::ResolutionNotificationController() { |
| 154 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 154 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
| 155 gfx::Screen::GetScreen()->AddObserver(this); | 155 display::Screen::GetScreen()->AddObserver(this); |
| 156 } | 156 } |
| 157 | 157 |
| 158 ResolutionNotificationController::~ResolutionNotificationController() { | 158 ResolutionNotificationController::~ResolutionNotificationController() { |
| 159 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 159 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
| 160 gfx::Screen::GetScreen()->RemoveObserver(this); | 160 display::Screen::GetScreen()->RemoveObserver(this); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void ResolutionNotificationController::PrepareNotification( | 163 void ResolutionNotificationController::PrepareNotification( |
| 164 int64_t display_id, | 164 int64_t display_id, |
| 165 const DisplayMode& old_resolution, | 165 const DisplayMode& old_resolution, |
| 166 const DisplayMode& new_resolution, | 166 const DisplayMode& new_resolution, |
| 167 const base::Closure& accept_callback) { | 167 const base::Closure& accept_callback) { |
| 168 DCHECK(!gfx::Display::IsInternalDisplayId(display_id)); | 168 DCHECK(!display::Display::IsInternalDisplayId(display_id)); |
| 169 // If multiple resolution changes are invoked for the same display, | 169 // If multiple resolution changes are invoked for the same display, |
| 170 // the original resolution for the first resolution change has to be used | 170 // the original resolution for the first resolution change has to be used |
| 171 // instead of the specified |old_resolution|. | 171 // instead of the specified |old_resolution|. |
| 172 DisplayMode original_resolution; | 172 DisplayMode original_resolution; |
| 173 if (change_info_ && change_info_->display_id == display_id) { | 173 if (change_info_ && change_info_->display_id == display_id) { |
| 174 DCHECK(change_info_->new_resolution.size == old_resolution.size); | 174 DCHECK(change_info_->new_resolution.size == old_resolution.size); |
| 175 original_resolution = change_info_->old_resolution; | 175 original_resolution = change_info_->old_resolution; |
| 176 } | 176 } |
| 177 | 177 |
| 178 change_info_.reset(new ResolutionChangeInfo( | 178 change_info_.reset(new ResolutionChangeInfo( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 if (!change_info_) | 270 if (!change_info_) |
| 271 return; | 271 return; |
| 272 int64_t display_id = change_info_->display_id; | 272 int64_t display_id = change_info_->display_id; |
| 273 DisplayMode old_resolution = change_info_->old_resolution; | 273 DisplayMode old_resolution = change_info_->old_resolution; |
| 274 change_info_.reset(); | 274 change_info_.reset(); |
| 275 Shell::GetInstance()->display_manager()->SetDisplayMode( | 275 Shell::GetInstance()->display_manager()->SetDisplayMode( |
| 276 display_id, old_resolution); | 276 display_id, old_resolution); |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ResolutionNotificationController::OnDisplayAdded( | 279 void ResolutionNotificationController::OnDisplayAdded( |
| 280 const gfx::Display& new_display) { | 280 const display::Display& new_display) {} |
| 281 } | |
| 282 | 281 |
| 283 void ResolutionNotificationController::OnDisplayRemoved( | 282 void ResolutionNotificationController::OnDisplayRemoved( |
| 284 const gfx::Display& old_display) { | 283 const display::Display& old_display) { |
| 285 if (change_info_ && change_info_->display_id == old_display.id()) | 284 if (change_info_ && change_info_->display_id == old_display.id()) |
| 286 RevertResolutionChange(); | 285 RevertResolutionChange(); |
| 287 } | 286 } |
| 288 | 287 |
| 289 void ResolutionNotificationController::OnDisplayMetricsChanged( | 288 void ResolutionNotificationController::OnDisplayMetricsChanged( |
| 290 const gfx::Display&, uint32_t) { | 289 const display::Display&, |
| 291 } | 290 uint32_t) {} |
| 292 | 291 |
| 293 void ResolutionNotificationController::OnDisplayConfigurationChanged() { | 292 void ResolutionNotificationController::OnDisplayConfigurationChanged() { |
| 294 if (!change_info_) | 293 if (!change_info_) |
| 295 return; | 294 return; |
| 296 | 295 |
| 297 change_info_->current_resolution = Shell::GetInstance()->display_manager()-> | 296 change_info_->current_resolution = Shell::GetInstance()->display_manager()-> |
| 298 GetActiveModeForDisplayId(change_info_->display_id); | 297 GetActiveModeForDisplayId(change_info_->display_id); |
| 299 CreateOrUpdateNotification(true); | 298 CreateOrUpdateNotification(true); |
| 300 if (g_use_timer && change_info_->timeout_count > 0) { | 299 if (g_use_timer && change_info_->timeout_count > 0) { |
| 301 change_info_->timer.Start(FROM_HERE, | 300 change_info_->timer.Start(FROM_HERE, |
| 302 base::TimeDelta::FromSeconds(1), | 301 base::TimeDelta::FromSeconds(1), |
| 303 this, | 302 this, |
| 304 &ResolutionNotificationController::OnTimerTick); | 303 &ResolutionNotificationController::OnTimerTick); |
| 305 } | 304 } |
| 306 } | 305 } |
| 307 | 306 |
| 308 void ResolutionNotificationController::SuppressTimerForTest() { | 307 void ResolutionNotificationController::SuppressTimerForTest() { |
| 309 g_use_timer = false; | 308 g_use_timer = false; |
| 310 } | 309 } |
| 311 | 310 |
| 312 } // namespace ash | 311 } // namespace ash |
| OLD | NEW |