OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 value:DimTextColor() | 148 value:DimTextColor() |
149 range:range]; | 149 range:range]; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 return as; | 153 return as; |
154 } | 154 } |
155 | 155 |
156 } // namespace | 156 } // namespace |
157 | 157 |
158 @implementation AutocompleteMatchWrapper | |
159 @end | |
160 | |
158 @implementation OmniboxPopupCell | 161 @implementation OmniboxPopupCell |
159 | 162 |
163 @synthesize attributedTitle; | |
164 | |
160 - (id)init { | 165 - (id)init { |
161 self = [super init]; | 166 self = [super init]; |
162 if (self) { | 167 if (self) { |
163 [self setImagePosition:NSImageLeft]; | |
164 [self setBordered:NO]; | |
165 [self setButtonType:NSRadioButton]; | |
166 | |
167 // Without this highlighting messes up white areas of images. | |
168 [self setHighlightsBy:NSNoCellMask]; | |
169 | |
170 const base::string16& raw_separator = | 168 const base::string16& raw_separator = |
171 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 169 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); |
172 separator_.reset( | 170 separator_.reset( |
173 [CreateAttributedString(raw_separator, DimTextColor()) retain]); | 171 [CreateAttributedString(raw_separator, DimTextColor()) retain]); |
174 } | 172 } |
175 return self; | 173 return self; |
176 } | 174 } |
177 | 175 |
178 - (void)setMatch:(const AutocompleteMatch&)match { | 176 - (void)setMatch:(const AutocompleteMatch&)match { |
179 match_ = match; | 177 match_ = match; |
(...skipping 18 matching lines...) Expand all Loading... | |
198 description_.reset([CreateClassifiedAttributedString( | 196 description_.reset([CreateClassifiedAttributedString( |
199 answerString, DimTextColor(), match_.description_class) retain]); | 197 answerString, DimTextColor(), match_.description_class) retain]); |
200 } else if (match_.description.empty()) { | 198 } else if (match_.description.empty()) { |
201 description_.reset(); | 199 description_.reset(); |
202 } else { | 200 } else { |
203 description_.reset([CreateClassifiedAttributedString( | 201 description_.reset([CreateClassifiedAttributedString( |
204 match_.description, DimTextColor(), match_.description_class) retain]); | 202 match_.description, DimTextColor(), match_.description_class) retain]); |
205 } | 203 } |
206 } | 204 } |
207 | 205 |
206 - (id)copyWithZone:(NSZone*)zone { | |
207 NSAttributedString* separator = separator_.release(); | |
208 NSAttributedString* description = description_.release(); | |
209 NSAttributedString* prefix = prefix_.release(); | |
210 OmniboxPopupCell* copy = [super copyWithZone:zone]; | |
211 copy->match_ = match_; | |
212 copy->separator_.reset([separator copy]); | |
213 copy->description_.reset([description copy]); | |
214 copy->prefix_.reset([prefix copy]); | |
215 copy->maxMatchContentsWidth_ = maxMatchContentsWidth_; | |
216 copy->contentsOffset_ = contentsOffset_; | |
217 separator_.reset(separator); | |
218 description_.reset(description); | |
219 prefix_.reset(prefix); | |
220 return copy; | |
221 } | |
Scott Hess - ex-Googler
2015/05/04 19:40:20
WRT your other question about whether -copyWithZon
dschuyler
2015/05/04 23:51:40
Yeah, it does seem to use the same cell over and o
Scott Hess - ex-Googler
2015/05/07 22:35:41
This is something I'm not entirely certain of. It
| |
222 | |
208 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth { | 223 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth { |
209 maxMatchContentsWidth_ = maxMatchContentsWidth; | 224 maxMatchContentsWidth_ = maxMatchContentsWidth; |
210 } | 225 } |
211 | 226 |
212 - (void)setContentsOffset:(CGFloat)contentsOffset { | 227 - (void)setContentsOffset:(CGFloat)contentsOffset { |
213 contentsOffset_ = contentsOffset; | 228 contentsOffset_ = contentsOffset; |
214 } | 229 } |
215 | 230 |
216 // The default NSButtonCell drawing leaves the image flush left and | 231 // The default NSButtonCell drawing leaves the image flush left and |
217 // the title next to the image. This spaces things out to line up | 232 // the title next to the image. This spaces things out to line up |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 - (CGFloat)drawMatchPart:(NSAttributedString*)as | 361 - (CGFloat)drawMatchPart:(NSAttributedString*)as |
347 withFrame:(NSRect)cellFrame | 362 withFrame:(NSRect)cellFrame |
348 atOffset:(CGFloat)offset | 363 atOffset:(CGFloat)offset |
349 withMaxWidth:(int)maxWidth | 364 withMaxWidth:(int)maxWidth |
350 inView:(NSView*)controlView { | 365 inView:(NSView*)controlView { |
351 if (offset > NSWidth(cellFrame)) | 366 if (offset > NSWidth(cellFrame)) |
352 return 0.0f; | 367 return 0.0f; |
353 NSRect renderRect = ShiftRect(cellFrame, offset); | 368 NSRect renderRect = ShiftRect(cellFrame, offset); |
354 renderRect.size.width = | 369 renderRect.size.width = |
355 std::min(NSWidth(renderRect), static_cast<CGFloat>(maxWidth)); | 370 std::min(NSWidth(renderRect), static_cast<CGFloat>(maxWidth)); |
371 NSRect textRect = [as boundingRectWithSize:renderRect.size options:nil]; | |
372 renderRect.origin.y += (NSHeight(cellFrame) - NSHeight(textRect)) / 2; | |
356 if (renderRect.size.width != 0) { | 373 if (renderRect.size.width != 0) { |
357 [self drawTitle:as | 374 [as drawInRect:FlipIfRTL(renderRect, cellFrame)]; |
358 withFrame:FlipIfRTL(renderRect, cellFrame) | |
359 inView:controlView]; | |
360 } | 375 } |
361 return NSWidth(renderRect); | 376 return NSWidth(renderRect); |
362 } | 377 } |
363 | 378 |
364 - (CGFloat)getMatchContentsWidth { | 379 - (CGFloat)getMatchContentsWidth { |
365 NSAttributedString* contents = [self attributedTitle]; | 380 NSAttributedString* contents = [self attributedTitle]; |
366 return contents ? [contents size].width : 0; | 381 return contents ? [contents size].width : 0; |
367 } | 382 } |
368 | 383 |
369 | 384 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 } | 442 } |
428 glyphOffset -= minOffset; | 443 glyphOffset -= minOffset; |
429 if (glyphWidth == 0) | 444 if (glyphWidth == 0) |
430 glyphWidth = inputWidth - glyphOffset; | 445 glyphWidth = inputWidth - glyphOffset; |
431 if (isContentsRTL) | 446 if (isContentsRTL) |
432 glyphOffset += glyphWidth; | 447 glyphOffset += glyphWidth; |
433 return isRTL ? (inputWidth - glyphOffset) : glyphOffset; | 448 return isRTL ? (inputWidth - glyphOffset) : glyphOffset; |
434 } | 449 } |
435 | 450 |
436 @end | 451 @end |
OLD | NEW |