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

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

Issue 12386019: Instant: Use only one hidden WebContents per profile. (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/previewable_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_preview_controller_mac.h" 9 #include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h"
10 #include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_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 PreviewableContentsController() 14 @interface OverlayableContentsController()
15 - (void)viewDidResize:(NSNotification*)note; 15 - (void)viewDidResize:(NSNotification*)note;
16 - (void)layoutViews; 16 - (void)layoutViews;
17 - (CGFloat)previewHeightInPixels; 17 - (CGFloat)overlayHeightInPixels;
18 @end 18 @end
19 19
20 @implementation PreviewableContentsController 20 @implementation OverlayableContentsController
21 21
22 @synthesize drawDropShadow = drawDropShadow_; 22 @synthesize drawDropShadow = drawDropShadow_;
23 @synthesize activeContainerOffset = activeContainerOffset_; 23 @synthesize activeContainerOffset = activeContainerOffset_;
24 24
25 - (id)initWithBrowser:(Browser*)browser 25 - (id)initWithBrowser:(Browser*)browser
26 windowController:(BrowserWindowController*)windowController { 26 windowController:(BrowserWindowController*)windowController {
27 if ((self = [super init])) { 27 if ((self = [super init])) {
28 windowController_ = windowController; 28 windowController_ = windowController;
29 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 29 scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
30 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; 30 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
31 [view setAutoresizesSubviews:NO]; 31 [view setAutoresizesSubviews:NO];
32 [[NSNotificationCenter defaultCenter] 32 [[NSNotificationCenter defaultCenter]
33 addObserver:self 33 addObserver:self
34 selector:@selector(viewDidResize:) 34 selector:@selector(viewDidResize:)
35 name:NSViewFrameDidChangeNotification 35 name:NSViewFrameDidChangeNotification
36 object:view]; 36 object:view];
37 [self setView:view]; 37 [self setView:view];
38 38
39 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); 39 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]);
40 [view addSubview:activeContainer_]; 40 [view addSubview:activeContainer_];
41 41
42 instantPreviewController_.reset( 42 instantOverlayController_.reset(
43 new InstantPreviewControllerMac(browser, windowController, self)); 43 new InstantOverlayControllerMac(browser, windowController, self));
44 } 44 }
45 return self; 45 return self;
46 } 46 }
47 47
48 - (void)dealloc { 48 - (void)dealloc {
49 [[NSNotificationCenter defaultCenter] removeObserver:self]; 49 [[NSNotificationCenter defaultCenter] removeObserver:self];
50 [super dealloc]; 50 [super dealloc];
51 } 51 }
52 52
53 - (void)setPreview:(content::WebContents*)preview 53 - (void)setOverlay:(content::WebContents*)overlay
54 height:(CGFloat)height 54 height:(CGFloat)height
55 heightUnits:(InstantSizeUnits)heightUnits 55 isHeightInPixels:(BOOL)isHeightInPixels
56 drawDropShadow:(BOOL)drawDropShadow { 56 drawDropShadow:(BOOL)drawDropShadow {
57 // If drawing drop shadow, clip the bottom 1-px-thick separator out of 57 // If drawing drop shadow, clip the bottom 1-px-thick separator out of
58 // preview. 58 // overlay.
59 // TODO(sail): remove this when GWS gives chrome the height without the 59 // TODO(sail): remove this when GWS gives chrome the height without the
60 // separator. 60 // separator.
61 if (drawDropShadow && heightUnits != INSTANT_SIZE_PERCENT) 61 if (drawDropShadow && isHeightInPixels)
62 --height; 62 --height;
63 63
64 if (previewContents_ == preview && 64 if (overlayContents_ == overlay &&
65 previewHeight_ == height && 65 overlayHeight_ == height &&
66 previewHeightUnits_ == heightUnits && 66 isHeightInPixels_ == isHeightInPixels &&
67 drawDropShadow_ == drawDropShadow) { 67 drawDropShadow_ == drawDropShadow) {
68 return; 68 return;
69 } 69 }
70 70
71 // Remove any old preview contents before showing the new one. 71 // Remove any old overlay contents before showing the new one.
72 if (previewContents_) { 72 if (overlayContents_) {
73 [previewContents_->GetView()->GetNativeView() removeFromSuperview]; 73 [overlayContents_->GetView()->GetNativeView() removeFromSuperview];
74 previewContents_->WasHidden(); 74 overlayContents_->WasHidden();
75 } 75 }
76 76
77 previewContents_ = preview; 77 overlayContents_ = overlay;
78 previewHeight_ = height; 78 overlayHeight_ = height;
79 previewHeightUnits_ = heightUnits; 79 isHeightInPixels_ = isHeightInPixels;
80 drawDropShadow_ = drawDropShadow; 80 drawDropShadow_ = drawDropShadow;
81 81
82 // Add the preview contents. 82 // Add the overlay contents.
83 if (previewContents_) { 83 if (overlayContents_) {
84 [[[self view] window] disableScreenUpdatesUntilFlush]; 84 [[[self view] window] disableScreenUpdatesUntilFlush];
85 previewContents_->GetView()->SetAllowOverlappingViews(true); 85 overlayContents_->GetView()->SetAllowOverlappingViews(true);
86 [[self view] addSubview:previewContents_->GetView()->GetNativeView()]; 86 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()];
87 } 87 }
88 88
89 if (drawDropShadow_) { 89 if (drawDropShadow_) {
90 if (!dropShadowView_) { 90 if (!dropShadowView_) {
91 dropShadowView_.reset( 91 dropShadowView_.reset(
92 [[PreviewDropShadowView alloc] initWithFrame:NSZeroRect]); 92 [[OverlayDropShadowView alloc] initWithFrame:NSZeroRect]);
93 [[self view] addSubview:dropShadowView_]; 93 [[self view] addSubview:dropShadowView_];
94 } 94 }
95 } else { 95 } else {
96 [dropShadowView_ removeFromSuperview]; 96 [dropShadowView_ removeFromSuperview];
97 dropShadowView_.reset(); 97 dropShadowView_.reset();
98 } 98 }
99 99
100 [self layoutViews]; 100 [self layoutViews];
101 101
102 if (previewContents_) 102 if (overlayContents_)
103 previewContents_->WasShown(); 103 overlayContents_->WasShown();
104 } 104 }
105 105
106 - (void)onActivateTabWithContents:(content::WebContents*)contents { 106 - (void)onActivateTabWithContents:(content::WebContents*)contents {
107 if (previewContents_ == contents) { 107 if (overlayContents_ == contents) {
108 if (previewContents_) { 108 if (overlayContents_) {
109 [previewContents_->GetView()->GetNativeView() removeFromSuperview]; 109 [overlayContents_->GetView()->GetNativeView() removeFromSuperview];
110 previewContents_ = NULL; 110 overlayContents_ = NULL;
111 } 111 }
112 [self setPreview:NULL 112 [self setOverlay:NULL
113 height:0 113 height:0
114 heightUnits:INSTANT_SIZE_PIXELS 114 isHeightInPixels:NO
115 drawDropShadow:NO]; 115 drawDropShadow:NO];
116 } 116 }
117 } 117 }
118 118
119 - (BOOL)isShowingPreview { 119 - (BOOL)isShowingOverlay {
120 return previewContents_ != nil; 120 return overlayContents_ != nil;
121 } 121 }
122 122
123 - (InstantPreviewControllerMac*)instantPreviewController { 123 - (InstantOverlayControllerMac*)instantOverlayController {
124 return instantPreviewController_.get(); 124 return instantOverlayController_.get();
125 } 125 }
126 126
127 - (NSView*)activeContainer { 127 - (NSView*)activeContainer {
128 return activeContainer_.get(); 128 return activeContainer_.get();
129 } 129 }
130 130
131 - (NSView*)dropShadowView { 131 - (NSView*)dropShadowView {
132 return dropShadowView_.get(); 132 return dropShadowView_.get();
133 } 133 }
134 134
135 - (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { 135 - (void)setActiveContainerOffset:(CGFloat)activeContainerOffset {
136 if (activeContainerOffset_ == activeContainerOffset) 136 if (activeContainerOffset_ == activeContainerOffset)
137 return; 137 return;
138 138
139 activeContainerOffset_ = activeContainerOffset; 139 activeContainerOffset_ = activeContainerOffset;
140 [self layoutViews]; 140 [self layoutViews];
141 } 141 }
142 142
143 - (void)viewDidResize:(NSNotification*)note { 143 - (void)viewDidResize:(NSNotification*)note {
144 [self layoutViews]; 144 [self layoutViews];
145 } 145 }
146 146
147 - (void)layoutViews { 147 - (void)layoutViews {
148 NSRect bounds = [[self view] bounds]; 148 NSRect bounds = [[self view] bounds];
149 149
150 if (previewContents_) { 150 if (overlayContents_) {
151 NSRect previewFrame = bounds; 151 NSRect overlayFrame = bounds;
152 previewFrame.size.height = [self previewHeightInPixels]; 152 overlayFrame.size.height = [self overlayHeightInPixels];
153 previewFrame.origin.y = NSMaxY(bounds) - NSHeight(previewFrame); 153 overlayFrame.origin.y = NSMaxY(bounds) - NSHeight(overlayFrame);
154 [previewContents_->GetView()->GetNativeView() setFrame:previewFrame]; 154 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame];
155 155
156 if (dropShadowView_) { 156 if (dropShadowView_) {
157 NSRect dropShadowFrame = bounds; 157 NSRect dropShadowFrame = bounds;
158 dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight]; 158 dropShadowFrame.size.height = [OverlayDropShadowView preferredHeight];
159 dropShadowFrame.origin.y = 159 dropShadowFrame.origin.y =
160 NSMinY(previewFrame) - NSHeight(dropShadowFrame); 160 NSMinY(overlayFrame) - NSHeight(dropShadowFrame);
161 [dropShadowView_ setFrame:dropShadowFrame]; 161 [dropShadowView_ setFrame:dropShadowFrame];
162 } 162 }
163 } 163 }
164 164
165 NSRect activeFrame = bounds; 165 NSRect activeFrame = bounds;
166 activeFrame.size.height -= activeContainerOffset_; 166 activeFrame.size.height -= activeContainerOffset_;
167 [activeContainer_ setFrame:activeFrame]; 167 [activeContainer_ setFrame:activeFrame];
168 } 168 }
169 169
170 - (CGFloat)previewHeightInPixels { 170 - (CGFloat)overlayHeightInPixels {
171 CGFloat height = NSHeight([[self view] bounds]); 171 CGFloat height = NSHeight([[self view] bounds]);
172 switch (previewHeightUnits_) { 172 return std::min(height, isHeightInPixels_ ? overlayHeight_ :
173 case INSTANT_SIZE_PERCENT: 173 (height * overlayHeight_) / 100);
174 return std::min(height, (height * previewHeight_) / 100);
175 case INSTANT_SIZE_PIXELS:
176 return std::min(height, previewHeight_);
177 }
178 } 174 }
179 175
180 @end 176 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698