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/previewable_contents_controller.h" | 5 #import "chrome/browser/ui/cocoa/tab_contents/previewable_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/tab_contents/instant_preview_controller_mac.h" | 9 #include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" |
9 #include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" | 10 #include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" |
10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
11 #include "content/public/browser/web_contents_view.h" | 12 #include "content/public/browser/web_contents_view.h" |
12 | 13 |
13 @interface PreviewableContentsController() | 14 @interface PreviewableContentsController() |
14 - (void)viewDidResize:(NSNotification*)note; | 15 - (void)viewDidResize:(NSNotification*)note; |
15 - (void)layoutViews; | 16 - (void)layoutViews; |
16 - (CGFloat)previewHeightInPixels; | 17 - (CGFloat)previewHeightInPixels; |
17 @end | 18 @end |
18 | 19 |
19 @implementation PreviewableContentsController | 20 @implementation PreviewableContentsController |
20 | 21 |
21 @synthesize drawDropShadow = drawDropShadow_; | 22 @synthesize drawDropShadow = drawDropShadow_; |
| 23 @synthesize previewOffset = previewOffset_; |
| 24 @synthesize activeContainerOffset = activeContainerOffset_; |
22 | 25 |
23 - (id)initWithBrowser:(Browser*)browser | 26 - (id)initWithBrowser:(Browser*)browser |
24 windowController:(BrowserWindowController*)windowController { | 27 windowController:(BrowserWindowController*)windowController { |
25 if ((self = [super init])) { | 28 if ((self = [super init])) { |
| 29 windowController_ = windowController; |
26 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 30 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
27 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; | 31 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; |
28 [view setAutoresizesSubviews:NO]; | 32 [view setAutoresizesSubviews:NO]; |
29 [[NSNotificationCenter defaultCenter] | 33 [[NSNotificationCenter defaultCenter] |
30 addObserver:self | 34 addObserver:self |
31 selector:@selector(viewDidResize:) | 35 selector:@selector(viewDidResize:) |
32 name:NSViewFrameDidChangeNotification | 36 name:NSViewFrameDidChangeNotification |
33 object:view]; | 37 object:view]; |
34 [self setView:view]; | 38 [self setView:view]; |
35 | 39 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 131 } |
128 | 132 |
129 - (NSView*)activeContainer { | 133 - (NSView*)activeContainer { |
130 return activeContainer_.get(); | 134 return activeContainer_.get(); |
131 } | 135 } |
132 | 136 |
133 - (NSView*)dropShadowView { | 137 - (NSView*)dropShadowView { |
134 return dropShadowView_.get(); | 138 return dropShadowView_.get(); |
135 } | 139 } |
136 | 140 |
| 141 - (void)setPreviewOffset:(CGFloat)previewOffset { |
| 142 if (previewOffset_ == previewOffset) |
| 143 return; |
| 144 |
| 145 previewOffset_ = previewOffset; |
| 146 [self layoutViews]; |
| 147 } |
| 148 |
| 149 - (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { |
| 150 if (activeContainerOffset_ == activeContainerOffset) |
| 151 return; |
| 152 |
| 153 activeContainerOffset_ = activeContainerOffset; |
| 154 [self layoutViews]; |
| 155 } |
| 156 |
137 - (void)viewDidResize:(NSNotification*)note { | 157 - (void)viewDidResize:(NSNotification*)note { |
138 [self layoutViews]; | 158 [self layoutViews]; |
139 } | 159 } |
140 | 160 |
141 - (void)layoutViews { | 161 - (void)layoutViews { |
142 NSRect bounds = [[self view] bounds]; | 162 NSRect bounds = [[self view] bounds]; |
143 | 163 |
144 if (previewContents_) { | 164 if (previewContents_) { |
145 NSRect previewFrame = bounds; | 165 NSRect previewFrame = bounds; |
146 previewFrame.size.height = [self previewHeightInPixels]; | 166 previewFrame.size.height = [self previewHeightInPixels]; |
147 previewFrame.origin.y = NSMaxY(bounds) - NSHeight(previewFrame); | 167 previewFrame.origin.y = |
| 168 NSMaxY(bounds) - NSHeight(previewFrame) - previewOffset_; |
148 [previewContents_->GetNativeView() setFrame:previewFrame]; | 169 [previewContents_->GetNativeView() setFrame:previewFrame]; |
149 | 170 |
150 if (dropShadowView_) { | 171 if (dropShadowView_) { |
151 NSRect dropShadowFrame = bounds; | 172 NSRect dropShadowFrame = bounds; |
152 dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight]; | 173 dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight]; |
153 dropShadowFrame.origin.y = | 174 dropShadowFrame.origin.y = |
154 NSMinY(previewFrame) - NSHeight(dropShadowFrame); | 175 NSMinY(previewFrame) - NSHeight(dropShadowFrame); |
155 [dropShadowView_ setFrame:dropShadowFrame]; | 176 [dropShadowView_ setFrame:dropShadowFrame]; |
156 } | 177 } |
157 } | 178 } |
158 | 179 |
159 [activeContainer_ setFrame:bounds]; | 180 NSRect activeFrame = bounds; |
| 181 activeFrame.size.height -= activeContainerOffset_; |
| 182 [activeContainer_ setFrame:activeFrame]; |
160 } | 183 } |
161 | 184 |
162 - (CGFloat)previewHeightInPixels { | 185 - (CGFloat)previewHeightInPixels { |
163 CGFloat height = NSHeight([[self view] bounds]); | 186 CGFloat height = NSHeight([[self view] bounds]) - previewOffset_; |
164 switch (previewHeightUnits_) { | 187 switch (previewHeightUnits_) { |
165 case INSTANT_SIZE_PERCENT: | 188 case INSTANT_SIZE_PERCENT: |
166 return std::min(height, (height * previewHeight_) / 100); | 189 return std::min(height, (height * previewHeight_) / 100); |
167 case INSTANT_SIZE_PIXELS: | 190 case INSTANT_SIZE_PIXELS: |
168 return std::min(height, previewHeight_); | 191 return std::min(height, previewHeight_); |
169 } | 192 } |
170 } | 193 } |
171 | 194 |
172 @end | 195 @end |
OLD | NEW |