| 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 "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" | 11 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
| 12 #import "chrome/browser/cocoa/autocomplete_text_field.h" | 12 #import "chrome/browser/cocoa/autocomplete_text_field.h" |
| 13 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" | 13 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
| 14 #import "chrome/browser/cocoa/back_forward_menu_controller.h" | 14 #import "chrome/browser/cocoa/back_forward_menu_controller.h" |
| 15 #import "chrome/browser/cocoa/gradient_button_cell.h" | 15 #import "chrome/browser/cocoa/gradient_button_cell.h" |
| 16 #import "chrome/browser/cocoa/location_bar_view_mac.h" | 16 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
| 17 #include "chrome/browser/cocoa/nsimage_cache.h" | 17 #include "chrome/browser/cocoa/nsimage_cache.h" |
| 18 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
| 19 #include "chrome/browser/toolbar_model.h" | 19 #include "chrome/browser/toolbar_model.h" |
| 20 #include "chrome/common/notification_details.h" | 20 #include "chrome/common/notification_details.h" |
| 21 #include "chrome/common/notification_observer.h" | 21 #include "chrome/common/notification_observer.h" |
| 22 #include "chrome/common/notification_type.h" | 22 #include "chrome/common/notification_type.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/pref_service.h" | 24 #include "chrome/common/pref_service.h" |
| 25 | 25 |
| 26 // Name of image in the bundle for the yellow of the star icon. | 26 // Name of image in the bundle for the yellow of the star icon. |
| 27 static NSString* const kStarredImageName = @"starred.pdf"; | 27 static NSString* const kStarredImageName = @"starred.pdf"; |
| 28 | 28 |
| 29 // Height of the toolbar in pixels when the bookmark bar is closed. | 29 // Height of the toolbar in pixels when the bookmark bar is closed. |
| 30 static const float kBaseToolbarHeight = 36.0; | 30 static const float kBaseToolbarHeight = 39.0; |
| 31 | 31 |
| 32 // Overlap (in pixels) between the toolbar and the bookmark bar. | 32 // Overlap (in pixels) between the toolbar and the bookmark bar. |
| 33 static const float kBookmarkBarOverlap = 7.0; | 33 static const float kBookmarkBarOverlap = 5.0; |
| 34 | 34 |
| 35 @interface ToolbarController(Private) | 35 @interface ToolbarController(Private) |
| 36 - (void)initCommandStatus:(CommandUpdater*)commands; | 36 - (void)initCommandStatus:(CommandUpdater*)commands; |
| 37 - (void)prefChanged:(std::wstring*)prefName; | 37 - (void)prefChanged:(std::wstring*)prefName; |
| 38 @end | 38 @end |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // A C++ class used to correctly position the autocomplete popup. | 42 // A C++ class used to correctly position the autocomplete popup. |
| 43 class AutocompletePopupPositionerMac : public AutocompletePopupPositioner { | 43 class AutocompletePopupPositionerMac : public AutocompletePopupPositioner { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 commandObserver_->ObserveCommand(IDC_STAR); | 106 commandObserver_->ObserveCommand(IDC_STAR); |
| 107 } | 107 } |
| 108 return self; | 108 return self; |
| 109 } | 109 } |
| 110 | 110 |
| 111 - (void)dealloc { | 111 - (void)dealloc { |
| 112 // Make sure any code in the base class which assumes [self view] is | 112 // Make sure any code in the base class which assumes [self view] is |
| 113 // the "parent" view continues to work. | 113 // the "parent" view continues to work. |
| 114 hasToolbar_ = YES; | 114 hasToolbar_ = YES; |
| 115 | 115 |
| 116 if (trackingArea_.get()) | |
| 117 [[self view] removeTrackingArea:trackingArea_.get()]; | |
| 118 [super dealloc]; | 116 [super dealloc]; |
| 119 } | 117 } |
| 120 | 118 |
| 121 // Called after the view is done loading and the outlets have been hooked up. | 119 // Called after the view is done loading and the outlets have been hooked up. |
| 122 // Now we can hook up bridges that rely on UI objects such as the location | 120 // Now we can hook up bridges that rely on UI objects such as the location |
| 123 // bar and button state. | 121 // bar and button state. |
| 124 - (void)awakeFromNib { | 122 - (void)awakeFromNib { |
| 125 [self initCommandStatus:commands_]; | 123 [self initCommandStatus:commands_]; |
| 126 popupPositioner_.reset(new AutocompletePopupPositionerMac(self)); | 124 popupPositioner_.reset(new AutocompletePopupPositionerMac(self)); |
| 127 locationBarView_.reset(new LocationBarViewMac(locationBar_, | 125 locationBarView_.reset(new LocationBarViewMac(locationBar_, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 168 |
| 171 // For a popup window, the toolbar is really just a location bar | 169 // For a popup window, the toolbar is really just a location bar |
| 172 // (see override for [ToolbarController view], below). When going | 170 // (see override for [ToolbarController view], below). When going |
| 173 // fullscreen, we remove the toolbar controller's view from the view | 171 // fullscreen, we remove the toolbar controller's view from the view |
| 174 // hierarchy. Calling [locationBar_ removeFromSuperview] when going | 172 // hierarchy. Calling [locationBar_ removeFromSuperview] when going |
| 175 // fullscreen causes it to get released, making us unhappy | 173 // fullscreen causes it to get released, making us unhappy |
| 176 // (http://crbug.com/18551). We avoid the problem by incrementing | 174 // (http://crbug.com/18551). We avoid the problem by incrementing |
| 177 // the retain count of the location bar; use of the scoped object | 175 // the retain count of the location bar; use of the scoped object |
| 178 // helps us remember to release it. | 176 // helps us remember to release it. |
| 179 locationBarRetainer_.reset([locationBar_ retain]); | 177 locationBarRetainer_.reset([locationBar_ retain]); |
| 180 trackingArea_.reset( | |
| 181 [[NSTrackingArea alloc] initWithRect:NSZeroRect // Ignored | |
| 182 options:NSTrackingMouseMoved | | |
| 183 NSTrackingInVisibleRect | | |
| 184 NSTrackingMouseEnteredAndExited | | |
| 185 NSTrackingActiveAlways | |
| 186 owner:self | |
| 187 userInfo:nil]); | |
| 188 [[self view] addTrackingArea:trackingArea_.get()]; | |
| 189 } | |
| 190 | |
| 191 - (void)mouseExited:(NSEvent*)theEvent { | |
| 192 [[hoveredButton_ cell] setMouseInside:NO animate:YES]; | |
| 193 hoveredButton_ = nil; | |
| 194 } | |
| 195 | |
| 196 - (void)mouseMoved:(NSEvent *)theEvent { | |
| 197 NSButton *targetView = (NSButton *)[[self view] | |
| 198 hitTest:[theEvent locationInWindow]]; | |
| 199 if (![targetView isKindOfClass:[NSButton class]]) targetView = nil; | |
| 200 if (hoveredButton_ != targetView) { | |
| 201 [[hoveredButton_ cell] setMouseInside:NO animate:YES]; | |
| 202 [[targetView cell] setMouseInside:YES animate:YES]; | |
| 203 hoveredButton_ = targetView; | |
| 204 } | |
| 205 } | |
| 206 | |
| 207 - (void)mouseEntered:(NSEvent*)event { | |
| 208 [self mouseMoved:event]; | |
| 209 } | 178 } |
| 210 | 179 |
| 211 - (void)resizeView:(NSView*)view newHeight:(float)height { | 180 - (void)resizeView:(NSView*)view newHeight:(float)height { |
| 212 DCHECK(view == [bookmarkBarController_ view]); | 181 DCHECK(view == [bookmarkBarController_ view]); |
| 213 | 182 |
| 214 // The bookmark bar is always rooted at the bottom of the toolbar view, with | 183 // The bookmark bar is always rooted at the bottom of the toolbar view, with |
| 215 // width equal to the toolbar's width. The toolbar view is resized to | 184 // width equal to the toolbar's width. The toolbar view is resized to |
| 216 // accomodate the new bookmark bar height. | 185 // accomodate the new bookmark bar height. |
| 217 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height); | 186 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height); |
| 218 [view setFrame:frame]; | 187 [view setFrame:frame]; |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 NSRect locationFrame = [locationBar_ frame]; | 409 NSRect locationFrame = [locationBar_ frame]; |
| 441 int minX = NSMinX([starButton_ frame]); | 410 int minX = NSMinX([starButton_ frame]); |
| 442 int maxX = NSMaxX([goButton_ frame]); | 411 int maxX = NSMaxX([goButton_ frame]); |
| 443 DCHECK(minX < NSMinX(locationFrame)); | 412 DCHECK(minX < NSMinX(locationFrame)); |
| 444 DCHECK(maxX > NSMaxX(locationFrame)); | 413 DCHECK(maxX > NSMaxX(locationFrame)); |
| 445 | 414 |
| 446 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, 0); | 415 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, 0); |
| 447 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil])); | 416 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil])); |
| 448 } | 417 } |
| 449 @end | 418 @end |
| OLD | NEW |