1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
ash / wm / overview / birch / birch_chip_context_menu_model.cc [blame]
// 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/wm/overview/birch/birch_chip_context_menu_model.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/overview/birch/birch_bar_controller.h"
#include "ash/wm/overview/overview_utils.h"
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/menu_separator_types.h"
#include "ui/views/controls/menu/menu_types.h"
namespace ash {
namespace {
// Returns the pref service to use for Birch bar prefs.
PrefService* GetPrefService() {
return Shell::Get()->session_controller()->GetPrimaryUserPrefService();
}
} // namespace
BirchChipContextMenuModel::BirchChipContextMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
BirchSuggestionType chip_type)
: ui::SimpleMenuModel(delegate),
sub_menu_model_(std::make_unique<BirchBarContextMenuModel>(
delegate,
BirchBarContextMenuModel::Type::kExpandedBarMenu)) {
auto add_hide_suggestion_item = [&]() {
AddItemWithIcon(
base::to_underlying(CommandId::kHideSuggestion),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_THIS_SUGGESTION),
CreateIconForMenuItem(kSystemTrayDoNotDisturbIcon));
};
switch (chip_type) {
case BirchSuggestionType::kWeather:
AddItemWithIcon(
base::to_underlying(CommandId::kHideWeatherSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_WEATHER_SUGGESTION),
CreateIconForMenuItem(kForbidIcon));
break;
case BirchSuggestionType::kCalendar:
add_hide_suggestion_item();
AddItemWithIcon(
base::to_underlying(CommandId::kHideCalendarSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_CALENDAR_SUGGESTIONS),
CreateIconForMenuItem(kForbidIcon));
break;
case BirchSuggestionType::kDrive:
add_hide_suggestion_item();
AddItemWithIcon(
base::to_underlying(CommandId::kHideDriveSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_DRIVE_SUGGESTIONS),
CreateIconForMenuItem(kForbidIcon));
break;
case BirchSuggestionType::kChromeTab:
add_hide_suggestion_item();
AddItemWithIcon(
base::to_underlying(CommandId::kHideChromeTabSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_CHROME_SUGGESTIONS),
CreateIconForMenuItem(kForbidIcon));
break;
case BirchSuggestionType::kMedia:
// There's no "Hide this suggestion" for media because the media URLs we
// have in the BirchItem are very generic (e.g. "youtube.com"), so hiding
// "this" suggestion would hide all media from a given site.
AddItemWithIcon(
base::to_underlying(CommandId::kHideMediaSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_HIDE_MEDIA_SUGGESTIONS),
CreateIconForMenuItem(kForbidIcon));
break;
case BirchSuggestionType::kCoral:
// TODO(zxdan): Localize the strings.
AddItemWithIcon(base::to_underlying(CommandId::kCoralNewDesk), u"Open",
CreateIconForMenuItem(kCoralOpenIcon));
if (features::IsCoralFeatureEnabled() &&
!display::Screen::GetScreen()->InTabletMode() &&
!BirchBarController::Get()->is_informed_restore()) {
AddItemWithIcon(base::to_underlying(CommandId::kCoralSaveForLater),
u"Save group for later",
CreateIconForMenuItem(kSaveDeskForLaterIcon));
}
AddSeparator(ui::NORMAL_SEPARATOR);
add_hide_suggestion_item();
AddItemWithIcon(base::to_underlying(CommandId::kHideCoralSuggestions),
u"Don't suggest group to resume",
CreateIconForMenuItem(kForbidIcon));
break;
default:
break;
}
AddSubMenuWithIcon(
base::to_underlying(CommandId::kCustomizeSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_CUSTOMIZE_SUGGESTIONS),
sub_menu_model_.get(), CreateIconForMenuItem(kPencilIcon));
if (chip_type == BirchSuggestionType::kWeather) {
bool is_celsius = GetPrefService()->GetBoolean(prefs::kBirchUseCelsius);
AddItem(base::to_underlying(CommandId::kToggleTemperatureUnits),
l10n_util::GetStringUTF16(
is_celsius ? IDS_ASH_BIRCH_SHOW_TEMPERATURE_IN_FAHRENHEIT
: IDS_ASH_BIRCH_SHOW_TEMPERATURE_IN_CELSIUS));
}
// Add feedback menu for Coral.
if (chip_type == BirchSuggestionType::kCoral) {
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithIcon(base::to_underlying(CommandId::kProvideFeedback),
u"Send feedback", CreateIconForMenuItem(kFeedbackIcon));
}
}
BirchChipContextMenuModel::~BirchChipContextMenuModel() = default;
} // namespace ash