| 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 = 39.0; | 30 static const float kBaseToolbarHeight = 36.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 = 5.0; | 33 static const float kBookmarkBarOverlap = 7.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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 if ((self = [super initWithNibName:@"Toolbar" | 90 if ((self = [super initWithNibName:@"Toolbar" |
| 91 bundle:mac_util::MainAppBundle()])) { | 91 bundle:mac_util::MainAppBundle()])) { |
| 92 toolbarModel_ = model; | 92 toolbarModel_ = model; |
| 93 commands_ = commands; | 93 commands_ = commands; |
| 94 profile_ = profile; | 94 profile_ = profile; |
| 95 browser_ = browser; | 95 browser_ = browser; |
| 96 resizeDelegate_ = resizeDelegate; | 96 resizeDelegate_ = resizeDelegate; |
| 97 bookmarkBarDelegate_ = delegate; | 97 bookmarkBarDelegate_ = delegate; |
| 98 hasToolbar_ = YES; | 98 hasToolbar_ = YES; |
| 99 | 99 |
| 100 // Register for notifications about state changes for the toolbar buttons | 100 // Register for notificaotions about state changes for the toolbar buttons |
| 101 commandObserver_.reset(new CommandObserverBridge(self, commands)); | 101 commandObserver_.reset(new CommandObserverBridge(self, commands)); |
| 102 commandObserver_->ObserveCommand(IDC_BACK); | 102 commandObserver_->ObserveCommand(IDC_BACK); |
| 103 commandObserver_->ObserveCommand(IDC_FORWARD); | 103 commandObserver_->ObserveCommand(IDC_FORWARD); |
| 104 commandObserver_->ObserveCommand(IDC_RELOAD); | 104 commandObserver_->ObserveCommand(IDC_RELOAD); |
| 105 commandObserver_->ObserveCommand(IDC_HOME); | 105 commandObserver_->ObserveCommand(IDC_HOME); |
| 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()]; |
| 116 [super dealloc]; | 118 [super dealloc]; |
| 117 } | 119 } |
| 118 | 120 |
| 119 // Called after the view is done loading and the outlets have been hooked up. | 121 // Called after the view is done loading and the outlets have been hooked up. |
| 120 // Now we can hook up bridges that rely on UI objects such as the location | 122 // Now we can hook up bridges that rely on UI objects such as the location |
| 121 // bar and button state. | 123 // bar and button state. |
| 122 - (void)awakeFromNib { | 124 - (void)awakeFromNib { |
| 123 [self initCommandStatus:commands_]; | 125 [self initCommandStatus:commands_]; |
| 124 popupPositioner_.reset(new AutocompletePopupPositionerMac(self)); | 126 popupPositioner_.reset(new AutocompletePopupPositionerMac(self)); |
| 125 locationBarView_.reset(new LocationBarViewMac(locationBar_, | 127 locationBarView_.reset(new LocationBarViewMac(locationBar_, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 170 |
| 169 // For a popup window, the toolbar is really just a location bar | 171 // For a popup window, the toolbar is really just a location bar |
| 170 // (see override for [ToolbarController view], below). When going | 172 // (see override for [ToolbarController view], below). When going |
| 171 // fullscreen, we remove the toolbar controller's view from the view | 173 // fullscreen, we remove the toolbar controller's view from the view |
| 172 // hierarchy. Calling [locationBar_ removeFromSuperview] when going | 174 // hierarchy. Calling [locationBar_ removeFromSuperview] when going |
| 173 // fullscreen causes it to get released, making us unhappy | 175 // fullscreen causes it to get released, making us unhappy |
| 174 // (http://crbug.com/18551). We avoid the problem by incrementing | 176 // (http://crbug.com/18551). We avoid the problem by incrementing |
| 175 // the retain count of the location bar; use of the scoped object | 177 // the retain count of the location bar; use of the scoped object |
| 176 // helps us remember to release it. | 178 // helps us remember to release it. |
| 177 locationBarRetainer_.reset([locationBar_ retain]); | 179 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 - (void)removeFromSuperview { |
| 191 NSLog(@"remove"); |
| 192 } |
| 193 - (void)mouseExited:(NSEvent*)theEvent { |
| 194 [[hoveredButton_ cell] setMouseInside:NO animate:YES]; |
| 195 hoveredButton_ = nil; |
| 196 } |
| 197 |
| 198 - (void)mouseMoved:(NSEvent *)theEvent { |
| 199 NSButton *targetView = (NSButton *)[[self view] |
| 200 hitTest:[theEvent locationInWindow]]; |
| 201 if (![targetView isKindOfClass:[NSButton class]]) targetView = nil; |
| 202 if (hoveredButton_ != targetView) { |
| 203 [[hoveredButton_ cell] setMouseInside:NO animate:YES]; |
| 204 [[targetView cell] setMouseInside:YES animate:YES]; |
| 205 hoveredButton_ = targetView; |
| 206 } |
| 207 } |
| 208 |
| 209 - (void)mouseEntered:(NSEvent*)event { |
| 210 [self mouseMoved:event]; |
| 178 } | 211 } |
| 179 | 212 |
| 180 - (void)resizeView:(NSView*)view newHeight:(float)height { | 213 - (void)resizeView:(NSView*)view newHeight:(float)height { |
| 181 DCHECK(view == [bookmarkBarController_ view]); | 214 DCHECK(view == [bookmarkBarController_ view]); |
| 182 | 215 |
| 183 // The bookmark bar is always rooted at the bottom of the toolbar view, with | 216 // The bookmark bar is always rooted at the bottom of the toolbar view, with |
| 184 // width equal to the toolbar's width. The toolbar view is resized to | 217 // width equal to the toolbar's width. The toolbar view is resized to |
| 185 // accomodate the new bookmark bar height. | 218 // accomodate the new bookmark bar height. |
| 186 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height); | 219 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height); |
| 187 [view setFrame:frame]; | 220 [view setFrame:frame]; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 int maxX = NSMaxX([goButton_ frame]); | 444 int maxX = NSMaxX([goButton_ frame]); |
| 412 DCHECK(minX < NSMinX(locationFrame)); | 445 DCHECK(minX < NSMinX(locationFrame)); |
| 413 DCHECK(maxX > NSMaxX(locationFrame)); | 446 DCHECK(maxX > NSMaxX(locationFrame)); |
| 414 | 447 |
| 415 // TODO(shess): The + 1.0 is because the field's visual boundary | 448 // TODO(shess): The + 1.0 is because the field's visual boundary |
| 416 // differs from its on-screen boundary. | 449 // differs from its on-screen boundary. |
| 417 NSRect r = NSMakeRect(minX, NSMinY(locationFrame) + 1.0, maxX - minX, 0); | 450 NSRect r = NSMakeRect(minX, NSMinY(locationFrame) + 1.0, maxX - minX, 0); |
| 418 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil])); | 451 return gfx::Rect(NSRectToCGRect([[self view] convertRect:r toView:nil])); |
| 419 } | 452 } |
| 420 @end | 453 @end |
| OLD | NEW |