0

Componentize GlanceablesErrorMessageView to ash/style

The error message view is planned to be reused in focus mode.
This cl componentize GlanceablesErrorMessageView to ErrorMessageToast
in ash/style.

Bug: b/361640410
Change-Id: Iae28e9579ca4f6ddf06a42210dde2da13bc49253
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5814368
Reviewed-by: Toni Barzic <tbarzic@google.com>
Reviewed-by: Xiaodan Zhu <zxdan@chromium.org>
Commit-Queue: Wen-Chien Wang <wcwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1347528}
This commit is contained in:
Wen-Chien Wang
2024-08-27 19:09:38 +00:00
committed by Chromium LUCI CQ
parent da081a3dd4
commit ceb083898b
17 changed files with 71 additions and 76 deletions

@ -757,8 +757,6 @@ component("ash") {
"glanceables/classroom/glanceables_classroom_types.h",
"glanceables/common/glanceables_contents_scroll_view.cc",
"glanceables/common/glanceables_contents_scroll_view.h",
"glanceables/common/glanceables_error_message_view.cc",
"glanceables/common/glanceables_error_message_view.h",
"glanceables/common/glanceables_list_footer_view.cc",
"glanceables/common/glanceables_list_footer_view.h",
"glanceables/common/glanceables_progress_bar_view.cc",
@ -1473,6 +1471,8 @@ component("ash") {
"style/dot_indicator.h",
"style/drop_down_checkbox.cc",
"style/drop_down_checkbox.h",
"style/error_message_toast.cc",
"style/error_message_toast.h",
"style/harmonized_colors.cc",
"style/harmonized_colors.h",
"style/icon_button.cc",

@ -7931,12 +7931,6 @@ New install
<message name="IDS_GLANCEABLES_TASKS_EDIT_IN_TASKS_LABEL" desc="A glanceables label button placed under the task title textfield that allows users to edit the task in Google Tasks website.">
Edit in Google Tasks
</message>
<message name="IDS_GLANCEABLES_ERROR_DISMISS" desc="A glanceables bubble (classroom or tasks) displays a notification with an error message when an error occurs during any action within said glanceables bubble. This is the text that is displayed on the button within said notification in order to dismiss it.">
Dismiss
</message>
<message name="IDS_GLANCEABLES_ERROR_RELOAD" desc="A glanceables bubble (classroom or tasks) displays a notification with an error message when an error occurs during any action within said glanceables bubble. This is the text that is displayed on the button within said notification in order to reload the list of tasks to update it.">
Reload
</message>
<message name="IDS_GLANCEABLES_CLASSROOM_SEE_ALL_BUTTON_ACCESSIBLE_NAME" desc="The glanceable displays classroom items fetched from Google Classroom API. Glanceables UI renders only limited number of items, the rest of them can be seen by clicking this button, which will open a corresponding website. This is the text announced by ChromeVox for this button.">
See all classwork on Google Classroom website
</message>
@ -8740,6 +8734,14 @@ To shut down the device, press and hold the power button on the device again.
<message name="IDS_ASH_BIRCH_SEND_FEEDBACK" desc="Context menu item that sends feedback about suggestions in informed restore/overview UI">
Send feedback
</message>
<!-- Ash style -->
<message name="IDS_ASH_ERROR_MESSAGE_TOAST_DISMISS" desc="An error message toast is a notification that shows up when an error occurs. This is the text that is displayed on the button within said notification in order to dismiss it.">
Dismiss
</message>
<message name="IDS_ASH_ERROR_MESSAGE_TOAST_RELOAD" desc="An error message toast is a notification that shows up when an error occurs. This is the text that is displayed on the button within said notification in order to reload the contents.">
Reload
</message>
</messages>
</release>
</grit>

@ -14,7 +14,6 @@
#include "ash/glanceables/classroom/glanceables_classroom_item_view.h"
#include "ash/glanceables/classroom/glanceables_classroom_types.h"
#include "ash/glanceables/common/glanceables_contents_scroll_view.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/glanceables/common/glanceables_list_footer_view.h"
#include "ash/glanceables/common/glanceables_progress_bar_view.h"
#include "ash/glanceables/common/glanceables_view_id.h"
@ -26,6 +25,7 @@
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/combobox.h"
#include "ash/style/error_message_toast.h"
#include "ash/style/typography.h"
#include "base/check.h"
#include "base/functional/bind.h"
@ -424,7 +424,7 @@ void GlanceablesClassroomStudentView::OnGetAssignments(
base::BindRepeating(
&GlanceablesClassroomStudentView::MaybeDismissErrorMessage,
base::Unretained(this)),
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ErrorMessageToast::ButtonActionType::kDismiss);
}
}

