Chromium Code Reviews| 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 <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 | 133 |
| 134 // Moves the given button both visually and within the toolbar model to the | 134 // Moves the given button both visually and within the toolbar model to the |
| 135 // specified index. | 135 // specified index. |
| 136 - (void)moveButton:(BrowserActionButton*)button | 136 - (void)moveButton:(BrowserActionButton*)button |
| 137 toIndex:(NSUInteger)index | 137 toIndex:(NSUInteger)index |
| 138 animate:(BOOL)animate; | 138 animate:(BOOL)animate; |
| 139 | 139 |
| 140 // Handles when the given BrowserActionButton object is clicked. | 140 // Handles when the given BrowserActionButton object is clicked. |
| 141 - (void)browserActionClicked:(BrowserActionButton*)button; | 141 - (void)browserActionClicked:(BrowserActionButton*)button; |
| 142 | 142 |
| 143 // Triggers opening the popup window for an extension without a user action. | |
| 144 // Used by an extension API that opens an extension's popup. | |
| 145 - (void)openPopup:(const Extension*)extension; | |
| 146 | |
| 143 // Returns whether the given extension should be displayed. Only displays | 147 // Returns whether the given extension should be displayed. Only displays |
| 144 // incognito-enabled extensions in incognito mode. Otherwise returns YES. | 148 // incognito-enabled extensions in incognito mode. Otherwise returns YES. |
| 145 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; | 149 - (BOOL)shouldDisplayBrowserAction:(const Extension*)extension; |
| 146 | 150 |
| 147 // The reason |frame| is specified in these chevron functions is because the | 151 // The reason |frame| is specified in these chevron functions is because the |
| 148 // container may be animating and the end frame of the animation should be | 152 // container may be animating and the end frame of the animation should be |
| 149 // passed instead of the current frame (which may be off and cause the chevron | 153 // passed instead of the current frame (which may be off and cause the chevron |
| 150 // to jump at the end of its animation). | 154 // to jump at the end of its animation). |
| 151 | 155 |
| 152 // Shows the overflow chevron button depending on whether there are any hidden | 156 // Shows the overflow chevron button depending on whether there are any hidden |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 int index) OVERRIDE { | 235 int index) OVERRIDE { |
| 232 [owner_ createActionButtonForExtension:extension withIndex:index]; | 236 [owner_ createActionButtonForExtension:extension withIndex:index]; |
| 233 [owner_ resizeContainerAndAnimate:NO]; | 237 [owner_ resizeContainerAndAnimate:NO]; |
| 234 } | 238 } |
| 235 | 239 |
| 236 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { | 240 virtual void BrowserActionRemoved(const Extension* extension) OVERRIDE { |
| 237 [owner_ removeActionButtonForExtension:extension]; | 241 [owner_ removeActionButtonForExtension:extension]; |
| 238 [owner_ resizeContainerAndAnimate:NO]; | 242 [owner_ resizeContainerAndAnimate:NO]; |
| 239 } | 243 } |
| 240 | 244 |
| 245 virtual void BrowserActionShowPopup(const Extension* extension) OVERRIDE { | |
| 246 content::WebContents* active_tab = | |
| 247 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 248 if (!active_tab) | |
| 249 return; | |
| 250 [owner_ openPopup:extension]; | |
| 251 } | |
| 252 | |
| 241 private: | 253 private: |
| 242 // The object we need to inform when we get a notification. Weak. Owns us. | 254 // The object we need to inform when we get a notification. Weak. Owns us. |
| 243 BrowserActionsController* owner_; | 255 BrowserActionsController* owner_; |
| 244 | 256 |
| 245 // The browser we listen for events from. Weak. | 257 // The browser we listen for events from. Weak. |
| 246 Browser* browser_; | 258 Browser* browser_; |
| 247 | 259 |
| 248 // Used for registering to receive notifications and automatic clean up. | 260 // Used for registering to receive notifications and automatic clean up. |
| 249 content::NotificationRegistrar registrar_; | 261 content::NotificationRegistrar registrar_; |
| 250 | 262 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 [button setAlphaValue:1.0]; | 744 [button setAlphaValue:1.0]; |
| 733 [hiddenButtons_ removeObjectIdenticalTo:button]; | 745 [hiddenButtons_ removeObjectIdenticalTo:button]; |
| 734 } | 746 } |
| 735 } else if (![hiddenButtons_ containsObject:button]) { | 747 } else if (![hiddenButtons_ containsObject:button]) { |
| 736 [hiddenButtons_ addObject:button]; | 748 [hiddenButtons_ addObject:button]; |
| 737 [button removeFromSuperview]; | 749 [button removeFromSuperview]; |
| 738 [button setAlphaValue:0.0]; | 750 [button setAlphaValue:0.0]; |
| 739 } | 751 } |
| 740 } | 752 } |
| 741 | 753 |
| 754 - (void)openPopup:(const Extension*)extension { | |
| 755 const GURL popupUrl = toolbarModel_->GetPopupUrl(extension, browser_); | |
| 756 if (!popupUrl.is_empty()) { | |
| 757 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | |
| 758 if (NSEqualPoints(arrowPoint, NSZeroPoint)) { | |
| 759 // The button is hidden if arrowPoint is zero. | |
| 760 | |
| 761 // TODO(justinlin): This is not right.. position below hotdog menu. | |
|
mark a. foltz
2013/10/11 20:25:30
When an extension is installed into the overflow b
justinlin
2013/10/16 07:06:48
Right. It's a bit unclear how to plumb that in rig
| |
| 762 arrowPoint = NSMakePoint(NSWidth([containerView_ frame]), | |
| 763 kBrowserActionOriginYOffset); | |
| 764 } | |
| 765 | |
| 766 [ExtensionPopupController showURL:popupUrl | |
| 767 inBrowser:browser_ | |
| 768 anchoredAt:arrowPoint | |
| 769 arrowLocation:info_bubble::kTopRight | |
| 770 devMode:NO]; | |
| 771 } | |
| 772 } | |
| 773 | |
| 742 - (void)browserActionClicked:(BrowserActionButton*)button { | 774 - (void)browserActionClicked:(BrowserActionButton*)button { |
| 743 const Extension* extension = [button extension]; | 775 const Extension* extension = [button extension]; |
| 744 GURL popupUrl; | 776 GURL popupUrl; |
| 745 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { | 777 switch (toolbarModel_->ExecuteBrowserAction(extension, browser_, &popupUrl)) { |
| 746 case ExtensionToolbarModel::ACTION_NONE: | 778 case ExtensionToolbarModel::ACTION_NONE: |
| 747 break; | 779 break; |
| 748 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { | 780 case ExtensionToolbarModel::ACTION_SHOW_POPUP: { |
| 749 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; | 781 NSPoint arrowPoint = [self popupPointForBrowserAction:extension]; |
| 750 [ExtensionPopupController showURL:popupUrl | 782 [ExtensionPopupController showURL:popupUrl |
| 751 inBrowser:browser_ | 783 inBrowser:browser_ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 const extensions::ExtensionList& toolbar_items = | 895 const extensions::ExtensionList& toolbar_items = |
| 864 toolbarModel_->toolbar_items(); | 896 toolbarModel_->toolbar_items(); |
| 865 if (index < toolbar_items.size()) { | 897 if (index < toolbar_items.size()) { |
| 866 const Extension* extension = toolbar_items[index].get(); | 898 const Extension* extension = toolbar_items[index].get(); |
| 867 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 899 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 868 } | 900 } |
| 869 return nil; | 901 return nil; |
| 870 } | 902 } |
| 871 | 903 |
| 872 @end | 904 @end |
| OLD | NEW |