[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 1 | // Copyright (c) 2010 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_ |
| 7 | |
| 8 | #include <gtk/gtk.h> |
| 9 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 10 | #include "base/basictypes.h" |
| 11 | #include "base/scoped_ptr.h" |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 12 | #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 13 | #include "chrome/common/notification_observer.h" |
| 14 | #include "chrome/common/notification_registrar.h" |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 15 | #include "webkit/glue/window_open_disposition.h" |
| 16 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 17 | class AutocompleteEditModel; |
[email protected] | fb5153c5 | 2009-07-31 19:40:33 | [diff] [blame] | 18 | class AutocompleteEditView; |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 19 | class AutocompletePopupModel; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 20 | class GtkThemeProvider; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 21 | class Profile; |
| 22 | class SkBitmap; |
| 23 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 24 | class AutocompletePopupViewGtk : public AutocompletePopupView, |
| 25 | public NotificationObserver { |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 26 | public: |
[email protected] | fb5153c5 | 2009-07-31 19:40:33 | [diff] [blame] | 27 | AutocompletePopupViewGtk(AutocompleteEditView* edit_view, |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 28 | AutocompleteEditModel* edit_model, |
[email protected] | aa90e58 | 2009-04-27 08:13:43 | [diff] [blame] | 29 | Profile* profile, |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 30 | GtkWidget* location_bar); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 31 | ~AutocompletePopupViewGtk(); |
| 32 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 33 | // Overridden from AutocompletePopupView: |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 34 | virtual bool IsOpen() const { return opened_; } |
| 35 | virtual void InvalidateLine(size_t line); |
| 36 | virtual void UpdatePopupAppearance(); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 37 | virtual void PaintUpdatesNow(); |
[email protected] | 6a4ea5c | 2010-04-22 17:10:27 | [diff] [blame] | 38 | virtual void OnDragCanceled(); |
[email protected] | 252a08e | 2009-04-10 20:59:18 | [diff] [blame] | 39 | virtual AutocompletePopupModel* GetModel(); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 40 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 41 | // Overridden from NotificationObserver: |
| 42 | virtual void Observe(NotificationType type, |
| 43 | const NotificationSource& source, |
| 44 | const NotificationDetails& details); |
| 45 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 46 | private: |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 47 | void Show(size_t num_results); |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 48 | void Hide(); |
| 49 | |
[email protected] | aeba67b | 2009-10-15 08:20:19 | [diff] [blame] | 50 | // Restack the popup window directly above the browser's toplevel window. |
| 51 | void StackWindow(); |
| 52 | |
[email protected] | 1b24f85 | 2009-04-27 08:11:23 | [diff] [blame] | 53 | // Convert a y-coordinate to the closest line / result. |
| 54 | size_t LineFromY(int y); |
| 55 | |
| 56 | // Accept a line of the results, for example, when the user clicks a line. |
| 57 | void AcceptLine(size_t line, WindowOpenDisposition disposition); |
| 58 | |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 59 | static gboolean HandleExposeThunk(GtkWidget* widget, GdkEventExpose* event, |
| 60 | gpointer userdata) { |
| 61 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 62 | HandleExpose(widget, event); |
| 63 | } |
[email protected] | f41290e | 2009-04-09 10:21:57 | [diff] [blame] | 64 | gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event); |
| 65 | |
[email protected] | 1b24f85 | 2009-04-27 08:11:23 | [diff] [blame] | 66 | static gboolean HandleMotionThunk(GtkWidget* widget, GdkEventMotion* event, |
| 67 | gpointer userdata) { |
| 68 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 69 | HandleMotion(widget, event); |
| 70 | } |
| 71 | gboolean HandleMotion(GtkWidget* widget, GdkEventMotion* event); |
| 72 | |
| 73 | static gboolean HandleButtonPressThunk(GtkWidget* widget, |
| 74 | GdkEventButton* event, |
| 75 | gpointer userdata) { |
| 76 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 77 | HandleButtonPress(widget, event); |
| 78 | } |
| 79 | gboolean HandleButtonPress(GtkWidget* widget, GdkEventButton* event); |
| 80 | |
| 81 | static gboolean HandleButtonReleaseThunk(GtkWidget* widget, |
| 82 | GdkEventButton* event, |
| 83 | gpointer userdata) { |
| 84 | return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)-> |
| 85 | HandleButtonRelease(widget, event); |
| 86 | } |
| 87 | gboolean HandleButtonRelease(GtkWidget* widget, GdkEventButton* event); |
| 88 | |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 89 | scoped_ptr<AutocompletePopupModel> model_; |
[email protected] | fb5153c5 | 2009-07-31 19:40:33 | [diff] [blame] | 90 | AutocompleteEditView* edit_view_; |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 91 | GtkWidget* location_bar_; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 92 | |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 93 | // Our popup window, which is the only widget used, and we paint it on our |
| 94 | // own. This widget shouldn't be exposed outside of this class. |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 95 | GtkWidget* window_; |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 96 | // The pango layout object created from the window, cached across exposes. |
| 97 | PangoLayout* layout_; |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 98 | |
[email protected] | 69c579e | 2010-04-23 20:01:00 | [diff] [blame^] | 99 | GtkThemeProvider* theme_provider_; |
| 100 | NotificationRegistrar registrar_; |
| 101 | |
| 102 | // A list of colors which we should use for drawing the popup. These change |
| 103 | // between gtk and normal mode. |
| 104 | GdkColor border_color_; |
| 105 | GdkColor background_color_; |
| 106 | GdkColor selected_background_color_; |
| 107 | GdkColor hovered_background_color_; |
| 108 | GdkColor content_text_color_; |
| 109 | GdkColor selected_content_text_color_; |
| 110 | GdkColor url_text_color_; |
| 111 | GdkColor url_selected_text_color_; |
| 112 | GdkColor description_text_color_; |
| 113 | GdkColor description_selected_text_color_; |
| 114 | |
[email protected] | 6a4ea5c | 2010-04-22 17:10:27 | [diff] [blame] | 115 | // If the user cancels a dragging action (i.e. by pressing ESC), we don't have |
| 116 | // a convenient way to release mouse capture. Instead we use this flag to |
| 117 | // simply ignore all remaining drag events, and the eventual mouse release |
| 118 | // event. Since OnDragCanceled() can be called when we're not dragging, this |
| 119 | // flag is reset to false on a mouse pressed event, to make sure we don't |
| 120 | // erroneously ignore the next drag. |
| 121 | bool ignore_mouse_drag_; |
| 122 | |
[email protected] | 2c287e07 | 2009-04-16 16:25:52 | [diff] [blame] | 123 | // Whether our popup is currently open / shown, or closed / hidden. |
[email protected] | bdfde861c | 2009-03-10 12:35:31 | [diff] [blame] | 124 | bool opened_; |
| 125 | |
| 126 | DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtk); |
| 127 | }; |
| 128 | |
| 129 | #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_ |