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"
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
{
27 virtual ~BaseDateTimeView();
29 // Updates the displayed text for the current time and calls SetTimer().
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 virtual void ChildPreferredSizeChanged(views::View
* child
) OVERRIDE
;
44 virtual 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
{
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;
69 // Overridden from BaseDateTimeView.
70 virtual void UpdateTextInternal(const base::Time
& now
) OVERRIDE
;
72 // Overridden from ActionableView.
73 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
75 // Overridden from views::View.
76 virtual void OnMouseEntered(const ui::MouseEvent
& event
) OVERRIDE
;
77 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
79 views::Label
* date_label_
;
81 // Time format (12/24hr) used for accessibility string.
82 base::HourClockType hour_type_
;
84 TrayDate::DateAction action_
;
86 DISALLOW_COPY_AND_ASSIGN(DateView
);
89 // Tray view used to display the current time.
90 // Exported for tests.
91 class ASH_EXPORT TimeView
: public BaseDateTimeView
{
93 explicit TimeView(TrayDate::ClockLayout clock_layout
);
96 // Updates the format of the displayed time.
97 void UpdateTimeFormat();
99 // Updates clock layout.
100 void UpdateClockLayout(TrayDate::ClockLayout clock_layout
);
102 base::HourClockType
GetHourTypeForTesting() const;
105 friend class TimeViewTest
;
107 // Overridden from BaseDateTimeView.
108 virtual void UpdateTextInternal(const base::Time
& now
) OVERRIDE
;
110 // Overridden from ActionableView.
111 virtual bool PerformAction(const ui::Event
& event
) OVERRIDE
;
113 // Overridden from views::View.
114 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
;
116 void SetBorderFromLayout(TrayDate::ClockLayout clock_layout
);
118 void SetupLabel(views::Label
* label
);
120 // Label text used for the normal horizontal shelf.
121 scoped_ptr
<views::Label
> horizontal_label_
;
123 // The time label is split into two lines for the vertical shelf.
124 scoped_ptr
<views::Label
> vertical_label_hours_
;
125 scoped_ptr
<views::Label
> vertical_label_minutes_
;
127 base::HourClockType hour_type_
;
129 DISALLOW_COPY_AND_ASSIGN(TimeView
);
135 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_