Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.mm

Issue 2602903002: Factor iOS native image loading into a utility function. (Closed)
Patch Set: Fixed BUILD files. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 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/omnibox/omnibox_popup_material_row.h" 5 #import "ios/chrome/browser/ui/omnibox/omnibox_popup_material_row.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_property_releaser.h"
9 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h" 9 #import "ios/chrome/browser/ui/omnibox/truncating_attributed_label.h"
10 #include "ios/chrome/browser/ui/rtl_geometry.h" 10 #include "ios/chrome/browser/ui/rtl_geometry.h"
11 #include "ios/chrome/browser/ui/ui_util.h" 11 #include "ios/chrome/browser/ui/ui_util.h"
12 #import "ios/chrome/browser/ui/uikit_ui_util.h" 12 #import "ios/chrome/browser/ui/uikit_ui_util.h"
13 #include "ios/chrome/grit/ios_theme_resources.h" 13 #include "ios/chrome/grit/ios_theme_resources.h"
14 #include "ui/base/resource/resource_bundle.h"
15 14
16 namespace { 15 namespace {
17 const CGFloat kImageDimensionLength = 19.0; 16 const CGFloat kImageDimensionLength = 19.0;
18 const CGFloat kLeadingPaddingIpad = 164; 17 const CGFloat kLeadingPaddingIpad = 164;
19 const CGFloat kLeadingPaddingIpadCompact = 71; 18 const CGFloat kLeadingPaddingIpadCompact = 71;
20 const CGFloat kAppendButtonTrailingMargin = 4; 19 const CGFloat kAppendButtonTrailingMargin = 4;
21 } 20 }
22 21
23 @interface OmniboxPopupMaterialRow () { 22 @interface OmniboxPopupMaterialRow () {
24 BOOL _incognito; 23 BOOL _incognito;
25 base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxPopupMaterialRow; 24 base::mac::ObjCPropertyReleaser _propertyReleaser_OmniboxPopupMaterialRow;
26 } 25 }
27 26
28 // Set the append button normal and highlighted images. 27 // Set the append button normal and highlighted images.
29 - (void)updateAppendButtonImages; 28 - (void)updateAppendButtonImages;
30 29
31 // Set the Physical Web image view image.
32 - (void)updatePhysicalWebImage;
33
34 @end 30 @end
35 31
36 @implementation OmniboxPopupMaterialRow 32 @implementation OmniboxPopupMaterialRow
37 33
38 @synthesize textTruncatingLabel = _textTruncatingLabel; 34 @synthesize textTruncatingLabel = _textTruncatingLabel;
39 @synthesize detailTruncatingLabel = _detailTruncatingLabel; 35 @synthesize detailTruncatingLabel = _detailTruncatingLabel;
40 @synthesize appendButton = _appendButton; 36 @synthesize appendButton = _appendButton;
41 @synthesize answerImageView = _answerImageView; 37 @synthesize answerImageView = _answerImageView;
42 @synthesize imageView = _imageView; 38 @synthesize imageView = _imageView;
43 @synthesize physicalWebImageView = _physicalWebImageView; 39 @synthesize physicalWebImageView = _physicalWebImageView;
(...skipping 29 matching lines...) Expand all
73 _appendButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; 69 _appendButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
74 [_appendButton setContentMode:UIViewContentModeRight]; 70 [_appendButton setContentMode:UIViewContentModeRight];
75 [self updateAppendButtonImages]; 71 [self updateAppendButtonImages];
76 // TODO(justincohen): Consider using the UITableViewCell's accessory view. 72 // TODO(justincohen): Consider using the UITableViewCell's accessory view.
77 // The current implementation is from before using a UITableViewCell. 73 // The current implementation is from before using a UITableViewCell.
78 [self addSubview:_appendButton]; 74 [self addSubview:_appendButton];
79 75
80 _physicalWebImageView = [[UIImageView alloc] initWithFrame:CGRectZero]; 76 _physicalWebImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
81 _physicalWebImageView.userInteractionEnabled = NO; 77 _physicalWebImageView.userInteractionEnabled = NO;
82 _physicalWebImageView.contentMode = UIViewContentModeCenter; 78 _physicalWebImageView.contentMode = UIViewContentModeCenter;
83 [self updatePhysicalWebImage]; 79 _physicalWebImageView.image = NativeImage(IDR_IOS_OMNIBOX_PHYSICAL_WEB);
84 [self addSubview:_physicalWebImageView]; 80 [self addSubview:_physicalWebImageView];
85 81
86 // Left icon is only displayed on iPad. 82 // Left icon is only displayed on iPad.
87 if (IsIPadIdiom()) { 83 if (IsIPadIdiom()) {
88 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; 84 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
89 _imageView.userInteractionEnabled = NO; 85 _imageView.userInteractionEnabled = NO;
90 _imageView.contentMode = UIViewContentModeCenter; 86 _imageView.contentMode = UIViewContentModeCenter;
91 87
92 // TODO(justincohen): Consider using the UITableViewCell's image view. 88 // TODO(justincohen): Consider using the UITableViewCell's image view.
93 // The current implementation is from before using a UITableViewCell. 89 // The current implementation is from before using a UITableViewCell.
(...skipping 26 matching lines...) Expand all
120 LayoutRect rightAccessoryLayout = 116 LayoutRect rightAccessoryLayout =
121 LayoutRectMake(CGRectGetWidth(self.bounds) - appendButtonDimensionLength - 117 LayoutRectMake(CGRectGetWidth(self.bounds) - appendButtonDimensionLength -
122 kAppendButtonTrailingMargin, 118 kAppendButtonTrailingMargin,
123 CGRectGetWidth(self.bounds), 119 CGRectGetWidth(self.bounds),
124 floor((_rowHeight - appendButtonDimensionLength) / 2), 120 floor((_rowHeight - appendButtonDimensionLength) / 2),
125 appendButtonDimensionLength, appendButtonDimensionLength); 121 appendButtonDimensionLength, appendButtonDimensionLength);
126 _appendButton.frame = LayoutRectGetRect(rightAccessoryLayout); 122 _appendButton.frame = LayoutRectGetRect(rightAccessoryLayout);
127 _physicalWebImageView.frame = LayoutRectGetRect(rightAccessoryLayout); 123 _physicalWebImageView.frame = LayoutRectGetRect(rightAccessoryLayout);
128 } 124 }
129 125
130 - (void)updateLeftImage:(int)imageId { 126 - (void)updateLeftImage:(int)imageID {
131 // Update the image. 127 _imageView.image = NativeImage(imageID);
132 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
133 UIImage* image = rb.GetNativeImageNamed(imageId).ToUIImage();
134 _imageView.image = image;
135 128
136 // Adjust the vertical position based on the current size of the row. 129 // Adjust the vertical position based on the current size of the row.
137 CGRect frame = _imageView.frame; 130 CGRect frame = _imageView.frame;
138 frame.origin.y = floor((_rowHeight - kImageDimensionLength) / 2); 131 frame.origin.y = floor((_rowHeight - kImageDimensionLength) / 2);
139 _imageView.frame = frame; 132 _imageView.frame = frame;
140 } 133 }
141 134
142 - (void)updateHighlightBackground:(BOOL)highlighted { 135 - (void)updateHighlightBackground:(BOOL)highlighted {
143 // Set the background color to match the color of selected table view cells 136 // Set the background color to match the color of selected table view cells
144 // when their selection style is UITableViewCellSelectionStyleGray. 137 // when their selection style is UITableViewCellSelectionStyleGray.
145 if (highlighted) { 138 if (highlighted) {
146 self.backgroundColor = _incognito ? [UIColor colorWithWhite:1 alpha:0.1] 139 self.backgroundColor = _incognito ? [UIColor colorWithWhite:1 alpha:0.1]
147 : [UIColor colorWithWhite:0 alpha:0.05]; 140 : [UIColor colorWithWhite:0 alpha:0.05];
148 } else { 141 } else {
149 self.backgroundColor = [UIColor clearColor]; 142 self.backgroundColor = [UIColor clearColor];
150 } 143 }
151 } 144 }
152 145
153 - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 146 - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
154 [super setHighlighted:highlighted animated:animated]; 147 [super setHighlighted:highlighted animated:animated];
155 [self updateHighlightBackground:highlighted]; 148 [self updateHighlightBackground:highlighted];
156 } 149 }
157 150
158 - (void)setHighlighted:(BOOL)highlighted { 151 - (void)setHighlighted:(BOOL)highlighted {
159 [super setHighlighted:highlighted]; 152 [super setHighlighted:highlighted];
160 [self updateHighlightBackground:highlighted]; 153 [self updateHighlightBackground:highlighted];
161 } 154 }
162 155
163 - (void)updateAppendButtonImages { 156 - (void)updateAppendButtonImages {
164 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
165 int appendResourceID = _incognito 157 int appendResourceID = _incognito
166 ? IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_INCOGNITO 158 ? IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_INCOGNITO
167 : IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND; 159 : IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND;
168 UIImage* appendImage = rb.GetNativeImageNamed(appendResourceID).ToUIImage(); 160 UIImage* appendImage = NativeReversableImage(appendResourceID, YES);
169 if (UseRTLLayout()) {
170 appendImage = [appendImage imageFlippedForRightToLeftLayoutDirection];
171 }
172 161
173 [_appendButton setImage:appendImage forState:UIControlStateNormal]; 162 [_appendButton setImage:appendImage forState:UIControlStateNormal];
174 int appendSelectedResourceID = 163 int appendSelectedResourceID =
175 _incognito ? IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_INCOGNITO_HIGHLIGHTED 164 _incognito ? IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_INCOGNITO_HIGHLIGHTED
176 : IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_HIGHLIGHTED; 165 : IDR_IOS_OMNIBOX_KEYBOARD_VIEW_APPEND_HIGHLIGHTED;
177 UIImage* appendImageSelected = 166 UIImage* appendImageSelected = NativeImage(appendSelectedResourceID);
178 rb.GetNativeImageNamed(appendSelectedResourceID).ToUIImage();
179 [_appendButton setImage:appendImageSelected 167 [_appendButton setImage:appendImageSelected
180 forState:UIControlStateHighlighted]; 168 forState:UIControlStateHighlighted];
181 } 169 }
182 170
183 - (void)updatePhysicalWebImage {
184 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
185 UIImage* physicalWebImage =
186 rb.GetNativeImageNamed(IDR_IOS_OMNIBOX_PHYSICAL_WEB).ToUIImage();
187 _physicalWebImageView.image = physicalWebImage;
188 }
189
190 - (NSString*)accessibilityLabel { 171 - (NSString*)accessibilityLabel {
191 return _textTruncatingLabel.attributedText.string; 172 return _textTruncatingLabel.attributedText.string;
192 } 173 }
193 174
194 - (NSString*)accessibilityValue { 175 - (NSString*)accessibilityValue {
195 return _detailTruncatingLabel.attributedText.string; 176 return _detailTruncatingLabel.attributedText.string;
196 } 177 }
197 178
198 @end 179 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698