#ifndef ASH_SYSTEM_TIME_TIME_VIEW_H_
#define ASH_SYSTEM_TIME_TIME_VIEW_H_
#include "ash/ash_export.h"
#include "ash/system/model/clock_observer.h"
#include "base/i18n/time_formatting.h"
#include "base/memory/raw_ptr.h"
#include "base/timer/timer.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
namespace base {
class Time;
}
namespace views {
class ImageView;
class Label;
}
namespace ash {
class ClockModel;
class VerticalDateView : public views::View {
METADATA_HEADER(VerticalDateView, views::View)
public:
VerticalDateView();
VerticalDateView(const VerticalDateView& other) = delete;
VerticalDateView& operator=(const VerticalDateView& other) = delete;
~VerticalDateView() override;
void UpdateText();
void UpdateIconAndLabelColorId(ui::ColorId color_id);
private:
friend class TimeViewTest;
raw_ptr<views::ImageView> icon_ = nullptr;
raw_ptr<views::Label> text_label_ = nullptr;
};
class ASH_EXPORT TimeView : public views::View, public ClockObserver {
METADATA_HEADER(TimeView, views::View)
public:
enum class ClockLayout {
HORIZONTAL_CLOCK,
VERTICAL_CLOCK,
};
enum Type { kTime, kDate };
TimeView(ClockLayout clock_layout, ClockModel* model, Type type = kTime);
TimeView(const TimeView&) = delete;
TimeView& operator=(const TimeView&) = delete;
~TimeView() override;
void UpdateClockLayout(ClockLayout clock_layout);
void SetTextColorId(ui::ColorId color_id,
bool auto_color_readability_enabled = false);
void SetTextColor(SkColor color, bool auto_color_readability_enabled = false);
void SetTextFont(const gfx::FontList& font_list);
void SetTextShadowValues(const gfx::ShadowValues& shadows);
void SetDateViewColorId(ui::ColorId color_id);
void SetAmPmClockType(base::AmPmClockType am_pm_clock_type);
void OnDateFormatChanged() override;
void OnSystemClockTimeUpdated() override;
void OnSystemClockCanSetTimeChanged(bool can_set_time) override;
void Refresh() override;
base::AmPmClockType GetAmPmClockTypeForTesting() const {
return am_pm_clock_type_;
}
base::HourClockType GetHourTypeForTesting() const;
views::Label* GetHorizontalTimeLabelForTesting() {
return horizontal_time_label_;
}
views::Label* GetHorizontalDateLabelForTesting() {
return horizontal_date_label_;
}
views::Label* GetVerticalMinutesLabelForTesting() {
return vertical_label_minutes_;
}
views::Label* GetVerticalHoursLabelForTesting() {
return vertical_label_hours_;
}
private:
friend class TimeViewTest;
friend class TimeTrayItemViewTest;
friend class DateTrayTest;
friend class UnifiedSystemTrayAccessibilityTest;
void ChildPreferredSizeChanged(views::View* child) override;
bool OnMousePressed(const ui::MouseEvent& event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
void UpdateText();
void UpdateTimeFormat();
void UpdateTextInternal(const base::Time& now);
void SetupDateviews(ClockLayout clock_layout);
void SetupSubviews(ClockLayout clock_layout);
void SetupLabel(views::Label* label);
void SetTimer(const base::Time& now);
base::AmPmClockType am_pm_clock_type_ = base::kDropAmPm;
raw_ptr<views::View> horizontal_time_label_container_ = nullptr;
raw_ptr<views::Label> horizontal_time_label_ = nullptr;
raw_ptr<views::View> vertical_time_label_container_ = nullptr;
raw_ptr<views::Label> vertical_label_hours_ = nullptr;
raw_ptr<views::Label> vertical_label_minutes_ = nullptr;
raw_ptr<views::View> horizontal_date_label_container_ = nullptr;
raw_ptr<views::Label, DanglingUntriaged> horizontal_date_label_ = nullptr;
raw_ptr<views::View> vertical_date_view_container_ = nullptr;
raw_ptr<VerticalDateView> vertical_date_view_ = nullptr;
base::OneShotTimer timer_;
const raw_ptr<ClockModel> model_;
const Type type_;
};
}
#endif