| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/chrome/browser/ui/stack_view/stack_card.h" | 5 #import "ios/chrome/browser/ui/stack_view/stack_card.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/scoped_nsobject.h" |
| 8 #import "ios/chrome/browser/ui/rtl_geometry.h" | 9 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 9 #import "ios/chrome/browser/ui/stack_view/card_view.h" | 10 #import "ios/chrome/browser/ui/stack_view/card_view.h" |
| 10 #import "ios/chrome/browser/ui/ui_util.h" | 11 #import "ios/chrome/browser/ui/ui_util.h" |
| 11 | 12 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 13 #error "This file requires ARC support." | |
| 14 #endif | |
| 15 | |
| 16 @interface StackCard () { | 13 @interface StackCard () { |
| 17 __weak id<StackCardViewProvider> _viewProvider; | 14 id<StackCardViewProvider> _viewProvider; |
| 18 CardView* _view; | 15 base::scoped_nsobject<CardView> _view; |
| 19 } | 16 } |
| 20 | 17 |
| 21 // The pixel-aligned frame generated by applying |self.layout| under the current | 18 // The pixel-aligned frame generated by applying |self.layout| under the current |
| 22 // language direction. | 19 // language direction. |
| 23 @property(nonatomic, readonly) CGRect frame; | 20 @property(nonatomic, readonly) CGRect frame; |
| 24 | 21 |
| 25 // Applies |self.layout| to the underlying CardView if it exists. | 22 // Applies |self.layout| to the underlying CardView if it exists. |
| 26 - (void)applyLayout; | 23 - (void)applyLayout; |
| 27 | 24 |
| 28 @end | 25 @end |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 return self; | 40 return self; |
| 44 } | 41 } |
| 45 | 42 |
| 46 - (instancetype)init { | 43 - (instancetype)init { |
| 47 NOTREACHED(); | 44 NOTREACHED(); |
| 48 return nil; | 45 return nil; |
| 49 } | 46 } |
| 50 | 47 |
| 51 - (void)releaseView { | 48 - (void)releaseView { |
| 52 if (self.viewIsLive) | 49 if (self.viewIsLive) |
| 53 _view = nil; | 50 _view.reset(); |
| 54 } | 51 } |
| 55 | 52 |
| 56 #pragma mark - Properties | 53 #pragma mark - Properties |
| 57 | 54 |
| 58 - (CardView*)view { | 55 - (CardView*)view { |
| 59 if (!_view) { | 56 if (!_view) { |
| 60 _view = [_viewProvider cardViewWithFrame:self.frame forStackCard:self]; | 57 _view.reset([[_viewProvider cardViewWithFrame:self.frame forStackCard:self] |
| 61 _view.isActiveTab = _isActiveTab; | 58 retain]); |
| 59 _view.get().isActiveTab = _isActiveTab; |
| 62 } | 60 } |
| 63 return _view; | 61 return _view.get(); |
| 64 } | 62 } |
| 65 | 63 |
| 66 - (void)setLayout:(LayoutRect)layout { | 64 - (void)setLayout:(LayoutRect)layout { |
| 67 if (!LayoutRectEqualToRect(_layout, layout)) { | 65 if (!LayoutRectEqualToRect(_layout, layout)) { |
| 68 _layout = layout; | 66 _layout = layout; |
| 69 [self applyLayout]; | 67 [self applyLayout]; |
| 70 } | 68 } |
| 71 } | 69 } |
| 72 | 70 |
| 73 - (CGSize)size { | 71 - (CGSize)size { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 | 84 |
| 87 - (void)setSynchronizeView:(BOOL)synchronizeView { | 85 - (void)setSynchronizeView:(BOOL)synchronizeView { |
| 88 if (_synchronizeView != synchronizeView) { | 86 if (_synchronizeView != synchronizeView) { |
| 89 _synchronizeView = synchronizeView; | 87 _synchronizeView = synchronizeView; |
| 90 [self applyLayout]; | 88 [self applyLayout]; |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 | 91 |
| 94 - (void)setIsActiveTab:(BOOL)isActiveTab { | 92 - (void)setIsActiveTab:(BOOL)isActiveTab { |
| 95 _isActiveTab = isActiveTab; | 93 _isActiveTab = isActiveTab; |
| 96 _view.isActiveTab = _isActiveTab; | 94 _view.get().isActiveTab = _isActiveTab; |
| 97 } | 95 } |
| 98 | 96 |
| 99 - (BOOL)viewIsLive { | 97 - (BOOL)viewIsLive { |
| 100 return _view != nil; | 98 return _view != nil; |
| 101 } | 99 } |
| 102 | 100 |
| 103 - (CGRect)frame { | 101 - (CGRect)frame { |
| 104 return AlignRectOriginAndSizeToPixels(LayoutRectGetRect(self.layout)); | 102 return AlignRectOriginAndSizeToPixels(LayoutRectGetRect(self.layout)); |
| 105 } | 103 } |
| 106 | 104 |
| 107 #pragma mark - | 105 #pragma mark - |
| 108 | 106 |
| 109 - (void)applyLayout { | 107 - (void)applyLayout { |
| 110 if (!self.viewIsLive || !self.synchronizeView) | 108 if (!self.viewIsLive || !self.synchronizeView) |
| 111 return; | 109 return; |
| 112 self.view.frame = self.frame; | 110 self.view.frame = self.frame; |
| 113 } | 111 } |
| 114 | 112 |
| 115 @end | 113 @end |
| OLD | NEW |