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

Side by Side Diff: ash/system/tray/system_tray.cc

Issue 10332152: Add TraySms for SMS messages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bubble sizing code Created 8 years, 7 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
« no previous file with comments | « ash/system/tray/system_tray.h ('k') | ash/system/tray/system_tray_bubble.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/system/tray/system_tray.h" 5 #include "ash/system/tray/system_tray.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell/panel_window.h" 8 #include "ash/shell/panel_window.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/system/audio/tray_volume.h" 10 #include "ash/system/audio/tray_volume.h"
11 #include "ash/system/bluetooth/tray_bluetooth.h" 11 #include "ash/system/bluetooth/tray_bluetooth.h"
12 #include "ash/system/brightness/tray_brightness.h" 12 #include "ash/system/brightness/tray_brightness.h"
13 #include "ash/system/date/tray_date.h" 13 #include "ash/system/date/tray_date.h"
14 #include "ash/system/drive/tray_drive.h" 14 #include "ash/system/drive/tray_drive.h"
15 #include "ash/system/ime/tray_ime.h" 15 #include "ash/system/ime/tray_ime.h"
16 #include "ash/system/network/tray_network.h" 16 #include "ash/system/network/tray_network.h"
17 #include "ash/system/network/tray_sms.h"
17 #include "ash/system/power/power_status_observer.h" 18 #include "ash/system/power/power_status_observer.h"
18 #include "ash/system/power/power_supply_status.h" 19 #include "ash/system/power/power_supply_status.h"
19 #include "ash/system/power/tray_power.h" 20 #include "ash/system/power/tray_power.h"
20 #include "ash/system/settings/tray_settings.h" 21 #include "ash/system/settings/tray_settings.h"
21 #include "ash/system/tray/system_tray_bubble.h" 22 #include "ash/system/tray/system_tray_bubble.h"
22 #include "ash/system/tray/system_tray_delegate.h" 23 #include "ash/system/tray/system_tray_delegate.h"
23 #include "ash/system/tray/system_tray_item.h" 24 #include "ash/system/tray/system_tray_item.h"
24 #include "ash/system/tray/system_tray_widget_delegate.h" 25 #include "ash/system/tray/system_tray_widget_delegate.h"
25 #include "ash/system/tray/tray_constants.h" 26 #include "ash/system/tray/tray_constants.h"
26 #include "ash/system/tray_accessibility.h" 27 #include "ash/system/tray_accessibility.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 200 }
200 } 201 }
201 202
202 void SystemTray::CreateItems() { 203 void SystemTray::CreateItems() {
203 internal::TrayVolume* tray_volume = new internal::TrayVolume(); 204 internal::TrayVolume* tray_volume = new internal::TrayVolume();
204 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); 205 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth();
205 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness(); 206 internal::TrayBrightness* tray_brightness = new internal::TrayBrightness();
206 internal::TrayDate* tray_date = new internal::TrayDate(); 207 internal::TrayDate* tray_date = new internal::TrayDate();
207 internal::TrayPower* tray_power = new internal::TrayPower(); 208 internal::TrayPower* tray_power = new internal::TrayPower();
208 internal::TrayNetwork* tray_network = new internal::TrayNetwork; 209 internal::TrayNetwork* tray_network = new internal::TrayNetwork;
210 internal::TraySms* tray_sms = new internal::TraySms();
209 internal::TrayUser* tray_user = new internal::TrayUser; 211 internal::TrayUser* tray_user = new internal::TrayUser;
210 internal::TrayAccessibility* tray_accessibility = 212 internal::TrayAccessibility* tray_accessibility =
211 new internal::TrayAccessibility; 213 new internal::TrayAccessibility;
212 internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock; 214 internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock;
213 internal::TrayDrive* tray_drive = new internal::TrayDrive; 215 internal::TrayDrive* tray_drive = new internal::TrayDrive;
214 internal::TrayIME* tray_ime = new internal::TrayIME; 216 internal::TrayIME* tray_ime = new internal::TrayIME;
215 internal::TrayUpdate* tray_update = new internal::TrayUpdate; 217 internal::TrayUpdate* tray_update = new internal::TrayUpdate;
216 218
217 accessibility_observer_ = tray_accessibility; 219 accessibility_observer_ = tray_accessibility;
218 audio_observer_ = tray_volume; 220 audio_observer_ = tray_volume;
219 bluetooth_observer_ = tray_bluetooth; 221 bluetooth_observer_ = tray_bluetooth;
220 brightness_observer_ = tray_brightness; 222 brightness_observer_ = tray_brightness;
221 caps_lock_observer_ = tray_caps_lock; 223 caps_lock_observer_ = tray_caps_lock;
222 clock_observer_ = tray_date; 224 clock_observer_ = tray_date;
223 drive_observer_ = tray_drive; 225 drive_observer_ = tray_drive;
224 ime_observer_ = tray_ime; 226 ime_observer_ = tray_ime;
225 network_observer_ = tray_network; 227 network_observer_ = tray_network;
226 power_status_observer_ = tray_power; 228 power_status_observer_ = tray_power;
227 update_observer_ = tray_update; 229 update_observer_ = tray_update;
228 user_observer_ = tray_user; 230 user_observer_ = tray_user;
229 231
230 AddTrayItem(tray_user); 232 AddTrayItem(tray_user);
231 AddTrayItem(tray_power); 233 AddTrayItem(tray_power);
232 AddTrayItem(tray_network); 234 AddTrayItem(tray_network);
233 AddTrayItem(tray_bluetooth); 235 AddTrayItem(tray_bluetooth);
236 AddTrayItem(tray_sms);
234 AddTrayItem(tray_drive); 237 AddTrayItem(tray_drive);
235 AddTrayItem(tray_ime); 238 AddTrayItem(tray_ime);
236 AddTrayItem(tray_volume); 239 AddTrayItem(tray_volume);
237 AddTrayItem(tray_brightness); 240 AddTrayItem(tray_brightness);
238 AddTrayItem(tray_update); 241 AddTrayItem(tray_update);
239 AddTrayItem(tray_accessibility); 242 AddTrayItem(tray_accessibility);
240 AddTrayItem(tray_caps_lock); 243 AddTrayItem(tray_caps_lock);
241 AddTrayItem(new internal::TraySettings()); 244 AddTrayItem(new internal::TraySettings());
242 AddTrayItem(tray_date); 245 AddTrayItem(tray_date);
243 SetVisible(ash::Shell::GetInstance()->tray_delegate()-> 246 SetVisible(ash::Shell::GetInstance()->tray_delegate()->
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 void SystemTray::ShowDetailedView(SystemTrayItem* item, 295 void SystemTray::ShowDetailedView(SystemTrayItem* item,
293 int close_delay, 296 int close_delay,
294 bool activate, 297 bool activate,
295 BubbleCreationType creation_type) { 298 BubbleCreationType creation_type) {
296 std::vector<SystemTrayItem*> items; 299 std::vector<SystemTrayItem*> items;
297 items.push_back(item); 300 items.push_back(item);
298 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item)); 301 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item));
299 bubble_->StartAutoCloseTimer(close_delay); 302 bubble_->StartAutoCloseTimer(close_delay);
300 } 303 }
301 304
305 void SystemTray::SetDetailedViewCloseDelay(int close_delay) {
306 if (bubble_.get() &&
307 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DETAILED)
308 bubble_->StartAutoCloseTimer(close_delay);
309 }
310
311 void SystemTray::HideDetailedView(SystemTrayItem* item) {
312 if (item != detailed_item_)
313 return;
314 bubble_.reset();
315 UpdateNotificationBubble();
316 }
317
302 void SystemTray::ShowNotificationView(SystemTrayItem* item) { 318 void SystemTray::ShowNotificationView(SystemTrayItem* item) {
303 if (std::find(notification_items_.begin(), notification_items_.end(), item) 319 if (std::find(notification_items_.begin(), notification_items_.end(), item)
304 != notification_items_.end()) 320 != notification_items_.end())
305 return; 321 return;
306 notification_items_.push_back(item); 322 notification_items_.push_back(item);
307 UpdateNotificationBubble(); 323 UpdateNotificationBubble();
308 } 324 }
309 325
310 void SystemTray::HideNotificationView(SystemTrayItem* item) { 326 void SystemTray::HideNotificationView(SystemTrayItem* item) {
311 std::vector<SystemTrayItem*>::iterator found_iter = 327 std::vector<SystemTrayItem*>::iterator found_iter =
312 std::find(notification_items_.begin(), notification_items_.end(), item); 328 std::find(notification_items_.begin(), notification_items_.end(), item);
313 if (found_iter == notification_items_.end()) 329 if (found_iter == notification_items_.end())
314 return; 330 return;
315 notification_items_.erase(found_iter); 331 notification_items_.erase(found_iter);
316 UpdateNotificationBubble(); 332 // Only update the notification bubble if visible (i.e. don't create one).
317 } 333 if (notification_bubble_.get())
318 334 UpdateNotificationBubble();
319 void SystemTray::SetDetailedViewCloseDelay(int close_delay) {
320 if (bubble_.get() &&
321 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DETAILED)
322 bubble_->StartAutoCloseTimer(close_delay);
323 } 335 }
324 336
325 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { 337 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) {
326 bubble_.reset(); 338 bubble_.reset();
327 339
328 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); 340 for (std::vector<SystemTrayItem*>::iterator it = items_.begin();
329 it != items_.end(); 341 it != items_.end();
330 ++it) { 342 ++it) {
331 (*it)->UpdateAfterLoginStatusChange(login_status); 343 (*it)->UpdateAfterLoginStatusChange(login_status);
332 } 344 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 421
410 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items, 422 void SystemTray::ShowItems(const std::vector<SystemTrayItem*>& items,
411 bool detailed, 423 bool detailed,
412 bool can_activate, 424 bool can_activate,
413 BubbleCreationType creation_type, 425 BubbleCreationType creation_type,
414 int arrow_offset) { 426 int arrow_offset) {
415 // Destroy any existing bubble and create a new one. 427 // Destroy any existing bubble and create a new one.
416 SystemTrayBubble::BubbleType bubble_type = detailed ? 428 SystemTrayBubble::BubbleType bubble_type = detailed ?
417 SystemTrayBubble::BUBBLE_TYPE_DETAILED : 429 SystemTrayBubble::BUBBLE_TYPE_DETAILED :
418 SystemTrayBubble::BUBBLE_TYPE_DEFAULT; 430 SystemTrayBubble::BUBBLE_TYPE_DEFAULT;
431
432 // Destroy the notification bubble here so that it doesn't get rebuilt
433 // while we add items to the main bubble_ (e.g. in HideNotificationView).
434 notification_bubble_.reset();
435
419 if (bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { 436 if (bubble_.get() && creation_type == BUBBLE_USE_EXISTING) {
420 bubble_->UpdateView(items, bubble_type); 437 bubble_->UpdateView(items, bubble_type);
421 } else { 438 } else {
422 bubble_.reset(new SystemTrayBubble(this, items, bubble_type)); 439 bubble_.reset(new SystemTrayBubble(this, items, bubble_type));
423 ash::SystemTrayDelegate* delegate = 440 ash::SystemTrayDelegate* delegate =
424 ash::Shell::GetInstance()->tray_delegate(); 441 ash::Shell::GetInstance()->tray_delegate();
425 views::View* anchor = tray_container_; 442 views::View* anchor = tray_container_;
426 SystemTrayBubble::InitParams init_params( 443 SystemTrayBubble::InitParams init_params(
427 SystemTrayBubble::ANCHOR_TYPE_TRAY); 444 SystemTrayBubble::ANCHOR_TYPE_TRAY);
428 init_params.anchor = anchor; 445 init_params.anchor = anchor;
429 init_params.can_activate = can_activate; 446 init_params.can_activate = can_activate;
430 init_params.login_status = delegate->GetUserLoginStatus(); 447 init_params.login_status = delegate->GetUserLoginStatus();
431 if (arrow_offset >= 0) 448 if (arrow_offset >= 0)
432 init_params.arrow_offset = arrow_offset; 449 init_params.arrow_offset = arrow_offset;
433 bubble_->InitView(init_params); 450 bubble_->InitView(init_params);
434 } 451 }
452
453 if (detailed && items.size() > 0)
454 detailed_item_ = items[0];
455 else
456 detailed_item_ = NULL;
457
435 // If we have focus the shelf should be visible and we need to continue 458 // If we have focus the shelf should be visible and we need to continue
436 // showing the shelf when the popup is shown. 459 // showing the shelf when the popup is shown.
437 if (GetWidget()->IsActive()) 460 if (GetWidget()->IsActive())
438 should_show_launcher_ = true; 461 should_show_launcher_ = true;
462
439 UpdateNotificationBubble(); // State changed, re-create notifications. 463 UpdateNotificationBubble(); // State changed, re-create notifications.
440 } 464 }
441 465
442 void SystemTray::UpdateNotificationBubble() { 466 void SystemTray::UpdateNotificationBubble() {
443 // Only show the notification buble if we have notifications and we are not 467 // Only show the notification buble if we have notifications and we are not
444 // showing the default bubble. 468 // showing the default bubble.
445 if (notification_items_.empty() || 469 if (notification_items_.empty() ||
446 (bubble_.get() && 470 (bubble_.get() &&
447 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 471 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
448 notification_bubble_.reset(); 472 notification_bubble_.reset();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 canvas->DrawFocusRect(tray_container_->bounds()); 555 canvas->DrawFocusRect(tray_container_->bounds());
532 } 556 }
533 557
534 void SystemTray::UpdateBackground(int alpha) { 558 void SystemTray::UpdateBackground(int alpha) {
535 background_->set_alpha(hide_background_animator_.alpha() + 559 background_->set_alpha(hide_background_animator_.alpha() +
536 hover_background_animator_.alpha()); 560 hover_background_animator_.alpha());
537 SchedulePaint(); 561 SchedulePaint();
538 } 562 }
539 563
540 } // namespace ash 564 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray.h ('k') | ash/system/tray/system_tray_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698