Skip to content

Commit

Permalink
Implement the redesigned calendar entry point(vertical)
Browse files Browse the repository at this point in the history
Btw fix, phoneHubTray is not center aligned when the shelf is on the
side. See screenshots:
before: https://screenshot.googleplex.com/AyjLUYS3qSMzqsr
after: https://screenshot.googleplex.com/7WGJaMz7kccdrBC

Screenshot of the date tray:
https://screenshot.googleplex.com/7WGJaMz7kccdrBC

Bug: 1303921, 1312244
Change-Id: I6e8f42e31d91da0db5eae5ea2f7189f185a959c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3561509
Reviewed-by: Alex Newcomer <newcomer@chromium.org>
Commit-Queue: Jiaming Cheng <jiamingc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#988621}
  • Loading branch information
Jiaming Cheng authored and Chromium LUCI CQ committed Apr 4, 2022
1 parent 597b079 commit c8fe22b
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 151 deletions.
2 changes: 2 additions & 0 deletions ash/system/phonehub/phone_hub_tray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ PhoneHubTray::PhoneHubTray(Shelf* shelf)
l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_TRAY_ACCESSIBLE_NAME));
icon->SetImageVerticalAlignment(
views::ImageButton::VerticalAlignment::ALIGN_MIDDLE);
icon->SetImageHorizontalAlignment(
views::ImageButton::HorizontalAlignment::ALIGN_CENTER);
icon_ = tray_container()->AddChildView(std::move(icon));
}

Expand Down
23 changes: 2 additions & 21 deletions ash/system/time/time_tray_item_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,24 @@

#include <memory>

#include "ash/constants/ash_features.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/time/time_view.h"
#include "ash/system/tray/tray_utils.h"
#include "base/memory/scoped_refptr.h"
#include "ui/views/border.h"

