Commit 757eb222 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup in ExtensionPopup code:

* Use constexpr
* Change override comments to match more common style
* Call superclass methods (more technically correct)
* In OnWidgetActivationChanged(), call superclass method before doing override
  code instead of after; this makes it harder to omit calling the superclass via
  early return
* Use CloseWithReason(), as BubbleDialogDelegateView does
* Shorten code by using conditional instead of switch, and not handling DCHECK
  failure

Bug: none
Change-Id: Iffe3a4f229924fad13fd9b08e431a31308821fbb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1531652
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642376}
parent 383ba7fc
...@@ -24,14 +24,6 @@ ...@@ -24,14 +24,6 @@
#include "ui/wm/core/window_animations.h" #include "ui/wm/core/window_animations.h"
#endif #endif
// The minimum/maximum dimensions of the popup.
// The minimum is just a little larger than the size of the button itself.
// The maximum is an arbitrary number that should be smaller than most screens.
const int ExtensionPopup::kMinWidth = 25;
const int ExtensionPopup::kMinHeight = 25;
const int ExtensionPopup::kMaxWidth = 800;
const int ExtensionPopup::kMaxHeight = 600;
// static // static
void ExtensionPopup::ShowPopup( void ExtensionPopup::ShowPopup(
std::unique_ptr<extensions::ExtensionViewHost> host, std::unique_ptr<extensions::ExtensionViewHost> host,
...@@ -59,12 +51,14 @@ ExtensionPopup::~ExtensionPopup() { ...@@ -59,12 +51,14 @@ ExtensionPopup::~ExtensionPopup() {
gfx::Size ExtensionPopup::CalculatePreferredSize() const { gfx::Size ExtensionPopup::CalculatePreferredSize() const {
// Constrain the size to popup min/max. // Constrain the size to popup min/max.
gfx::Size sz = views::View::CalculatePreferredSize(); gfx::Size sz = views::View::CalculatePreferredSize();
sz.set_width(std::max(kMinWidth, std::min(kMaxWidth, sz.width()))); sz.SetToMax(gfx::Size(kMinWidth, kMinHeight));
sz.set_height(std::max(kMinHeight, std::min(kMaxHeight, sz.height()))); sz.SetToMin(gfx::Size(kMaxWidth, kMaxHeight));
return sz; return sz;
} }
void ExtensionPopup::AddedToWidget() { void ExtensionPopup::AddedToWidget() {
BubbleDialogDelegateView::AddedToWidget();
const int radius = const int radius =
GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius(); GetBubbleFrameView()->bubble_border()->GetBorderCornerRadius();
const bool contents_has_rounded_corners = const bool contents_has_rounded_corners =
...@@ -79,13 +73,14 @@ int ExtensionPopup::GetDialogButtons() const { ...@@ -79,13 +73,14 @@ int ExtensionPopup::GetDialogButtons() const {
void ExtensionPopup::OnWidgetActivationChanged(views::Widget* widget, void ExtensionPopup::OnWidgetActivationChanged(views::Widget* widget,
bool active) { bool active) {
BubbleDialogDelegateView::OnWidgetActivationChanged(widget, active);
if (active && observe_next_widget_activation_) { if (active && observe_next_widget_activation_) {
observe_next_widget_activation_ = false; observe_next_widget_activation_ = false;
views::Widget* const my_widget = GetWidget(); views::Widget* const my_widget = GetWidget();
if (widget != my_widget) if (widget != my_widget)
my_widget->Close(); my_widget->CloseWithReason(views::Widget::ClosedReason::kLostFocus);
} }
BubbleDialogDelegateView::OnWidgetActivationChanged(widget, active);
} }
bool ExtensionPopup::ShouldHaveRoundCorners() const { bool ExtensionPopup::ShouldHaveRoundCorners() const {
...@@ -99,21 +94,18 @@ void ExtensionPopup::OnExtensionSizeChanged(ExtensionViewViews* view) { ...@@ -99,21 +94,18 @@ void ExtensionPopup::OnExtensionSizeChanged(ExtensionViewViews* view) {
void ExtensionPopup::Observe(int type, void ExtensionPopup::Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { if (type == content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME) {
case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: DCHECK_EQ(host()->host_contents(),
DCHECK_EQ(host()->host_contents(), content::Source<content::WebContents>(source).ptr());
content::Source<content::WebContents>(source).ptr()); // Show when the content finishes loading and its width is computed.
// Show when the content finishes loading and its width is computed. ShowBubble();
ShowBubble(); return;
break;
case extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE:
// If we aren't the host of the popup, then disregard the notification.
if (content::Details<extensions::ExtensionHost>(host()) == details)
GetWidget()->Close();
break;
default:
NOTREACHED() << "Received unexpected notification";
} }
DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, type);
// If we aren't the host of the popup, then disregard the notification.
if (content::Details<extensions::ExtensionHost>(host()) == details)
GetWidget()->Close();
} }
void ExtensionPopup::OnTabStripModelChanged( void ExtensionPopup::OnTabStripModelChanged(
......
...@@ -41,10 +41,12 @@ class ExtensionPopup : public views::BubbleDialogDelegateView, ...@@ -41,10 +41,12 @@ class ExtensionPopup : public views::BubbleDialogDelegateView,
}; };
// The min/max height of popups. // The min/max height of popups.
static const int kMinWidth; // The minimum is just a little larger than the size of the button itself.
static const int kMinHeight; // The maximum is an arbitrary number and should be smaller than most screens.
static const int kMaxWidth; static constexpr int kMinWidth = 25;
static const int kMaxHeight; static constexpr int kMinHeight = 25;
static constexpr int kMaxWidth = 800;
static constexpr int kMaxHeight = 600;
// Creates and shows a popup with the given |host| positioned adjacent to // Creates and shows a popup with the given |host| positioned adjacent to
// |anchor_view|. // |anchor_view|.
...@@ -63,28 +65,28 @@ class ExtensionPopup : public views::BubbleDialogDelegateView, ...@@ -63,28 +65,28 @@ class ExtensionPopup : public views::BubbleDialogDelegateView,
extensions::ExtensionViewHost* host() const { return host_.get(); } extensions::ExtensionViewHost* host() const { return host_.get(); }
// views::BubbleDialogDelegateView overrides. // views::BubbleDialogDelegateView:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override; void AddedToWidget() override;
int GetDialogButtons() const override; int GetDialogButtons() const override;
void OnWidgetActivationChanged(views::Widget* widget, bool active) override; void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
bool ShouldHaveRoundCorners() const override; bool ShouldHaveRoundCorners() const override;
// ExtensionViewViews::Container overrides. // ExtensionViewViews::Container:
void OnExtensionSizeChanged(ExtensionViewViews* view) override; void OnExtensionSizeChanged(ExtensionViewViews* view) override;
// content::NotificationObserver overrides. // content::NotificationObserver:
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override; const content::NotificationDetails& details) override;
// TabStripModelObserver overrides. // TabStripModelObserver:
void OnTabStripModelChanged( void OnTabStripModelChanged(
TabStripModel* tab_strip_model, TabStripModel* tab_strip_model,
const TabStripModelChange& change, const TabStripModelChange& change,
const TabStripSelectionChange& selection) override; const TabStripSelectionChange& selection) override;
// content::DevToolsAgentHostObserver overrides. // content::DevToolsAgentHostObserver:
void DevToolsAgentHostAttached( void DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) override; content::DevToolsAgentHost* agent_host) override;
void DevToolsAgentHostDetached( void DevToolsAgentHostDetached(
......
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