@ -176,8 +176,8 @@ class GlanceablesClassroomStudentViewTest : public AshTestBase {
base::to_underlying(GlanceablesViewId::kProgressBar)));
}
const GlanceablesErrorMessageView* GetErrorMessage() const {
return views::AsViewClass<GlanceablesErrorMessageView>(
const ErrorMessageToast* GetErrorMessage() const {
return views::AsViewClass<ErrorMessageToast>(
view_->GetViewByID(base::to_underlying(
GlanceablesViewId::kTimeManagementErrorMessageToast)));
}

@ -458,10 +458,10 @@ void GlanceablesTimeManagementBubbleView::MaybeDismissErrorMessage() {
void GlanceablesTimeManagementBubbleView::ShowErrorMessage(
const std::u16string& error_message,
views::Button::PressedCallback callback,
GlanceablesErrorMessageView::ButtonActionType type) {
ErrorMessageToast::ButtonActionType type) {
MaybeDismissErrorMessage();
error_message_ = AddChildView(std::make_unique<GlanceablesErrorMessageView>(
error_message_ = AddChildView(std::make_unique<ErrorMessageToast>(
std::move(callback), error_message, type));
error_message_->SetID(
base::to_underlying(GlanceablesViewId::kTimeManagementErrorMessageToast));

@ -9,8 +9,8 @@
#include <string>
#include "ash/ash_export.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/style/counter_expand_button.h"
#include "ash/style/error_message_toast.h"
#include "base/functional/callback_forward.h"
#include "ui/base/models/combobox_model.h"
#include "ui/compositor/throughput_tracker.h"
@ -190,7 +190,7 @@ class ASH_EXPORT GlanceablesTimeManagementBubbleView
void MaybeDismissErrorMessage();
void ShowErrorMessage(const std::u16string& error_message,
views::Button::PressedCallback callback,
GlanceablesErrorMessageView::ButtonActionType type);
ErrorMessageToast::ButtonActionType type);
Combobox* combobox_view() { return combobox_view_; }
GlanceablesExpandButton* expand_button() { return expand_button_; }
@ -243,7 +243,7 @@ class ASH_EXPORT GlanceablesTimeManagementBubbleView
base::OnceClosure resize_animation_ended_closure_;
// Owned by views hierarchy.
raw_ptr<GlanceablesErrorMessageView> error_message_ = nullptr;
raw_ptr<ErrorMessageToast> error_message_ = nullptr;
};
} // namespace ash

@ -664,14 +664,14 @@ void GlanceablesTaskView::CheckButtonPressed() {
if (!glanceables_util::IsNetworkConnected()) {
show_error_message_callback_.Run(
GlanceablesTasksErrorType::kCantMarkCompleteNoNetwork,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ErrorMessageToast::ButtonActionType::kDismiss);
return;
}
if (task_id_.empty()) {
show_error_message_callback_.Run(
GlanceablesTasksErrorType::kCantMarkComplete,
GlanceablesErrorMessageView::ButtonActionType::kReload);
ErrorMessageToast::ButtonActionType::kReload);
return;
}
@ -689,7 +689,7 @@ void GlanceablesTaskView::TaskTitleButtonPressed() {
if (!glanceables_util::IsNetworkConnected()) {
show_error_message_callback_.Run(
GlanceablesTasksErrorType::kCantUpdateTitleNoNetwork,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ErrorMessageToast::ButtonActionType::kDismiss);
return;
}
RecordUserModifyingTask();

@ -10,8 +10,8 @@
#include "ash/api/tasks/tasks_client.h"
#include "ash/api/tasks/tasks_types.h"
#include "ash/ash_export.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/glanceables/tasks/glanceables_tasks_error_type.h"
#include "ash/style/error_message_toast.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
@ -58,9 +58,9 @@ class ASH_EXPORT GlanceablesTaskView : public views::FlexLayoutView,
const std::string& task_id,
const std::string& title,
api::TasksClient::OnTaskSavedCallback callback)>;
using ShowErrorMessageCallback = base::RepeatingCallback<void(
GlanceablesTasksErrorType,
GlanceablesErrorMessageView::ButtonActionType)>;
using ShowErrorMessageCallback =
base::RepeatingCallback<void(GlanceablesTasksErrorType,
ErrorMessageToast::ButtonActionType)>;
using StateChangeObserverCallback =
base::RepeatingCallback<void(bool view_expanding)>;
// Modes of `tasks_title_view_` (simple label or text field).

@ -159,7 +159,7 @@ TEST_F(GlanceablesTaskViewTest, UpdatingTaskTriggersErrorMessageIfNoNetwork) {
const auto widget = CreateFramelessTestWidget();
widget->SetFullscreen(true);
base::test::TestFuture<GlanceablesTasksErrorType,
GlanceablesErrorMessageView::ButtonActionType>
ErrorMessageToast::ButtonActionType>
error_future;
const auto* const view =
@ -186,7 +186,7 @@ TEST_F(GlanceablesTaskViewTest, UpdatingTaskTriggersErrorMessageIfNoNetwork) {
EXPECT_EQ(task_error_type,
GlanceablesTasksErrorType::kCantMarkCompleteNoNetwork);
EXPECT_EQ(button_action_type,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ErrorMessageToast::ButtonActionType::kDismiss);
}
// No `STRIKE_THROUGH` style should be applied to the label.
@ -207,7 +207,7 @@ TEST_F(GlanceablesTaskViewTest, UpdatingTaskTriggersErrorMessageIfNoNetwork) {
EXPECT_EQ(task_error_type,
GlanceablesTasksErrorType::kCantUpdateTitleNoNetwork);
EXPECT_EQ(button_action_type,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ErrorMessageToast::ButtonActionType::kDismiss);
}
}

@ -291,9 +291,8 @@ void GlanceablesTasksView::SelectedListChanged() {
if (!glanceables_util::IsNetworkConnected()) {
// If the network is disconnected, cancel the list change and show the error
// message.
ShowErrorMessageWithType(
GlanceablesTasksErrorType::kCantLoadTasksNoNetwork,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ShowErrorMessageWithType(GlanceablesTasksErrorType::kCantLoadTasksNoNetwork,
ErrorMessageToast::ButtonActionType::kDismiss);
combobox_view()->SetSelectedIndex(cached_selected_list_index_);
return;
}
@ -459,20 +458,19 @@ void GlanceablesTasksView::UpdateTasksInTaskList(
// data.
ShowErrorMessageWithType(
GlanceablesTasksErrorType::kCantUpdateTasks,
GlanceablesErrorMessageView::ButtonActionType::kReload);
ErrorMessageToast::ButtonActionType::kReload);
} else {
// Notify users that the target list of tasks wasn't loaded and guide
// them to retry.
ShowErrorMessageWithType(
GlanceablesTasksErrorType::kCantLoadTasks,
GlanceablesErrorMessageView::ButtonActionType::kReload);
ErrorMessageToast::ButtonActionType::kReload);
}
return;
}
case ListShownContext::kUserSelectedList:
ShowErrorMessageWithType(
GlanceablesTasksErrorType::kCantLoadTasks,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ShowErrorMessageWithType(GlanceablesTasksErrorType::kCantLoadTasks,
ErrorMessageToast::ButtonActionType::kDismiss);
combobox_view()->SetSelectedIndex(cached_selected_list_index_);
return;
}
@ -705,9 +703,8 @@ void GlanceablesTasksView::OnTaskSaved(
google_apis::ApiErrorCode http_error,
const api::Task* task) {
if (!task) {
ShowErrorMessageWithType(
GlanceablesTasksErrorType::kCantUpdateTitle,
GlanceablesErrorMessageView::ButtonActionType::kDismiss);
ShowErrorMessageWithType(GlanceablesTasksErrorType::kCantUpdateTitle,
ErrorMessageToast::ButtonActionType::kDismiss);
if (task_id.empty() && view) {
// Empty `task_id` means that the task has not yet been created. Delete
// the corresponding `view` from the scrollable container in case of
@ -732,15 +729,15 @@ const api::TaskList* GlanceablesTasksView::GetActiveTaskList() const {
void GlanceablesTasksView::ShowErrorMessageWithType(
GlanceablesTasksErrorType error_type,
GlanceablesErrorMessageView::ButtonActionType button_type) {
ErrorMessageToast::ButtonActionType button_type) {
views::Button::PressedCallback callback;
switch (button_type) {
case GlanceablesErrorMessageView::ButtonActionType::kDismiss:
case ErrorMessageToast::ButtonActionType::kDismiss:
callback =
base::BindRepeating(&GlanceablesTasksView::MaybeDismissErrorMessage,
base::Unretained(this));
break;
case GlanceablesErrorMessageView::ButtonActionType::kReload:
case ErrorMessageToast::ButtonActionType::kReload:
// This only used to reload the current shown list.
callback = base::BindRepeating(&GlanceablesTasksView::RetryUpdateTasks,
base::Unretained(this),

@ -142,7 +142,7 @@ class ASH_EXPORT GlanceablesTasksView
// `button_action_type`.
void ShowErrorMessageWithType(
GlanceablesTasksErrorType error_type,
GlanceablesErrorMessageView::ButtonActionType button_action_type);
ErrorMessageToast::ButtonActionType button_action_type);
// Returns the string to show on `error_message_` according to the
// `error_type`.

@ -8,7 +8,6 @@
#include "ash/api/tasks/fake_tasks_client.h"
#include "ash/constants/ash_features.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/glanceables/common/glanceables_list_footer_view.h"
#include "ash/glanceables/common/glanceables_util.h"
#include "ash/glanceables/common/glanceables_view_id.h"
@ -158,8 +157,8 @@ class GlanceablesTasksViewTest : public AshTestBase {
base::to_underlying(GlanceablesViewId::kProgressBar)));
}
const GlanceablesErrorMessageView* GetErrorMessage() const {
return views::AsViewClass<GlanceablesErrorMessageView>(
const ErrorMessageToast* GetErrorMessage() const {
return views::AsViewClass<ErrorMessageToast>(
view_->GetViewByID(base::to_underlying(
GlanceablesViewId::kTimeManagementErrorMessageToast)));
}

@ -1,25 +1,22 @@
// Copyright 2023 The Chromium Authors
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/style/error_message_toast.h"
#include <algorithm>
#include <memory>
#include <string>
#include "ash/glanceables/common/glanceables_view_id.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/typography.h"
#include "base/types/cxx23_to_underlying.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/flex_layout_types.h"
@ -41,15 +38,15 @@ class ActionLabelButton : public views::LabelButton {
public:
ActionLabelButton(PressedCallback callback,
GlanceablesErrorMessageView::ButtonActionType type)
ErrorMessageToast::ButtonActionType type)
: views::LabelButton(std::move(callback)) {
int string_id;
switch (type) {
case GlanceablesErrorMessageView::ButtonActionType::kDismiss:
string_id = IDS_GLANCEABLES_ERROR_DISMISS;
case ErrorMessageToast::ButtonActionType::kDismiss:
string_id = IDS_ASH_ERROR_MESSAGE_TOAST_DISMISS;
break;
case GlanceablesErrorMessageView::ButtonActionType::kReload:
string_id = IDS_GLANCEABLES_ERROR_RELOAD;
case ErrorMessageToast::ButtonActionType::kReload:
string_id = IDS_ASH_ERROR_MESSAGE_TOAST_RELOAD;
break;
}
SetText(l10n_util::GetStringUTF16(string_id));
@ -68,7 +65,7 @@ END_METADATA
} // namespace
GlanceablesErrorMessageView::GlanceablesErrorMessageView(
ErrorMessageToast::ErrorMessageToast(
views::Button::PressedCallback callback,
const std::u16string& error_message,
ButtonActionType type) {
@ -100,7 +97,7 @@ GlanceablesErrorMessageView::GlanceablesErrorMessageView(
std::make_unique<ActionLabelButton>(std::move(callback), type));
}
void GlanceablesErrorMessageView::UpdateBoundsToContainer(
void ErrorMessageToast::UpdateBoundsToContainer(
const gfx::Rect& container_bounds) {
gfx::Rect preferred_bounds(container_bounds);
@ -110,11 +107,11 @@ void GlanceablesErrorMessageView::UpdateBoundsToContainer(
SetBoundsRect(preferred_bounds);
}
std::u16string GlanceablesErrorMessageView::GetMessageForTest() const {
std::u16string ErrorMessageToast::GetMessageForTest() const {
return error_message_label_->GetText();
}
BEGIN_METADATA(GlanceablesErrorMessageView)
BEGIN_METADATA(ErrorMessageToast)
END_METADATA
} // namespace ash

@ -1,9 +1,9 @@
// Copyright 2023 The Chromium Authors
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_GLANCEABLES_COMMON_GLANCEABLES_ERROR_MESSAGE_VIEW_H_
#define ASH_GLANCEABLES_COMMON_GLANCEABLES_ERROR_MESSAGE_VIEW_H_
#ifndef ASH_STYLE_ERROR_MESSAGE_TOAST_H_
#define ASH_STYLE_ERROR_MESSAGE_TOAST_H_
#include <string>
@ -20,22 +20,22 @@ class LabelButton;
namespace ash {
// Displays error message at the bottom of the glanceables bubble. Used in
// tasks bubbles.
class ASH_EXPORT GlanceablesErrorMessageView : public views::FlexLayoutView {
METADATA_HEADER(GlanceablesErrorMessageView, views::FlexLayoutView)
// Displays error message in a toast view. This is usually placed at the
// bottom of its parent bubble.
class ASH_EXPORT ErrorMessageToast : public views::FlexLayoutView {
METADATA_HEADER(ErrorMessageToast, views::FlexLayoutView)
public:
// Used for `action_button_` that indicates what to expect on click.
enum class ButtonActionType { kDismiss, kReload };
GlanceablesErrorMessageView(views::Button::PressedCallback callback,
const std::u16string& error_message,
ButtonActionType type);
GlanceablesErrorMessageView(const GlanceablesErrorMessageView&) = delete;
GlanceablesErrorMessageView& operator=(const GlanceablesErrorMessageView&) =
ErrorMessageToast(views::Button::PressedCallback callback,
const std::u16string& error_message,
ButtonActionType type);
ErrorMessageToast(const ErrorMessageToast&) = delete;
ErrorMessageToast& operator=(const ErrorMessageToast&) =
delete;
~GlanceablesErrorMessageView() override = default;
~ErrorMessageToast() override = default;
// Updates the error message view to display proportionally to the given
// `container_bounds`.
@ -51,4 +51,4 @@ class ASH_EXPORT GlanceablesErrorMessageView : public views::FlexLayoutView {
} // namespace ash
#endif // ASH_GLANCEABLES_COMMON_GLANCEABLES_ERROR_MESSAGE_VIEW_H_
#endif // ASH_STYLE_ERROR_MESSAGE_TOAST_H_

@ -11,7 +11,6 @@
#include "ash/glanceables/classroom/fake_glanceables_classroom_client.h"
#include "ash/glanceables/classroom/glanceables_classroom_item_view.h"
#include "ash/glanceables/classroom/glanceables_classroom_student_view.h"
#include "ash/glanceables/common/glanceables_error_message_view.h"
#include "ash/glanceables/common/glanceables_view_id.h"
#include "ash/glanceables/glanceables_controller.h"
#include "ash/glanceables/tasks/glanceables_task_view.h"
@ -21,6 +20,7 @@
#include "ash/shell.h"
#include "ash/style/combobox.h"
#include "ash/style/counter_expand_button.h"
#include "ash/style/error_message_toast.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/unified/date_tray.h"
#include "ash/system/unified/glanceable_tray_bubble.h"
@ -851,7 +851,7 @@ IN_PROC_BROWSER_TEST_F(GlanceablesTasksBrowserTest,
EXPECT_TRUE(GetGlanceableTrayBubble());
EXPECT_TRUE(GetTasksView());
auto* error_view = views::AsViewClass<GlanceablesErrorMessageView>(
auto* error_view = views::AsViewClass<ErrorMessageToast>(
GetTasksView()->GetViewByID(base::to_underlying(
GlanceablesViewId::kTimeManagementErrorMessageToast)));
ASSERT_TRUE(error_view);
@ -909,7 +909,7 @@ IN_PROC_BROWSER_TEST_F(GlanceablesTasksBrowserTest, SwitchTaskListsWithError) {
EXPECT_EQ(combobox->GetTextForRow(combobox->GetSelectedIndex().value()),
u"Task List 1 Title");
auto* error_view = views::AsViewClass<GlanceablesErrorMessageView>(
auto* error_view = views::AsViewClass<ErrorMessageToast>(
GetTasksView()->GetViewByID(base::to_underlying(
GlanceablesViewId::kTimeManagementErrorMessageToast)));
ASSERT_TRUE(error_view);