OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef ASH_COMMON_SYSTEM_DATE_DATE_VIEW_H_ | |
6 #define ASH_COMMON_SYSTEM_DATE_DATE_VIEW_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/ash_export.h" | |
11 #include "ash/common/system/date/tray_date.h" | |
12 #include "ash/common/system/tray/actionable_view.h" | |
13 #include "base/i18n/time_formatting.h" | |
14 #include "base/macros.h" | |
15 #include "base/timer/timer.h" | |
16 #include "ui/views/view.h" | |
17 | |
18 namespace base { | |
19 class Time; | |
20 } | |
21 | |
22 namespace views { | |
23 class Label; | |
24 } | |
25 | |
26 namespace ash { | |
27 namespace tray { | |
28 | |
29 // Abstract base class containing common updating and layout code for the | |
30 // DateView popup and the TimeView tray icon. Exported for tests. | |
31 class ASH_EXPORT BaseDateTimeView : public ActionableView { | |
32 public: | |
33 ~BaseDateTimeView() override; | |
34 | |
35 // Updates the displayed text for the current time and calls SetTimer(). | |
36 void UpdateText(); | |
37 | |
38 // views::View: | |
39 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | |
40 | |
41 protected: | |
42 explicit BaseDateTimeView(SystemTrayItem* owner); | |
43 | |
44 // Updates labels to display the current time. | |
45 virtual void UpdateTextInternal(const base::Time& now); | |
46 | |
47 // Time format (12/24hr) used for accessibility string. | |
48 base::HourClockType hour_type_; | |
49 | |
50 private: | |
51 // Starts |timer_| to schedule the next update. | |
52 void SetTimer(const base::Time& now); | |
53 | |
54 // views::View: | |
55 void ChildPreferredSizeChanged(views::View* child) override; | |
56 void OnLocaleChanged() override; | |
57 | |
58 // Invokes UpdateText() when the displayed time should change. | |
59 base::OneShotTimer timer_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView); | |
62 }; | |
63 | |
64 // Popup view used to display the date and day of week. | |
65 class ASH_EXPORT DateView : public BaseDateTimeView { | |
66 public: | |
67 enum class DateAction { | |
68 NONE, | |
69 SET_SYSTEM_TIME, | |
70 SHOW_DATE_SETTINGS, | |
71 }; | |
72 | |
73 explicit DateView(SystemTrayItem* owner); | |
74 ~DateView() override; | |
75 | |
76 // Sets the action the view should take. An actionable date view gives visual | |
77 // feedback on hover, can be focused by keyboard, and clicking/pressing space | |
78 // or enter on the view executes the action. | |
79 void SetAction(DateAction action); | |
80 | |
81 // Updates the format of the displayed time. | |
82 void UpdateTimeFormat(); | |
83 | |
84 base::HourClockType GetHourTypeForTesting() const; | |
85 | |
86 private: | |
87 // Sets active rendering state and updates the color of |date_label_|. | |
88 void SetActive(bool active); | |
89 | |
90 // BaseDateTimeView: | |
91 void UpdateTextInternal(const base::Time& now) override; | |
92 | |
93 // ActionableView: | |
94 bool PerformAction(const ui::Event& event) override; | |
95 | |
96 // views::View: | |
97 void OnMouseEntered(const ui::MouseEvent& event) override; | |
98 void OnMouseExited(const ui::MouseEvent& event) override; | |
99 void OnGestureEvent(ui::GestureEvent* event) override; | |
100 | |
101 views::Label* date_label_; | |
102 | |
103 DateAction action_; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(DateView); | |
106 }; | |
107 | |
108 // Tray view used to display the current time. | |
109 // Exported for tests. | |
110 class ASH_EXPORT TimeView : public BaseDateTimeView { | |
111 public: | |
112 enum class ClockLayout { | |
113 HORIZONTAL_CLOCK, | |
114 VERTICAL_CLOCK, | |
115 }; | |
116 | |
117 explicit TimeView(ClockLayout clock_layout); | |
118 ~TimeView() override; | |
119 | |
120 // Updates the format of the displayed time. | |
121 void UpdateTimeFormat(); | |
122 | |
123 // Updates clock layout. | |
124 void UpdateClockLayout(ClockLayout clock_layout); | |
125 | |
126 base::HourClockType GetHourTypeForTesting() const; | |
127 | |
128 private: | |
129 friend class TimeViewTest; | |
130 | |
131 // BaseDateTimeView: | |
132 void UpdateTextInternal(const base::Time& now) override; | |
133 | |
134 // ActionableView: | |
135 bool PerformAction(const ui::Event& event) override; | |
136 | |
137 // views::View: | |
138 bool OnMousePressed(const ui::MouseEvent& event) override; | |
139 void OnGestureEvent(ui::GestureEvent* event) override; | |
140 | |
141 void SetBorderFromLayout(ClockLayout clock_layout); | |
142 void SetupLabels(); | |
143 void SetupLabel(views::Label* label); | |
144 | |
145 // Label text used for the normal horizontal shelf. | |
146 std::unique_ptr<views::Label> horizontal_label_; | |
147 | |
148 // The time label is split into two lines for the vertical shelf. | |
149 std::unique_ptr<views::Label> vertical_label_hours_; | |
150 std::unique_ptr<views::Label> vertical_label_minutes_; | |
151 | |
152 DISALLOW_COPY_AND_ASSIGN(TimeView); | |
153 }; | |
154 | |
155 } // namespace tray | |
156 } // namespace ash | |
157 | |
158 #endif // ASH_COMMON_SYSTEM_DATE_DATE_VIEW_H_ | |
OLD | NEW |