| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/toolbar_controller.h" | 5 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/nsimage_cache_mac.h" | 9 #include "base/nsimage_cache_mac.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "base/gfx/rect.h" | 11 #include "base/gfx/rect.h" |
| 12 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 13 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 14 #include "chrome/browser/bubble_positioner.h" | 14 #include "chrome/browser/bubble_positioner.h" |
| 15 #import "chrome/browser/cocoa/autocomplete_text_field.h" | 15 #import "chrome/browser/cocoa/autocomplete_text_field.h" |
| 16 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" | 16 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
| 17 #import "chrome/browser/cocoa/back_forward_menu_controller.h" | 17 #import "chrome/browser/cocoa/back_forward_menu_controller.h" |
| 18 #import "chrome/browser/cocoa/background_gradient_view.h" |
| 18 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" | 19 #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" |
| 19 #import "chrome/browser/cocoa/extensions/browser_actions_controller.h" | 20 #import "chrome/browser/cocoa/extensions/browser_actions_controller.h" |
| 20 #import "chrome/browser/cocoa/gradient_button_cell.h" | 21 #import "chrome/browser/cocoa/gradient_button_cell.h" |
| 21 #import "chrome/browser/cocoa/location_bar_view_mac.h" | 22 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
| 22 #import "chrome/browser/cocoa/menu_button.h" | 23 #import "chrome/browser/cocoa/menu_button.h" |
| 23 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
| 24 #include "chrome/browser/search_engines/template_url_model.h" | 25 #include "chrome/browser/search_engines/template_url_model.h" |
| 25 #include "chrome/browser/toolbar_model.h" | 26 #include "chrome/browser/toolbar_model.h" |
| 26 #include "chrome/common/notification_details.h" | 27 #include "chrome/common/notification_details.h" |
| 27 #include "chrome/common/notification_observer.h" | 28 #include "chrome/common/notification_observer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 static NSString* const kStarButtonImageName = @"star_Template.pdf"; | 39 static NSString* const kStarButtonImageName = @"star_Template.pdf"; |
| 39 static NSString* const kStarButtonFillingImageName = @"starred.pdf"; | 40 static NSString* const kStarButtonFillingImageName = @"starred.pdf"; |
| 40 static NSString* const kGoButtonGoImageName = @"go_Template.pdf"; | 41 static NSString* const kGoButtonGoImageName = @"go_Template.pdf"; |
| 41 static NSString* const kGoButtonStopImageName = @"stop_Template.pdf"; | 42 static NSString* const kGoButtonStopImageName = @"stop_Template.pdf"; |
| 42 static NSString* const kPageButtonImageName = @"menu_page_Template.pdf"; | 43 static NSString* const kPageButtonImageName = @"menu_page_Template.pdf"; |
| 43 static NSString* const kWrenchButtonImageName = @"menu_chrome_Template.pdf"; | 44 static NSString* const kWrenchButtonImageName = @"menu_chrome_Template.pdf"; |
| 44 | 45 |
| 45 // Height of the toolbar in pixels when the bookmark bar is closed. | 46 // Height of the toolbar in pixels when the bookmark bar is closed. |
| 46 static const float kBaseToolbarHeight = 36.0; | 47 static const float kBaseToolbarHeight = 36.0; |
| 47 | 48 |
| 48 // Overlap (in pixels) between the toolbar and the bookmark bar. | |
| 49 static const float kBookmarkBarOverlap = 6.0; | |
| 50 | |
| 51 @interface ToolbarController(Private) | 49 @interface ToolbarController(Private) |
| 52 - (void)initCommandStatus:(CommandUpdater*)commands; | 50 - (void)initCommandStatus:(CommandUpdater*)commands; |
| 53 - (void)prefChanged:(std::wstring*)prefName; | 51 - (void)prefChanged:(std::wstring*)prefName; |
| 52 - (BackgroundGradientView*)backgroundGradientView; |
| 54 - (void)browserActionsChanged; | 53 - (void)browserActionsChanged; |
| 55 - (void)adjustLocationAndGoPositionsBy:(CGFloat)dX; | 54 - (void)adjustLocationAndGoPositionsBy:(CGFloat)dX; |
| 56 @end | 55 @end |
| 57 | 56 |
| 58 namespace { | 57 namespace { |
| 59 | 58 |
| 60 // A C++ class used to correctly position the omnibox. | 59 // A C++ class used to correctly position the omnibox. |
| 61 class BubblePositionerMac : public BubblePositioner { | 60 class BubblePositionerMac : public BubblePositioner { |
| 62 public: | 61 public: |
| 63 BubblePositionerMac(ToolbarController* controller) | 62 BubblePositionerMac(ToolbarController* controller) |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Make location bar not editable when in a pop-up. | 344 // Make location bar not editable when in a pop-up. |
| 346 [locationBar_ setEditable:toolbar]; | 345 [locationBar_ setEditable:toolbar]; |
| 347 } | 346 } |
| 348 | 347 |
| 349 - (NSView*)view { | 348 - (NSView*)view { |
| 350 if (hasToolbar_) | 349 if (hasToolbar_) |
| 351 return [super view]; | 350 return [super view]; |
| 352 return locationBar_; | 351 return locationBar_; |
| 353 } | 352 } |
| 354 | 353 |
| 354 // (Private) Returns the backdrop to the toolbar. |
| 355 - (BackgroundGradientView*)backgroundGradientView { | 355 - (BackgroundGradientView*)backgroundGradientView { |
| 356 // We really do mean |[super view]|; see our override of |-view|. |
| 357 DCHECK([[super view] isKindOfClass:[BackgroundGradientView class]]); |
| 356 return (BackgroundGradientView*)[super view]; | 358 return (BackgroundGradientView*)[super view]; |
| 357 } | 359 } |
| 358 | 360 |
| 359 - (id)customFieldEditorForObject:(id)obj { | 361 - (id)customFieldEditorForObject:(id)obj { |
| 360 if (obj == locationBar_) { | 362 if (obj == locationBar_) { |
| 361 // Lazilly construct Field editor, Cocoa UI code always runs on the | 363 // Lazilly construct Field editor, Cocoa UI code always runs on the |
| 362 // same thread, so there shoudn't be a race condition here. | 364 // same thread, so there shoudn't be a race condition here. |
| 363 if (autocompleteTextFieldEditor_.get() == nil) { | 365 if (autocompleteTextFieldEditor_.get() == nil) { |
| 364 autocompleteTextFieldEditor_.reset( | 366 autocompleteTextFieldEditor_.reset( |
| 365 [[AutocompleteTextFieldEditor alloc] init]); | 367 [[AutocompleteTextFieldEditor alloc] init]); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 NSRect locationFrame = [locationBar_ frame]; | 509 NSRect locationFrame = [locationBar_ frame]; |
| 508 locationFrame.size.width += dX; | 510 locationFrame.size.width += dX; |
| 509 [locationBar_ setFrame:locationFrame]; | 511 [locationBar_ setFrame:locationFrame]; |
| 510 } | 512 } |
| 511 | 513 |
| 512 - (NSRect)starButtonInWindowCoordinates { | 514 - (NSRect)starButtonInWindowCoordinates { |
| 513 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds] | 515 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds] |
| 514 fromView:starButton_]; | 516 fromView:starButton_]; |
| 515 } | 517 } |
| 516 | 518 |
| 517 - (void)setShouldBeCompressed:(BOOL)compressed { | 519 - (void)setHeightCompression:(CGFloat)compressByHeight { |
| 518 CGFloat newToolbarHeight = kBaseToolbarHeight; | 520 // Resize. |
| 519 if (compressed) | 521 CGFloat newToolbarHeight = kBaseToolbarHeight - compressByHeight; |
| 520 newToolbarHeight -= kBookmarkBarOverlap; | 522 [resizeDelegate_ resizeView:[self view] newHeight:newToolbarHeight]; |
| 523 } |
| 521 | 524 |
| 522 [resizeDelegate_ resizeView:[self view] newHeight:newToolbarHeight]; | 525 - (void)setShowsDivider:(BOOL)showDivider { |
| 526 [[self backgroundGradientView] setShowsDivider:showDivider]; |
| 523 } | 527 } |
| 524 | 528 |
| 525 - (NSString*)view:(NSView*)view | 529 - (NSString*)view:(NSView*)view |
| 526 stringForToolTip:(NSToolTipTag)tag | 530 stringForToolTip:(NSToolTipTag)tag |
| 527 point:(NSPoint)point | 531 point:(NSPoint)point |
| 528 userData:(void*)userData { | 532 userData:(void*)userData { |
| 529 DCHECK(view == goButton_); | 533 DCHECK(view == goButton_); |
| 530 | 534 |
| 531 // Following chrome/browser/views/go_button.cc: GoButton::GetTooltipText() | 535 // Following chrome/browser/views/go_button.cc: GoButton::GetTooltipText() |
| 532 | 536 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 594 |
| 591 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, | 595 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, |
| 592 NSHeight(locationFrame)); | 596 NSHeight(locationFrame)); |
| 593 gfx::Rect stack_bounds( | 597 gfx::Rect stack_bounds( |
| 594 NSRectToCGRect([[self view] convertRect:r toView:nil])); | 598 NSRectToCGRect([[self view] convertRect:r toView:nil])); |
| 595 // Inset the bounds to just inside the visible edges (see comment above). | 599 // Inset the bounds to just inside the visible edges (see comment above). |
| 596 stack_bounds.Inset(kLocationStackEdgeWidth, 0); | 600 stack_bounds.Inset(kLocationStackEdgeWidth, 0); |
| 597 return stack_bounds; | 601 return stack_bounds; |
| 598 } | 602 } |
| 599 @end | 603 @end |
| OLD | NEW |