Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 1809813002: [Extensions] Show a "refresh" bubble when needed with click-to-script (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
diff --git a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
index 3f97173ebd586de502c3e41e5576aec843711d5f..d6b7bb5a8876a34a7a37e3796b5e34d280fab26d 100644
--- a/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
+++ b/chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm
@@ -167,11 +167,11 @@ const CGFloat kBrowserActionBubbleYOffset = 3.0;
// Returns the associated ToolbarController.
- (ToolbarController*)toolbarController;
-// Creates a message bubble anchored to the given |anchorAction|, or the app
-// menu if no |anchorAction| is null.
+// Creates a message bubble with the given |delegate| that is anchored to the
+// given |anchorView|.
- (ToolbarActionsBarBubbleMac*)createMessageBubble:
(scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate
- anchorToSelf:(BOOL)anchorToSelf;
+ anchorView:(NSView*)anchorView;
// Called when the window for the active bubble is closing, and sets the active
// bubble to nil.
@@ -223,6 +223,8 @@ class ToolbarActionsBarBridge : public ToolbarActionsBarDelegate {
void ShowExtensionMessageBubble(
scoped_ptr<extensions::ExtensionMessageBubbleController> controller,
ToolbarActionViewController* anchor_action) override;
+ void ShowToolbarActionBubble(
+ scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) override;
// The owning BrowserActionsController; weak.
BrowserActionsController* controller_;
@@ -297,6 +299,19 @@ int ToolbarActionsBarBridge::GetChevronWidth() const {
void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
scoped_ptr<extensions::ExtensionMessageBubbleController> bubble_controller,
ToolbarActionViewController* anchor_action) {
+ NSView* anchorView = nil;
+ BOOL anchoredToAction = NO;
+ if (anchor_action) {
+ BrowserActionButton* actionButton =
+ [controller_ buttonForId:anchor_action->GetId()];
+ if (actionButton && [actionButton superview]) {
+ anchorView = actionButton;
+ anchoredToAction = YES;
+ }
+ }
+ if (!anchorView)
+ anchorView = [[controller_ toolbarController] appMenuButton];
+
// This goop is a by-product of needing to wire together abstract classes,
// C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange
// Show() interface. It's ugly, but it's pretty confined, so it's probably
@@ -305,14 +320,32 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
bubble_controller.get();
scoped_ptr<ExtensionMessageBubbleBridge> bridge(
new ExtensionMessageBubbleBridge(std::move(bubble_controller),
- anchor_action != nullptr));
+ anchoredToAction));
ToolbarActionsBarBubbleMac* bubble =
[controller_ createMessageBubble:std::move(bridge)
- anchorToSelf:anchor_action != nil];
+ anchorView:anchorView];
weak_controller->OnShown();
[bubble showWindow:nil];
}
+void ToolbarActionsBarBridge::ShowToolbarActionBubble(
+ scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) {
+ NSView* anchorView = nil;
+ if (!bubble->GetAnchorActionId().empty()) {
+ BrowserActionButton* button =
+ [controller_ buttonForId:bubble->GetAnchorActionId()];
+ anchorView = button && [button superview] ? button :
+ [[controller_ toolbarController] appMenuButton];
+ } else {
+ anchorView = [controller_ containerView];
+ }
+
+ ToolbarActionsBarBubbleMac* bubbleView =
+ [controller_ createMessageBubble:std::move(bubble)
+ anchorView:anchorView];
+ [bubbleView showWindow:nil];
+}
+
} // namespace
@implementation BrowserActionsController
@@ -826,7 +859,8 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
scoped_ptr<ToolbarActionsBarBubbleDelegate> delegate(
new ExtensionToolbarIconSurfacingBubbleDelegate(browser_->profile()));
ToolbarActionsBarBubbleMac* bubble =
- [self createMessageBubble:std::move(delegate) anchorToSelf:YES];
+ [self createMessageBubble:std::move(delegate)
+ anchorView:containerView_];
[bubble showWindow:nil];
}
[containerView_ setTrackingEnabled:NO];
@@ -1042,10 +1076,9 @@ void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
- (ToolbarActionsBarBubbleMac*)createMessageBubble:
(scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate
- anchorToSelf:(BOOL)anchorToSelf {
+ anchorView:(NSView*)anchorView {
+ DCHECK(anchorView);
DCHECK_GE([buttons_ count], 0u);
- NSView* anchorView =
- anchorToSelf ? containerView_ : [[self toolbarController] appMenuButton];
NSPoint anchor = [self popupPointForView:anchorView
withBounds:[anchorView bounds]];

Powered by Google App Engine
This is Rietveld 408576698