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 "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" | |
8 #include "content/public/browser/web_contents.h" | 7 #include "content/public/browser/web_contents.h" |
9 #include "content/public/browser/web_contents_view.h" | 8 #include "content/public/browser/web_contents_view.h" |
10 | 9 |
11 @interface OverlayableContentsController() | 10 @interface OverlayableContentsController() |
Robert Sesek
2013/08/12 15:08:37
Delete this and the line below, too.
Jered
2013/08/12 18:11:08
Done.
| |
12 - (void)viewDidResize:(NSNotification*)note; | |
13 - (void)layoutViews; | |
14 - (CGFloat)overlayHeightInPixels; | |
15 @end | 11 @end |
16 | 12 |
17 @implementation OverlayableContentsController | 13 @implementation OverlayableContentsController |
18 | 14 |
19 - (id)initWithBrowser:(Browser*)browser { | 15 - (id)initWithBrowser:(Browser*)browser { |
20 if ((self = [super init])) { | 16 if ((self = [super init])) { |
21 base::scoped_nsobject<NSView> view( | 17 base::scoped_nsobject<NSView> view( |
22 [[NSView alloc] initWithFrame:NSZeroRect]); | 18 [[NSView alloc] initWithFrame:NSZeroRect]); |
23 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; | 19 [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; |
24 [[NSNotificationCenter defaultCenter] | |
25 addObserver:self | |
26 selector:@selector(viewDidResize:) | |
27 name:NSViewFrameDidChangeNotification | |
28 object:view]; | |
29 [self setView:view]; | 20 [self setView:view]; |
30 | 21 |
31 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); | 22 activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); |
32 [activeContainer_ setAutoresizingMask:NSViewHeightSizable | | 23 [activeContainer_ setAutoresizingMask:NSViewHeightSizable | |
33 NSViewWidthSizable]; | 24 NSViewWidthSizable]; |
34 [view addSubview:activeContainer_]; | 25 [view addSubview:activeContainer_]; |
35 | |
36 instantOverlayController_.reset( | |
37 new InstantOverlayControllerMac(browser, self)); | |
38 } | 26 } |
39 return self; | 27 return self; |
40 } | 28 } |
41 | 29 |
42 - (void)dealloc { | 30 - (void)dealloc { |
Robert Sesek
2013/08/12 15:08:37
Can remove this entire method, too.
Jered
2013/08/12 18:11:08
Done.
| |
43 [[NSNotificationCenter defaultCenter] removeObserver:self]; | |
44 [super dealloc]; | 31 [super dealloc]; |
45 } | 32 } |
46 | 33 |
47 - (void)setOverlay:(content::WebContents*)overlay | |
48 height:(CGFloat)height | |
49 heightUnits:(InstantSizeUnits)heightUnits | |
50 drawDropShadow:(BOOL)drawDropShadow { | |
51 if (overlayContents_ == overlay && | |
52 overlayHeight_ == height && | |
53 overlayHeightUnits_ == heightUnits) { | |
54 return; | |
55 } | |
56 | |
57 // Remove any old overlay contents before showing the new one. | |
58 if (overlayContents_) { | |
59 if (overlayContents_ != overlay) | |
60 overlayContents_->WasHidden(); | |
61 [overlayContents_->GetView()->GetNativeView() removeFromSuperview]; | |
62 } | |
63 | |
64 overlayContents_ = overlay; | |
65 overlayHeight_ = height; | |
66 overlayHeightUnits_ = heightUnits; | |
67 | |
68 // Add the overlay contents. | |
69 if (overlayContents_) { | |
70 [[[self view] window] disableScreenUpdatesUntilFlush]; | |
71 [[self view] addSubview:overlayContents_->GetView()->GetNativeView()]; | |
72 } | |
73 | |
74 [self layoutViews]; | |
75 | |
76 if (overlayContents_) | |
77 overlayContents_->WasShown(); | |
78 } | |
79 | |
80 - (void)onActivateTabWithContents:(content::WebContents*)contents { | |
81 if (overlayContents_ == contents) { | |
82 if (overlayContents_) { | |
83 [overlayContents_->GetView()->GetNativeView() removeFromSuperview]; | |
84 overlayContents_ = NULL; | |
85 } | |
86 [self setOverlay:NULL | |
87 height:0 | |
88 heightUnits:INSTANT_SIZE_PIXELS | |
89 drawDropShadow:NO]; | |
90 } | |
91 } | |
92 | |
93 - (InstantOverlayControllerMac*)instantOverlayController { | |
94 return instantOverlayController_.get(); | |
95 } | |
96 | |
97 - (BOOL)isShowingOverlay { | |
98 return overlayContents_ != nil; | |
99 } | |
100 | |
101 - (NSView*)activeContainer { | 34 - (NSView*)activeContainer { |
102 return activeContainer_.get(); | 35 return activeContainer_.get(); |
103 } | 36 } |
104 | 37 |
105 - (void)viewDidResize:(NSNotification*)note { | |
106 [self layoutViews]; | |
107 } | |
108 | |
109 - (void)layoutViews { | |
110 if (!overlayContents_) | |
111 return; | |
112 | |
113 // Layout the overlay. | |
114 NSRect bounds = [[self view] bounds]; | |
115 NSRect overlayFrame = bounds; | |
116 overlayFrame.size.height = [self overlayHeightInPixels]; | |
117 overlayFrame.origin.y = NSMaxY(bounds) - NSHeight(overlayFrame); | |
118 [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; | |
119 } | |
120 | |
121 - (CGFloat)overlayHeightInPixels { | |
122 CGFloat height = NSHeight([[self view] bounds]); | |
123 switch (overlayHeightUnits_) { | |
124 case INSTANT_SIZE_PERCENT: | |
125 return std::min(height, (height * overlayHeight_) / 100); | |
126 case INSTANT_SIZE_PIXELS: | |
127 return std::min(height, overlayHeight_); | |
128 } | |
129 } | |
130 | |
131 @end | 38 @end |
OLD | NEW |