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
ash / wm / overview / birch / birch_bar_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_bar_context_menu_model.h"
#include "ash/constants/ash_features.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/wm/overview/overview_utils.h"
#include "base/types/cxx23_to_underlying.h"
#include "chromeos/ash/components/geolocation/simple_geolocation_provider.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 whether the weather item should be enabled based on the geolocation
// permission. See BirchWeatherProvider.
bool IsWeatherAllowedByGeolocation() {
return SimpleGeolocationProvider::GetInstance()
->IsGeolocationUsageAllowedForSystem();
}
} // namespace
BirchBarContextMenuModel::BirchBarContextMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
Type type)
: ui::SimpleMenuModel(delegate) {
// Show suggestions option is in both expanded and collapsed menu.
AddItem(base::to_underlying(CommandId::kShowSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_SHOW_SUGGESTIONS));
// Expanded menu also has customizing suggestions options.
if (type == Type::kExpandedBarMenu) {
AddSeparator(ui::MenuSeparatorType::NORMAL_SEPARATOR);
if (features::IsCoralFeatureEnabled()) {
AddItem(base::to_underlying(CommandId::kCoralSuggestions),
u"Suggested group");
}
bool enabled = IsWeatherAllowedByGeolocation();
std::u16string weather_label =
enabled ? l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_WEATHER)
: l10n_util::GetStringUTF16(
IDS_ASH_BIRCH_MENU_WEATHER_NOT_AVAILABLE);
AddItem(base::to_underlying(CommandId::kWeatherSuggestions), weather_label);
auto weather_index = GetIndexOfCommandId(
base::to_underlying(CommandId::kWeatherSuggestions));
SetEnabledAt(weather_index.value(), enabled);
if (!enabled) {
SetMinorText(weather_index.value(),
l10n_util::GetStringUTF16(
IDS_ASH_BIRCH_MENU_WEATHER_NOT_AVAILABLE_TOOLTIP));
}
AddItem(base::to_underlying(CommandId::kCalendarSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_CALENDAR));
AddItem(base::to_underlying(CommandId::kDriveSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_DRIVE));
AddItem(base::to_underlying(CommandId::kChromeTabSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_CHROME_BROWSER));
AddItem(base::to_underlying(CommandId::kMediaSuggestions),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_MEDIA));
AddSeparator(ui::MenuSeparatorType::NORMAL_SEPARATOR);
AddItemWithIcon(base::to_underlying(CommandId::kReset),
l10n_util::GetStringUTF16(IDS_ASH_BIRCH_MENU_RESET),
CreateIconForMenuItem(kResetIcon));
}
}
BirchBarContextMenuModel::~BirchBarContextMenuModel() = default;
} // namespace ash