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

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

Issue 417113012: Introduce user customization of external HighDPI mode for 4K monitor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 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 | Annotate | Revision Log
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 "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
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 DisplayMode& old_resolution,
106 const gfx::Size& new_resolution, 107 const 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 DisplayMode old_resolution;
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 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 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 DisplayMode& old_resolution,
141 const gfx::Size& new_resolution, 142 const 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::PrepareNotification(
170 int64 display_id, 171 int64 display_id,
171 const gfx::Size& old_resolution, 172 const DisplayMode& old_resolution,
172 const gfx::Size& new_resolution, 173 const 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 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 // SetDisplayResolution() causes OnConfigurationChanged() and the notification
189 // will be shown at that point.
190 Shell::GetInstance()->display_manager()->SetDisplayResolution(
191 display_id, new_resolution);
192 } 188 }
193 189
194 bool ResolutionNotificationController::DoesNotificationTimeout() { 190 bool ResolutionNotificationController::DoesNotificationTimeout() {
195 return change_info_ && change_info_->timeout_count > 0; 191 return change_info_ && change_info_->timeout_count > 0;
196 } 192 }
197 193
198 void ResolutionNotificationController::CreateOrUpdateNotification( 194 void ResolutionNotificationController::CreateOrUpdateNotification(
199 bool enable_spoken_feedback) { 195 bool enable_spoken_feedback) {
200 message_center::MessageCenter* message_center = 196 message_center::MessageCenter* message_center =
201 message_center::MessageCenter::Get(); 197 message_center::MessageCenter::Get();
(...skipping 15 matching lines...) Expand all
217 } 213 }
218 data.buttons.push_back(message_center::ButtonInfo( 214 data.buttons.push_back(message_center::ButtonInfo(
219 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT))); 215 l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_RESOLUTION_CHANGE_REVERT)));
220 216
221 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback; 217 data.should_make_spoken_feedback_for_popup_updates = enable_spoken_feedback;
222 218
223 const base::string16 display_name = base::UTF8ToUTF16( 219 const base::string16 display_name = base::UTF8ToUTF16(
224 Shell::GetInstance()->display_manager()->GetDisplayNameForId( 220 Shell::GetInstance()->display_manager()->GetDisplayNameForId(
225 change_info_->display_id)); 221 change_info_->display_id));
226 const base::string16 message = 222 const base::string16 message =
227 (change_info_->new_resolution == change_info_->current_resolution) ? 223 (change_info_->new_resolution.size ==
224 change_info_->current_resolution.size) ?
228 l10n_util::GetStringFUTF16( 225 l10n_util::GetStringFUTF16(
229 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, 226 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
230 display_name, 227 display_name,
231 base::UTF8ToUTF16(change_info_->new_resolution.ToString())) : 228 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString())) :
232 l10n_util::GetStringFUTF16( 229 l10n_util::GetStringFUTF16(
233 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, 230 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED,
234 display_name, 231 display_name,
235 base::UTF8ToUTF16(change_info_->new_resolution.ToString()), 232 base::UTF8ToUTF16(change_info_->new_resolution.size.ToString()),
236 base::UTF8ToUTF16(change_info_->current_resolution.ToString())); 233 base::UTF8ToUTF16(change_info_->current_resolution.size.ToString()));
237 234
238 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 235 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
239 scoped_ptr<Notification> notification(new Notification( 236 scoped_ptr<Notification> notification(new Notification(
240 message_center::NOTIFICATION_TYPE_SIMPLE, 237 message_center::NOTIFICATION_TYPE_SIMPLE,
241 kNotificationId, 238 kNotificationId,
242 message, 239 message,
243 timeout_message, 240 timeout_message,
244 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), 241 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
245 base::string16() /* display_source */, 242 base::string16() /* display_source */,
246 message_center::NotifierId( 243 message_center::NotifierId(
(...skipping 25 matching lines...) Expand all
272 } 269 }
273 base::Closure callback = change_info_->accept_callback; 270 base::Closure callback = change_info_->accept_callback;
274 change_info_.reset(); 271 change_info_.reset();
275 callback.Run(); 272 callback.Run();
276 } 273 }
277 274
278 void ResolutionNotificationController::RevertResolutionChange() { 275 void ResolutionNotificationController::RevertResolutionChange() {
279 message_center::MessageCenter::Get()->RemoveNotification( 276 message_center::MessageCenter::Get()->RemoveNotification(
280 kNotificationId, false /* by_user */); 277 kNotificationId, false /* by_user */);
281 int64 display_id = change_info_->display_id; 278 int64 display_id = change_info_->display_id;
282 gfx::Size old_resolution = change_info_->old_resolution; 279 DisplayMode old_resolution = change_info_->old_resolution;
283 change_info_.reset(); 280 change_info_.reset();
284 Shell::GetInstance()->display_manager()->SetDisplayResolution( 281 Shell::GetInstance()->display_manager()->SetDisplayMode(
285 display_id, old_resolution); 282 display_id, old_resolution);
286 } 283 }
287 284
288 void ResolutionNotificationController::OnDisplayAdded( 285 void ResolutionNotificationController::OnDisplayAdded(
289 const gfx::Display& new_display) { 286 const gfx::Display& new_display) {
290 } 287 }
291 288
292 void ResolutionNotificationController::OnDisplayRemoved( 289 void ResolutionNotificationController::OnDisplayRemoved(
293 const gfx::Display& old_display) { 290 const gfx::Display& old_display) {
294 if (change_info_ && change_info_->display_id == old_display.id()) 291 if (change_info_ && change_info_->display_id == old_display.id())
295 RevertResolutionChange(); 292 RevertResolutionChange();
296 } 293 }
297 294
298 void ResolutionNotificationController::OnDisplayMetricsChanged( 295 void ResolutionNotificationController::OnDisplayMetricsChanged(
299 const gfx::Display&, uint32_t) { 296 const gfx::Display&, uint32_t) {
300 } 297 }
301 298
302 void ResolutionNotificationController::OnDisplayConfigurationChanged() { 299 void ResolutionNotificationController::OnDisplayConfigurationChanged() {
303 if (!change_info_) 300 if (!change_info_)
304 return; 301 return;
305 302
306 const DisplayInfo& info = Shell::GetInstance()->display_manager()-> 303 change_info_->current_resolution = Shell::GetInstance()->display_manager()->
307 GetDisplayInfo(change_info_->display_id); 304 GetActiveModeForDisplayId(change_info_->display_id);
308 change_info_->current_resolution = info.bounds_in_native().size();
309 CreateOrUpdateNotification(true); 305 CreateOrUpdateNotification(true);
310 if (g_use_timer && change_info_->timeout_count > 0) { 306 if (g_use_timer && change_info_->timeout_count > 0) {
311 change_info_->timer.Start(FROM_HERE, 307 change_info_->timer.Start(FROM_HERE,
312 base::TimeDelta::FromSeconds(1), 308 base::TimeDelta::FromSeconds(1),
313 this, 309 this,
314 &ResolutionNotificationController::OnTimerTick); 310 &ResolutionNotificationController::OnTimerTick);
315 } 311 }
316 } 312 }
317 313
318 void ResolutionNotificationController::SuppressTimerForTest() { 314 void ResolutionNotificationController::SuppressTimerForTest() {
319 g_use_timer = false; 315 g_use_timer = false;
320 } 316 }
321 317
322 } // namespace ash 318 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/resolution_notification_controller.h ('k') | ash/display/resolution_notification_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698