| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_SYSTEM_DATE_DATE_VIEW_H_ | 5 #ifndef ASH_SYSTEM_DATE_DATE_VIEW_H_ |
| 6 #define ASH_SYSTEM_DATE_DATE_VIEW_H_ | 6 #define ASH_SYSTEM_DATE_DATE_VIEW_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/system/date/tray_date.h" | 9 #include "ash/system/date/tray_date.h" |
| 10 #include "ash/system/tray/actionable_view.h" | 10 #include "ash/system/tray/actionable_view.h" |
| 11 #include "base/i18n/time_formatting.h" | 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
| 14 #include "ui/views/view.h" | 14 #include "ui/views/view.h" |
| 15 | 15 |
| 16 namespace views { | 16 namespace views { |
| 17 class Label; | 17 class Label; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace tray { | 21 namespace tray { |
| 22 | 22 |
| 23 // Abstract base class containing common updating and layout code for the | 23 // Abstract base class containing common updating and layout code for the |
| 24 // DateView popup and the TimeView tray icon. Exported for tests. | 24 // DateView popup and the TimeView tray icon. Exported for tests. |
| 25 class ASH_EXPORT BaseDateTimeView : public ActionableView { | 25 class ASH_EXPORT BaseDateTimeView : public ActionableView { |
| 26 public: | 26 public: |
| 27 virtual ~BaseDateTimeView(); | 27 ~BaseDateTimeView() override; |
| 28 | 28 |
| 29 // Updates the displayed text for the current time and calls SetTimer(). | 29 // Updates the displayed text for the current time and calls SetTimer(). |
| 30 void UpdateText(); | 30 void UpdateText(); |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 BaseDateTimeView(); | 33 BaseDateTimeView(); |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // Starts |timer_| to schedule the next update. | 36 // Starts |timer_| to schedule the next update. |
| 37 void SetTimer(const base::Time& now); | 37 void SetTimer(const base::Time& now); |
| 38 | 38 |
| 39 // Updates labels to display the current time. | 39 // Updates labels to display the current time. |
| 40 virtual void UpdateTextInternal(const base::Time& now) = 0; | 40 virtual void UpdateTextInternal(const base::Time& now) = 0; |
| 41 | 41 |
| 42 // Overridden from views::View. | 42 // Overridden from views::View. |
| 43 virtual void ChildPreferredSizeChanged(views::View* child) override; | 43 void ChildPreferredSizeChanged(views::View* child) override; |
| 44 virtual void OnLocaleChanged() override; | 44 void OnLocaleChanged() override; |
| 45 | 45 |
| 46 // Invokes UpdateText() when the displayed time should change. | 46 // Invokes UpdateText() when the displayed time should change. |
| 47 base::OneShotTimer<BaseDateTimeView> timer_; | 47 base::OneShotTimer<BaseDateTimeView> timer_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView); | 49 DISALLOW_COPY_AND_ASSIGN(BaseDateTimeView); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // Popup view used to display the date and day of week. | 52 // Popup view used to display the date and day of week. |
| 53 class ASH_EXPORT DateView : public BaseDateTimeView { | 53 class ASH_EXPORT DateView : public BaseDateTimeView { |
| 54 public: | 54 public: |
| 55 DateView(); | 55 DateView(); |
| 56 virtual ~DateView(); | 56 ~DateView() override; |
| 57 | 57 |
| 58 // Sets the action the view should take. An actionable date view gives visual | 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 | 59 // feedback on hover, can be focused by keyboard, and clicking/pressing space |
| 60 // or enter on the view executes the action. | 60 // or enter on the view executes the action. |
| 61 void SetAction(TrayDate::DateAction action); | 61 void SetAction(TrayDate::DateAction action); |
| 62 | 62 |
| 63 // Updates the format of the displayed time. | 63 // Updates the format of the displayed time. |
| 64 void UpdateTimeFormat(); | 64 void UpdateTimeFormat(); |
| 65 | 65 |
| 66 base::HourClockType GetHourTypeForTesting() const; | 66 base::HourClockType GetHourTypeForTesting() const; |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 // Sets active rendering state and updates the color of |date_label_|. | 69 // Sets active rendering state and updates the color of |date_label_|. |
| 70 void SetActive(bool active); | 70 void SetActive(bool active); |
| 71 | 71 |
| 72 // Overridden from BaseDateTimeView. | 72 // Overridden from BaseDateTimeView. |
| 73 virtual void UpdateTextInternal(const base::Time& now) override; | 73 void UpdateTextInternal(const base::Time& now) override; |
| 74 | 74 |
| 75 // Overridden from ActionableView. | 75 // Overridden from ActionableView. |
| 76 virtual bool PerformAction(const ui::Event& event) override; | 76 bool PerformAction(const ui::Event& event) override; |
| 77 | 77 |
| 78 // Overridden from views::View. | 78 // Overridden from views::View. |
| 79 virtual void OnMouseEntered(const ui::MouseEvent& event) override; | 79 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 80 virtual void OnMouseExited(const ui::MouseEvent& event) override; | 80 void OnMouseExited(const ui::MouseEvent& event) override; |
| 81 virtual void OnGestureEvent(ui::GestureEvent* event) override; | 81 void OnGestureEvent(ui::GestureEvent* event) override; |
| 82 | 82 |
| 83 views::Label* date_label_; | 83 views::Label* date_label_; |
| 84 | 84 |
| 85 // Time format (12/24hr) used for accessibility string. | 85 // Time format (12/24hr) used for accessibility string. |
| 86 base::HourClockType hour_type_; | 86 base::HourClockType hour_type_; |
| 87 | 87 |
| 88 TrayDate::DateAction action_; | 88 TrayDate::DateAction action_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(DateView); | 90 DISALLOW_COPY_AND_ASSIGN(DateView); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // Tray view used to display the current time. | 93 // Tray view used to display the current time. |
| 94 // Exported for tests. | 94 // Exported for tests. |
| 95 class ASH_EXPORT TimeView : public BaseDateTimeView { | 95 class ASH_EXPORT TimeView : public BaseDateTimeView { |
| 96 public: | 96 public: |
| 97 explicit TimeView(TrayDate::ClockLayout clock_layout); | 97 explicit TimeView(TrayDate::ClockLayout clock_layout); |
| 98 virtual ~TimeView(); | 98 ~TimeView() override; |
| 99 | 99 |
| 100 // Updates the format of the displayed time. | 100 // Updates the format of the displayed time. |
| 101 void UpdateTimeFormat(); | 101 void UpdateTimeFormat(); |
| 102 | 102 |
| 103 // Updates clock layout. | 103 // Updates clock layout. |
| 104 void UpdateClockLayout(TrayDate::ClockLayout clock_layout); | 104 void UpdateClockLayout(TrayDate::ClockLayout clock_layout); |
| 105 | 105 |
| 106 base::HourClockType GetHourTypeForTesting() const; | 106 base::HourClockType GetHourTypeForTesting() const; |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 friend class TimeViewTest; | 109 friend class TimeViewTest; |
| 110 | 110 |
| 111 // Overridden from BaseDateTimeView. | 111 // Overridden from BaseDateTimeView. |
| 112 virtual void UpdateTextInternal(const base::Time& now) override; | 112 void UpdateTextInternal(const base::Time& now) override; |
| 113 | 113 |
| 114 // Overridden from ActionableView. | 114 // Overridden from ActionableView. |
| 115 virtual bool PerformAction(const ui::Event& event) override; | 115 bool PerformAction(const ui::Event& event) override; |
| 116 | 116 |
| 117 // Overridden from views::View. | 117 // Overridden from views::View. |
| 118 virtual bool OnMousePressed(const ui::MouseEvent& event) override; | 118 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 119 | 119 |
| 120 void SetBorderFromLayout(TrayDate::ClockLayout clock_layout); | 120 void SetBorderFromLayout(TrayDate::ClockLayout clock_layout); |
| 121 void SetupLabels(); | 121 void SetupLabels(); |
| 122 void SetupLabel(views::Label* label); | 122 void SetupLabel(views::Label* label); |
| 123 | 123 |
| 124 // Label text used for the normal horizontal shelf. | 124 // Label text used for the normal horizontal shelf. |
| 125 scoped_ptr<views::Label> horizontal_label_; | 125 scoped_ptr<views::Label> horizontal_label_; |
| 126 | 126 |
| 127 // The time label is split into two lines for the vertical shelf. | 127 // The time label is split into two lines for the vertical shelf. |
| 128 scoped_ptr<views::Label> vertical_label_hours_; | 128 scoped_ptr<views::Label> vertical_label_hours_; |
| 129 scoped_ptr<views::Label> vertical_label_minutes_; | 129 scoped_ptr<views::Label> vertical_label_minutes_; |
| 130 | 130 |
| 131 base::HourClockType hour_type_; | 131 base::HourClockType hour_type_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(TimeView); | 133 DISALLOW_COPY_AND_ASSIGN(TimeView); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 } // namespace tray | 136 } // namespace tray |
| 137 } // namespace ash | 137 } // namespace ash |
| 138 | 138 |
| 139 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_ | 139 #endif // ASH_SYSTEM_DATE_DATE_VIEW_H_ |
| OLD | NEW |