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/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
9 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" | 9 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h" |
10 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" | 10 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 - (BOOL)selectCellForEvent:(NSEvent*)theEvent; | 25 - (BOOL)selectCellForEvent:(NSEvent*)theEvent; |
26 @end | 26 @end |
27 | 27 |
28 @implementation OmniboxPopupTableController | 28 @implementation OmniboxPopupTableController |
29 | 29 |
30 - (instancetype)initWithMatchResults:(const AutocompleteResult&)result | 30 - (instancetype)initWithMatchResults:(const AutocompleteResult&)result |
31 tableView:(OmniboxPopupMatrix*)tableView | 31 tableView:(OmniboxPopupMatrix*)tableView |
32 popupView:(const OmniboxPopupViewMac&)popupView | 32 popupView:(const OmniboxPopupViewMac&)popupView |
33 answerImage:(NSImage*)answerImage { | 33 answerImage:(NSImage*)answerImage { |
34 base::scoped_nsobject<NSMutableArray> array([[NSMutableArray alloc] init]); | 34 base::scoped_nsobject<NSMutableArray> array([[NSMutableArray alloc] init]); |
| 35 BOOL isDarkTheme = [tableView hasDarkTheme]; |
35 CGFloat max_match_contents_width = 0.0f; | 36 CGFloat max_match_contents_width = 0.0f; |
36 CGFloat contentsOffset = -1.0f; | 37 CGFloat contentsOffset = -1.0f; |
37 for (const AutocompleteMatch& match : result) { | 38 for (const AutocompleteMatch& match : result) { |
38 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL && | 39 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL && |
39 contentsOffset < 0.0f) | 40 contentsOffset < 0.0f) |
40 contentsOffset = [OmniboxPopupCell computeContentsOffset:match]; | 41 contentsOffset = [OmniboxPopupCell computeContentsOffset:match]; |
41 base::scoped_nsobject<OmniboxPopupCellData> cellData( | 42 base::scoped_nsobject<OmniboxPopupCellData> cellData( |
42 [[OmniboxPopupCellData alloc] | 43 [[OmniboxPopupCellData alloc] |
43 initWithMatch:match | 44 initWithMatch:match |
44 contentsOffset:contentsOffset | 45 contentsOffset:contentsOffset |
45 image:popupView.ImageForMatch(match) | 46 image:popupView.ImageForMatch(match, NO) |
46 answerImage:(match.answer ? answerImage : nil)]); | 47 answerImage:(match.answer ? answerImage : nil) |
| 48 forDarkTheme:isDarkTheme]); |
| 49 if (isDarkTheme) { |
| 50 [cellData setIncognitoImage:popupView.ImageForMatch(match, YES)]; |
| 51 } |
47 [array addObject:cellData]; | 52 [array addObject:cellData]; |
48 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 53 if (match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
49 max_match_contents_width = | 54 max_match_contents_width = |
50 std::max(max_match_contents_width, [cellData getMatchContentsWidth]); | 55 std::max(max_match_contents_width, [cellData getMatchContentsWidth]); |
51 } | 56 } |
52 } | 57 } |
53 | 58 |
54 [tableView setMaxMatchContentsWidth:max_match_contents_width]; | 59 [tableView setMaxMatchContentsWidth:max_match_contents_width]; |
55 return [self initWithArray:array]; | 60 return [self initWithArray:array]; |
56 } | 61 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return height; | 116 return height; |
112 } | 117 } |
113 | 118 |
114 @end | 119 @end |
115 | 120 |
116 @implementation OmniboxPopupMatrix | 121 @implementation OmniboxPopupMatrix |
117 | 122 |
118 @synthesize separator = separator_; | 123 @synthesize separator = separator_; |
119 @synthesize maxMatchContentsWidth = maxMatchContentsWidth_; | 124 @synthesize maxMatchContentsWidth = maxMatchContentsWidth_; |
120 @synthesize answerLineHeight = answerLineHeight_; | 125 @synthesize answerLineHeight = answerLineHeight_; |
| 126 @synthesize contentLeftPadding = contentLeftPadding_; |
| 127 @synthesize hasDarkTheme = hasDarkTheme_; |
121 | 128 |
122 - (instancetype)initWithObserver:(OmniboxPopupMatrixObserver*)observer { | 129 - (instancetype)initWithObserver:(OmniboxPopupMatrixObserver*)observer |
| 130 forDarkTheme:(BOOL)isDarkTheme { |
123 if ((self = [super initWithFrame:NSZeroRect])) { | 131 if ((self = [super initWithFrame:NSZeroRect])) { |
124 observer_ = observer; | 132 observer_ = observer; |
| 133 hasDarkTheme_ = isDarkTheme; |
125 | 134 |
126 base::scoped_nsobject<NSTableColumn> column( | 135 base::scoped_nsobject<NSTableColumn> column( |
127 [[NSTableColumn alloc] initWithIdentifier:@"MainColumn"]); | 136 [[NSTableColumn alloc] initWithIdentifier:@"MainColumn"]); |
128 [column setDataCell:[[[OmniboxPopupCell alloc] init] autorelease]]; | 137 [column setDataCell:[[[OmniboxPopupCell alloc] init] autorelease]]; |
129 [self addTableColumn:column]; | 138 [self addTableColumn:column]; |
130 | 139 |
131 // Cells pack with no spacing. | 140 // Cells pack with no spacing. |
132 [self setIntercellSpacing:NSMakeSize(0.0, 0.0)]; | 141 [self setIntercellSpacing:NSMakeSize(0.0, 0.0)]; |
133 | 142 |
134 [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; | 143 [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; |
135 [self setBackgroundColor:[NSColor controlBackgroundColor]]; | 144 NSColor* backgroundColor = |
| 145 OmniboxPopupViewMac::BackgroundColor(hasDarkTheme_); |
| 146 [self setBackgroundColor:backgroundColor]; |
136 [self setAllowsEmptySelection:YES]; | 147 [self setAllowsEmptySelection:YES]; |
137 [self deselectAll:self]; | 148 [self deselectAll:self]; |
138 | 149 |
139 [self resetTrackingArea]; | 150 [self resetTrackingArea]; |
140 | 151 |
141 base::scoped_nsobject<NSLayoutManager> layoutManager( | 152 base::scoped_nsobject<NSLayoutManager> layoutManager( |
142 [[NSLayoutManager alloc] init]); | 153 [[NSLayoutManager alloc] init]); |
143 answerLineHeight_ = | 154 answerLineHeight_ = |
144 [layoutManager defaultLineHeightForFont:OmniboxViewMac::GetLargeFont( | 155 [layoutManager defaultLineHeightForFont:OmniboxViewMac::GetLargeFont( |
145 gfx::Font::NORMAL)]; | 156 gfx::Font::NORMAL)]; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 [self selectRowIndex:row]; | 299 [self selectRowIndex:row]; |
289 if (row != -1) { | 300 if (row != -1) { |
290 DCHECK(observer_); | 301 DCHECK(observer_); |
291 observer_->OnMatrixRowSelected(self, row); | 302 observer_->OnMatrixRowSelected(self, row); |
292 return YES; | 303 return YES; |
293 } | 304 } |
294 return NO; | 305 return NO; |
295 } | 306 } |
296 | 307 |
297 @end | 308 @end |
OLD | NEW |