Commit f8b3bfb9 authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

Introducing ExtensionsMenuItemView.

ExtensionsMenuItemView will be a View container to hold a horizontal
extensions menu item (currently the label, pin button, and ... button).

Bug: 985382
Change-Id: I28e637731e506122b797fcb25a544909defd4b59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1749788
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686204}
parent bcafd318
......@@ -2672,6 +2672,8 @@ jumbo_split_static_library("ui") {
"views/extensions/extension_uninstall_dialog_view.cc",
"views/extensions/extensions_menu_button.cc",
"views/extensions/extensions_menu_button.h",
"views/extensions/extensions_menu_item_view.cc",
"views/extensions/extensions_menu_item_view.h",
"views/extensions/extensions_menu_view.cc",
"views/extensions/extensions_menu_view.h",
"views/extensions/extensions_toolbar_button.cc",
......
// Copyright 2019 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/views/extensions/extensions_menu_item_view.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_button.h"
#include "ui/views/layout/fill_layout.h"
ExtensionsMenuItemView::ExtensionsMenuItemView(
Browser* browser,
std::unique_ptr<ToolbarActionViewController> controller) {
extensions_menu_button_ = AddChildView(
std::make_unique<ExtensionsMenuButton>(browser, std::move(controller)));
SetLayoutManager(std::make_unique<views::FillLayout>());
}
ExtensionsMenuItemView::~ExtensionsMenuItemView() = default;
void ExtensionsMenuItemView::UpdatePinButton() {
extensions_menu_button_->UpdatePinButton();
}
views::ButtonController*
ExtensionsMenuItemView::primary_action_button_controller_for_testing() {
return extensions_menu_button_->button_controller();
}
// Copyright 2019 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_VIEWS_EXTENSIONS_EXTENSIONS_MENU_ITEM_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_MENU_ITEM_VIEW_H_
#include <memory>
#include "ui/views/layout/flex_layout.h"
#include "ui/views/view.h"
class Browser;
class ExtensionsMenuButton;
class ToolbarActionViewController;
namespace views {
class ButtonController;
} // namespace views
class ExtensionsMenuItemView : public views::View {
public:
ExtensionsMenuItemView(
Browser* browser,
std::unique_ptr<ToolbarActionViewController> controller);
~ExtensionsMenuItemView() override;
void UpdatePinButton();
views::ButtonController* primary_action_button_controller_for_testing();
private:
ExtensionsMenuButton* extensions_menu_button_;
DISALLOW_COPY_AND_ASSIGN(ExtensionsMenuItemView);
};
#endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSIONS_MENU_ITEM_VIEW_H_
......@@ -11,7 +11,8 @@
#include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_button.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_item_view.h"
#include "chrome/browser/ui/views/hover_button.h"
#include "chrome/grit/generated_resources.h"
#include "components/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkPath.h"
......@@ -19,6 +20,7 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
......@@ -55,7 +57,7 @@ ExtensionsMenuView::ExtensionsMenuView(
ExtensionsMenuView::~ExtensionsMenuView() {
DCHECK_EQ(g_extensions_dialog, this);
g_extensions_dialog = nullptr;
extension_menu_buttons_.clear();
extensions_menu_items_.clear();
}
void ExtensionsMenuView::ButtonPressed(views::Button* sender,
......@@ -109,7 +111,7 @@ void ExtensionsMenuView::Repopulate() {
std::unique_ptr<views::View>
ExtensionsMenuView::CreateExtensionButtonsContainer() {
extension_menu_buttons_.clear();
extensions_menu_items_.clear();
content::WebContents* const web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
......@@ -175,11 +177,12 @@ ExtensionsMenuView::CreateExtensionButtonsContainer() {
});
for (auto& controller : *controller_group) {
std::unique_ptr<ExtensionsMenuButton> extension_button =
std::make_unique<ExtensionsMenuButton>(browser_,
std::move(controller));
extension_menu_buttons_.push_back(extension_button.get());
extension_buttons->AddChildView(std::move(extension_button));
std::unique_ptr<ExtensionsMenuItemView> extensions_menu_item =
std::make_unique<ExtensionsMenuItemView>(browser_,
std::move(controller));
extensions_menu_items_.push_back(extensions_menu_item.get());
extension_buttons->AddChildView(std::move(extensions_menu_item));
}
controller_group->clear();
};
......@@ -231,8 +234,8 @@ void ExtensionsMenuView::OnToolbarModelInitialized() {
}
void ExtensionsMenuView::OnToolbarPinnedActionsChanged() {
for (auto* button : extension_menu_buttons_) {
button->UpdatePinButton();
for (auto* menu_item : extensions_menu_items_) {
menu_item->UpdatePinButton();
}
}
......
......@@ -16,8 +16,8 @@ class Button;
class ImageView;
} // namespace views
class ExtensionsMenuButton;
class ExtensionsContainer;
class ExtensionsMenuItemView;
// This bubble view displays a list of user extensions.
// TODO(pbos): Once there's more functionality in here (getting to
......@@ -63,8 +63,8 @@ class ExtensionsMenuView : public views::ButtonListener,
void OnToolbarModelInitialized() override;
void OnToolbarPinnedActionsChanged() override;
std::vector<ExtensionsMenuButton*> extension_menu_buttons_for_testing() {
return extension_menu_buttons_;
std::vector<ExtensionsMenuItemView*> extensions_menu_items_for_testing() {
return extensions_menu_items_;
}
views::Button* manage_extensions_button_for_testing() {
return manage_extensions_button_for_testing_;
......@@ -79,7 +79,7 @@ class ExtensionsMenuView : public views::ButtonListener,
ToolbarActionsModel* const model_;
ScopedObserver<ToolbarActionsModel, ToolbarActionsModel::Observer>
model_observer_;
std::vector<ExtensionsMenuButton*> extension_menu_buttons_;
std::vector<ExtensionsMenuItemView*> extensions_menu_items_;
views::Button* manage_extensions_button_for_testing_ = nullptr;
......
......@@ -14,6 +14,7 @@
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_button.h"
#include "chrome/browser/ui/views/extensions/extensions_menu_item_view.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
......@@ -57,9 +58,9 @@ class ExtensionsMenuViewBrowserTest : public DialogBrowserTest {
->OnMousePressed(click_event);
}
static std::vector<ExtensionsMenuButton*> GetExtensionMenuButtons() {
static std::vector<ExtensionsMenuItemView*> GetExtensionsMenuItemView() {
return ExtensionsMenuView::GetExtensionsMenuViewForTesting()
->extension_menu_buttons_for_testing();
->extensions_menu_items_for_testing();
}
std::vector<ToolbarActionView*> GetToolbarActionViews() const {
......@@ -81,12 +82,14 @@ class ExtensionsMenuViewBrowserTest : public DialogBrowserTest {
}
void TriggerSingleExtensionButton() {
auto buttons = GetExtensionMenuButtons();
ASSERT_EQ(1u, buttons.size());
auto menu_items = GetExtensionsMenuItemView();
ASSERT_EQ(1u, menu_items.size());
ui::MouseEvent click_event(ui::ET_MOUSE_RELEASED, gfx::Point(),
gfx::Point(), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0);
buttons[0]->button_controller()->OnMouseReleased(click_event);
menu_items[0]
->primary_action_button_controller_for_testing()
->OnMouseReleased(click_event);
}
base::test::ScopedFeatureList scoped_feature_list_;
......@@ -162,13 +165,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionsMenuViewBrowserTest,
}
IN_PROC_BROWSER_TEST_F(ExtensionsMenuViewBrowserTest,
CreatesOneButtonPerExtension) {
CreatesOneMenuItemPerExtension) {
LoadTestExtension("extensions/uitest/long_name");
LoadTestExtension("extensions/uitest/window_open");
ShowUi("");
VerifyUi();
EXPECT_EQ(2u, extensions_.size());
EXPECT_EQ(extensions_.size(), GetExtensionMenuButtons().size());
EXPECT_EQ(extensions_.size(), GetExtensionsMenuItemView().size());
DismissUi();
}
......
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