[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_ |
| 6 | #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 8 | |
| 9 | #include <gtk/gtk.h> |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 10 | #include <map> |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 11 | #include <string> |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 12 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 13 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 15 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 16 | #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 17 | #include "content/common/notification_observer.h" |
| 18 | #include "content/common/notification_registrar.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 19 | #include "ui/gfx/font.h" |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 20 | #include "webkit/glue/window_open_disposition.h" |
| 21 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 22 | class AutocompleteEditModel; |
[email protected] | fb5153c5 | 2009-07-31 19:40:33 | [diff] [blame] | 23 | class AutocompleteEditView; |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 24 | class AutocompletePopupModel; |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 25 | class GtkThemeService; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 26 | class Profile; |
| 27 | class SkBitmap; |
| 28 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 29 | class AutocompletePopupViewGtk : public AutocompletePopupView, |
| 30 | public NotificationObserver { |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 31 | public: |
[email protected] | c8a5c73 | 2011-01-28 18:54:50 | [diff] [blame] | 32 | AutocompletePopupViewGtk(const gfx::Font& font, |
| 33 | AutocompleteEditView* edit_view, |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 34 | AutocompleteEditModel* edit_model, |
[email protected] | aa90e58 | 2009-04-27 08:13:43 | [diff] [blame] | 35 | Profile* profile, |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 36 | GtkWidget* location_bar); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 37 | ~AutocompletePopupViewGtk(); |
| 38 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 39 | // Overridden from AutocompletePopupView: |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 40 | virtual bool IsOpen() const; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 41 | virtual void InvalidateLine(size_t line); |
| 42 | virtual void UpdatePopupAppearance(); |
[email protected] | 6af4014 | 2010-10-14 15:09:51 | [diff] [blame] | 43 | virtual gfx::Rect GetTargetBounds(); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 44 | virtual void PaintUpdatesNow(); |
[email protected] | 6a4ea5c | 2010-04-22 17:10:27 | [diff] [blame] | 45 | virtual void OnDragCanceled(); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 46 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 47 | // Overridden from NotificationObserver: |
| 48 | virtual void Observe(NotificationType type, |
| 49 | const NotificationSource& source, |
| 50 | const NotificationDetails& details); |
| 51 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 52 | private: |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 53 | // Be friendly for unit tests. |
| 54 | friend class AutocompletePopupViewGtkTest; |
| 55 | static void SetupLayoutForMatch( |
| 56 | PangoLayout* layout, |
[email protected] | a2fedb1e | 2011-01-25 15:23:36 | [diff] [blame] | 57 | const string16& text, |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 58 | const AutocompleteMatch::ACMatchClassifications& classifications, |
| 59 | const GdkColor* base_color, |
| 60 | const GdkColor* dim_color, |
| 61 | const GdkColor* url_color, |
| 62 | const std::string& prefix_text); |
| 63 | |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 64 | void Show(size_t num_results); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 65 | void Hide(); |
| 66 | |
[email protected] | aeba67b | 2009-10-15 08:20:19 | [diff] [blame] | 67 | // Restack the popup window directly above the browser's toplevel window. |
| 68 | void StackWindow(); |
| 69 | |
[email protected] | 1b24f85 | 2009-04-27 08:11:23 | [diff] [blame] | 70 | // Convert a y-coordinate to the closest line / result. |
| 71 | size_t LineFromY(int y); |
| 72 | |
| 73 | // Accept a line of the results, for example, when the user clicks a line. |
| 74 | void AcceptLine(size_t line, WindowOpenDisposition disposition); |
| 75 | |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 76 | GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected); |
| 77 | |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 78 | static gboolean HandleExposeThunk(GtkWidget* widget, GdkEventExpose* event, |
| 79 | gpointer userdata) { |
| 80 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 81 | HandleExpose(widget, event); |
| 82 | } |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 83 | gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event); |
| 84 | |
[email protected] | 1b24f85 | 2009-04-27 08:11:23 | [diff] [blame] | 85 | static gboolean HandleMotionThunk(GtkWidget* widget, GdkEventMotion* event, |
| 86 | gpointer userdata) { |
| 87 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 88 | HandleMotion(widget, event); |
| 89 | } |
| 90 | gboolean HandleMotion(GtkWidget* widget, GdkEventMotion* event); |
| 91 | |
| 92 | static gboolean HandleButtonPressThunk(GtkWidget* widget, |
| 93 | GdkEventButton* event, |
| 94 | gpointer userdata) { |
| 95 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 96 | HandleButtonPress(widget, event); |
| 97 | } |
| 98 | gboolean HandleButtonPress(GtkWidget* widget, GdkEventButton* event); |
| 99 | |
| 100 | static gboolean HandleButtonReleaseThunk(GtkWidget* widget, |
| 101 | GdkEventButton* event, |
| 102 | gpointer userdata) { |
| 103 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 104 | HandleButtonRelease(widget, event); |
| 105 | } |
| 106 | gboolean HandleButtonRelease(GtkWidget* widget, GdkEventButton* event); |
| 107 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 108 | scoped_ptr<AutocompletePopupModel> model_; |
[email protected] | fb5153c5 | 2009-07-31 19:40:33 | [diff] [blame] | 109 | AutocompleteEditView* edit_view_; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 110 | GtkWidget* location_bar_; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 111 | |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 112 | // Our popup window, which is the only widget used, and we paint it on our |
| 113 | // own. This widget shouldn't be exposed outside of this class. |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 114 | GtkWidget* window_; |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 115 | // The pango layout object created from the window, cached across exposes. |
| 116 | PangoLayout* layout_; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 117 | |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 118 | GtkThemeService* theme_service_; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 119 | NotificationRegistrar registrar_; |
| 120 | |
[email protected] | c8a5c73 | 2011-01-28 18:54:50 | [diff] [blame] | 121 | // Font used for suggestions after being derived from the constructor's |
| 122 | // |font|. |
| 123 | gfx::Font font_; |
| 124 | |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 125 | // Used to cache GdkPixbufs and map them from the SkBitmaps they were created |
| 126 | // from. |
| 127 | typedef std::map<const SkBitmap*, GdkPixbuf*> PixbufMap; |
| 128 | PixbufMap pixbufs_; |
| 129 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 130 | // A list of colors which we should use for drawing the popup. These change |
| 131 | // between gtk and normal mode. |
| 132 | GdkColor border_color_; |
| 133 | GdkColor background_color_; |
| 134 | GdkColor selected_background_color_; |
| 135 | GdkColor hovered_background_color_; |
| 136 | GdkColor content_text_color_; |
| 137 | GdkColor selected_content_text_color_; |
[email protected] | 68f1df4 | 2010-10-13 20:04:18 | [diff] [blame] | 138 | GdkColor content_dim_text_color_; |
| 139 | GdkColor selected_content_dim_text_color_; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 140 | GdkColor url_text_color_; |
| 141 | GdkColor url_selected_text_color_; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame] | 142 | |
[email protected] | 6a4ea5c | 2010-04-22 17:10:27 | [diff] [blame] | 143 | // If the user cancels a dragging action (i.e. by pressing ESC), we don't have |
| 144 | // a convenient way to release mouse capture. Instead we use this flag to |
| 145 | // simply ignore all remaining drag events, and the eventual mouse release |
| 146 | // event. Since OnDragCanceled() can be called when we're not dragging, this |
| 147 | // flag is reset to false on a mouse pressed event, to make sure we don't |
| 148 | // erroneously ignore the next drag. |
| 149 | bool ignore_mouse_drag_; |
| 150 | |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 151 | // Whether our popup is currently open / shown, or closed / hidden. |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 152 | bool opened_; |
| 153 | |
| 154 | DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtk); |
| 155 | }; |
| 156 | |
| 157 | #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_ |