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