Revert "Make CustomViewFactory final"
This reverts commit 5a802d7f76
.
Reason for revert: Looks like this broke compile: https://ci.chromium.org/ui/p/chromium/builders/ci/Win%20x64%20Builder%20(dbg)/137893/overview
Original change's description:
> Make CustomViewFactory final
>
> This makes BubbleDialogModelHost::CustomViewFactory final by instead of
> providing an interface using a callback and a FieldType in the
> constructor.
>
> This makes calling code simpler.
>
> Bug: 1325460
> Change-Id: I0a7fe3327c339dff7a62771489b4cd83d2722a35
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3651977
> Commit-Queue: Peter Boström <pbos@chromium.org>
> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1004770}
Bug: 1325460
Change-Id: I8e7250d41315bda4a63eeaaa252c1a9c71a9ed97
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3654235
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Scott Little <sclittle@chromium.org>
Commit-Queue: Scott Little <sclittle@chromium.org>
Owners-Override: Scott Little <sclittle@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1004793}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c89d26fe2b
commit
0a34f1a4c9
chrome/browser/ui/views
ui/views/bubble
@ -3,7 +3,6 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "chrome/browser/ui/views/extensions/extensions_request_access_button_hover_card.h"
|
||||
#include <memory>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/strings/strcat.h"
|
||||
@ -34,31 +33,38 @@ ui::ImageModel GetIcon(ToolbarActionViewController* action,
|
||||
.AsImageSkia());
|
||||
}
|
||||
|
||||
std::unique_ptr<views::BubbleDialogModelHost::CustomViewFactory>
|
||||
CreateExtensionItemFactory(std::u16string name, ui::ImageModel icon) {
|
||||
return std::make_unique<views::BubbleDialogModelHost::CustomViewFactory>(
|
||||
base::BindOnce(
|
||||
[](std::u16string name,
|
||||
ui::ImageModel icon) -> std::unique_ptr<views::View> {
|
||||
const gfx::Insets content_insets =
|
||||
ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
|
||||
views::DialogContentType::kText,
|
||||
views::DialogContentType::kText);
|
||||
class ExtensionItemFactory
|
||||
: public views::BubbleDialogModelHost::CustomViewFactory {
|
||||
public:
|
||||
ExtensionItemFactory(const std::u16string& name, const ui::ImageModel& icon)
|
||||
: name_(std::move(name)), icon_(icon) {}
|
||||
~ExtensionItemFactory() override = default;
|
||||
|
||||
return views::Builder<views::FlexLayoutView>()
|
||||
.SetOrientation(views::LayoutOrientation::kHorizontal)
|
||||
.SetMainAxisAlignment(views::LayoutAlignment::kStart)
|
||||
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
|
||||
.SetBorder(views::CreateEmptyBorder(gfx::Insets::TLBR(
|
||||
0, content_insets.left(), 0, content_insets.right())))
|
||||
.AddChildren(
|
||||
views::Builder<views::ImageView>().SetImage(icon),
|
||||
views::Builder<views::Label>().SetText(std::move(name)))
|
||||
.Build();
|
||||
},
|
||||
std::move(name), std::move(icon)),
|
||||
views::BubbleDialogModelHost::FieldType::kMenuItem);
|
||||
}
|
||||
// views::BubbleDialogModelHost::CustomViewFactory:
|
||||
std::unique_ptr<views::View> CreateView() override {
|
||||
const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
|
||||
const gfx::Insets content_insets = provider->GetDialogInsetsForContentType(
|
||||
views::DialogContentType::kText, views::DialogContentType::kText);
|
||||
|
||||
return views::Builder<views::FlexLayoutView>()
|
||||
.SetOrientation(views::LayoutOrientation::kHorizontal)
|
||||
.SetMainAxisAlignment(views::LayoutAlignment::kStart)
|
||||
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter)
|
||||
.SetBorder(views::CreateEmptyBorder(gfx::Insets::TLBR(
|
||||
0, content_insets.left(), 0, content_insets.right())))
|
||||
.AddChildren(views::Builder<views::ImageView>().SetImage(icon_),
|
||||
views::Builder<views::Label>().SetText(name_))
|
||||
.Build();
|
||||
}
|
||||
|
||||
views::BubbleDialogModelHost::FieldType GetFieldType() const override {
|
||||
return views::BubbleDialogModelHost::FieldType::kMenuItem;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::u16string name_;
|
||||
const ui::ImageModel icon_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -92,7 +98,7 @@ void ExtensionsRequestAccessButtonHoverCard::ShowBubble(
|
||||
IDS_EXTENSIONS_REQUEST_ACCESS_BUTTON_TOOLTIP_MULTIPLE_EXTENSIONS,
|
||||
url)));
|
||||
for (auto* action : actions) {
|
||||
dialog_builder.AddCustomField(CreateExtensionItemFactory(
|
||||
dialog_builder.AddCustomField(std::make_unique<ExtensionItemFactory>(
|
||||
action->GetActionName(), GetIcon(action, web_contents)));
|
||||
}
|
||||
}
|
||||
|
@ -98,20 +98,33 @@ std::unique_ptr<views::LabelButton> CreateMenuItem(
|
||||
return button;
|
||||
}
|
||||
|
||||
std::unique_ptr<views::BubbleDialogModelHost::CustomViewFactory>
|
||||
CreateMenuItemFactory(std::u16string name,
|
||||
views::Button::PressedCallback callback,
|
||||
const gfx::VectorIcon* icon) {
|
||||
return std::make_unique<views::BubbleDialogModelHost::CustomViewFactory>(
|
||||
base::BindOnce(
|
||||
[](std::u16string name, views::Button::PressedCallback callback,
|
||||
const gfx::VectorIcon* icon) -> std::unique_ptr<views::View> {
|
||||
return CreateMenuItem(-1, std::move(name), std::move(callback),
|
||||
icon);
|
||||
},
|
||||
std::move(name), std::move(callback), icon),
|
||||
views::BubbleDialogModelHost::FieldType::kMenuItem);
|
||||
}
|
||||
class MenuItemFactory : public views::BubbleDialogModelHost::CustomViewFactory {
|
||||
public:
|
||||
MenuItemFactory(const std::u16string& name,
|
||||
views::Button::PressedCallback callback,
|
||||
const gfx::VectorIcon* icon = nullptr)
|
||||
: name_(std::move(name)), callback_(std::move(callback)), icon_(icon) {}
|
||||
~MenuItemFactory() override = default;
|
||||
|
||||
// views::BubbleDialogModelHost::CustomViewFactory:
|
||||
std::unique_ptr<views::View> CreateView() override {
|
||||
// TODO(pbos): See if dialog_model()->host()->Close(); can be handled by the
|
||||
// menu item itself (after calling callback_). All menu-item actions close
|
||||
// the dialog. We should be able to chain some calls if we have access to
|
||||
// DialogModelDelegate here.
|
||||
|
||||
return CreateMenuItem(-1, name_, callback_, icon_);
|
||||
}
|
||||
|
||||
views::BubbleDialogModelHost::FieldType GetFieldType() const override {
|
||||
return views::BubbleDialogModelHost::FieldType::kMenuItem;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::u16string name_;
|
||||
const views::Button::PressedCallback callback_;
|
||||
const raw_ptr<const gfx::VectorIcon> icon_;
|
||||
};
|
||||
|
||||
class TabGroupEditorBubbleDelegate : public ui::DialogModelDelegate {
|
||||
public:
|
||||
@ -214,7 +227,7 @@ views::Widget* TabGroupEditorBubbleView::Show(
|
||||
dialog_builder.OverrideShowCloseButton(false)
|
||||
.AddSeparator()
|
||||
.AddCustomField(
|
||||
CreateMenuItemFactory(
|
||||
std::make_unique<MenuItemFactory>(
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_TAB_GROUP_HEADER_CXMENU_NEW_TAB_IN_GROUP),
|
||||
base::BindRepeating(
|
||||
@ -223,7 +236,7 @@ views::Widget* TabGroupEditorBubbleView::Show(
|
||||
&kNewTabInGroupIcon),
|
||||
TAB_GROUP_HEADER_CXMENU_NEW_TAB_IN_GROUP)
|
||||
.AddCustomField(
|
||||
CreateMenuItemFactory(
|
||||
std::make_unique<MenuItemFactory>(
|
||||
l10n_util::GetStringUTF16(IDS_TAB_GROUP_HEADER_CXMENU_UNGROUP),
|
||||
base::BindRepeating(
|
||||
&TabGroupEditorBubbleDelegate::UngroupPressed,
|
||||
@ -231,7 +244,7 @@ views::Widget* TabGroupEditorBubbleView::Show(
|
||||
&kUngroupIcon),
|
||||
TAB_GROUP_HEADER_CXMENU_UNGROUP)
|
||||
.AddCustomField(
|
||||
CreateMenuItemFactory(
|
||||
std::make_unique<MenuItemFactory>(
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_TAB_GROUP_HEADER_CXMENU_CLOSE_GROUP),
|
||||
base::BindRepeating(
|
||||
@ -240,7 +253,7 @@ views::Widget* TabGroupEditorBubbleView::Show(
|
||||
&kCloseGroupIcon),
|
||||
TAB_GROUP_HEADER_CXMENU_CLOSE_GROUP)
|
||||
.AddCustomField(
|
||||
CreateMenuItemFactory(
|
||||
std::make_unique<MenuItemFactory>(
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_TAB_GROUP_HEADER_CXMENU_MOVE_GROUP_TO_NEW_WINDOW),
|
||||
base::BindRepeating(
|
||||
|
@ -59,7 +59,7 @@ BubbleDialogModelHost::FieldType GetFieldTypeForField(
|
||||
case ui::DialogModelField::kCustom:
|
||||
return static_cast<BubbleDialogModelHost::CustomViewFactory*>(
|
||||
field->AsCustomField(pass_key)->factory(pass_key))
|
||||
->field_type();
|
||||
->GetFieldType();
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,18 +150,6 @@ END_METADATA
|
||||
|
||||
} // namespace
|
||||
|
||||
BubbleDialogModelHost::CustomViewFactory::CustomViewFactory(
|
||||
base::OnceCallback<std::unique_ptr<View>()> callback,
|
||||
FieldType field_type)
|
||||
: callback_(std::move(callback)), field_type_(field_type) {}
|
||||
|
||||
BubbleDialogModelHost::CustomViewFactory::~CustomViewFactory() = default;
|
||||
|
||||
std::unique_ptr<View> BubbleDialogModelHost::CustomViewFactory::CreateView() {
|
||||
DCHECK(callback_);
|
||||
return std::move(callback_).Run();
|
||||
}
|
||||
|
||||
// TODO(pbos): Migrate most code that calls contents_view_->(some View method)
|
||||
// into this class. This was done in steps to limit the size of the diff.
|
||||
class BubbleDialogModelHost::ContentsView : public View {
|
||||
|
@ -34,21 +34,14 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegate,
|
||||
|
||||
// TODO(pbos): Reconsider whether this should be generic outside of
|
||||
// BubbleDialogModelHost.
|
||||
// TODO(pbos): Consider making this appropriate for all fields (not just
|
||||
// custom ones). If so rename this ViewFactory (not CustomViewFactory).
|
||||
// Factory for adding bespoke Views to BubbleDialogModelHost.
|
||||
class CustomViewFactory final : public ui::DialogModelCustomField::Factory {
|
||||
// TODO(pbos): Consider making this interface appropriate for all fields (not
|
||||
// just custom ones). If so rename this ViewFactory (not CustomViewFactory).
|
||||
// Interface for adding custom views to a DialogModel. This factory interface
|
||||
// allows constructing views to be hosted in BubbleDialogModelHost.
|
||||
class CustomViewFactory : public ui::DialogModelCustomField::Factory {
|
||||
public:
|
||||
CustomViewFactory(base::OnceCallback<std::unique_ptr<View>()> callback,
|
||||
FieldType field_type);
|
||||
~CustomViewFactory() final;
|
||||
|
||||
std::unique_ptr<View> CreateView();
|
||||
FieldType field_type() const { return field_type_; }
|
||||
|
||||
private:
|
||||
base::OnceCallback<std::unique_ptr<View>()> callback_;
|
||||
const FieldType field_type_;
|
||||
virtual std::unique_ptr<View> CreateView() = 0;
|
||||
virtual FieldType GetFieldType() const = 0;
|
||||
};
|
||||
|
||||
// Constructs a BubbleDialogModelHost, which for most purposes is to used as a
|
||||
|
Reference in New Issue
Block a user