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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/browser_actions_controller.mm

Issue 1858773006: [Extensions UI] Use the ExtensionMessageBubbleBridge for Views platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "chrome/browser/extensions/extension_message_bubble_controller.h" 14 #include "chrome/browser/extensions/extension_message_bubble_controller.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 17 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" 18 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h"
19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h" 19 #import "chrome/browser/ui/cocoa/extensions/browser_actions_container_view.h"
20 #import "chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h"
21 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" 20 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h"
22 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" 21 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h"
23 #import "chrome/browser/ui/cocoa/image_button_cell.h" 22 #import "chrome/browser/ui/cocoa/image_button_cell.h"
24 #import "chrome/browser/ui/cocoa/menu_button.h" 23 #import "chrome/browser/ui/cocoa/menu_button.h"
25 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 24 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
25 #include "chrome/browser/ui/extensions/extension_message_bubble_bridge.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h" 26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 27 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" 29 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h"
30 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
31 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h " 31 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSAnimation+Duration.h "
32 #include "ui/base/cocoa/appkit_utils.h" 32 #include "ui/base/cocoa/appkit_utils.h"
33 #include "ui/base/cocoa/cocoa_base_utils.h" 33 #include "ui/base/cocoa/cocoa_base_utils.h"
34 #include "ui/base/material_design/material_design_controller.h" 34 #include "ui/base/material_design/material_design_controller.h"
35 35
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 // Handles when a menu item within the chevron overflow menu is selected. 157 // Handles when a menu item within the chevron overflow menu is selected.
158 - (void)chevronItemSelected:(id)menuItem; 158 - (void)chevronItemSelected:(id)menuItem;
159 159
160 // Updates the container's grippy cursor based on the number of hidden buttons. 160 // Updates the container's grippy cursor based on the number of hidden buttons.
161 - (void)updateGrippyCursors; 161 - (void)updateGrippyCursors;
162 162
163 // Returns the associated ToolbarController. 163 // Returns the associated ToolbarController.
164 - (ToolbarController*)toolbarController; 164 - (ToolbarController*)toolbarController;
165 165
166 // Creates a message bubble with the given |delegate| that is anchored to the 166 // Creates a message bubble with the given |delegate|.
167 // given |anchorView|. 167 - (void)createMessageBubble:
168 - (ToolbarActionsBarBubbleMac*) 168 (std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate;
169 createMessageBubble:(std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate
170 anchorView:(NSView*)anchorView;
171 169
172 // Called when the window for the active bubble is closing, and sets the active 170 // Called when the window for the active bubble is closing, and sets the active
173 // bubble to nil. 171 // bubble to nil.
174 - (void)bubbleWindowClosing:(NSNotification*)notification; 172 - (void)bubbleWindowClosing:(NSNotification*)notification;
175 173
176 // Sets the current focused view. Should only be used for the overflow 174 // Sets the current focused view. Should only be used for the overflow
177 // container. 175 // container.
178 - (void)setFocusedViewIndex:(NSInteger)index; 176 - (void)setFocusedViewIndex:(NSInteger)index;
179 177
180 @end 178 @end
(...skipping 28 matching lines...) Expand all
209 void RemoveAllViews() override; 207 void RemoveAllViews() override;
210 void Redraw(bool order_changed) override; 208 void Redraw(bool order_changed) override;
211 void ResizeAndAnimate(gfx::Tween::Type tween_type, 209 void ResizeAndAnimate(gfx::Tween::Type tween_type,
212 int target_width, 210 int target_width,
213 bool suppress_chevron) override; 211 bool suppress_chevron) override;
214 void SetChevronVisibility(bool chevron_visible) override; 212 void SetChevronVisibility(bool chevron_visible) override;
215 int GetWidth(GetWidthTime get_width_time) const override; 213 int GetWidth(GetWidthTime get_width_time) const override;
216 bool IsAnimating() const override; 214 bool IsAnimating() const override;
217 void StopAnimating() override; 215 void StopAnimating() override;
218 int GetChevronWidth() const override; 216 int GetChevronWidth() const override;
219 void ShowExtensionMessageBubble(
220 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller,
221 ToolbarActionViewController* anchor_action) override;
222 void ShowToolbarActionBubble( 217 void ShowToolbarActionBubble(
223 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) override; 218 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) override;
224 219
225 // The owning BrowserActionsController; weak. 220 // The owning BrowserActionsController; weak.
226 BrowserActionsController* controller_; 221 BrowserActionsController* controller_;
227 222
228 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge); 223 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge);
229 }; 224 };
230 225
231 ToolbarActionsBarBridge::ToolbarActionsBarBridge( 226 ToolbarActionsBarBridge::ToolbarActionsBarBridge(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // instead of just ending the animation, the cleanest way to terminate is to 280 // instead of just ending the animation, the cleanest way to terminate is to
286 // "animate" to the current frame. 281 // "animate" to the current frame.
287 [controller_ resizeContainerToWidth: 282 [controller_ resizeContainerToWidth:
288 NSWidth([[controller_ containerView] frame])]; 283 NSWidth([[controller_ containerView] frame])];
289 } 284 }
290 285
291 int ToolbarActionsBarBridge::GetChevronWidth() const { 286 int ToolbarActionsBarBridge::GetChevronWidth() const {
292 return kChevronWidth; 287 return kChevronWidth;
293 } 288 }
294 289
295 void ToolbarActionsBarBridge::ShowExtensionMessageBubble(
296 std::unique_ptr<extensions::ExtensionMessageBubbleController>
297 bubble_controller,
298 ToolbarActionViewController* anchor_action) {
299 NSView* anchorView = nil;
300 BOOL anchoredToAction = NO;
301 if (anchor_action) {
302 BrowserActionButton* actionButton =
303 [controller_ buttonForId:anchor_action->GetId()];
304 if (actionButton && [actionButton superview]) {
305 anchorView = actionButton;
306 anchoredToAction = YES;
307 }
308 }
309 if (!anchorView)
310 anchorView = [[controller_ toolbarController] appMenuButton];
311
312 // This goop is a by-product of needing to wire together abstract classes,
313 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange
314 // Show() interface. It's ugly, but it's pretty confined, so it's probably
315 // okay (but if we ever need to expand, it might need to be reconsidered).
316 extensions::ExtensionMessageBubbleController* weak_controller =
317 bubble_controller.get();
318 std::unique_ptr<ExtensionMessageBubbleBridge> bridge(
319 new ExtensionMessageBubbleBridge(std::move(bubble_controller),
320 anchoredToAction));
321 ToolbarActionsBarBubbleMac* bubble =
322 [controller_ createMessageBubble:std::move(bridge)
323 anchorView:anchorView];
324 weak_controller->OnShown();
325 [bubble showWindow:nil];
326 }
327
328 void ToolbarActionsBarBridge::ShowToolbarActionBubble( 290 void ToolbarActionsBarBridge::ShowToolbarActionBubble(
329 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { 291 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) {
330 NSView* anchorView = nil; 292 [controller_ createMessageBubble:std::move(bubble)];
331 if (!bubble->GetAnchorActionId().empty()) {
332 BrowserActionButton* button =
333 [controller_ buttonForId:bubble->GetAnchorActionId()];
334 anchorView = button && [button superview] ? button :
335 [[controller_ toolbarController] appMenuButton];
336 } else {
337 anchorView = [controller_ containerView];
338 }
339
340 ToolbarActionsBarBubbleMac* bubbleView =
341 [controller_ createMessageBubble:std::move(bubble)
342 anchorView:anchorView];
343 [bubbleView showWindow:nil];
344 } 293 }
345 294
346 } // namespace 295 } // namespace
347 296
348 @implementation BrowserActionsController 297 @implementation BrowserActionsController
349 298
350 @synthesize containerView = containerView_; 299 @synthesize containerView = containerView_;
351 @synthesize browser = browser_; 300 @synthesize browser = browser_;
352 @synthesize isOverflow = isOverflow_; 301 @synthesize isOverflow = isOverflow_;
353 @synthesize activeBubble = activeBubble_; 302 @synthesize activeBubble = activeBubble_;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; 988 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]];
1040 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; 989 [containerView_ setCanDragRight:[self visibleButtonCount] > 0];
1041 [[containerView_ window] invalidateCursorRectsForView:containerView_]; 990 [[containerView_ window] invalidateCursorRectsForView:containerView_];
1042 } 991 }
1043 992
1044 - (ToolbarController*)toolbarController { 993 - (ToolbarController*)toolbarController {
1045 return [[BrowserWindowController browserWindowControllerForWindow: 994 return [[BrowserWindowController browserWindowControllerForWindow:
1046 browser_->window()->GetNativeWindow()] toolbarController]; 995 browser_->window()->GetNativeWindow()] toolbarController];
1047 } 996 }
1048 997
1049 - (ToolbarActionsBarBubbleMac*) 998 - (void)createMessageBubble:
1050 createMessageBubble:(std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate 999 (std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate {
1051 anchorView:(NSView*)anchorView { 1000 NSView* anchorView = nil;
1052 DCHECK(anchorView); 1001 BOOL anchoredToAction = NO;
1002 if (!delegate->GetAnchorActionId().empty()) {
1003 BrowserActionButton* button =
1004 [self buttonForId:delegate->GetAnchorActionId()];
1005 if (button && [button superview]) {
1006 anchorView = button;
1007 anchoredToAction = YES;
1008 } else {
1009 anchorView = [[self toolbarController] appMenuButton];
1010 }
1011 } else {
1012 anchorView = containerView_;
1013 }
1014
1053 DCHECK_GE([buttons_ count], 0u); 1015 DCHECK_GE([buttons_ count], 0u);
1054 NSPoint anchor = [self popupPointForView:anchorView 1016 NSPoint anchor = [self popupPointForView:anchorView
1055 withBounds:[anchorView bounds]]; 1017 withBounds:[anchorView bounds]];
1056 1018
1057 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor); 1019 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor);
1058 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc] 1020 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc]
1059 initWithParentWindow:[containerView_ window] 1021 initWithParentWindow:[containerView_ window]
1060 anchorPoint:anchor 1022 anchorPoint:anchor
1023 anchoredToAction:anchoredToAction
1061 delegate:std::move(delegate)]; 1024 delegate:std::move(delegate)];
1062 [[NSNotificationCenter defaultCenter] 1025 [[NSNotificationCenter defaultCenter]
1063 addObserver:self 1026 addObserver:self
1064 selector:@selector(bubbleWindowClosing:) 1027 selector:@selector(bubbleWindowClosing:)
1065 name:NSWindowWillCloseNotification 1028 name:NSWindowWillCloseNotification
1066 object:[activeBubble_ window]]; 1029 object:[activeBubble_ window]];
1067 return activeBubble_; 1030 [activeBubble_ showWindow:nil];
1068 } 1031 }
1069 1032
1070 - (void)bubbleWindowClosing:(NSNotification*)notification { 1033 - (void)bubbleWindowClosing:(NSNotification*)notification {
1071 activeBubble_ = nil; 1034 activeBubble_ = nil;
1035 toolbarActionsBar_->OnBubbleClosed();
1072 } 1036 }
1073 1037
1074 - (void)setFocusedViewIndex:(NSInteger)index { 1038 - (void)setFocusedViewIndex:(NSInteger)index {
1075 DCHECK(isOverflow_); 1039 DCHECK(isOverflow_);
1076 focusedViewIndex_ = index; 1040 focusedViewIndex_ = index;
1077 } 1041 }
1078 1042
1079 #pragma mark - 1043 #pragma mark -
1080 #pragma mark Testing Methods 1044 #pragma mark Testing Methods
1081 1045
1082 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { 1046 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index {
1083 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; 1047 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil;
1084 } 1048 }
1085 1049
1086 @end 1050 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/extensions/extension_message_bubble_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698