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/system/date/tray_date.h"
9 #include "ash/system/tray/actionable_view.h"
10 #include "base/i18n/time_formatting.h"
11 #include "base/timer/timer.h"
12 #include "ui/views/view.h"
22 // Abstract base class containing common updating and layout code for the
23 // DateView popup and the TimeView tray icon.
24 class BaseDateTimeView
: public ActionableView
{
26 virtual ~BaseDateTimeView();
28 // Updates the displayed text for the current time and calls SetTimer().
35 // Starts |timer_| to schedule the next update.
36 void SetTimer(const base::Time
& now
);
38 // Updates labels to display the current time.
39 virtual void UpdateTextInternal(const base::Time
& now
) = 0;
41 // Overridden from views::View.
42 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
43 virtual void OnLocaleChanged() OVERRIDE
;
45 // Invokes UpdateText() when the displayed time should change.
46 base::OneShotTimer
<BaseDateTimeView
> timer_
;
48 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView
);
51 // Popup view used to display the date and day of week.
52 class DateView
: public BaseDateTimeView
{
57 // Sets whether the view is actionable. An actionable date view gives visual
58 // feedback on hover, can be focused by keyboard, and clicking/pressing space
59 // or enter on the view shows date-related settings.
60 void SetActionable(bool actionable
);
63 // Overridden from BaseDateTimeView.
64 virtual void UpdateTextInternal(const base::Time
& now
) OVERRIDE
;
66 // Overridden from ActionableView.
67 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
69 // Overridden from views::View.
70 virtual void OnMouseEntered(const ui::MouseEvent
& event
) OVERRIDE
;
71 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
73 views::Label
* date_label_
;
77 DISALLOW_COPY_AND_ASSIGN(DateView
);
80 // Tray view used to display the current time.
81 class TimeView
: public BaseDateTimeView
{
83 TimeView(TrayDate::ClockLayout clock_layout
);
86 views::Label
* label() const { return label_
.get(); }
87 views::Label
* label_hour_left() const { return label_hour_left_
.get(); }
88 views::Label
* label_hour_right() const { return label_hour_right_
.get(); }
89 views::Label
* label_minute_left() const { return label_minute_left_
.get(); }
90 views::Label
* label_minute_right() const { return label_minute_right_
.get(); }
92 // Updates the format of the displayed time.
93 void UpdateTimeFormat();
95 // Updates clock layout.
96 void UpdateClockLayout(TrayDate::ClockLayout clock_layout
);
99 // Overridden from BaseDateTimeView.
100 virtual void UpdateTextInternal(const base::Time
& now
) OVERRIDE
;
102 // Overridden from ActionableView.
103 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
105 // Overridden from views::View.
106 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
;
108 void SetBorder(TrayDate::ClockLayout clock_layout
);
110 void SetupLabel(views::Label
* label
);
112 scoped_ptr
<views::Label
> label_
;
113 scoped_ptr
<views::Label
> label_hour_left_
;
114 scoped_ptr
<views::Label
> label_hour_right_
;
115 scoped_ptr
<views::Label
> label_minute_left_
;
116 scoped_ptr
<views::Label
> label_minute_right_
;
118 base::HourClockType hour_type_
;
120 DISALLOW_COPY_AND_ASSIGN(TimeView
);
124 } // namespace internal
127 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_