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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm

Issue 12674019: Alternate NTP Mac: Show overlay at fixed position (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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/tab_contents/overlayable_contents_controller.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "chrome/browser/ui/cocoa/browser_window_controller.h" 8 #include "chrome/browser/ui/cocoa/browser_window_controller.h"
9 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" 9 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h"
10 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" 10 #include "chrome/browser/ui/cocoa/tab_contents/overlay_separator_view.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h" 12 #include "content/public/browser/web_contents_view.h"
13 13
14 @interface OverlayableContentsController() 14 @interface OverlayableContentsController()
15 - (void)viewDidResize:(NSNotification*)note; 15 - (void)viewDidResize:(NSNotification*)note;
16 - (void)layoutViews; 16 - (void)layoutViews;
17 - (CGFloat)overlayHeightInPixels; 17 - (CGFloat)overlayHeightInPixels;
18 - (BOOL)shouldShowTopSeparator;
18 @end 19 @end
19 20
20 @implementation OverlayableContentsController 21 @implementation OverlayableContentsController
21 22
22 @synthesize drawDropShadow = drawDropShadow_; 23 @synthesize drawDropShadow = drawDropShadow_;
23 @synthesize activeContainerOffset = activeContainerOffset_; 24 @synthesize activeContainerOffset = activeContainerOffset_;
24 25
25 - (id)initWithBrowser:(Browser*)browser 26 - (id)initWithBrowser:(Browser*)browser
26 windowController:(BrowserWindowController*)windowController { 27 windowController:(BrowserWindowController*)windowController {
27 if ((self = [super init])) { 28 if ((self = [super init])) {
28 windowController_ = windowController; 29 windowController_ = windowController;
29 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 30 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
30 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; 31 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
31 [view setAutoresizesSubviews:NO]; 32 [view setAutoresizesSubviews:NO];
32 [[NSNotificationCenter defaultCenter] 33 [[NSNotificationCenter defaultCenter]
33 addObserver:self 34 addObserver:self
34 selector:@selector(viewDidResize:) 35 selector:@selector(viewDidResize:)
35 name:NSViewFrameDidChangeNotification 36 name:NSViewFrameDidChangeNotification
36 object:view]; 37 object:view];
37 [self setView:view]; 38 [self setView:view];
38 39
39 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); 40 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
40 [view addSubview:activeContainer_]; 41 [view addSubview:activeContainer_];
41 42
42 instantOverlayController_.reset( 43 instantOverlayController_.reset(
43 new InstantOverlayControllerMac(browser, windowController, self)); 44 new InstantOverlayControllerMac(browser, windowController, self));
45 topSeparatorView_.reset(
46 [[OverlayTopSeparatorView alloc] initWithFrame:NSZeroRect]);
47 [[self view] addSubview:topSeparatorView_];
44 } 48 }
45 return self; 49 return self;
46 } 50 }
47 51
48 - (void)dealloc { 52 - (void)dealloc {
49 [[NSNotificationCenter defaultCenter] removeObserver:self]; 53 [[NSNotificationCenter defaultCenter] removeObserver:self];
50 [super dealloc]; 54 [super dealloc];
51 } 55 }
52 56
53 - (void)setOverlay:(content::WebContents*)overlay 57 - (void)setOverlay:(content::WebContents*)overlay
(...skipping 29 matching lines...) Expand all
83 // Add the overlay contents. 87 // Add the overlay contents.
84 if (overlayContents_) { 88 if (overlayContents_) {
85 [[[self view] window] disableScreenUpdatesUntilFlush]; 89 [[[self view] window] disableScreenUpdatesUntilFlush];
86 overlayContents_->GetView()->SetAllowOverlappingViews(true); 90 overlayContents_->GetView()->SetAllowOverlappingViews(true);
87 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()]; 91 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()];
88 } 92 }
89 93
90 if (drawDropShadow_) { 94 if (drawDropShadow_) {
91 if (!dropShadowView_) { 95 if (!dropShadowView_) {
92 dropShadowView_.reset( 96 dropShadowView_.reset(
93 [[OverlayDropShadowView alloc] initWithFrame:NSZeroRect]); 97 [[OverlayBottomSeparatorView alloc] initWithFrame:NSZeroRect]);
94 [[self view] addSubview:dropShadowView_]; 98 [[self view] addSubview:dropShadowView_];
95 } 99 }
96 } else { 100 } else {
97 [dropShadowView_ removeFromSuperview]; 101 [dropShadowView_ removeFromSuperview];
98 dropShadowView_.reset(); 102 dropShadowView_.reset();
99 } 103 }
100 104
101 [self layoutViews]; 105 [self layoutViews];
102 106
103 if (overlayContents_) 107 if (overlayContents_)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 [self layoutViews]; 145 [self layoutViews];
142 } 146 }
143 147
144 - (void)viewDidResize:(NSNotification*)note { 148 - (void)viewDidResize:(NSNotification*)note {
145 [self layoutViews]; 149 [self layoutViews];
146 } 150 }
147 151
148 - (void)layoutViews { 152 - (void)layoutViews {
149 NSRect bounds = [[self view] bounds]; 153 NSRect bounds = [[self view] bounds];
150 154
155 // Layout the separator at the top of the view.
156 NSRect separatorRect = bounds;
157 if ([self shouldShowTopSeparator])
158 separatorRect.size.height = [OverlayTopSeparatorView preferredHeight];
159 else
160 separatorRect.size.height = 0;
161 separatorRect.origin.y = NSMaxY(bounds) - NSHeight(separatorRect);
162 [topSeparatorView_ setFrame:separatorRect];
163
164 // Layout the overlay.
151 if (overlayContents_) { 165 if (overlayContents_) {
152 NSRect overlayFrame = bounds; 166 NSRect overlayFrame = bounds;
153 overlayFrame.size.height = [self overlayHeightInPixels]; 167 overlayFrame.size.height = [self overlayHeightInPixels];
154 overlayFrame.origin.y = NSMaxY(bounds) - NSHeight(overlayFrame); 168 overlayFrame.origin.y =
169 NSMinY([topSeparatorView_ frame]) - NSHeight(overlayFrame);
155 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; 170 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame];
156 171
157 if (dropShadowView_) { 172 if (dropShadowView_) {
158 NSRect dropShadowFrame = bounds; 173 NSRect dropShadowFrame = bounds;
159 dropShadowFrame.size.height = [OverlayDropShadowView preferredHeight]; 174 dropShadowFrame.size.height =
175 [OverlayBottomSeparatorView preferredHeight];
160 dropShadowFrame.origin.y = 176 dropShadowFrame.origin.y =
161 NSMinY(overlayFrame) - NSHeight(dropShadowFrame); 177 NSMinY(overlayFrame) - NSHeight(dropShadowFrame);
162 [dropShadowView_ setFrame:dropShadowFrame]; 178 [dropShadowView_ setFrame:dropShadowFrame];
163 } 179 }
164 } 180 }
165 181
182 // Layout the active tab contents.
166 NSRect activeFrame = bounds; 183 NSRect activeFrame = bounds;
167 activeFrame.size.height -= activeContainerOffset_; 184 if (activeContainerOffset_)
185 activeFrame.size.height -= activeContainerOffset_;
186 else
187 activeFrame.size.height -= NSHeight([topSeparatorView_ frame]);
168 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) { 188 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) {
169 [[activeContainer_ window] disableScreenUpdatesUntilFlush]; 189 [[activeContainer_ window] disableScreenUpdatesUntilFlush];
170 [activeContainer_ setFrame:activeFrame]; 190 [activeContainer_ setFrame:activeFrame];
171 } 191 }
172 } 192 }
173 193
174 - (CGFloat)overlayHeightInPixels { 194 - (CGFloat)overlayHeightInPixels {
175 CGFloat height = NSHeight([[self view] bounds]); 195 CGFloat height =
196 NSHeight([[self view] bounds]) - NSHeight([topSeparatorView_ frame]);
176 switch (overlayHeightUnits_) { 197 switch (overlayHeightUnits_) {
177 case INSTANT_SIZE_PERCENT: 198 case INSTANT_SIZE_PERCENT:
178 return std::min(height, (height * overlayHeight_) / 100); 199 return std::min(height, (height * overlayHeight_) / 100);
179 case INSTANT_SIZE_PIXELS: 200 case INSTANT_SIZE_PIXELS:
180 return std::min(height, overlayHeight_); 201 return std::min(height, overlayHeight_);
181 } 202 }
182 } 203 }
183 204
205 - (BOOL)shouldShowTopSeparator {
206 // In presentation mode tab contents are flush with the top of the screen
207 // so there's no need for a separator.
208 if ([windowController_ inPresentationMode])
209 return NO;
210
211 if (![windowController_ hasToolbar])
212 return NO;
213
214 // Show a separator is the overlay or the tab contents will be shown right
215 // next to the omnibox.
216 return activeContainerOffset_ == 0 || overlayContents_;
217 }
218
184 @end 219 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698