| 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/ntp/new_tab_page_view.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/objc_property_releaser.h" | 8 #include "base/mac/objc_release_properties.h" |
| 9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" | 9 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" |
| 10 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 10 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
| 11 #import "ios/chrome/browser/ui/rtl_geometry.h" | 11 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 12 #include "ios/chrome/browser/ui/ui_util.h" | 12 #include "ios/chrome/browser/ui/ui_util.h" |
| 13 | 13 |
| 14 @implementation NewTabPageView { | 14 @implementation NewTabPageView |
| 15 @private | |
| 16 // The objects pointed to by |tabBar_| and |scrollView_| are owned as | |
| 17 // subviews already. | |
| 18 __unsafe_unretained NewTabPageBar* tabBar_; // weak | |
| 19 __unsafe_unretained UIScrollView* scrollView_; // weak | |
| 20 | |
| 21 base::mac::ObjCPropertyReleaser propertyReleaser_NewTabPageView_; | |
| 22 } | |
| 23 | 15 |
| 24 @synthesize scrollView = scrollView_; | 16 @synthesize scrollView = scrollView_; |
| 25 @synthesize tabBar = tabBar_; | 17 @synthesize tabBar = tabBar_; |
| 26 | 18 |
| 27 - (instancetype)initWithFrame:(CGRect)frame | 19 - (instancetype)initWithFrame:(CGRect)frame |
| 28 andScrollView:(UIScrollView*)scrollView | 20 andScrollView:(UIScrollView*)scrollView |
| 29 andTabBar:(NewTabPageBar*)tabBar { | 21 andTabBar:(NewTabPageBar*)tabBar { |
| 30 self = [super initWithFrame:frame]; | 22 self = [super initWithFrame:frame]; |
| 31 if (self) { | 23 if (self) { |
| 32 propertyReleaser_NewTabPageView_.Init(self, [NewTabPageView class]); | |
| 33 [self addSubview:scrollView]; | 24 [self addSubview:scrollView]; |
| 34 [self addSubview:tabBar]; | 25 [self addSubview:tabBar]; |
| 35 scrollView_ = scrollView; | 26 scrollView_ = scrollView; |
| 36 tabBar_ = tabBar; | 27 tabBar_ = tabBar; |
| 37 } | 28 } |
| 38 return self; | 29 return self; |
| 39 } | 30 } |
| 40 | 31 |
| 41 - (instancetype)initWithFrame:(CGRect)frame { | 32 - (instancetype)initWithFrame:(CGRect)frame { |
| 42 NOTREACHED(); | 33 NOTREACHED(); |
| 43 return nil; | 34 return nil; |
| 44 } | 35 } |
| 45 | 36 |
| 46 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 37 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
| 47 NOTREACHED(); | 38 NOTREACHED(); |
| 48 return nil; | 39 return nil; |
| 49 } | 40 } |
| 50 | 41 |
| 42 - (void)dealloc { |
| 43 base::mac::ReleaseProperties(self); |
| 44 [super dealloc]; |
| 45 } |
| 46 |
| 51 - (void)setFrame:(CGRect)frame { | 47 - (void)setFrame:(CGRect)frame { |
| 52 // When transitioning the iPhone xib to an iPad idiom, the setFrame call below | 48 // When transitioning the iPhone xib to an iPad idiom, the setFrame call below |
| 53 // can sometimes fire a scrollViewDidScroll event which changes the | 49 // can sometimes fire a scrollViewDidScroll event which changes the |
| 54 // selectedIndex underneath us. Save the selected index and remove the | 50 // selectedIndex underneath us. Save the selected index and remove the |
| 55 // delegate so scrollViewDidScroll isn't called. Then fix the scrollView | 51 // delegate so scrollViewDidScroll isn't called. Then fix the scrollView |
| 56 // offset after updating the frame. | 52 // offset after updating the frame. |
| 57 NSUInteger selectedIndex = self.tabBar.selectedIndex; | 53 NSUInteger selectedIndex = self.tabBar.selectedIndex; |
| 58 id<UIScrollViewDelegate> delegate = self.scrollView.delegate; | 54 id<UIScrollViewDelegate> delegate = self.scrollView.delegate; |
| 59 self.scrollView.delegate = nil; | 55 self.scrollView.delegate = nil; |
| 60 [super setFrame:frame]; | 56 [super setFrame:frame]; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index { | 113 - (CGRect)panelFrameForItemAtIndex:(NSUInteger)index { |
| 118 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width, | 114 CGRect contentBounds = CGRectMake(0, 0, self.scrollView.contentSize.width, |
| 119 self.scrollView.contentSize.height); | 115 self.scrollView.contentSize.height); |
| 120 LayoutRect layout = | 116 LayoutRect layout = |
| 121 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds); | 117 LayoutRectForRectInBoundingRect(self.scrollView.bounds, contentBounds); |
| 122 layout.position.leading = layout.size.width * index; | 118 layout.position.leading = layout.size.width * index; |
| 123 return LayoutRectGetRect(layout); | 119 return LayoutRectGetRect(layout); |
| 124 } | 120 } |
| 125 | 121 |
| 126 @end | 122 @end |
| OLD | NEW |