| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/web/web_state/ui/crw_web_controller_container_view.h" | 5 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 | 9 |
| 10 #pragma mark - CRWToolbarContainerView | 10 #pragma mark - CRWToolbarContainerView |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | 110 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
| 111 } | 111 } |
| 112 return self; | 112 return self; |
| 113 } | 113 } |
| 114 | 114 |
| 115 #pragma mark Accessors | 115 #pragma mark Accessors |
| 116 | 116 |
| 117 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { | 117 - (void)setToolbarContainerView:(CRWToolbarContainerView*)toolbarContainerView { |
| 118 if (![_toolbarContainerView isEqual:toolbarContainerView]) { | 118 if (![_toolbarContainerView isEqual:toolbarContainerView]) { |
| 119 [_toolbarContainerView removeFromSuperview]; | 119 [_toolbarContainerView removeFromSuperview]; |
| 120 _toolbarContainerView.reset(toolbarContainerView); | 120 _toolbarContainerView.reset([toolbarContainerView retain]); |
| 121 [self addSubview:_toolbarContainerView]; | 121 [self addSubview:_toolbarContainerView]; |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 - (UIView*)toolbarContainerView { | 125 - (UIView*)toolbarContainerView { |
| 126 return _toolbarContainerView.get(); | 126 return _toolbarContainerView.get(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 #pragma mark Layout | 129 #pragma mark Layout |
| 130 | 130 |
| 131 - (void)layoutSubviews { | 131 - (void)layoutSubviews { |
| 132 [super layoutSubviews]; | 132 [super layoutSubviews]; |
| 133 | 133 |
| 134 if (self.toolbarContainerView) { | 134 if (self.toolbarContainerView) { |
| 135 [self bringSubviewToFront:self.toolbarContainerView]; | 135 [self bringSubviewToFront:self.toolbarContainerView]; |
| 136 CGSize toolbarContainerSize = | 136 CGSize toolbarContainerSize = |
| 137 [self.toolbarContainerView sizeThatFits:self.bounds.size]; | 137 [self.toolbarContainerView sizeThatFits:self.bounds.size]; |
| 138 self.toolbarContainerView.frame = | 138 self.toolbarContainerView.frame = |
| 139 CGRectMake(CGRectGetMinX(self.bounds), | 139 CGRectMake(CGRectGetMinX(self.bounds), |
| 140 CGRectGetMaxY(self.bounds) - toolbarContainerSize.height, | 140 CGRectGetMaxY(self.bounds) - toolbarContainerSize.height, |
| 141 toolbarContainerSize.width, toolbarContainerSize.height); | 141 toolbarContainerSize.width, toolbarContainerSize.height); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 #pragma mark Toolbars | 145 #pragma mark Toolbars |
| 146 | 146 |
| 147 - (void)addToolbar:(UIView*)toolbar { | 147 - (void)addToolbar:(UIView*)toolbar { |
| 148 // Create toolbar container if necessary. | 148 // Create toolbar container if necessary. |
| 149 if (!self.toolbarContainerView) { | 149 if (!self.toolbarContainerView) { |
| 150 self.toolbarContainerView = | 150 self.toolbarContainerView = [ |
| 151 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero]; | 151 [[CRWToolbarContainerView alloc] initWithFrame:CGRectZero] autorelease]; |
| 152 } | 152 } |
| 153 // Add the toolbar to the container. | 153 // Add the toolbar to the container. |
| 154 [self.toolbarContainerView addToolbar:toolbar]; | 154 [self.toolbarContainerView addToolbar:toolbar]; |
| 155 [self setNeedsLayout]; | 155 [self setNeedsLayout]; |
| 156 } | 156 } |
| 157 | 157 |
| 158 - (void)addToolbars:(NSArray*)toolbars { | 158 - (void)addToolbars:(NSArray*)toolbars { |
| 159 DCHECK(toolbars); | 159 DCHECK(toolbars); |
| 160 for (UIView* toolbar in toolbars) | 160 for (UIView* toolbar in toolbars) |
| 161 [self addToolbar:toolbar]; | 161 [self addToolbar:toolbar]; |
| 162 } | 162 } |
| 163 | 163 |
| 164 - (void)removeToolbar:(UIView*)toolbar { | 164 - (void)removeToolbar:(UIView*)toolbar { |
| 165 // Remove the toolbar from the container view. | 165 // Remove the toolbar from the container view. |
| 166 [self.toolbarContainerView removeToolbar:toolbar]; | 166 [self.toolbarContainerView removeToolbar:toolbar]; |
| 167 // Reset the container if there are no more toolbars. | 167 // Reset the container if there are no more toolbars. |
| 168 if ([self.toolbarContainerView.toolbars count]) | 168 if ([self.toolbarContainerView.toolbars count]) |
| 169 [self setNeedsLayout]; | 169 [self setNeedsLayout]; |
| 170 else | 170 else |
| 171 self.toolbarContainerView = nil; | 171 self.toolbarContainerView = nil; |
| 172 } | 172 } |
| 173 | 173 |
| 174 - (void)removeAllToolbars { | 174 - (void)removeAllToolbars { |
| 175 // Resetting the property will remove the toolbars from the hierarchy. | 175 // Resetting the property will remove the toolbars from the hierarchy. |
| 176 self.toolbarContainerView = nil; | 176 self.toolbarContainerView = nil; |
| 177 } | 177 } |
| 178 | 178 |
| 179 @end | 179 @end |
| OLD | NEW |