| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // Logo view, used to center the tab buttons. | 59 // Logo view, used to center the tab buttons. |
| 60 base::scoped_nsobject<UIImageView> logoView_; | 60 base::scoped_nsobject<UIImageView> logoView_; |
| 61 // Overlay view, used to highlight the selected button. | 61 // Overlay view, used to highlight the selected button. |
| 62 base::scoped_nsobject<UIImageView> overlayView_; | 62 base::scoped_nsobject<UIImageView> overlayView_; |
| 63 // Overlay view, used to highlight the selected button. | 63 // Overlay view, used to highlight the selected button. |
| 64 base::scoped_nsobject<UIView> overlayColorView_; | 64 base::scoped_nsobject<UIView> overlayColorView_; |
| 65 // Width of a button. | 65 // Width of a button. |
| 66 CGFloat buttonWidth_; | 66 CGFloat buttonWidth_; |
| 67 // Percentage overlay sits over tab bar buttons. | 67 // Percentage overlay sits over tab bar buttons. |
| 68 CGFloat overlayPercentage_; | 68 CGFloat overlayPercentage_; |
| 69 | |
| 70 base::mac::ObjCPropertyReleaser propertyReleaser_NewTabPageBar_; | |
| 71 } | 69 } |
| 72 | 70 |
| 73 @synthesize items = items_; | 71 @synthesize items = items_; |
| 74 @synthesize selectedIndex = selectedIndex_; | 72 @synthesize selectedIndex = selectedIndex_; |
| 75 @synthesize popupButton = popupButton_; | 73 @synthesize popupButton = popupButton_; |
| 76 @synthesize buttons = buttons_; | 74 @synthesize buttons = buttons_; |
| 77 @synthesize delegate = delegate_; | 75 @synthesize delegate = delegate_; |
| 78 @synthesize overlayPercentage = overlayPercentage_; | 76 @synthesize overlayPercentage = overlayPercentage_; |
| 79 | 77 |
| 80 - (id)initWithFrame:(CGRect)frame { | 78 - (id)initWithFrame:(CGRect)frame { |
| 81 self = [super initWithFrame:frame]; | 79 self = [super initWithFrame:frame]; |
| 82 if (self) { | 80 if (self) { |
| 83 [self setup]; | 81 [self setup]; |
| 84 } | 82 } |
| 85 return self; | 83 return self; |
| 86 } | 84 } |
| 87 | 85 |
| 88 - (id)initWithCoder:(NSCoder*)aDecoder { | 86 - (id)initWithCoder:(NSCoder*)aDecoder { |
| 89 self = [super initWithCoder:aDecoder]; | 87 self = [super initWithCoder:aDecoder]; |
| 90 if (self) { | 88 if (self) { |
| 91 [self setup]; | 89 [self setup]; |
| 92 } | 90 } |
| 93 return self; | 91 return self; |
| 94 } | 92 } |
| 95 | 93 |
| 96 - (void)setup { | 94 - (void)setup { |
| 97 propertyReleaser_NewTabPageBar_.Init(self, [NewTabPageBar class]); | |
| 98 self.selectedIndex = NSNotFound; | 95 self.selectedIndex = NSNotFound; |
| 99 canAnimate_ = NO; | 96 canAnimate_ = NO; |
| 100 self.autoresizingMask = | 97 self.autoresizingMask = |
| 101 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; | 98 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; |
| 102 self.autoresizesSubviews = YES; | 99 self.autoresizesSubviews = YES; |
| 103 self.backgroundColor = [UIColor clearColor]; | 100 self.backgroundColor = [UIColor clearColor]; |
| 104 | 101 |
| 105 if ([self showOverlay]) { | 102 if ([self showOverlay]) { |
| 106 overlayView_.reset( | 103 overlayView_.reset( |
| 107 [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, buttonWidth_, 2)]); | 104 [[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. | 123 // Shadow is positioned directly above the new tab page bar. |
| 127 [shadow_ | 124 [shadow_ |
| 128 setFrame:CGRectMake(0, -shadowImage.size.height, self.bounds.size.width, | 125 setFrame:CGRectMake(0, -shadowImage.size.height, self.bounds.size.width, |
| 129 shadowImage.size.height)]; | 126 shadowImage.size.height)]; |
| 130 [shadow_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; | 127 [shadow_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; |
| 131 [self addSubview:shadow_]; | 128 [self addSubview:shadow_]; |
| 132 | 129 |
| 133 self.contentMode = UIViewContentModeRedraw; | 130 self.contentMode = UIViewContentModeRedraw; |
| 134 } | 131 } |
| 135 | 132 |
| 133 - (void)dealloc { |
| 134 base::mac::ReleaseProperties(self); |
| 135 [super dealloc]; |
| 136 } |
| 137 |
| 136 - (void)layoutSubviews { | 138 - (void)layoutSubviews { |
| 137 [super layoutSubviews]; | 139 [super layoutSubviews]; |
| 138 | 140 |
| 139 // |buttonWidth_| changes with the screen orientation when the NTP button bar | 141 // |buttonWidth_| changes with the screen orientation when the NTP button bar |
| 140 // is enabled. | 142 // is enabled. |
| 141 [self calculateButtonWidth]; | 143 [self calculateButtonWidth]; |
| 142 | 144 |
| 143 CGFloat logoWidth = logoView_.get().image.size.width; | 145 CGFloat logoWidth = logoView_.get().image.size.width; |
| 144 CGFloat padding = [self useIconsInButtons] ? logoWidth : 0; | 146 CGFloat padding = [self useIconsInButtons] ? logoWidth : 0; |
| 145 CGFloat buttonPadding = floor((CGRectGetWidth(self.bounds) - padding - | 147 CGFloat buttonPadding = floor((CGRectGetWidth(self.bounds) - padding - |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return !IsIPadIdiom() || IsCompactTablet(); | 324 return !IsIPadIdiom() || IsCompactTablet(); |
| 323 } | 325 } |
| 324 | 326 |
| 325 - (BOOL)showOverlay { | 327 - (BOOL)showOverlay { |
| 326 // The bar buttons launch modal dialogs on tap on iPhone. Don't show overlay | 328 // The bar buttons launch modal dialogs on tap on iPhone. Don't show overlay |
| 327 // in this case. | 329 // in this case. |
| 328 return IsIPadIdiom(); | 330 return IsIPadIdiom(); |
| 329 } | 331 } |
| 330 | 332 |
| 331 @end | 333 @end |
| OLD | NEW |