| 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_bar.h" | 5 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/objc_property_releaser.h" | 11 #include "base/mac/objc_release_properties.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 14 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_button.h" | 14 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_button.h" |
| 15 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" | 15 #import "ios/chrome/browser/ui/ntp/new_tab_page_bar_item.h" |
| 16 #import "ios/chrome/browser/ui/rtl_geometry.h" | 16 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 17 #include "ios/chrome/browser/ui/ui_util.h" | 17 #include "ios/chrome/browser/ui/ui_util.h" |
| 18 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 18 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 19 #import "ui/gfx/ios/NSString+CrStringDrawing.h" | 19 #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
| 20 #include "ui/gfx/scoped_ui_graphics_push_context_ios.h" | 20 #include "ui/gfx/scoped_ui_graphics_push_context_ios.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const CGFloat kBarHeight = 48.0f; | 24 const CGFloat kBarHeight = 48.0f; |
| 25 | 25 |
| 26 const CGFloat kRegularLayoutButtonWidth = 168; | 26 const CGFloat kRegularLayoutButtonWidth = 168; |
| 27 | 27 |
| 28 const int kOverlayViewColor = 0x5A7EF5; | 28 const int kOverlayViewColor = 0x5A7EF5; |
| 29 const int kOverlayColorWidth = 98; | 29 const int kOverlayColorWidth = 98; |
| 30 const int kNumberOfTabsIncognito = 2; | 30 const int kNumberOfTabsIncognito = 2; |
| 31 | 31 |
| 32 } // anonymous namespace | 32 } // anonymous namespace |
| 33 | 33 |
| 34 @interface NewTabPageBar () { | 34 @interface NewTabPageBar () { |
| 35 base::scoped_nsobject<UIImageView> shadow_; | 35 base::scoped_nsobject<UIImageView> shadow_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 @property(nonatomic, readwrite, retain) NSArray* buttons; | 38 @property(nonatomic, readwrite, retain) NSArray* buttons; |
| 39 @property(nonatomic, readwrite, retain) UIButton* popupButton; | |
| 40 | 39 |
| 41 - (void)setup; | 40 - (void)setup; |
| 42 - (void)calculateButtonWidth; | 41 - (void)calculateButtonWidth; |
| 43 - (void)setupButton:(UIButton*)button; | 42 - (void)setupButton:(UIButton*)button; |
| 44 - (BOOL)useIconsInButtons; | 43 - (BOOL)useIconsInButtons; |
| 45 - (BOOL)showOverlay; | 44 - (BOOL)showOverlay; |
| 46 @end | 45 @end |
| 47 | 46 |
| 48 @implementation NewTabPageBar { | 47 @implementation NewTabPageBar { |
| 49 // Tabbar buttons. | 48 NSArray* buttons_; |
| 50 NSArray* buttons_; // UIButton | 49 NSArray* items_; |
| 51 NSArray* items_; // NewTabPageBarItem | |
| 52 // Which button is currently selected. | |
| 53 NSUInteger selectedIndex_; | 50 NSUInteger selectedIndex_; |
| 54 // Popup button helper, for iPhone labels. | |
| 55 UIButton* popupButton_; | |
| 56 // Don't allow tabbar animations on startup, only after first tap. | 51 // Don't allow tabbar animations on startup, only after first tap. |
| 57 BOOL canAnimate_; | 52 BOOL canAnimate_; |
| 58 id<NewTabPageBarDelegate> delegate_; // weak | 53 id<NewTabPageBarDelegate> delegate_; // weak |
| 59 // Logo view, used to center the tab buttons. | 54 // Logo view, used to center the tab buttons. |
| 60 base::scoped_nsobject<UIImageView> logoView_; | 55 base::scoped_nsobject<UIImageView> logoView_; |
| 61 // Overlay view, used to highlight the selected button. | 56 // Overlay view, used to highlight the selected button. |
| 62 base::scoped_nsobject<UIImageView> overlayView_; | 57 base::scoped_nsobject<UIImageView> overlayView_; |
| 63 // Overlay view, used to highlight the selected button. | 58 // Overlay view, used to highlight the selected button. |
| 64 base::scoped_nsobject<UIView> overlayColorView_; | 59 base::scoped_nsobject<UIView> overlayColorView_; |
| 65 // Width of a button. | 60 // Width of a button. |
| 66 CGFloat buttonWidth_; | 61 CGFloat buttonWidth_; |
| 67 // Percentage overlay sits over tab bar buttons. | 62 // Percentage overlay sits over tab bar buttons. |
| 68 CGFloat overlayPercentage_; | 63 CGFloat overlayPercentage_; |
| 69 | |
| 70 base::mac::ObjCPropertyReleaser propertyReleaser_NewTabPageBar_; | |
| 71 } | 64 } |
| 72 | 65 |
| 73 @synthesize items = items_; | 66 @synthesize items = items_; |
| 74 @synthesize selectedIndex = selectedIndex_; | 67 @synthesize selectedIndex = selectedIndex_; |
| 75 @synthesize popupButton = popupButton_; | |
| 76 @synthesize buttons = buttons_; | 68 @synthesize buttons = buttons_; |
| 77 @synthesize delegate = delegate_; | 69 @synthesize delegate = delegate_; |
| 78 @synthesize overlayPercentage = overlayPercentage_; | 70 @synthesize overlayPercentage = overlayPercentage_; |
| 79 | 71 |
| 80 - (id)initWithFrame:(CGRect)frame { | 72 - (id)initWithFrame:(CGRect)frame { |
| 81 self = [super initWithFrame:frame]; | 73 self = [super initWithFrame:frame]; |
| 82 if (self) { | 74 if (self) { |
| 83 [self setup]; | 75 [self setup]; |
| 84 } | 76 } |
| 85 return self; | 77 return self; |
| 86 } | 78 } |
| 87 | 79 |
| 88 - (id)initWithCoder:(NSCoder*)aDecoder { | 80 - (id)initWithCoder:(NSCoder*)aDecoder { |
| 89 self = [super initWithCoder:aDecoder]; | 81 self = [super initWithCoder:aDecoder]; |
| 90 if (self) { | 82 if (self) { |
| 91 [self setup]; | 83 [self setup]; |
| 92 } | 84 } |
| 93 return self; | 85 return self; |
| 94 } | 86 } |
| 95 | 87 |
| 96 - (void)setup { | 88 - (void)setup { |
| 97 propertyReleaser_NewTabPageBar_.Init(self, [NewTabPageBar class]); | |
| 98 self.selectedIndex = NSNotFound; | 89 self.selectedIndex = NSNotFound; |
| 99 canAnimate_ = NO; | 90 canAnimate_ = NO; |
| 100 self.autoresizingMask = | 91 self.autoresizingMask = |
| 101 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; | 92 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; |
| 102 self.autoresizesSubviews = YES; | 93 self.autoresizesSubviews = YES; |
| 103 self.backgroundColor = [UIColor clearColor]; | 94 self.backgroundColor = [UIColor clearColor]; |
| 104 | 95 |
| 105 if ([self showOverlay]) { | 96 if ([self showOverlay]) { |
| 106 overlayView_.reset( | 97 overlayView_.reset( |
| 107 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, buttonWidth_, 2)]); | 98 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, buttonWidth_, 2)]); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 // Shadow is positioned directly above the new tab page bar. | 117 // Shadow is positioned directly above the new tab page bar. |
| 127 [shadow_ | 118 [shadow_ |
| 128 setFrame:CGRectMake(0, -shadowImage.size.height, self.bounds.size.width, | 119 setFrame:CGRectMake(0, -shadowImage.size.height, self.bounds.size.width, |
| 129 shadowImage.size.height)]; | 120 shadowImage.size.height)]; |
| 130 [shadow_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 121 [shadow_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
| 131 [self addSubview:shadow_]; | 122 [self addSubview:shadow_]; |
| 132 | 123 |
| 133 self.contentMode = UIViewContentModeRedraw; | 124 self.contentMode = UIViewContentModeRedraw; |
| 134 } | 125 } |
| 135 | 126 |
| 127 - (void)dealloc { |
| 128 base::mac::ReleaseProperties(self); |
| 129 [super dealloc]; |
| 130 } |
| 131 |
| 136 - (void)layoutSubviews { | 132 - (void)layoutSubviews { |
| 137 [super layoutSubviews]; | 133 [super layoutSubviews]; |
| 138 | 134 |
| 139 // |buttonWidth_| changes with the screen orientation when the NTP button bar | 135 // |buttonWidth_| changes with the screen orientation when the NTP button bar |
| 140 // is enabled. | 136 // is enabled. |
| 141 [self calculateButtonWidth]; | 137 [self calculateButtonWidth]; |
| 142 | 138 |
| 143 CGFloat logoWidth = logoView_.get().image.size.width; | 139 CGFloat logoWidth = logoView_.get().image.size.width; |
| 144 CGFloat padding = [self useIconsInButtons] ? logoWidth : 0; | 140 CGFloat padding = [self useIconsInButtons] ? logoWidth : 0; |
| 145 CGFloat buttonPadding = floor((CGRectGetWidth(self.bounds) - padding - | 141 CGFloat buttonPadding = floor((CGRectGetWidth(self.bounds) - padding - |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return !IsIPadIdiom() || IsCompactTablet(); | 318 return !IsIPadIdiom() || IsCompactTablet(); |
| 323 } | 319 } |
| 324 | 320 |
| 325 - (BOOL)showOverlay { | 321 - (BOOL)showOverlay { |
| 326 // The bar buttons launch modal dialogs on tap on iPhone. Don't show overlay | 322 // The bar buttons launch modal dialogs on tap on iPhone. Don't show overlay |
| 327 // in this case. | 323 // in this case. |
| 328 return IsIPadIdiom(); | 324 return IsIPadIdiom(); |
| 329 } | 325 } |
| 330 | 326 |
| 331 @end | 327 @end |
| OLD | NEW |