Chromium Code Reviews| 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 "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/display_info.h" | |
| 8 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/system/system_notifier.h" | 11 #include "ash/system/system_notifier.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
| 13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/l10n/time_format.h" | 16 #include "ui/base/l10n/time_format.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 | 96 |
| 96 // static | 97 // static |
| 97 const int ResolutionNotificationController::kTimeoutInSec = 15; | 98 const int ResolutionNotificationController::kTimeoutInSec = 15; |
| 98 | 99 |
| 99 // static | 100 // static |
| 100 const char ResolutionNotificationController::kNotificationId[] = | 101 const char ResolutionNotificationController::kNotificationId[] = |
| 101 "chrome://settings/display/resolution"; | 102 "chrome://settings/display/resolution"; |
| 102 | 103 |
| 103 struct ResolutionNotificationController::ResolutionChangeInfo { | 104 struct ResolutionNotificationController::ResolutionChangeInfo { |
| 104 ResolutionChangeInfo(int64 display_id, | 105 ResolutionChangeInfo(int64 display_id, |
| 105 const gfx::Size& old_resolution, | 106 const ash::DisplayMode& old_resolution, |
| 106 const gfx::Size& new_resolution, | 107 const ash::DisplayMode& new_resolution, |
| 107 const base::Closure& accept_callback); | 108 const base::Closure& accept_callback); |
| 108 ~ResolutionChangeInfo(); | 109 ~ResolutionChangeInfo(); |
| 109 | 110 |
| 110 // The id of the display where the resolution change happens. | 111 // The id of the display where the resolution change happens. |
| 111 int64 display_id; | 112 int64 display_id; |
| 112 | 113 |
| 113 // The resolution before the change. | 114 // The resolution before the change. |
| 114 gfx::Size old_resolution; | 115 ash::DisplayMode old_resolution; |
|
oshima
2014/07/30 02:09:45
remove ash::
Jun Mukai
2014/07/30 02:18:31
Done.
| |
| 115 | 116 |
| 116 // The requested resolution. Note that this may be different from | 117 // The requested resolution. Note that this may be different from |
| 117 // |current_resolution| which is the actual resolution set. | 118 // |current_resolution| which is the actual resolution set. |
| 118 gfx::Size new_resolution; | 119 ash::DisplayMode new_resolution; |
| 119 | 120 |
| 120 // The actual resolution after the change. | 121 // The actual resolution after the change. |
| 121 gfx::Size current_resolution; | 122 ash::DisplayMode current_resolution; |
| 122 | 123 |
| 123 // The callback when accept is chosen. | 124 // The callback when accept is chosen. |
| 124 base::Closure accept_callback; | 125 base::Closure accept_callback; |
| 125 | 126 |
| 126 // The remaining timeout in seconds. 0 if the change does not time out. | 127 // The remaining timeout in seconds. 0 if the change does not time out. |
| 127 uint8 timeout_count; | 128 uint8 timeout_count; |
| 128 | 129 |
| 129 // The timer to invoke OnTimerTick() every second. This cannot be | 130 // The timer to invoke OnTimerTick() every second. This cannot be |
| 130 // OneShotTimer since the message contains text "automatically closed in xx | 131 // OneShotTimer since the message contains text "automatically closed in xx |
| 131 // seconds..." which has to be updated every second. | 132 // seconds..." which has to be updated every second. |
| 132 base::RepeatingTimer<ResolutionNotificationController> timer; | 133 base::RepeatingTimer<ResolutionNotificationController> timer; |
| 133 | 134 |
| 134 private: | 135 private: |
| 135 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo); | 136 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo); |
| 136 }; | 137 }; |
| 137 | 138 |
| 138 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo( | 139 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo( |
| 139 int64 display_id, | 140 int64 display_id, |
| 140 const gfx::Size& old_resolution, | 141 const ash::DisplayMode& old_resolution, |
| 141 const gfx::Size& new_resolution, | 142 const ash::DisplayMode& new_resolution, |
| 142 const base::Closure& accept_callback) | 143 const base::Closure& accept_callback) |
| 143 : display_id(display_id), | 144 : display_id(display_id), |
| 144 old_resolution(old_resolution), | 145 old_resolution(old_resolution), |
| 145 new_resolution(new_resolution), | 146 new_resolution(new_resolution), |
| 146 accept_callback(accept_callback), | 147 accept_callback(accept_callback), |
| 147 timeout_count(0) { | 148 timeout_count(0) { |
| 148 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 149 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 149 if (!display_manager->HasInternalDisplay() && | 150 if (!display_manager->HasInternalDisplay() && |
| 150 display_manager->num_connected_displays() == 1u) { | 151 display_manager->num_connected_displays() == 1u) { |
| 151 timeout_count = kTimeoutInSec; | 152 timeout_count = kTimeoutInSec; |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 ResolutionNotificationController::ResolutionChangeInfo:: | 156 ResolutionNotificationController::ResolutionChangeInfo:: |
| 156 ~ResolutionChangeInfo() { | 157 ~ResolutionChangeInfo() { |
| 157 } | 158 } |
| 158 | 159 |
| 159 ResolutionNotificationController::ResolutionNotificationController() { | 160 ResolutionNotificationController::ResolutionNotificationController() { |
| 160 Shell::GetInstance()->display_controller()->AddObserver(this); | 161 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 161 Shell::GetScreen()->AddObserver(this); | 162 Shell::GetScreen()->AddObserver(this); |
| 162 } | 163 } |
| 163 | 164 |
| 164 ResolutionNotificationController::~ResolutionNotificationController() { | 165 ResolutionNotificationController::~ResolutionNotificationController() { |
| 165 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 166 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 166 Shell::GetScreen()->RemoveObserver(this); | 167 Shell::GetScreen()->RemoveObserver(this); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void ResolutionNotificationController::SetDisplayResolutionAndNotify( | 170 void ResolutionNotificationController::SetDisplayResolutionAndNotify( |
| 170 int64 display_id, | 171 int64 display_id, |
| 171 const gfx::Size& old_resolution, | 172 const ash::DisplayMode& old_resolution, |
| 172 const gfx::Size& new_resolution, | 173 const ash::DisplayMode& new_resolution, |
| 173 const base::Closure& accept_callback) { | 174 const base::Closure& accept_callback) { |
| 174 // If multiple resolution changes are invoked for the same display, | 175 // If multiple resolution changes are invoked for the same display, |
| 175 // the original resolution for the first resolution change has to be used | 176 // the original resolution for the first resolution change has to be used |
| 176 // instead of the specified |old_resolution|. | 177 // instead of the specified |old_resolution|. |
| 177 gfx::Size original_resolution; | 178 ash::DisplayMode original_resolution; |
| 178 if (change_info_ && change_info_->display_id == display_id) { | 179 if (change_info_ && change_info_->display_id == display_id) { |
| 179 DCHECK(change_info_->new_resolution == old_resolution); | 180 DCHECK(change_info_->new_resolution.size == old_resolution.size); |
| 180 original_resolution = change_info_->old_resolution; | 181 original_resolution = change_info_->old_resolution; |
| 181 } | 182 } |
| 182 | 183 |
| 183 change_info_.reset(new ResolutionChangeInfo( | 184 change_info_.reset(new ResolutionChangeInfo( |
| 184 display_id, old_resolution, new_resolution, accept_callback)); | 185 display_id, old_resolution, new_resolution, accept_callback)); |
| 185 if (!original_resolution.IsEmpty()) | 186 if (!original_resolution.size.IsEmpty()) |
| 186 change_info_->old_resolution = original_resolution; | 187 change_info_->old_resolution = original_resolution; |
| 187 | 188 |
| 188 // SetDisplayResolution() causes OnConfigurationChanged() and the notification | 189 // SetDisplayMode() causes OnConfigurationChanged() and the notification |
| 189 // will be shown at that point. | 190 // will be shown at that point. |
| 190 Shell::GetInstance()->display_manager()->SetDisplayResolution( | 191 Shell::GetInstance()->display_manager()->SetDisplayMode( |
| 191 display_id, new_resolution); | 192 display_id, new_resolution); |
| 192 } | 193 } |
| 193 | 194 |
| 194 bool ResolutionNotificationController::DoesNotificationTimeout() { | 195 bool ResolutionNotificationController::DoesNotificationTimeout() { |
| 195 return change_info_ && change_info_->timeout_count > 0; | 196 return change_info_ && change_info_->timeout_count > 0; |
| 196 } | 197 } |
| 197 | 198 |
| 198 void ResolutionNotificationController::CreateOrUpdateNotification( | 199 void ResolutionNotificationController::CreateOrUpdateNotification( |
| 199 bool enable_spoken_feedback) { | 200 bool enable_spoken_feedback) { |
| 200 message_center::MessageCenter* message_center = | 201 message_center::MessageCenter* message_center = |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 217 } | 218 } |
| 218 data.buttons.push_back(message_center::ButtonInfo( | 219 data.buttons.push_back(message_center::ButtonInfo( |
| 219 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); | 220 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); |
| 220 | 221 |
| 221 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; | 222 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; |
| 222 | 223 |
| 223 const base::string16 display_name = base::UTF8ToUTF16( | 224 const base::string16 display_name = base::UTF8ToUTF16( |
| 224 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 225 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
| 225 change_info_->display_id)); | 226 change_info_->display_id)); |
| 226 const base::string16 message = | 227 const base::string16 message = |
| 227 (change_info_->new_resolution == change_info_->current_resolution) ? | 228 (change_info_->new_resolution.size == |
| 229 change_info_->current_resolution.size) ? | |
| 228 l10n_util::GetStringFUTF16( | 230 l10n_util::GetStringFUTF16( |
| 229 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 231 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 230 display_name, | 232 display_name, |
| 231 base::UTF8ToUTF16(change_info_->new_resolution.ToString())) : | 233 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString())) : |
| 232 l10n_util::GetStringFUTF16( | 234 l10n_util::GetStringFUTF16( |
| 233 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, | 235 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, |
| 234 display_name, | 236 display_name, |
| 235 base::UTF8ToUTF16(change_info_->new_resolution.ToString()), | 237 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString()), |
| 236 base::UTF8ToUTF16(change_info_->current_resolution.ToString())); | 238 base::UTF8ToUTF16(change_info_->current_resolution.size.ToString())); |
| 237 | 239 |
| 238 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 240 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 239 scoped_ptr<Notification> notification(new Notification( | 241 scoped_ptr<Notification> notification(new Notification( |
| 240 message_center::NOTIFICATION_TYPE_SIMPLE, | 242 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 241 kNotificationId, | 243 kNotificationId, |
| 242 message, | 244 message, |
| 243 timeout_message, | 245 timeout_message, |
| 244 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 246 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
| 245 base::string16() /* display_source */, | 247 base::string16() /* display_source */, |
| 246 message_center::NotifierId( | 248 message_center::NotifierId( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 272 } | 274 } |
| 273 base::Closure callback = change_info_->accept_callback; | 275 base::Closure callback = change_info_->accept_callback; |
| 274 change_info_.reset(); | 276 change_info_.reset(); |
| 275 callback.Run(); | 277 callback.Run(); |
| 276 } | 278 } |
| 277 | 279 |
| 278 void ResolutionNotificationController::RevertResolutionChange() { | 280 void ResolutionNotificationController::RevertResolutionChange() { |
| 279 message_center::MessageCenter::Get()->RemoveNotification( | 281 message_center::MessageCenter::Get()->RemoveNotification( |
| 280 kNotificationId, false /* by_user */); | 282 kNotificationId, false /* by_user */); |
| 281 int64 display_id = change_info_->display_id; | 283 int64 display_id = change_info_->display_id; |
| 282 gfx::Size old_resolution = change_info_->old_resolution; | 284 ash::DisplayMode old_resolution = change_info_->old_resolution; |
| 283 change_info_.reset(); | 285 change_info_.reset(); |
| 284 Shell::GetInstance()->display_manager()->SetDisplayResolution( | 286 Shell::GetInstance()->display_manager()->SetDisplayMode( |
| 285 display_id, old_resolution); | 287 display_id, old_resolution); |
| 286 } | 288 } |
| 287 | 289 |
| 288 void ResolutionNotificationController::OnDisplayAdded( | 290 void ResolutionNotificationController::OnDisplayAdded( |
| 289 const gfx::Display& new_display) { | 291 const gfx::Display& new_display) { |
| 290 } | 292 } |
| 291 | 293 |
| 292 void ResolutionNotificationController::OnDisplayRemoved( | 294 void ResolutionNotificationController::OnDisplayRemoved( |
| 293 const gfx::Display& old_display) { | 295 const gfx::Display& old_display) { |
| 294 if (change_info_ && change_info_->display_id == old_display.id()) | 296 if (change_info_ && change_info_->display_id == old_display.id()) |
| 295 RevertResolutionChange(); | 297 RevertResolutionChange(); |
| 296 } | 298 } |
| 297 | 299 |
| 298 void ResolutionNotificationController::OnDisplayMetricsChanged( | 300 void ResolutionNotificationController::OnDisplayMetricsChanged( |
| 299 const gfx::Display&, uint32_t) { | 301 const gfx::Display&, uint32_t) { |
| 300 } | 302 } |
| 301 | 303 |
| 302 void ResolutionNotificationController::OnDisplayConfigurationChanged() { | 304 void ResolutionNotificationController::OnDisplayConfigurationChanged() { |
| 303 if (!change_info_) | 305 if (!change_info_) |
| 304 return; | 306 return; |
| 305 | 307 |
| 306 const DisplayInfo& info = Shell::GetInstance()->display_manager()-> | 308 DisplayMode mode; |
| 307 GetDisplayInfo(change_info_->display_id); | 309 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId( |
| 308 change_info_->current_resolution = info.bounds_in_native().size(); | 310 change_info_->display_id, &mode)) { |
| 311 return; | |
| 312 } | |
| 313 | |
| 314 change_info_->current_resolution = mode; | |
| 309 CreateOrUpdateNotification(true); | 315 CreateOrUpdateNotification(true); |
| 310 if (g_use_timer && change_info_->timeout_count > 0) { | 316 if (g_use_timer && change_info_->timeout_count > 0) { |
| 311 change_info_->timer.Start(FROM_HERE, | 317 change_info_->timer.Start(FROM_HERE, |
| 312 base::TimeDelta::FromSeconds(1), | 318 base::TimeDelta::FromSeconds(1), |
| 313 this, | 319 this, |
| 314 &ResolutionNotificationController::OnTimerTick); | 320 &ResolutionNotificationController::OnTimerTick); |
| 315 } | 321 } |
| 316 } | 322 } |
| 317 | 323 |
| 318 void ResolutionNotificationController::SuppressTimerForTest() { | 324 void ResolutionNotificationController::SuppressTimerForTest() { |
| 319 g_use_timer = false; | 325 g_use_timer = false; |
| 320 } | 326 } |
| 321 | 327 |
| 322 } // namespace ash | 328 } // namespace ash |
| OLD | NEW |