namespace ash {

TimeTrayItemView::TimeTrayItemView(Shelf* shelf,
scoped_refptr<UnifiedSystemTrayModel> model,
TimeView::Type type)
: TrayItemView(shelf), model_(model), session_observer_(this) {
system_tray_model_observation_.Observe(model_.get());

TimeTrayItemView::TimeTrayItemView(Shelf* shelf, TimeView::Type type)
: TrayItemView(shelf), session_observer_(this) {
TimeView::ClockLayout clock_layout =
shelf->IsHorizontalAlignment() ? TimeView::ClockLayout::HORIZONTAL_CLOCK
: TimeView::ClockLayout::VERTICAL_CLOCK;
time_view_ = AddChildView(std::make_unique<TimeView>(
clock_layout, Shell::Get()->system_tray_model()->clock(), type));

OnSystemTrayButtonSizeChanged(model_->GetSystemTrayButtonSize());
}

TimeTrayItemView::~TimeTrayItemView() = default;
Expand All @@ -52,17 +44,6 @@ void TimeTrayItemView::OnSessionStateChanged(
time_view_->SetTextColor(TrayIconColor(state));
}

void TimeTrayItemView::OnSystemTrayButtonSizeChanged(
UnifiedSystemTrayModel::SystemTrayButtonSize system_tray_size) {
time_view_->SetShowDate(
features::IsCalendarViewEnabled() &&
system_tray_size == UnifiedSystemTrayModel::SystemTrayButtonSize::kLarge);
}

void TimeTrayItemView::Reset() {
system_tray_model_observation_.Reset();
}

const char* TimeTrayItemView::GetClassName() const {
return "TimeTrayItemView";
}
Expand Down
21 changes: 2 additions & 19 deletions ash/system/time/time_tray_item_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/system/tray/tray_item_view.h"
#include "ash/system/unified/unified_system_tray_model.h"
#include "base/memory/scoped_refptr.h"
#include "base/scoped_observation.h"
#include "time_view.h"

namespace ash {
class Shelf;

class ASH_EXPORT TimeTrayItemView : public TrayItemView,
public SessionObserver,
public UnifiedSystemTrayModel::Observer {
public SessionObserver {
public:
TimeTrayItemView(Shelf* shelf,
scoped_refptr<UnifiedSystemTrayModel> model,
TimeView::Type type);
TimeTrayItemView(Shelf* shelf, TimeView::Type type);

TimeTrayItemView(const TimeTrayItemView&) = delete;
TimeTrayItemView& operator=(const TimeTrayItemView&) = delete;
Expand All @@ -38,26 +32,15 @@ class ASH_EXPORT TimeTrayItemView : public TrayItemView,
// SessionObserver:
void OnSessionStateChanged(session_manager::SessionState state) override;

// UnifiedSystemTrayModel::Observer:
void OnSystemTrayButtonSizeChanged(
UnifiedSystemTrayModel::SystemTrayButtonSize system_tray_size) override;

// Reset the view by removing observer to |model_|.
void Reset();

// views::View:
const char* GetClassName() const override;
void OnThemeChanged() override;

private:
friend class TimeTrayItemViewTest;

scoped_refptr<UnifiedSystemTrayModel> model_;
TimeView* time_view_ = nullptr;
ScopedSessionObserver session_observer_;
base::ScopedObservation<UnifiedSystemTrayModel,
UnifiedSystemTrayModel::Observer>
system_tray_model_observation_{this};
};

} // namespace ash
Expand Down
20 changes: 1 addition & 19 deletions ash/system/time/time_tray_item_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include "ash/constants/ash_features.h"
#include "ash/shelf/shelf.h"
#include "ash/system/time/time_view.h"
#include "ash/system/unified/unified_system_tray_model.h"
#include "ash/test/ash_test_base.h"
#include "base/memory/scoped_refptr.h"
#include "base/test/scoped_feature_list.h"

namespace ash {
Expand All @@ -30,14 +28,12 @@ class TimeTrayItemViewTest : public AshTestBase,
else
scoped_feature_list_.InitWithFeatures({}, features);

model_ = base::MakeRefCounted<UnifiedSystemTrayModel>(GetPrimaryShelf());
time_tray_item_view_ = std::make_unique<TimeTrayItemView>(
GetPrimaryShelf(), model_.get(), TimeView::Type::kTime);
GetPrimaryShelf(), TimeView::Type::kTime);
}

void TearDown() override {
time_tray_item_view_.reset();
model_.reset();
AshTestBase::TearDown();
}

Expand All @@ -51,13 +47,8 @@ class TimeTrayItemViewTest : public AshTestBase,
return !time_tray_item_view_->time_view_->horizontal_view_;
}

bool ShouldShowDateInTimeView() const {
return time_tray_item_view_->time_view_->show_date_;
}

protected:
base::test::ScopedFeatureList scoped_feature_list_;
scoped_refptr<UnifiedSystemTrayModel> model_;
std::unique_ptr<TimeTrayItemView> time_tray_item_view_;
};

Expand Down Expand Up @@ -87,13 +78,4 @@ TEST_P(TimeTrayItemViewTest, ShelfAlignment) {
EXPECT_TRUE(IsTimeViewInHorizontalLayout());
}

TEST_P(TimeTrayItemViewTest, DisplayChanged) {
UpdateDisplay("800x700");
EXPECT_FALSE(ShouldShowDateInTimeView());

// Date should be shown in large screen size (when the feature is enabled).
UpdateDisplay("1680x800");
EXPECT_EQ(IsCalendarViewEnabled(), ShouldShowDateInTimeView());
}

} // namespace ash
89 changes: 49 additions & 40 deletions ash/system/time/time_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const int kVerticalClockLeftPadding = 9;
const int kVerticalDateClockHorizontalPadding = 4;

// Padding on top/bottom of the vertical clock date view.
const int kVerticalDateVerticalPadding = 4;
const int kVerticalDateVerticalPadding = 2;

