blob: 53adbc29bfd86650bf7048db6cf6c10bb246c5ae [file] [log] [blame]
[email protected]69c579e2010-04-23 20:01:001// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]bdfde861c2009-03-10 12:35:312// 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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]bdfde861c2009-03-10 12:35:318
9#include <gtk/gtk.h>
[email protected]b671760b2010-07-15 21:13:4710#include <map>
[email protected]bdfde861c2009-03-10 12:35:3111
[email protected]bdfde861c2009-03-10 12:35:3112#include "base/basictypes.h"
13#include "base/scoped_ptr.h"
[email protected]bdfde861c2009-03-10 12:35:3114#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
[email protected]69c579e2010-04-23 20:01:0015#include "chrome/common/notification_observer.h"
16#include "chrome/common/notification_registrar.h"
[email protected]bdfde861c2009-03-10 12:35:3117#include "webkit/glue/window_open_disposition.h"
18
[email protected]bdfde861c2009-03-10 12:35:3119class AutocompleteEditModel;
[email protected]fb5153c52009-07-31 19:40:3320class AutocompleteEditView;
[email protected]7ce7ec52010-08-03 17:40:2821struct AutocompleteMatch;
[email protected]f41290e2009-04-09 10:21:5722class AutocompletePopupModel;
[email protected]69c579e2010-04-23 20:01:0023class GtkThemeProvider;
[email protected]bdfde861c2009-03-10 12:35:3124class Profile;
25class SkBitmap;
26
[email protected]69c579e2010-04-23 20:01:0027class AutocompletePopupViewGtk : public AutocompletePopupView,
28 public NotificationObserver {
[email protected]bdfde861c2009-03-10 12:35:3129 public:
[email protected]fb5153c52009-07-31 19:40:3330 AutocompletePopupViewGtk(AutocompleteEditView* edit_view,
[email protected]bdfde861c2009-03-10 12:35:3131 AutocompleteEditModel* edit_model,
[email protected]aa90e582009-04-27 08:13:4332 Profile* profile,
[email protected]69c579e2010-04-23 20:01:0033 GtkWidget* location_bar);
[email protected]bdfde861c2009-03-10 12:35:3134 ~AutocompletePopupViewGtk();
35
[email protected]69c579e2010-04-23 20:01:0036 // Overridden from AutocompletePopupView:
[email protected]bdfde861c2009-03-10 12:35:3137 virtual bool IsOpen() const { return opened_; }
38 virtual void InvalidateLine(size_t line);
39 virtual void UpdatePopupAppearance();
[email protected]bdfde861c2009-03-10 12:35:3140 virtual void PaintUpdatesNow();
[email protected]6a4ea5c2010-04-22 17:10:2741 virtual void OnDragCanceled();
[email protected]252a08e2009-04-10 20:59:1842 virtual AutocompletePopupModel* GetModel();
[email protected]6c4e66312010-08-09 15:18:1743 virtual int GetMaxYCoordinate();
[email protected]bdfde861c2009-03-10 12:35:3144
[email protected]69c579e2010-04-23 20:01:0045 // Overridden from NotificationObserver:
46 virtual void Observe(NotificationType type,
47 const NotificationSource& source,
48 const NotificationDetails& details);
49
[email protected]bdfde861c2009-03-10 12:35:3150 private:
[email protected]f41290e2009-04-09 10:21:5751 void Show(size_t num_results);
[email protected]bdfde861c2009-03-10 12:35:3152 void Hide();
53
[email protected]aeba67b2009-10-15 08:20:1954 // Restack the popup window directly above the browser's toplevel window.
55 void StackWindow();
56
[email protected]1b24f852009-04-27 08:11:2357 // 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]b671760b2010-07-15 21:13:4763 GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected);
64
[email protected]f41290e2009-04-09 10:21:5765 static gboolean HandleExposeThunk(GtkWidget* widget, GdkEventExpose* event,
66 gpointer userdata) {
67 return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)->
68 HandleExpose(widget, event);
69 }
[email protected]f41290e2009-04-09 10:21:5770 gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event);
71
[email protected]1b24f852009-04-27 08:11:2372 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]bdfde861c2009-03-10 12:35:3195 scoped_ptr<AutocompletePopupModel> model_;
[email protected]fb5153c52009-07-31 19:40:3396 AutocompleteEditView* edit_view_;
[email protected]69c579e2010-04-23 20:01:0097 GtkWidget* location_bar_;
[email protected]bdfde861c2009-03-10 12:35:3198
[email protected]2c287e072009-04-16 16:25:5299 // 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]bdfde861c2009-03-10 12:35:31101 GtkWidget* window_;
[email protected]2c287e072009-04-16 16:25:52102 // The pango layout object created from the window, cached across exposes.
103 PangoLayout* layout_;
[email protected]bdfde861c2009-03-10 12:35:31104
[email protected]69c579e2010-04-23 20:01:00105 GtkThemeProvider* theme_provider_;
106 NotificationRegistrar registrar_;
107
[email protected]b671760b2010-07-15 21:13:47108 // 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]69c579e2010-04-23 20:01:00113 // 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]68f1df42010-10-13 20:04:18121 GdkColor content_dim_text_color_;
122 GdkColor selected_content_dim_text_color_;
[email protected]69c579e2010-04-23 20:01:00123 GdkColor url_text_color_;
124 GdkColor url_selected_text_color_;
[email protected]69c579e2010-04-23 20:01:00125
[email protected]6a4ea5c2010-04-22 17:10:27126 // 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]2c287e072009-04-16 16:25:52134 // Whether our popup is currently open / shown, or closed / hidden.
[email protected]bdfde861c2009-03-10 12:35:31135 bool opened_;
136
137 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtk);
138};
139
140#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_