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 internal { 22 namespace tray { 23 24 // Abstract base class containing common updating and layout code for the 25 // DateView popup and the TimeView tray icon. Exported for tests. 26 class ASH_EXPORT BaseDateTimeView : public ActionableView { 27 public: 28 virtual ~BaseDateTimeView(); 29 30 // Updates the displayed text for the current time and calls SetTimer(). 31 void UpdateText(); 32 33 protected: 34 BaseDateTimeView(); 35 36 private: 37 // Starts |timer_| to schedule the next update. 38 void SetTimer(const base::Time& now); 39 40 // Updates labels to display the current time. 41 virtual void UpdateTextInternal(const base::Time& now) = 0; 42 43 // Overridden from views::View. 44 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 45 virtual void OnLocaleChanged() OVERRIDE; 46 47 // Invokes UpdateText() when the displayed time should change. 48 base::OneShotTimer<BaseDateTimeView> timer_; 49 50 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView); 51 }; 52 53 // Popup view used to display the date and day of week. 54 class DateView : public BaseDateTimeView { 55 public: 56 DateView(); 57 virtual ~DateView(); 58 59 // Sets whether the view is actionable. An actionable date view gives visual 60 // feedback on hover, can be focused by keyboard, and clicking/pressing space 61 // or enter on the view shows date-related settings. 62 void SetActionable(bool actionable); 63 64 // Updates the format of the displayed time. 65 void UpdateTimeFormat(); 66 67 private: 68 // Overridden from BaseDateTimeView. 69 virtual void UpdateTextInternal(const base::Time& now) OVERRIDE; 70 71 // Overridden from ActionableView. 72 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 73 74 // Overridden from views::View. 75 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 76 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 77 78 views::Label* date_label_; 79 80 // Time format (12/24hr) used for accessibility string. 81 base::HourClockType hour_type_; 82 83 bool actionable_; 84 85 DISALLOW_COPY_AND_ASSIGN(DateView); 86 }; 87 88 // Tray view used to display the current time. 89 // Exported for tests. 90 class ASH_EXPORT TimeView : public BaseDateTimeView { 91 public: 92 explicit TimeView(TrayDate::ClockLayout clock_layout); 93 virtual ~TimeView(); 94 95 // Updates the format of the displayed time. 96 void UpdateTimeFormat(); 97 98 // Updates clock layout. 99 void UpdateClockLayout(TrayDate::ClockLayout clock_layout); 100 101 private: 102 friend class TimeViewTest; 103 104 // Overridden from BaseDateTimeView. 105 virtual void UpdateTextInternal(const base::Time& now) OVERRIDE; 106 107 // Overridden from ActionableView. 108 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 109 110 // Overridden from views::View. 111 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 112 113 void SetBorder(TrayDate::ClockLayout clock_layout); 114 void SetupLabels(); 115 void SetupLabel(views::Label* label); 116 117 // Label text used for the normal horizontal shelf. 118 scoped_ptr<views::Label> horizontal_label_; 119 120 // The time label is split into two lines for the vertical shelf. 121 scoped_ptr<views::Label> vertical_label_hours_; 122 scoped_ptr<views::Label> vertical_label_minutes_; 123 124 base::HourClockType hour_type_; 125 126 DISALLOW_COPY_AND_ASSIGN(TimeView); 127 }; 128 129 } // namespace tray 130 } // namespace internal 131 } // namespace ash 132 133 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_ 134