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

Side by Side Diff: ash/system/chromeos/network/tray_network.cc

Issue 11415014: Stop using shell::GetInstance()->system_tray() in system tray items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix single-letter typo :(. Created 8 years, 1 month 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/chromeos/network/tray_network.h ('k') | ash/system/chromeos/network/tray_sms.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/chromeos/network/tray_network.h" 5 #include "ash/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" 8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h"
9 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 MessageMap& messages() { return messages_; } 82 MessageMap& messages() { return messages_; }
83 const MessageMap& messages() const { return messages_; } 83 const MessageMap& messages() const { return messages_; }
84 84
85 private: 85 private:
86 MessageMap messages_; 86 MessageMap messages_;
87 }; 87 };
88 88
89 class NetworkTrayView : public TrayItemView { 89 class NetworkTrayView : public TrayItemView {
90 public: 90 public:
91 NetworkTrayView(ColorTheme size, bool tray_icon) 91 NetworkTrayView(SystemTrayItem* owner, ColorTheme size, bool tray_icon)
92 : color_theme_(size), tray_icon_(tray_icon) { 92 : TrayItemView(owner), color_theme_(size), tray_icon_(tray_icon) {
93 SetLayoutManager( 93 SetLayoutManager(
94 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 94 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
95 95
96 image_view_ = color_theme_ == DARK ? 96 image_view_ = color_theme_ == DARK ?
97 new FixedSizedImageView(0, kTrayPopupItemHeight) : 97 new FixedSizedImageView(0, kTrayPopupItemHeight) :
98 new views::ImageView; 98 new views::ImageView;
99 AddChildView(image_view_); 99 AddChildView(image_view_);
100 100
101 NetworkIconInfo info; 101 NetworkIconInfo info;
102 Shell::GetInstance()->tray_delegate()-> 102 Shell::GetInstance()->tray_delegate()->
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 SetLabel(info.description); 138 SetLabel(info.description);
139 SetAccessibleName(info.description); 139 SetAccessibleName(info.description);
140 } 140 }
141 141
142 private: 142 private:
143 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); 143 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
144 }; 144 };
145 145
146 class NetworkListDetailedView : public NetworkListDetailedViewBase { 146 class NetworkListDetailedView : public NetworkListDetailedViewBase {
147 public: 147 public:
148 NetworkListDetailedView(user::LoginStatus login, int header_string_id) 148 NetworkListDetailedView(SystemTrayItem* owner,
149 : NetworkListDetailedViewBase(login, header_string_id), 149 user::LoginStatus login,
150 int header_string_id)
151 : NetworkListDetailedViewBase(owner, login, header_string_id),
150 airplane_(NULL), 152 airplane_(NULL),
151 button_wifi_(NULL), 153 button_wifi_(NULL),
152 button_mobile_(NULL), 154 button_mobile_(NULL),
153 view_mobile_account_(NULL), 155 view_mobile_account_(NULL),
154 setup_mobile_account_(NULL), 156 setup_mobile_account_(NULL),
155 other_wifi_(NULL), 157 other_wifi_(NULL),
156 turn_on_wifi_(NULL), 158 turn_on_wifi_(NULL),
157 other_mobile_(NULL) { 159 other_mobile_(NULL) {
158 } 160 }
159 161
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 views::View* setup_mobile_account_; 365 views::View* setup_mobile_account_;
364 TrayPopupLabelButton* other_wifi_; 366 TrayPopupLabelButton* other_wifi_;
365 TrayPopupLabelButton* turn_on_wifi_; 367 TrayPopupLabelButton* turn_on_wifi_;
366 TrayPopupLabelButton* other_mobile_; 368 TrayPopupLabelButton* other_mobile_;
367 369
368 DISALLOW_COPY_AND_ASSIGN(NetworkListDetailedView); 370 DISALLOW_COPY_AND_ASSIGN(NetworkListDetailedView);
369 }; 371 };
370 372
371 class NetworkWifiDetailedView : public NetworkDetailedView { 373 class NetworkWifiDetailedView : public NetworkDetailedView {
372 public: 374 public:
373 explicit NetworkWifiDetailedView(bool wifi_enabled) { 375 NetworkWifiDetailedView(SystemTrayItem* owner, bool wifi_enabled)
376 : NetworkDetailedView(owner) {
374 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 377 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
375 kTrayPopupPaddingHorizontal, 378 kTrayPopupPaddingHorizontal,
376 10, 379 10,
377 kTrayPopupPaddingBetweenItems)); 380 kTrayPopupPaddingBetweenItems));
378 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 381 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
379 views::ImageView* image = new views::ImageView; 382 views::ImageView* image = new views::ImageView;
380 const int image_id = wifi_enabled ? 383 const int image_id = wifi_enabled ?
381 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; 384 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED;
382 image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); 385 image->SetImage(bundle.GetImageNamed(image_id).ToImageSkia());
383 AddChildView(image); 386 AddChildView(image);
(...skipping 21 matching lines...) Expand all
405 408
406 virtual void Update() OVERRIDE {} 409 virtual void Update() OVERRIDE {}
407 410
408 private: 411 private:
409 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); 412 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
410 }; 413 };
411 414
412 class NetworkMessageView : public views::View, 415 class NetworkMessageView : public views::View,
413 public views::LinkListener { 416 public views::LinkListener {
414 public: 417 public:
415 NetworkMessageView(TrayNetwork* tray, 418 NetworkMessageView(TrayNetwork* owner,
416 TrayNetwork::MessageType message_type, 419 TrayNetwork::MessageType message_type,
417 const NetworkMessages::Message& network_msg) 420 const NetworkMessages::Message& network_msg)
418 : tray_(tray), 421 : owner_(owner),
419 message_type_(message_type), 422 message_type_(message_type),
420 network_type_(network_msg.network_type_) { 423 network_type_(network_msg.network_type_) {
421 SetLayoutManager( 424 SetLayoutManager(
422 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 425 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1));
423 426
424 if (!network_msg.title.empty()) { 427 if (!network_msg.title.empty()) {
425 views::Label* title = new views::Label(network_msg.title); 428 views::Label* title = new views::Label(network_msg.title);
426 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 429 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
427 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD)); 430 title->SetFont(title->font().DeriveFont(0, gfx::Font::BOLD));
428 AddChildView(title); 431 AddChildView(title);
(...skipping 18 matching lines...) Expand all
447 AddChildView(link); 450 AddChildView(link);
448 } 451 }
449 } 452 }
450 } 453 }
451 454
452 virtual ~NetworkMessageView() { 455 virtual ~NetworkMessageView() {
453 } 456 }
454 457
455 // Overridden from views::LinkListener. 458 // Overridden from views::LinkListener.
456 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { 459 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
457 tray_->LinkClicked(message_type_, source->id()); 460 owner_->LinkClicked(message_type_, source->id());
458 } 461 }
459 462
460 TrayNetwork::MessageType message_type() const { return message_type_; } 463 TrayNetwork::MessageType message_type() const { return message_type_; }
461 TrayNetwork::NetworkType network_type() const { return network_type_; } 464 TrayNetwork::NetworkType network_type() const { return network_type_; }
462 465
463 private: 466 private:
464 TrayNetwork* tray_; 467 TrayNetwork* owner_;
465 TrayNetwork::MessageType message_type_; 468 TrayNetwork::MessageType message_type_;
466 TrayNetwork::NetworkType network_type_; 469 TrayNetwork::NetworkType network_type_;
467 470
468 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView); 471 DISALLOW_COPY_AND_ASSIGN(NetworkMessageView);
469 }; 472 };
470 473
471 class NetworkNotificationView : public TrayNotificationView { 474 class NetworkNotificationView : public TrayNotificationView {
472 public: 475 public:
473 explicit NetworkNotificationView(TrayNetwork* tray) 476 explicit NetworkNotificationView(TrayNetwork* owner)
474 : TrayNotificationView(tray, 0) { 477 : TrayNotificationView(owner, 0) {
475 CreateMessageView(); 478 CreateMessageView();
476 InitView(network_message_view_); 479 InitView(network_message_view_);
477 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 480 SetIconImage(*ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
478 GetMessageIcon(network_message_view_->message_type(), 481 GetMessageIcon(network_message_view_->message_type(),
479 network_message_view_->network_type()))); 482 network_message_view_->network_type())));
480 } 483 }
481 484
482 // Overridden from TrayNotificationView. 485 // Overridden from TrayNotificationView.
483 virtual void OnClose() OVERRIDE { 486 virtual void OnClose() OVERRIDE {
484 tray_network()->ClearNetworkMessage(network_message_view_->message_type()); 487 tray_network()->ClearNetworkMessage(network_message_view_->message_type());
485 } 488 }
486 489
487 virtual void OnClickAction() OVERRIDE { 490 virtual void OnClickAction() OVERRIDE {
488 if (network_message_view_->message_type() != 491 if (network_message_view_->message_type() !=
489 TrayNetwork::MESSAGE_DATA_PROMO) 492 TrayNetwork::MESSAGE_DATA_PROMO)
490 tray()->PopupDetailedView(0, true); 493 owner()->PopupDetailedView(0, true);
491 } 494 }
492 495
493 void Update() { 496 void Update() {
494 CreateMessageView(); 497 CreateMessageView();
495 UpdateViewAndImage(network_message_view_, 498 UpdateViewAndImage(network_message_view_,
496 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 499 *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
497 GetMessageIcon(network_message_view_->message_type(), 500 GetMessageIcon(network_message_view_->message_type(),
498 network_message_view_->network_type()))); 501 network_message_view_->network_type())));
499 } 502 }
500 503
501 private: 504 private:
502 TrayNetwork* tray_network() { 505 TrayNetwork* tray_network() {
503 return static_cast<TrayNetwork*>(tray()); 506 return static_cast<TrayNetwork*>(owner());
504 } 507 }
505 508
506 void CreateMessageView() { 509 void CreateMessageView() {
507 // Display the first (highest priority) message. 510 // Display the first (highest priority) message.
508 CHECK(!tray_network()->messages()->messages().empty()); 511 CHECK(!tray_network()->messages()->messages().empty());
509 NetworkMessages::MessageMap::const_iterator iter = 512 NetworkMessages::MessageMap::const_iterator iter =
510 tray_network()->messages()->messages().begin(); 513 tray_network()->messages()->messages().begin();
511 network_message_view_ = 514 network_message_view_ =
512 new NetworkMessageView(tray_network(), iter->first, iter->second); 515 new NetworkMessageView(tray_network(), iter->first, iter->second);
513 } 516 }
514 517
515 tray::NetworkMessageView* network_message_view_; 518 tray::NetworkMessageView* network_message_view_;
516 519
517 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView); 520 DISALLOW_COPY_AND_ASSIGN(NetworkNotificationView);
518 }; 521 };
519 522
520 } // namespace tray 523 } // namespace tray
521 524
522 TrayNetwork::TrayNetwork() 525 TrayNetwork::TrayNetwork(SystemTray* system_tray)
523 : tray_(NULL), 526 : SystemTrayItem(system_tray),
527 tray_(NULL),
524 default_(NULL), 528 default_(NULL),
525 detailed_(NULL), 529 detailed_(NULL),
526 notification_(NULL), 530 notification_(NULL),
527 messages_(new tray::NetworkMessages()), 531 messages_(new tray::NetworkMessages()),
528 request_wifi_view_(false) { 532 request_wifi_view_(false) {
529 } 533 }
530 534
531 TrayNetwork::~TrayNetwork() { 535 TrayNetwork::~TrayNetwork() {
532 } 536 }
533 537
534 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { 538 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) {
535 CHECK(tray_ == NULL); 539 CHECK(tray_ == NULL);
536 tray_ = new tray::NetworkTrayView(tray::LIGHT, true /*tray_icon*/); 540 tray_ = new tray::NetworkTrayView(this, tray::LIGHT, true /*tray_icon*/);
537 return tray_; 541 return tray_;
538 } 542 }
539 543
540 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { 544 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) {
541 CHECK(default_ == NULL); 545 CHECK(default_ == NULL);
542 default_ = 546 default_ =
543 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); 547 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED);
544 return default_; 548 return default_;
545 } 549 }
546 550
547 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { 551 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) {
548 CHECK(detailed_ == NULL); 552 CHECK(detailed_ == NULL);
549 // Clear any notifications when showing the detailed view. 553 // Clear any notifications when showing the detailed view.
550 messages_->messages().clear(); 554 messages_->messages().clear();
551 HideNotificationView(); 555 HideNotificationView();
552 if (request_wifi_view_) { 556 if (request_wifi_view_) {
553 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); 557 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate();
554 // The Wi-Fi state is not toggled yet at this point. 558 // The Wi-Fi state is not toggled yet at this point.
555 detailed_ = new tray::NetworkWifiDetailedView(!delegate->GetWifiEnabled()); 559 detailed_ = new tray::NetworkWifiDetailedView(this,
560 !delegate->GetWifiEnabled());
556 request_wifi_view_ = false; 561 request_wifi_view_ = false;
557 } else { 562 } else {
558 detailed_ = new tray::NetworkListDetailedView( 563 detailed_ = new tray::NetworkListDetailedView(
559 status, IDS_ASH_STATUS_TRAY_NETWORK); 564 this, status, IDS_ASH_STATUS_TRAY_NETWORK);
560 detailed_->Init(); 565 detailed_->Init();
561 } 566 }
562 return detailed_; 567 return detailed_;
563 } 568 }
564 569
565 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { 570 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) {
566 CHECK(notification_ == NULL); 571 CHECK(notification_ == NULL);
567 if (messages_->messages().empty()) 572 if (messages_->messages().empty())
568 return NULL; // Message has already been cleared. 573 return NULL; // Message has already been cleared.
569 notification_ = new tray::NetworkNotificationView(this); 574 notification_ = new tray::NetworkNotificationView(this);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 643
639 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { 644 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) {
640 tray::NetworkMessages::MessageMap::const_iterator iter = 645 tray::NetworkMessages::MessageMap::const_iterator iter =
641 messages()->messages().find(message_type); 646 messages()->messages().find(message_type);
642 if (iter != messages()->messages().end() && iter->second.delegate) 647 if (iter != messages()->messages().end() && iter->second.delegate)
643 iter->second.delegate->NotificationLinkClicked(link_id); 648 iter->second.delegate->NotificationLinkClicked(link_id);
644 } 649 }
645 650
646 } // namespace internal 651 } // namespace internal
647 } // namespace ash 652 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/network/tray_network.h ('k') | ash/system/chromeos/network/tray_sms.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698