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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 if (popup || !browser_->window()->IsActive()) | 239 if (popup || !browser_->window()->IsActive()) |
240 return false; | 240 return false; |
241 | 241 |
242 BrowserActionButton* button = [owner_ buttonForExtension:extension]; | 242 BrowserActionButton* button = [owner_ buttonForExtension:extension]; |
243 return button && [owner_ browserActionClicked:button | 243 return button && [owner_ browserActionClicked:button |
244 shouldGrant:grant_active_tab]; | 244 shouldGrant:grant_active_tab]; |
245 } | 245 } |
246 | 246 |
247 void ToolbarVisibleCountChanged() override {} | 247 void ToolbarVisibleCountChanged() override {} |
248 | 248 |
| 249 void OnToolbarReorderNecessary(content::WebContents* web_contents) override { |
| 250 // TODO(devlin): Implement on mac. |
| 251 } |
| 252 |
249 void ToolbarHighlightModeChanged(bool is_highlighting) override {} | 253 void ToolbarHighlightModeChanged(bool is_highlighting) override {} |
250 | 254 |
251 Browser* GetBrowser() override { return browser_; } | 255 Browser* GetBrowser() override { return browser_; } |
252 | 256 |
253 private: | 257 private: |
254 // The object we need to inform when we get a notification. Weak. Owns us. | 258 // The object we need to inform when we get a notification. Weak. Owns us. |
255 BrowserActionsController* owner_; | 259 BrowserActionsController* owner_; |
256 | 260 |
257 // The browser we listen for events from. Weak. | 261 // The browser we listen for events from. Weak. |
258 Browser* browser_; | 262 Browser* browser_; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 350 |
347 - (NSUInteger)buttonCount { | 351 - (NSUInteger)buttonCount { |
348 return [buttons_ count]; | 352 return [buttons_ count]; |
349 } | 353 } |
350 | 354 |
351 - (NSUInteger)visibleButtonCount { | 355 - (NSUInteger)visibleButtonCount { |
352 return [self buttonCount] - [hiddenButtons_ count]; | 356 return [self buttonCount] - [hiddenButtons_ count]; |
353 } | 357 } |
354 | 358 |
355 - (void)resizeContainerAndAnimate:(BOOL)animate { | 359 - (void)resizeContainerAndAnimate:(BOOL)animate { |
356 int iconCount = toolbarModel_->GetVisibleIconCount(); | 360 int iconCount = toolbarModel_->visible_icon_count(); |
357 if (iconCount < 0) // If no buttons are hidden. | |
358 iconCount = [self buttonCount]; | |
359 | 361 |
360 [containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount] | 362 [containerView_ resizeToWidth:[self containerWidthWithButtonCount:iconCount] |
361 animate:animate]; | 363 animate:animate]; |
362 NSRect frame = animate ? [containerView_ animationEndFrame] : | 364 NSRect frame = animate ? [containerView_ animationEndFrame] : |
363 [containerView_ frame]; | 365 [containerView_ frame]; |
364 | 366 |
365 [self showChevronIfNecessaryInFrame:frame animate:animate]; | 367 [self showChevronIfNecessaryInFrame:frame animate:animate]; |
366 | 368 |
367 if (!animate) { | 369 if (!animate) { |
368 [[NSNotificationCenter defaultCenter] | 370 [[NSNotificationCenter defaultCenter] |
369 postNotificationName:kBrowserActionVisibilityChangedNotification | 371 postNotificationName:kBrowserActionVisibilityChangedNotification |
370 object:self]; | 372 object:self]; |
371 } | 373 } |
372 } | 374 } |
373 | 375 |
374 - (NSView*)browserActionViewForExtension:(const Extension*)extension { | 376 - (NSView*)browserActionViewForExtension:(const Extension*)extension { |
375 for (BrowserActionButton* button in [buttons_ allValues]) { | 377 for (BrowserActionButton* button in [buttons_ allValues]) { |
376 if ([button extension] == extension) | 378 if ([button extension] == extension) |
377 return button; | 379 return button; |
378 } | 380 } |
379 NOTREACHED(); | 381 NOTREACHED(); |
380 return nil; | 382 return nil; |
381 } | 383 } |
382 | 384 |
383 - (CGFloat)savedWidth { | 385 - (CGFloat)savedWidth { |
384 if (!toolbarModel_) | 386 if (!toolbarModel_) |
385 return 0; | 387 return 0; |
386 | 388 |
387 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); | 389 int savedButtonCount = toolbarModel_->visible_icon_count(); |
388 if (savedButtonCount < 0 || // all icons are visible | 390 if (static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) |
389 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) | |
390 savedButtonCount = [self buttonCount]; | 391 savedButtonCount = [self buttonCount]; |
391 return [self containerWidthWithButtonCount:savedButtonCount]; | 392 return [self containerWidthWithButtonCount:savedButtonCount]; |
392 } | 393 } |
393 | 394 |
394 - (NSPoint)popupPointForBrowserAction:(const Extension*)extension { | 395 - (NSPoint)popupPointForBrowserAction:(const Extension*)extension { |
395 if (!extensions::ExtensionActionManager::Get(profile_)-> | 396 if (!extensions::ExtensionActionManager::Get(profile_)-> |
396 GetBrowserAction(*extension)) { | 397 GetBrowserAction(*extension)) { |
397 return NSZeroPoint; | 398 return NSZeroPoint; |
398 } | 399 } |
399 | 400 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 const extensions::ExtensionList& toolbar_items = | 850 const extensions::ExtensionList& toolbar_items = |
850 toolbarModel_->toolbar_items(); | 851 toolbarModel_->toolbar_items(); |
851 if (index < toolbar_items.size()) { | 852 if (index < toolbar_items.size()) { |
852 const Extension* extension = toolbar_items[index].get(); | 853 const Extension* extension = toolbar_items[index].get(); |
853 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 854 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
854 } | 855 } |
855 return nil; | 856 return nil; |
856 } | 857 } |
857 | 858 |
858 @end | 859 @end |
OLD | NEW |