summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/status/status_area_view_chromeos.cc
blob: 5503b49a7f491b4483279d0bbf0c5270fe716bbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/status/status_area_view_chromeos.h"

#include "base/command_line.h"
#include "chrome/browser/chromeos/status/accessibility_menu_button.h"
#include "chrome/browser/chromeos/status/caps_lock_menu_button.h"
#include "chrome/browser/chromeos/status/clock_menu_button.h"
#include "chrome/browser/chromeos/status/input_method_menu_button.h"
#include "chrome/browser/chromeos/status/memory_menu_button.h"
#include "chrome/browser/chromeos/status/network_menu_button.h"
#include "chrome/browser/chromeos/status/power_menu_button.h"
#include "chrome/browser/chromeos/status/volume_menu_button.h"
#include "chrome/browser/chromeos/view_ids.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"

namespace chromeos {

// static
StatusAreaViewChromeos::ScreenMode
    StatusAreaViewChromeos::screen_mode_ = BROWSER_MODE;

// static
bool StatusAreaViewChromeos::IsBrowserMode() {
  return screen_mode_ == BROWSER_MODE;
}

// static
bool StatusAreaViewChromeos::IsLoginMode() {
  return screen_mode_ == LOGIN_MODE_WEBUI;
}

// static
bool StatusAreaViewChromeos::IsScreenLockMode() {
  return screen_mode_ == SCREEN_LOCKER_MODE;
}

// static
void StatusAreaViewChromeos::SetScreenMode(ScreenMode mode) {
  screen_mode_ = mode;
}

StatusAreaViewChromeos::StatusAreaViewChromeos() {
  DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
  system::TimezoneSettings::GetInstance()->AddObserver(this);
}

StatusAreaViewChromeos::~StatusAreaViewChromeos() {
  DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
  system::TimezoneSettings::GetInstance()->RemoveObserver(this);
}

void StatusAreaViewChromeos::Init(StatusAreaButton::Delegate* delegate) {
  AddChromeosButtons(this, delegate, NULL);
}

void StatusAreaViewChromeos::SystemResumed() {
  UpdateClockText();
}

void StatusAreaViewChromeos::TimezoneChanged(const icu::TimeZone& timezone) {
  UpdateClockText();
}

void StatusAreaViewChromeos::UpdateClockText() {
  ClockMenuButton* clock_button =
      static_cast<ClockMenuButton*>(GetViewByID(VIEW_ID_STATUS_BUTTON_CLOCK));
  if (clock_button)
    clock_button->UpdateText();
}

// static
void StatusAreaViewChromeos::AddChromeosButtons(
    StatusAreaView* status_area,
    StatusAreaButton::Delegate* delegate,
    ClockMenuButton** clock_button) {
  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kMemoryWidget))
    status_area->AddButton(new MemoryMenuButton(delegate),
                           StatusAreaView::NO_BORDER);

  status_area->AddButton(new AccessibilityMenuButton(delegate),
                         StatusAreaView::HAS_BORDER);
  status_area->AddButton(new CapsLockMenuButton(delegate),
                         StatusAreaView::HAS_BORDER);
  ClockMenuButton* clock = new ClockMenuButton(delegate);
  status_area->AddButton(clock, StatusAreaView::HAS_BORDER);
  if (clock_button)
    *clock_button = clock;

  status_area->AddButton(new VolumeMenuButton(delegate),
                         StatusAreaView::NO_BORDER);
  status_area->AddButton(new InputMethodMenuButton(delegate),
                         StatusAreaView::NO_BORDER);
  status_area->AddButton(new NetworkMenuButton(delegate),
                         StatusAreaView::NO_BORDER);
  status_area->AddButton(new PowerMenuButton(delegate),
                         StatusAreaView::NO_BORDER);
}

}  // namespace chromeos