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) const; |
| 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) const; |
| 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() const; |
| 77 |
| 78 // Returns the current autocomplete result. |
| 79 virtual const AutocompleteResult& GetResult() const; |
| 80 |
60 private: | 81 private: |
61 // Be friendly for unit tests. | 82 // Be friendly for unit tests. |
62 friend class OmniboxPopupViewGtkTest; | 83 friend class OmniboxPopupViewGtkTest; |
63 | 84 |
64 static void SetupLayoutForMatch( | 85 static void SetupLayoutForMatch( |
65 PangoLayout* layout, | 86 PangoLayout* layout, |
66 const string16& text, | 87 const string16& text, |
67 const AutocompleteMatch::ACMatchClassifications& classifications, | 88 const AutocompleteMatch::ACMatchClassifications& classifications, |
68 const GdkColor* base_color, | 89 const GdkColor* base_color, |
69 const GdkColor* dim_color, | 90 const GdkColor* dim_color, |
70 const GdkColor* url_color, | 91 const GdkColor* url_color, |
71 const std::string& prefix_text); | 92 const std::string& prefix_text); |
72 | 93 |
73 void Show(size_t num_results); | 94 virtual void Show(size_t num_results); |
74 void Hide(); | 95 virtual void Hide(); |
75 | 96 |
76 // Restack the popup window directly above the browser's toplevel window. | 97 // Restack the popup window directly above the browser's toplevel window. |
77 void StackWindow(); | 98 void StackWindow(); |
78 | 99 |
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. | 100 // Accept a line of the results, for example, when the user clicks a line. |
83 void AcceptLine(size_t line, WindowOpenDisposition disposition); | 101 void AcceptLine(size_t line, WindowOpenDisposition disposition); |
84 | 102 |
| 103 // Returns the appropriate icon to display beside |match|. |
85 gfx::Image IconForMatch(const AutocompleteMatch& match, | 104 gfx::Image IconForMatch(const AutocompleteMatch& match, |
86 bool selected, | 105 bool selected, |
87 bool is_selected_keyword); | 106 bool is_selected_keyword); |
88 | 107 |
89 // Returns the |index|th element of match, unless we're selected and showing | 108 // Returns the |index|th element of match, unless we're selected and showing |
90 // the associated keyword match. | 109 // the associated keyword match. |
91 void GetVisibleMatchForInput(size_t index, | 110 void GetVisibleMatchForInput(size_t index, |
92 const AutocompleteMatch** match, | 111 const AutocompleteMatch** match, |
93 bool* is_selected_keyword); | 112 bool* is_selected_keyword); |
94 | 113 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // erroneously ignore the next drag. | 162 // erroneously ignore the next drag. |
144 bool ignore_mouse_drag_; | 163 bool ignore_mouse_drag_; |
145 | 164 |
146 // Whether our popup is currently open / shown, or closed / hidden. | 165 // Whether our popup is currently open / shown, or closed / hidden. |
147 bool opened_; | 166 bool opened_; |
148 | 167 |
149 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); | 168 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); |
150 }; | 169 }; |
151 | 170 |
152 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ | 171 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ |
OLD | NEW |