Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / system / date / date_view.h
blob05d042c0d4415e895b4a33530b27f605cb08eeba
1 // Copyright (c) 2012 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.
5 #ifndef ASH_SYSTEM_DATE_DATE_VIEW_H_
6 #define ASH_SYSTEM_DATE_DATE_VIEW_H_
8 #include "ash/ash_export.h"
9 #include "ash/system/date/tray_date.h"
10 #include "ash/system/tray/actionable_view.h"
11 #include "base/i18n/time_formatting.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/timer/timer.h"
14 #include "ui/views/view.h"
16 namespace views {
17 class Label;
20 namespace ash {
21 namespace tray {
23 // Abstract base class containing common updating and layout code for the
24 // DateView popup and the TimeView tray icon. Exported for tests.
25 class ASH_EXPORT BaseDateTimeView : public ActionableView {
26 public:
27 ~BaseDateTimeView() override;
29 // Updates the displayed text for the current time and calls SetTimer().
30 void UpdateText();
32 protected:
33 BaseDateTimeView();
35 private:
36 // Starts |timer_| to schedule the next update.
37 void SetTimer(const base::Time& now);
39 // Updates labels to display the current time.
40 virtual void UpdateTextInternal(const base::Time& now) = 0;
42 // Overridden from views::View.
43 void ChildPreferredSizeChanged(views::View* child) override;
44 void OnLocaleChanged() override;
46 // Invokes UpdateText() when the displayed time should change.
47 base::OneShotTimer<BaseDateTimeView> timer_;
49 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView);
52 // Popup view used to display the date and day of week.
53 class ASH_EXPORT DateView : public BaseDateTimeView {
54 public:
55 DateView();
56 ~DateView() override;
58 // Sets the action the view should take. An actionable date view gives visual
59 // feedback on hover, can be focused by keyboard, and clicking/pressing space
60 // or enter on the view executes the action.
61 void SetAction(TrayDate::DateAction action);
63 // Updates the format of the displayed time.
64 void UpdateTimeFormat();
66 base::HourClockType GetHourTypeForTesting() const;
68 private:
69 // Sets active rendering state and updates the color of |date_label_|.
70 void SetActive(bool active);
72 // Overridden from BaseDateTimeView.
73 void UpdateTextInternal(const base::Time& now) override;
75 // Overridden from ActionableView.
76 bool PerformAction(const ui::Event& event) override;
78 // Overridden from views::View.
79 void OnMouseEntered(const ui::MouseEvent& event) override;
80 void OnMouseExited(const ui::MouseEvent& event) override;
81 void OnGestureEvent(ui::GestureEvent* event) override;
83 views::Label* date_label_;
85 // Time format (12/24hr) used for accessibility string.
86 base::HourClockType hour_type_;
88 TrayDate::DateAction action_;
90 DISALLOW_COPY_AND_ASSIGN(DateView);
93 // Tray view used to display the current time.
94 // Exported for tests.
95 class ASH_EXPORT TimeView : public BaseDateTimeView {
96 public:
97 explicit TimeView(TrayDate::ClockLayout clock_layout);
98 ~TimeView() override;
100 // Updates the format of the displayed time.
101 void UpdateTimeFormat();
103 // Updates clock layout.
104 void UpdateClockLayout(TrayDate::ClockLayout clock_layout);
106 base::HourClockType GetHourTypeForTesting() const;
108 private:
109 friend class TimeViewTest;
111 // Overridden from BaseDateTimeView.
112 void UpdateTextInternal(const base::Time& now) override;
114 // Overridden from ActionableView.
115 bool PerformAction(const ui::Event& event) override;
117 // Overridden from views::View.
118 bool OnMousePressed(const ui::MouseEvent& event) override;
120 void SetBorderFromLayout(TrayDate::ClockLayout clock_layout);
121 void SetupLabels();
122 void SetupLabel(views::Label* label);
124 // Label text used for the normal horizontal shelf.
125 scoped_ptr<views::Label> horizontal_label_;
127 // The time label is split into two lines for the vertical shelf.
128 scoped_ptr<views::Label> vertical_label_hours_;
129 scoped_ptr<views::Label> vertical_label_minutes_;
131 base::HourClockType hour_type_;
133 DISALLOW_COPY_AND_ASSIGN(TimeView);
136 } // namespace tray
137 } // namespace ash
139 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_