1ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
2ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
3ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// found in the LICENSE file.
4ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
5ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/chromeos/tray_tracing.h"
6ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shell.h"
8ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/actionable_view.h"
9ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/fixed_sized_image_view.h"
10ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/system_tray.h"
11ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/system_tray_delegate.h"
12ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/system_tray_notifier.h"
13ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ash/system/tray/tray_constants.h"
14ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "grit/ash_resources.h"
15ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "grit/ash_strings.h"
16ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/base/resource/resource_bundle.h"
17ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/gfx/image/image.h"
18ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/views/controls/image_view.h"
19ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/views/controls/label.h"
20ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "ui/views/layout/box_layout.h"
21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace ash {
23ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochnamespace tray {
24ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
25c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochclass DefaultTracingView : public ActionableView {
26ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch public:
27ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DefaultTracingView() {
28ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    SetLayoutManager(new views::BoxLayout(
29ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        views::BoxLayout::kHorizontal,
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kTrayPopupPaddingHorizontal, 0,
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        kTrayPopupPaddingBetweenItems));
32ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
33ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
34c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch    image_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
35ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    image_->SetImage(
36ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch        bundle.GetImageNamed(IDR_AURA_UBER_TRAY_TRACING).ToImageSkia());
37ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    AddChildView(image_);
38ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
39ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    label_ = new views::Label();
40ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    label_->SetMultiLine(true);
41ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
42ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_TRACING));
43ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    AddChildView(label_);
44ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
45ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
46ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual ~DefaultTracingView() {}
47ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
48ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch private:
49ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Overridden from ActionableView.
50ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual bool PerformAction(const ui::Event& event) OVERRIDE {
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    Shell::GetInstance()->system_tray_delegate()->ShowChromeSlow();
52ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    return true;
53ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  }
54ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
55ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  views::ImageView* image_;
56ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  views::Label* label_;
57ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
58ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DISALLOW_COPY_AND_ASSIGN(DefaultTracingView);
59ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch};
60ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
61ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}  // namespace tray
62ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
63ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch////////////////////////////////////////////////////////////////////////////////
64c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch// ash::TrayTracing
65ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
66ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben MurdochTrayTracing::TrayTracing(SystemTray* system_tray)
67ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_TRACING),
68ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      default_(NULL) {
69ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DCHECK(Shell::GetInstance()->delegate());
70ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  DCHECK(system_tray);
71ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  Shell::GetInstance()->system_tray_notifier()->AddTracingObserver(this);
72ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
73ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
74ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben MurdochTrayTracing::~TrayTracing() {
75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  Shell::GetInstance()->system_tray_notifier()->RemoveTracingObserver(this);
76ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
77ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
78ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid TrayTracing::SetTrayIconVisible(bool visible) {
79ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  if (tray_view())
80ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch    tray_view()->SetVisible(visible);
81ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
82ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
83ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochbool TrayTracing::GetInitialVisibility() {
84ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  return false;
85ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
86ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
87ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochviews::View* TrayTracing::CreateDefaultView(user::LoginStatus status) {
88ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  CHECK(default_ == NULL);
893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  if (tray_view() && tray_view()->visible())
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    default_ = new tray::DefaultTracingView();
91ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  return default_;
92ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
93ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
94ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochviews::View* TrayTracing::CreateDetailedView(user::LoginStatus status) {
95ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  return NULL;
96ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
97ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
98ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid TrayTracing::DestroyDefaultView() {
99ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  default_ = NULL;
100ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
101ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
102ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid TrayTracing::DestroyDetailedView() {
103ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
104ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
105ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdochvoid TrayTracing::OnTracingModeChanged(bool value) {
106ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  SetTrayIconVisible(value);
107ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
108ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
109ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}  // namespace ash
110