Refactor SystemNudge and add Adaptive charging nudge
1. Refactor SystemNudge so that subclasses can customize icon size There is no visual change. 2. Add an educational nudge for adaptive charging Context: go/cros-charge-educational-nudge TEST: tested with clipboard nudge on eve. BUG=b:216035485 Change-Id: Ib8b593d3a9b9f42f5fb1cfa8adca3d2544502fe1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3528338 Reviewed-by: Alex Newcomer <newcomer@chromium.org> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org> Commit-Queue: Thanh Nguyen <thanhdng@chromium.org> Cr-Commit-Position: refs/heads/main@{#986858}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
fef6bd2981
commit
a997d8299b
ash
@ -1410,6 +1410,10 @@ component("ash") {
|
||||
"system/phonehub/ui_constants.h",
|
||||
"system/power/adaptive_charging_controller.cc",
|
||||
"system/power/adaptive_charging_controller.h",
|
||||
"system/power/adaptive_charging_nudge.cc",
|
||||
"system/power/adaptive_charging_nudge.h",
|
||||
"system/power/adaptive_charging_nudge_controller.cc",
|
||||
"system/power/adaptive_charging_nudge_controller.h",
|
||||
"system/power/backlights_forced_off_setter.cc",
|
||||
"system/power/backlights_forced_off_setter.h",
|
||||
"system/power/battery_image_source.cc",
|
||||
@ -2682,6 +2686,7 @@ test("ash_unittests") {
|
||||
"system/phonehub/quick_actions_view_unittest.cc",
|
||||
"system/phonehub/silence_phone_quick_action_controller_unittest.cc",
|
||||
"system/phonehub/task_continuation_view_unittest.cc",
|
||||
"system/power/adaptive_charging_nudge_controller_unittest.cc",
|
||||
"system/power/backlights_forced_off_setter_unittest.cc",
|
||||
"system/power/hps_sense_controller_unittest.cc",
|
||||
"system/power/peripheral_battery_listener_unittest.cc",
|
||||
|
@ -35,7 +35,11 @@ constexpr char kDictationNudgeName[] = "DictationOfflineContextualNudge";
|
||||
} // namespace
|
||||
|
||||
DictationNudge::DictationNudge(DictationNudgeController* controller)
|
||||
: SystemNudge(kDictationNudgeName), controller_(controller) {}
|
||||
: SystemNudge(kDictationNudgeName,
|
||||
kIconSize,
|
||||
kIconLabelSpacing,
|
||||
kNudgePadding),
|
||||
controller_(controller) {}
|
||||
|
||||
DictationNudge::~DictationNudge() = default;
|
||||
|
||||
@ -43,8 +47,6 @@ std::unique_ptr<views::View> DictationNudge::CreateLabelView() const {
|
||||
std::unique_ptr<views::Label> label = std::make_unique<views::Label>();
|
||||
label->SetPaintToLayer();
|
||||
label->layer()->SetFillsBoundsOpaquely(false);
|
||||
label->SetPosition(
|
||||
gfx::Point(kNudgePadding + kIconSize + kIconLabelSpacing, kNudgePadding));
|
||||
|
||||
label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
|
||||
label->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
|
||||
|
@ -25,8 +25,6 @@ class ASH_EXPORT DictationNudgeController : public SystemNudgeController {
|
||||
DictationNudgeController& operator=(const DictationNudgeController&) = delete;
|
||||
~DictationNudgeController() override;
|
||||
|
||||
SystemNudge* GetDictationNudgeForTesting() const { return nudge_.get(); }
|
||||
|
||||
std::string dictation_locale() const { return dictation_locale_; }
|
||||
std::string application_locale() const { return application_locale_; }
|
||||
|
||||
|
@ -124,7 +124,7 @@ TEST_F(DictationNudgeControllerTest, ShowsAndHidesNudge) {
|
||||
DictationNudgeController* controller = GetDictationNudgeController();
|
||||
ASSERT_TRUE(controller);
|
||||
|
||||
SystemNudge* nudge = controller->GetDictationNudgeForTesting();
|
||||
SystemNudge* nudge = controller->GetSystemNudgeForTesting();
|
||||
ASSERT_TRUE(nudge);
|
||||
|
||||
WaitForWidgetClose(controller, nudge);
|
||||
@ -149,7 +149,7 @@ TEST_F(DictationNudgeControllerTest, SetsLabelBasedOnApplicationLocale) {
|
||||
ASSERT_TRUE(controller);
|
||||
|
||||
DictationNudge* nudge =
|
||||
static_cast<DictationNudge*>(controller->GetDictationNudgeForTesting());
|
||||
static_cast<DictationNudge*>(controller->GetSystemNudgeForTesting());
|
||||
ASSERT_TRUE(nudge);
|
||||
|
||||
std::unique_ptr<views::View> label = GetDictationNudgeLabel(nudge);
|
||||
@ -161,4 +161,4 @@ TEST_F(DictationNudgeControllerTest, SetsLabelBasedOnApplicationLocale) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ash
|
||||
} // namespace ash
|
||||
|
@ -4846,6 +4846,11 @@ New install
|
||||
<message name="IDS_ASH_USB_NOTIFICATION_V2_CABLE_WARNING_SPEED_LIMITED_BODY" desc="Notification body text for when a user connects a device to their Chromebook with a cable that has a lower maximum data rate than the device.">
|
||||
Your device supports a higher data rate than your cable. Device performance may be limited.
|
||||
</message>
|
||||
|
||||
<!-- Adaptive charging -->
|
||||
<message name="IDS_ASH_ADAPTIVE_CHARGING_EDUCATIONAL_NUDGE_TEXT" desc="The body text explaining to the user that adaptive charging is on.">
|
||||
Adaptive charging is on. Your battery will stay at 80% to extend battery life, and fully charge when you need it.
|
||||
</message>
|
||||
</messages>
|
||||
</release>
|
||||
</grit>
|
||||
|
@ -0,0 +1 @@
|
||||
7eacc3eb101f3d69f8ff42de1e6561a2289558c8
|
@ -56,7 +56,11 @@ bool IsAssistantAvailable() {
|
||||
} // namespace
|
||||
|
||||
ClipboardNudge::ClipboardNudge(ClipboardNudgeType nudge_type)
|
||||
: SystemNudge(kClipboardNudgeName), nudge_type_(nudge_type) {}
|
||||
: SystemNudge(kClipboardNudgeName,
|
||||
kClipboardIconSize,
|
||||
kIconLabelSpacing,
|
||||
kNudgePadding),
|
||||
nudge_type_(nudge_type) {}
|
||||
|
||||
ClipboardNudge::~ClipboardNudge() = default;
|
||||
|
||||
@ -65,8 +69,6 @@ std::unique_ptr<views::View> ClipboardNudge::CreateLabelView() const {
|
||||
std::make_unique<views::StyledLabel>();
|
||||
label->SetPaintToLayer();
|
||||
label->layer()->SetFillsBoundsOpaquely(false);
|
||||
label->SetPosition(gfx::Point(
|
||||
kNudgePadding + kClipboardIconSize + kIconLabelSpacing, kNudgePadding));
|
||||
|
||||
bool use_launcher_key = ui::DeviceUsesKeyboardLayout2();
|
||||
|
||||
|
@ -106,7 +106,6 @@ class ASH_EXPORT ClipboardNudgeController
|
||||
void ClearClockOverrideForTesting();
|
||||
|
||||
const ClipboardState& GetClipboardStateForTesting();
|
||||
SystemNudge* GetClipboardNudgeForTesting() { return nudge_.get(); }
|
||||
|
||||
protected:
|
||||
// SystemNudgeController:
|
||||
|
@ -131,7 +131,7 @@ TEST_F(ClipboardNudgeControllerTest, ShouldShowNudgeAfterCorrectSequence) {
|
||||
nudge_controller_->GetClipboardStateForTesting());
|
||||
|
||||
// Check that clipbaord nudge has not yet been created.
|
||||
EXPECT_FALSE(nudge_controller_->GetClipboardNudgeForTesting());
|
||||
EXPECT_FALSE(nudge_controller_->GetSystemNudgeForTesting());
|
||||
|
||||
// Checks that the second paste resets state as expected.
|
||||
nudge_controller_->OnClipboardDataRead();
|
||||
@ -139,7 +139,7 @@ TEST_F(ClipboardNudgeControllerTest, ShouldShowNudgeAfterCorrectSequence) {
|
||||
nudge_controller_->GetClipboardStateForTesting());
|
||||
|
||||
// Check that clipbaord nudge has been created.
|
||||
EXPECT_TRUE(nudge_controller_->GetClipboardNudgeForTesting());
|
||||
EXPECT_TRUE(nudge_controller_->GetSystemNudgeForTesting());
|
||||
}
|
||||
|
||||
// Checks that the clipboard state does not advace if too much time passes
|
||||
@ -183,7 +183,7 @@ TEST_F(ClipboardNudgeControllerTest, NudgeDoesNotTimeOutWithSparsePastes) {
|
||||
}
|
||||
|
||||
// Check that clipbaord nudge has not yet been created.
|
||||
EXPECT_FALSE(nudge_controller_->GetClipboardNudgeForTesting());
|
||||
EXPECT_FALSE(nudge_controller_->GetSystemNudgeForTesting());
|
||||
|
||||
// Check that HandleClipboardChanged() will advance nudge_controller's
|
||||
// ClipboardState.
|
||||
@ -196,7 +196,7 @@ TEST_F(ClipboardNudgeControllerTest, NudgeDoesNotTimeOutWithSparsePastes) {
|
||||
nudge_controller_->GetClipboardStateForTesting());
|
||||
|
||||
// Check that clipbaord nudge has been created.
|
||||
EXPECT_TRUE(nudge_controller_->GetClipboardNudgeForTesting());
|
||||
EXPECT_TRUE(nudge_controller_->GetSystemNudgeForTesting());
|
||||
}
|
||||
|
||||
// Checks that consecutive copy events does not advance the clipboard state.
|
||||
@ -268,7 +268,7 @@ TEST_F(ClipboardNudgeControllerTest, ShowZeroStateNudgeAfterOngoingNudge) {
|
||||
ShowNudgeForType(ClipboardNudgeType::kOnboardingNudge);
|
||||
|
||||
ClipboardNudge* nudge = static_cast<ClipboardNudge*>(
|
||||
nudge_controller_->GetClipboardNudgeForTesting());
|
||||
nudge_controller_->GetSystemNudgeForTesting());
|
||||
views::Widget* nudge_widget = nudge->widget();
|
||||
ASSERT_TRUE(nudge_widget->GetLayer()->GetAnimator()->is_animating());
|
||||
EXPECT_FALSE(nudge_widget->IsClosed());
|
||||
@ -281,7 +281,7 @@ TEST_F(ClipboardNudgeControllerTest, ShowZeroStateNudgeAfterOngoingNudge) {
|
||||
EXPECT_TRUE(widget_close_observer.WidgetClosed());
|
||||
|
||||
nudge = static_cast<ClipboardNudge*>(
|
||||
nudge_controller_->GetClipboardNudgeForTesting());
|
||||
nudge_controller_->GetSystemNudgeForTesting());
|
||||
EXPECT_FALSE(nudge->widget()->IsClosed());
|
||||
EXPECT_EQ(ClipboardNudgeType::kZeroStateNudge, nudge->nudge_type());
|
||||
}
|
||||
@ -292,7 +292,7 @@ TEST_F(ClipboardNudgeControllerTest, NudgeClosingDuringShutdown) {
|
||||
ShowNudgeForType(ClipboardNudgeType::kOnboardingNudge);
|
||||
|
||||
ClipboardNudge* nudge = static_cast<ClipboardNudge*>(
|
||||
nudge_controller_->GetClipboardNudgeForTesting());
|
||||
nudge_controller_->GetSystemNudgeForTesting());
|
||||
views::Widget* nudge_widget = nudge->widget();
|
||||
EXPECT_FALSE(nudge_widget->IsClosed());
|
||||
EXPECT_EQ(ClipboardNudgeType::kOnboardingNudge, nudge->nudge_type());
|
||||
|
@ -12,6 +12,8 @@ aggregate_vector_icons("ash_vector_icons") {
|
||||
icon_directory = "."
|
||||
|
||||
sources = [
|
||||
"adaptive_charging_nudge_dark.icon",
|
||||
"adaptive_charging_nudge_light.icon",
|
||||
"add_cellular_network.icon",
|
||||
"add_cellular_network_rtl.icon",
|
||||
"always_show_shelf.icon",
|
||||
|
100
ash/resources/vector_icons/adaptive_charging_nudge_dark.icon
Normal file
100
ash/resources/vector_icons/adaptive_charging_nudge_dark.icon
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
CANVAS_DIMENSIONS, 60,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x5B, 0xB9, 0x74,
|
||||
MOVE_TO, 53.09f, 20.44f,
|
||||
R_CUBIC_TO, 0.24f, -0.24f, 0.45f, -0.52f, 0.65f, -0.78f,
|
||||
R_ARC_TO, 1.76f, 1.76f, 0, 0, 1, 1.18f, -0.65f,
|
||||
R_CUBIC_TO, 0.25f, -0.03f, 0.52f, -0.04f, 0.77f, -0.1f,
|
||||
R_CUBIC_TO, 0.89f, -0.2f, 1.43f, -1.12f, 1.1f, -1.99f,
|
||||
R_CUBIC_TO, -0.3f, -0.76f, -1.22f, -1.17f, -1.97f, -0.8f,
|
||||
R_CUBIC_TO, -0.35f, 0.17f, -0.62f, 0.44f, -0.95f, 0.64f,
|
||||
R_CUBIC_TO, -0.35f, 0.21f, -0.75f, 0.3f, -1.16f, 0.23f,
|
||||
R_CUBIC_TO, -0.35f, -0.05f, -0.68f, -0.14f, -1.04f, -0.14f,
|
||||
R_ARC_TO, 2.06f, 2.06f, 0, 0, 0, -0.99f, 0.23f,
|
||||
R_ARC_TO, 2.13f, 2.13f, 0, 0, 0, -1.06f, 2.54f,
|
||||
R_ARC_TO, 2.1f, 2.1f, 0, 0, 0, 2.78f, 1.32f,
|
||||
R_CUBIC_TO, 0.28f, -0.11f, 0.51f, -0.28f, 0.71f, -0.49f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xFC, 0xC9, 0x34,
|
||||
MOVE_TO, 48.87f, 42.12f,
|
||||
R_ARC_TO, 2.12f, 2.12f, 0, 0, 1, 1, -2.84f,
|
||||
R_LINE_TO, 0.03f, -0.01f,
|
||||
R_ARC_TO, 2.14f, 2.14f, 0, 0, 1, 2.85f, 1,
|
||||
R_CUBIC_TO, 0.51f, 1.06f, 0.06f, 2.33f, -1, 2.84f,
|
||||
R_LINE_TO, -0.03f, 0.01f,
|
||||
R_CUBIC_TO, -1.06f, 0.5f, -2.34f, 0.05f, -2.85f, -1,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x18, 0x5A, 0xBC,
|
||||
MOVE_TO, 4.31f, 50.01f,
|
||||
R_ARC_TO, 1.83f, 1.83f, 0, 0, 1, 0.25f, -2.55f,
|
||||
R_LINE_TO, 3.25f, -2.72f,
|
||||
R_CUBIC_TO, 0.77f, -0.63f, 1.9f, -0.55f, 2.53f, 0.23f,
|
||||
R_CUBIC_TO, 0.62f, 0.77f, 0.53f, 1.91f, -0.25f, 2.55f,
|
||||
LINE_TO, 6.84f, 50.24f,
|
||||
R_CUBIC_TO, -0.76f, 0.64f, -1.89f, 0.54f, -2.53f, -0.23f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xF8, 0x82, 0xFF,
|
||||
R_MOVE_TO, 11.78f, 27.98f,
|
||||
R_LINE_TO, -0.43f, -3.45f,
|
||||
R_CUBIC_TO, -0.01f, -0.12f, -0.17f, -0.18f, -0.27f, -0.11f,
|
||||
R_LINE_TO, -3.01f, 2.06f,
|
||||
R_ARC_TO, 0.15f, 0.15f, 0, 0, 0, 0.04f, 0.27f,
|
||||
R_LINE_TO, 3.45f, 1.37f,
|
||||
R_CUBIC_TO, 0.1f, 0.06f, 0.25f, -0.04f, 0.22f, -0.15f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x8A, 0xB4, 0xF8,
|
||||
MOVE_TO, 41, 5.71f,
|
||||
R_H_LINE_TO, -4.92f,
|
||||
V_LINE_TO, 1.35f,
|
||||
H_LINE_TO, 24.3f,
|
||||
R_V_LINE_TO, 4.36f,
|
||||
H_LINE_TO, 19.38f,
|
||||
R_CUBIC_TO, -2.15f, 0, -3.92f, 1.76f, -3.92f, 3.9f,
|
||||
R_V_LINE_TO, 44.93f,
|
||||
R_ARC_TO, 3.93f, 3.93f, 0, 0, 0, 3.92f, 3.93f,
|
||||
R_H_LINE_TO, 21.59f,
|
||||
R_CUBIC_TO, 2.18f, 0, 3.95f, -1.76f, 3.95f, -3.9f,
|
||||
V_LINE_TO, 9.61f,
|
||||
R_CUBIC_TO, -0.01f, -2.14f, -1.77f, -3.9f, -3.92f, -3.9f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x66, 0x9D, 0xF6,
|
||||
MOVE_TO, 43, 20.94f,
|
||||
R_CUBIC_TO, 0.23f, -3.83f, -3.06f, -6.99f, -7.12f, -6.96f,
|
||||
R_ARC_TO, 7.44f, 7.44f, 0, 0, 0, -2.79f, 0.56f,
|
||||
R_CUBIC_TO, -0.3f, 0.12f, -0.59f, 0.27f, -0.86f, 0.43f,
|
||||
R_ARC_TO, 10.46f, 10.46f, 0, 0, 0, -0.55f, 0.35f,
|
||||
R_LINE_TO, -1.52f, 0.83f,
|
||||
R_ARC_TO, 6.26f, 6.26f, 0, 0, 1, -4.31f, 0.61f,
|
||||
R_CUBIC_TO, -0.03f, -0.01f, -0.05f, -0.01f, -0.08f, -0.01f,
|
||||
R_CUBIC_TO, -0.85f, -0.2f, -1.71f, -0.47f, -2.6f, -0.59f,
|
||||
R_CUBIC_TO, -3.01f, -0.41f, -5.81f, 1.66f, -5.8f, 4.56f,
|
||||
R_V_LINE_TO, 33.3f,
|
||||
R_ARC_TO, 2.52f, 2.52f, 0, 0, 0, 2.53f, 2.52f,
|
||||
H_LINE_TO, 40.48f,
|
||||
R_ARC_TO, 2.52f, 2.52f, 0, 0, 0, 2.53f, -2.52f,
|
||||
R_LINE_TO, -0.01f, -33.06f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
R_MOVE_TO, 31.55f, 26.67f,
|
||||
R_LINE_TO, -4.88f, 9.23f,
|
||||
R_H_LINE_TO, 2.45f,
|
||||
R_V_LINE_TO, 6.77f,
|
||||
R_LINE_TO, 4.88f, -9.23f,
|
||||
R_H_LINE_TO, -2.45f,
|
||||
R_V_LINE_TO, -6.77f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x8A, 0xB4, 0xF8,
|
||||
MOVE_TO, 4.35f, 15.07f,
|
||||
R_ARC_TO, 1.67f, 1.67f, 0, 1, 0, 0, -3.33f,
|
||||
R_ARC_TO, 1.67f, 1.67f, 0, 0, 0, 0, 3.33f,
|
||||
CLOSE
|
100
ash/resources/vector_icons/adaptive_charging_nudge_light.icon
Normal file
100
ash/resources/vector_icons/adaptive_charging_nudge_light.icon
Normal file
@ -0,0 +1,100 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
CANVAS_DIMENSIONS, 60,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x34, 0xA8, 0x53,
|
||||
MOVE_TO, 53.12f, 20.43f,
|
||||
R_CUBIC_TO, 0.24f, -0.24f, 0.45f, -0.52f, 0.65f, -0.78f,
|
||||
R_ARC_TO, 1.76f, 1.76f, 0, 0, 1, 1.18f, -0.65f,
|
||||
R_CUBIC_TO, 0.25f, -0.03f, 0.52f, -0.04f, 0.77f, -0.1f,
|
||||
R_CUBIC_TO, 0.89f, -0.2f, 1.43f, -1.12f, 1.1f, -1.99f,
|
||||
R_CUBIC_TO, -0.3f, -0.76f, -1.22f, -1.17f, -1.98f, -0.8f,
|
||||
R_CUBIC_TO, -0.35f, 0.17f, -0.62f, 0.44f, -0.95f, 0.64f,
|
||||
R_CUBIC_TO, -0.35f, 0.21f, -0.75f, 0.3f, -1.16f, 0.24f,
|
||||
R_CUBIC_TO, -0.35f, -0.05f, -0.68f, -0.14f, -1.04f, -0.15f,
|
||||
R_ARC_TO, 2.07f, 2.07f, 0, 0, 0, -1, 0.23f,
|
||||
R_ARC_TO, 2.14f, 2.14f, 0, 0, 0, -1.06f, 2.54f,
|
||||
R_ARC_TO, 2.1f, 2.1f, 0, 0, 0, 2.78f, 1.32f,
|
||||
R_CUBIC_TO, 0.29f, -0.11f, 0.51f, -0.28f, 0.71f, -0.49f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xFB, 0xBC, 0x04,
|
||||
MOVE_TO, 48.89f, 42.13f,
|
||||
R_ARC_TO, 2.13f, 2.13f, 0, 0, 1, 1.01f, -2.84f,
|
||||
R_LINE_TO, 0.03f, -0.01f,
|
||||
R_ARC_TO, 2.15f, 2.15f, 0, 0, 1, 2.86f, 1,
|
||||
R_ARC_TO, 2.13f, 2.13f, 0, 0, 1, -1.01f, 2.84f,
|
||||
R_LINE_TO, -0.03f, 0.01f,
|
||||
R_CUBIC_TO, -1.07f, 0.5f, -2.34f, 0.05f, -2.86f, -1,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x17, 0x4E, 0xA6,
|
||||
MOVE_TO, 4.28f, 50.03f,
|
||||
R_ARC_TO, 1.83f, 1.83f, 0, 0, 1, 0.25f, -2.56f,
|
||||
R_LINE_TO, 3.25f, -2.72f,
|
||||
R_CUBIC_TO, 0.77f, -0.63f, 1.9f, -0.55f, 2.54f, 0.23f,
|
||||
R_CUBIC_TO, 0.62f, 0.77f, 0.53f, 1.91f, -0.25f, 2.56f,
|
||||
R_LINE_TO, -3.25f, 2.73f,
|
||||
R_CUBIC_TO, -0.76f, 0.64f, -1.9f, 0.54f, -2.54f, -0.23f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xEE, 0x5F, 0xFA,
|
||||
R_MOVE_TO, 11.76f, 27.98f,
|
||||
R_LINE_TO, -0.43f, -3.45f,
|
||||
R_CUBIC_TO, -0.01f, -0.12f, -0.17f, -0.18f, -0.27f, -0.11f,
|
||||
R_LINE_TO, -3.01f, 2.07f,
|
||||
R_ARC_TO, 0.15f, 0.15f, 0, 0, 0, 0.04f, 0.28f,
|
||||
R_LINE_TO, 3.45f, 1.37f,
|
||||
R_CUBIC_TO, 0.1f, 0.06f, 0.25f, -0.04f, 0.22f, -0.16f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xD2, 0xE3, 0xFC,
|
||||
MOVE_TO, 41.01f, 5.68f,
|
||||
R_H_LINE_TO, -4.93f,
|
||||
V_LINE_TO, 1.32f,
|
||||
H_LINE_TO, 24.29f,
|
||||
R_V_LINE_TO, 4.36f,
|
||||
R_H_LINE_TO, -4.92f,
|
||||
R_CUBIC_TO, -2.15f, 0, -3.92f, 1.76f, -3.92f, 3.9f,
|
||||
V_LINE_TO, 54.56f,
|
||||
R_ARC_TO, 3.94f, 3.94f, 0, 0, 0, 3.92f, 3.93f,
|
||||
R_H_LINE_TO, 21.62f,
|
||||
R_CUBIC_TO, 2.19f, 0, 3.95f, -1.76f, 3.95f, -3.9f,
|
||||
V_LINE_TO, 9.58f,
|
||||
R_CUBIC_TO, -0.01f, -2.14f, -1.78f, -3.9f, -3.92f, -3.9f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0x42, 0x85, 0xF4,
|
||||
MOVE_TO, 43.02f, 20.93f,
|
||||
R_CUBIC_TO, 0.23f, -3.84f, -3.06f, -7, -7.13f, -6.97f,
|
||||
R_ARC_TO, 7.45f, 7.45f, 0, 0, 0, -2.8f, 0.56f,
|
||||
R_CUBIC_TO, -0.3f, 0.12f, -0.59f, 0.27f, -0.86f, 0.43f,
|
||||
R_ARC_TO, 10.37f, 10.37f, 0, 0, 0, -0.55f, 0.35f,
|
||||
R_LINE_TO, -1.52f, 0.83f,
|
||||
R_ARC_TO, 6.26f, 6.26f, 0, 0, 1, -4.32f, 0.61f,
|
||||
R_CUBIC_TO, -0.03f, -0.01f, -0.05f, -0.01f, -0.08f, -0.01f,
|
||||
R_CUBIC_TO, -0.85f, -0.2f, -1.72f, -0.47f, -2.6f, -0.59f,
|
||||
R_CUBIC_TO, -3.02f, -0.41f, -5.82f, 1.66f, -5.81f, 4.57f,
|
||||
V_LINE_TO, 54.03f,
|
||||
R_ARC_TO, 2.53f, 2.53f, 0, 0, 0, 2.53f, 2.52f,
|
||||
R_H_LINE_TO, 20.61f,
|
||||
R_ARC_TO, 2.53f, 2.53f, 0, 0, 0, 2.53f, -2.52f,
|
||||
R_LINE_TO, -0.01f, -33.1f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
R_MOVE_TO, 31.55f, 26.67f,
|
||||
R_LINE_TO, -4.89f, 9.24f,
|
||||
R_H_LINE_TO, 2.45f,
|
||||
R_V_LINE_TO, 6.77f,
|
||||
R_LINE_TO, 4.89f, -9.24f,
|
||||
R_H_LINE_TO, -2.45f,
|
||||
R_V_LINE_TO, -6.77f,
|
||||
CLOSE,
|
||||
NEW_PATH,
|
||||
PATH_COLOR_ARGB, 0xFF, 0xD2, 0xE3, 0xFC,
|
||||
MOVE_TO, 4.32f, 15.05f,
|
||||
R_ARC_TO, 1.67f, 1.67f, 0, 1, 0, 0, -3.33f,
|
||||
R_ARC_TO, 1.67f, 1.67f, 0, 0, 0, 0, 3.34f,
|
||||
CLOSE
|
82
ash/system/power/adaptive_charging_nudge.cc
Normal file
82
ash/system/power/adaptive_charging_nudge.cc
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ash/system/power/adaptive_charging_nudge.h"
|
||||
|
||||
#include "ash/resources/vector_icons/vector_icons.h"
|
||||
#include "ash/strings/grit/ash_strings.h"
|
||||
#include "ash/style/ash_color_provider.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/views/controls/styled_label.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
namespace {
|
||||
|
||||
// The size of the icon.
|
||||
constexpr int kIconSize = 60;
|
||||
|
||||
// The spacing between the icon and label in the nudge view.
|
||||
constexpr int kIconLabelSpacing = 20;
|
||||
|
||||
// The padding which separates the nudge's border with its inner contents.
|
||||
constexpr int kNudgePadding = 20;
|
||||
|
||||
// The minimum width of the label.
|
||||
constexpr int kMinLabelWidth = 232;
|
||||
|
||||
// Use a bigger font size than the default one.
|
||||
constexpr int kFontSizeDelta = 2;
|
||||
|
||||
constexpr char kAdaptiveChargingNudgeName[] =
|
||||
"AdaptiveChargingEducationalNudge";
|
||||
|
||||
} // namespace
|
||||
|
||||
AdaptiveChargingNudge::AdaptiveChargingNudge()
|
||||
: SystemNudge(kAdaptiveChargingNudgeName,
|
||||
kIconSize,
|
||||
kIconLabelSpacing,
|
||||
kNudgePadding) {}
|
||||
|
||||
AdaptiveChargingNudge::~AdaptiveChargingNudge() = default;
|
||||
|
||||
std::unique_ptr<views::View> AdaptiveChargingNudge::CreateLabelView() const {
|
||||
std::unique_ptr<views::StyledLabel> label =
|
||||
std::make_unique<views::StyledLabel>();
|
||||
label->SetPaintToLayer();
|
||||
label->layer()->SetFillsBoundsOpaquely(false);
|
||||
label->SetPosition(
|
||||
gfx::Point(kNudgePadding + kIconSize + kIconLabelSpacing, kNudgePadding));
|
||||
|
||||
std::u16string label_text = l10n_util::GetStringUTF16(
|
||||
IDS_ASH_ADAPTIVE_CHARGING_EDUCATIONAL_NUDGE_TEXT);
|
||||
label->SetText(label_text);
|
||||
|
||||
// Text color and size.
|
||||
views::StyledLabel::RangeStyleInfo text_style;
|
||||
text_style.override_color = AshColorProvider::Get()->GetContentLayerColor(
|
||||
AshColorProvider::ContentLayerType::kTextColorPrimary);
|
||||
text_style.custom_font =
|
||||
label->GetFontList().DeriveWithSizeDelta(kFontSizeDelta);
|
||||
label->AddStyleRange(gfx::Range(0, label_text.length()), text_style);
|
||||
|
||||
label->SizeToFit(kMinLabelWidth);
|
||||
label->SetDisplayedOnBackgroundColor(SK_ColorTRANSPARENT);
|
||||
return std::move(label);
|
||||
}
|
||||
|
||||
const gfx::VectorIcon& AdaptiveChargingNudge::GetIcon() const {
|
||||
return AshColorProvider::Get()->IsDarkModeEnabled()
|
||||
? kAdaptiveChargingNudgeDarkIcon
|
||||
: kAdaptiveChargingNudgeLightIcon;
|
||||
}
|
||||
|
||||
std::u16string AdaptiveChargingNudge::GetAccessibilityText() const {
|
||||
// TODO(b:216035485): Calculate text for screen readers.
|
||||
return u"";
|
||||
}
|
||||
|
||||
} // namespace ash
|
30
ash/system/power/adaptive_charging_nudge.h
Normal file
30
ash/system/power/adaptive_charging_nudge.h
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_H_
|
||||
#define ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_H_
|
||||
|
||||
#include "ash/ash_export.h"
|
||||
#include "ash/system/tray/system_nudge.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
// Implements a contextual nudge for apdative charging.
|
||||
class ASH_EXPORT AdaptiveChargingNudge : public SystemNudge {
|
||||
public:
|
||||
explicit AdaptiveChargingNudge();
|
||||
AdaptiveChargingNudge(const AdaptiveChargingNudge&) = delete;
|
||||
AdaptiveChargingNudge& operator=(const AdaptiveChargingNudge&) = delete;
|
||||
~AdaptiveChargingNudge() override;
|
||||
|
||||
private:
|
||||
// SystemNudge:
|
||||
std::unique_ptr<views::View> CreateLabelView() const override;
|
||||
const gfx::VectorIcon& GetIcon() const override;
|
||||
std::u16string GetAccessibilityText() const override;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_H_
|
19
ash/system/power/adaptive_charging_nudge_controller.cc
Normal file
19
ash/system/power/adaptive_charging_nudge_controller.cc
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ash/system/power/adaptive_charging_nudge_controller.h"
|
||||
|
||||
#include "ash/system/power/adaptive_charging_nudge.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
AdaptiveChargingNudgeController::AdaptiveChargingNudgeController() {}
|
||||
AdaptiveChargingNudgeController::~AdaptiveChargingNudgeController() {}
|
||||
|
||||
std::unique_ptr<SystemNudge>
|
||||
AdaptiveChargingNudgeController::CreateSystemNudge() {
|
||||
return std::make_unique<AdaptiveChargingNudge>();
|
||||
}
|
||||
|
||||
} // namespace ash
|
34
ash/system/power/adaptive_charging_nudge_controller.h
Normal file
34
ash/system/power/adaptive_charging_nudge_controller.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_CONTROLLER_H_
|
||||
#define ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_CONTROLLER_H_
|
||||
|
||||
#include "ash/ash_export.h"
|
||||
#include "ash/system/tray/system_nudge_controller.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
class SystemNudge;
|
||||
|
||||
// Class that manages showing a nudge explaining that adaptive charging has been
|
||||
// enabled on this device.
|
||||
class ASH_EXPORT AdaptiveChargingNudgeController
|
||||
: public SystemNudgeController {
|
||||
public:
|
||||
AdaptiveChargingNudgeController();
|
||||
AdaptiveChargingNudgeController(const AdaptiveChargingNudgeController&) =
|
||||
delete;
|
||||
AdaptiveChargingNudgeController operator=(
|
||||
const AdaptiveChargingNudgeController&) = delete;
|
||||
~AdaptiveChargingNudgeController() override;
|
||||
|
||||
private:
|
||||
// SystemNudgeController:
|
||||
std::unique_ptr<SystemNudge> CreateSystemNudge() override;
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_SYSTEM_POWER_ADAPTIVE_CHARGING_NUDGE_CONTROLLER_H_
|
103
ash/system/power/adaptive_charging_nudge_controller_unittest.cc
Normal file
103
ash/system/power/adaptive_charging_nudge_controller_unittest.cc
Normal file
@ -0,0 +1,103 @@
|
||||
// Copyright 2022 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ash/shell.h"
|
||||
#include "ash/system/power/adaptive_charging_nudge_controller.h"
|
||||
#include "ash/system/tray/system_nudge.h"
|
||||
#include "ash/test/ash_test_base.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/compositor/layer_animator.h"
|
||||
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
#include "ui/views/widget/widget_observer.h"
|
||||
|
||||
namespace ash {
|
||||
|
||||
namespace {
|
||||
|
||||
// Utility class to wait/observe the closing of the nudge.
|
||||
class NudgeWidgetObserver : public views::WidgetObserver {
|
||||
public:
|
||||
NudgeWidgetObserver(views::Widget* widget) {
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
widget_observation_.Observe(widget);
|
||||
}
|
||||
|
||||
void WaitForClose() {
|
||||
run_loop_ = std::make_unique<base::RunLoop>();
|
||||
run_loop_->Run();
|
||||
}
|
||||
|
||||
// views::WidgetObserver:
|
||||
void OnWidgetClosing(views::Widget* widget) override {
|
||||
if (run_loop_)
|
||||
run_loop_->Quit();
|
||||
}
|
||||
|
||||
private:
|
||||
base::ScopedObservation<views::Widget, views::WidgetObserver>
|
||||
widget_observation_{this};
|
||||
std::unique_ptr<base::RunLoop> run_loop_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
class AdaptiveChargingNudgeControllerTest : public AshTestBase {
|
||||
public:
|
||||
AdaptiveChargingNudgeControllerTest() = default;
|
||||
AdaptiveChargingNudgeControllerTest(
|
||||
const AdaptiveChargingNudgeControllerTest&) = delete;
|
||||
AdaptiveChargingNudgeControllerTest& operator=(
|
||||
const AdaptiveChargingNudgeControllerTest&) = delete;
|
||||
~AdaptiveChargingNudgeControllerTest() override = default;
|
||||
|
||||
// AshTestBase:
|
||||
void SetUp() override {
|
||||
AshTestBase::SetUp();
|
||||
controller_ = std::make_unique<AdaptiveChargingNudgeController>();
|
||||
}
|
||||
|
||||
AdaptiveChargingNudgeController* GetController() { return controller_.get(); }
|
||||
|
||||
void WaitForWidgetClose(AdaptiveChargingNudgeController* controller,
|
||||
SystemNudge* nudge) {
|
||||
views::Widget* nudge_widget = nudge->widget();
|
||||
ASSERT_TRUE(nudge_widget);
|
||||
EXPECT_FALSE(nudge_widget->IsClosed());
|
||||
|
||||
// Slow down the duration of the nudge.
|
||||
ui::ScopedAnimationDurationScaleMode test_duration_mode(
|
||||
ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
|
||||
|
||||
// Pretend the hide nudge timer has elapsed.
|
||||
NudgeWidgetObserver widget_close_observer(nudge_widget);
|
||||
controller->FireHideNudgeTimerForTesting();
|
||||
|
||||
EXPECT_TRUE(nudge_widget->GetLayer()->GetAnimator()->is_animating());
|
||||
|
||||
widget_close_observer.WaitForClose();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<AdaptiveChargingNudgeController> controller_;
|
||||
};
|
||||
|
||||
TEST_F(AdaptiveChargingNudgeControllerTest, ShowsAndHidesNudge) {
|
||||
AdaptiveChargingNudgeController* controller = GetController();
|
||||
ASSERT_TRUE(controller);
|
||||
|
||||
controller->ShowNudge();
|
||||
|
||||
SystemNudge* nudge = controller->GetSystemNudgeForTesting();
|
||||
ASSERT_TRUE(nudge);
|
||||
|
||||
WaitForWidgetClose(controller, nudge);
|
||||
}
|
||||
|
||||
} // namespace ash
|
@ -35,18 +35,9 @@ constexpr int kNudgeCornerRadius = 8;
|
||||
// The blur radius for the nudge view's background.
|
||||
constexpr int kNudgeBlurRadius = 30;
|
||||
|
||||
// The size of the icon.
|
||||
constexpr int kIconSize = 20;
|
||||
|
||||
// The margin between the edge of the screen/shelf and the nudge widget bounds.
|
||||
constexpr int kNudgeMargin = 8;
|
||||
|
||||
// The spacing between the icon and label in the nudge view.
|
||||
constexpr int kIconLabelSpacing = 16;
|
||||
|
||||
// The padding which separates the nudge's border with its inner contents.
|
||||
constexpr int kNudgePadding = 16;
|
||||
|
||||
constexpr base::TimeDelta kNudgeBoundsAnimationTime = base::Milliseconds(250);
|
||||
|
||||
} // namespace
|
||||
@ -54,7 +45,8 @@ constexpr base::TimeDelta kNudgeBoundsAnimationTime = base::Milliseconds(250);
|
||||
class SystemNudge::SystemNudgeView : public views::View {
|
||||
public:
|
||||
explicit SystemNudgeView(std::unique_ptr<views::View> label_view,
|
||||
const gfx::VectorIcon& icon_img) {
|
||||
const gfx::VectorIcon& icon_img,
|
||||
const SystemNudgeParams& params) {
|
||||
SetPaintToLayer(ui::LAYER_SOLID_COLOR);
|
||||
layer()->SetColor(ShelfConfig::Get()->GetDefaultShelfColor());
|
||||
if (features::IsBackgroundBlurEnabled())
|
||||
@ -68,14 +60,16 @@ class SystemNudge::SystemNudgeView : public views::View {
|
||||
icon_ = AddChildView(std::make_unique<views::ImageView>());
|
||||
icon_->SetPaintToLayer();
|
||||
icon_->layer()->SetFillsBoundsOpaquely(false);
|
||||
icon_->SetBounds(kNudgePadding, kNudgePadding, kIconSize, kIconSize);
|
||||
icon_->SetBounds(params.nudge_padding, params.nudge_padding,
|
||||
params.icon_size, params.icon_size);
|
||||
icon_->SetImage(gfx::CreateVectorIcon(icon_img, icon_color));
|
||||
|
||||
label_ = AddChildView(std::move(label_view));
|
||||
label_->SetPaintToLayer();
|
||||
label_->layer()->SetFillsBoundsOpaquely(false);
|
||||
label_->SetPosition(gfx::Point(
|
||||
kNudgePadding + kIconSize + kIconLabelSpacing, kNudgePadding));
|
||||
params.nudge_padding + params.icon_size + params.icon_label_spacing,
|
||||
params.nudge_padding));
|
||||
}
|
||||
|
||||
~SystemNudgeView() override = default;
|
||||
@ -84,8 +78,16 @@ class SystemNudge::SystemNudgeView : public views::View {
|
||||
views::ImageView* icon_ = nullptr;
|
||||
};
|
||||
|
||||
SystemNudge::SystemNudge(const std::string& name)
|
||||
: root_window_(Shell::GetRootWindowForNewWindows()), name_(name) {}
|
||||
SystemNudge::SystemNudge(const std::string& name,
|
||||
int icon_size,
|
||||
int icon_label_spacing,
|
||||
int nudge_padding)
|
||||
: root_window_(Shell::GetRootWindowForNewWindows()) {
|
||||
params_.name = name;
|
||||
params_.icon_size = icon_size;
|
||||
params_.icon_label_spacing = icon_label_spacing;
|
||||
params_.nudge_padding = nudge_padding;
|
||||
}
|
||||
|
||||
SystemNudge::~SystemNudge() = default;
|
||||
|
||||
@ -110,7 +112,7 @@ void SystemNudge::Show() {
|
||||
params.z_order = ui::ZOrderLevel::kFloatingWindow;
|
||||
params.activatable = views::Widget::InitParams::Activatable::kNo;
|
||||
params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
|
||||
params.name = name_;
|
||||
params.name = params_.name;
|
||||
params.layer_type = ui::LAYER_NOT_DRAWN;
|
||||
params.parent =
|
||||
root_window_->GetChildById(kShellWindowId_SettingBubbleContainer);
|
||||
@ -118,7 +120,7 @@ void SystemNudge::Show() {
|
||||
}
|
||||
|
||||
nudge_view_ = widget_->SetContentsView(
|
||||
std::make_unique<SystemNudgeView>(CreateLabelView(), GetIcon()));
|
||||
std::make_unique<SystemNudgeView>(CreateLabelView(), GetIcon(), params_));
|
||||
CalculateAndSetWidgetBounds();
|
||||
widget_->Show();
|
||||
|
||||
@ -135,14 +137,19 @@ void SystemNudge::CalculateAndSetWidgetBounds() {
|
||||
if (!widget_ || !root_window_ || !nudge_view_)
|
||||
return;
|
||||
|
||||
DCHECK(nudge_view_->label_);
|
||||
|
||||
gfx::Rect display_bounds = root_window_->bounds();
|
||||
::wm::ConvertRectToScreen(root_window_, &display_bounds);
|
||||
gfx::Rect widget_bounds;
|
||||
|
||||
// Calculate the nudge's size to ensure the label text accurately fits.
|
||||
// Calculate the nudge's size to ensure the label text and the icon accurately
|
||||
// fit.
|
||||
const int nudge_height =
|
||||
2 * kNudgePadding + nudge_view_->label_->bounds().height();
|
||||
const int nudge_width = 2 * kNudgePadding + kIconSize + kIconLabelSpacing +
|
||||
2 * params_.nudge_padding +
|
||||
std::max(nudge_view_->label_->bounds().height(), params_.icon_size);
|
||||
const int nudge_width = 2 * params_.nudge_padding + params_.icon_size +
|
||||
params_.icon_label_spacing +
|
||||
nudge_view_->label_->bounds().width();
|
||||
|
||||
widget_bounds =
|
||||
|
@ -31,8 +31,10 @@ namespace ash {
|
||||
// system bubble with rounded corners.
|
||||
class ASH_EXPORT SystemNudge : public ShelfObserver {
|
||||
public:
|
||||
// |name| is used as the Widget name.
|
||||
explicit SystemNudge(const std::string& name);
|
||||
SystemNudge(const std::string& name,
|
||||
int icon_size,
|
||||
int icon_label_spacing,
|
||||
int nudge_padding);
|
||||
SystemNudge(const SystemNudge&) = delete;
|
||||
SystemNudge& operator=(const SystemNudge&) = delete;
|
||||
~SystemNudge() override;
|
||||
@ -52,8 +54,8 @@ class ASH_EXPORT SystemNudge : public ShelfObserver {
|
||||
|
||||
protected:
|
||||
// Each SystemNudge subclass must override these methods to customize
|
||||
// their nudge by creating a label and getting an icon specific to the
|
||||
// feature being nudged. These will be called only when needed by Show().
|
||||
// their nudge by creating a label and getting an icon specific to the feature
|
||||
// being nudged. These will be called only when needed by Show().
|
||||
|
||||
// Creates and initializes a view representing the label for the nudge.
|
||||
// Returns a views::View in case the subclass wishes to creates a StyledLabel,
|
||||
@ -70,6 +72,17 @@ class ASH_EXPORT SystemNudge : public ShelfObserver {
|
||||
private:
|
||||
class SystemNudgeView;
|
||||
|
||||
struct SystemNudgeParams {
|
||||
// The name for the widget.
|
||||
std::string name;
|
||||
// The size of the icon.
|
||||
int icon_size;
|
||||
// The size of the space between icon and label.
|
||||
int icon_label_spacing;
|
||||
// The padding which separates the nudge's border with its inner contents.
|
||||
int nudge_padding;
|
||||
};
|
||||
|
||||
// Calculate and set widget bounds based on a fixed width and a variable
|
||||
// height to correctly fit the label contents.
|
||||
void CalculateAndSetWidgetBounds();
|
||||
@ -80,12 +93,11 @@ class ASH_EXPORT SystemNudge : public ShelfObserver {
|
||||
|
||||
aura::Window* const root_window_;
|
||||
|
||||
// The name for the widget.
|
||||
const std::string name_;
|
||||
SystemNudgeParams params_;
|
||||
|
||||
base::ScopedObservation<Shelf, ShelfObserver> shelf_observation_{this};
|
||||
};
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_H_
|
||||
#endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_H_
|
||||
|
@ -37,6 +37,9 @@ class ASH_EXPORT SystemNudgeController {
|
||||
// Test method for triggering the nudge timer to hide.
|
||||
void FireHideNudgeTimerForTesting();
|
||||
|
||||
// Get the system nudge for testing purpose.
|
||||
SystemNudge* GetSystemNudgeForTesting() { return nudge_.get(); }
|
||||
|
||||
protected:
|
||||
// Concrete subclasses must implement this method to return a
|
||||
// SystemNudge that creates a label and specifies an icon specific
|
||||
@ -46,13 +49,13 @@ class ASH_EXPORT SystemNudgeController {
|
||||
// Hides the nudge widget.
|
||||
void HideNudge();
|
||||
|
||||
// Contextual nudge which shows a view.
|
||||
std::unique_ptr<SystemNudge> nudge_;
|
||||
|
||||
private:
|
||||
// Begins the animation for fading in or fading out the nudge.
|
||||
void StartFadeAnimation(bool show);
|
||||
|
||||
// Contextual nudge which shows a view.
|
||||
std::unique_ptr<SystemNudge> nudge_;
|
||||
|
||||
// Timer to hide the nudge.
|
||||
base::OneShotTimer hide_nudge_timer_;
|
||||
|
||||
@ -63,4 +66,4 @@ class ASH_EXPORT SystemNudgeController {
|
||||
|
||||
} // namespace ash
|
||||
|
||||
#endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_CONTROLLER_H_
|
||||
#endif // ASH_SYSTEM_TRAY_SYSTEM_NUDGE_CONTROLLER_H_
|
||||
|
Reference in New Issue
Block a user