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

Side by Side Diff: chrome/browser/ui/views/aura/status_area_host_aura.cc

Issue 9570044: Rename chrome/browser/ui/views/{aura => ash}/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 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
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/aura/status_area_host_aura.h"
6
7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
9 #include "base/command_line.h"
10 #include "chrome/browser/chromeos/status/clock_menu_button.h"
11 #include "chrome/browser/chromeos/status/memory_menu_button.h"
12 #include "chrome/browser/chromeos/status/status_area_view.h"
13 #include "chrome/browser/defaults.h"
14 #include "chrome/browser/prefs/incognito_mode_prefs.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/themes/theme_service.h"
17 #include "chrome/browser/themes/theme_service_factory.h"
18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/view_ids.h"
20 #include "chrome/browser/ui/views/aura/chrome_shell_delegate.h"
21 #include "chrome/browser/ui/views/aura/multiple_window_indicator_button.h"
22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "content/public/browser/notification_service.h"
25 #include "ui/aura/window.h"
26 #include "ui/views/widget/widget.h"
27
28 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/login/base_login_display_host.h"
30 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
31 #include "chrome/browser/chromeos/login/screen_locker.h"
32 #include "chrome/browser/chromeos/login/user_manager.h"
33 #include "chrome/browser/chromeos/status/clock_updater.h"
34 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
35 #include "chrome/browser/chromeos/system/runtime_environment.h"
36 #include "ui/gfx/native_widget_types.h"
37 #endif
38
39 namespace {
40
41 // Horizontal padding between the side of the status area and the side of the
42 // screen in compact mode.
43 const int kCompactModeHorizontalOffset = 3;
44
45 // Vertical padding between the top of the status area and the top of the screen
46 // when we're displaying either the login/lock screen or a browser window in
47 // compact mode.
48 const int kCompactModeLoginAndLockVerticalOffset = 4;
49 const int kCompactModeBrowserVerticalOffset = 2;
50
51 } // namespace
52
53 // static
54 gfx::Size StatusAreaHostAura::GetCompactModeLoginAndLockOffset() {
55 return gfx::Size(kCompactModeHorizontalOffset,
56 kCompactModeLoginAndLockVerticalOffset);
57 }
58
59 // static
60 gfx::Size StatusAreaHostAura::GetCompactModeBrowserOffset() {
61 return gfx::Size(kCompactModeHorizontalOffset,
62 kCompactModeBrowserVerticalOffset);
63 }
64
65 StatusAreaHostAura::StatusAreaHostAura()
66 : status_area_widget_(NULL),
67 status_area_view_(NULL) {
68 BrowserList::AddObserver(this);
69 registrar_.Add(this,
70 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
71 content::NotificationService::AllSources());
72 #if defined(OS_CHROMEOS)
73 registrar_.Add(this,
74 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
75 content::NotificationService::AllSources());
76 #endif
77 }
78
79 StatusAreaHostAura::~StatusAreaHostAura() {
80 BrowserList::RemoveObserver(this);
81 }
82
83 StatusAreaView* StatusAreaHostAura::GetStatusArea() {
84 return status_area_view_;
85 }
86
87 views::Widget* StatusAreaHostAura::CreateStatusArea() {
88 ash::Shell* shell = ash::Shell::GetInstance();
89 aura::Window* status_window = shell->GetContainer(
90 ash::internal::kShellWindowId_StatusContainer);
91
92 // Create status area view.
93 status_area_view_ = new StatusAreaView();
94
95 // Add multiple window indicator button for compact mode. Note this should be
96 // the last button added to status area so that it could be right most there.
97 if (ash::Shell::GetInstance()->IsWindowModeCompact()) {
98 status_area_view_->AddButton(new MultipleWindowIndicatorButton(this),
99 StatusAreaView::NO_BORDER);
100 }
101
102 // Create widget to hold status area view.
103 status_area_widget_ = new views::Widget;
104 views::Widget::InitParams params(
105 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
106 gfx::Size ps = status_area_view_->GetPreferredSize();
107 params.bounds = gfx::Rect(0, 0, ps.width(), ps.height());
108 params.parent = status_window;
109 params.transparent = true;
110 status_area_widget_->Init(params);
111 status_area_widget_->GetNativeWindow()->SetName("StatusAreaWindow");
112 // Turn off focus on creation, otherwise the status area will request focus
113 // every time it is shown.
114 status_area_widget_->set_focus_on_creation(false);
115 status_area_widget_->SetContentsView(status_area_view_);
116 status_area_widget_->Show();
117 status_area_widget_->GetNativeView()->SetName("StatusAreaView");
118
119 UpdateAppearance();
120
121 return status_area_widget_;
122 }
123
124 void StatusAreaHostAura::AddButtons() {
125 #if defined(OS_CHROMEOS)
126 ClockMenuButton* clock = NULL;
127 chromeos::StatusAreaViewChromeos::AddChromeosButtons(status_area_view_,
128 this,
129 &clock);
130 if (clock)
131 clock_updater_.reset(new ClockUpdater(clock));
132 #else
133 #if defined(OS_LINUX)
134 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget))
135 status_area_view_->AddButton(new MemoryMenuButton(this),
136 StatusAreaView::NO_BORDER);
137 #endif
138 status_area_view_->AddButton(new ClockMenuButton(this),
139 StatusAreaView::HAS_BORDER);
140 #endif
141 }
142
143 // StatusAreaButton::Delegate implementation.
144
145 bool StatusAreaHostAura::ShouldExecuteStatusAreaCommand(
146 const views::View* button_view, int command_id) const {
147 #if defined(OS_CHROMEOS)
148 if (chromeos::StatusAreaViewChromeos::IsLoginMode()) {
149 // In login mode network options command means proxy settings dialog.
150 return command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS;
151 } else {
152 return !chromeos::StatusAreaViewChromeos::IsScreenLockMode();
153 }
154 #else
155 // TODO(stevenjb): system options for non-chromeos Aura?
156 return false;
157 #endif
158 }
159
160 void StatusAreaHostAura::ExecuteStatusAreaCommand(
161 const views::View* button_view, int command_id) {
162 #if defined(OS_CHROMEOS)
163 if (chromeos::StatusAreaViewChromeos::IsBrowserMode()) {
164 Profile* profile = ProfileManager::GetDefaultProfile();
165 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
166 IncognitoModePrefs::ShouldLaunchIncognito(
167 *CommandLine::ForCurrentProcess(),
168 profile->GetPrefs())) {
169 profile = profile->GetOffTheRecordProfile();
170 }
171 Browser* browser = BrowserList::FindBrowserWithProfile(profile);
172 if (!browser)
173 browser = Browser::Create(profile);
174 switch (command_id) {
175 case StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS:
176 browser->OpenInternetOptionsDialog();
177 break;
178 case StatusAreaButton::Delegate::SHOW_LANGUAGE_OPTIONS:
179 browser->OpenLanguageOptionsDialog();
180 break;
181 case StatusAreaButton::Delegate::SHOW_ADVANCED_OPTIONS:
182 browser->OpenAdvancedOptionsDialog();
183 break;
184 default:
185 NOTREACHED();
186 }
187 } else if (chromeos::StatusAreaViewChromeos::IsLoginMode()) {
188 if (command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS &&
189 chromeos::BaseLoginDisplayHost::default_host()) {
190 gfx::NativeWindow native_window =
191 chromeos::BaseLoginDisplayHost::default_host()->GetNativeWindow();
192 proxy_settings_dialog_.reset(new chromeos::ProxySettingsDialog(
193 NULL, native_window));
194 proxy_settings_dialog_->Show();
195 } else {
196 NOTREACHED();
197 }
198 } else if (chromeos::StatusAreaViewChromeos::IsScreenLockMode()) {
199 if (command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS &&
200 chromeos::ScreenLocker::default_screen_locker()) {
201 gfx::NativeWindow native_window =
202 chromeos::ScreenLocker::default_screen_locker()->delegate()->
203 GetNativeWindow();
204 proxy_settings_dialog_.reset(new chromeos::ProxySettingsDialog(
205 NULL,
206 native_window));
207 proxy_settings_dialog_->Show();
208 } else {
209 NOTREACHED();
210 }
211 }
212 #endif
213 }
214
215 StatusAreaButton::TextStyle StatusAreaHostAura::GetStatusAreaTextStyle() const {
216 #if defined(OS_CHROMEOS)
217 if (IsLoginOrLockScreenDisplayed())
218 return StatusAreaButton::GRAY_PLAIN_LIGHT;
219 #endif
220
221 if (ash::Shell::GetInstance()->IsWindowModeCompact()) {
222 Browser* browser = BrowserList::GetLastActive();
223 if (!browser)
224 return StatusAreaButton::WHITE_HALOED_BOLD;
225
226 ThemeService* theme_service =
227 ThemeServiceFactory::GetForProfile(browser->profile());
228 if (!theme_service->UsingDefaultTheme())
229 return StatusAreaButton::WHITE_HALOED_BOLD;
230
231 return browser->profile()->IsOffTheRecord() ?
232 StatusAreaButton::WHITE_PLAIN_BOLD :
233 StatusAreaButton::GRAY_EMBOSSED_BOLD;
234 } else {
235 return StatusAreaButton::WHITE_HALOED_BOLD;
236 }
237 }
238
239 void StatusAreaHostAura::ButtonVisibilityChanged(views::View* button_view) {
240 if (status_area_view_)
241 status_area_view_->UpdateButtonVisibility();
242 }
243
244 void StatusAreaHostAura::OnBrowserSetLastActive(const Browser* browser) {
245 UpdateAppearance();
246 }
247
248 void StatusAreaHostAura::Observe(int type,
249 const content::NotificationSource& source,
250 const content::NotificationDetails& details) {
251 switch (type) {
252 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
253 UpdateAppearance();
254 break;
255 #if defined(OS_CHROMEOS)
256 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED:
257 UpdateAppearance();
258 break;
259 #endif
260 default:
261 NOTREACHED() << "Unexpected notification " << type;
262 }
263 }
264
265 bool StatusAreaHostAura::IsLoginOrLockScreenDisplayed() const {
266 #if defined(OS_CHROMEOS)
267 if (!chromeos::UserManager::Get()->user_is_logged_in() &&
268 chromeos::system::runtime_environment::IsRunningOnChromeOS())
269 return true;
270
271 const chromeos::ScreenLocker* locker =
272 chromeos::ScreenLocker::default_screen_locker();
273 if (locker && locker->locked())
274 return true;
275 #endif
276
277 return false;
278 }
279
280 void StatusAreaHostAura::UpdateAppearance() {
281 status_area_view_->UpdateButtonTextStyle();
282
283 gfx::Size offset = IsLoginOrLockScreenDisplayed() ?
284 GetCompactModeLoginAndLockOffset() :
285 GetCompactModeBrowserOffset();
286 ash::Shell::GetInstance()->SetCompactStatusAreaOffset(offset);
287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698