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_MATRIX_H_
6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_MATRIX_H_
8 #import <Cocoa/Cocoa.h>
10 #import "ui/base/cocoa/tracking_area.h"
11 #include "ui/base/window_open_disposition.h"
13 class AutocompleteResult
;
14 @
class OmniboxPopupCell
;
15 @
class OmniboxPopupMatrix
;
16 class OmniboxPopupViewMac
;
18 @interface OmniboxPopupTableController
19 : NSViewController
<NSTableViewDelegate
, NSTableViewDataSource
> {
21 base::scoped_nsobject
<NSArray
> array_
;
22 NSInteger hoveredIndex_
;
25 // Setup the information used by the NSTableView data source.
26 - (instancetype
)initWithMatchResults
:(const AutocompleteResult
&)result
27 tableView
:(OmniboxPopupMatrix
*)tableView
28 popupView
:(const OmniboxPopupViewMac
&)popupView
29 answerImage
:(NSImage
*)answerImage
;
31 // Set the hovered highlight.
32 - (void)setHighlightedRow
:(NSInteger
)rowIndex
;
34 // Which row has the hovered highlight.
35 - (NSInteger
)highlightedRow
;
39 @interface
OmniboxPopupTableController (TestingAPI
)
40 - (instancetype
)initWithArray
:(NSArray
*)array
;
43 @
class OmniboxPopupMatrix
;
45 class OmniboxPopupMatrixObserver
{
47 // Called when the selection in the matrix changes.
48 virtual void OnMatrixRowSelected(OmniboxPopupMatrix
* matrix
, size_t row
) = 0;
50 // Called when the user clicks on a row.
51 virtual void OnMatrixRowClicked(OmniboxPopupMatrix
* matrix
, size_t row
) = 0;
53 // Called when the user middle clicks on a row.
54 virtual void OnMatrixRowMiddleClicked(OmniboxPopupMatrix
* matrix
,
58 // Sets up a tracking area to implement hover by highlighting the cell the mouse
60 @interface OmniboxPopupMatrix
: NSTableView
{
61 base::scoped_nsobject
<OmniboxPopupTableController
> matrixController_
;
62 OmniboxPopupMatrixObserver
* observer_
; // weak
63 ui::ScopedCrTrackingArea trackingArea_
;
64 NSAttributedString
* separator_
;
66 // The width of widest match contents in a set of infinite suggestions.
67 CGFloat maxMatchContentsWidth_
;
69 CGFloat answerLineHeight_
;
72 @
property(retain
, nonatomic
) NSAttributedString
* separator
;
73 @
property(nonatomic
) CGFloat maxMatchContentsWidth
;
74 @
property(nonatomic
) CGFloat answerLineHeight
;
76 // Create a zero-size matrix.
77 - (instancetype
)initWithObserver
:(OmniboxPopupMatrixObserver
*)observer
;
80 - (void)setObserver
:(OmniboxPopupMatrixObserver
*)observer
;
82 // Return the currently highlighted row. Returns -1 if no row is highlighted.
83 - (NSInteger
)highlightedRow
;
85 // Move the selection to |rowIndex|.
86 - (void)selectRowIndex
:(NSInteger
)rowIndex
;
88 // Setup the NSTableView data source.
89 - (void)setController
:(OmniboxPopupTableController
*)controller
;
93 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_MATRIX_H_