| 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 <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <cmath> | 10 #include <cmath> | 
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 476 } | 476 } | 
| 477 | 477 | 
| 478 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 478 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 
| 479   bool isVerticalLayout = | 479   bool isVerticalLayout = | 
| 480       base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout); | 480       base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout); | 
| 481 | 481 | 
| 482   OmniboxPopupCellData* cellData = | 482   OmniboxPopupCellData* cellData = | 
| 483       base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]); | 483       base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]); | 
| 484   OmniboxPopupMatrix* tableView = | 484   OmniboxPopupMatrix* tableView = | 
| 485       base::mac::ObjCCastStrict<OmniboxPopupMatrix>(controlView); | 485       base::mac::ObjCCastStrict<OmniboxPopupMatrix>(controlView); | 
| 486   CGFloat remainingWidth = [OmniboxPopupCell getContentAreaWidth:cellFrame] - | 486   CGFloat remainingWidth = | 
| 487                            [tableView contentLeftPadding]; | 487       [OmniboxPopupCell getTextContentAreaWidth:[tableView contentMaxWidth]]; | 
| 488   CGFloat contentsWidth = [cellData getMatchContentsWidth]; | 488   CGFloat contentsWidth = [cellData getMatchContentsWidth]; | 
| 489   CGFloat separatorWidth = [[tableView separator] size].width; | 489   CGFloat separatorWidth = [[tableView separator] size].width; | 
| 490   CGFloat descriptionWidth = | 490   CGFloat descriptionWidth = | 
| 491       [cellData description] ? [[cellData description] size].width : 0; | 491       [cellData description] ? [[cellData description] size].width : 0; | 
| 492   int contentsMaxWidth, descriptionMaxWidth; | 492   int contentsMaxWidth, descriptionMaxWidth; | 
| 493   OmniboxPopupModel::ComputeMatchMaxWidths( | 493   OmniboxPopupModel::ComputeMatchMaxWidths( | 
| 494       ceilf(contentsWidth), ceilf(separatorWidth), ceilf(descriptionWidth), | 494       ceilf(contentsWidth), ceilf(separatorWidth), ceilf(descriptionWidth), | 
| 495       ceilf(remainingWidth), [cellData isAnswer] || isVerticalLayout, | 495       ceilf(remainingWidth), [cellData isAnswer] || isVerticalLayout, | 
| 496       !AutocompleteMatch::IsSearchType([cellData matchType]), &contentsMaxWidth, | 496       !AutocompleteMatch::IsSearchType([cellData matchType]), &contentsMaxWidth, | 
| 497       &descriptionMaxWidth); | 497       &descriptionMaxWidth); | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 579   } | 579   } | 
| 580 } | 580 } | 
| 581 | 581 | 
| 582 - (CGFloat)drawMatchPrefixWithFrame:(NSRect)cellFrame | 582 - (CGFloat)drawMatchPrefixWithFrame:(NSRect)cellFrame | 
| 583                           tableView:(OmniboxPopupMatrix*)tableView | 583                           tableView:(OmniboxPopupMatrix*)tableView | 
| 584                withContentsMaxWidth:(int*)contentsMaxWidth | 584                withContentsMaxWidth:(int*)contentsMaxWidth | 
| 585                        forDarkTheme:(BOOL)isDarkTheme { | 585                        forDarkTheme:(BOOL)isDarkTheme { | 
| 586   OmniboxPopupCellData* cellData = | 586   OmniboxPopupCellData* cellData = | 
| 587       base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]); | 587       base::mac::ObjCCastStrict<OmniboxPopupCellData>([self objectValue]); | 
| 588   CGFloat offset = 0.0f; | 588   CGFloat offset = 0.0f; | 
| 589   CGFloat remainingWidth = [OmniboxPopupCell getContentAreaWidth:cellFrame] - | 589   CGFloat remainingWidth = | 
| 590                            [tableView contentLeftPadding]; | 590       [OmniboxPopupCell getTextContentAreaWidth:[tableView contentMaxWidth]]; | 
| 591   CGFloat prefixWidth = [[cellData prefix] size].width; | 591   CGFloat prefixWidth = [[cellData prefix] size].width; | 
| 592 | 592 | 
| 593   CGFloat prefixOffset = 0.0f; | 593   CGFloat prefixOffset = 0.0f; | 
| 594   if (base::i18n::IsRTL() != [cellData isContentsRTL]) { | 594   if (base::i18n::IsRTL() != [cellData isContentsRTL]) { | 
| 595     // The contents is rendered between the contents offset extending towards | 595     // The contents is rendered between the contents offset extending towards | 
| 596     // the start edge, while prefix is rendered in opposite direction. Ideally | 596     // the start edge, while prefix is rendered in opposite direction. Ideally | 
| 597     // the prefix should be rendered at |contentsOffset_|. If that is not | 597     // the prefix should be rendered at |contentsOffset_|. If that is not | 
| 598     // sufficient to render the widest suggestion, we increase it to | 598     // sufficient to render the widest suggestion, we increase it to | 
| 599     // |maxMatchContentsWidth|.  If |remainingWidth| is not sufficient to | 599     // |maxMatchContentsWidth|.  If |remainingWidth| is not sufficient to | 
| 600     // accommodate that, we reduce the offset so that the prefix gets rendered. | 600     // accommodate that, we reduce the offset so that the prefix gets rendered. | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 713     glyphOffset += glyphWidth; | 713     glyphOffset += glyphWidth; | 
| 714   return base::i18n::IsRTL() ? (inputWidth - glyphOffset) : glyphOffset; | 714   return base::i18n::IsRTL() ? (inputWidth - glyphOffset) : glyphOffset; | 
| 715 } | 715 } | 
| 716 | 716 | 
| 717 + (NSAttributedString*)createSeparatorStringForDarkTheme:(BOOL)isDarkTheme { | 717 + (NSAttributedString*)createSeparatorStringForDarkTheme:(BOOL)isDarkTheme { | 
| 718   base::string16 raw_separator = | 718   base::string16 raw_separator = | 
| 719       l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 719       l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 
| 720   return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); | 720   return CreateAttributedString(raw_separator, DimTextColor(isDarkTheme)); | 
| 721 } | 721 } | 
| 722 | 722 | 
| 723 + (CGFloat)getContentAreaWidth:(NSRect)cellFrame { | 723 + (CGFloat)getTextContentAreaWidth:(CGFloat)cellContentMaxWidth { | 
| 724   return NSWidth(cellFrame) - kMaterialTextStartOffset; | 724   return cellContentMaxWidth - kMaterialTextStartOffset; | 
| 725 } | 725 } | 
| 726 | 726 | 
| 727 + (CGFloat)getContentTextHeightForDoubleLine:(BOOL)isDoubleLine { | 727 + (CGFloat)getContentTextHeightForDoubleLine:(BOOL)isDoubleLine { | 
| 728   CGFloat height = kDefaultTextHeight + 2 * GetVerticalMargin(); | 728   CGFloat height = kDefaultTextHeight + 2 * GetVerticalMargin(); | 
| 729   if (isDoubleLine) | 729   if (isDoubleLine) | 
| 730     height += kDefaultTextHeight + kDefaultVerticalMargin; | 730     height += kDefaultTextHeight + kDefaultVerticalMargin; | 
| 731   return height; | 731   return height; | 
| 732 } | 732 } | 
| 733 | 733 | 
| 734 @end | 734 @end | 
| OLD | NEW | 
|---|