1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_
#define CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_
#include <gtk/gtk.h>
#include <map>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/font.h"
class AutocompleteResult;
class GtkThemeService;
class OmniboxEditModel;
class OmniboxPopupModel;
class OmniboxView;
class SkBitmap;
namespace gfx {
class Image;
}
class OmniboxPopupViewGtk : public OmniboxPopupView,
public content::NotificationObserver {
public:
OmniboxPopupViewGtk(const gfx::Font& font,
OmniboxView* omnibox_view,
OmniboxEditModel* edit_model,
GtkWidget* location_bar);
virtual ~OmniboxPopupViewGtk();
// Initializes the view.
virtual void Init();
// Overridden from OmniboxPopupView:
virtual bool IsOpen() const OVERRIDE;
virtual void InvalidateLine(size_t line) OVERRIDE;
virtual void UpdatePopupAppearance() OVERRIDE;
virtual gfx::Rect GetTargetBounds() OVERRIDE;
virtual void PaintUpdatesNow() OVERRIDE;
virtual void OnDragCanceled() OVERRIDE;
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
protected:
// Convert a y-coordinate to the closest line / result.
size_t LineFromY(int y) const;
// Return a Rect for the space for a result line. This excludes the border,
// but includes the padding. This is the area that is colored for a
// selection.
gfx::Rect GetRectForLine(size_t line, int width) const;
// Returns the number of hidden matches at the top of the popup. This is
// non-zero when a verbatim match like search-what-you-typed is present but
// should not be shown.
size_t GetHiddenMatchCount() const;
// Returns the current autocomplete result.
virtual const AutocompleteResult& GetResult() const;
private:
// Be friendly for unit tests.
friend class OmniboxPopupViewGtkTest;
static void SetupLayoutForMatch(
PangoLayout* layout,
const base::string16& text,
const AutocompleteMatch::ACMatchClassifications& classifications,
const GdkColor* base_color,
const GdkColor* dim_color,
const GdkColor* url_color,
const std::string& prefix_text);
virtual void Show(size_t num_results);
virtual void Hide();
// Restack the popup window directly above the browser's toplevel window.
void StackWindow();
// Accept a line of the results, for example, when the user clicks a line.
void AcceptLine(size_t line, WindowOpenDisposition disposition);
// Returns the appropriate icon to display beside |match|.
gfx::Image IconForMatch(const AutocompleteMatch& match,
bool selected,
bool is_selected_keyword);
// Returns the |index|th element of match, unless we're selected and showing
// the associated keyword match.
void GetVisibleMatchForInput(size_t index,
const AutocompleteMatch** match,
bool* is_selected_keyword);
CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleMotion,
GdkEventMotion*);
CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonPress,
GdkEventButton*);
CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleButtonRelease,
GdkEventButton*);
CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleExpose,
GdkEventExpose*);
scoped_ptr<OmniboxPopupModel> model_;
OmniboxView* omnibox_view_;
GtkWidget* location_bar_;
// Our popup window, which is the only widget used, and we paint it on our
// own. This widget shouldn't be exposed outside of this class.
GtkWidget* window_;
// The pango layout object created from the window, cached across exposes.
PangoLayout* layout_;
GtkThemeService* theme_service_;
content::NotificationRegistrar registrar_;
// Font used for suggestions after being derived from the constructor's
// |font|.
gfx::Font font_;
// A list of colors which we should use for drawing the popup. These change
// between gtk and normal mode.
GdkColor border_color_;
GdkColor background_color_;
GdkColor selected_background_color_;
GdkColor hovered_background_color_;
GdkColor content_text_color_;
GdkColor selected_content_text_color_;
GdkColor content_dim_text_color_;
GdkColor selected_content_dim_text_color_;
GdkColor url_text_color_;
GdkColor url_selected_text_color_;
// If the user cancels a dragging action (i.e. by pressing ESC), we don't have
// a convenient way to release mouse capture. Instead we use this flag to
// simply ignore all remaining drag events, and the eventual mouse release
// event. Since OnDragCanceled() can be called when we're not dragging, this
// flag is reset to false on a mouse pressed event, to make sure we don't
// erroneously ignore the next drag.
bool ignore_mouse_drag_;
// Whether our popup is currently open / shown, or closed / hidden.
bool opened_;
DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewGtk);
};
#endif // CHROME_BROWSER_UI_GTK_OMNIBOX_OMNIBOX_POPUP_VIEW_GTK_H_
|