// How much size smaller the text in the date view compare to the text size of
// the clock view.
Expand Down Expand Up @@ -95,8 +95,6 @@ VerticalDateView::VerticalDateView()
UpdateText();
text_label_->SetBorder(views::CreateEmptyBorder(
gfx::Insets::TLBR(kVerticalDateVerticalPadding, 0, 0, 0)));
SetBorder(views::CreateEmptyBorder(
gfx::Insets::TLBR(0, 0, kVerticalDateVerticalPadding, 0)));
}

VerticalDateView::~VerticalDateView() = default;
Expand Down Expand Up @@ -145,20 +143,40 @@ TimeView::~TimeView() {
}

void TimeView::UpdateClockLayout(ClockLayout clock_layout) {
if (type_ != kTime)
return;

// Do nothing if the layout hasn't changed.
if (clock_layout == ClockLayout::HORIZONTAL_CLOCK ? vertical_view_
: horizontal_view_)
return;

if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) {
vertical_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(horizontal_view_));
} else {
horizontal_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(vertical_view_));
switch (type_) {
case kDate: {
// Do nothing if the layout hasn't changed.
if (clock_layout == ClockLayout::HORIZONTAL_CLOCK
? vertical_date_view_
: horizontal_date_view_) {
return;
}

if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) {
vertical_date_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(horizontal_date_view_));
} else {
horizontal_date_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(vertical_date_view_));
}
break;
}
case kTime: {
// Do nothing if the layout hasn't changed.
if (clock_layout == ClockLayout::HORIZONTAL_CLOCK ? vertical_view_
: horizontal_view_) {
return;
}

if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) {
vertical_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(horizontal_view_));
} else {
horizontal_view_ = RemoveChildViewT(children()[0]);
AddChildView(std::move(vertical_view_));
}
break;
}
}
Layout();
}
Expand Down Expand Up @@ -205,16 +223,6 @@ void TimeView::SetTextShadowValues(const gfx::ShadowValues& shadows) {
}
}

void TimeView::SetShowDate(bool show_date) {
if (show_date_ == show_date)
return;
show_date_ = show_date;
UpdateText();
if (type_ == kTime)
SetupVerticalSubViews();
PreferredSizeChanged();
}

void TimeView::OnDateFormatChanged() {
UpdateTimeFormat();
}
Expand Down Expand Up @@ -306,7 +314,6 @@ void TimeView::UpdateTextInternal(const base::Time& now) {
!base::i18n::IsRTL())
hour = u"0" + hour;

vertical_date_view_->UpdateText();
vertical_label_hours_->SetText(hour);
vertical_label_minutes_->SetText(minute);
vertical_label_hours_->NotifyAccessibilityEvent(
Expand All @@ -328,6 +335,7 @@ void TimeView::UpdateTextInternal(const base::Time& now) {
horizontal_label_date_->SetTooltipText(friendly_format_date);
horizontal_label_date_->NotifyAccessibilityEvent(
ax::mojom::Event::kTextChanged, true);
date_view_->UpdateText();
}
}
}
Expand All @@ -340,17 +348,10 @@ void TimeView::SetupVerticalSubViews() {
vertical_view->SetLayoutManager(std::make_unique<views::GridLayout>());
const int kColumnId = 0;
views::ColumnSet* columns = layout->AddColumnSet(kColumnId);
columns->AddPaddingColumn(0, show_date_ ? kVerticalDateClockHorizontalPadding
: kVerticalClockLeftPadding);
columns->AddPaddingColumn(0, kVerticalClockLeftPadding);
columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0,
views::GridLayout::ColumnSize::kUsePreferred, 0, 0);
if (show_date_) {
layout->StartRow(0, kColumnId);
layout->AddExistingView(vertical_date_view_);
vertical_date_view_->SetVisible(true);
} else {
vertical_date_view_->SetVisible(false);
}

