0

oak birch: add context menu in overview

This cl implemented the birch bar context menu showing when right
click in Overview.

When it is in clamshell Overview mode without a split screen
session, we make the RootWindowController to show the birch bar
context menu instead of the shelf context menu.

BUG: b:326256018
Change-Id: Ia2c8aee03b4375ab69519692f11d9b170e7de801
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362997
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Commit-Queue: Xiaodan Zhu <zxdan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1271818}
This commit is contained in:
Xiaodan Zhu
2024-03-12 21:09:13 +00:00
committed by Chromium LUCI CQ
parent 79ce673b35
commit 56ae1e1022
2 changed files with 115 additions and 70 deletions

@ -61,8 +61,12 @@
#include "ash/wm/lock_layout_manager.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/overlay_layout_manager.h"
#include "ash/wm/overview/birch/birch_bar_context_menu_model.h"
#include "ash/wm/overview/birch/birch_bar_menu_model_adapter.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/overview/overview_grid.h"
#include "ash/wm/overview/overview_session.h"
#include "ash/wm/overview/overview_utils.h"
#include "ash/wm/root_window_layout_manager.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_overview_session.h"
@ -425,13 +429,13 @@ class RootWindowTargeter : public aura::WindowTargeter {
ui::EventType last_mouse_event_type_ = ui::ET_UNKNOWN;
};
class RootWindowMenuModelAdapter : public AppMenuModelAdapter {
class ShelfMenuModelAdapter : public AppMenuModelAdapter {
public:
RootWindowMenuModelAdapter(std::unique_ptr<ui::SimpleMenuModel> model,
views::Widget* widget_owner,
ui::MenuSourceType source_type,
base::OnceClosure on_menu_closed_callback,
bool is_tablet_mode)
ShelfMenuModelAdapter(std::unique_ptr<ui::SimpleMenuModel> model,
views::Widget* widget_owner,
ui::MenuSourceType source_type,
base::OnceClosure on_menu_closed_callback,
bool is_tablet_mode)
: AppMenuModelAdapter(std::string(),
std::move(model),
widget_owner,
@ -439,11 +443,10 @@ class RootWindowMenuModelAdapter : public AppMenuModelAdapter {
std::move(on_menu_closed_callback),
is_tablet_mode) {}
RootWindowMenuModelAdapter(const RootWindowMenuModelAdapter&) = delete;
RootWindowMenuModelAdapter& operator=(const RootWindowMenuModelAdapter&) =
delete;
ShelfMenuModelAdapter(const ShelfMenuModelAdapter&) = delete;
ShelfMenuModelAdapter& operator=(const ShelfMenuModelAdapter&) = delete;
~RootWindowMenuModelAdapter() override = default;
~ShelfMenuModelAdapter() override = default;
private:
// AppMenuModelAdapter overrides:
@ -842,66 +845,17 @@ void RootWindowController::SetTouchAccessibilityAnchorPoint(
void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
ui::MenuSourceType source_type) {
const int64_t display_id = display::Screen::GetScreen()
->GetDisplayNearestWindow(GetRootWindow())
.id();
const bool tablet_mode = display::Screen::GetScreen()->InTabletMode();
root_window_menu_model_adapter_ =
std::make_unique<RootWindowMenuModelAdapter>(
std::make_unique<ShelfContextMenuModel>(nullptr, display_id,
/*menu_in_shelf=*/false),
wallpaper_widget_controller()->GetWidget(), source_type,
base::BindOnce(&RootWindowController::OnMenuClosed,
base::Unretained(this)),
tablet_mode);
// Appends the apps sort options in ShelfContextMenuModel in tablet mode. Note
// that the launcher UI is fullscreen in tablet mode, so the whole root window
// can be perceived by users to be part of the launcher.
auto* const app_list_controller = Shell::Get()->app_list_controller();
if (tablet_mode && app_list_controller->IsVisible(display_id) &&
app_list_controller->GetCurrentAppListPage() ==
AppListState::kStateApps) {
ui::SimpleMenuModel* menu_model = root_window_menu_model_adapter_->model();
sort_apps_submenu_ = std::make_unique<ui::SimpleMenuModel>(
static_cast<ShelfContextMenuModel*>(menu_model));
sort_apps_submenu_->AddItemWithIcon(
REORDER_BY_NAME_ALPHABETICAL,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_BY_NAME),
ui::ImageModel::FromVectorIcon(kSortAlphabeticalIcon,
ui::kColorAshSystemUIMenuIcon));
sort_apps_submenu_->AddItemWithIcon(
REORDER_BY_COLOR,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_BY_COLOR),
ui::ImageModel::FromVectorIcon(kSortColorIcon,
ui::kColorAshSystemUIMenuIcon));
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
menu_model->AddSubMenuWithIcon(
REORDER_SUBMENU,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_TITLE),
sort_apps_submenu_.get(),
ui::ImageModel::FromVectorIcon(kReorderIcon,
ui::kColorAshSystemUIMenuIcon));
// Append the "Show all suggestions" / "Hide all suggestions" item.
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
if (app_list_controller->ShouldHideContinueSection()) {
menu_model->AddItemWithIcon(
ShelfContextMenuModel::MENU_SHOW_CONTINUE_SECTION,
l10n_util::GetStringUTF16(IDS_ASH_LAUNCHER_SHOW_CONTINUE_SECTION),
ui::ImageModel::FromVectorIcon(kLauncherShowContinueSectionIcon,
ui::kColorAshSystemUIMenuIcon));
} else {
menu_model->AddItemWithIcon(
ShelfContextMenuModel::MENU_HIDE_CONTINUE_SECTION,
l10n_util::GetStringUTF16(IDS_ASH_LAUNCHER_HIDE_CONTINUE_SECTION),
ui::ImageModel::FromVectorIcon(kLauncherHideContinueSectionIcon,
ui::kColorAshSystemUIMenuIcon));
}
// Show birch bar context menu in clamshell mode Overview without a partial
// split screen.
// TODO(http://325963519): remove the tablet mode restriction when tablet mode
// birch bar is implemented.
if (features::IsForestFeatureEnabled() &&
OverviewController::Get()->InOverviewSession() &&
!display::Screen::GetScreen()->InTabletMode() &&
!split_view_overview_session_) {
root_window_menu_model_adapter_ = BuildBirchMenuModelAdapter(source_type);
} else {
root_window_menu_model_adapter_ = BuildShelfMenuModelAdapter(source_type);
}
root_window_menu_model_adapter_->Run(
@ -1485,6 +1439,89 @@ RootWindowController::GetAccessibilityPanelLayoutManager() const {
return layout_manager;
}
std::unique_ptr<AppMenuModelAdapter>
RootWindowController::BuildBirchMenuModelAdapter(
ui::MenuSourceType source_type) {
const bool is_birch_bar_showing = GetOverviewSession()
->GetGridWithRootWindow(GetRootWindow())
->IsBirchBarShowing();
return std::make_unique<BirchBarMenuModelAdapter>(
std::make_unique<BirchBarContextMenuModel>(
nullptr, is_birch_bar_showing
? BirchBarContextMenuModel::Type::kExpandedBarMenu
: BirchBarContextMenuModel::Type::kCollapsedBarMenu),
wallpaper_widget_controller()->GetWidget(), source_type,
base::BindOnce(&RootWindowController::OnMenuClosed,
base::Unretained(this)),
display::Screen::GetScreen()->InTabletMode());
}
std::unique_ptr<AppMenuModelAdapter>
RootWindowController::BuildShelfMenuModelAdapter(
ui::MenuSourceType source_type) {
const bool tablet_mode = display::Screen::GetScreen()->InTabletMode();
const int64_t display_id = display::Screen::GetScreen()
->GetDisplayNearestWindow(GetRootWindow())
.id();
auto shelf_menu_model_adapter = std::make_unique<ShelfMenuModelAdapter>(
std::make_unique<ShelfContextMenuModel>(nullptr, display_id,
/*menu_in_shelf=*/false),
wallpaper_widget_controller()->GetWidget(), source_type,
base::BindOnce(&RootWindowController::OnMenuClosed,
base::Unretained(this)),
tablet_mode);
// Appends the apps sort options in ShelfContextMenuModel in tablet mode.
// Note that the launcher UI is fullscreen in tablet mode, so the whole root
// window can be perceived by users to be part of the launcher.
auto* const app_list_controller = Shell::Get()->app_list_controller();
if (tablet_mode && app_list_controller->IsVisible(display_id) &&
app_list_controller->GetCurrentAppListPage() ==
AppListState::kStateApps) {
ui::SimpleMenuModel* menu_model = shelf_menu_model_adapter->model();
sort_apps_submenu_ = std::make_unique<ui::SimpleMenuModel>(
static_cast<ShelfContextMenuModel*>(menu_model));
sort_apps_submenu_->AddItemWithIcon(
REORDER_BY_NAME_ALPHABETICAL,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_BY_NAME),
ui::ImageModel::FromVectorIcon(kSortAlphabeticalIcon,
ui::kColorAshSystemUIMenuIcon));
sort_apps_submenu_->AddItemWithIcon(
REORDER_BY_COLOR,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_BY_COLOR),
ui::ImageModel::FromVectorIcon(kSortColorIcon,
ui::kColorAshSystemUIMenuIcon));
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
menu_model->AddSubMenuWithIcon(
REORDER_SUBMENU,
l10n_util::GetStringUTF16(
IDS_ASH_LAUNCHER_APPS_GRID_CONTEXT_MENU_REORDER_TITLE),
sort_apps_submenu_.get(),
ui::ImageModel::FromVectorIcon(kReorderIcon,
ui::kColorAshSystemUIMenuIcon));
// Append the "Show all suggestions" / "Hide all suggestions" item.
menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
if (app_list_controller->ShouldHideContinueSection()) {
menu_model->AddItemWithIcon(
ShelfContextMenuModel::MENU_SHOW_CONTINUE_SECTION,
l10n_util::GetStringUTF16(IDS_ASH_LAUNCHER_SHOW_CONTINUE_SECTION),
ui::ImageModel::FromVectorIcon(kLauncherShowContinueSectionIcon,
ui::kColorAshSystemUIMenuIcon));
} else {
menu_model->AddItemWithIcon(
ShelfContextMenuModel::MENU_HIDE_CONTINUE_SECTION,
l10n_util::GetStringUTF16(IDS_ASH_LAUNCHER_HIDE_CONTINUE_SECTION),
ui::ImageModel::FromVectorIcon(kLauncherHideContinueSectionIcon,
ui::kColorAshSystemUIMenuIcon));
}
}
return shelf_menu_model_adapter;
}
void RootWindowController::OnMenuClosed() {
root_window_menu_model_adapter_.reset();
sort_apps_submenu_.reset();

@ -300,6 +300,14 @@ class ASH_EXPORT RootWindowController {
const char* name,
aura::Window* parent);
// Build a menu model adapter to configure birch bar in Overview.
std::unique_ptr<AppMenuModelAdapter> BuildBirchMenuModelAdapter(
ui::MenuSourceType source_type);
// Build a menu model adapter to configure shelf.
std::unique_ptr<AppMenuModelAdapter> BuildShelfMenuModelAdapter(
ui::MenuSourceType source_type);
// Callback for MenuRunner.
void OnMenuClosed();