1 // Copyright (c) 2012 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_VIEW_MAC_H_
6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_VIEW_MAC_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/basictypes.h"
11 #include "base/mac/scoped_nsobject.h"
12 #include "base/memory/scoped_ptr.h"
13 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_matrix.h"
14 #include "components/omnibox/browser/autocomplete_match.h"
15 #include "components/omnibox/browser/omnibox_popup_view.h"
16 #include "ui/gfx/font.h"
18 class AutocompleteResult
;
19 class OmniboxEditModel
;
20 class OmniboxPopupModel
;
23 // Implements OmniboxPopupView using a raw NSWindow containing an
25 class OmniboxPopupViewMac
: public OmniboxPopupView
,
26 public OmniboxPopupMatrixObserver
{
28 OmniboxPopupViewMac(OmniboxView
* omnibox_view
,
29 OmniboxEditModel
* edit_model
,
31 ~OmniboxPopupViewMac() override
;
33 // Overridden from OmniboxPopupView:
34 bool IsOpen() const override
;
35 void InvalidateLine(size_t line
) override
{}
36 void UpdatePopupAppearance() override
;
37 gfx::Rect
GetTargetBounds() override
;
38 // This is only called by model in SetSelectedLine() after updating
39 // everything. Popup should already be visible.
40 void PaintUpdatesNow() override
;
41 void OnDragCanceled() override
{}
43 // Overridden from OmniboxPopupMatrixDelegate:
44 void OnMatrixRowSelected(OmniboxPopupMatrix
* matrix
, size_t row
) override
;
45 void OnMatrixRowClicked(OmniboxPopupMatrix
* matrix
, size_t row
) override
;
46 void OnMatrixRowMiddleClicked(OmniboxPopupMatrix
* matrix
,
49 // Returns the NSImage that should be used as an icon for the given match.
50 NSImage
* ImageForMatch(const AutocompleteMatch
& match
) const;
52 OmniboxPopupMatrix
* matrix() { return matrix_
; }
55 // Gets the autocomplete results. This is virtual so that it can be overridden
57 virtual const AutocompleteResult
& GetResult() const;
60 // Create the popup_ instance if needed.
61 void CreatePopupIfNeeded();
63 // Calculate the appropriate position for the popup based on the
64 // field's screen position and the given target for the matrix
65 // height, and makes the popup visible. Animates to the new frame
66 // if the popup shrinks, snaps to the new frame if the popup grows,
67 // allows existing animations to continue if the size doesn't
69 void PositionPopup(const CGFloat matrixHeight
);
71 // Opens the URL at the given row.
72 void OpenURLForRow(size_t row
, WindowOpenDisposition disposition
);
74 OmniboxView
* omnibox_view_
;
75 scoped_ptr
<OmniboxPopupModel
> model_
;
76 NSTextField
* field_
; // owned by tab controller
78 // Child window containing a matrix which implements the popup.
79 base::scoped_nsobject
<NSWindow
> popup_
;
80 NSRect target_popup_frame_
;
82 base::scoped_nsobject
<OmniboxPopupMatrix
> matrix_
;
83 base::scoped_nsobject
<NSView
> top_separator_view_
;
84 base::scoped_nsobject
<NSView
> bottom_separator_view_
;
85 base::scoped_nsobject
<NSBox
> background_view_
;
87 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewMac
);
90 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_POPUP_VIEW_MAC_H_