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

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

Issue 11876036: Alternate NTP: Don't hide bookmark bar on instant (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 7 years, 11 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/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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 dropShadowView_.reset(); 115 dropShadowView_.reset();
112 } 116 }
113 117
114 - (void)onActivateTabWithContents:(content::WebContents*)contents { 118 - (void)onActivateTabWithContents:(content::WebContents*)contents {
115 if (previewContents_ == contents) { 119 if (previewContents_ == contents) {
116 [previewContents_->GetNativeView() removeFromSuperview]; 120 [previewContents_->GetNativeView() removeFromSuperview];
117 previewContents_ = nil; 121 previewContents_ = nil;
118 } 122 }
119 } 123 }
120 124
125 - (BOOL)isShowingPreview {
126 return previewContents_ != nil;
127 }
128
121 - (InstantPreviewControllerMac*)instantPreviewController { 129 - (InstantPreviewControllerMac*)instantPreviewController {
122 return instantPreviewController_.get(); 130 return instantPreviewController_.get();
123 } 131 }
124 132
125 - (NSView*)activeContainer { 133 - (NSView*)activeContainer {
126 return activeContainer_.get(); 134 return activeContainer_.get();
127 } 135 }
128 136
129 - (NSView*)dropShadowView { 137 - (NSView*)dropShadowView {
130 return dropShadowView_.get(); 138 return dropShadowView_.get();
131 } 139 }
132 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
133 - (void)viewDidResize:(NSNotification*)note { 157 - (void)viewDidResize:(NSNotification*)note {
134 [self layoutViews]; 158 [self layoutViews];
135 } 159 }
136 160
137 - (void)layoutViews { 161 - (void)layoutViews {
138 NSRect bounds = [[self view] bounds]; 162 NSRect bounds = [[self view] bounds];
139 163
140 if (previewContents_) { 164 if (previewContents_) {
141 NSRect previewFrame = bounds; 165 NSRect previewFrame = bounds;
142 previewFrame.size.height = [self previewHeightInPixels]; 166 previewFrame.size.height = [self previewHeightInPixels];
143 previewFrame.origin.y = NSMaxY(bounds) - NSHeight(previewFrame); 167 previewFrame.origin.y =
168 NSMaxY(bounds) - NSHeight(previewFrame) - previewOffset_;
144 [previewContents_->GetNativeView() setFrame:previewFrame]; 169 [previewContents_->GetNativeView() setFrame:previewFrame];
145 170
146 if (dropShadowView_) { 171 if (dropShadowView_) {
147 NSRect dropShadowFrame = bounds; 172 NSRect dropShadowFrame = bounds;
148 dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight]; 173 dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight];
149 dropShadowFrame.origin.y = 174 dropShadowFrame.origin.y =
150 NSMinY(previewFrame) - NSHeight(dropShadowFrame); 175 NSMinY(previewFrame) - NSHeight(dropShadowFrame);
151 [dropShadowView_ setFrame:dropShadowFrame]; 176 [dropShadowView_ setFrame:dropShadowFrame];
152 } 177 }
153 } 178 }
154 179
155 [activeContainer_ setFrame:bounds]; 180 NSRect activeFrame = bounds;
181 activeFrame.size.height -= activeContainerOffset_;
182 [activeContainer_ setFrame:activeFrame];
156 } 183 }
157 184
158 - (CGFloat)previewHeightInPixels { 185 - (CGFloat)previewHeightInPixels {
159 CGFloat height = NSHeight([[self view] bounds]); 186 CGFloat height = NSHeight([[self view] bounds]) - previewOffset_;
160 switch (previewHeightUnits_) { 187 switch (previewHeightUnits_) {
161 case INSTANT_SIZE_PERCENT: 188 case INSTANT_SIZE_PERCENT:
162 return std::min(height, (height * previewHeight_) / 100); 189 return std::min(height, (height * previewHeight_) / 100);
163 case INSTANT_SIZE_PIXELS: 190 case INSTANT_SIZE_PIXELS:
164 return std::min(height, previewHeight_); 191 return std::min(height, previewHeight_);
165 } 192 }
166 } 193 }
167 194
168 @end 195 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698