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(); | |
Scott Hess - ex-Googler
2015/05/07 22:35:42
This is an unexpected approach. Why do you need t
groby-ooo-7-16
2015/05/08 03:24:08
This is here due to NSCopyObject. NSCell uses that
Scott Hess - ex-Googler
2015/05/08 04:11:48
W. T. F.
In that case, might I suggest:
scope
groby-ooo-7-16
2015/05/08 05:08:29
I hate to be the contrarian, but...
Assume a sep
Scott Hess - ex-Googler
2015/05/08 06:00:13
Alternative 3:
scoped_nsobject<NSAttributedStrin
groby-ooo-7-16
2015/05/08 06:20:43
I like the symmetry of #3. I'm reasonably certain
Scott Hess - ex-Googler
2015/05/08 18:25:49
Another option which just occurred to me would be
| |
210 OmniboxPopupCell* copy = [super copyWithZone:zone]; | |
211 copy->match_ = match_; | |
212 copy->separator_.reset([separator copy]); | |
groby-ooo-7-16
2015/05/08 03:24:08
You technically don't need to copy the NSAttribute
Scott Hess - ex-Googler
2015/05/08 04:11:48
If they aren't mutable, then -copy should be imple
| |
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 } | |
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 += std::floor((NSHeight(cellFrame) - NSHeight(textRect)) | |
373 / 2.0); | |
Scott Hess - ex-Googler
2015/05/07 22:35:42
As long as you're on two lines, just pull everythi
dschuyler
2015/05/13 01:41:11
Done.
| |
356 if (renderRect.size.width != 0) { | 374 if (renderRect.size.width != 0) { |
357 [self drawTitle:as | 375 [as drawInRect:FlipIfRTL(renderRect, cellFrame)]; |
Scott Hess - ex-Googler
2015/05/07 22:35:42
I think the style in here is to drop the {} when i
dschuyler
2015/05/13 01:41:11
Done.
| |
358 withFrame:FlipIfRTL(renderRect, cellFrame) | |
359 inView:controlView]; | |
360 } | 376 } |
361 return NSWidth(renderRect); | 377 return NSWidth(renderRect); |
362 } | 378 } |
363 | 379 |
364 - (CGFloat)getMatchContentsWidth { | 380 - (CGFloat)getMatchContentsWidth { |
365 NSAttributedString* contents = [self attributedTitle]; | 381 NSAttributedString* contents = [self attributedTitle]; |
366 return contents ? [contents size].width : 0; | 382 return contents ? [contents size].width : 0; |
367 } | 383 } |
368 | 384 |
369 | 385 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 } | 443 } |
428 glyphOffset -= minOffset; | 444 glyphOffset -= minOffset; |
429 if (glyphWidth == 0) | 445 if (glyphWidth == 0) |
430 glyphWidth = inputWidth - glyphOffset; | 446 glyphWidth = inputWidth - glyphOffset; |
431 if (isContentsRTL) | 447 if (isContentsRTL) |
432 glyphOffset += glyphWidth; | 448 glyphOffset += glyphWidth; |
433 return isRTL ? (inputWidth - glyphOffset) : glyphOffset; | 449 return isRTL ? (inputWidth - glyphOffset) : glyphOffset; |
434 } | 450 } |
435 | 451 |
436 @end | 452 @end |
OLD | NEW |