blob: b3d442c840a6bc714355c5ee8cdf53d80ad7107e [file] [log] [blame]
[email protected]f20d7332011-03-08 21:11:531// Copyright (c) 2011 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]9ac40092010-10-27 23:05:2611#include <string>
[email protected]bdfde861c2009-03-10 12:35:3112
[email protected]bdfde861c2009-03-10 12:35:3113#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]9ac40092010-10-27 23:05:2615#include "chrome/browser/autocomplete/autocomplete_match.h"
[email protected]bdfde861c2009-03-10 12:35:3116#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
[email protected]f20d7332011-03-08 21:11:5317#include "content/common/notification_observer.h"
18#include "content/common/notification_registrar.h"
[email protected]08397d52011-02-05 01:53:3819#include "ui/gfx/font.h"
[email protected]bdfde861c2009-03-10 12:35:3120#include "webkit/glue/window_open_disposition.h"
21
[email protected]bdfde861c2009-03-10 12:35:3122class AutocompleteEditModel;
[email protected]fb5153c52009-07-31 19:40:3323class AutocompleteEditView;
[email protected]f41290e2009-04-09 10:21:5724class AutocompletePopupModel;
[email protected]a0ea76c2011-03-23 17:36:4225class GtkThemeService;
[email protected]bdfde861c2009-03-10 12:35:3126class Profile;
27class SkBitmap;
28
[email protected]69c579e2010-04-23 20:01:0029class AutocompletePopupViewGtk : public AutocompletePopupView,
30 public NotificationObserver {
[email protected]bdfde861c2009-03-10 12:35:3131 public:
[email protected]c8a5c732011-01-28 18:54:5032 AutocompletePopupViewGtk(const gfx::Font& font,
33 AutocompleteEditView* edit_view,
[email protected]bdfde861c2009-03-10 12:35:3134 AutocompleteEditModel* edit_model,
[email protected]aa90e582009-04-27 08:13:4335 Profile* profile,
[email protected]69c579e2010-04-23 20:01:0036 GtkWidget* location_bar);
[email protected]bdfde861c2009-03-10 12:35:3137 ~AutocompletePopupViewGtk();
38
[email protected]69c579e2010-04-23 20:01:0039 // Overridden from AutocompletePopupView:
[email protected]ddb1e5a2010-12-13 20:10:4540 virtual bool IsOpen() const;
[email protected]bdfde861c2009-03-10 12:35:3141 virtual void InvalidateLine(size_t line);
42 virtual void UpdatePopupAppearance();
[email protected]6af40142010-10-14 15:09:5143 virtual gfx::Rect GetTargetBounds();
[email protected]bdfde861c2009-03-10 12:35:3144 virtual void PaintUpdatesNow();
[email protected]6a4ea5c2010-04-22 17:10:2745 virtual void OnDragCanceled();
[email protected]bdfde861c2009-03-10 12:35:3146
[email protected]69c579e2010-04-23 20:01:0047 // Overridden from NotificationObserver:
48 virtual void Observe(NotificationType type,
49 const NotificationSource& source,
50 const NotificationDetails& details);
51
[email protected]bdfde861c2009-03-10 12:35:3152 private:
[email protected]9ac40092010-10-27 23:05:2653 // Be friendly for unit tests.
54 friend class AutocompletePopupViewGtkTest;
55 static void SetupLayoutForMatch(
56 PangoLayout* layout,
[email protected]a2fedb1e2011-01-25 15:23:3657 const string16& text,
[email protected]9ac40092010-10-27 23:05:2658 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]f41290e2009-04-09 10:21:5764 void Show(size_t num_results);
[email protected]bdfde861c2009-03-10 12:35:3165 void Hide();
66
[email protected]aeba67b2009-10-15 08:20:1967 // Restack the popup window directly above the browser's toplevel window.
68 void StackWindow();
69
[email protected]1b24f852009-04-27 08:11:2370 // 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]b671760b2010-07-15 21:13:4776 GdkPixbuf* IconForMatch(const AutocompleteMatch& match, bool selected);
77
[email protected]f41290e2009-04-09 10:21:5778 static gboolean HandleExposeThunk(GtkWidget* widget, GdkEventExpose* event,
79 gpointer userdata) {
80 return reinterpret_cast<AutocompletePopupViewGtk*>(userdata)->
81 HandleExpose(widget, event);
82 }
[email protected]f41290e2009-04-09 10:21:5783 gboolean HandleExpose(GtkWidget* widget, GdkEventExpose* event);
84
[email protected]1b24f852009-04-27 08:11:2385 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]bdfde861c2009-03-10 12:35:31108 scoped_ptr<AutocompletePopupModel> model_;
[email protected]fb5153c52009-07-31 19:40:33109 AutocompleteEditView* edit_view_;
[email protected]69c579e2010-04-23 20:01:00110 GtkWidget* location_bar_;
[email protected]bdfde861c2009-03-10 12:35:31111
[email protected]2c287e072009-04-16 16:25:52112 // 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]bdfde861c2009-03-10 12:35:31114 GtkWidget* window_;
[email protected]2c287e072009-04-16 16:25:52115 // The pango layout object created from the window, cached across exposes.
116 PangoLayout* layout_;
[email protected]bdfde861c2009-03-10 12:35:31117
[email protected]a0ea76c2011-03-23 17:36:42118 GtkThemeService* theme_service_;
[email protected]69c579e2010-04-23 20:01:00119 NotificationRegistrar registrar_;
120
[email protected]c8a5c732011-01-28 18:54:50121 // Font used for suggestions after being derived from the constructor's
122 // |font|.
123 gfx::Font font_;
124
[email protected]b671760b2010-07-15 21:13:47125 // 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]69c579e2010-04-23 20:01:00130 // 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]68f1df42010-10-13 20:04:18138 GdkColor content_dim_text_color_;
139 GdkColor selected_content_dim_text_color_;
[email protected]69c579e2010-04-23 20:01:00140 GdkColor url_text_color_;
141 GdkColor url_selected_text_color_;
[email protected]69c579e2010-04-23 20:01:00142
[email protected]6a4ea5c2010-04-22 17:10:27143 // 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]2c287e072009-04-16 16:25:52151 // Whether our popup is currently open / shown, or closed / hidden.
[email protected]bdfde861c2009-03-10 12:35:31152 bool opened_;
153
154 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtk);
155};
156
157#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_GTK_H_