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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" 5 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 // Handles when a menu item within the chevron overflow menu is selected. 161 // Handles when a menu item within the chevron overflow menu is selected.
162 - (void)chevronItemSelected:(id)menuItem; 162 - (void)chevronItemSelected:(id)menuItem;
163 163
164 // Updates the container's grippy cursor based on the number of hidden buttons. 164 // Updates the container's grippy cursor based on the number of hidden buttons.
165 - (void)updateGrippyCursors; 165 - (void)updateGrippyCursors;
166 166
167 // Returns the associated ToolbarController. 167 // Returns the associated ToolbarController.
168 - (ToolbarController*)toolbarController; 168 - (ToolbarController*)toolbarController;
169 169
170 // Creates a message bubble anchored to the given |anchorAction|, or the app 170 // Creates a message bubble with the given |delegate| that is anchored to the
171 // menu if no |anchorAction| is null. 171 // given |anchorView|.
172 - (ToolbarActionsBarBubbleMac*)createMessageBubble: 172 - (ToolbarActionsBarBubbleMac*)createMessageBubble:
173 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate 173 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate
174 anchorToSelf:(BOOL)anchorToSelf; 174 anchorView:(NSView*)anchorView;
175 175
176 // Called when the window for the active bubble is closing, and sets the active 176 // Called when the window for the active bubble is closing, and sets the active
177 // bubble to nil. 177 // bubble to nil.
178 - (void)bubbleWindowClosing:(NSNotification*)notification; 178 - (void)bubbleWindowClosing:(NSNotification*)notification;
179 179
180 // Sets the current focused view. Should only be used for the overflow 180 // Sets the current focused view. Should only be used for the overflow
181 // container. 181 // container.
182 - (void)setFocusedViewIndex:(NSInteger)index; 182 - (void)setFocusedViewIndex:(NSInteger)index;
183 183
184 @end 184 @end
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 int target_width, 216 int target_width,
217 bool suppress_chevron) override; 217 bool suppress_chevron) override;
218 void SetChevronVisibility(bool chevron_visible) override; 218 void SetChevronVisibility(bool chevron_visible) override;
219 int GetWidth(GetWidthTime get_width_time) const override; 219 int GetWidth(GetWidthTime get_width_time) const override;
220 bool IsAnimating() const override; 220 bool IsAnimating() const override;
221 void StopAnimating() override; 221 void StopAnimating() override;
222 int GetChevronWidth() const override; 222 int GetChevronWidth() const override;
223 void ShowExtensionMessageBubble( 223 void ShowExtensionMessageBubble(
224 scoped_ptr<extensions::ExtensionMessageBubbleController> controller, 224 scoped_ptr<extensions::ExtensionMessageBubbleController> controller,
225 ToolbarActionViewController* anchor_action) override; 225 ToolbarActionViewController* anchor_action) override;
226 void ShowToolbarActionBubble(
227 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) override;
226 228
227 // The owning BrowserActionsController; weak. 229 // The owning BrowserActionsController; weak.
228 BrowserActionsController* controller_; 230 BrowserActionsController* controller_;
229 231
230 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge); 232 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge);
231 }; 233 };
232 234
233 ToolbarActionsBarBridge::ToolbarActionsBarBridge( 235 ToolbarActionsBarBridge::ToolbarActionsBarBridge(
234 BrowserActionsController* controller) 236 BrowserActionsController* controller)
235 : controller_(controller) { 237 : controller_(controller) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 NSWidth([[controller_ containerView] frame])]; 292 NSWidth([[controller_ containerView] frame])];
291 } 293 }
292 294
293 int ToolbarActionsBarBridge::GetChevronWidth() const { 295 int ToolbarActionsBarBridge::GetChevronWidth() const {
294 return kChevronWidth; 296 return kChevronWidth;
295 } 297 }
296 298
297 void ToolbarActionsBarBridge::ShowExtensionMessageBubble( 299 void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
298 scoped_ptr<extensions::ExtensionMessageBubbleController> bubble_controller, 300 scoped_ptr<extensions::ExtensionMessageBubbleController> bubble_controller,
299 ToolbarActionViewController* anchor_action) { 301 ToolbarActionViewController* anchor_action) {
302 NSView* anchorView = nil;
303 BOOL anchoredToAction = NO;
304 if (anchor_action) {
305 BrowserActionButton* actionButton =
306 [controller_ buttonForId:anchor_action->GetId()];
307 if (actionButton && [actionButton superview]) {
308 anchorView = actionButton;
309 anchoredToAction = YES;
310 }
311 }
312 if (!anchorView)
313 anchorView = [[controller_ toolbarController] appMenuButton];
314
300 // This goop is a by-product of needing to wire together abstract classes, 315 // This goop is a by-product of needing to wire together abstract classes,
301 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange 316 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange
302 // Show() interface. It's ugly, but it's pretty confined, so it's probably 317 // Show() interface. It's ugly, but it's pretty confined, so it's probably
303 // okay (but if we ever need to expand, it might need to be reconsidered). 318 // okay (but if we ever need to expand, it might need to be reconsidered).
304 extensions::ExtensionMessageBubbleController* weak_controller = 319 extensions::ExtensionMessageBubbleController* weak_controller =
305 bubble_controller.get(); 320 bubble_controller.get();
306 scoped_ptr<ExtensionMessageBubbleBridge> bridge( 321 scoped_ptr<ExtensionMessageBubbleBridge> bridge(
307 new ExtensionMessageBubbleBridge(std::move(bubble_controller), 322 new ExtensionMessageBubbleBridge(std::move(bubble_controller),
308 anchor_action != nullptr)); 323 anchoredToAction));
309 ToolbarActionsBarBubbleMac* bubble = 324 ToolbarActionsBarBubbleMac* bubble =
310 [controller_ createMessageBubble:std::move(bridge) 325 [controller_ createMessageBubble:std::move(bridge)
311 anchorToSelf:anchor_action != nil]; 326 anchorView:anchorView];
312 weak_controller->OnShown(); 327 weak_controller->OnShown();
313 [bubble showWindow:nil]; 328 [bubble showWindow:nil];
314 } 329 }
315 330
331 void ToolbarActionsBarBridge::ShowToolbarActionBubble(
332 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) {
333 NSView* anchorView = nil;
334 if (!bubble->GetAnchorActionId().empty()) {
335 BrowserActionButton* button =
336 [controller_ buttonForId:bubble->GetAnchorActionId()];
337 anchorView = button && [button superview] ? button :
338 [[controller_ toolbarController] appMenuButton];
339 } else {
340 anchorView = [controller_ containerView];
341 }
342
343 ToolbarActionsBarBubbleMac* bubbleView =
344 [controller_ createMessageBubble:std::move(bubble)
345 anchorView:anchorView];
346 [bubbleView showWindow:nil];
347 }
348
316 } // namespace 349 } // namespace
317 350
318 @implementation BrowserActionsController 351 @implementation BrowserActionsController
319 352
320 @synthesize containerView = containerView_; 353 @synthesize containerView = containerView_;
321 @synthesize browser = browser_; 354 @synthesize browser = browser_;
322 @synthesize isOverflow = isOverflow_; 355 @synthesize isOverflow = isOverflow_;
323 @synthesize activeBubble = activeBubble_; 356 @synthesize activeBubble = activeBubble_;
324 357
325 #pragma mark - 358 #pragma mark -
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 NOTREACHED(); 852 NOTREACHED();
820 } 853 }
821 } 854 }
822 855
823 - (void)containerMouseEntered:(NSNotification*)notification { 856 - (void)containerMouseEntered:(NSNotification*)notification {
824 if (!activeBubble_ && // only show one bubble at a time 857 if (!activeBubble_ && // only show one bubble at a time
825 toolbarActionsBar_->show_icon_surfacing_bubble()) { 858 toolbarActionsBar_->show_icon_surfacing_bubble()) {
826 scoped_ptr<ToolbarActionsBarBubbleDelegate> delegate( 859 scoped_ptr<ToolbarActionsBarBubbleDelegate> delegate(
827 new ExtensionToolbarIconSurfacingBubbleDelegate(browser_->profile())); 860 new ExtensionToolbarIconSurfacingBubbleDelegate(browser_->profile()));
828 ToolbarActionsBarBubbleMac* bubble = 861 ToolbarActionsBarBubbleMac* bubble =
829 [self createMessageBubble:std::move(delegate) anchorToSelf:YES]; 862 [self createMessageBubble:std::move(delegate)
863 anchorView:containerView_];
830 [bubble showWindow:nil]; 864 [bubble showWindow:nil];
831 } 865 }
832 [containerView_ setTrackingEnabled:NO]; 866 [containerView_ setTrackingEnabled:NO];
833 [[NSNotificationCenter defaultCenter] 867 [[NSNotificationCenter defaultCenter]
834 removeObserver:self 868 removeObserver:self
835 name:kBrowserActionsContainerMouseEntered 869 name:kBrowserActionsContainerMouseEntered
836 object:containerView_]; 870 object:containerView_];
837 } 871 }
838 872
839 - (void)actionButtonDragging:(NSNotification*)notification { 873 - (void)actionButtonDragging:(NSNotification*)notification {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 [[containerView_ window] invalidateCursorRectsForView:containerView_]; 1069 [[containerView_ window] invalidateCursorRectsForView:containerView_];
1036 } 1070 }
1037 1071
1038 - (ToolbarController*)toolbarController { 1072 - (ToolbarController*)toolbarController {
1039 return [[BrowserWindowController browserWindowControllerForWindow: 1073 return [[BrowserWindowController browserWindowControllerForWindow:
1040 browser_->window()->GetNativeWindow()] toolbarController]; 1074 browser_->window()->GetNativeWindow()] toolbarController];
1041 } 1075 }
1042 1076
1043 - (ToolbarActionsBarBubbleMac*)createMessageBubble: 1077 - (ToolbarActionsBarBubbleMac*)createMessageBubble:
1044 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate 1078 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate
1045 anchorToSelf:(BOOL)anchorToSelf { 1079 anchorView:(NSView*)anchorView {
1080 DCHECK(anchorView);
1046 DCHECK_GE([buttons_ count], 0u); 1081 DCHECK_GE([buttons_ count], 0u);
1047 NSView* anchorView =
1048 anchorToSelf ? containerView_ : [[self toolbarController] appMenuButton];
1049 NSPoint anchor = [self popupPointForView:anchorView 1082 NSPoint anchor = [self popupPointForView:anchorView
1050 withBounds:[anchorView bounds]]; 1083 withBounds:[anchorView bounds]];
1051 1084
1052 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor); 1085 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor);
1053 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc] 1086 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc]
1054 initWithParentWindow:[containerView_ window] 1087 initWithParentWindow:[containerView_ window]
1055 anchorPoint:anchor 1088 anchorPoint:anchor
1056 delegate:std::move(delegate)]; 1089 delegate:std::move(delegate)];
1057 [[NSNotificationCenter defaultCenter] 1090 [[NSNotificationCenter defaultCenter]
1058 addObserver:self 1091 addObserver:self
(...skipping 13 matching lines...) Expand all
1072 } 1105 }
1073 1106
1074 #pragma mark - 1107 #pragma mark -
1075 #pragma mark Testing Methods 1108 #pragma mark Testing Methods
1076 1109
1077 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { 1110 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index {
1078 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; 1111 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil;
1079 } 1112 }
1080 1113
1081 @end 1114 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698