Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / omnibox / omnibox_popup_cell.h
blob34d69e76d1522a4b255a0733be485c50922bfa45
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> {
16 @private
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.
29 NSImage* image_;
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_;
36 BOOL isContentsRTL_;
38 // Is this suggestion an answer or calculator result.
39 bool isAnswer_;
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
56 image:(NSImage*)image
57 answerImage:(NSImage*)answerImage;
59 // Returns the width of the match contents.
60 - (CGFloat)getMatchContentsWidth;
62 @end
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;
77 @end
79 const CGFloat kContentLineHeight = 25.0;
81 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_CELL_H_