0

[gtm] Expand button refactor

Currently we have a similar expand button classes in Tasks and
Classroom. Move the class to parent GlanceableTimeManagementBubbleView
class.

Bug: b/333770880
Change-Id: I519f313d65fc79be4283a8584b909f2ac9a65891
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5634906
Reviewed-by: Xiaodan Zhu <zxdan@chromium.org>
Reviewed-by: Artsiom Mitrokhin <amitrokhin@chromium.org>
Reviewed-by: Andre Le <leandre@chromium.org>
Commit-Queue: Wen-Chien Wang <wcwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1316780}
This commit is contained in:
Wen-Chien Wang
2024-06-19 00:13:31 +00:00
committed by Chromium LUCI CQ
parent 2431c6e259
commit bb696138dd
9 changed files with 81 additions and 61 deletions

@ -120,31 +120,6 @@ std::u16string GetAssignmentListName(size_t index) {
return l10n_util::GetStringUTF16(iter->second);
}
class ClassroomExpandButton : public CounterExpandButton {
METADATA_HEADER(ClassroomExpandButton, CounterExpandButton)
public:
ClassroomExpandButton() = default;
ClassroomExpandButton(const ClassroomExpandButton&) = delete;
ClassroomExpandButton& operator=(const ClassroomExpandButton&) = delete;
~ClassroomExpandButton() override = default;
std::u16string GetExpandedStateTooltipText() override {
// The tooltip tells users that clicking on the button will collapse the
// Classroom view.
return l10n_util::GetStringUTF16(
IDS_GLANCEABLES_CLASSROOM_EXPAND_BUTTON_COLLAPSE_TOOLTIP);
}
std::u16string GetCollapsedStateTooltipText() override {
// The tooltip tells users that clicking on the button will expand the
// Classroom view.
return l10n_util::GetStringUTF16(
IDS_GLANCEABLES_CLASSROOM_EXPAND_BUTTON_EXPAND_TOOLTIP);
}
};
BEGIN_METADATA(ClassroomExpandButton)
END_METADATA
class ClassroomStudentComboboxModel : public ui::ComboboxModel {
public:
ClassroomStudentComboboxModel() = default;
@ -241,7 +216,9 @@ GlanceablesClassroomStudentView::GlanceablesClassroomStudentView()
combobox_replacement_label_->SetVisible(false);
expand_button_ =
header_container->AddChildView(std::make_unique<ClassroomExpandButton>());
header_container->AddChildView(std::make_unique<GlanceablesExpandButton>(
IDS_GLANCEABLES_CLASSROOM_EXPAND_BUTTON_EXPAND_TOOLTIP,
IDS_GLANCEABLES_CLASSROOM_EXPAND_BUTTON_COLLAPSE_TOOLTIP));
expand_button_->SetID(
base::to_underlying(GlanceablesViewId::kClassroomBubbleExpandButton));
// This is only set visible when both Tasks and Classroom exist, where the

@ -7,6 +7,7 @@
#include "ash/public/cpp/metrics_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/time/time.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
@ -30,6 +31,36 @@ constexpr gfx::Tween::Type kExpandStateChangeAnimationTweenType =
} // namespace
GlanceablesTimeManagementBubbleView::GlanceablesExpandButton::
GlanceablesExpandButton(int expand_tooltip_string_id,
int collapse_tooltip_string_id)
: expand_tooltip_string_id_(expand_tooltip_string_id),
collapse_tooltip_string_id_(collapse_tooltip_string_id) {
// Base class ctor doesn't have the tooltip string information yet. Explicitly
// call `UpdateTooltip` to set it.
UpdateTooltip();
}
GlanceablesTimeManagementBubbleView::GlanceablesExpandButton::
~GlanceablesExpandButton() = default;
std::u16string GlanceablesTimeManagementBubbleView::GlanceablesExpandButton::
GetExpandedStateTooltipText() const {
// The tooltip tells users that clicking on the button will collapse the
// glanceables bubble.
return l10n_util::GetStringUTF16(collapse_tooltip_string_id_);
}
std::u16string GlanceablesTimeManagementBubbleView::GlanceablesExpandButton::
GetCollapsedStateTooltipText() const {
// The tooltip tells users that clicking on the button will expand the
// glanceables bubble.
return l10n_util::GetStringUTF16(expand_tooltip_string_id_);
}
BEGIN_METADATA(GlanceablesTimeManagementBubbleView, GlanceablesExpandButton)
END_METADATA
GlanceablesTimeManagementBubbleView::ResizeAnimation::ResizeAnimation(
int start_height,
int end_height,

@ -7,6 +7,7 @@
#include "ash/ash_export.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/style/counter_expand_button.h"
#include "base/functional/callback_forward.h"
#include "ui/compositor/throughput_tracker.h"
#include "ui/views/controls/button/button.h"
@ -69,6 +70,23 @@ class ASH_EXPORT GlanceablesTimeManagementBubbleView
void SetAnimationEndedClosureForTest(base::OnceClosure closure);
protected:
class GlanceablesExpandButton : public CounterExpandButton {
METADATA_HEADER(GlanceablesExpandButton, CounterExpandButton)
public:
GlanceablesExpandButton(int expand_tooltip_string_id,
int collapse_tooltip_string_id);
~GlanceablesExpandButton() override;
std::u16string GetExpandedStateTooltipText() const override;
std::u16string GetCollapsedStateTooltipText() const override;
private:
// The tooltip string that tells that the button can expand the bubble.
const int expand_tooltip_string_id_;
// The tooltip string that tells that the button can collapse the bubble.
const int collapse_tooltip_string_id_;
};
// Linear animation to track time management bubble resize animation - as the
// animation progresses, the bubble view preferred size will change causing
// bubble bounds updates. `ResizeAnimation` will provide the expected

@ -307,24 +307,39 @@ TEST_F(GlanceablesTasksAndClassroomTest, TimeManagementExpandStates) {
ASSERT_TRUE(classroom_expand_button);
EXPECT_TRUE(tasks_expand_button->expanded());
EXPECT_FALSE(classroom_expand_button->expanded());
EXPECT_EQ(tasks_expand_button->GetTooltipText(), u"Collapse Google Tasks");
EXPECT_EQ(classroom_expand_button->GetTooltipText(),
u"Expand Google Classroom");
// Expanding/Collapsing `tasks_view` will collapse/expand `classroom_view`.
LeftClickOn(tasks_expand_button);
EXPECT_FALSE(tasks_view->IsExpanded());
EXPECT_TRUE(classroom_view->IsExpanded());
EXPECT_EQ(tasks_expand_button->GetTooltipText(), u"Expand Google Tasks");
EXPECT_EQ(classroom_expand_button->GetTooltipText(),
u"Collapse Google Classroom");
LeftClickOn(tasks_expand_button);
EXPECT_TRUE(tasks_view->IsExpanded());
EXPECT_FALSE(classroom_view->IsExpanded());
EXPECT_EQ(tasks_expand_button->GetTooltipText(), u"Collapse Google Tasks");
EXPECT_EQ(classroom_expand_button->GetTooltipText(),
u"Expand Google Classroom");
// Same for `classroom_view`.
LeftClickOn(classroom_expand_button);
EXPECT_FALSE(tasks_view->IsExpanded());
EXPECT_TRUE(classroom_view->IsExpanded());
EXPECT_EQ(tasks_expand_button->GetTooltipText(), u"Expand Google Tasks");
EXPECT_EQ(classroom_expand_button->GetTooltipText(),
u"Collapse Google Classroom");
LeftClickOn(classroom_expand_button);
EXPECT_TRUE(tasks_view->IsExpanded());
EXPECT_FALSE(classroom_view->IsExpanded());
EXPECT_EQ(tasks_expand_button->GetTooltipText(), u"Collapse Google Tasks");
EXPECT_EQ(classroom_expand_button->GetTooltipText(),
u"Expand Google Classroom");
}
TEST_F(GlanceablesTasksAndClassroomTest,

@ -122,31 +122,6 @@ std::u16string GetLastUpdateTimeMessage(base::Time time) {
}
}
class TasksExpandButton : public CounterExpandButton {
METADATA_HEADER(TasksExpandButton, CounterExpandButton)
public:
TasksExpandButton() = default;
TasksExpandButton(const TasksExpandButton&) = delete;
TasksExpandButton& operator=(const TasksExpandButton&) = delete;
~TasksExpandButton() override = default;
std::u16string GetExpandedStateTooltipText() override {
// The tooltip tells users that clicking on the button will collapse the
// Tasks view.
return l10n_util::GetStringUTF16(
IDS_GLANCEABLES_TASKS_EXPAND_BUTTON_COLLAPSE_TOOLTIP);
}
std::u16string GetCollapsedStateTooltipText() override {
// The tooltip tells users that clicking on the button will expand the
// Tasks view.
return l10n_util::GetStringUTF16(
IDS_GLANCEABLES_TASKS_EXPAND_BUTTON_EXPAND_TOOLTIP);
}
};
BEGIN_METADATA(TasksExpandButton)
END_METADATA
class AddNewTaskButton : public views::LabelButton {
METADATA_HEADER(AddNewTaskButton, views::LabelButton)
public:
@ -211,7 +186,9 @@ GlanceablesTasksView::GlanceablesTasksView(
.WithWeight(1));
expand_button_ = tasks_header_container->AddChildView(
std::make_unique<TasksExpandButton>());
std::make_unique<GlanceablesExpandButton>(
IDS_GLANCEABLES_TASKS_EXPAND_BUTTON_EXPAND_TOOLTIP,
IDS_GLANCEABLES_TASKS_EXPAND_BUTTON_COLLAPSE_TOOLTIP));
expand_button_->SetID(
base::to_underlying(GlanceablesViewId::kTasksBubbleExpandButton));
// This is only set visible when both Tasks and Classroom exist, where the

@ -130,7 +130,7 @@ void CounterExpandButton::UpdateIcons() {
void CounterExpandButton::UpdateTooltip() {
std::u16string tooltip_text = expanded_ ? GetExpandedStateTooltipText()
: GetCollapsedStateTooltipText();
image_->SetTooltipText(tooltip_text);
SetTooltipText(tooltip_text);
GetViewAccessibility().SetName(
tooltip_text, tooltip_text.empty()
? ax::mojom::NameFrom::kAttributeExplicitlyEmpty
@ -262,11 +262,11 @@ void CounterExpandButton::AnimateBoundsChange(
.SetBounds(image_, image_target_bounds, tween_type);
}
std::u16string CounterExpandButton::GetExpandedStateTooltipText() {
std::u16string CounterExpandButton::GetExpandedStateTooltipText() const {
return u"";
}
std::u16string CounterExpandButton::GetCollapsedStateTooltipText() {
std::u16string CounterExpandButton::GetCollapsedStateTooltipText() const {
return u"";
}

@ -98,8 +98,8 @@ class ASH_EXPORT CounterExpandButton : public views::Button {
void UpdateTooltip();
// Returns the tooltip text on the button in expanded/collapsed state.
virtual std::u16string GetExpandedStateTooltipText();
virtual std::u16string GetCollapsedStateTooltipText();
virtual std::u16string GetExpandedStateTooltipText() const;
virtual std::u16string GetCollapsedStateTooltipText() const;
private:
void UpdateBackgroundColor();

@ -65,14 +65,16 @@ const std::string AshNotificationExpandButton::GetAnimationHistogramName(
}
}
std::u16string AshNotificationExpandButton::GetExpandedStateTooltipText() {
std::u16string AshNotificationExpandButton::GetExpandedStateTooltipText()
const {
// The tooltip tells users that clicking on the button will collapse the
// notification group.
return l10n_util::GetStringFUTF16(IDS_ASH_NOTIFICATION_COLLAPSE_TOOLTIP,
notification_title_);
}
std::u16string AshNotificationExpandButton::GetCollapsedStateTooltipText() {
std::u16string AshNotificationExpandButton::GetCollapsedStateTooltipText()
const {
// The tooltip tells users that clicking on the button will expand the
// notification group.
return l10n_util::GetStringFUTF16(IDS_ASH_NOTIFICATION_EXPAND_TOOLTIP,

@ -35,8 +35,8 @@ class AshNotificationExpandButton : public CounterExpandButton {
private:
// CounterExpandButton:
std::u16string GetExpandedStateTooltipText() override;
std::u16string GetCollapsedStateTooltipText() override;
std::u16string GetExpandedStateTooltipText() const override;
std::u16string GetCollapsedStateTooltipText() const override;
// Cache of the notification title. Used this to display in the button
// tooltip.