| 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 class OmniboxPopupViewGtk : public OmniboxPopupView, | 35 class OmniboxPopupViewGtk : public OmniboxPopupView, |
| 35 public content::NotificationObserver { | 36 public content::NotificationObserver { |
| 36 public: | 37 public: |
| 37 OmniboxPopupViewGtk(const gfx::Font& font, | 38 OmniboxPopupViewGtk(const gfx::Font& font, |
| 38 OmniboxView* omnibox_view, | 39 OmniboxView* omnibox_view, |
| 39 OmniboxEditModel* edit_model, | 40 OmniboxEditModel* edit_model, |
| 40 GtkWidget* location_bar); | 41 GtkWidget* location_bar); |
| 41 virtual ~OmniboxPopupViewGtk(); | 42 virtual ~OmniboxPopupViewGtk(); |
| 42 | 43 |
| 44 // Initializes the view. |
| 45 virtual void Init(); |
| 46 |
| 43 // Overridden from OmniboxPopupView: | 47 // Overridden from OmniboxPopupView: |
| 44 virtual bool IsOpen() const OVERRIDE; | 48 virtual bool IsOpen() const OVERRIDE; |
| 45 virtual void InvalidateLine(size_t line) OVERRIDE; | 49 virtual void InvalidateLine(size_t line) OVERRIDE; |
| 46 virtual void UpdatePopupAppearance() OVERRIDE; | 50 virtual void UpdatePopupAppearance() OVERRIDE; |
| 47 virtual gfx::Rect GetTargetBounds() OVERRIDE; | 51 virtual gfx::Rect GetTargetBounds() OVERRIDE; |
| 48 virtual void PaintUpdatesNow() OVERRIDE; | 52 virtual void PaintUpdatesNow() OVERRIDE; |
| 49 virtual void OnDragCanceled() OVERRIDE; | 53 virtual void OnDragCanceled() OVERRIDE; |
| 50 | 54 |
| 51 // Overridden from content::NotificationObserver: | 55 // Overridden from content::NotificationObserver: |
| 52 virtual void Observe(int type, | 56 virtual void Observe(int type, |
| 53 const content::NotificationSource& source, | 57 const content::NotificationSource& source, |
| 54 const content::NotificationDetails& details) OVERRIDE; | 58 const content::NotificationDetails& details) OVERRIDE; |
| 55 | 59 |
| 60 protected: |
| 61 // Convert a y-coordinate to the closest line / result. |
| 62 size_t LineFromY(int y) const; |
| 63 |
| 64 // Return a Rect for the space for a result line. This excludes the border, |
| 65 // but includes the padding. This is the area that is colored for a |
| 66 // selection. |
| 67 gfx::Rect GetRectForLine(size_t line, int width) const; |
| 68 |
| 69 // Returns the number of hidden matches at the top of the popup. This is |
| 70 // non-zero when a verbatim match like search-what-you-typed is present but |
| 71 // should not be shown. |
| 72 size_t GetHiddenMatchCount() const; |
| 73 |
| 74 // Returns the current autocomplete result. |
| 75 virtual const AutocompleteResult& GetResult() const; |
| 76 |
| 56 private: | 77 private: |
| 57 // Be friendly for unit tests. | 78 // Be friendly for unit tests. |
| 58 friend class OmniboxPopupViewGtkTest; | 79 friend class OmniboxPopupViewGtkTest; |
| 59 | 80 |
| 60 static void SetupLayoutForMatch( | 81 static void SetupLayoutForMatch( |
| 61 PangoLayout* layout, | 82 PangoLayout* layout, |
| 62 const string16& text, | 83 const string16& text, |
| 63 const AutocompleteMatch::ACMatchClassifications& classifications, | 84 const AutocompleteMatch::ACMatchClassifications& classifications, |
| 64 const GdkColor* base_color, | 85 const GdkColor* base_color, |
| 65 const GdkColor* dim_color, | 86 const GdkColor* dim_color, |
| 66 const GdkColor* url_color, | 87 const GdkColor* url_color, |
| 67 const std::string& prefix_text); | 88 const std::string& prefix_text); |
| 68 | 89 |
| 69 void Show(size_t num_results); | 90 virtual void Show(size_t num_results); |
| 70 void Hide(); | 91 virtual void Hide(); |
| 71 | 92 |
| 72 // Restack the popup window directly above the browser's toplevel window. | 93 // Restack the popup window directly above the browser's toplevel window. |
| 73 void StackWindow(); | 94 void StackWindow(); |
| 74 | 95 |
| 75 // Convert a y-coordinate to the closest line / result. | |
| 76 size_t LineFromY(int y); | |
| 77 | |
| 78 // Accept a line of the results, for example, when the user clicks a line. | 96 // Accept a line of the results, for example, when the user clicks a line. |
| 79 void AcceptLine(size_t line, WindowOpenDisposition disposition); | 97 void AcceptLine(size_t line, WindowOpenDisposition disposition); |
| 80 | 98 |
| 99 // Returns the appropriate icon to display beside |match|. |
| 81 gfx::Image IconForMatch(const AutocompleteMatch& match, | 100 gfx::Image IconForMatch(const AutocompleteMatch& match, |
| 82 bool selected, | 101 bool selected, |
| 83 bool is_selected_keyword); | 102 bool is_selected_keyword); |
| 84 | 103 |
| 85 // 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 |
| 86 // the associated keyword match. | 105 // the associated keyword match. |
| 87 void GetVisibleMatchForInput(size_t index, | 106 void GetVisibleMatchForInput(size_t index, |
| 88 const AutocompleteMatch** match, | 107 const AutocompleteMatch** match, |
| 89 bool* is_selected_keyword); | 108 bool* is_selected_keyword); |
| 90 | 109 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // erroneously ignore the next drag. | 157 // erroneously ignore the next drag. |
| 139 bool ignore_mouse_drag_; | 158 bool ignore_mouse_drag_; |
| 140 | 159 |
| 141 // Whether our popup is currently open / shown, or closed / hidden. | 160 // Whether our popup is currently open / shown, or closed / hidden. |
| 142 bool opened_; | 161 bool opened_; |
| 143 | 162 |
| 144 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); | 163 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk); |
| 145 }; | 164 }; |
| 146 | 165 |
| 147 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ | 166 #endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_ |
| OLD | NEW |