Commit dcc58ae0 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbui: ExtensionInstalledBubble de-BubbleUi, part 1

Here is the overall plan of attack here:
Currently, there are three key classes:

* ExtensionInstalledBubble is a BubbleDelegate (bad)
* ExtensionInstalledBubbleUi is a BubbleUi (bad)
* ExtensionInstalledBubbleView is a BubbleDialogDelegateView (good)

The ideal end state is that all clients of ExtensionInstalledBubble
directly use ExtensionInstalledBubbleView instead, and then the former
two classes are deleted.

To get to that state, we:
1) Iteratively break every dependency from EIBV to EIB or EIBU, so that
   eventually an EIBV can be constructed without an EIB or EIBU - we do
   this by passing data from the EIB or EIBU into the EIVB's constructor
   directly so that it has it without asking the EIB.
2) Once EIBV does not depend on EIB or EIBU, make EIBV public (promote
   it into a header file), then have ShowExtensionInstalledBubble
   (the only non-test entry point to EIB) call EIBV directly
3) Delete EIB & EIBU :)

Bug: 496955
Change-Id: Ic013bf89badf507d13599ff92ebc50b6afa50f58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954739Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722647}
parent 868344ac
...@@ -58,8 +58,6 @@ using extensions::Extension; ...@@ -58,8 +58,6 @@ using extensions::Extension;
namespace { namespace {
const int kExtensionInstalledIconSize = 43;
const int kRightColumnWidth = 285; const int kRightColumnWidth = 285;
views::Label* CreateLabel(const base::string16& text) { views::Label* CreateLabel(const base::string16& text) {
...@@ -132,6 +130,19 @@ std::unique_ptr<views::View> CreateSigninPromoView( ...@@ -132,6 +130,19 @@ std::unique_ptr<views::View> CreateSigninPromoView(
#endif #endif
} }
gfx::ImageSkia MakeIconFromBitmap(const SkBitmap& bitmap) {
constexpr int kMaxIconSize = 43;
// Scale down to 43x43, but allow smaller icons (don't scale up).
gfx::Size size(bitmap.width(), bitmap.height());
if (size.width() > kMaxIconSize || size.height() > kMaxIconSize)
size.SetSize(kMaxIconSize, kMaxIconSize);
return gfx::ImageSkiaOperations::CreateResizedImage(
gfx::ImageSkia::CreateFrom1xBitmap(bitmap),
skia::ImageOperations::RESIZE_BEST, size);
}
} // namespace } // namespace
// Provides feedback to the user upon successful installation of an // Provides feedback to the user upon successful installation of an
...@@ -148,7 +159,8 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate, ...@@ -148,7 +159,8 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate,
public views::LinkListener { public views::LinkListener {
public: public:
ExtensionInstalledBubbleView(ExtensionInstalledBubble* bubble, ExtensionInstalledBubbleView(ExtensionInstalledBubble* bubble,
BubbleReference reference); BubbleReference reference,
const SkBitmap& icon);
~ExtensionInstalledBubbleView() override; ~ExtensionInstalledBubbleView() override;
// Recalculate the anchor position for this bubble. // Recalculate the anchor position for this bubble.
...@@ -173,9 +185,6 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate, ...@@ -173,9 +185,6 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate,
// views::LinkListener: // views::LinkListener:
void LinkClicked(views::Link* source, int event_flags) override; void LinkClicked(views::Link* source, int event_flags) override;
// Gets the size of the icon, capped at kExtensionInstalledIconSize.
gfx::Size GetIconSize() const;
ExtensionInstalledBubble* controller_; ExtensionInstalledBubble* controller_;
BubbleReference bubble_reference_; BubbleReference bubble_reference_;
...@@ -183,12 +192,15 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate, ...@@ -183,12 +192,15 @@ class ExtensionInstalledBubbleView : public BubbleSyncPromoDelegate,
// The shortcut to open the manage shortcuts page. // The shortcut to open the manage shortcuts page.
views::Link* manage_shortcut_; views::Link* manage_shortcut_;
const gfx::ImageSkia icon_;
DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleView); DISALLOW_COPY_AND_ASSIGN(ExtensionInstalledBubbleView);
}; };
ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( ExtensionInstalledBubbleView::ExtensionInstalledBubbleView(
ExtensionInstalledBubble* controller, ExtensionInstalledBubble* controller,
BubbleReference bubble_reference) BubbleReference bubble_reference,
const SkBitmap& icon)
: BubbleDialogDelegateView(nullptr, : BubbleDialogDelegateView(nullptr,
controller->anchor_position() == controller->anchor_position() ==
ExtensionInstalledBubble::ANCHOR_OMNIBOX ExtensionInstalledBubble::ANCHOR_OMNIBOX
...@@ -196,7 +208,8 @@ ExtensionInstalledBubbleView::ExtensionInstalledBubbleView( ...@@ -196,7 +208,8 @@ ExtensionInstalledBubbleView::ExtensionInstalledBubbleView(
: views::BubbleBorder::TOP_RIGHT), : views::BubbleBorder::TOP_RIGHT),
controller_(controller), controller_(controller),
bubble_reference_(bubble_reference), bubble_reference_(bubble_reference),
manage_shortcut_(nullptr) { manage_shortcut_(nullptr),
icon_(MakeIconFromBitmap(icon)) {
chrome::RecordDialogCreation(chrome::DialogIdentifier::EXTENSION_INSTALLED); chrome::RecordDialogCreation(chrome::DialogIdentifier::EXTENSION_INSTALLED);
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE); DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE);
DialogDelegate::SetFootnoteView(CreateSigninPromoView( DialogDelegate::SetFootnoteView(CreateSigninPromoView(
...@@ -237,10 +250,7 @@ base::string16 ExtensionInstalledBubbleView::GetWindowTitle() const { ...@@ -237,10 +250,7 @@ base::string16 ExtensionInstalledBubbleView::GetWindowTitle() const {
} }
gfx::ImageSkia ExtensionInstalledBubbleView::GetWindowIcon() { gfx::ImageSkia ExtensionInstalledBubbleView::GetWindowIcon() {
const SkBitmap& bitmap = controller_->icon(); return icon_;
return gfx::ImageSkiaOperations::CreateResizedImage(
gfx::ImageSkia::CreateFrom1xBitmap(bitmap),
skia::ImageOperations::RESIZE_BEST, GetIconSize());
} }
bool ExtensionInstalledBubbleView::ShouldShowWindowIcon() const { bool ExtensionInstalledBubbleView::ShouldShowWindowIcon() const {
...@@ -279,7 +289,7 @@ void ExtensionInstalledBubbleView::Init() { ...@@ -279,7 +289,7 @@ void ExtensionInstalledBubbleView::Init() {
// Indent by the size of the icon. // Indent by the size of the icon.
layout->set_inside_border_insets(gfx::Insets( layout->set_inside_border_insets(gfx::Insets(
0, 0,
GetIconSize().width() + icon_.width() +
provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL), provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL),
0, 0)); 0, 0));
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
...@@ -324,17 +334,6 @@ void ExtensionInstalledBubbleView::LinkClicked(views::Link* source, ...@@ -324,17 +334,6 @@ void ExtensionInstalledBubbleView::LinkClicked(views::Link* source,
CloseBubble(BUBBLE_CLOSE_NAVIGATED); CloseBubble(BUBBLE_CLOSE_NAVIGATED);
} }
gfx::Size ExtensionInstalledBubbleView::GetIconSize() const {
const SkBitmap& bitmap = controller_->icon();
// Scale down to 43x43, but allow smaller icons (don't scale up).
gfx::Size size(bitmap.width(), bitmap.height());
return size.width() > kExtensionInstalledIconSize ||
size.height() > kExtensionInstalledIconSize
? gfx::Size(kExtensionInstalledIconSize,
kExtensionInstalledIconSize)
: size;
}
ExtensionInstalledBubbleUi::ExtensionInstalledBubbleUi( ExtensionInstalledBubbleUi::ExtensionInstalledBubbleUi(
ExtensionInstalledBubble* bubble) ExtensionInstalledBubble* bubble)
: bubble_(bubble), bubble_view_(nullptr) { : bubble_(bubble), bubble_view_(nullptr) {
...@@ -347,7 +346,8 @@ ExtensionInstalledBubbleUi::~ExtensionInstalledBubbleUi() { ...@@ -347,7 +346,8 @@ ExtensionInstalledBubbleUi::~ExtensionInstalledBubbleUi() {
} }
void ExtensionInstalledBubbleUi::Show(BubbleReference bubble_reference) { void ExtensionInstalledBubbleUi::Show(BubbleReference bubble_reference) {
bubble_view_ = new ExtensionInstalledBubbleView(bubble_, bubble_reference); bubble_view_ = new ExtensionInstalledBubbleView(bubble_, bubble_reference,
bubble_->icon());
bubble_reference_ = bubble_reference; bubble_reference_ = bubble_reference;
views::BubbleDialogDelegateView::CreateBubble(bubble_view_)->Show(); views::BubbleDialogDelegateView::CreateBubble(bubble_view_)->Show();
......
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