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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_
6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "components/omnibox/browser/autocomplete_match.h"
13 class OmniboxPopupViewMac
;
15 @interface OmniboxPopupCellData
: NSObject
<NSCopying
> {
17 // Left hand side of the separator (e.g. a hyphen).
18 NSAttributedString
* contents_
;
19 // Right hand side of the separator (e.g. a hyphen).
20 NSAttributedString
* description_
;
22 // NOTE: While |prefix_| is used only for postfix suggestions, it still needs
23 // to be a member of the class. This allows the |NSAttributedString| instance
24 // to stay alive between the call to |drawTitle| and the actual paint event
25 // which accesses the |NSAttributedString| instance.
26 NSAttributedString
* prefix_
;
28 // Common icon that shows next to most rows in the list.
30 // Uncommon icon that only shows on answer rows (e.g. weather).
31 NSImage
* answerImage_
;
33 // The offset at which the infinite suggestion contents should be displayed.
34 CGFloat contentsOffset_
;
38 // Is this suggestion an answer or calculator result.
41 AutocompleteMatch::Type matchType_
;
44 @
property(readonly
, retain
, nonatomic
) NSAttributedString
* contents
;
45 @
property(readonly
, retain
, nonatomic
) NSAttributedString
* description
;
46 @
property(readonly
, retain
, nonatomic
) NSAttributedString
* prefix
;
47 @
property(readonly
, retain
, nonatomic
) NSImage
* image
;
48 @
property(readonly
, retain
, nonatomic
) NSImage
* answerImage
;
49 @
property(readonly
, nonatomic
) CGFloat contentsOffset
;
50 @
property(readonly
, nonatomic
) BOOL isContentsRTL
;
51 @
property(readonly
, nonatomic
) bool isAnswer
;
52 @
property(readonly
, nonatomic
) AutocompleteMatch::Type matchType
;
54 - (instancetype
)initWithMatch
:(const AutocompleteMatch
&)match
55 contentsOffset
:(CGFloat
)contentsOffset
57 answerImage
:(NSImage
*)answerImage
;
59 // Returns the width of the match contents.
60 - (CGFloat
)getMatchContentsWidth
;
64 // Overrides how cells are displayed. Uses information from
65 // OmniboxPopupCellData to draw suggestion results.
66 @interface OmniboxPopupCell
: NSCell
68 - (void)drawMatchWithFrame
:(NSRect
)cellFrame inView
:(NSView
*)controlView
;
70 // Returns the offset of the start of the contents in the input text for the
71 // given match. It is costly to compute this offset, so it is computed once and
72 // shared by all OmniboxPopupCell instances through OmniboxPopupViewMac parent.
73 + (CGFloat
)computeContentsOffset
:(const AutocompleteMatch
&)match
;
75 + (NSAttributedString
*)createSeparatorString
;
79 const CGFloat kContentLineHeight
= 25.0;
81 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_