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