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