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/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 ExtensionPopupController* popup = [ExtensionPopupController popup]; | 238 ExtensionPopupController* popup = [ExtensionPopupController popup]; |
239 if (popup || !browser_->window()->IsActive()) | 239 if (popup || !browser_->window()->IsActive()) |
240 return false; | 240 return false; |
241 | 241 |
242 BrowserActionButton* button = [owner_ buttonForId:extension->id()]; | 242 BrowserActionButton* button = [owner_ buttonForId:extension->id()]; |
243 return button && [button viewController]->ExecuteAction(grant_active_tab); | 243 return button && [button viewController]->ExecuteAction(grant_active_tab); |
244 } | 244 } |
245 | 245 |
246 void ToolbarVisibleCountChanged() override {} | 246 void ToolbarVisibleCountChanged() override {} |
247 | 247 |
248 void OnToolbarReorderNecessary(content::WebContents* web_contents) override { | |
249 // TODO(devlin): Implement on mac. | |
250 } | |
251 | |
252 void ToolbarHighlightModeChanged(bool is_highlighting) override {} | 248 void ToolbarHighlightModeChanged(bool is_highlighting) override {} |
253 | 249 |
254 Browser* GetBrowser() override { return browser_; } | 250 Browser* GetBrowser() override { return browser_; } |
255 | 251 |
256 private: | 252 private: |
257 // The object we need to inform when we get a notification. Weak. Owns us. | 253 // The object we need to inform when we get a notification. Weak. Owns us. |
258 BrowserActionsController* owner_; | 254 BrowserActionsController* owner_; |
259 | 255 |
260 // The browser we listen for events from. Weak. | 256 // The browser we listen for events from. Weak. |
261 Browser* browser_; | 257 Browser* browser_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 348 |
353 - (NSUInteger)buttonCount { | 349 - (NSUInteger)buttonCount { |
354 return [buttons_ count]; | 350 return [buttons_ count]; |
355 } | 351 } |
356 | 352 |
357 - (NSUInteger)visibleButtonCount { | 353 - (NSUInteger)visibleButtonCount { |
358 return [self buttonCount] - [hiddenButtons_ count]; | 354 return [self buttonCount] - [hiddenButtons_ count]; |
359 } | 355 } |
360 | 356 |
361 - (void)resizeContainerAndAnimate:(BOOL)animate { | 357 - (void)resizeContainerAndAnimate:(BOOL)animate { |
362 int iconCount = toolbarModel_->visible_icon_count(); | 358 int iconCount = toolbarModel_->GetVisibleIconCount(); |
| 359 if (iconCount < 0) // If no buttons are hidden. |
| 360 iconCount = [self buttonCount]; |
363 | 361 |
364 [containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount] | 362 [containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount] |
365 animate:animate]; | 363 animate:animate]; |
366 NSRect frame = animate ? [containerView_ animationEndFrame] : | 364 NSRect frame = animate ? [containerView_ animationEndFrame] : |
367 [containerView_ frame]; | 365 [containerView_ frame]; |
368 | 366 |
369 [self showChevronIfNecessaryInFrame:frame animate:animate]; | 367 [self showChevronIfNecessaryInFrame:frame animate:animate]; |
370 | 368 |
371 if (!animate) { | 369 if (!animate) { |
372 [[NSNotificationCenter defaultCenter] | 370 [[NSNotificationCenter defaultCenter] |
373 postNotificationName:kBrowserActionVisibilityChangedNotification | 371 postNotificationName:kBrowserActionVisibilityChangedNotification |
374 object:self]; | 372 object:self]; |
375 } | 373 } |
376 } | 374 } |
377 | 375 |
378 - (CGFloat)savedWidth { | 376 - (CGFloat)savedWidth { |
379 if (!toolbarModel_) | 377 if (!toolbarModel_) |
380 return 0; | 378 return 0; |
381 | 379 |
382 int savedButtonCount = toolbarModel_->visible_icon_count(); | 380 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); |
383 if (static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) | 381 if (savedButtonCount < 0 || // all icons are visible |
| 382 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) |
384 savedButtonCount = [self buttonCount]; | 383 savedButtonCount = [self buttonCount]; |
385 return [self containerWidthWithButtonCount:savedButtonCount]; | 384 return [self containerWidthWithButtonCount:savedButtonCount]; |
386 } | 385 } |
387 | 386 |
388 - (NSPoint)popupPointForId:(const std::string&)id { | 387 - (NSPoint)popupPointForId:(const std::string&)id { |
389 NSButton* button = [self buttonForId:id]; | 388 NSButton* button = [self buttonForId:id]; |
390 if (!button) | 389 if (!button) |
391 return NSZeroPoint; | 390 return NSZeroPoint; |
392 | 391 |
393 if ([hiddenButtons_ containsObject:button]) | 392 if ([hiddenButtons_ containsObject:button]) |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 const extensions::ExtensionList& toolbar_items = | 833 const extensions::ExtensionList& toolbar_items = |
835 toolbarModel_->toolbar_items(); | 834 toolbarModel_->toolbar_items(); |
836 if (index < toolbar_items.size()) { | 835 if (index < toolbar_items.size()) { |
837 const Extension* extension = toolbar_items[index].get(); | 836 const Extension* extension = toolbar_items[index].get(); |
838 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 837 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
839 } | 838 } |
840 return nil; | 839 return nil; |
841 } | 840 } |
842 | 841 |
843 @end | 842 @end |
OLD | NEW |