layout->StartRow(0, kColumnId);
layout->AddExistingView(vertical_label_hours_);
layout->StartRow(0, kColumnId);
Expand All @@ -362,14 +363,24 @@ void TimeView::SetupVerticalSubViews() {
void TimeView::SetupDateviews(ClockLayout clock_layout) {
DCHECK_EQ(type_, kDate);
SetLayoutManager(std::make_unique<views::FillLayout>());
horizontal_date_view_ = AddChildView(std::make_unique<View>());
horizontal_date_view_ = std::make_unique<View>();
horizontal_date_view_->SetLayoutManager(
std::make_unique<views::FillLayout>());
horizontal_date_view_->SetBorder(views::CreateEmptyBorder(gfx::Insets::TLBR(
kUnifiedTrayTextTopPadding, kUnifiedTrayTimeLeftPadding, 0, 0)));
horizontal_label_date_ =
horizontal_date_view_->AddChildView(std::make_unique<views::Label>());
SetupLabel(horizontal_label_date_);

vertical_date_view_ = std::make_unique<View>();
vertical_date_view_->SetLayoutManager(std::make_unique<views::FillLayout>());
date_view_ =
vertical_date_view_->AddChildView(std::make_unique<VerticalDateView>());
date_view_->SetBorder(
views::CreateEmptyBorder(gfx::Insets::TLBR(0, 0, 0, 0)));
AddChildView(clock_layout == ClockLayout::HORIZONTAL_CLOCK
? std::move(horizontal_date_view_)
: std::move(vertical_date_view_));
}

void TimeView::SetupSubviews(ClockLayout clock_layout) {
Expand All @@ -384,8 +395,6 @@ void TimeView::SetupSubviews(ClockLayout clock_layout) {

vertical_view_ = std::make_unique<View>();
vertical_view_->SetID(kVerticalViewId);
vertical_date_view_ =
vertical_view_->AddChildView(std::make_unique<VerticalDateView>());
vertical_label_hours_ =
vertical_view_->AddChildView(std::make_unique<views::Label>());
SetupLabel(vertical_label_hours_);
Expand Down
19 changes: 5 additions & 14 deletions ash/system/time/time_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ class ASH_EXPORT TimeView : public ActionableView, public ClockObserver {
// Updates the time text shadow values.
void SetTextShadowValues(const gfx::ShadowValues& shadows);

// Shows the date when `show_date` is true.
void SetShowDate(bool show_date);

// ClockObserver:
void OnDateFormatChanged() override;
void OnSystemClockTimeUpdated() override;
Expand All @@ -94,10 +91,6 @@ class ASH_EXPORT TimeView : public ActionableView, public ClockObserver {

base::HourClockType GetHourTypeForTesting() const;

// If this time view should show date. If in the horizontal view it's today's
// date, and in the vertical view it's a calendar date view.
bool show_date() { return show_date_; }

views::Label* horizontal_label_for_test() { return horizontal_label_; }
views::Label* horizontal_label_date_for_test() {
return horizontal_label_date_;
Expand Down Expand Up @@ -143,18 +136,16 @@ class ASH_EXPORT TimeView : public ActionableView, public ClockObserver {
views::Label* horizontal_label_ = nullptr;
views::Label* horizontal_label_date_ = nullptr;

// The horizontal and vertical date view for the `DateTray`.
std::unique_ptr<views::View> horizontal_date_view_;
std::unique_ptr<views::View> vertical_date_view_;

// The time label is split into two lines for the vertical shelf.
views::Label* vertical_label_hours_ = nullptr;
views::Label* vertical_label_minutes_ = nullptr;

// The vertical date in a calendar icon view for the vertical shelf.
VerticalDateView* vertical_date_view_ = nullptr;

// The horizontal date view for the `DateTray`.
views::View* horizontal_date_view_ = nullptr;

// Indicates if date should be show in horizontal view.
bool show_date_ = false;
VerticalDateView* date_view_ = nullptr;

// Invokes UpdateText() when the displayed time should change.
base::OneShotTimer timer_;
Expand Down

0 comments on commit c8fe22b

Please sign in to comment.