| OLD | NEW |
| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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| that is anchored to the |
| 167 // given |anchorView|. | 167 // given |anchorView|. |
| 168 - (ToolbarActionsBarBubbleMac*)createMessageBubble: | 168 - (ToolbarActionsBarBubbleMac*) |
| 169 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate | 169 createMessageBubble:(std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate |
| 170 anchorView:(NSView*)anchorView; | 170 anchorView:(NSView*)anchorView; |
| 171 | 171 |
| 172 // Called when the window for the active bubble is closing, and sets the active | 172 // Called when the window for the active bubble is closing, and sets the active |
| 173 // bubble to nil. | 173 // bubble to nil. |
| 174 - (void)bubbleWindowClosing:(NSNotification*)notification; | 174 - (void)bubbleWindowClosing:(NSNotification*)notification; |
| 175 | 175 |
| 176 // Sets the current focused view. Should only be used for the overflow | 176 // Sets the current focused view. Should only be used for the overflow |
| 177 // container. | 177 // container. |
| 178 - (void)setFocusedViewIndex:(NSInteger)index; | 178 - (void)setFocusedViewIndex:(NSInteger)index; |
| 179 | 179 |
| 180 @end | 180 @end |
| (...skipping 29 matching lines...) Expand all Loading... |
| 210 void Redraw(bool order_changed) override; | 210 void Redraw(bool order_changed) override; |
| 211 void ResizeAndAnimate(gfx::Tween::Type tween_type, | 211 void ResizeAndAnimate(gfx::Tween::Type tween_type, |
| 212 int target_width, | 212 int target_width, |
| 213 bool suppress_chevron) override; | 213 bool suppress_chevron) override; |
| 214 void SetChevronVisibility(bool chevron_visible) override; | 214 void SetChevronVisibility(bool chevron_visible) override; |
| 215 int GetWidth(GetWidthTime get_width_time) const override; | 215 int GetWidth(GetWidthTime get_width_time) const override; |
| 216 bool IsAnimating() const override; | 216 bool IsAnimating() const override; |
| 217 void StopAnimating() override; | 217 void StopAnimating() override; |
| 218 int GetChevronWidth() const override; | 218 int GetChevronWidth() const override; |
| 219 void ShowExtensionMessageBubble( | 219 void ShowExtensionMessageBubble( |
| 220 scoped_ptr<extensions::ExtensionMessageBubbleController> controller, | 220 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller, |
| 221 ToolbarActionViewController* anchor_action) override; | 221 ToolbarActionViewController* anchor_action) override; |
| 222 void ShowToolbarActionBubble( | 222 void ShowToolbarActionBubble( |
| 223 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) override; | 223 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) override; |
| 224 | 224 |
| 225 // The owning BrowserActionsController; weak. | 225 // The owning BrowserActionsController; weak. |
| 226 BrowserActionsController* controller_; | 226 BrowserActionsController* controller_; |
| 227 | 227 |
| 228 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge); | 228 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarBridge); |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 ToolbarActionsBarBridge::ToolbarActionsBarBridge( | 231 ToolbarActionsBarBridge::ToolbarActionsBarBridge( |
| 232 BrowserActionsController* controller) | 232 BrowserActionsController* controller) |
| 233 : controller_(controller) { | 233 : controller_(controller) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // "animate" to the current frame. | 286 // "animate" to the current frame. |
| 287 [controller_ resizeContainerToWidth: | 287 [controller_ resizeContainerToWidth: |
| 288 NSWidth([[controller_ containerView] frame])]; | 288 NSWidth([[controller_ containerView] frame])]; |
| 289 } | 289 } |
| 290 | 290 |
| 291 int ToolbarActionsBarBridge::GetChevronWidth() const { | 291 int ToolbarActionsBarBridge::GetChevronWidth() const { |
| 292 return kChevronWidth; | 292 return kChevronWidth; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void ToolbarActionsBarBridge::ShowExtensionMessageBubble( | 295 void ToolbarActionsBarBridge::ShowExtensionMessageBubble( |
| 296 scoped_ptr<extensions::ExtensionMessageBubbleController> bubble_controller, | 296 std::unique_ptr<extensions::ExtensionMessageBubbleController> |
| 297 bubble_controller, |
| 297 ToolbarActionViewController* anchor_action) { | 298 ToolbarActionViewController* anchor_action) { |
| 298 NSView* anchorView = nil; | 299 NSView* anchorView = nil; |
| 299 BOOL anchoredToAction = NO; | 300 BOOL anchoredToAction = NO; |
| 300 if (anchor_action) { | 301 if (anchor_action) { |
| 301 BrowserActionButton* actionButton = | 302 BrowserActionButton* actionButton = |
| 302 [controller_ buttonForId:anchor_action->GetId()]; | 303 [controller_ buttonForId:anchor_action->GetId()]; |
| 303 if (actionButton && [actionButton superview]) { | 304 if (actionButton && [actionButton superview]) { |
| 304 anchorView = actionButton; | 305 anchorView = actionButton; |
| 305 anchoredToAction = YES; | 306 anchoredToAction = YES; |
| 306 } | 307 } |
| 307 } | 308 } |
| 308 if (!anchorView) | 309 if (!anchorView) |
| 309 anchorView = [[controller_ toolbarController] appMenuButton]; | 310 anchorView = [[controller_ toolbarController] appMenuButton]; |
| 310 | 311 |
| 311 // This goop is a by-product of needing to wire together abstract classes, | 312 // This goop is a by-product of needing to wire together abstract classes, |
| 312 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange | 313 // C++/Cocoa bridges, and ExtensionMessageBubbleController's somewhat strange |
| 313 // Show() interface. It's ugly, but it's pretty confined, so it's probably | 314 // Show() interface. It's ugly, but it's pretty confined, so it's probably |
| 314 // okay (but if we ever need to expand, it might need to be reconsidered). | 315 // okay (but if we ever need to expand, it might need to be reconsidered). |
| 315 extensions::ExtensionMessageBubbleController* weak_controller = | 316 extensions::ExtensionMessageBubbleController* weak_controller = |
| 316 bubble_controller.get(); | 317 bubble_controller.get(); |
| 317 scoped_ptr<ExtensionMessageBubbleBridge> bridge( | 318 std::unique_ptr<ExtensionMessageBubbleBridge> bridge( |
| 318 new ExtensionMessageBubbleBridge(std::move(bubble_controller), | 319 new ExtensionMessageBubbleBridge(std::move(bubble_controller), |
| 319 anchoredToAction)); | 320 anchoredToAction)); |
| 320 ToolbarActionsBarBubbleMac* bubble = | 321 ToolbarActionsBarBubbleMac* bubble = |
| 321 [controller_ createMessageBubble:std::move(bridge) | 322 [controller_ createMessageBubble:std::move(bridge) |
| 322 anchorView:anchorView]; | 323 anchorView:anchorView]; |
| 323 weak_controller->OnShown(); | 324 weak_controller->OnShown(); |
| 324 [bubble showWindow:nil]; | 325 [bubble showWindow:nil]; |
| 325 } | 326 } |
| 326 | 327 |
| 327 void ToolbarActionsBarBridge::ShowToolbarActionBubble( | 328 void ToolbarActionsBarBridge::ShowToolbarActionBubble( |
| 328 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble) { | 329 std::unique_ptr<ToolbarActionsBarBubbleDelegate> bubble) { |
| 329 NSView* anchorView = nil; | 330 NSView* anchorView = nil; |
| 330 if (!bubble->GetAnchorActionId().empty()) { | 331 if (!bubble->GetAnchorActionId().empty()) { |
| 331 BrowserActionButton* button = | 332 BrowserActionButton* button = |
| 332 [controller_ buttonForId:bubble->GetAnchorActionId()]; | 333 [controller_ buttonForId:bubble->GetAnchorActionId()]; |
| 333 anchorView = button && [button superview] ? button : | 334 anchorView = button && [button superview] ? button : |
| 334 [[controller_ toolbarController] appMenuButton]; | 335 [[controller_ toolbarController] appMenuButton]; |
| 335 } else { | 336 } else { |
| 336 anchorView = [controller_ containerView]; | 337 anchorView = [controller_ containerView]; |
| 337 } | 338 } |
| 338 | 339 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 name:kBrowserActionButtonDraggingNotification | 589 name:kBrowserActionButtonDraggingNotification |
| 589 object:newButton]; | 590 object:newButton]; |
| 590 | 591 |
| 591 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; | 592 [containerView_ setMaxDesiredWidth:toolbarActionsBar_->GetMaximumWidth()]; |
| 592 } | 593 } |
| 593 | 594 |
| 594 - (void)redraw { | 595 - (void)redraw { |
| 595 if (![self updateContainerVisibility]) | 596 if (![self updateContainerVisibility]) |
| 596 return; // Container is hidden; no need to update. | 597 return; // Container is hidden; no need to update. |
| 597 | 598 |
| 598 scoped_ptr<ui::NinePartImageIds> highlight; | 599 std::unique_ptr<ui::NinePartImageIds> highlight; |
| 599 if (toolbarActionsBar_->is_highlighting()) { | 600 if (toolbarActionsBar_->is_highlighting()) { |
| 600 if (toolbarActionsBar_->highlight_type() == | 601 if (toolbarActionsBar_->highlight_type() == |
| 601 ToolbarActionsModel::HIGHLIGHT_INFO) | 602 ToolbarActionsModel::HIGHLIGHT_INFO) |
| 602 highlight.reset( | 603 highlight.reset( |
| 603 new ui::NinePartImageIds(IMAGE_GRID(IDR_TOOLBAR_ACTION_HIGHLIGHT))); | 604 new ui::NinePartImageIds(IMAGE_GRID(IDR_TOOLBAR_ACTION_HIGHLIGHT))); |
| 604 else | 605 else |
| 605 highlight.reset( | 606 highlight.reset( |
| 606 new ui::NinePartImageIds(IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT))); | 607 new ui::NinePartImageIds(IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT))); |
| 607 } | 608 } |
| 608 [containerView_ setHighlight:std::move(highlight)]; | 609 [containerView_ setHighlight:std::move(highlight)]; |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; | 1038 setCanDragLeft:toolbarActionsBar_->GetIconCount() != [buttons_ count]]; |
| 1038 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; | 1039 [containerView_ setCanDragRight:[self visibleButtonCount] > 0]; |
| 1039 [[containerView_ window] invalidateCursorRectsForView:containerView_]; | 1040 [[containerView_ window] invalidateCursorRectsForView:containerView_]; |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 - (ToolbarController*)toolbarController { | 1043 - (ToolbarController*)toolbarController { |
| 1043 return [[BrowserWindowController browserWindowControllerForWindow: | 1044 return [[BrowserWindowController browserWindowControllerForWindow: |
| 1044 browser_->window()->GetNativeWindow()] toolbarController]; | 1045 browser_->window()->GetNativeWindow()] toolbarController]; |
| 1045 } | 1046 } |
| 1046 | 1047 |
| 1047 - (ToolbarActionsBarBubbleMac*)createMessageBubble: | 1048 - (ToolbarActionsBarBubbleMac*) |
| 1048 (scoped_ptr<ToolbarActionsBarBubbleDelegate>)delegate | 1049 createMessageBubble:(std::unique_ptr<ToolbarActionsBarBubbleDelegate>)delegate |
| 1049 anchorView:(NSView*)anchorView { | 1050 anchorView:(NSView*)anchorView { |
| 1050 DCHECK(anchorView); | 1051 DCHECK(anchorView); |
| 1051 DCHECK_GE([buttons_ count], 0u); | 1052 DCHECK_GE([buttons_ count], 0u); |
| 1052 NSPoint anchor = [self popupPointForView:anchorView | 1053 NSPoint anchor = [self popupPointForView:anchorView |
| 1053 withBounds:[anchorView bounds]]; | 1054 withBounds:[anchorView bounds]]; |
| 1054 | 1055 |
| 1055 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor); | 1056 anchor = ui::ConvertPointFromWindowToScreen([containerView_ window], anchor); |
| 1056 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc] | 1057 activeBubble_ = [[ToolbarActionsBarBubbleMac alloc] |
| 1057 initWithParentWindow:[containerView_ window] | 1058 initWithParentWindow:[containerView_ window] |
| 1058 anchorPoint:anchor | 1059 anchorPoint:anchor |
| 1059 delegate:std::move(delegate)]; | 1060 delegate:std::move(delegate)]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1075 } | 1076 } |
| 1076 | 1077 |
| 1077 #pragma mark - | 1078 #pragma mark - |
| 1078 #pragma mark Testing Methods | 1079 #pragma mark Testing Methods |
| 1079 | 1080 |
| 1080 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { | 1081 - (BrowserActionButton*)buttonWithIndex:(NSUInteger)index { |
| 1081 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; | 1082 return index < [buttons_ count] ? [buttons_ objectAtIndex:index] : nil; |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 @end | 1085 @end |
| OLD | NEW |