blob: 4759417b5e8425ac6f70f6606c60e5290e296d8e [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_
7
8#include <gtk/gtk.h>
9
[email protected]bdfde861c2009-03-10 12:35:3110#include "base/basictypes.h"
11#include "base/scoped_ptr.h"
[email protected]bdfde861c2009-03-10 12:35:3112#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
[email protected]69c579e2010-04-23 20:01:0013#include "chrome/common/notification_observer.h"
14#include "chrome/common/notification_registrar.h"
[email protected]bdfde861c2009-03-10 12:35:3115#include "webkit/glue/window_open_disposition.h"
16
[email protected]bdfde861c2009-03-10 12:35:3117class AutocompleteEditModel;
[email protected]fb5153c52009-07-31 19:40:3318class AutocompleteEditView;
[email protected]f41290e2009-04-09 10:21:5719class AutocompletePopupModel;
[email protected]69c579e2010-04-23 20:01:0020class GtkThemeProvider;
[email protected]bdfde861c2009-03-10 12:35:3121class Profile;
22class SkBitmap;
23
[email protected]69c579e2010-04-23 20:01:0024class AutocompletePopupViewGtk : public AutocompletePopupView,
25 public NotificationObserver {
[email protected]bdfde861c2009-03-10 12:35:3126 public:
[email protected]fb5153c52009-07-31 19:40:3327 AutocompletePopupViewGtk(AutocompleteEditView* edit_view,
[email protected]bdfde861c2009-03-10 12:35:3128 AutocompleteEditModel* edit_model,
[email protected]aa90e582009-04-27 08:13:4329 Profile* profile,
[email protected]69c579e2010-04-23 20:01:0030 GtkWidget* location_bar);
[email protected]bdfde861c2009-03-10 12:35:3131 ~AutocompletePopupViewGtk();
32
[email protected]69c579e2010-04-23 20:01:0033 // Overridden from AutocompletePopupView:
[email protected]bdfde861c2009-03-10 12:35:3134 virtual bool IsOpen() const { return opened_; }
35 virtual void InvalidateLine(size_t line);
36 virtual void UpdatePopupAppearance();
[email protected]bdfde861c2009-03-10 12:35:3137 virtual void PaintUpdatesNow();
[email protected]6a4ea5c2010-04-22 17:10:2738 virtual void OnDragCanceled();
[email protected]252a08e2009-04-10 20:59:1839 virtual AutocompletePopupModel* GetModel();
[email protected]bdfde861c2009-03-10 12:35:3140
[email protected]69c579e2010-04-23 20:01:0041 // Overridden from NotificationObserver:
42 virtual void Observe(NotificationType type,
43 const NotificationSource& source,
44 const NotificationDetails& details);
45
[email protected]bdfde861c2009-03-10 12:35:3146 private:
[email protected]f41290e2009-04-09 10:21:5747 void Show(size_t num_results);
[email protected]bdfde861c2009-03-10 12:35:3148 void Hide();
49
[email protected]aeba67b2009-10-15 08:20:1950 // Restack the popup window directly above the browser's toplevel window.
51 void StackWindow();
52
[email protected]1b24f852009-04-27 08:11:2353 // 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]f41290e2009-04-09 10:21:5759 static gboolean HandleExposeThunk(GtkWidget* widget, GdkEventExpose* event,
60 gpointer userdata) {
61 return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)->
62 HandleExpose(widget, event);
63 }
[email protected]f41290e2009-04-09 10:21:5764 gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event);
65
[email protected]1b24f852009-04-27 08:11:2366 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]bdfde861c2009-03-10 12:35:3189 scoped_ptr<AutocompletePopupModel> model_;
[email protected]fb5153c52009-07-31 19:40:3390 AutocompleteEditView* edit_view_;
[email protected]69c579e2010-04-23 20:01:0091 GtkWidget* location_bar_;
[email protected]bdfde861c2009-03-10 12:35:3192
[email protected]2c287e072009-04-16 16:25:5293 // 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]bdfde861c2009-03-10 12:35:3195 GtkWidget* window_;
[email protected]2c287e072009-04-16 16:25:5296 // The pango layout object created from the window, cached across exposes.
97 PangoLayout* layout_;
[email protected]bdfde861c2009-03-10 12:35:3198
[email protected]69c579e2010-04-23 20:01:0099 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]6a4ea5c2010-04-22 17:10:27115 // 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]2c287e072009-04-16 16:25:52123 // Whether our popup is currently open / shown, or closed / hidden.
[email protected]bdfde861c2009-03-10 12:35:31124 bool opened_;
125
126 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtk);
127};
128
129#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_