| 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/toolbar/toolbar_controller.h" | 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 #include "components/omnibox/browser/autocomplete_classifier.h" | 54 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 55 #include "components/omnibox/browser/autocomplete_match.h" | 55 #include "components/omnibox/browser/autocomplete_match.h" |
| 56 #include "components/omnibox/browser/omnibox_view.h" | 56 #include "components/omnibox/browser/omnibox_view.h" |
| 57 #include "components/prefs/pref_service.h" | 57 #include "components/prefs/pref_service.h" |
| 58 #include "components/search_engines/template_url_service.h" | 58 #include "components/search_engines/template_url_service.h" |
| 59 #include "components/url_formatter/url_fixer.h" | 59 #include "components/url_formatter/url_fixer.h" |
| 60 #include "content/public/browser/web_contents.h" | 60 #include "content/public/browser/web_contents.h" |
| 61 #include "grit/components_strings.h" | 61 #include "grit/components_strings.h" |
| 62 #include "grit/theme_resources.h" | 62 #include "grit/theme_resources.h" |
| 63 #import "ui/base/cocoa/menu_controller.h" | 63 #import "ui/base/cocoa/menu_controller.h" |
| 64 #import "ui/base/cocoa/nsview_additions.h" |
| 64 #include "ui/base/l10n/l10n_util.h" | 65 #include "ui/base/l10n/l10n_util.h" |
| 65 #include "ui/base/l10n/l10n_util_mac.h" | 66 #include "ui/base/l10n/l10n_util_mac.h" |
| 66 #include "ui/gfx/geometry/rect.h" | 67 #include "ui/gfx/geometry/rect.h" |
| 67 #include "ui/gfx/image/image.h" | 68 #include "ui/gfx/image/image.h" |
| 68 | 69 |
| 69 using content::OpenURLParams; | 70 using content::OpenURLParams; |
| 70 using content::Referrer; | 71 using content::Referrer; |
| 71 using content::WebContents; | 72 using content::WebContents; |
| 72 | 73 |
| 73 namespace { | 74 namespace { |
| 74 | 75 |
| 75 // Duration of the toolbar animation. | 76 // Duration of the toolbar animation. |
| 76 const NSTimeInterval kToolBarAnimationDuration = 0.12; | 77 const NSTimeInterval kToolBarAnimationDuration = 0.12; |
| 77 | 78 |
| 78 // Height of the toolbar in pixels when the bookmark bar is closed. | |
| 79 const CGFloat kBaseToolbarHeightNormal = 35.0; | |
| 80 | |
| 81 // Height of the location bar. Used for animating the toolbar in and out when | 79 // Height of the location bar. Used for animating the toolbar in and out when |
| 82 // the location bar is displayed stand-alone for bookmark apps. | 80 // the location bar is displayed stand-alone for bookmark apps. |
| 83 const CGFloat kLocationBarHeight = 29.0; | 81 const CGFloat kLocationBarHeight = 29.0; |
| 84 | 82 |
| 85 // The padding above the toolbar elements. This is calculated from the values | 83 // The padding above the toolbar elements. This is calculated from the values |
| 86 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child | 84 // in Toolbar.xib: the height of the toolbar (35) minus the height of the child |
| 87 // elements (29) minus the y-origin of the elements (4). | 85 // elements (29) minus the y-origin of the elements (4). |
| 88 const CGFloat kToolbarElementTopPadding = 2.0; | 86 const CGFloat kToolbarElementTopPadding = 2.0; |
| 89 | 87 |
| 90 // The minimum width of the location bar in pixels. | 88 // The minimum width of the location bar in pixels. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 [reloadButton_ setHandleMiddleClick:YES]; | 319 [reloadButton_ setHandleMiddleClick:YES]; |
| 322 [homeButton_ setHandleMiddleClick:YES]; | 320 [homeButton_ setHandleMiddleClick:YES]; |
| 323 | 321 |
| 324 [self initCommandStatus:commands_]; | 322 [self initCommandStatus:commands_]; |
| 325 [reloadButton_ setCommandUpdater:commands_]; | 323 [reloadButton_ setCommandUpdater:commands_]; |
| 326 | 324 |
| 327 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, | 325 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, |
| 328 profile_, browser_)); | 326 profile_, browser_)); |
| 329 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 327 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 330 | 328 |
| 329 // Adjust the toolbar height if running on Retina - see the comment in |
| 330 // -baseToolbarHeight. |
| 331 CGFloat toolbarHeight = [self baseToolbarHeight]; |
| 332 NSRect toolbarFrame = [[locationBar_ superview] frame]; |
| 333 if (toolbarFrame.size.height != toolbarHeight) { |
| 334 toolbarFrame.size.height = toolbarHeight; |
| 335 [[locationBar_ superview] setFrame:toolbarFrame]; |
| 336 } |
| 337 |
| 331 // Register pref observers for the optional home and page/options buttons | 338 // Register pref observers for the optional home and page/options buttons |
| 332 // and then add them to the toolbar based on those prefs. | 339 // and then add them to the toolbar based on those prefs. |
| 333 PrefService* prefs = profile_->GetPrefs(); | 340 PrefService* prefs = profile_->GetPrefs(); |
| 334 showHomeButton_.Init( | 341 showHomeButton_.Init( |
| 335 prefs::kShowHomeButton, prefs, | 342 prefs::kShowHomeButton, prefs, |
| 336 base::Bind( | 343 base::Bind( |
| 337 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, | 344 &ToolbarControllerInternal::NotificationBridge::OnPreferenceChanged, |
| 338 base::Unretained(notificationBridge_.get()))); | 345 base::Unretained(notificationBridge_.get()))); |
| 339 [self showOptionalHomeButton]; | 346 [self showOptionalHomeButton]; |
| 340 [self installAppMenu]; | 347 [self installAppMenu]; |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 900 } |
| 894 | 901 |
| 895 - (NSPoint)saveCreditCardBubblePoint { | 902 - (NSPoint)saveCreditCardBubblePoint { |
| 896 return locationBarView_->GetSaveCreditCardBubblePoint(); | 903 return locationBarView_->GetSaveCreditCardBubblePoint(); |
| 897 } | 904 } |
| 898 | 905 |
| 899 - (NSPoint)translateBubblePoint { | 906 - (NSPoint)translateBubblePoint { |
| 900 return locationBarView_->GetTranslateBubblePoint(); | 907 return locationBarView_->GetTranslateBubblePoint(); |
| 901 } | 908 } |
| 902 | 909 |
| 910 - (CGFloat)baseToolbarHeight { |
| 911 // Height of the toolbar in pixels when the bookmark bar is closed. |
| 912 const CGFloat baseToolbarHeightNormal = 35.0; |
| 913 |
| 914 // Not all lines are drawn at 2x normal height when running on Retina, which |
| 915 // causes the toolbar controls to be visually 1pt too high within the toolbar |
| 916 // area. It's not possible to adjust the control y-positions by 0.5pt and have |
| 917 // them appear 0.5pt lower (they are still drawn at their original locations), |
| 918 // so instead shave off 1pt from the bottom of the toolbar. Note that there's |
| 919 // an offsetting change in -[BookmarkBarController preferredHeight] to |
| 920 // maintain the proper spacing between bookmark icons and toolbar items. See |
| 921 // https://crbug.com/326245 . |
| 922 return [[self view] cr_lineWidth] == 0.5 ? baseToolbarHeightNormal - 1 |
| 923 : baseToolbarHeightNormal; |
| 924 } |
| 925 |
| 903 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { | 926 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { |
| 904 // With no toolbar, just ignore the compression. | 927 // With no toolbar, just ignore the compression. |
| 905 if (!hasToolbar_) | 928 if (!hasToolbar_) |
| 906 return NSHeight([locationBar_ frame]); | 929 return NSHeight([locationBar_ frame]); |
| 907 | 930 |
| 908 return kBaseToolbarHeightNormal - compressByHeight; | 931 return [self baseToolbarHeight] - compressByHeight; |
| 909 } | 932 } |
| 910 | 933 |
| 911 - (void)setDividerOpacity:(CGFloat)opacity { | 934 - (void)setDividerOpacity:(CGFloat)opacity { |
| 912 ToolbarView* toolbarView = [self toolbarView]; | 935 ToolbarView* toolbarView = [self toolbarView]; |
| 913 [toolbarView setShowsDivider:(opacity > 0 ? YES : NO)]; | 936 [toolbarView setShowsDivider:(opacity > 0 ? YES : NO)]; |
| 914 [toolbarView setDividerOpacity:opacity]; | 937 [toolbarView setDividerOpacity:opacity]; |
| 915 [toolbarView setNeedsDisplay:YES]; | 938 [toolbarView setNeedsDisplay:YES]; |
| 916 } | 939 } |
| 917 | 940 |
| 918 - (BrowserActionsController*)browserActionsController { | 941 - (BrowserActionsController*)browserActionsController { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 - (void)hideDropURLsIndicatorInView:(NSView*)view { | 1004 - (void)hideDropURLsIndicatorInView:(NSView*)view { |
| 982 // Do nothing. | 1005 // Do nothing. |
| 983 } | 1006 } |
| 984 | 1007 |
| 985 // (URLDropTargetController protocol) | 1008 // (URLDropTargetController protocol) |
| 986 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { | 1009 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { |
| 987 return drag_util::IsUnsupportedDropData(profile_, info); | 1010 return drag_util::IsUnsupportedDropData(profile_, info); |
| 988 } | 1011 } |
| 989 | 1012 |
| 990 @end | 1013 @end |
| OLD | NEW |