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

polychrome: wire ExtensionInstalledBubble

This change:
1) Adds a bubble_anchor_util helper for getting the extension installed bubble's
   anchor point in a Cocoa browser window;
2) Uses it in the existing Cocoa implementation and in the Views implementation
   when appropriate.

This fixes many of the Webstore browser tests.

Bug: 817408
Change-Id: I761bb51aede351a8203d4dd08de6f2fd44e25095
Reviewed-on: https://chromium-review.googlesource.com/960802Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543578}
parent e0887d3e
......@@ -6,12 +6,15 @@
#define CHROME_BROWSER_UI_BUBBLE_ANCHOR_UTIL_H_
#include "build/build_config.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Point;
class Rect;
}
class Browser;
class ExtensionInstalledBubble;
namespace bubble_anchor_util {
......@@ -38,6 +41,12 @@ gfx::Rect GetPageInfoAnchorRect(Browser* browser);
// Returns the page info anchor rect for |browser|, which is assumed to have a
// Cocoa browser window.
gfx::Rect GetPageInfoAnchorRectCocoa(Browser* browser);
// Returns the anchor point for the extension installed bubble for |window|,
// which is assumed to be a Cocoa browser window.
gfx::Point GetExtensionInstalledAnchorPointCocoa(
gfx::NativeWindow window,
const ExtensionInstalledBubble* bubble);
#endif
} // namespace bubble_anchor_util
......
......@@ -4,7 +4,15 @@
#include "chrome/browser/ui/views/bubble_anchor_util_views.h"
#include "chrome/browser/ui/cocoa/bubble_anchor_helper.h"
#import <Cocoa/Cocoa.h>
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/bubble_anchor_helper.h"
#import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#include "chrome/browser/ui/extensions/extension_installed_bubble.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/base/ui_features.h"
#include "ui/gfx/geometry/rect.h"
#import "ui/gfx/mac/coordinate_conversion.h"
......@@ -21,6 +29,41 @@ gfx::Rect GetPageInfoAnchorRectCocoa(Browser* browser) {
gfx::Size());
}
gfx::Point GetExtensionInstalledAnchorPointCocoa(
gfx::NativeWindow window,
const ExtensionInstalledBubble* bubble) {
BrowserWindowController* window_controller =
[BrowserWindowController browserWindowControllerForWindow:window];
ToolbarController* toolbar_controller = [window_controller toolbarController];
NSPoint arrow_point;
switch (bubble->anchor_position()) {
case ExtensionInstalledBubble::ANCHOR_ACTION: {
BrowserActionsController* controller =
[toolbar_controller browserActionsController];
arrow_point = [controller popupPointForId:bubble->extension()->id()];
break;
}
case ExtensionInstalledBubble::ANCHOR_OMNIBOX: {
LocationBarViewMac* locationBarView =
[window_controller locationBarBridge];
arrow_point = locationBarView->GetPageInfoBubblePoint();
break;
}
case ExtensionInstalledBubble::ANCHOR_APP_MENU: {
arrow_point = [toolbar_controller appMenuBubblePoint];
break;
}
default: {
NOTREACHED();
break;
}
}
// Convert to screen coordinates.
arrow_point = ui::ConvertPointFromWindowToScreen(window, arrow_point);
return gfx::ScreenPointFromNSPoint(arrow_point);
}
#if !BUILDFLAG(MAC_VIEWS_BROWSER)
gfx::Rect GetPageInfoAnchorRect(Browser* browser) {
return GetPageInfoAnchorRectCocoa(browser);
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/bubble_anchor_util.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
......@@ -123,44 +124,8 @@ bool ExtensionInstalledBubble::ShouldShow() {
gfx::Point ExtensionInstalledBubble::GetAnchorPoint(
gfx::NativeWindow window) const {
BrowserWindowController* windowController =
[BrowserWindowController browserWindowControllerForWindow:window];
auto getAppMenuButtonAnchorPoint = [windowController]() {
// Point at the bottom of the app menu menu.
NSView* appMenuButton =
[[windowController toolbarController] appMenuButton];
const NSRect bounds = [appMenuButton bounds];
NSPoint anchor = NSMakePoint(NSMidX(bounds), NSMaxY(bounds));
return [appMenuButton convertPoint:anchor toView:nil];
};
NSPoint arrowPoint;
switch (anchor_position()) {
case ExtensionInstalledBubble::ANCHOR_ACTION: {
BrowserActionsController* controller =
[[windowController toolbarController] browserActionsController];
arrowPoint = [controller popupPointForId:extension()->id()];
break;
}
case ExtensionInstalledBubble::ANCHOR_OMNIBOX: {
LocationBarViewMac* locationBarView =
[windowController locationBarBridge];
arrowPoint = locationBarView->GetPageInfoBubblePoint();
break;
}
case ExtensionInstalledBubble::ANCHOR_APP_MENU: {
arrowPoint = getAppMenuButtonAnchorPoint();
break;
}
default: {
NOTREACHED();
break;
}
}
// Convert to screen coordinates.
arrowPoint = ui::ConvertPointFromWindowToScreen(window, arrowPoint);
return gfx::ScreenPointFromNSPoint(arrowPoint);
return bubble_anchor_util::GetExtensionInstalledAnchorPointCocoa(window,
this);
}
// Implemented here to create the platform specific instance of the BubbleUi.
......
......@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/bubble_anchor_util.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/extensions/extension_installed_bubble.h"
#include "chrome/browser/ui/singleton_tabs.h"
......@@ -77,14 +78,15 @@ views::Label* CreateLabel(const base::string16& text) {
#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
views::View* AnchorViewForBrowser(ExtensionInstalledBubble* controller,
Browser* browser) {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
views::View* reference_view = nullptr;
#if defined(OS_MACOSX)
// The Cocoa browser always needs to use an anchor point.
#if BUILDFLAG(MAC_VIEWS_BROWSER)
if (views_mode_controller::IsViewsBrowserCocoa())
return nullptr;
#endif
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
views::View* reference_view = nullptr;
switch (controller->anchor_position()) {
case ExtensionInstalledBubble::ANCHOR_ACTION: {
BrowserActionsContainer* container =
......@@ -109,10 +111,12 @@ views::View* AnchorViewForBrowser(ExtensionInstalledBubble* controller,
return browser_view->button_provider()->GetAppMenuButton();
return reference_view;
}
#else
#else // OS_MACOSX && !MAC_VIEWS_BROWSER
// Always use an anchor point in non-Views Mac builds. This needs a separate
// implementation because non-Views Mac builds can't even reference BrowserView.
views::View* AnchorViewForBrowser(ExtensionInstalledBubble* controller,
Browser* browser) {
return nullptr; // Always use the anchor point.
return nullptr;
}
#endif
......@@ -387,6 +391,13 @@ void ExtensionInstalledBubbleUi::OnWidgetClosing(views::Widget* widget) {
// Views (BrowserView) specific implementation.
bool ExtensionInstalledBubble::ShouldShow() {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
// Cocoa browser windows can always show the bubble - no need to check for an
// animation.
// TODO(ellyjones): Is that actually true?
if (views_mode_controller::IsViewsBrowserCocoa())
return true;
#endif
if (anchor_position() == ANCHOR_ACTION) {
BrowserActionsContainer* container =
BrowserView::GetBrowserViewForBrowser(browser())
......@@ -399,6 +410,11 @@ bool ExtensionInstalledBubble::ShouldShow() {
gfx::Point ExtensionInstalledBubble::GetAnchorPoint(
gfx::NativeWindow window) const {
#if BUILDFLAG(MAC_VIEWS_BROWSER)
DCHECK(views_mode_controller::IsViewsBrowserCocoa());
return bubble_anchor_util::GetExtensionInstalledAnchorPointCocoa(window,
this);
#endif
NOTREACHED(); // There is always an anchor view.
return gfx::Point();
}
......
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