1/*
2 * Copyright (C) 2011 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#pragma once
21
22#include "WebPopupMenuProxy.h"
23#include <WebCore/GUniquePtrGtk.h>
24#include <wtf/Vector.h>
25#include <wtf/glib/GRefPtr.h>
26#include <wtf/text/WTFString.h>
27
28typedef struct _GMainLoop GMainLoop;
29typedef struct _GdkDevice GdkDevice;
30typedef struct _GdkEventButton GdkEventButton;
31typedef struct _GdkEventKey GdkEventKey;
32typedef struct _GtkTreePath GtkTreePath;
33typedef struct _GtkTreeView GtkTreeView;
34typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
35
36namespace WebCore {
37class IntRect;
38}
39
40namespace WebKit {
41
42class WebPageProxy;
43
44class WebPopupMenuProxyGtk : public WebPopupMenuProxy {
45public:
46 static Ref<WebPopupMenuProxyGtk> create(GtkWidget* webView, WebPopupMenuProxy::Client& client)
47 {
48 return adoptRef(*new WebPopupMenuProxyGtk(webView, client));
49 }
50 ~WebPopupMenuProxyGtk();
51
52 void showPopupMenu(const WebCore::IntRect&, WebCore::TextDirection, double pageScaleFactor, const Vector<WebPopupItem>&, const PlatformPopupMenuData&, int32_t selectedIndex) override;
53 void hidePopupMenu() override;
54 void cancelTracking() override;
55
56 virtual void selectItem(unsigned itemIndex);
57 virtual void activateItem(Optional<unsigned> itemIndex);
58
59protected:
60 WebPopupMenuProxyGtk(GtkWidget*, WebPopupMenuProxy::Client&);
61
62 GtkWidget* m_webView { nullptr };
63
64private:
65 void createPopupMenu(const Vector<WebPopupItem>&, int32_t selectedIndex);
66 void show();
67 bool activateItemAtPath(GtkTreePath*);
68 Optional<unsigned> typeAheadFindIndex(GdkEventKey*);
69 bool typeAheadFind(GdkEventKey*);
70
71 static gboolean buttonPressEventCallback(GtkWidget*, GdkEventButton*, WebPopupMenuProxyGtk*);
72 static gboolean keyPressEventCallback(GtkWidget*, GdkEventKey*, WebPopupMenuProxyGtk*);
73 static void treeViewRowActivatedCallback(GtkTreeView*, GtkTreePath*, GtkTreeViewColumn*, WebPopupMenuProxyGtk*);
74 static gboolean treeViewButtonReleaseEventCallback(GtkWidget*, GdkEventButton*, WebPopupMenuProxyGtk*);
75
76 GtkWidget* m_popup { nullptr };
77 GtkWidget* m_treeView { nullptr };
78 GdkDevice* m_device { nullptr };
79
80 Vector<GUniquePtr<GtkTreePath>> m_paths;
81 Optional<unsigned> m_selectedItem;
82
83 // Typeahead find.
84 gunichar m_repeatingCharacter { '\0' };
85 uint32_t m_previousKeyEventTime { 0 };
86 GString* m_currentSearchString { nullptr };
87};
88
89} // namespace WebKit
90