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

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

Issue 10056001: chromeos: Remove old status-area related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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/ash/status_area_host_aura.h"
6
7 #include "ash/shell_window_ids.h"
8 #include "base/command_line.h"
9 #include "chrome/browser/chromeos/status/clock_menu_button.h"
10 #include "chrome/browser/chromeos/status/memory_menu_button.h"
11 #include "chrome/browser/chromeos/status/status_area_view.h"
12 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/prefs/incognito_mode_prefs.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/view_ids.h"
17 #include "chrome/browser/ui/views/ash/chrome_shell_delegate.h"
18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "content/public/browser/notification_service.h"
21 #include "ui/aura/window.h"
22 #include "ui/views/widget/widget.h"
23
24 #if defined(OS_CHROMEOS)
25 #include "base/chromeos/chromeos_version.h"
26 #include "chrome/browser/chromeos/login/base_login_display_host.h"
27 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h"
28 #include "chrome/browser/chromeos/login/screen_locker.h"
29 #include "chrome/browser/chromeos/login/user_manager.h"
30 #include "chrome/browser/chromeos/status/clock_updater.h"
31 #include "chrome/browser/chromeos/status/status_area_view_chromeos.h"
32 #include "ui/gfx/native_widget_types.h"
33 #endif
34
35 StatusAreaHostAura::StatusAreaHostAura()
36 : status_area_widget_(NULL),
37 status_area_view_(NULL) {
38 BrowserList::AddObserver(this);
39 registrar_.Add(this,
40 chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
41 content::NotificationService::AllSources());
42 #if defined(OS_CHROMEOS)
43 registrar_.Add(this,
44 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
45 content::NotificationService::AllSources());
46 #endif
47 }
48
49 StatusAreaHostAura::~StatusAreaHostAura() {
50 BrowserList::RemoveObserver(this);
51 }
52
53 StatusAreaView* StatusAreaHostAura::GetStatusArea() {
54 return status_area_view_;
55 }
56
57 views::Widget* StatusAreaHostAura::CreateStatusArea() {
58 ash::Shell* shell = ash::Shell::GetInstance();
59 aura::Window* status_window = shell->GetContainer(
60 ash::internal::kShellWindowId_StatusContainer);
61
62 // Create status area view.
63 status_area_view_ = new StatusAreaView();
64
65 // Create widget to hold status area view.
66 status_area_widget_ = new views::Widget;
67 views::Widget::InitParams params(
68 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
69 gfx::Size ps = status_area_view_->GetPreferredSize();
70 params.bounds = gfx::Rect(0, 0, ps.width(), ps.height());
71 params.delegate = status_area_view_;
72 params.parent = status_window;
73 params.transparent = true;
74 status_area_widget_->Init(params);
75 status_area_widget_->GetNativeWindow()->SetName("StatusAreaWindow");
76 // Turn off focus on creation, otherwise the status area will request focus
77 // every time it is shown.
78 status_area_widget_->set_focus_on_creation(false);
79 status_area_widget_->SetContentsView(status_area_view_);
80 status_area_widget_->Show();
81 status_area_widget_->GetNativeView()->SetName("StatusAreaView");
82
83 UpdateAppearance();
84
85 return status_area_widget_;
86 }
87
88 void StatusAreaHostAura::AddButtons() {
89 #if defined(OS_CHROMEOS)
90 ClockMenuButton* clock = NULL;
91 chromeos::StatusAreaViewChromeos::AddChromeosButtons(status_area_view_,
92 this,
93 &clock);
94 if (clock)
95 clock_updater_.reset(new ClockUpdater(clock));
96 #else
97 #if defined(OS_LINUX)
98 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget))
99 status_area_view_->AddButton(new MemoryMenuButton(this),
100 StatusAreaView::NO_BORDER);
101 #endif
102 status_area_view_->AddButton(new ClockMenuButton(this),
103 StatusAreaView::HAS_BORDER);
104 #endif
105 }
106
107 // StatusAreaButton::Delegate implementation.
108
109 bool StatusAreaHostAura::ShouldExecuteStatusAreaCommand(
110 const views::View* button_view, int command_id) const {
111 #if defined(OS_CHROMEOS)
112 if (chromeos::StatusAreaViewChromeos::IsLoginMode()) {
113 // In login mode network options command means proxy settings dialog.
114 return command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS;
115 } else {
116 return !chromeos::StatusAreaViewChromeos::IsScreenLockMode();
117 }
118 #else
119 // TODO(stevenjb): system options for non-chromeos Aura?
120 return false;
121 #endif
122 }
123
124 void StatusAreaHostAura::ExecuteStatusAreaCommand(
125 const views::View* button_view, int command_id) {
126 #if defined(OS_CHROMEOS)
127 if (chromeos::StatusAreaViewChromeos::IsBrowserMode()) {
128 Profile* profile = ProfileManager::GetDefaultProfile();
129 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
130 IncognitoModePrefs::ShouldLaunchIncognito(
131 *CommandLine::ForCurrentProcess(),
132 profile->GetPrefs())) {
133 profile = profile->GetOffTheRecordProfile();
134 }
135 Browser* browser = BrowserList::FindBrowserWithProfile(profile);
136 if (!browser)
137 browser = Browser::Create(profile);
138 switch (command_id) {
139 case StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS:
140 browser->OpenInternetOptionsDialog();
141 break;
142 case StatusAreaButton::Delegate::SHOW_LANGUAGE_OPTIONS:
143 browser->OpenLanguageOptionsDialog();
144 break;
145 case StatusAreaButton::Delegate::SHOW_DATE_OPTIONS:
146 browser->ShowDateOptions();
147 break;
148 default:
149 NOTREACHED();
150 }
151 } else if (chromeos::StatusAreaViewChromeos::IsLoginMode()) {
152 if (command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS &&
153 chromeos::BaseLoginDisplayHost::default_host()) {
154 gfx::NativeWindow native_window =
155 chromeos::BaseLoginDisplayHost::default_host()->GetNativeWindow();
156 chromeos::ProxySettingsDialog* dialog =
157 new chromeos::ProxySettingsDialog(NULL, native_window);
158 dialog->Show();
159 } else {
160 NOTREACHED();
161 }
162 } else if (chromeos::StatusAreaViewChromeos::IsScreenLockMode()) {
163 if (command_id == StatusAreaButton::Delegate::SHOW_NETWORK_OPTIONS &&
164 chromeos::ScreenLocker::default_screen_locker()) {
165 gfx::NativeWindow native_window =
166 chromeos::ScreenLocker::default_screen_locker()->delegate()->
167 GetNativeWindow();
168 chromeos::ProxySettingsDialog* dialog =
169 new chromeos::ProxySettingsDialog(NULL, native_window);
170 dialog->Show();
171 } else {
172 NOTREACHED();
173 }
174 }
175 #endif
176 }
177
178 StatusAreaButton::TextStyle StatusAreaHostAura::GetStatusAreaTextStyle() const {
179 #if defined(OS_CHROMEOS)
180 if (IsLoginOrLockScreenDisplayed())
181 return StatusAreaButton::GRAY_PLAIN_LIGHT;
182 #endif
183 return StatusAreaButton::WHITE_HALOED_BOLD;
184 }
185
186 void StatusAreaHostAura::ButtonVisibilityChanged(views::View* button_view) {
187 if (status_area_view_)
188 status_area_view_->UpdateButtonVisibility();
189 }
190
191 void StatusAreaHostAura::OnBrowserSetLastActive(const Browser* browser) {
192 UpdateAppearance();
193 }
194
195 void StatusAreaHostAura::Observe(int type,
196 const content::NotificationSource& source,
197 const content::NotificationDetails& details) {
198 switch (type) {
199 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
200 UpdateAppearance();
201 break;
202 #if defined(OS_CHROMEOS)
203 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED:
204 UpdateAppearance();
205 ash::Shell::GetInstance()->UpdateShelfVisibility();
206 break;
207 #endif
208 default:
209 NOTREACHED() << "Unexpected notification " << type;
210 }
211 }
212
213 bool StatusAreaHostAura::IsLoginOrLockScreenDisplayed() const {
214 #if defined(OS_CHROMEOS)
215 if (!chromeos::UserManager::Get()->IsUserLoggedIn() &&
216 base::chromeos::IsRunningOnChromeOS())
217 return true;
218
219 const chromeos::ScreenLocker* locker =
220 chromeos::ScreenLocker::default_screen_locker();
221 if (locker && locker->locked())
222 return true;
223 #endif
224
225 return false;
226 }
227
228 void StatusAreaHostAura::UpdateAppearance() {
229 status_area_view_->UpdateButtonTextStyle();
230 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/status_area_host_aura.h ('k') | chrome/browser/ui/views/ash/status_area_host_aura_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698