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 #ifndef CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ |
6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ | 6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "components/omnibox/autocomplete_match.h" | 11 #include "components/omnibox/autocomplete_match.h" |
12 | 12 |
13 class OmniboxPopupViewMac; | 13 class OmniboxPopupViewMac; |
14 | 14 |
15 // OmniboxPopupCell overrides how backgrounds are displayed to | 15 @interface OmniboxPopupCellData : NSObject<NSCopying> { |
16 // handle hover versus selected. So long as we're in there, it also | |
17 // provides some default initialization. | |
18 @interface OmniboxPopupCell : NSButtonCell { | |
19 @private | 16 @private |
20 // The match which will be rendered for this row in omnibox dropdown. | 17 // Left hand side of the separator (e.g. a hyphen). |
21 AutocompleteMatch match_; | 18 NSAttributedString* contents_; |
22 | 19 // Right hand side of the separator (e.g. a hyphen). |
23 // NSAttributedString instances for various match components. | 20 NSAttributedString* description_; |
24 base::scoped_nsobject<NSAttributedString> separator_; | |
25 base::scoped_nsobject<NSAttributedString> description_; | |
26 | |
27 base::scoped_nsobject<NSImage> answerImage_; | |
28 | 21 |
29 // NOTE: While |prefix_| is used only for postfix suggestions, it still needs | 22 // NOTE: While |prefix_| is used only for postfix suggestions, it still needs |
30 // to be a member of the class. This allows the |NSAttributedString| instance | 23 // to be a member of the class. This allows the |NSAttributedString| instance |
31 // to stay alive between the call to |drawTitle| and the actual paint event | 24 // to stay alive between the call to |drawTitle| and the actual paint event |
32 // which accesses the |NSAttributedString| instance. | 25 // which accesses the |NSAttributedString| instance. |
33 base::scoped_nsobject<NSAttributedString> prefix_; | 26 NSAttributedString* prefix_; |
34 | 27 |
35 // The width of widest match contents in a set of infinite suggestions. | 28 // Common icon that shows next to most rows in the list. |
36 CGFloat maxMatchContentsWidth_; | 29 NSImage* image_; |
| 30 // Uncommon icon that only shows on answer rows (e.g. weather). |
| 31 NSImage* answerImage_; |
37 | 32 |
38 // The offset at which the infinite suggestion contents should be displayed. | 33 // The offset at which the infinite suggestion contents should be displayed. |
39 CGFloat contentsOffset_; | 34 CGFloat contentsOffset_; |
| 35 |
| 36 BOOL isContentsRTL_; |
| 37 AutocompleteMatch::Type matchType_; |
40 } | 38 } |
41 | 39 |
42 - (void)setAnswerImage:(NSImage*)image; | 40 @property(readonly, retain, nonatomic) NSAttributedString* contents; |
| 41 @property(readonly, retain, nonatomic) NSAttributedString* description; |
| 42 @property(readonly, retain, nonatomic) NSAttributedString* prefix; |
| 43 @property(readonly, retain, nonatomic) NSImage* image; |
| 44 @property(readonly, retain, nonatomic) NSImage* answerImage; |
| 45 @property(readonly, nonatomic) CGFloat contentsOffset; |
| 46 @property(readonly, nonatomic) BOOL isContentsRTL; |
| 47 @property(readonly, nonatomic) AutocompleteMatch::Type matchType; |
43 | 48 |
44 - (void)setMatch:(const AutocompleteMatch&)match; | 49 - (instancetype)initWithMatch:(const AutocompleteMatch&)match |
| 50 contentsOffset:(CGFloat)contentsOffset |
| 51 image:(NSImage*)image |
| 52 answerImage:(NSImage*)answerImage; |
45 | 53 |
46 - (NSAttributedString*)description; | 54 // Each row is allowed to have a different value. |
47 | 55 - (CGFloat)rowHeight; |
48 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth; | |
49 | |
50 - (void)setContentsOffset:(CGFloat)contentsOffset; | |
51 | 56 |
52 // Returns the width of the match contents. | 57 // Returns the width of the match contents. |
53 - (CGFloat)getMatchContentsWidth; | 58 - (CGFloat)getMatchContentsWidth; |
54 | 59 |
| 60 @end |
| 61 |
| 62 // Overrides how cells are displayed. Uses information from |
| 63 // OmniboxPopupCellData to draw suggestion results. |
| 64 @interface OmniboxPopupCell : NSCell |
| 65 |
| 66 - (void)drawMatchWithFrame:(NSRect)cellFrame inView:(NSView*)controlView; |
| 67 |
55 // Returns the offset of the start of the contents in the input text for the | 68 // Returns the offset of the start of the contents in the input text for the |
56 // given match. It is costly to compute this offset, so it is computed once and | 69 // given match. It is costly to compute this offset, so it is computed once and |
57 // shared by all OmniboxPopupCell instances through OmniboxPopupViewMac parent. | 70 // shared by all OmniboxPopupCell instances through OmniboxPopupViewMac parent. |
58 + (CGFloat)computeContentsOffset:(const AutocompleteMatch&)match; | 71 + (CGFloat)computeContentsOffset:(const AutocompleteMatch&)match; |
59 | 72 |
| 73 + (NSAttributedString*)createSeparatorString; |
| 74 |
60 @end | 75 @end |
61 | 76 |
62 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ | 77 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_ |
OLD | NEW |