OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ |
6 #define CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 16 #include "chrome/browser/autocomplete/autocomplete_match.h" |
17 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 17 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 #include "ui/base/gtk/gtk_signal.h" | 20 #include "ui/base/gtk/gtk_signal.h" |
21 #include "ui/base/window_open_disposition.h" | 21 #include "ui/base/window_open_disposition.h" |
22 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
23 | 23 |
24 class AutocompleteResult; | |
24 class GtkThemeService; | 25 class GtkThemeService; |
25 class OmniboxEditModel; | 26 class OmniboxEditModel; |
26 class OmniboxPopupModel; | 27 class OmniboxPopupModel; |
27 class OmniboxView; | 28 class OmniboxView; |
28 class SkBitmap; | 29 class SkBitmap; |
29 | 30 |
30 namespace gfx { | 31 namespace gfx { |
31 class Image; | 32 class Image; |
32 } | 33 } |
33 | 34 |
34 namespace ui { | 35 namespace ui { |
35 class GtkSignalRegistrar; | 36 class GtkSignalRegistrar; |
36 } | 37 } |
37 | 38 |
38 class OmniboxPopupViewGtk : public OmniboxPopupView, | 39 class OmniboxPopupViewGtk : public OmniboxPopupView, |
39 public content::NotificationObserver { | 40 public content::NotificationObserver { |
40 public: | 41 public: |
41 OmniboxPopupViewGtk(const gfx::Font& font, | 42 OmniboxPopupViewGtk(const gfx::Font& font, |
42 OmniboxView* omnibox_view, | 43 OmniboxView* omnibox_view, |
43 OmniboxEditModel* edit_model, | 44 OmniboxEditModel* edit_model, |
44 GtkWidget* location_bar); | 45 GtkWidget* location_bar); |
45 virtual ~OmniboxPopupViewGtk(); | 46 virtual ~OmniboxPopupViewGtk(); |
46 | 47 |
48 // Initializes the view. | |
49 virtual void Init(); | |
50 | |
47 // Overridden from OmniboxPopupView: | 51 // Overridden from OmniboxPopupView: |
48 virtual bool IsOpen() const OVERRIDE; | 52 virtual bool IsOpen() const OVERRIDE; |
49 virtual void InvalidateLine(size_t line) OVERRIDE; | 53 virtual void InvalidateLine(size_t line) OVERRIDE; |
50 virtual void UpdatePopupAppearance() OVERRIDE; | 54 virtual void UpdatePopupAppearance() OVERRIDE; |
51 virtual gfx::Rect GetTargetBounds() OVERRIDE; | 55 virtual gfx::Rect GetTargetBounds() OVERRIDE; |
52 virtual void PaintUpdatesNow() OVERRIDE; | 56 virtual void PaintUpdatesNow() OVERRIDE; |
53 virtual void OnDragCanceled() OVERRIDE; | 57 virtual void OnDragCanceled() OVERRIDE; |
54 | 58 |
55 // Overridden from content::NotificationObserver: | 59 // Overridden from content::NotificationObserver: |
56 virtual void Observe(int type, | 60 virtual void Observe(int type, |
57 const content::NotificationSource& source, | 61 const content::NotificationSource& source, |
58 const content::NotificationDetails& details) OVERRIDE; | 62 const content::NotificationDetails& details) OVERRIDE; |
59 | 63 |
64 protected: | |
65 // Convert a y-coordinate to the closest line / result. | |
66 size_t LineFromY(int y); | |
67 | |
68 // Return a Rect for the space for a result line. This excludes the border, | |
69 // but includes the padding. This is the area that is colored for a | |
70 // selection. | |
71 gfx::Rect GetRectForLine(size_t line, int width); | |
72 | |
73 // Returns the number of hidden matches at the top of the popup. This is | |
74 // non-zero when a verbatim match like search-what-you-typed is present but | |
75 // should not be shown. | |
76 size_t GetHiddenMatchCount(); | |
77 | |
60 private: | 78 private: |
61 // Be friendly for unit tests. | 79 // Be friendly for unit tests. |
62 friend class OmniboxPopupViewGtkTest; | 80 friend class OmniboxPopupViewGtkTest; |
63 | 81 |
64 static void SetupLayoutForMatch( | 82 static void SetupLayoutForMatch( |
65 PangoLayout* layout, | 83 PangoLayout* layout, |
66 const string16& text, | 84 const string16& text, |
67 const AutocompleteMatch::ACMatchClassifications& classifications, | 85 const AutocompleteMatch::ACMatchClassifications& classifications, |
68 const GdkColor* base_color, | 86 const GdkColor* base_color, |
69 const GdkColor* dim_color, | 87 const GdkColor* dim_color, |
70 const GdkColor* url_color, | 88 const GdkColor* url_color, |
71 const std::string& prefix_text); | 89 const std::string& prefix_text); |
72 | 90 |
73 void Show(size_t num_results); | 91 virtual void Show(size_t num_results); |
74 void Hide(); | 92 virtual void Hide(); |
75 | 93 |
76 // Restack the popup window directly above the browser's toplevel window. | 94 // Restack the popup window directly above the browser's toplevel window. |
77 void StackWindow(); | 95 void StackWindow(); |
78 | 96 |
79 // Convert a y-coordinate to the closest line / result. | |
80 size_t LineFromY(int y); | |
81 | |
82 // Accept a line of the results, for example, when the user clicks a line. | 97 // Accept a line of the results, for example, when the user clicks a line. |
83 void AcceptLine(size_t line, WindowOpenDisposition disposition); | 98 void AcceptLine(size_t line, WindowOpenDisposition disposition); |
84 | 99 |
85 gfx::Image IconForMatch(const AutocompleteMatch& match, | 100 gfx::Image IconForMatch(const AutocompleteMatch& match, |
86 bool selected, | 101 bool selected, |
87 bool is_selected_keyword); | 102 bool is_selected_keyword); |
88 | 103 |
89 // Returns the |index|th element of match, unless we're selected and showing | 104 // Returns the |index|th element of match, unless we're selected and showing |
90 // the associated keyword match. | 105 // the associated keyword match. |
91 void GetVisibleMatchForInput(size_t index, | 106 void GetVisibleMatchForInput(size_t index, |
92 const AutocompleteMatch** match, | 107 const AutocompleteMatch** match, |
93 bool* is_selected_keyword); | 108 bool* is_selected_keyword); |
94 | 109 |
110 // Returns the current autocomplete result. | |
111 virtual const AutocompleteResult& GetResult() const; | |
Evan Stade
2013/08/15 01:05:12
should be protected rather than private
Jered
2013/08/15 16:08:49
Done.
| |
112 | |
95 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleMotion, | 113 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleMotion, |
96 GdkEventMotion*); | 114 GdkEventMotion*); |
97 | 115 |
98 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonPress, | 116 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonPress, |
99 GdkEventButton*); | 117 GdkEventButton*); |
100 | 118 |
101 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonRelease, | 119 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonRelease, |
102 GdkEventButton*); | 120 GdkEventButton*); |
103 | 121 |
104 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleExpose, | 122 CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleExpose, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 // erroneously ignore the next drag. | 161 // erroneously ignore the next drag. |
144 bool ignore_mouse_drag_; | 162 bool ignore_mouse_drag_; |
145 | 163 |
146 // Whether our popup is currently open / shown, or closed / hidden. | 164 // Whether our popup is currently open / shown, or closed / hidden. |
147 bool opened_; | 165 bool opened_; |
148 | 166 |
149 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); | 167 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); |
150 }; | 168 }; |
151 | 169 |
152 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ | 170 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ |
OLD | NEW |