Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/cocoa/toolbar_controller.mm

Issue 159776: Rewrites the Mac view resizing logic to have the BrowserWindowController... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #import "chrome/browser/cocoa/autocomplete_text_field.h" 10 #import "chrome/browser/cocoa/autocomplete_text_field.h"
11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" 11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
12 #import "chrome/browser/cocoa/gradient_button_cell.h" 12 #import "chrome/browser/cocoa/gradient_button_cell.h"
13 #import "chrome/browser/cocoa/location_bar_view_mac.h" 13 #import "chrome/browser/cocoa/location_bar_view_mac.h"
14 #include "chrome/browser/cocoa/nsimage_cache.h" 14 #include "chrome/browser/cocoa/nsimage_cache.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/toolbar_model.h" 16 #include "chrome/browser/toolbar_model.h"
17 #include "chrome/common/notification_details.h" 17 #include "chrome/common/notification_details.h"
18 #include "chrome/common/notification_observer.h" 18 #include "chrome/common/notification_observer.h"
19 #include "chrome/common/notification_type.h" 19 #include "chrome/common/notification_type.h"
20 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "chrome/common/pref_service.h" 21 #include "chrome/common/pref_service.h"
22 22
23 // Name of image in the bundle for the yellow of the star icon. 23 // Name of image in the bundle for the yellow of the star icon.
24 static NSString* const kStarredImageName = @"starred.pdf"; 24 static NSString* const kStarredImageName = @"starred.pdf";
25 25
26 // Height of the toolbar in pixels when the bookmark bar is closed.
27 static const float kBaseToolbarHeight = 39.0;
28
29 // Overlap (in pixels) between the toolbar and the bookmark bar.
30 static const float kBookmarkBarOverlap = 5.0;
31
26 @interface ToolbarController(Private) 32 @interface ToolbarController(Private)
27 - (void)initCommandStatus:(CommandUpdater*)commands; 33 - (void)initCommandStatus:(CommandUpdater*)commands;
28 - (void)prefChanged:(std::wstring*)prefName; 34 - (void)prefChanged:(std::wstring*)prefName;
29 @end 35 @end
30 36
31 namespace ToolbarControllerInternal { 37 namespace ToolbarControllerInternal {
32 38
33 // A C++ class registered for changes in preferences. Bridges the 39 // A C++ class registered for changes in preferences. Bridges the
34 // notification back to the ToolbarController. 40 // notification back to the ToolbarController.
35 class PrefObserverBridge : public NotificationObserver { 41 class PrefObserverBridge : public NotificationObserver {
(...skipping 11 matching lines...) Expand all
47 ToolbarController* controller_; // weak, owns us 53 ToolbarController* controller_; // weak, owns us
48 }; 54 };
49 55
50 } // namespace 56 } // namespace
51 57
52 @implementation ToolbarController 58 @implementation ToolbarController
53 59
54 - (id)initWithModel:(ToolbarModel*)model 60 - (id)initWithModel:(ToolbarModel*)model
55 commands:(CommandUpdater*)commands 61 commands:(CommandUpdater*)commands
56 profile:(Profile*)profile 62 profile:(Profile*)profile
57 webContentView:(NSView*)webContentView 63 resizeDelegate:(id<ViewResizer>)resizeDelegate
58 infoBarsView:(NSView*)infoBarsView
59 bookmarkDelegate:(id<BookmarkURLOpener>)delegate { 64 bookmarkDelegate:(id<BookmarkURLOpener>)delegate {
60 DCHECK(model && commands && profile); 65 DCHECK(model && commands && profile);
61 if ((self = [super initWithNibName:@"Toolbar" 66 if ((self = [super initWithNibName:@"Toolbar"
62 bundle:mac_util::MainAppBundle()])) { 67 bundle:mac_util::MainAppBundle()])) {
63 toolbarModel_ = model; 68 toolbarModel_ = model;
64 commands_ = commands; 69 commands_ = commands;
65 profile_ = profile; 70 profile_ = profile;
71 resizeDelegate_ = resizeDelegate;
66 bookmarkBarDelegate_ = delegate; 72 bookmarkBarDelegate_ = delegate;
67 webContentView_ = webContentView;
68 infoBarsView_ = infoBarsView;
69 hasToolbar_ = YES; 73 hasToolbar_ = YES;
70 74
71 // Register for notifications about state changes for the toolbar buttons 75 // Register for notifications about state changes for the toolbar buttons
72 commandObserver_.reset(new CommandObserverBridge(self, commands)); 76 commandObserver_.reset(new CommandObserverBridge(self, commands));
73 commandObserver_->ObserveCommand(IDC_BACK); 77 commandObserver_->ObserveCommand(IDC_BACK);
74 commandObserver_->ObserveCommand(IDC_FORWARD); 78 commandObserver_->ObserveCommand(IDC_FORWARD);
75 commandObserver_->ObserveCommand(IDC_RELOAD); 79 commandObserver_->ObserveCommand(IDC_RELOAD);
76 commandObserver_->ObserveCommand(IDC_HOME); 80 commandObserver_->ObserveCommand(IDC_HOME);
77 commandObserver_->ObserveCommand(IDC_STAR); 81 commandObserver_->ObserveCommand(IDC_STAR);
78 } 82 }
(...skipping 23 matching lines...) Expand all
102 PrefService* prefs = profile_->GetPrefs(); 106 PrefService* prefs = profile_->GetPrefs();
103 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get()); 107 showHomeButton_.Init(prefs::kShowHomeButton, prefs, prefObserver_.get());
104 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs, 108 showPageOptionButtons_.Init(prefs::kShowPageOptionsButtons, prefs,
105 prefObserver_.get()); 109 prefObserver_.get());
106 [self showOptionalHomeButton]; 110 [self showOptionalHomeButton];
107 [self showOptionalPageWrenchButtons]; 111 [self showOptionalPageWrenchButtons];
108 112
109 // Create a sub-controller for the bookmark bar. 113 // Create a sub-controller for the bookmark bar.
110 bookmarkBarController_.reset([[BookmarkBarController alloc] 114 bookmarkBarController_.reset([[BookmarkBarController alloc]
111 initWithProfile:profile_ 115 initWithProfile:profile_
112 parentView:[self view] 116 initialWidth:NSWidth([[self view] frame])
113 webContentView:webContentView_ 117 resizeDelegate:self
114 infoBarsView:infoBarsView_ 118 urlDelegate:bookmarkBarDelegate_]);
115 delegate:bookmarkBarDelegate_]);
116 119
117 // Add bookmark bar to the view hierarchy. This also triggers the 120 // Add bookmark bar to the view hierarchy. This also triggers the
118 // nib load. The bookmark bar is defined (in the nib) to be 121 // nib load. The bookmark bar is defined (in the nib) to be
119 // bottom-aligned to it's parent view (among other things), so 122 // bottom-aligned to it's parent view (among other things), so
120 // position and resize properties don't need to be set. 123 // position and resize properties don't need to be set.
121 [[self view] addSubview:[bookmarkBarController_ view]]; 124 [[self view] addSubview:[bookmarkBarController_ view]];
122 } 125 }
123 126
127 - (void)resizeView:(NSView*)view newHeight:(float)height {
128 DCHECK(view == [bookmarkBarController_ view]);
129
130 // The bookmark bar is always rooted at the bottom of the toolbar view, with
131 // width equal to the toolbar's width. The toolbar view is resized to
132 // accomodate the new bookmark bar height.
133 NSRect frame = NSMakeRect(0, 0, [[self view] bounds].size.width, height);
134 [view setFrame:frame];
135
136 float newToolbarHeight = kBaseToolbarHeight + height - kBookmarkBarOverlap;
137 if (newToolbarHeight < kBaseToolbarHeight)
138 newToolbarHeight = kBaseToolbarHeight;
139
140 [resizeDelegate_ resizeView:[self view] newHeight:newToolbarHeight];
141 }
142
124 - (LocationBar*)locationBar { 143 - (LocationBar*)locationBar {
125 return locationBarView_.get(); 144 return locationBarView_.get();
126 } 145 }
127 146
128 - (void)focusLocationBar { 147 - (void)focusLocationBar {
129 if (locationBarView_.get()) { 148 if (locationBarView_.get()) {
130 locationBarView_->FocusLocation(); 149 locationBarView_->FocusLocation();
131 } 150 }
132 } 151 }
133 152
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 forView:pageButton_]; 339 forView:pageButton_];
321 } 340 }
322 341
323 - (IBAction)showWrenchMenu:(id)sender { 342 - (IBAction)showWrenchMenu:(id)sender {
324 [NSMenu popUpContextMenu:wrenchMenu_ 343 [NSMenu popUpContextMenu:wrenchMenu_
325 withEvent:[NSApp currentEvent] 344 withEvent:[NSApp currentEvent]
326 forView:wrenchButton_]; 345 forView:wrenchButton_];
327 } 346 }
328 347
329 @end 348 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/toolbar_controller.h ('k') | chrome/browser/cocoa/toolbar_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698