| 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_matrix.h" | 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 10 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 [OmniboxPopupCell getContentTextHeightForDoubleLine:isDoubleLine]; | 115 [OmniboxPopupCell getContentTextHeightForDoubleLine:isDoubleLine]; |
| 116 | 116 |
| 117 if (isAnswer) { | 117 if (isAnswer) { |
| 118 OmniboxPopupMatrix* matrix = | 118 OmniboxPopupMatrix* matrix = |
| 119 base::mac::ObjCCastStrict<OmniboxPopupMatrix>(tableView); | 119 base::mac::ObjCCastStrict<OmniboxPopupMatrix>(tableView); |
| 120 NSRect rowRect = [tableView rectOfColumn:0]; | 120 NSRect rowRect = [tableView rectOfColumn:0]; |
| 121 OmniboxPopupCellData* cellData = | 121 OmniboxPopupCellData* cellData = |
| 122 base::mac::ObjCCastStrict<OmniboxPopupCellData>( | 122 base::mac::ObjCCastStrict<OmniboxPopupCellData>( |
| 123 [array_ objectAtIndex:row]); | 123 [array_ objectAtIndex:row]); |
| 124 // Subtract any Material Design padding and/or icon. | 124 // Subtract any Material Design padding and/or icon. |
| 125 rowRect.size.width = [OmniboxPopupCell getContentAreaWidth:rowRect] - | 125 rowRect.size.width = |
| 126 [matrix contentLeftPadding]; | 126 [OmniboxPopupCell getTextContentAreaWidth:[matrix contentMaxWidth]]; |
| 127 NSAttributedString* text = [cellData description]; | 127 NSAttributedString* text = [cellData description]; |
| 128 // Provide no more than 3 lines of space. | 128 // Provide no more than 3 lines of space. |
| 129 rowRect.size.height = | 129 rowRect.size.height = |
| 130 std::min(3, [cellData maxLines]) * [text size].height; | 130 std::min(3, [cellData maxLines]) * [text size].height; |
| 131 NSRect textRect = | 131 NSRect textRect = |
| 132 [text boundingRectWithSize:rowRect.size | 132 [text boundingRectWithSize:rowRect.size |
| 133 options:NSStringDrawingUsesLineFragmentOrigin | | 133 options:NSStringDrawingUsesLineFragmentOrigin | |
| 134 NSStringDrawingTruncatesLastVisibleLine]; | 134 NSStringDrawingTruncatesLastVisibleLine]; |
| 135 // Add a little padding or it looks cramped. | 135 // Add a little padding or it looks cramped. |
| 136 int heightProvided = textRect.size.height + 2; | 136 int heightProvided = textRect.size.height + 2; |
| 137 height += heightProvided; | 137 height += heightProvided; |
| 138 } | 138 } |
| 139 return height; | 139 return height; |
| 140 } | 140 } |
| 141 | 141 |
| 142 @end | 142 @end |
| 143 | 143 |
| 144 @implementation OmniboxPopupMatrix | 144 @implementation OmniboxPopupMatrix |
| 145 | 145 |
| 146 @synthesize separator = separator_; | 146 @synthesize separator = separator_; |
| 147 @synthesize maxMatchContentsWidth = maxMatchContentsWidth_; | 147 @synthesize maxMatchContentsWidth = maxMatchContentsWidth_; |
| 148 @synthesize contentLeftPadding = contentLeftPadding_; | 148 @synthesize contentLeftPadding = contentLeftPadding_; |
| 149 @synthesize contentMaxWidth = contentMaxWidth_; |
| 149 @synthesize answerLineHeight = answerLineHeight_; | 150 @synthesize answerLineHeight = answerLineHeight_; |
| 150 @synthesize hasDarkTheme = hasDarkTheme_; | 151 @synthesize hasDarkTheme = hasDarkTheme_; |
| 151 | 152 |
| 152 - (instancetype)initWithObserver:(OmniboxPopupMatrixObserver*)observer | 153 - (instancetype)initWithObserver:(OmniboxPopupMatrixObserver*)observer |
| 153 forDarkTheme:(BOOL)isDarkTheme { | 154 forDarkTheme:(BOOL)isDarkTheme { |
| 154 if ((self = [super initWithFrame:NSZeroRect])) { | 155 if ((self = [super initWithFrame:NSZeroRect])) { |
| 155 observer_ = observer; | 156 observer_ = observer; |
| 156 hasDarkTheme_ = isDarkTheme; | 157 hasDarkTheme_ = isDarkTheme; |
| 157 | 158 |
| 158 base::scoped_nsobject<NSTableColumn> column( | 159 base::scoped_nsobject<NSTableColumn> column( |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 [self selectRowIndex:row]; | 322 [self selectRowIndex:row]; |
| 322 if (row != -1) { | 323 if (row != -1) { |
| 323 DCHECK(observer_); | 324 DCHECK(observer_); |
| 324 observer_->OnMatrixRowSelected(self, row); | 325 observer_->OnMatrixRowSelected(self, row); |
| 325 return YES; | 326 return YES; |
| 326 } | 327 } |
| 327 return NO; | 328 return NO; |
| 328 } | 329 } |
| 329 | 330 |
| 330 @end | 331 @end |
| OLD | NEW |