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