Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "browser_actions_controller.h" | 5 #import "browser_actions_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/nsimage_cache_mac.h" | 10 #include "base/nsimage_cache_mac.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 const CGFloat kBrowserActionHeight = 29.0; | 50 const CGFloat kBrowserActionHeight = 29.0; |
| 51 const CGFloat kBrowserActionWidth = 29.0; | 51 const CGFloat kBrowserActionWidth = 29.0; |
| 52 | 52 |
| 53 // The padding between browser action buttons. | 53 // The padding between browser action buttons. |
| 54 const CGFloat kBrowserActionButtonPadding = 2.0; | 54 const CGFloat kBrowserActionButtonPadding = 2.0; |
| 55 | 55 |
| 56 // Padding between Omnibox and first button. Since the buttons have a | 56 // Padding between Omnibox and first button. Since the buttons have a |
| 57 // pixel of internal padding, this needs an extra pixel. | 57 // pixel of internal padding, this needs an extra pixel. |
| 58 const CGFloat kBrowserActionLeftPadding = kBrowserActionButtonPadding + 1.0; | 58 const CGFloat kBrowserActionLeftPadding = kBrowserActionButtonPadding + 1.0; |
| 59 | 59 |
| 60 // How far to inset from the bottom of the view to get the top border | |
| 61 // of the popup 2px below the bottom of the Omnibox. | |
| 62 const CGFloat kBrowserActionBubbleYOffset = 3.0; | |
| 63 | |
| 60 } // namespace | 64 } // namespace |
| 61 | 65 |
| 62 @interface BrowserActionsController(Private) | 66 @interface BrowserActionsController(Private) |
| 63 // Used during initialization to create the BrowserActionButton objects from the | 67 // Used during initialization to create the BrowserActionButton objects from the |
| 64 // stored toolbar model. | 68 // stored toolbar model. |
| 65 - (void)createButtons; | 69 - (void)createButtons; |
| 66 | 70 |
| 67 // Creates and then adds the given extension's action button to the container | 71 // Creates and then adds the given extension's action button to the container |
| 68 // at the given index within the container. It does not affect the toolbar model | 72 // at the given index within the container. It does not affect the toolbar model |
| 69 // object since it is called when the toolbar model changes. | 73 // object since it is called when the toolbar model changes. |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); | 371 int savedButtonCount = toolbarModel_->GetVisibleIconCount(); |
| 368 if (savedButtonCount < 0 || // all icons are visible | 372 if (savedButtonCount < 0 || // all icons are visible |
| 369 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) | 373 static_cast<NSUInteger>(savedButtonCount) > [self buttonCount]) |
| 370 savedButtonCount = [self buttonCount]; | 374 savedButtonCount = [self buttonCount]; |
| 371 return [self containerWidthWithButtonCount:savedButtonCount]; | 375 return [self containerWidthWithButtonCount:savedButtonCount]; |
| 372 } | 376 } |
| 373 | 377 |
| 374 - (NSPoint)popupPointForBrowserAction:(Extension*)extension { | 378 - (NSPoint)popupPointForBrowserAction:(Extension*)extension { |
| 375 if (!extension->browser_action()) | 379 if (!extension->browser_action()) |
| 376 return NSZeroPoint; | 380 return NSZeroPoint; |
| 377 BrowserActionButton* button = [self buttonForExtension:extension]; | 381 |
| 382 NSButton* button = [self buttonForExtension:extension]; | |
| 378 if (!button) | 383 if (!button) |
| 379 return NSZeroPoint; | 384 return NSZeroPoint; |
| 380 | 385 |
| 381 NSView* view = button; | 386 if ([hiddenButtons_ containsObject:button]) |
| 382 BOOL isHidden = [hiddenButtons_ containsObject:button]; | 387 button = chevronMenuButton_.get(); |
| 383 if (isHidden) | |
| 384 view = chevronMenuButton_.get(); | |
| 385 | 388 |
| 386 NSPoint arrowPoint = [view frame].origin; | 389 // Anchor point just above the center of the bottom. |
| 387 // Adjust the anchor point to be at the center of the browser action button | 390 const NSRect bounds = [button bounds]; |
| 388 // or chevron. | 391 DCHECK([button isFlipped]); |
|
Bons
2010/08/03 21:11:49
isFlipped is deprecated on 10.6 so we don't use it
Scott Hess - ex-Googler
2010/08/03 21:22:50
The -isFlipped of the button affects whether the c
Bons
2010/08/03 21:40:36
Ah you're right. No worries. As needed.
| |
| 389 arrowPoint.x += NSWidth([view frame]) / 2; | 392 NSPoint anchor = NSMakePoint(NSMidX(bounds), |
| 390 // Move the arrow up a bit in the case that it's pointing to the chevron. | 393 NSMaxY(bounds) - kBrowserActionBubbleYOffset); |
| 391 if (isHidden) | 394 return [button convertPoint:anchor toView:nil]; |
| 392 arrowPoint.y += NSHeight([view frame]) / 4; | |
| 393 | |
| 394 return [[view superview] convertPoint:arrowPoint toView:nil]; | |
| 395 } | 395 } |
| 396 | 396 |
| 397 - (BOOL)chevronIsHidden { | 397 - (BOOL)chevronIsHidden { |
| 398 if (!chevronMenuButton_.get()) | 398 if (!chevronMenuButton_.get()) |
| 399 return YES; | 399 return YES; |
| 400 | 400 |
| 401 if (![chevronAnimation_ isAnimating]) | 401 if (![chevronAnimation_ isAnimating]) |
| 402 return [chevronMenuButton_ isHidden]; | 402 return [chevronMenuButton_ isHidden]; |
| 403 | 403 |
| 404 DCHECK([[chevronAnimation_ viewAnimations] count] > 0); | 404 DCHECK([[chevronAnimation_ viewAnimations] count] > 0); |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 if (profile_->IsOffTheRecord()) | 857 if (profile_->IsOffTheRecord()) |
| 858 index = toolbarModel_->IncognitoIndexToOriginal(index); | 858 index = toolbarModel_->IncognitoIndexToOriginal(index); |
| 859 if (index < toolbarModel_->size()) { | 859 if (index < toolbarModel_->size()) { |
| 860 Extension* extension = toolbarModel_->GetExtensionByIndex(index); | 860 Extension* extension = toolbarModel_->GetExtensionByIndex(index); |
| 861 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; | 861 return [buttons_ objectForKey:base::SysUTF8ToNSString(extension->id())]; |
| 862 } | 862 } |
| 863 return nil; | 863 return nil; |
| 864 } | 864 } |
| 865 | 865 |
| 866 @end | 866 @end |
| OLD | NEW |