Use unified build for UIProcess
[WebKit-https.git] / Source / WebKit / UIProcess / gtk / WebPopupMenuProxyGtk.h
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
28 typedef struct _GMainLoop GMainLoop;
29 typedef struct _GdkDevice GdkDevice;
30 typedef struct _GdkEventButton GdkEventButton;
31 typedef struct _GdkEventKey GdkEventKey;
32 typedef struct _GtkTreePath GtkTreePath;
33 typedef struct _GtkTreeView GtkTreeView;
34 typedef struct _GtkTreeViewColumn GtkTreeViewColumn;
35
36 namespace WebCore {
37 class IntRect;
38 }
39
40 namespace WebKit {
41
42 class WebPageProxy;
43
44 class WebPopupMenuProxyGtk : public WebPopupMenuProxy {
45 public:
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(std::optional<unsigned> itemIndex);
58
59 protected:
60     WebPopupMenuProxyGtk(GtkWidget*, WebPopupMenuProxy::Client&);
61
62     GtkWidget* m_webView { nullptr };
63
64 private:
65     void createPopupMenu(const Vector<WebPopupItem>&, int32_t selectedIndex);
66     void show();
67     bool activateItemAtPath(GtkTreePath*);
68     std::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     std::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