Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / ash / system / date / date_view.h
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_SYSTEM_DATE_DATE_VIEW_H_
6 #define ASH_SYSTEM_DATE_DATE_VIEW_H_
7
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"
15
16 namespace views {
17 class Label;
18 }
19
20 namespace ash {
21 namespace tray {
22
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;
28
29   // Updates the displayed text for the current time and calls SetTimer().
30   void UpdateText();
31
32  protected:
33   BaseDateTimeView();
34
35  private:
36   // Starts |timer_| to schedule the next update.
37   void SetTimer(const base::Time& now);
38
39   // Updates labels to display the current time.
40   virtual void UpdateTextInternal(const base::Time& now) = 0;
41
42   // Overridden from views::View.
43   void ChildPreferredSizeChanged(views::View* child) override;
44   void OnLocaleChanged() override;
45
46   // Invokes UpdateText() when the displayed time should change.
47   base::OneShotTimer<BaseDateTimeView> timer_;
48
49   DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView);
50 };
51
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;
57
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);
62
63   // Updates the format of the displayed time.
64   void UpdateTimeFormat();
65
66   base::HourClockType GetHourTypeForTesting() const;
67
68  private:
69   // Sets active rendering state and updates the color of |date_label_|.
70   void SetActive(bool active);
71
72   // Overridden from BaseDateTimeView.
73   void UpdateTextInternal(const base::Time& now) override;
74
75   // Overridden from ActionableView.
76   bool PerformAction(const ui::Event& event) override;
77
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;
82
83   views::Label* date_label_;
84
85   // Time format (12/24hr) used for accessibility string.
86   base::HourClockType hour_type_;
87
88   TrayDate::DateAction action_;
89
90   DISALLOW_COPY_AND_ASSIGN(DateView);
91 };
92
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;
99
100   // Updates the format of the displayed time.
101   void UpdateTimeFormat();
102
103   // Updates clock layout.
104   void UpdateClockLayout(TrayDate::ClockLayout clock_layout);
105
106   base::HourClockType GetHourTypeForTesting() const;
107
108  private:
109   friend class TimeViewTest;
110
111   // Overridden from BaseDateTimeView.
112   void UpdateTextInternal(const base::Time& now) override;
113
114   // Overridden from ActionableView.
115   bool PerformAction(const ui::Event& event) override;
116
117   // Overridden from views::View.
118   bool OnMousePressed(const ui::MouseEvent& event) override;
119
120   void SetBorderFromLayout(TrayDate::ClockLayout clock_layout);
121   void SetupLabels();
122   void SetupLabel(views::Label* label);
123
124   // Label text used for the normal horizontal shelf.
125   scoped_ptr<views::Label> horizontal_label_;
126
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_;
130
131   base::HourClockType hour_type_;
132
133   DISALLOW_COPY_AND_ASSIGN(TimeView);
134 };
135
136 }  // namespace tray
137 }  // namespace ash
138
139 #endif  // ASH_SYSTEM_DATE_DATE_VIEW_H_