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

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

Issue 2270553002: Move ash::DisplayInfo to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 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
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 <utility> 7 #include <utility>
8 8
9 #include "ash/common/display/display_info.h"
10 #include "ash/common/system/system_notifier.h" 9 #include "ash/common/system/system_notifier.h"
11 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
12 #include "ash/shell.h" 11 #include "ash/shell.h"
13 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
14 #include "grit/ash_resources.h" 13 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h" 14 #include "grit/ash_strings.h"
16 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/time_format.h" 16 #include "ui/base/l10n/time_format.h"
18 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/display/display.h" 18 #include "ui/display/display.h"
19 #include "ui/display/manager/managed_display_info.h"
20 #include "ui/display/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
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } // namespace 86 } // namespace
87 87
88 // static 88 // static
89 const int ResolutionNotificationController::kTimeoutInSec = 15; 89 const int ResolutionNotificationController::kTimeoutInSec = 15;
90 90
91 // static 91 // static
92 const char ResolutionNotificationController::kNotificationId[] = 92 const char ResolutionNotificationController::kNotificationId[] =
93 "chrome://settings/display/resolution"; 93 "chrome://settings/display/resolution";
94 94
95 struct ResolutionNotificationController::ResolutionChangeInfo { 95 struct ResolutionNotificationController::ResolutionChangeInfo {
96 ResolutionChangeInfo(int64_t display_id, 96 ResolutionChangeInfo(
97 const scoped_refptr<ManagedDisplayMode>& old_resolution, 97 int64_t display_id,
98 const scoped_refptr<ManagedDisplayMode>& new_resolution, 98 const scoped_refptr<display::ManagedDisplayMode>& old_resolution,
99 const base::Closure& accept_callback); 99 const scoped_refptr<display::ManagedDisplayMode>& new_resolution,
100 const base::Closure& accept_callback);
100 ~ResolutionChangeInfo(); 101 ~ResolutionChangeInfo();
101 102
102 // The id of the display where the resolution change happens. 103 // The id of the display where the resolution change happens.
103 int64_t display_id; 104 int64_t display_id;
104 105
105 // The resolution before the change. 106 // The resolution before the change.
106 scoped_refptr<ManagedDisplayMode> old_resolution; 107 scoped_refptr<display::ManagedDisplayMode> old_resolution;
107 108
108 // The requested resolution. Note that this may be different from 109 // The requested resolution. Note that this may be different from
109 // |current_resolution| which is the actual resolution set. 110 // |current_resolution| which is the actual resolution set.
110 scoped_refptr<ManagedDisplayMode> new_resolution; 111 scoped_refptr<display::ManagedDisplayMode> new_resolution;
111 112
112 // The actual resolution after the change. 113 // The actual resolution after the change.
113 scoped_refptr<ManagedDisplayMode> current_resolution; 114 scoped_refptr<display::ManagedDisplayMode> current_resolution;
114 115
115 // The callback when accept is chosen. 116 // The callback when accept is chosen.
116 base::Closure accept_callback; 117 base::Closure accept_callback;
117 118
118 // The remaining timeout in seconds. 0 if the change does not time out. 119 // The remaining timeout in seconds. 0 if the change does not time out.
119 uint8_t timeout_count; 120 uint8_t timeout_count;
120 121
121 // The timer to invoke OnTimerTick() every second. This cannot be 122 // The timer to invoke OnTimerTick() every second. This cannot be
122 // OneShotTimer since the message contains text "automatically closed in xx 123 // OneShotTimer since the message contains text "automatically closed in xx
123 // seconds..." which has to be updated every second. 124 // seconds..." which has to be updated every second.
124 base::RepeatingTimer timer; 125 base::RepeatingTimer timer;
125 126
126 private: 127 private:
127 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo); 128 DISALLOW_COPY_AND_ASSIGN(ResolutionChangeInfo);
128 }; 129 };
129 130
130 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo( 131 ResolutionNotificationController::ResolutionChangeInfo::ResolutionChangeInfo(
131 int64_t display_id, 132 int64_t display_id,
132 const scoped_refptr<ManagedDisplayMode>& old_resolution, 133 const scoped_refptr<display::ManagedDisplayMode>& old_resolution,
133 const scoped_refptr<ManagedDisplayMode>& new_resolution, 134 const scoped_refptr<display::ManagedDisplayMode>& new_resolution,
134 const base::Closure& accept_callback) 135 const base::Closure& accept_callback)
135 : display_id(display_id), 136 : display_id(display_id),
136 old_resolution(old_resolution), 137 old_resolution(old_resolution),
137 new_resolution(new_resolution), 138 new_resolution(new_resolution),
138 accept_callback(accept_callback), 139 accept_callback(accept_callback),
139 timeout_count(0) { 140 timeout_count(0) {
140 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 141 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
141 if (!display::Display::HasInternalDisplay() && 142 if (!display::Display::HasInternalDisplay() &&
142 display_manager->num_connected_displays() == 1u) { 143 display_manager->num_connected_displays() == 1u) {
143 timeout_count = kTimeoutInSec; 144 timeout_count = kTimeoutInSec;
(...skipping 12 matching lines...) Expand all
156 display::Screen::GetScreen()->AddObserver(this); 157 display::Screen::GetScreen()->AddObserver(this);
157 } 158 }
158 159
159 ResolutionNotificationController::~ResolutionNotificationController() { 160 ResolutionNotificationController::~ResolutionNotificationController() {
160 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 161 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
161 display::Screen::GetScreen()->RemoveObserver(this); 162 display::Screen::GetScreen()->RemoveObserver(this);
162 } 163 }
163 164
164 void ResolutionNotificationController::PrepareNotification( 165 void ResolutionNotificationController::PrepareNotification(
165 int64_t display_id, 166 int64_t display_id,
166 const scoped_refptr<ManagedDisplayMode>& old_resolution, 167 const scoped_refptr<display::ManagedDisplayMode>& old_resolution,
167 const scoped_refptr<ManagedDisplayMode>& new_resolution, 168 const scoped_refptr<display::ManagedDisplayMode>& new_resolution,
168 const base::Closure& accept_callback) { 169 const base::Closure& accept_callback) {
169 DCHECK(old_resolution); 170 DCHECK(old_resolution);
170 DCHECK(new_resolution); 171 DCHECK(new_resolution);
171 172
172 DCHECK(!display::Display::IsInternalDisplayId(display_id)); 173 DCHECK(!display::Display::IsInternalDisplayId(display_id));
173 // If multiple resolution changes are invoked for the same display, 174 // If multiple resolution changes are invoked for the same display,
174 // the original resolution for the first resolution change has to be used 175 // the original resolution for the first resolution change has to be used
175 // instead of the specified |old_resolution|. 176 // instead of the specified |old_resolution|.
176 scoped_refptr<ManagedDisplayMode> original_resolution; 177 scoped_refptr<display::ManagedDisplayMode> original_resolution;
177 if (change_info_ && change_info_->display_id == display_id) { 178 if (change_info_ && change_info_->display_id == display_id) {
178 DCHECK(change_info_->new_resolution->size() == old_resolution->size()); 179 DCHECK(change_info_->new_resolution->size() == old_resolution->size());
179 original_resolution = change_info_->old_resolution; 180 original_resolution = change_info_->old_resolution;
180 } 181 }
181 182
182 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution, 183 change_info_.reset(new ResolutionChangeInfo(display_id, old_resolution,
183 new_resolution, accept_callback)); 184 new_resolution, accept_callback));
184 if (original_resolution && !original_resolution->size().IsEmpty()) 185 if (original_resolution && !original_resolution->size().IsEmpty())
185 change_info_->old_resolution = original_resolution; 186 change_info_->old_resolution = original_resolution;
186 } 187 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 change_info_.reset(); 270 change_info_.reset();
270 callback.Run(); 271 callback.Run();
271 } 272 }
272 273
273 void ResolutionNotificationController::RevertResolutionChange() { 274 void ResolutionNotificationController::RevertResolutionChange() {
274 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, 275 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId,
275 false /* by_user */); 276 false /* by_user */);
276 if (!change_info_) 277 if (!change_info_)
277 return; 278 return;
278 int64_t display_id = change_info_->display_id; 279 int64_t display_id = change_info_->display_id;
279 scoped_refptr<ManagedDisplayMode> old_resolution = 280 scoped_refptr<display::ManagedDisplayMode> old_resolution =
280 change_info_->old_resolution; 281 change_info_->old_resolution;
281 change_info_.reset(); 282 change_info_.reset();
282 Shell::GetInstance()->display_manager()->SetDisplayMode(display_id, 283 Shell::GetInstance()->display_manager()->SetDisplayMode(display_id,
283 old_resolution); 284 old_resolution);
284 } 285 }
285 286
286 void ResolutionNotificationController::OnDisplayAdded( 287 void ResolutionNotificationController::OnDisplayAdded(
287 const display::Display& new_display) {} 288 const display::Display& new_display) {}
288 289
289 void ResolutionNotificationController::OnDisplayRemoved( 290 void ResolutionNotificationController::OnDisplayRemoved(
(...skipping 18 matching lines...) Expand all
308 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this, 309 change_info_->timer.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), this,
309 &ResolutionNotificationController::OnTimerTick); 310 &ResolutionNotificationController::OnTimerTick);
310 } 311 }
311 } 312 }
312 313
313 void ResolutionNotificationController::SuppressTimerForTest() { 314 void ResolutionNotificationController::SuppressTimerForTest() {
314 g_use_timer = false; 315 g_use_timer = false;
315 } 316 }
316 317
317 } // 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