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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller_private.mm

Issue 11428149: Alternate NTP: Move bookmark bar to bottom (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years 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) 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/browser_window_controller_private.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller_private.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #import "base/memory/scoped_nsobject.h" 10 #import "base/memory/scoped_nsobject.h"
(...skipping 14 matching lines...) Expand all
25 #import "chrome/browser/ui/cocoa/fullscreen_window.h" 25 #import "chrome/browser/ui/cocoa/fullscreen_window.h"
26 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" 26 #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h"
27 #import "chrome/browser/ui/cocoa/nsview_additions.h" 27 #import "chrome/browser/ui/cocoa/nsview_additions.h"
28 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" 28 #import "chrome/browser/ui/cocoa/presentation_mode_controller.h"
29 #import "chrome/browser/ui/cocoa/status_bubble_mac.h" 29 #import "chrome/browser/ui/cocoa/status_bubble_mac.h"
30 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" 30 #import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h"
31 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" 31 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
32 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" 32 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
33 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 33 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
34 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 34 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
35 #include "chrome/browser/ui/search/search_ui.h"
35 #include "chrome/browser/ui/tab_contents/tab_contents.h" 36 #include "chrome/browser/ui/tab_contents/tab_contents.h"
36 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
37 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
38 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
39 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
40 #include "content/public/browser/web_contents_view.h" 41 #include "content/public/browser/web_contents_view.h"
41 #import "ui/base/cocoa/focus_tracker.h" 42 #import "ui/base/cocoa/focus_tracker.h"
42 #include "ui/base/ui_base_types.h" 43 #include "ui/base/ui_base_types.h"
43 44
44 using content::RenderWidgetHostView; 45 using content::RenderWidgetHostView;
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 DCHECK_GE(maxY, minY); 206 DCHECK_GE(maxY, minY);
206 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset); 207 DCHECK_LE(maxY, NSMaxY(contentBounds) + yOffset);
207 208
208 // Place the toolbar at the top of the reserved area. 209 // Place the toolbar at the top of the reserved area.
209 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width]; 210 maxY = [self layoutToolbarAtMinX:minX maxY:maxY width:width];
210 211
211 // If we're not displaying the bookmark bar below the infobar, then it goes 212 // If we're not displaying the bookmark bar below the infobar, then it goes
212 // immediately below the toolbar. 213 // immediately below the toolbar.
213 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar]; 214 BOOL placeBookmarkBarBelowInfoBar = [self placeBookmarkBarBelowInfoBar];
214 if (!placeBookmarkBarBelowInfoBar) 215 if (!placeBookmarkBarBelowInfoBar)
215 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width]; 216 maxY = [self layoutTopBookmarkBarAtMinX:minX maxY:maxY width:width];
216 217
217 // The floating bar backing view doesn't actually add any height. 218 // The floating bar backing view doesn't actually add any height.
218 NSRect floatingBarBackingRect = 219 NSRect floatingBarBackingRect =
219 NSMakeRect(minX, maxY, width, floatingBarHeight); 220 NSMakeRect(minX, maxY, width, floatingBarHeight);
220 [self layoutFloatingBarBackingView:floatingBarBackingRect 221 [self layoutFloatingBarBackingView:floatingBarBackingRect
221 presentationMode:inPresentationMode]; 222 presentationMode:inPresentationMode];
222 223
223 // Place the find bar immediately below the toolbar/attached bookmark bar. In 224 // Place the find bar immediately below the toolbar/attached bookmark bar. In
224 // presentation mode, it hangs off the top of the screen when the bar is 225 // presentation mode, it hangs off the top of the screen when the bar is
225 // hidden. The find bar is unaffected by the side tab positioning. 226 // hidden. The find bar is unaffected by the side tab positioning.
226 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width]; 227 [findBarCocoaController_ positionFindBarViewAtMaxY:maxY maxWidth:width];
227 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width]; 228 [fullscreenExitBubbleController_ positionInWindowAtTop:maxY width:width];
228 229
229 // If in presentation mode, reset |maxY| to top of screen, so that the 230 // If in presentation mode, reset |maxY| to top of screen, so that the
230 // floating bar slides over the things which appear to be in the content area. 231 // floating bar slides over the things which appear to be in the content area.
231 if (inPresentationMode) 232 if (inPresentationMode)
232 maxY = NSMaxY(contentBounds); 233 maxY = NSMaxY(contentBounds);
233 234
234 // Also place the infobar container immediate below the toolbar, except in 235 // Also place the infobar container immediate below the toolbar, except in
235 // presentation mode in which case it's at the top of the visual content area. 236 // presentation mode in which case it's at the top of the visual content area.
236 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width]; 237 maxY = [self layoutInfoBarAtMinX:minX maxY:maxY width:width];
237 238
238 // If the bookmark bar is detached, place it next in the visual content area.
239 if (placeBookmarkBarBelowInfoBar)
240 maxY = [self layoutBookmarkBarAtMinX:minX maxY:maxY width:width];
241
242 // Place the download shelf, if any, at the bottom of the view. 239 // Place the download shelf, if any, at the bottom of the view.
243 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width]; 240 minY = [self layoutDownloadShelfAtMinX:minX minY:minY width:width];
244 241
242 // Place the bookmark bar.
243 if (placeBookmarkBarBelowInfoBar) {
244 if ([bookmarkBarController_ shouldShowAtBottomWhenDetached]) {
245 [self layoutBottomBookmarkBarInContentFrame:
246 NSMakeRect(minX, minY, width, maxY - minY)];
247 } else {
248 maxY = [self layoutTopBookmarkBarAtMinX:minX maxY:maxY width:width];
249 }
250 }
251
245 // Finally, the content area takes up all of the remaining space. 252 // Finally, the content area takes up all of the remaining space.
246 NSRect contentAreaRect = NSMakeRect(minX, minY, width, maxY - minY); 253 NSRect contentAreaRect = NSMakeRect(minX, minY, width, maxY - minY);
247 [self layoutTabContentArea:contentAreaRect]; 254 [self layoutTabContentArea:contentAreaRect];
248 255
249 // Normally, we don't need to tell the toolbar whether or not to show the 256 // Normally, we don't need to tell the toolbar whether or not to show the
250 // divider, but things break down during animation. 257 // divider, but things break down during animation.
251 [toolbarController_ 258 [toolbarController_
252 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]]; 259 setDividerOpacity:[bookmarkBarController_ toolbarDividerOpacity]];
253 } 260 }
254 261
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 370
364 - (BOOL)placeBookmarkBarBelowInfoBar { 371 - (BOOL)placeBookmarkBarBelowInfoBar {
365 // If we are currently displaying the NTP detached bookmark bar or animating 372 // If we are currently displaying the NTP detached bookmark bar or animating
366 // to/from it (from/to anything else), we display the bookmark bar below the 373 // to/from it (from/to anything else), we display the bookmark bar below the
367 // infobar. 374 // infobar.
368 return [bookmarkBarController_ isInState:bookmarks::kDetachedState] || 375 return [bookmarkBarController_ isInState:bookmarks::kDetachedState] ||
369 [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] || 376 [bookmarkBarController_ isAnimatingToState:bookmarks::kDetachedState] ||
370 [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState]; 377 [bookmarkBarController_ isAnimatingFromState:bookmarks::kDetachedState];
371 } 378 }
372 379
373 - (CGFloat)layoutBookmarkBarAtMinX:(CGFloat)minX 380 - (CGFloat)layoutTopBookmarkBarAtMinX:(CGFloat)minX
374 maxY:(CGFloat)maxY 381 maxY:(CGFloat)maxY
375 width:(CGFloat)width { 382 width:(CGFloat)width {
383 [bookmarkBarController_ updateHiddenState];
384
376 NSView* bookmarkBarView = [bookmarkBarController_ view]; 385 NSView* bookmarkBarView = [bookmarkBarController_ view];
377 NSRect bookmarkBarFrame = [bookmarkBarView frame]; 386 NSRect frame = [bookmarkBarView frame];
378 BOOL oldHidden = [bookmarkBarView isHidden]; 387 frame.origin.x = minX;
379 BOOL newHidden = ![self isBookmarkBarVisible]; 388 frame.origin.y = maxY - NSHeight(frame);
380 if (oldHidden != newHidden) 389 frame.size.width = width;
381 [bookmarkBarView setHidden:newHidden]; 390 [bookmarkBarView setFrame:frame];
382 bookmarkBarFrame.origin.x = minX; 391 maxY -= NSHeight(frame);
383 bookmarkBarFrame.origin.y = maxY - NSHeight(bookmarkBarFrame); 392
384 bookmarkBarFrame.size.width = width; 393 // Pin the bookmark bar to the top of the window and make the width flexible.
385 [bookmarkBarView setFrame:bookmarkBarFrame]; 394 [bookmarkBarView setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin];
386 maxY -= NSHeight(bookmarkBarFrame);
387 395
388 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be 396 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be
389 // necessary in the non-NTP case. 397 // necessary in the non-NTP case.
390 [bookmarkBarController_ layoutSubviews]; 398 [bookmarkBarController_ layoutSubviews];
391 399
392 return maxY; 400 return maxY;
393 } 401 }
394 402
403 - (void)layoutBottomBookmarkBarInContentFrame:(NSRect)contentFrame {
404 [bookmarkBarController_ updateHiddenState];
405
406 NSView* bookmarkBarView = [bookmarkBarController_ view];
407 NSRect frame;
408 frame.size.width = NSWidth(contentFrame) -
409 chrome::search::kHorizontalPaddingForBottomBookmarkBar * 2;
410 frame.size.width = std::min(frame.size.width,
411 static_cast<CGFloat>(chrome::search::kMaxWidthForBottomBookmarkBar));
412 frame.size.height = NSHeight([bookmarkBarView frame]);
413 frame.origin.x = NSMinX(contentFrame) +
414 roundf((NSWidth(contentFrame)- frame.size.width) / 2.0);
415 frame.origin.y = NSMinY(contentFrame);
416 [bookmarkBarView setFrame:frame];
417
418 // Disable auto-resizing.
419 [bookmarkBarView setAutoresizingMask:0];
420
421 // TODO(viettrungluu): Does this really belong here? Calling it shouldn't be
422 // necessary in the non-NTP case.
423 [bookmarkBarController_ layoutSubviews];
424 }
425
395 - (void)layoutFloatingBarBackingView:(NSRect)frame 426 - (void)layoutFloatingBarBackingView:(NSRect)frame
396 presentationMode:(BOOL)presentationMode { 427 presentationMode:(BOOL)presentationMode {
397 // Only display when in presentation mode. 428 // Only display when in presentation mode.
398 if (presentationMode) { 429 if (presentationMode) {
399 // For certain window types such as app windows (e.g., the dev tools 430 // For certain window types such as app windows (e.g., the dev tools
400 // window), there's no actual overlay. (Displaying one would result in an 431 // window), there's no actual overlay. (Displaying one would result in an
401 // overly sliding in only under the menu, which gives an ugly effect.) 432 // overly sliding in only under the menu, which gives an ugly effect.)
402 if (floatingBarBackingView_.get()) { 433 if (floatingBarBackingView_.get()) {
403 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar]; 434 BOOL aboveBookmarkBar = [self placeBookmarkBarBelowInfoBar];
404 435
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 - (void)disableBarVisibilityUpdates { 892 - (void)disableBarVisibilityUpdates {
862 // Early escape if there's nothing to do. 893 // Early escape if there's nothing to do.
863 if (!barVisibilityUpdatesEnabled_) 894 if (!barVisibilityUpdatesEnabled_)
864 return; 895 return;
865 896
866 barVisibilityUpdatesEnabled_ = NO; 897 barVisibilityUpdatesEnabled_ = NO;
867 [presentationModeController_ cancelAnimationAndTimers]; 898 [presentationModeController_ cancelAnimationAndTimers];
868 } 899 }
869 900
870 @end // @implementation BrowserWindowController(Private) 901 @end // @implementation BrowserWindowController(Private)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller_private.h ('k') | chrome/browser/ui/search/search.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698