OLD | NEW |
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_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 - (BOOL)shouldShowTopSeparator; |
19 @end | 19 @end |
20 | 20 |
21 @implementation OverlayableContentsController | 21 @implementation OverlayableContentsController |
22 | 22 |
23 @synthesize drawDropShadow = drawDropShadow_; | 23 @synthesize drawDropShadow = drawDropShadow_; |
24 @synthesize activeContainerOffset = activeContainerOffset_; | 24 @synthesize activeContainerOffset = activeContainerOffset_; |
| 25 @synthesize overlayContentsOffset = overlayContentsOffset_; |
25 | 26 |
26 - (id)initWithBrowser:(Browser*)browser | 27 - (id)initWithBrowser:(Browser*)browser |
27 windowController:(BrowserWindowController*)windowController { | 28 windowController:(BrowserWindowController*)windowController { |
28 if ((self = [super init])) { | 29 if ((self = [super init])) { |
29 windowController_ = windowController; | 30 windowController_ = windowController; |
30 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 31 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
31 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; | 32 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; |
32 [view setAutoresizesSubviews:NO]; | 33 [view setAutoresizesSubviews:NO]; |
33 [[NSNotificationCenter defaultCenter] | 34 [[NSNotificationCenter defaultCenter] |
34 addObserver:self | 35 addObserver:self |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 139 } |
139 | 140 |
140 - (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { | 141 - (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { |
141 if (activeContainerOffset_ == activeContainerOffset) | 142 if (activeContainerOffset_ == activeContainerOffset) |
142 return; | 143 return; |
143 | 144 |
144 activeContainerOffset_ = activeContainerOffset; | 145 activeContainerOffset_ = activeContainerOffset; |
145 [self layoutViews]; | 146 [self layoutViews]; |
146 } | 147 } |
147 | 148 |
| 149 - (void)setOverlayContentsOffset:(CGFloat)overlayContentsOffset { |
| 150 if (overlayContentsOffset_ == overlayContentsOffset) |
| 151 return; |
| 152 |
| 153 overlayContentsOffset_ = overlayContentsOffset; |
| 154 [self layoutViews]; |
| 155 } |
| 156 |
148 - (void)viewDidResize:(NSNotification*)note { | 157 - (void)viewDidResize:(NSNotification*)note { |
149 [self layoutViews]; | 158 [self layoutViews]; |
150 } | 159 } |
151 | 160 |
152 - (void)layoutViews { | 161 - (void)layoutViews { |
153 NSRect bounds = [[self view] bounds]; | 162 NSRect bounds = [[self view] bounds]; |
154 | 163 |
155 // Layout the separator at the top of the view. | 164 // Layout the separator at the top of the view. |
156 NSRect separatorRect = bounds; | 165 NSRect separatorRect = bounds; |
157 if ([self shouldShowTopSeparator]) | 166 if ([self shouldShowTopSeparator]) |
158 separatorRect.size.height = [OverlayTopSeparatorView preferredHeight]; | 167 separatorRect.size.height = [OverlayTopSeparatorView preferredHeight]; |
159 else | 168 else |
160 separatorRect.size.height = 0; | 169 separatorRect.size.height = 0; |
161 separatorRect.origin.y = NSMaxY(bounds) - NSHeight(separatorRect); | 170 separatorRect.origin.y = NSMaxY(bounds) - NSHeight(separatorRect); |
162 [topSeparatorView_ setFrame:separatorRect]; | 171 [topSeparatorView_ setFrame:separatorRect]; |
163 | 172 |
164 // Layout the overlay. | 173 // Layout the overlay. |
165 if (overlayContents_) { | 174 if (overlayContents_) { |
166 NSRect overlayFrame = bounds; | 175 NSRect overlayFrame = bounds; |
167 overlayFrame.size.height = [self overlayHeightInPixels]; | 176 overlayFrame.size.height = [self overlayHeightInPixels]; |
168 overlayFrame.origin.y = | 177 overlayFrame.origin.y = NSMinY([topSeparatorView_ frame]) - |
169 NSMinY([topSeparatorView_ frame]) - NSHeight(overlayFrame); | 178 NSHeight(overlayFrame) - overlayContentsOffset_; |
170 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; | 179 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; |
171 | 180 |
172 if (dropShadowView_) { | 181 if (dropShadowView_) { |
173 NSRect dropShadowFrame = bounds; | 182 NSRect dropShadowFrame = bounds; |
174 dropShadowFrame.size.height = | 183 dropShadowFrame.size.height = |
175 [OverlayBottomSeparatorView preferredHeight]; | 184 [OverlayBottomSeparatorView preferredHeight]; |
176 dropShadowFrame.origin.y = | 185 dropShadowFrame.origin.y = |
177 NSMinY(overlayFrame) - NSHeight(dropShadowFrame); | 186 NSMinY(overlayFrame) - NSHeight(dropShadowFrame); |
178 [dropShadowView_ setFrame:dropShadowFrame]; | 187 [dropShadowView_ setFrame:dropShadowFrame]; |
179 } | 188 } |
180 } | 189 } |
181 | 190 |
182 // Layout the active tab contents. | 191 // Layout the active tab contents. |
183 NSRect activeFrame = bounds; | 192 NSRect activeFrame = bounds; |
184 if (activeContainerOffset_) | 193 if (activeContainerOffset_) |
185 activeFrame.size.height -= activeContainerOffset_; | 194 activeFrame.size.height -= activeContainerOffset_; |
186 else | 195 else |
187 activeFrame.size.height -= NSHeight([topSeparatorView_ frame]); | 196 activeFrame.size.height -= NSHeight([topSeparatorView_ frame]); |
188 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) { | 197 if (!NSEqualRects(activeFrame, [activeContainer_ frame])) { |
189 [[activeContainer_ window] disableScreenUpdatesUntilFlush]; | 198 [[activeContainer_ window] disableScreenUpdatesUntilFlush]; |
190 [activeContainer_ setFrame:activeFrame]; | 199 [activeContainer_ setFrame:activeFrame]; |
191 } | 200 } |
192 } | 201 } |
193 | 202 |
194 - (CGFloat)overlayHeightInPixels { | 203 - (CGFloat)overlayHeightInPixels { |
195 CGFloat height = | 204 CGFloat height = NSHeight([[self view] bounds]) - |
196 NSHeight([[self view] bounds]) - NSHeight([topSeparatorView_ frame]); | 205 NSHeight([topSeparatorView_ frame]) - overlayContentsOffset_; |
197 switch (overlayHeightUnits_) { | 206 switch (overlayHeightUnits_) { |
198 case INSTANT_SIZE_PERCENT: | 207 case INSTANT_SIZE_PERCENT: |
199 return std::min(height, (height * overlayHeight_) / 100); | 208 return std::min(height, (height * overlayHeight_) / 100); |
200 case INSTANT_SIZE_PIXELS: | 209 case INSTANT_SIZE_PIXELS: |
201 return std::min(height, overlayHeight_); | 210 return std::min(height, overlayHeight_); |
202 } | 211 } |
203 } | 212 } |
204 | 213 |
205 - (BOOL)shouldShowTopSeparator { | 214 - (BOOL)shouldShowTopSeparator { |
206 // In presentation mode tab contents are flush with the top of the screen | 215 // In presentation mode tab contents are flush with the top of the screen |
207 // so there's no need for a separator. | 216 // so there's no need for a separator. |
208 if ([windowController_ inPresentationMode]) | 217 if ([windowController_ inPresentationMode]) |
209 return NO; | 218 return NO; |
210 | 219 |
211 if (![windowController_ hasToolbar]) | 220 if (![windowController_ hasToolbar]) |
212 return NO; | 221 return NO; |
213 | 222 |
214 // Show a separator is the overlay or the tab contents will be shown right | 223 // Show a separator is the overlay or the tab contents will be shown right |
215 // next to the omnibox. | 224 // next to the omnibox. |
216 return activeContainerOffset_ == 0 || overlayContents_; | 225 return activeContainerOffset_ == 0 || overlayContents_; |
217 } | 226 } |
218 | 227 |
219 @end | 228 @end |
OLD | NEW |