blob: 43f3baa18526fc1e548b520141ba35b295659f92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_DATE_DATE_VIEW_H_
#define ASH_SYSTEM_DATE_DATE_VIEW_H_
#include "ash/system/date/tray_date.h"
#include "ash/system/tray/tray_views.h"
#include "base/i18n/time_formatting.h"
#include "base/timer.h"
#include "ui/views/view.h"
namespace views {
class Label;
}
namespace ash {
namespace internal {
namespace tray {
// Abstract base class containing common updating and layout code for the
// DateView popup and the TimeView tray icon.
class BaseDateTimeView : public ActionableView {
public:
virtual ~BaseDateTimeView();
// Updates the displayed text for the current time and calls SetTimer().
void UpdateText();
protected:
BaseDateTimeView();
private:
// Starts |timer_| to schedule the next update.
void SetTimer(const base::Time& now);
// Updates labels to display the current time.
virtual void UpdateTextInternal(const base::Time& now) = 0;
// Overridden from views::View.
virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
virtual void OnLocaleChanged() OVERRIDE;
// Invokes UpdateText() when the displayed time should change.
base::OneShotTimer<BaseDateTimeView> timer_;
DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView);
};
// Popup view used to display the date and day of week.
class DateView : public BaseDateTimeView {
public:
DateView();
virtual ~DateView();
// Sets whether the view is actionable. An actionable date view gives visual
// feedback on hover, can be focused by keyboard, and clicking/pressing space
// or enter on the view shows date-related settings.
void SetActionable(bool actionable);
private:
// Overridden from BaseDateTimeView.
virtual void UpdateTextInternal(const base::Time& now) OVERRIDE;
// Overridden from ActionableView.
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
// Overridden from views::View.
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
views::Label* date_label_;
bool actionable_;
DISALLOW_COPY_AND_ASSIGN(DateView);
};
// Tray view used to display the current time.
class TimeView : public BaseDateTimeView {
public:
TimeView(TrayDate::ClockLayout clock_layout);
virtual ~TimeView();
views::Label* label() const { return label_.get(); }
views::Label* label_hour_left() const { return label_hour_left_.get(); }
views::Label* label_hour_right() const { return label_hour_right_.get(); }
views::Label* label_minute_left() const { return label_minute_left_.get(); }
views::Label* label_minute_right() const { return label_minute_right_.get(); }
// Updates the format of the displayed time.
void UpdateTimeFormat();
// Updates clock layout.
void UpdateClockLayout(TrayDate::ClockLayout clock_layout);
private:
// Overridden from BaseDateTimeView.
virtual void UpdateTextInternal(const base::Time& now) OVERRIDE;
// Overridden from ActionableView.
virtual bool PerformAction(const ui::Event& event) OVERRIDE;
// Overridden from views::View.
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
void SetBorder(TrayDate::ClockLayout clock_layout);
void SetupLabels();
void SetupLabel(views::Label* label);
scoped_ptr<views::Label> label_;
scoped_ptr<views::Label> label_hour_left_;
scoped_ptr<views::Label> label_hour_right_;
scoped_ptr<views::Label> label_minute_left_;
scoped_ptr<views::Label> label_minute_right_;
base::HourClockType hour_type_;
DISALLOW_COPY_AND_ASSIGN(TimeView);
};
} // namespace tray
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_DATE_DATE_VIEW_H_
|