Home | History | Annotate | Download | only in chromeos
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ash/system/chromeos/tray_tracing.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ash/system/tray/actionable_view.h"
      9 #include "ash/system/tray/fixed_sized_image_view.h"
     10 #include "ash/system/tray/system_tray.h"
     11 #include "ash/system/tray/system_tray_delegate.h"
     12 #include "ash/system/tray/system_tray_notifier.h"
     13 #include "ash/system/tray/tray_constants.h"
     14 #include "grit/ash_resources.h"
     15 #include "grit/ash_strings.h"
     16 #include "ui/base/resource/resource_bundle.h"
     17 #include "ui/gfx/image/image.h"
     18 #include "ui/views/controls/image_view.h"
     19 #include "ui/views/controls/label.h"
     20 #include "ui/views/layout/box_layout.h"
     21 
     22 namespace ash {
     23 namespace tray {
     24 
     25 class DefaultTracingView : public ActionableView {
     26  public:
     27   DefaultTracingView() {
     28     SetLayoutManager(new views::BoxLayout(
     29         views::BoxLayout::kHorizontal,
     30         kTrayPopupPaddingHorizontal, 0,
     31         kTrayPopupPaddingBetweenItems));
     32 
     33     ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
     34     image_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
     35     image_->SetImage(
     36         bundle.GetImageNamed(IDR_AURA_UBER_TRAY_TRACING).ToImageSkia());
     37     AddChildView(image_);
     38 
     39     label_ = new views::Label();
     40     label_->SetMultiLine(true);
     41     label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
     42     label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_TRACING));
     43     AddChildView(label_);
     44   }
     45 
     46   virtual ~DefaultTracingView() {}
     47 
     48  private:
     49   // Overridden from ActionableView.
     50   virtual bool PerformAction(const ui::Event& event) OVERRIDE {
     51     Shell::GetInstance()->system_tray_delegate()->ShowChromeSlow();
     52     return true;
     53   }
     54 
     55   views::ImageView* image_;
     56   views::Label* label_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(DefaultTracingView);
     59 };
     60 
     61 }  // namespace tray
     62 
     63 ////////////////////////////////////////////////////////////////////////////////
     64 // ash::TrayTracing
     65 
     66 TrayTracing::TrayTracing(SystemTray* system_tray)
     67     : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_TRACING),
     68       default_(NULL) {
     69   DCHECK(Shell::GetInstance()->delegate());
     70   DCHECK(system_tray);
     71   Shell::GetInstance()->system_tray_notifier()->AddTracingObserver(this);
     72 }
     73 
     74 TrayTracing::~TrayTracing() {
     75   Shell::GetInstance()->system_tray_notifier()->RemoveTracingObserver(this);
     76 }
     77 
     78 void TrayTracing::SetTrayIconVisible(bool visible) {
     79   if (tray_view())
     80     tray_view()->SetVisible(visible);
     81 }
     82 
     83 bool TrayTracing::GetInitialVisibility() {
     84   return false;
     85 }
     86 
     87 views::View* TrayTracing::CreateDefaultView(user::LoginStatus status) {
     88   CHECK(default_ == NULL);
     89   if (tray_view() && tray_view()->visible())
     90     default_ = new tray::DefaultTracingView();
     91   return default_;
     92 }
     93 
     94 views::View* TrayTracing::CreateDetailedView(user::LoginStatus status) {
     95   return NULL;
     96 }
     97 
     98 void TrayTracing::DestroyDefaultView() {
     99   default_ = NULL;
    100 }
    101 
    102 void TrayTracing::DestroyDetailedView() {
    103 }
    104 
    105 void TrayTracing::OnTracingModeChanged(bool value) {
    106   SetTrayIconVisible(value);
    107 }
    108 
    109 }  // namespace ash
    110