tray_tracing.cc revision ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16
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/system/tray/actionable_view.h"
8#include "ash/system/tray/fixed_sized_image_view.h"
9#include "ash/system/tray/system_tray.h"
10#include "ash/system/tray/system_tray_delegate.h"
11#include "ash/system/tray/system_tray_notifier.h"
12#include "ash/system/tray/tray_constants.h"
13#include "grit/ash_resources.h"
14#include "grit/ash_strings.h"
15#include "ui/base/l10n/l10n_util.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
22namespace ash {
23namespace internal {
24
25namespace tray {
26
27class DefaultTracingView : public ash::internal::ActionableView {
28 public:
29  DefaultTracingView() {
30    SetLayoutManager(new views::BoxLayout(
31        views::BoxLayout::kHorizontal,
32        ash::kTrayPopupPaddingHorizontal, 0,
33        ash::kTrayPopupPaddingBetweenItems));
34
35    ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
36    image_ =
37        new ash::internal::FixedSizedImageView(0, ash::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    ash::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  default_ = new tray::DefaultTracingView();
93  return default_;
94}
95
96views::View* TrayTracing::CreateDetailedView(user::LoginStatus status) {
97  return NULL;
98}
99
100void TrayTracing::DestroyDefaultView() {
101  default_ = NULL;
102}
103
104void TrayTracing::DestroyDetailedView() {
105}
106
107void TrayTracing::OnTracingModeChanged(bool value) {
108  SetTrayIconVisible(value);
109}
110
111}  // namespace internal
112}  // namespace ash
113