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

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

Issue 12905008: Revert 190519 "Alternate NTP Mac: Show overlay at fixed position" (Closed) Base URL: svn://svn.chromium.org/chrome/
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_separator_view.h" 10 #include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_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;
19 @end 18 @end
20 19
21 @implementation OverlayableContentsController 20 @implementation OverlayableContentsController
22 21
23 @synthesize drawDropShadow = drawDropShadow_; 22 @synthesize drawDropShadow = drawDropShadow_;
24 @synthesize activeContainerOffset = activeContainerOffset_; 23 @synthesize activeContainerOffset = activeContainerOffset_;
25 24
26 - (id)initWithBrowser:(Browser*)browser 25 - (id)initWithBrowser:(Browser*)browser
27 windowController:(BrowserWindowController*)windowController { 26 windowController:(BrowserWindowController*)windowController {
28 if ((self = [super init])) { 27 if ((self = [super init])) {
29 windowController_ = windowController; 28 windowController_ = windowController;
30 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 29 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
31 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; 30 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
32 [view setAutoresizesSubviews:NO]; 31 [view setAutoresizesSubviews:NO];
33 [[NSNotificationCenter defaultCenter] 32 [[NSNotificationCenter defaultCenter]
34 addObserver:self 33 addObserver:self
35 selector:@selector(viewDidResize:) 34 selector:@selector(viewDidResize:)
36 name:NSViewFrameDidChangeNotification 35 name:NSViewFrameDidChangeNotification
37 object:view]; 36 object:view];
38 [self setView:view]; 37 [self setView:view];
39 38
40 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); 39 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
41 [view addSubview:activeContainer_]; 40 [view addSubview:activeContainer_];
42 41
43 instantOverlayController_.reset( 42 instantOverlayController_.reset(
44 new InstantOverlayControllerMac(browser, windowController, self)); 43 new InstantOverlayControllerMac(browser, windowController, self));
45 topSeparatorView_.reset(
46 [[OverlayTopSeparatorView alloc] initWithFrame:NSZeroRect]);
47 [[self view] addSubview:topSeparatorView_];
48 } 44 }
49 return self; 45 return self;
50 } 46 }
51 47
52 - (void)dealloc { 48 - (void)dealloc {
53 [[NSNotificationCenter defaultCenter] removeObserver:self]; 49 [[NSNotificationCenter defaultCenter] removeObserver:self];
54 [super dealloc]; 50 [super dealloc];
55 } 51 }
56 52
57 - (void)setOverlay:(content::WebContents*)overlay 53 - (void)setOverlay:(content::WebContents*)overlay
(...skipping 29 matching lines...) Expand all
87 // Add the overlay contents. 83 // Add the overlay contents.
88 if (overlayContents_) { 84 if (overlayContents_) {
89 [[[self view] window] disableScreenUpdatesUntilFlush]; 85 [[[self view] window] disableScreenUpdatesUntilFlush];
90 overlayContents_->GetView()->SetAllowOverlappingViews(true); 86 overlayContents_->GetView()->SetAllowOverlappingViews(true);
91 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()]; 87 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()];
92 } 88 }
93 89
94 if (drawDropShadow_) { 90 if (drawDropShadow_) {
95 if (!dropShadowView_) { 91 if (!dropShadowView_) {
96 dropShadowView_.reset( 92 dropShadowView_.reset(
97 [[OverlayBottomSeparatorView alloc] initWithFrame:NSZeroRect]); 93 [[OverlayDropShadowView alloc] initWithFrame:NSZeroRect]);
98 [[self view] addSubview:dropShadowView_]; 94 [[self view] addSubview:dropShadowView_];
99 } 95 }
100 } else { 96 } else {
101 [dropShadowView_ removeFromSuperview]; 97 [dropShadowView_ removeFromSuperview];
102 dropShadowView_.reset(); 98 dropShadowView_.reset();
103 } 99 }
104 100
105 [self layoutViews]; 101 [self layoutViews];
106 102
107 if (overlayContents_) 103 if (overlayContents_)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 [self layoutViews]; 141 [self layoutViews];
146 } 142 }
147 143
148 - (void)viewDidResize:(NSNotification*)note { 144 - (void)viewDidResize:(NSNotification*)note {
149 [self layoutViews]; 145 [self layoutViews];
150 } 146 }
151 147
152 - (void)layoutViews { 148 - (void)layoutViews {
153 NSRect bounds = [[self view] bounds]; 149 NSRect bounds = [[self view] bounds];
154 150
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.
165 if (overlayContents_) { 151 if (overlayContents_) {
166 NSRect overlayFrame = bounds; 152 NSRect overlayFrame = bounds;
167 overlayFrame.size.height = [self overlayHeightInPixels]; 153 overlayFrame.size.height = [self overlayHeightInPixels];
168 overlayFrame.origin.y = 154 overlayFrame.origin.y = NSMaxY(bounds) - NSHeight(overlayFrame);
169 NSMinY([topSeparatorView_ frame]) - NSHeight(overlayFrame);
170 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; 155 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame];
171 156
172 if (dropShadowView_) { 157 if (dropShadowView_) {
173 NSRect dropShadowFrame = bounds; 158 NSRect dropShadowFrame = bounds;
174 dropShadowFrame.size.height = 159 dropShadowFrame.size.height = [OverlayDropShadowView preferredHeight];
175 [OverlayBottomSeparatorView preferredHeight];
176 dropShadowFrame.origin.y = 160 dropShadowFrame.origin.y =
177 NSMinY(overlayFrame) - NSHeight(dropShadowFrame); 161 NSMinY(overlayFrame) - NSHeight(dropShadowFrame);
178 [dropShadowView_ setFrame:dropShadowFrame]; 162 [dropShadowView_ setFrame:dropShadowFrame];
179 } 163 }
180 } 164 }
181 165
182 // Layout the active tab contents.
183 NSRect activeFrame = bounds; 166 NSRect activeFrame = bounds;
184 if (activeContainerOffset_) 167 activeFrame.size.height -= activeContainerOffset_;
185 activeFrame.size.height -= activeContainerOffset_;
186 else
187 activeFrame.size.height -= NSHeight([topSeparatorView_ frame]);
188 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) { 168 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) {
189 [[activeContainer_ window] disableScreenUpdatesUntilFlush]; 169 [[activeContainer_ window] disableScreenUpdatesUntilFlush];
190 [activeContainer_ setFrame:activeFrame]; 170 [activeContainer_ setFrame:activeFrame];
191 } 171 }
192 } 172 }
193 173
194 - (CGFloat)overlayHeightInPixels { 174 - (CGFloat)overlayHeightInPixels {
195 CGFloat height = 175 CGFloat height = NSHeight([[self view] bounds]);
196 NSHeight([[self view] bounds]) - NSHeight([topSeparatorView_ frame]);
197 switch (overlayHeightUnits_) { 176 switch (overlayHeightUnits_) {
198 case INSTANT_SIZE_PERCENT: 177 case INSTANT_SIZE_PERCENT:
199 return std::min(height, (height * overlayHeight_) / 100); 178 return std::min(height, (height * overlayHeight_) / 100);
200 case INSTANT_SIZE_PIXELS: 179 case INSTANT_SIZE_PIXELS:
201 return std::min(height, overlayHeight_); 180 return std::min(height, overlayHeight_);
202 } 181 }
203 } 182 }
204 183
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
219 @end 184 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698