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

Side by Side Diff: chrome/browser/cocoa/browser_window_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 #include <Carbon/Carbon.h> 5 #include <Carbon/Carbon.h>
6 6
7 #include "base/mac_util.h" 7 #include "base/mac_util.h"
8 #include "base/scoped_nsdisable_screen_updates.h" 8 #include "base/scoped_nsdisable_screen_updates.h"
9 #import "base/scoped_nsobject.h" 9 #import "base/scoped_nsobject.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e; 59 - (void)setContentBorderThickness:(CGFloat)b forEdge:(NSRectEdge)e;
60 60
61 - (void)setBottomCornerRounded:(BOOL)rounded; 61 - (void)setBottomCornerRounded:(BOOL)rounded;
62 62
63 - (NSRect)_growBoxRect; 63 - (NSRect)_growBoxRect;
64 @end 64 @end
65 65
66 66
67 @interface BrowserWindowController(Private) 67 @interface BrowserWindowController(Private)
68 68
69 - (void)positionInfoBar;
70 - (void)positionBar; // toolbar or URL bar
71 - (void)removeBar; // toolbar or URL bar
72
73 // Leopard's gradient heuristic gets confused by our tabs and makes the title 69 // Leopard's gradient heuristic gets confused by our tabs and makes the title
74 // gradient jump when creating a tab that is less than a tab width from the 70 // gradient jump when creating a tab that is less than a tab width from the
75 // right side of the screen. This function disables Leopard's gradient 71 // right side of the screen. This function disables Leopard's gradient
76 // heuristic. 72 // heuristic.
77 - (void)fixWindowGradient; 73 - (void)fixWindowGradient;
78 74
79 // Called by the Notification Center whenever the tabContentArea's
80 // frame changes. Re-positions the bookmark bar and the find bar.
81 - (void)tabContentAreaFrameChanged:(id)sender;
82
83 // Saves the window's position in the local state preferences. 75 // Saves the window's position in the local state preferences.
84 - (void)saveWindowPositionIfNeeded; 76 - (void)saveWindowPositionIfNeeded;
85 77
86 // Saves the window's position to the given pref service. 78 // Saves the window's position to the given pref service.
87 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; 79 - (void)saveWindowPositionToPrefs:(PrefService*)prefs;
88 80
89 // We need to adjust where sheets come out of the window, as by default they 81 // We need to adjust where sheets come out of the window, as by default they
90 // erupt from the omnibox, which is rather weird. 82 // erupt from the omnibox, which is rather weird.
91 - (NSRect)window:(NSWindow*)window 83 - (NSRect)window:(NSWindow*)window
92 willPositionSheet:(NSWindow*)sheet 84 willPositionSheet:(NSWindow*)sheet
93 usingRect:(NSRect)defaultSheetRect; 85 usingRect:(NSRect)defaultSheetRect;
94 86
95 // Assign a theme to the window. 87 // Assign a theme to the window.
96 - (void)setTheme; 88 - (void)setTheme;
97 89
98 // Theme up the window. 90 // Theme up the window.
99 - (void)applyTheme; 91 - (void)applyTheme;
92
93 // Repositions the windows subviews.
94 - (void)layoutSubviews;
100 @end 95 @end
101 96
102 97
103 @implementation BrowserWindowController 98 @implementation BrowserWindowController
104 99
105 // Load the browser window nib and do any Cocoa-specific initialization. 100 // Load the browser window nib and do any Cocoa-specific initialization.
106 // Takes ownership of |browser|. Note that the nib also sets this controller 101 // Takes ownership of |browser|. Note that the nib also sets this controller
107 // up as the window's delegate. 102 // up as the window's delegate.
108 - (id)initWithBrowser:(Browser*)browser { 103 - (id)initWithBrowser:(Browser*)browser {
109 return [self initWithBrowser:browser takeOwnership:YES]; 104 return [self initWithBrowser:browser takeOwnership:YES];
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Create a controller for the tab strip, giving it the model object for 153 // Create a controller for the tab strip, giving it the model object for
159 // this window's Browser and the tab strip view. The controller will handle 154 // this window's Browser and the tab strip view. The controller will handle
160 // registering for the appropriate tab notifications from the back-end and 155 // registering for the appropriate tab notifications from the back-end and
161 // managing the creation of new tabs. 156 // managing the creation of new tabs.
162 tabStripController_.reset([[TabStripController alloc] 157 tabStripController_.reset([[TabStripController alloc]
163 initWithView:[self tabStripView] 158 initWithView:[self tabStripView]
164 switchView:[self tabContentArea] 159 switchView:[self tabContentArea]
165 model:browser_->tabstrip_model()]); 160 model:browser_->tabstrip_model()]);
166 161
167 // Create the infobar container view, so we can pass it to the 162 // Create the infobar container view, so we can pass it to the
168 // ToolbarController, but do not position the view until after the 163 // ToolbarController.
169 // toolbar is in place, as positionToolbar will move the tab content area.
170 infoBarContainerController_.reset( 164 infoBarContainerController_.reset(
171 [[InfoBarContainerController alloc] 165 [[InfoBarContainerController alloc]
172 initWithTabStripModel:(browser_->tabstrip_model()) 166 initWithTabStripModel:(browser_->tabstrip_model())
173 browserWindowController:self]); 167 resizeDelegate:self]);
168 [[[self window] contentView] addSubview:[infoBarContainerController_ view]];
174 169
175 // Create a controller for the toolbar, giving it the toolbar model object 170 // Create a controller for the toolbar, giving it the toolbar model object
176 // and the toolbar view from the nib. The controller will handle 171 // and the toolbar view from the nib. The controller will handle
177 // registering for the appropriate command state changes from the back-end. 172 // registering for the appropriate command state changes from the back-end.
178 toolbarController_.reset([[ToolbarController alloc] 173 toolbarController_.reset([[ToolbarController alloc]
179 initWithModel:browser->toolbar_model() 174 initWithModel:browser->toolbar_model()
180 commands:browser->command_updater() 175 commands:browser->command_updater()
181 profile:browser->profile() 176 profile:browser->profile()
182 webContentView:[self tabContentArea] 177 resizeDelegate:self
183 infoBarsView:[infoBarContainerController_ view]
184 bookmarkDelegate:self]); 178 bookmarkDelegate:self]);
185 // If we are a pop-up, we have a titlebar and no toolbar. 179 // If we are a pop-up, we have a titlebar and no toolbar.
186 if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) && 180 if (!browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) &&
187 browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) { 181 browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR)) {
188 [toolbarController_ setHasToolbar:NO]; 182 [toolbarController_ setHasToolbar:NO];
189 } 183 }
190 [self positionBar]; 184 [[[self window] contentView] addSubview:[toolbarController_ view]];
185
191 [self fixWindowGradient]; 186 [self fixWindowGradient];
192 187
193 // Put the infobar container view into the window above the 188 // Force a relayout of all the various bars.
194 // tabcontentarea. There are no infobars when starting up, so its 189 [self layoutSubviews];
195 // initial height is 0.
196 [self positionInfoBar];
197
198 // Register ourselves for frame changed notifications from the
199 // tabContentArea. This has to come after all of the resizing and
200 // positioning above.
201 [[NSNotificationCenter defaultCenter]
202 addObserver:self
203 selector:@selector(tabContentAreaFrameChanged:)
204 name:nil
205 object:[self tabContentArea]];
206 190
207 // Create the bridge for the status bubble. 191 // Create the bridge for the status bubble.
208 statusBubble_.reset(new StatusBubbleMac([self window], self)); 192 statusBubble_.reset(new StatusBubbleMac([self window], self));
209 193
210 #if 0 194 #if 0
211 // Move all buttons down two pixels for visual balance. 195 // Move all buttons down two pixels for visual balance.
212 // TODO(alcor): remove this if we can't prevent window resize from breaking. 196 // TODO(alcor): remove this if we can't prevent window resize from breaking.
213 NSArray* buttons = 197 NSArray* buttons =
214 [NSArray arrayWithObjects: 198 [NSArray arrayWithObjects:
215 [[self window] standardWindowButton:NSWindowCloseButton], 199 [[self window] standardWindowButton:NSWindowCloseButton],
(...skipping 13 matching lines...) Expand all
229 [downloadShelfController_ exiting]; 213 [downloadShelfController_ exiting];
230 214
231 // Under certain testing configurations we may not actually own the browser. 215 // Under certain testing configurations we may not actually own the browser.
232 if (ownsBrowser_ == NO) 216 if (ownsBrowser_ == NO)
233 browser_.release(); 217 browser_.release();
234 // Since |window_| outlives our obj-c shutdown sequence, clear out the 218 // Since |window_| outlives our obj-c shutdown sequence, clear out the
235 // delegate so nothing tries to call us back in the meantime as part of 219 // delegate so nothing tries to call us back in the meantime as part of
236 // window destruction. 220 // window destruction.
237 [window_ setDelegate:nil]; 221 [window_ setDelegate:nil];
238 222
239 [[NSNotificationCenter defaultCenter] removeObserver:self];
240 [super dealloc]; 223 [super dealloc];
241 } 224 }
242 225
243 // Access the C++ bridge between the NSWindow and the rest of Chromium 226 // Access the C++ bridge between the NSWindow and the rest of Chromium
244 - (BrowserWindow*)browserWindow { 227 - (BrowserWindow*)browserWindow {
245 return windowShim_.get(); 228 return windowShim_.get();
246 } 229 }
247 230
248 - (void)destroyBrowser { 231 - (void)destroyBrowser {
249 [NSApp removeWindowsItem:[self window]]; 232 [NSApp removeWindowsItem:[self window]];
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return; 314 return;
332 315
333 // We need to deactivate the controls (in the "WebView"). To do this, get the 316 // We need to deactivate the controls (in the "WebView"). To do this, get the
334 // selected TabContents's RenderWidgetHostView and tell it to deactivate. 317 // selected TabContents's RenderWidgetHostView and tell it to deactivate.
335 if (TabContents* contents = browser_->GetSelectedTabContents()) { 318 if (TabContents* contents = browser_->GetSelectedTabContents()) {
336 if (RenderWidgetHostView* rwhv = contents->render_widget_host_view()) 319 if (RenderWidgetHostView* rwhv = contents->render_widget_host_view())
337 rwhv->SetActive(false); 320 rwhv->SetActive(false);
338 } 321 }
339 } 322 }
340 323
341
342
343 // Called when the user clicks the zoom button (or selects it from the Window 324 // Called when the user clicks the zoom button (or selects it from the Window
344 // menu). Zoom to the appropriate size based on the content. Make sure we 325 // menu). Zoom to the appropriate size based on the content. Make sure we
345 // enforce a minimum width to ensure websites with small intrinsic widths 326 // enforce a minimum width to ensure websites with small intrinsic widths
346 // (such as google.com) don't end up with a wee window. Enforce a max width 327 // (such as google.com) don't end up with a wee window. Enforce a max width
347 // that leaves room for icons on the right side. Use the full (usable) height 328 // that leaves room for icons on the right side. Use the full (usable) height
348 // regardless. 329 // regardless.
349 - (NSRect)windowWillUseStandardFrame:(NSWindow*)window 330 - (NSRect)windowWillUseStandardFrame:(NSWindow*)window
350 defaultFrame:(NSRect)frame { 331 defaultFrame:(NSRect)frame {
351 // If the shift key is down, maximize. Hopefully this should make the 332 // If the shift key is down, maximize. Hopefully this should make the
352 // "switchers" happy. 333 // "switchers" happy.
(...skipping 12 matching lines...) Expand all
365 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents(); 346 TabContents* contents = browser_->tabstrip_model()->GetSelectedTabContents();
366 if (contents) { 347 if (contents) {
367 int intrinsicWidth = contents->view()->preferred_width() + kScrollbarWidth; 348 int intrinsicWidth = contents->view()->preferred_width() + kScrollbarWidth;
368 int tempWidth = std::max(intrinsicWidth, kMinimumIntrinsicWidth); 349 int tempWidth = std::max(intrinsicWidth, kMinimumIntrinsicWidth);
369 frame.size.width = std::min(tempWidth, kMaxWidth); 350 frame.size.width = std::min(tempWidth, kMaxWidth);
370 frame.size.height = screenSize.height; 351 frame.size.height = screenSize.height;
371 } 352 }
372 return frame; 353 return frame;
373 } 354 }
374 355
356 // Main method to resize browser window subviews. This method should be called
357 // when resizing any child of the content view, rather than resizing the views
358 // directly. If the view is already the correct height, does not force a
359 // relayout.
360 - (void)resizeView:(NSView*)view newHeight:(float)height {
361 // We should only ever be called for one of the following three views.
362 // |downloadShelfController_| may be nil.
363 DCHECK(view);
364 DCHECK(view == [toolbarController_ view] ||
365 view == [infoBarContainerController_ view] ||
366 view == [downloadShelfController_ view]);
367
368 // Change the height of the view and call layoutViews. We set the height here
369 // without regard to where the view is on the screen or whether it needs to
370 // "grow up" or "grow down." The below call to layoutSubviews will position
371 // each view correctly.
372 NSRect frame = [view frame];
373 if (frame.size.height == height)
374 return;
375
376 frame.size.height = height;
377 // TODO(rohitrao): Determine if calling setFrame: twice is bad.
378 [view setFrame:frame];
379 [self layoutSubviews];
380 }
381
375 // Update a toggle state for an NSMenuItem if modified. 382 // Update a toggle state for an NSMenuItem if modified.
376 // Take care to insure |item| looks like a NSMenuItem. 383 // Take care to insure |item| looks like a NSMenuItem.
377 // Called by validateUserInterfaceItem:. 384 // Called by validateUserInterfaceItem:.
378 - (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item { 385 - (void)updateToggleStateWithTag:(NSInteger)tag forItem:(id)item {
379 if (![item respondsToSelector:@selector(state)] || 386 if (![item respondsToSelector:@selector(state)] ||
380 ![item respondsToSelector:@selector(setState:)]) 387 ![item respondsToSelector:@selector(setState:)])
381 return; 388 return;
382 389
383 // On Windows this logic happens in bookmark_bar_view.cc. On the 390 // On Windows this logic happens in bookmark_bar_view.cc. On the
384 // Mac we're a lot more MVC happy so we've moved it into a 391 // Mac we're a lot more MVC happy so we've moved it into a
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 708 }
702 709
703 - (BOOL)isDownloadShelfVisible { 710 - (BOOL)isDownloadShelfVisible {
704 return downloadShelfController_ != nil && 711 return downloadShelfController_ != nil &&
705 [downloadShelfController_ isVisible]; 712 [downloadShelfController_ isVisible];
706 } 713 }
707 714
708 - (DownloadShelfController*)downloadShelf { 715 - (DownloadShelfController*)downloadShelf {
709 if (!downloadShelfController_.get()) { 716 if (!downloadShelfController_.get()) {
710 downloadShelfController_.reset([[DownloadShelfController alloc] 717 downloadShelfController_.reset([[DownloadShelfController alloc]
711 initWithBrowser:browser_.get() contentArea:[self tabContentArea]]); 718 initWithBrowser:browser_.get() resizeDelegate:self]);
719 [[[self window] contentView] addSubview:[downloadShelfController_ view]];
720 [downloadShelfController_ show:nil];
712 } 721 }
713 return downloadShelfController_; 722 return downloadShelfController_;
714 } 723 }
715 724
716 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController { 725 - (void)addFindBar:(FindBarCocoaController*)findBarCocoaController {
717 // Shouldn't call addFindBar twice. 726 // Shouldn't call addFindBar twice.
718 DCHECK(!findBarCocoaController_.get()); 727 DCHECK(!findBarCocoaController_.get());
719 728
720 // Create a controller for the findbar. 729 // Create a controller for the findbar.
721 findBarCocoaController_.reset([findBarCocoaController retain]); 730 findBarCocoaController_.reset([findBarCocoaController retain]);
722 [[[self window] contentView] addSubview:[findBarCocoaController_ view]]; 731 [[[self window] contentView] addSubview:[findBarCocoaController_ view]
723 [findBarCocoaController_ positionFindBarView:[self tabContentArea]]; 732 positioned:NSWindowAbove
733 relativeTo:[toolbarController_ view]];
734 [findBarCocoaController_
735 positionFindBarView:[infoBarContainerController_ view]];
724 } 736 }
725 737
726 // Adjust the UI for fullscreen mode. E.g. when going fullscreen, 738 // Adjust the UI for fullscreen mode. E.g. when going fullscreen,
727 // remove the toolbar. When stopping fullscreen, add it back in. 739 // remove the toolbar. When stopping fullscreen, add it back in.
728 - (void)adjustUIForFullscreen:(BOOL)fullscreen { 740 - (void)adjustUIForFullscreen:(BOOL)fullscreen {
729 if (fullscreen) { 741 if (fullscreen) {
730 // Disable showing of the bookmark bar. This does not toggle the 742 // Disable showing of the bookmark bar. This does not toggle the
731 // preference. 743 // preference.
744 // TODO(jrg): Is this still necessary?
732 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:NO]; 745 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:NO];
733 // Make room for more content area. 746 // Make room for more content area.
734 [self removeBar]; 747 [[toolbarController_ view] removeFromSuperview];
735 // Hide the menubar, and allow it to un-hide when moving the mouse 748 // Hide the menubar, and allow it to un-hide when moving the mouse
736 // to the top of the screen. Does this eliminate the need for an 749 // to the top of the screen. Does this eliminate the need for an
737 // info bubble describing how to exit fullscreen mode? 750 // info bubble describing how to exit fullscreen mode?
738 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 751 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
739 } else { 752 } else {
740 SetSystemUIMode(kUIModeNormal, 0); 753 SetSystemUIMode(kUIModeNormal, 0);
741 [self positionBar]; 754 [[[self window] contentView] addSubview:[toolbarController_ view]];
755 // TODO(jrg): Is this still necessary?
742 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:YES]; 756 [[toolbarController_ bookmarkBarController] setBookmarkBarEnabled:YES];
743 } 757 }
758
759 // Force a relayout.
760 [self layoutSubviews];
744 } 761 }
745 762
746 - (NSWindow*)fullscreenWindow { 763 - (NSWindow*)fullscreenWindow {
747 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]] 764 return [[[FullscreenWindow alloc] initForScreen:[[self window] screen]]
748 autorelease]; 765 autorelease];
749 } 766 }
750 767
751 - (void)setFullscreen:(BOOL)fullscreen { 768 - (void)setFullscreen:(BOOL)fullscreen {
752 fullscreen_ = fullscreen; 769 fullscreen_ = fullscreen;
753 if (fullscreen) { 770 if (fullscreen) {
754 // Minimize our UI
755 [self adjustUIForFullscreen:fullscreen];
756 // Move content to a new fullscreen window 771 // Move content to a new fullscreen window
757 NSView* content = [[self window] contentView]; 772 NSView* content = [[self window] contentView];
758 fullscreen_window_.reset([[self fullscreenWindow] retain]); 773 fullscreen_window_.reset([[self fullscreenWindow] retain]);
759 [content removeFromSuperview]; 774 [content removeFromSuperview];
760 [fullscreen_window_ setContentView:content]; 775 [fullscreen_window_ setContentView:content];
761 [self setWindow:fullscreen_window_.get()]; 776 [self setWindow:fullscreen_window_.get()];
777 // Minimize our UI. This call triggers a relayout, so it needs to come
778 // after we move the contentview to the new window.
779 [self adjustUIForFullscreen:fullscreen];
762 // Show one window, hide the other. 780 // Show one window, hide the other.
763 [fullscreen_window_ makeKeyAndOrderFront:self]; 781 [fullscreen_window_ makeKeyAndOrderFront:self];
764 [content setNeedsDisplay:YES]; 782 [content setNeedsDisplay:YES];
765 [window_ orderOut:self]; 783 [window_ orderOut:self];
766 } else { 784 } else {
767 [self adjustUIForFullscreen:fullscreen];
768 NSView* content = [fullscreen_window_ contentView]; 785 NSView* content = [fullscreen_window_ contentView];
769 [content removeFromSuperview]; 786 [content removeFromSuperview];
770 [window_ setContentView:content]; 787 [window_ setContentView:content];
771 [self setWindow:window_.get()]; 788 [self setWindow:window_.get()];
789 // This call triggers a relayout, so it needs to come after we move the
790 // contentview to the new window.
791 [self adjustUIForFullscreen:fullscreen];
772 [content setNeedsDisplay:YES]; 792 [content setNeedsDisplay:YES];
773 793
774 // With this call, valgrind yells at me about "Conditional jump or 794 // With this call, valgrind yells at me about "Conditional jump or
775 // move depends on uninitialised value(s)". The error happens in 795 // move depends on uninitialised value(s)". The error happens in
776 // -[NSThemeFrame drawOverlayRect:]. I'm pretty convinced this is 796 // -[NSThemeFrame drawOverlayRect:]. I'm pretty convinced this is
777 // an Apple bug, but there is no visual impact. I have been 797 // an Apple bug, but there is no visual impact. I have been
778 // unable to tickle it away with other window or view manipulation 798 // unable to tickle it away with other window or view manipulation
779 // Cocoa calls. Stack added to suppressions_mac.txt. 799 // Cocoa calls. Stack added to suppressions_mac.txt.
780 [window_ makeKeyAndOrderFront:self]; 800 [window_ makeKeyAndOrderFront:self];
781 801
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 windowShim_->UpdateTitleBar(); 864 windowShim_->UpdateTitleBar();
845 } 865 }
846 866
847 - (void)userChangedTheme { 867 - (void)userChangedTheme {
848 [self setTheme]; 868 [self setTheme];
849 [self applyTheme]; 869 [self applyTheme];
850 870
851 [tabStripController_ userChangedTheme]; 871 [tabStripController_ userChangedTheme];
852 } 872 }
853 873
854 // TODO(rohitrao, jrg): Move this logic out of BrowserWindowController?
855 - (void)infoBarResized:(float)newHeight {
856 // The top edge of the infobar is fixed.
857 NSView* infoBarView = [infoBarContainerController_ view];
858 NSRect infoBarFrame = [infoBarView frame];
859 int maxY = NSMaxY(infoBarFrame);
860 int minY = maxY - newHeight;
861
862 [infoBarView setFrame:NSMakeRect(infoBarFrame.origin.x, minY,
863 infoBarFrame.size.width, newHeight)];
864
865 NSRect contentFrame = [[self tabContentArea] frame];
866 contentFrame.size.height = minY - contentFrame.origin.y;
867 [[self tabContentArea] setFrame:contentFrame];
868 }
869
870 - (GTMTheme *)gtm_themeForWindow:(NSWindow*)window { 874 - (GTMTheme *)gtm_themeForWindow:(NSWindow*)window {
871 return theme_ ? theme_ : [GTMTheme defaultTheme]; 875 return theme_ ? theme_ : [GTMTheme defaultTheme];
872 } 876 }
873 877
874 @end 878 @end
875 879
876 @implementation BrowserWindowController (Private) 880 @implementation BrowserWindowController (Private)
877 881
878 // TODO(rohitrao, jrg): Move this logic out of BrowserWindowController?
879 - (void)positionInfoBar {
880 NSView* infoBarView = [infoBarContainerController_ view];
881 NSRect infoBarFrame = [[self tabContentArea] frame];
882 infoBarFrame.origin.y = NSMaxY(infoBarFrame);
883 infoBarFrame.size.height = 0;
884 [infoBarView setFrame:infoBarFrame];
885 [[[self window] contentView] addSubview:infoBarView];
886 }
887
888 // If |add| is YES:
889 // Position |barView| below the tab strip, but not as a sibling. The
890 // toolbar or titlebar is part of the window's contentView, mainly
891 // because we want the opacity during drags to be the same as the web
892 // content. This can be used for either the initial add or a
893 // reposition.
894 // If |add| is NO:
895 // Remove the toolbar or titlebar from it's parent view (the window's
896 // content view). Called when going fullscreen and we need to
897 // minimize UI.
898 - (void)positionOrRemoveBar:(BOOL)add {
899 NSView* barView = [toolbarController_ view];
900 NSRect barFrame = [barView frame];
901 NSView* contentView = [self tabContentArea];
902 NSRect contentFrame = [contentView frame];
903
904 // Shrink or grow the content area by the height of the toolbar.
905 if (add)
906 contentFrame.size.height -= barFrame.size.height;
907 else
908 contentFrame.size.height += barFrame.size.height;
909 [contentView setFrame:contentFrame];
910
911 if (add) {
912 // Move the toolbar above the content area, within the window's content view
913 // (as opposed to the tab strip, which is a sibling).
914 barFrame.origin.y = NSMaxY(contentFrame);
915 barFrame.origin.x = 0;
916 barFrame.size.width = contentFrame.size.width;
917 [barView setFrame:barFrame];
918 [[[self window] contentView] addSubview:barView];
919 } else {
920 [barView removeFromSuperview];
921 }
922 }
923
924 - (void)positionBar {
925 [self positionOrRemoveBar:YES];
926 }
927
928 - (void)removeBar {
929 [self positionOrRemoveBar:NO];
930 }
931
932 // If the browser is in incognito mode, install the image view to decorate 882 // If the browser is in incognito mode, install the image view to decorate
933 // the window at the upper right. Use the same base y coordinate as the 883 // the window at the upper right. Use the same base y coordinate as the
934 // tab strip. 884 // tab strip.
935 - (void)installIncognitoBadge { 885 - (void)installIncognitoBadge {
936 if (!browser_->profile()->IsOffTheRecord()) 886 if (!browser_->profile()->IsOffTheRecord())
937 return; 887 return;
938 // Don't install if we're not a normal browser (ie, a popup). 888 // Don't install if we're not a normal browser (ie, a popup).
939 if (![self isNormalWindow]) 889 if (![self isNormalWindow])
940 return; 890 return;
941 891
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 NSWindow* win = [self window]; 923 NSWindow* win = [self window];
974 if ([win respondsToSelector:@selector( 924 if ([win respondsToSelector:@selector(
975 setAutorecalculatesContentBorderThickness:forEdge:)] && 925 setAutorecalculatesContentBorderThickness:forEdge:)] &&
976 [win respondsToSelector:@selector( 926 [win respondsToSelector:@selector(
977 setContentBorderThickness:forEdge:)]) { 927 setContentBorderThickness:forEdge:)]) {
978 [win setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; 928 [win setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];
979 [win setContentBorderThickness:kWindowGradientHeight forEdge:NSMaxYEdge]; 929 [win setContentBorderThickness:kWindowGradientHeight forEdge:NSMaxYEdge];
980 } 930 }
981 } 931 }
982 932
983 - (void)tabContentAreaFrameChanged:(id)sender {
984 // TODO(rohitrao): This is triggered by window resizes also. Make
985 // sure we aren't doing anything wasteful in those cases.
986 [downloadShelfController_ resizeDownloadShelf];
987
988 [findBarCocoaController_ positionFindBarView:[self tabContentArea]];
989 }
990
991 - (void)saveWindowPositionIfNeeded { 933 - (void)saveWindowPositionIfNeeded {
992 if (browser_ != BrowserList::GetLastActive()) 934 if (browser_ != BrowserList::GetLastActive())
993 return; 935 return;
994 936
995 if (!g_browser_process || !g_browser_process->local_state() || 937 if (!g_browser_process || !g_browser_process->local_state() ||
996 !browser_->ShouldSaveWindowPlacement()) 938 !browser_->ShouldSaveWindowPlacement())
997 return; 939 return;
998 940
999 [self saveWindowPositionToPrefs:g_browser_process->local_state()]; 941 [self saveWindowPositionToPrefs:g_browser_process->local_state()];
1000 } 942 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 } 1016 }
1075 } 1017 }
1076 1018
1077 - (void)applyTheme { 1019 - (void)applyTheme {
1078 NSColor* color = 1020 NSColor* color =
1079 [theme_ backgroundPatternColorForStyle:GTMThemeStyleWindow 1021 [theme_ backgroundPatternColorForStyle:GTMThemeStyleWindow
1080 state:[[self window] isMainWindow]]; 1022 state:[[self window] isMainWindow]];
1081 [[self window] setBackgroundColor:color]; 1023 [[self window] setBackgroundColor:color];
1082 } 1024 }
1083 1025
1026 // Private method to layout browser window subviews. Positions the toolbar and
1027 // the infobar above the tab content area. Positions the download shelf below
1028 // the tab content area. If the toolbar is not a child of the contentview, this
1029 // method will not leave room for it. If we are currently running in fullscreen
1030 // mode, or if the tabstrip is not a descendant of the window, this method fills
1031 // the entire content area. Otherwise, this method places the topmost view
1032 // directly beneath the tabstrip.
1033 - (void)layoutSubviews {
1034 NSView* contentView = fullscreen_ ? [fullscreen_window_ contentView]
1035 : [[self window] contentView];
1036 NSRect contentFrame = [contentView frame];
1037 int maxY = NSMaxY(contentFrame);
1038 int minY = NSMinY(contentFrame);
1039 if (!fullscreen_ && [self isNormalWindow]) {
1040 maxY = NSMinY([[self tabStripView] frame]);
1041 }
1042 DCHECK_GE(maxY, minY);
1043
1044 // Place the toolbar at the top of the reserved area, but only if we're not in
1045 // fullscreen mode.
1046 NSView* toolbarView = [toolbarController_ view];
1047 NSRect toolbarFrame = [toolbarView frame];
1048 if (!fullscreen_) {
1049 // The toolbar is present in the window, so we make room for it.
1050 toolbarFrame.origin.x = 0;
1051 toolbarFrame.origin.y = maxY - NSHeight(toolbarFrame);
1052 toolbarFrame.size.width = NSWidth(contentFrame);
1053 maxY -= NSHeight(toolbarFrame);
1054 }
1055 [toolbarView setFrame:toolbarFrame];
1056
1057 // Place the infobar container in place below the toolbar.
1058 NSView* infoBarView = [infoBarContainerController_ view];
1059 NSRect infoBarFrame = [infoBarView frame];
1060 infoBarFrame.origin.y = maxY - NSHeight(infoBarFrame);
1061 infoBarFrame.size.width = NSWidth(contentFrame);
1062 [infoBarView setFrame:infoBarFrame];
1063 maxY -= NSHeight(infoBarFrame);
1064
1065 // Place the download shelf at the bottom of the view, if it exists.
1066 if (downloadShelfController_.get()) {
1067 NSView* downloadView = [downloadShelfController_ view];
1068 NSRect downloadFrame = [downloadView frame];
1069 downloadFrame.origin.y = minY;
1070 downloadFrame.size.width = NSWidth(contentFrame);
1071 [downloadView setFrame:downloadFrame];
1072 minY += NSHeight(downloadFrame);
1073 }
1074
1075 // Finally, the tabContentArea takes up all of the remaining space.
1076 NSView* tabContentView = [self tabContentArea];
1077 NSRect tabContentFrame = [tabContentView frame];
1078 tabContentFrame.origin.y = minY;
1079 tabContentFrame.size.height = maxY - minY;
1080 tabContentFrame.size.width = NSWidth(contentFrame);
1081 [tabContentView setFrame:tabContentFrame];
1082
1083 // Position the find bar relative to the infobar container.
1084 [findBarCocoaController_
1085 positionFindBarView:[infoBarContainerController_ view]];
1086 }
1087
1084 @end 1088 @end
1085 1089
1086 @implementation GTMTheme (BrowserThemeProviderInitialization) 1090 @implementation GTMTheme (BrowserThemeProviderInitialization)
1087 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider 1091 + (GTMTheme *)themeWithBrowserThemeProvider:(BrowserThemeProvider*)provider
1088 isOffTheRecord:(BOOL)isOffTheRecord { 1092 isOffTheRecord:(BOOL)isOffTheRecord {
1089 GTMTheme *theme = [[[GTMTheme alloc] init] autorelease]; 1093 GTMTheme *theme = [[[GTMTheme alloc] init] autorelease];
1090 if (isOffTheRecord) { 1094 if (isOffTheRecord) {
1091 NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0 1095 NSColor* incognitoColor = [NSColor colorWithCalibratedRed:83/255.0
1092 green:108.0/255.0 1096 green:108.0/255.0
1093 blue:140/255.0 1097 blue:140/255.0
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 NSColor* toolbarButtonBorderColor = toolbarButtonIconColor; 1173 NSColor* toolbarButtonBorderColor = toolbarButtonIconColor;
1170 [theme setValue:toolbarButtonBorderColor 1174 [theme setValue:toolbarButtonBorderColor
1171 forAttribute:@"borderColor" 1175 forAttribute:@"borderColor"
1172 style:GTMThemeStyleToolBar 1176 style:GTMThemeStyleToolBar
1173 state:YES]; 1177 state:YES];
1174 1178
1175 return theme; 1179 return theme;
1176 } 1180 }
1177 @end 1181 @end
1178 1182
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/browser_window_controller.h ('k') | chrome/browser/cocoa/browser_window_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698