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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm

Issue 1099403005: [AiS] changing mac omnibox suggestions form NSMatrix to NSTableView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: autorelease on column data cell Created 5 years, 6 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 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"
11 #include "base/mac/foundation_util.h"
11 #include "base/mac/scoped_nsobject.h" 12 #include "base/mac/scoped_nsobject.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" 17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"
17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 18 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
18 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 19 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
19 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
20 #include "components/omnibox/suggestion_answer.h" 21 #include "components/omnibox/suggestion_answer.h"
21 #include "skia/ext/skia_utils_mac.h" 22 #include "skia/ext/skia_utils_mac.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/font.h" 24 #include "ui/gfx/font.h"
24 25
25 namespace { 26 namespace {
26 27
28 // How much to adjust the cell sizing up from the default determined
29 // by the font.
30 const CGFloat kCellHeightAdjust = 6.0;
31
32 // How large the icon should be when displayed.
33 const CGFloat kImageSize = 19.0;
34
27 // How far to offset image column from the left. 35 // How far to offset image column from the left.
28 const CGFloat kImageXOffset = 5.0; 36 const CGFloat kImageXOffset = 5.0;
29 37
30 // How far to offset the text column from the left. 38 // How far to offset the text column from the left.
31 const CGFloat kTextStartOffset = 28.0; 39 const CGFloat kTextStartOffset = 28.0;
32 40
33 // Rounding radius of selection and hover background on popup items. 41 // Rounding radius of selection and hover background on popup items.
34 const CGFloat kCellRoundingRadius = 2.0; 42 const CGFloat kCellRoundingRadius = 2.0;
35 43
36 // Flips the given |rect| in context of the given |frame|. 44 // Flips the given |rect| in context of the given |frame|.
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 value:DimTextColor() 280 value:DimTextColor()
273 range:range]; 281 range:range];
274 } 282 }
275 } 283 }
276 284
277 return attributedString; 285 return attributedString;
278 } 286 }
279 287
280 } // namespace 288 } // namespace
281 289
282 @implementation OmniboxPopupCell 290 @interface OmniboxPopupCell ()
291 - (CGFloat)drawMatchPart:(NSAttributedString*)attributedString
292 withFrame:(NSRect)cellFrame
293 atOffset:(CGFloat)offset
294 withMaxWidth:(int)maxWidth;
295 - (CGFloat)drawMatchPrefixWithFrame:(NSRect)cellFrame
296 tableView:(OmniboxPopupMatrix*)tableView
297 withContentsMaxWidth:(int*)contentsMaxWidth;
298 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView;
299 @end
283 300
284 - (instancetype)init { 301 @implementation OmniboxPopupCellData
285 self = [super init];
286 if (self) {
287 [self setImagePosition:NSImageLeft];
288 [self setBordered:NO];
289 [self setButtonType:NSRadioButton];
290 302
291 // Without this highlighting messes up white areas of images. 303 @synthesize contents = contents_;
292 [self setHighlightsBy:NSNoCellMask]; 304 @synthesize description = description_;
305 @synthesize prefix = prefix_;
306 @synthesize image = image_;
307 @synthesize answerImage = answerImage_;
308 @synthesize contentsOffset = contentsOffset_;
309 @synthesize isContentsRTL = isContentsRTL_;
310 @synthesize matchType = matchType_;
293 311
294 const base::string16& raw_separator = 312 - (instancetype)initWithMatch:(const AutocompleteMatch&)match
295 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); 313 contentsOffset:(CGFloat)contentsOffset
296 separator_.reset( 314 image:(NSImage*)image
297 [CreateAttributedString(raw_separator, DimTextColor()) retain]); 315 answerImage:(NSImage*)answerImage {
316 if ((self = [super init])) {
317 image_ = [image retain];
318 answerImage_ = [answerImage retain];
319 contentsOffset_ = contentsOffset;
320
321 isContentsRTL_ =
322 (base::i18n::RIGHT_TO_LEFT ==
323 base::i18n::GetFirstStrongCharacterDirection(match.contents));
324 matchType_ = match.type;
325
326 // Prefix may not have any characters with strong directionality, and may
327 // take the UI directionality. But prefix needs to appear in continuation
328 // of the contents so we force the directionality.
329 NSTextAlignment textAlignment =
330 isContentsRTL_ ? NSRightTextAlignment : NSLeftTextAlignment;
331 prefix_ =
332 [CreateAttributedString(base::UTF8ToUTF16(match.GetAdditionalInfo(
333 kACMatchPropertyContentsPrefix)),
334 ContentTextColor(), textAlignment) retain];
335
336 contents_ = [CreateClassifiedAttributedString(
337 match.contents, ContentTextColor(), match.contents_class) retain];
338
339 if (match.answer) {
340 base::scoped_nsobject<NSMutableAttributedString> answerString(
341 [[NSMutableAttributedString alloc] init]);
342 DCHECK(!match.answer->second_line().text_fields().empty());
343 for (const SuggestionAnswer::TextField& textField :
344 match.answer->second_line().text_fields()) {
345 [answerString
346 appendAttributedString:CreateAnswerString(textField.text(),
347 textField.type())];
348 }
349 const base::string16 space(base::ASCIIToUTF16(" "));
350 const SuggestionAnswer::TextField* textField =
351 match.answer->second_line().additional_text();
352 if (textField) {
353 [answerString
354 appendAttributedString:CreateAnswerString(space + textField->text(),
355 textField->type())];
356 }
357 textField = match.answer->second_line().status_text();
358 if (textField) {
359 [answerString
360 appendAttributedString:CreateAnswerString(space + textField->text(),
361 textField->type())];
362 }
363 description_ = answerString.release();
364 } else if (!match.description.empty()) {
365 description_ = [CreateClassifiedAttributedString(
366 match.description, DimTextColor(), match.description_class) retain];
367 }
298 } 368 }
299 return self; 369 return self;
300 } 370 }
301 371
302 - (void)setAnswerImage:(NSImage*)image { 372 - (instancetype)copyWithZone:(NSZone*)zone {
303 answerImage_.reset([image retain]); 373 return [self retain];
304 } 374 }
305 375
306 - (void)setMatch:(const AutocompleteMatch&)match { 376 - (CGFloat)getMatchContentsWidth {
307 match_ = match; 377 return [contents_ size].width;
308 NSAttributedString *contents = CreateClassifiedAttributedString(
309 match_.contents, ContentTextColor(), match_.contents_class);
310 [self setAttributedTitle:contents];
311 [self setAnswerImage:nil];
312 if (match_.answer) {
313 base::scoped_nsobject<NSMutableAttributedString> answerString(
314 [[NSMutableAttributedString alloc] init]);
315 DCHECK(!match_.answer->second_line().text_fields().empty());
316 for (const SuggestionAnswer::TextField& textField :
317 match_.answer->second_line().text_fields()) {
318 NSAttributedString* attributedString =
319 CreateAnswerString(textField.text(), textField.type());
320 [answerString appendAttributedString:attributedString];
321 }
322 const base::char16 space(' ');
323 const SuggestionAnswer::TextField* textField =
324 match_.answer->second_line().additional_text();
325 if (textField) {
326 [answerString
327 appendAttributedString:CreateAnswerString(space + textField->text(),
328 textField->type())];
329 }
330 textField = match_.answer->second_line().status_text();
331 if (textField) {
332 [answerString
333 appendAttributedString:CreateAnswerString(space + textField->text(),
334 textField->type())];
335 }
336 description_.reset(answerString.release());
337 } else if (match_.description.empty()) {
338 description_.reset();
339 } else {
340 description_.reset([CreateClassifiedAttributedString(
341 match_.description, DimTextColor(), match_.description_class) retain]);
342 }
343 } 378 }
344 379
345 - (NSAttributedString*)description { 380 - (CGFloat)rowHeight {
346 return description_; 381 return kImageSize + kCellHeightAdjust;
347 } 382 }
348 383
349 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth { 384 @end
350 maxMatchContentsWidth_ = maxMatchContentsWidth;
351 }
352 385
353 - (void)setContentsOffset:(CGFloat)contentsOffset { 386 @implementation OmniboxPopupCell
354 contentsOffset_ = contentsOffset;
355 }
356 387
357 // The default NSButtonCell drawing leaves the image flush left and 388 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
358 // the title next to the image. This spaces things out to line up
359 // with the star button and autocomplete field.
360 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
361 if ([self state] == NSOnState || [self isHighlighted]) { 389 if ([self state] == NSOnState || [self isHighlighted]) {
362 if ([self state] == NSOnState) 390 if ([self state] == NSOnState)
363 [SelectedBackgroundColor() set]; 391 [SelectedBackgroundColor() set];
364 else 392 else
365 [HoveredBackgroundColor() set]; 393 [HoveredBackgroundColor() set];
366 NSBezierPath* path = 394 NSBezierPath* path =
367 [NSBezierPath bezierPathWithRoundedRect:cellFrame 395 [NSBezierPath bezierPathWithRoundedRect:cellFrame
368 xRadius:kCellRoundingRadius 396 xRadius:kCellRoundingRadius
369 yRadius:kCellRoundingRadius]; 397 yRadius:kCellRoundingRadius];
370 [path fill]; 398 [path fill];
371 } 399 }
372 400
373 // Put the image centered vertically but in a fixed column.
374 NSImage* image = [self image];
375 if (image) {
376 NSRect imageRect = cellFrame;
377 imageRect.size = [image size];
378 imageRect.origin.y +=
379 std::floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0);
380 imageRect.origin.x += kImageXOffset;
381 [image drawInRect:FlipIfRTL(imageRect, cellFrame)
382 fromRect:NSZeroRect // Entire image
383 operation:NSCompositeSourceOver
384 fraction:1.0
385 respectFlipped:YES
386 hints:nil];
387 }
388
389 [self drawMatchWithFrame:cellFrame inView:controlView]; 401 [self drawMatchWithFrame:cellFrame inView:controlView];
390 } 402 }
391 403
392 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { 404 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
393 NSAttributedString* contents = [self attributedTitle]; 405 OmniboxPopupCellData* cellData =
394 406 base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]);
407 OmniboxPopupMatrix* tableView =
408 base::mac::ObjCCastStrict<OmniboxPopupMatrix>(controlView);
395 CGFloat remainingWidth = GetContentAreaWidth(cellFrame); 409 CGFloat remainingWidth = GetContentAreaWidth(cellFrame);
396 CGFloat contentsWidth = [self getMatchContentsWidth]; 410 CGFloat contentsWidth = [cellData getMatchContentsWidth];
397 CGFloat separatorWidth = [separator_ size].width; 411 CGFloat separatorWidth = [[tableView separator] size].width;
398 CGFloat descriptionWidth = description_.get() ? [description_ size].width : 0; 412 CGFloat descriptionWidth =
413 [cellData description] ? [[cellData description] size].width : 0;
399 int contentsMaxWidth, descriptionMaxWidth; 414 int contentsMaxWidth, descriptionMaxWidth;
400 OmniboxPopupModel::ComputeMatchMaxWidths( 415 OmniboxPopupModel::ComputeMatchMaxWidths(
401 ceilf(contentsWidth), 416 ceilf(contentsWidth), ceilf(separatorWidth), ceilf(descriptionWidth),
402 ceilf(separatorWidth),
403 ceilf(descriptionWidth),
404 ceilf(remainingWidth), 417 ceilf(remainingWidth),
405 !AutocompleteMatch::IsSearchType(match_.type), 418 !AutocompleteMatch::IsSearchType([cellData matchType]), &contentsMaxWidth,
406 &contentsMaxWidth,
407 &descriptionMaxWidth); 419 &descriptionMaxWidth);
408 420
409 CGFloat offset = kTextStartOffset; 421 // Put the image centered vertically but in a fixed column.
410 if (match_.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { 422 NSRect imageRect = cellFrame;
411 // Infinite suggestions are rendered with a prefix (usually ellipsis), which 423 imageRect.size = [[cellData image] size];
412 // appear vertically stacked. 424 imageRect.origin.y +=
413 offset += [self drawMatchPrefixWithFrame:cellFrame 425 std::floor((NSHeight(cellFrame) - NSHeight(imageRect)) / 2.0);
414 inView:controlView 426 imageRect.origin.x += kImageXOffset;
415 withContentsMaxWidth:&contentsMaxWidth]; 427 [[cellData image] drawInRect:FlipIfRTL(imageRect, cellFrame)
416 }
417 offset += [self drawMatchPart:contents
418 withFrame:cellFrame
419 atOffset:offset
420 withMaxWidth:contentsMaxWidth
421 inView:controlView];
422
423 if (descriptionMaxWidth != 0) {
424 offset += [self drawMatchPart:separator_
425 withFrame:cellFrame
426 atOffset:offset
427 withMaxWidth:separatorWidth
428 inView:controlView];
429 if (answerImage_) {
430 NSRect imageRect = NSMakeRect(offset, NSMinY(cellFrame),
431 NSHeight(cellFrame), NSHeight(cellFrame));
432 [answerImage_ drawInRect:FlipIfRTL(imageRect, cellFrame)
433 fromRect:NSZeroRect 428 fromRect:NSZeroRect
434 operation:NSCompositeSourceOver 429 operation:NSCompositeSourceOver
435 fraction:1.0 430 fraction:1.0
436 respectFlipped:YES 431 respectFlipped:YES
437 hints:nil]; 432 hints:nil];
438 offset += NSWidth(imageRect); 433
439 } 434 CGFloat offset = kTextStartOffset;
440 offset += [self drawMatchPart:description_ 435 if ([cellData matchType] == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) {
436 // Infinite suggestions are rendered with a prefix (usually ellipsis), which
437 // appear vertically stacked.
438 offset += [self drawMatchPrefixWithFrame:cellFrame
439 tableView:tableView
440 withContentsMaxWidth:&contentsMaxWidth];
441 }
442 offset += [self drawMatchPart:[cellData contents]
443 withFrame:cellFrame
444 atOffset:offset
445 withMaxWidth:contentsMaxWidth];
446
447 if (descriptionMaxWidth != 0) {
448 offset += [self drawMatchPart:[tableView separator]
441 withFrame:cellFrame 449 withFrame:cellFrame
442 atOffset:offset 450 atOffset:offset
443 withMaxWidth:descriptionMaxWidth 451 withMaxWidth:separatorWidth];
444 inView:controlView]; 452 NSRect imageRect = NSMakeRect(offset, NSMinY(cellFrame),
453 NSHeight(cellFrame), NSHeight(cellFrame));
454 [[cellData answerImage] drawInRect:FlipIfRTL(imageRect, cellFrame)
455 fromRect:NSZeroRect
456 operation:NSCompositeSourceOver
457 fraction:1.0
458 respectFlipped:YES
459 hints:nil];
460 if ([cellData answerImage])
461 offset += NSWidth(imageRect);
462 offset += [self drawMatchPart:[cellData description]
463 withFrame:cellFrame
464 atOffset:offset
465 withMaxWidth:descriptionMaxWidth];
445 } 466 }
446 } 467 }
447 468
448 - (CGFloat)drawMatchPrefixWithFrame:(NSRect)cellFrame 469 - (CGFloat)drawMatchPrefixWithFrame:(NSRect)cellFrame
449 inView:(NSView*)controlView 470 tableView:(OmniboxPopupMatrix*)tableView
450 withContentsMaxWidth:(int*)contentsMaxWidth { 471 withContentsMaxWidth:(int*)contentsMaxWidth {
472 OmniboxPopupCellData* cellData =
473 base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]);
451 CGFloat offset = 0.0f; 474 CGFloat offset = 0.0f;
452 CGFloat remainingWidth = GetContentAreaWidth(cellFrame); 475 CGFloat remainingWidth = GetContentAreaWidth(cellFrame);
453 bool isContentsRTL = (base::i18n::RIGHT_TO_LEFT == 476 CGFloat prefixWidth = [[cellData prefix] size].width;
454 base::i18n::GetFirstStrongCharacterDirection(match_.contents));
455 // Prefix may not have any characters with strong directionality, and may take
456 // the UI directionality. But prefix needs to appear in continuation of the
457 // contents so we force the directionality.
458 NSTextAlignment textAlignment = isContentsRTL ?
459 NSRightTextAlignment : NSLeftTextAlignment;
460 prefix_.reset([CreateAttributedString(base::UTF8ToUTF16(
461 match_.GetAdditionalInfo(kACMatchPropertyContentsPrefix)),
462 ContentTextColor(), textAlignment) retain]);
463 CGFloat prefixWidth = [prefix_ size].width;
464 477
465 CGFloat prefixOffset = 0.0f; 478 CGFloat prefixOffset = 0.0f;
466 if (base::i18n::IsRTL() != isContentsRTL) { 479 if (base::i18n::IsRTL() != [cellData isContentsRTL]) {
467 // The contents is rendered between the contents offset extending towards 480 // The contents is rendered between the contents offset extending towards
468 // the start edge, while prefix is rendered in opposite direction. Ideally 481 // the start edge, while prefix is rendered in opposite direction. Ideally
469 // the prefix should be rendered at |contentsOffset_|. If that is not 482 // the prefix should be rendered at |contentsOffset_|. If that is not
470 // sufficient to render the widest suggestion, we increase it to 483 // sufficient to render the widest suggestion, we increase it to
471 // |maxMatchContentsWidth_|. If |remainingWidth| is not sufficient to 484 // |maxMatchContentsWidth|. If |remainingWidth| is not sufficient to
472 // accommodate that, we reduce the offset so that the prefix gets rendered. 485 // accommodate that, we reduce the offset so that the prefix gets rendered.
473 prefixOffset = std::min( 486 prefixOffset = std::min(
474 remainingWidth - prefixWidth, std::max(contentsOffset_, 487 remainingWidth - prefixWidth,
475 maxMatchContentsWidth_)); 488 std::max([cellData contentsOffset], [tableView maxMatchContentsWidth]));
476 offset = std::max<CGFloat>(0.0, prefixOffset - *contentsMaxWidth); 489 offset = std::max<CGFloat>(0.0, prefixOffset - *contentsMaxWidth);
477 } else { // The direction of contents is same as UI direction. 490 } else { // The direction of contents is same as UI direction.
478 // Ideally the offset should be |contentsOffset_|. If the max total width 491 // Ideally the offset should be |contentsOffset_|. If the max total width
479 // (|prefixWidth| + |maxMatchContentsWidth_|) from offset will exceed the 492 // (|prefixWidth| + |maxMatchContentsWidth|) from offset will exceed the
480 // |remainingWidth|, then we shift the offset to the left , so that all 493 // |remainingWidth|, then we shift the offset to the left , so that all
481 // postfix suggestions are visible. 494 // postfix suggestions are visible.
482 // We have to render the prefix, so offset has to be at least |prefixWidth|. 495 // We have to render the prefix, so offset has to be at least |prefixWidth|.
483 offset = std::max(prefixWidth, 496 offset =
484 std::min(remainingWidth - maxMatchContentsWidth_, contentsOffset_)); 497 std::max(prefixWidth,
498 std::min(remainingWidth - [tableView maxMatchContentsWidth],
499 [cellData contentsOffset]));
485 prefixOffset = offset - prefixWidth; 500 prefixOffset = offset - prefixWidth;
486 } 501 }
487 *contentsMaxWidth = std::min((int)ceilf(remainingWidth - prefixWidth), 502 *contentsMaxWidth = std::min((int)ceilf(remainingWidth - prefixWidth),
488 *contentsMaxWidth); 503 *contentsMaxWidth);
489 [self drawMatchPart:prefix_ 504 [self drawMatchPart:[cellData prefix]
490 withFrame:cellFrame 505 withFrame:cellFrame
491 atOffset:prefixOffset + kTextStartOffset 506 atOffset:prefixOffset + kTextStartOffset
492 withMaxWidth:prefixWidth 507 withMaxWidth:prefixWidth];
493 inView:controlView];
494 return offset; 508 return offset;
495 } 509 }
496 510
497 - (CGFloat)drawMatchPart:(NSAttributedString*)attributedString 511 - (CGFloat)drawMatchPart:(NSAttributedString*)attributedString
498 withFrame:(NSRect)cellFrame 512 withFrame:(NSRect)cellFrame
499 atOffset:(CGFloat)offset 513 atOffset:(CGFloat)offset
500 withMaxWidth:(int)maxWidth 514 withMaxWidth:(int)maxWidth {
501 inView:(NSView*)controlView {
502 if (offset > NSWidth(cellFrame)) 515 if (offset > NSWidth(cellFrame))
503 return 0.0f; 516 return 0.0f;
504 NSRect renderRect = ShiftRect(cellFrame, offset); 517 NSRect renderRect = ShiftRect(cellFrame, offset);
505 renderRect.size.width = 518 renderRect.size.width =
506 std::min(NSWidth(renderRect), static_cast<CGFloat>(maxWidth)); 519 std::min(NSWidth(renderRect), static_cast<CGFloat>(maxWidth));
507 if (renderRect.size.width != 0) { 520 if (NSWidth(renderRect) > 0.0)
508 [self drawTitle:attributedString 521 [attributedString drawInRect:FlipIfRTL(renderRect, cellFrame)];
509 withFrame:FlipIfRTL(renderRect, cellFrame)
510 inView:controlView];
511 }
512 return NSWidth(renderRect); 522 return NSWidth(renderRect);
513 } 523 }
514 524
515 - (CGFloat)getMatchContentsWidth {
516 NSAttributedString* contents = [self attributedTitle];
517 return contents ? [contents size].width : 0;
518 }
519
520
521 + (CGFloat)computeContentsOffset:(const AutocompleteMatch&)match { 525 + (CGFloat)computeContentsOffset:(const AutocompleteMatch&)match {
522 const base::string16& inputText = base::UTF8ToUTF16( 526 const base::string16& inputText = base::UTF8ToUTF16(
523 match.GetAdditionalInfo(kACMatchPropertyInputText)); 527 match.GetAdditionalInfo(kACMatchPropertyInputText));
524 int contentsStartIndex = 0; 528 int contentsStartIndex = 0;
525 base::StringToInt( 529 base::StringToInt(
526 match.GetAdditionalInfo(kACMatchPropertyContentsStartIndex), 530 match.GetAdditionalInfo(kACMatchPropertyContentsStartIndex),
527 &contentsStartIndex); 531 &contentsStartIndex);
528 // Ignore invalid state. 532 // Ignore invalid state.
529 if (!StartsWith(match.fill_into_edit, inputText, true) 533 if (!StartsWith(match.fill_into_edit, inputText, true)
530 || !EndsWith(match.fill_into_edit, match.contents, true) 534 || !EndsWith(match.fill_into_edit, match.contents, true)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 glyphWidth = std::min(glyphWidth, offset - glyphOffset); 581 glyphWidth = std::min(glyphWidth, offset - glyphOffset);
578 } 582 }
579 glyphOffset -= minOffset; 583 glyphOffset -= minOffset;
580 if (glyphWidth == 0) 584 if (glyphWidth == 0)
581 glyphWidth = inputWidth - glyphOffset; 585 glyphWidth = inputWidth - glyphOffset;
582 if (isContentsRTL) 586 if (isContentsRTL)
583 glyphOffset += glyphWidth; 587 glyphOffset += glyphWidth;
584 return base::i18n::IsRTL() ? (inputWidth - glyphOffset) : glyphOffset; 588 return base::i18n::IsRTL() ? (inputWidth - glyphOffset) : glyphOffset;
585 } 589 }
586 590
591 + (NSAttributedString*)createSeparatorString {
592 base::string16 raw_separator =
593 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR);
594 return CreateAttributedString(raw_separator, DimTextColor());
595 }
596
587 @end 597 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h ('k') | chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698