Commit 510a2977 authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

crostini: remove irrelevant items from terminal's tab menu

Some of the default tab menu items (e.g. reload, move to existing
window) does not make sense or work well with the terminal SWA, so we
want to remove them.

This CL adds GetTabMenuModelFactory() to AppBrowserController to allow
an app to specify the tab menu model that it wants.

Before screenshot: https://bugs.chromium.org/p/chromium/issues/attachment?aid=438083&signed_aid=ucqPxHzsGWc98617EvvGUQ==&inline=1
After Screenshot: https://bugs.chromium.org/p/chromium/issues/attachment?aid=438084&signed_aid=R3gAlYCzETMUFNVq8NvAxw==&inline=1

Bug: 1060861
Change-Id: If1c318663690f2db637c31330299f95fb2b06ecd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105676Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Jason Lin <lxj@google.com>
Cr-Commit-Position: refs/heads/master@{#751913}
parent 184b648e
......@@ -1200,6 +1200,8 @@ jumbo_static_library("ui") {
"tabs/tab_group_model.h",
"tabs/tab_menu_model.cc",
"tabs/tab_menu_model.h",
"tabs/tab_menu_model_factory.cc",
"tabs/tab_menu_model_factory.h",
"tabs/tab_network_state.cc",
"tabs/tab_network_state.h",
"tabs/tab_renderer_data.cc",
......
// Copyright 2020 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 "chrome/browser/ui/tabs/tab_menu_model_factory.h"
#include "chrome/browser/ui/tabs/tab_menu_model.h"
std::unique_ptr<ui::SimpleMenuModel> TabMenuModelFactory::Create(
ui::SimpleMenuModel::Delegate* delegate,
TabStripModel* tab_strip,
int index) {
return std::make_unique<TabMenuModel>(delegate, tab_strip, index);
}
// Copyright 2020 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 CHROME_BROWSER_UI_TABS_TAB_MENU_MODEL_FACTORY_H_
#define CHROME_BROWSER_UI_TABS_TAB_MENU_MODEL_FACTORY_H_
#include <memory>
#include "ui/base/models/simple_menu_model.h"
class TabStripModel;
// A factory to create menu models for tab menu.
class TabMenuModelFactory {
public:
TabMenuModelFactory() = default;
TabMenuModelFactory(const TabMenuModelFactory&) = delete;
virtual ~TabMenuModelFactory() = default;
TabMenuModelFactory& operator=(const TabMenuModelFactory&) = delete;
virtual std::unique_ptr<ui::SimpleMenuModel> Create(
ui::SimpleMenuModel::Delegate* delegate,
TabStripModel* tab_strip,
int index);
};
#endif // CHROME_BROWSER_UI_TABS_TAB_MENU_MODEL_FACTORY_H_
......@@ -500,9 +500,14 @@ BrowserView::BrowserView(std::unique_ptr<Browser> browser)
tab_strip_region_view_ =
top_container_->AddChildView(std::make_unique<TabStripRegionView>());
std::unique_ptr<TabMenuModelFactory> tab_menu_model_factory;
if (browser_->app_controller()) {
tab_menu_model_factory =
browser_->app_controller()->GetTabMenuModelFactory();
}
// TabStrip takes ownership of the controller.
auto tabstrip_controller = std::make_unique<BrowserTabStripController>(
browser_->tab_strip_model(), this);
browser_->tab_strip_model(), this, std::move(tab_menu_model_factory));
BrowserTabStripController* tabstrip_controller_ptr =
tabstrip_controller.get();
tabstrip_ = tab_strip_region_view_->AddChildView(std::make_unique<TabStrip>(
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h"
#include <limits>
#include <memory>
#include <utility>
#include "base/auto_reset.h"
......@@ -57,6 +58,7 @@
#include "ipc/ipc_message.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/base/models/list_selection_model.h"
#include "ui/base/models/menu_model.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h"
#include "ui/views/controls/menu/menu_runner.h"
......@@ -105,7 +107,7 @@ class BrowserTabStripController::TabContextMenuContents
public:
TabContextMenuContents(Tab* tab, BrowserTabStripController* controller)
: tab_(tab), controller_(controller) {
model_ = std::make_unique<TabMenuModel>(
model_ = controller_->menu_model_factory_->Create(
this, controller->model_, controller->tabstrip_->GetModelIndexOf(tab));
menu_runner_ = std::make_unique<views::MenuRunner>(
model_.get(),
......@@ -145,7 +147,7 @@ class BrowserTabStripController::TabContextMenuContents
}
private:
std::unique_ptr<TabMenuModel> model_;
std::unique_ptr<ui::SimpleMenuModel> model_;
std::unique_ptr<views::MenuRunner> menu_runner_;
// The tab we're showing a menu for.
......@@ -160,12 +162,19 @@ class BrowserTabStripController::TabContextMenuContents
////////////////////////////////////////////////////////////////////////////////
// BrowserTabStripController, public:
BrowserTabStripController::BrowserTabStripController(TabStripModel* model,
BrowserView* browser_view)
BrowserTabStripController::BrowserTabStripController(
TabStripModel* model,
BrowserView* browser_view,
std::unique_ptr<TabMenuModelFactory> menu_model_factory_override)
: model_(model),
tabstrip_(nullptr),
browser_view_(browser_view),
hover_tab_selector_(model) {
hover_tab_selector_(model),
menu_model_factory_(std::move(menu_model_factory_override)) {
if (!menu_model_factory_) {
// Use the default one.
menu_model_factory_ = std::make_unique<TabMenuModelFactory>();
}
model_->SetTabStripUI(this);
local_pref_registrar_.Init(g_browser_process->local_state());
......
......@@ -8,15 +8,18 @@
#include <memory>
#include <vector>
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/browser/ui/tabs/hover_tab_selector.h"
#include "chrome/browser/ui/tabs/tab_menu_model_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/tab_groups/tab_group_color.h"
#include "ui/base/models/simple_menu_model.h"
class Browser;
class BrowserNonClientFrameView;
......@@ -37,7 +40,10 @@ class ListSelectionModel;
class BrowserTabStripController : public TabStripController,
public TabStripModelObserver {
public:
BrowserTabStripController(TabStripModel* model, BrowserView* browser_view);
BrowserTabStripController(TabStripModel* model,
BrowserView* browser_view,
std::unique_ptr<TabMenuModelFactory>
menu_model_factory_override = nullptr);
~BrowserTabStripController() override;
void InitFromModel(TabStrip* tabstrip);
......@@ -158,6 +164,8 @@ class BrowserTabStripController : public TabStripController,
PrefChangeRegistrar local_pref_registrar_;
std::unique_ptr<TabMenuModelFactory> menu_model_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserTabStripController);
};
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/strings/string_piece.h"
#include "chrome/browser/installable/installable_manager.h"
......@@ -16,6 +17,7 @@
#include "chrome/browser/ui/browser_window_state.h"
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "chrome/browser/ui/manifest_web_app_browser_controller.h"
#include "chrome/browser/ui/tabs/tab_menu_model_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h"
#include "chrome/browser/ui/web_applications/web_app_browser_controller.h"
......@@ -25,6 +27,7 @@
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/themes/autogenerated_theme_util.h"
#include "chrome/grit/generated_resources.h"
#include "components/security_state/core/security_state.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/browser/navigation_controller.h"
......@@ -36,13 +39,46 @@
#include "extensions/common/constants.h"
#include "net/base/escape.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "url/gurl.h"
namespace {
class TerminalTabMenuModel : public ui::SimpleMenuModel {
public:
explicit TerminalTabMenuModel(ui::SimpleMenuModel::Delegate* delegate)
: ui::SimpleMenuModel(delegate) {
AddItemWithStringId(TabStripModel::CommandNewTabToRight,
IDS_TAB_CXMENU_NEWTABTORIGHT);
AddSeparator(ui::NORMAL_SEPARATOR);
AddItemWithStringId(TabStripModel::CommandCloseTab,
IDS_TAB_CXMENU_CLOSETAB);
AddItemWithStringId(TabStripModel::CommandCloseOtherTabs,
IDS_TAB_CXMENU_CLOSEOTHERTABS);
AddItemWithStringId(TabStripModel::CommandCloseTabsToRight,
IDS_TAB_CXMENU_CLOSETABSTORIGHT);
}
};
class TerminalTabMenuModelFactory : public TabMenuModelFactory {
public:
std::unique_ptr<ui::SimpleMenuModel> Create(
ui::SimpleMenuModel::Delegate* delegate,
TabStripModel*,
int) override {
return std::make_unique<TerminalTabMenuModel>(delegate);
}
};
} // namespace
namespace web_app {
namespace {
......@@ -246,6 +282,15 @@ bool AppBrowserController::IsInstalled() const {
return false;
}
std::unique_ptr<TabMenuModelFactory>
AppBrowserController::GetTabMenuModelFactory() const {
if (system_app_type_ == SystemAppType::TERMINAL) {
// TODO(crbug.com/1061822) move terminal specific code out.
return std::make_unique<TerminalTabMenuModelFactory>();
}
return nullptr;
}
bool AppBrowserController::IsHostedApp() const {
return false;
}
......
......@@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
......@@ -16,12 +17,16 @@
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
class Browser;
class BrowserThemePack;
class CustomThemeSupplier;
class TabMenuModelFactory;
namespace gfx {
class ImageSkia;
class Rect;
} // namespace gfx
namespace web_app {
......@@ -117,6 +122,8 @@ class AppBrowserController : public TabStripModelObserver,
// the lifetime of HostedAppBrowserController).
virtual bool IsInstalled() const;
virtual std::unique_ptr<TabMenuModelFactory> GetTabMenuModelFactory() const;
// Updates the custom tab bar's visibility based on whether it should be
// currently visible or not. If |animate| is set, the change will be
// animated.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment