[cr144] TabContextMenuController introduced
Chromium changes: https://chromium.googlesource.com/chromium/src/+/fc89d1caf10c032d6e15f1e59e9fe1ec0bd7d6cf commit fc89d1caf10c032d6e15f1e59e9fe1ec0bd7d6cf Author: Kunal Daftari <kunaldaftari@google.com> Date: Wed Nov 26 10:15:36 2025 -0800 [Vertical Tabs] Creating TabContextMenuHelper In order for vertical tabs to reuse some of the tab context menu logic, we will move the existing TabContextMenuContents out of BrowserTabStripController. This lets us create a new class called TabContextMenuController which abstracts the functionality. Bug: 462464656 Change-Id: I1fde57af113e7e7197dddeadcd7f83571d278a48 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7170762 Reviewed-by: Charles Meng <charlesmeng@chromium.org> Reviewed-by: David Pennington <dpenning@chromium.org> Commit-Queue: Kunal Daftari <kunaldaftari@google.com> Cr-Commit-Position: refs/heads/main@{#1550607}
This commit is contained in:
@@ -46,6 +46,15 @@ void BraveBrowserTabStripController::SetCustomTitleForTab(
|
||||
->SetCustomTitleForTab(index, title);
|
||||
}
|
||||
|
||||
bool BraveBrowserTabStripController::IsCommandEnabledForTab(
|
||||
TabStripModel::ContextMenuCommand command_id,
|
||||
const Tab* tab) const {
|
||||
const std::optional<int> model_index = tabstrip_->GetModelIndexOf(tab);
|
||||
return model_index.has_value() ? model_->IsContextMenuCommandEnabled(
|
||||
model_index.value(), command_id)
|
||||
: false;
|
||||
}
|
||||
|
||||
void BraveBrowserTabStripController::ShowContextMenuForTab(
|
||||
Tab* tab,
|
||||
const gfx::Point& p,
|
||||
@@ -60,15 +69,10 @@ void BraveBrowserTabStripController::ShowContextMenuForTab(
|
||||
context_menu_contents_->RunMenuAt(p, source_type);
|
||||
}
|
||||
|
||||
void BraveBrowserTabStripController::ExecuteCommandForTab(
|
||||
void BraveBrowserTabStripController::ExecuteContextMenuCommand(
|
||||
int index,
|
||||
TabStripModel::ContextMenuCommand command_id,
|
||||
const Tab* tab) {
|
||||
const std::optional<int> model_index = tabstrip_->GetModelIndexOf(tab);
|
||||
if (!model_index.has_value()) {
|
||||
BrowserTabStripController::ExecuteCommandForTab(command_id, tab);
|
||||
return;
|
||||
}
|
||||
|
||||
int event_flags) {
|
||||
// This tab close customization targets only for split |tab|.
|
||||
// When select close tab from context menu, we want to close
|
||||
// only that split tab instead of both tabs in split.
|
||||
@@ -77,9 +81,9 @@ void BraveBrowserTabStripController::ExecuteCommandForTab(
|
||||
// behavior, apply strictly in some specific situations.
|
||||
// Follow upstream behavior in all other cases.
|
||||
// We can add other specific situations when user want to.
|
||||
const auto split_id = model_->GetSplitForTab(*model_index);
|
||||
const auto split_id = model_->GetSplitForTab(index);
|
||||
if (command_id == TabStripModel::CommandCloseTab && split_id.has_value()) {
|
||||
auto* tab_interface = model_->GetTabAtIndex(*model_index);
|
||||
auto* tab_interface = model_->GetTabAtIndex(index);
|
||||
// If |tab| is split and selection size is 1, it means split tab that
|
||||
// contains |tab| is inactive and the active tab is normal. Close |tab|.
|
||||
if (model_->selection_model().size() == 1) {
|
||||
@@ -97,5 +101,6 @@ void BraveBrowserTabStripController::ExecuteCommandForTab(
|
||||
}
|
||||
}
|
||||
|
||||
BrowserTabStripController::ExecuteCommandForTab(command_id, tab);
|
||||
BrowserTabStripController::ExecuteContextMenuCommand(index, command_id,
|
||||
event_flags);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,16 @@ class BraveBrowserTabStripController : public BrowserTabStripController {
|
||||
void SetCustomTitleForTab(int index,
|
||||
const std::optional<std::u16string>& title);
|
||||
|
||||
bool IsCommandEnabledForTab(TabStripModel::ContextMenuCommand command_id,
|
||||
const Tab* tab) const;
|
||||
|
||||
// BrowserTabStripController overrides:
|
||||
void ShowContextMenuForTab(Tab* tab,
|
||||
const gfx::Point& p,
|
||||
ui::mojom::MenuSourceType source_type) override;
|
||||
void ExecuteCommandForTab(TabStripModel::ContextMenuCommand command_id,
|
||||
const Tab* tab) override;
|
||||
void ExecuteContextMenuCommand(int index,
|
||||
TabStripModel::ContextMenuCommand command_id,
|
||||
int event_flags) override;
|
||||
|
||||
private:
|
||||
// If non-NULL it means we're showing a menu for the tab.
|
||||
|
||||
@@ -153,8 +153,9 @@ void BraveTabContextMenuContents::ExecuteCommand(int command_id,
|
||||
|
||||
// Executing the command destroys |this|, and can also end up destroying
|
||||
// |controller_|. So stop the highlights before executing the command.
|
||||
controller_->ExecuteCommandForTab(
|
||||
static_cast<TabStripModel::ContextMenuCommand>(command_id), tab_);
|
||||
controller_->ExecuteContextMenuCommand(
|
||||
tab_index_, static_cast<TabStripModel::ContextMenuCommand>(command_id),
|
||||
event_flags);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(ENABLE_CONTAINERS)
|
||||
|
||||
@@ -6,12 +6,18 @@
|
||||
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
|
||||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
|
||||
|
||||
#define ExecuteCommandForTab(...) \
|
||||
virtual ExecuteCommandForTab(__VA_ARGS__); \
|
||||
// To prevent overriding TabStripModel's ExecuteContextMenuCommand
|
||||
// with below macro. It caused crash when executing
|
||||
// TabStripModel::ExecuteContextMenuCommand() from
|
||||
// BrowserTabStripController::ExecuteContextMenuCommand().
|
||||
#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
||||
|
||||
#define ExecuteContextMenuCommand(...) \
|
||||
virtual ExecuteContextMenuCommand(__VA_ARGS__); \
|
||||
friend class BraveBrowserTabStripController
|
||||
|
||||
#include <chrome/browser/ui/views/tabs/browser_tab_strip_controller.h> // IWYU pragma: export
|
||||
|
||||
#undef ExecuteCommandForTab
|
||||
#undef ExecuteContextMenuCommand
|
||||
|
||||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TABS_BROWSER_TAB_STRIP_CONTROLLER_H_
|
||||
|
||||
Reference in New Issue
Block a user