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/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_preview_controller_mac.h" |
10 #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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 new InstantPreviewControllerMac(browser, windowController, self)); | 44 new InstantPreviewControllerMac(browser, windowController, self)); |
45 } | 45 } |
46 return self; | 46 return self; |
47 } | 47 } |
48 | 48 |
49 - (void)dealloc { | 49 - (void)dealloc { |
50 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 50 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
51 [super dealloc]; | 51 [super dealloc]; |
52 } | 52 } |
53 | 53 |
54 - (void)showPreview:(content::WebContents*)preview | 54 - (void)setPreview:(content::WebContents*)preview |
55 height:(CGFloat)height | 55 height:(CGFloat)height |
56 heightUnits:(InstantSizeUnits)heightUnits | 56 heightUnits:(InstantSizeUnits)heightUnits |
57 drawDropShadow:(BOOL)drawDropShadow { | 57 drawDropShadow:(BOOL)drawDropShadow { |
58 DCHECK(preview); | |
59 | |
60 // If drawing drop shadow, clip the bottom 1-px-thick separator out of | 58 // If drawing drop shadow, clip the bottom 1-px-thick separator out of |
61 // preview. | 59 // preview. |
62 // TODO(sail): remove this when GWS gives chrome the height without the | 60 // TODO(sail): remove this when GWS gives chrome the height without the |
63 // separator. | 61 // separator. |
64 if (drawDropShadow && heightUnits != INSTANT_SIZE_PERCENT) | 62 if (drawDropShadow && heightUnits != INSTANT_SIZE_PERCENT) |
65 --height; | 63 --height; |
66 | 64 |
67 if (previewContents_ == preview && | 65 if (previewContents_ == preview && |
68 previewHeight_ == height && | 66 previewHeight_ == height && |
69 previewHeightUnits_ == heightUnits && | 67 previewHeightUnits_ == heightUnits && |
70 drawDropShadow_ == drawDropShadow) { | 68 drawDropShadow_ == drawDropShadow) { |
71 return; | 69 return; |
72 } | 70 } |
73 | 71 |
74 // Remove any old preview contents before showing the new one. | 72 // Remove any old preview contents before showing the new one. |
75 if (previewContents_) | 73 if (previewContents_) { |
76 [previewContents_->GetNativeView() removeFromSuperview]; | 74 [previewContents_->GetNativeView() removeFromSuperview]; |
| 75 previewContents_->WasHidden(); |
| 76 } |
77 | 77 |
78 previewContents_ = preview; | 78 previewContents_ = preview; |
79 previewHeight_ = height; | 79 previewHeight_ = height; |
80 previewHeightUnits_ = heightUnits; | 80 previewHeightUnits_ = heightUnits; |
81 drawDropShadow_ = drawDropShadow; | 81 drawDropShadow_ = drawDropShadow; |
82 | 82 |
83 // Add the preview contents. | 83 // Add the preview contents. |
84 [[[self view] window] disableScreenUpdatesUntilFlush]; | 84 if (previewContents_) { |
85 previewContents_->GetView()->SetAllowOverlappingViews(true); | 85 [[[self view] window] disableScreenUpdatesUntilFlush]; |
86 [[self view] addSubview:previewContents_->GetNativeView()]; | 86 previewContents_->GetView()->SetAllowOverlappingViews(true); |
| 87 [[self view] addSubview:previewContents_->GetNativeView()]; |
| 88 } |
87 | 89 |
88 if (drawDropShadow_) { | 90 if (drawDropShadow_) { |
89 if (!dropShadowView_) { | 91 if (!dropShadowView_) { |
90 dropShadowView_.reset( | 92 dropShadowView_.reset( |
91 [[PreviewDropShadowView alloc] initWithFrame:NSZeroRect]); | 93 [[PreviewDropShadowView alloc] initWithFrame:NSZeroRect]); |
92 [[self view] addSubview:dropShadowView_]; | 94 [[self view] addSubview:dropShadowView_]; |
93 } | 95 } |
94 } else { | 96 } else { |
95 [dropShadowView_ removeFromSuperview]; | 97 [dropShadowView_ removeFromSuperview]; |
96 dropShadowView_.reset(); | 98 dropShadowView_.reset(); |
97 } | 99 } |
98 | 100 |
99 [self layoutViews]; | 101 [self layoutViews]; |
100 | 102 |
101 previewContents_->WasShown(); | 103 if (previewContents_) |
102 } | 104 previewContents_->WasShown(); |
103 | |
104 - (void)hidePreview { | |
105 // There may be no previewContents_ in the prerender case. | |
106 if (!previewContents_) | |
107 return; | |
108 | |
109 // Remove the preview contents. | |
110 [previewContents_->GetNativeView() removeFromSuperview]; | |
111 previewContents_->WasHidden(); | |
112 previewContents_ = nil; | |
113 | |
114 drawDropShadow_ = false; | |
115 [dropShadowView_ removeFromSuperview]; | |
116 dropShadowView_.reset(); | |
117 } | 105 } |
118 | 106 |
119 - (void)onActivateTabWithContents:(content::WebContents*)contents { | 107 - (void)onActivateTabWithContents:(content::WebContents*)contents { |
120 if (previewContents_ == contents) { | 108 if (previewContents_ == contents) { |
121 [previewContents_->GetNativeView() removeFromSuperview]; | 109 if (previewContents_) { |
122 previewContents_ = nil; | 110 [previewContents_->GetNativeView() removeFromSuperview]; |
| 111 previewContents_ = NULL; |
| 112 } |
| 113 [self setPreview:NULL |
| 114 height:0 |
| 115 heightUnits:INSTANT_SIZE_PIXELS |
| 116 drawDropShadow:NO]; |
123 } | 117 } |
124 } | 118 } |
125 | 119 |
126 - (BOOL)isShowingPreview { | 120 - (BOOL)isShowingPreview { |
127 return previewContents_ != nil; | 121 return previewContents_ != nil; |
128 } | 122 } |
129 | 123 |
130 - (InstantPreviewControllerMac*)instantPreviewController { | 124 - (InstantPreviewControllerMac*)instantPreviewController { |
131 return instantPreviewController_.get(); | 125 return instantPreviewController_.get(); |
132 } | 126 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 CGFloat height = NSHeight([[self view] bounds]) - previewOffset_; | 181 CGFloat height = NSHeight([[self view] bounds]) - previewOffset_; |
188 switch (previewHeightUnits_) { | 182 switch (previewHeightUnits_) { |
189 case INSTANT_SIZE_PERCENT: | 183 case INSTANT_SIZE_PERCENT: |
190 return std::min(height, (height * previewHeight_) / 100); | 184 return std::min(height, (height * previewHeight_) / 100); |
191 case INSTANT_SIZE_PIXELS: | 185 case INSTANT_SIZE_PIXELS: |
192 return std::min(height, previewHeight_); | 186 return std::min(height, previewHeight_); |
193 } | 187 } |
194 } | 188 } |
195 | 189 |
196 @end | 190 @end |
OLD | NEW |