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