[WPE][GTK] Bump minimum versions of GLib, GTK, libsoup, ATK, GStreamer, and Cairo
[WebKit-https.git] / Source / WebKit / WebProcess / WebPage / gtk / WebPageGtk.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4  * Copyright (C) 2011 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "WebPage.h"
30
31 #include "EditorState.h"
32 #include "WebEvent.h"
33 #include "WebFrame.h"
34 #include "WebKitWebPageAccessibilityObject.h"
35 #include "WebPageProxyMessages.h"
36 #include "WebProcess.h"
37 #include <WebCore/BackForwardController.h>
38 #include <WebCore/Editor.h>
39 #include <WebCore/EventHandler.h>
40 #include <WebCore/FocusController.h>
41 #include <WebCore/Frame.h>
42 #include <WebCore/FrameView.h>
43 #include <WebCore/KeyboardEvent.h>
44 #include <WebCore/NotImplemented.h>
45 #include <WebCore/Page.h>
46 #include <WebCore/PasteboardHelper.h>
47 #include <WebCore/PlatformKeyboardEvent.h>
48 #include <WebCore/Settings.h>
49 #include <WebCore/SharedBuffer.h>
50 #include <WebCore/UserAgent.h>
51 #include <WebCore/WindowsKeyboardCodes.h>
52 #include <gtk/gtk.h>
53 #include <wtf/glib/GUniquePtr.h>
54
55 namespace WebKit {
56 using namespace WebCore;
57
58 void WebPage::platformInitialize()
59 {
60 #if HAVE(ACCESSIBILITY)
61     // Create the accessible object (the plug) that will serve as the
62     // entry point to the Web process, and send a message to the UI
63     // process to connect the two worlds through the accessibility
64     // object there specifically placed for that purpose (the socket).
65     m_accessibilityObject = adoptGRef(webkitWebPageAccessibilityObjectNew(this));
66     GUniquePtr<gchar> plugID(atk_plug_get_id(ATK_PLUG(m_accessibilityObject.get())));
67     send(Messages::WebPageProxy::BindAccessibilityTree(String(plugID.get())));
68 #endif
69 }
70
71 void WebPage::platformReinitialize()
72 {
73 }
74
75 void WebPage::platformDetach()
76 {
77 }
78
79 void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePostLayoutDataHint shouldIncludePostLayoutData) const
80 {
81     if (shouldIncludePostLayoutData == IncludePostLayoutDataHint::No || !frame.view() || frame.view()->needsLayout()) {
82         result.isMissingPostLayoutData = true;
83         return;
84     }
85
86     auto& postLayoutData = result.postLayoutData();
87     postLayoutData.caretRectAtStart = frame.selection().absoluteCaretBounds();
88
89     const VisibleSelection& selection = frame.selection().selection();
90     if (selection.isNone())
91         return;
92
93     const Editor& editor = frame.editor();
94     if (selection.isRange()) {
95         if (editor.selectionHasStyle(CSSPropertyFontWeight, "bold") == TrueTriState)
96             postLayoutData.typingAttributes |= AttributeBold;
97         if (editor.selectionHasStyle(CSSPropertyFontStyle, "italic") == TrueTriState)
98             postLayoutData.typingAttributes |= AttributeItalics;
99         if (editor.selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline") == TrueTriState)
100             postLayoutData.typingAttributes |= AttributeUnderline;
101         if (editor.selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "line-through") == TrueTriState)
102             postLayoutData.typingAttributes |= AttributeStrikeThrough;
103     } else if (selection.isCaret()) {
104         if (editor.selectionStartHasStyle(CSSPropertyFontWeight, "bold"))
105             postLayoutData.typingAttributes |= AttributeBold;
106         if (editor.selectionStartHasStyle(CSSPropertyFontStyle, "italic"))
107             postLayoutData.typingAttributes |= AttributeItalics;
108         if (editor.selectionStartHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline"))
109             postLayoutData.typingAttributes |= AttributeUnderline;
110         if (editor.selectionStartHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "line-through"))
111             postLayoutData.typingAttributes |= AttributeStrikeThrough;
112     }
113 }
114
115 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
116 {
117     if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown)
118         return false;
119
120     switch (keyboardEvent.windowsVirtualKeyCode()) {
121     case VK_SPACE:
122         scroll(m_page.get(), keyboardEvent.shiftKey() ? ScrollUp : ScrollDown, ScrollByPage);
123         break;
124     case VK_LEFT:
125         scroll(m_page.get(), ScrollLeft, ScrollByLine);
126         break;
127     case VK_RIGHT:
128         scroll(m_page.get(), ScrollRight, ScrollByLine);
129         break;
130     case VK_UP:
131         scroll(m_page.get(), ScrollUp, ScrollByLine);
132         break;
133     case VK_DOWN:
134         scroll(m_page.get(), ScrollDown, ScrollByLine);
135         break;
136     case VK_HOME:
137         scroll(m_page.get(), ScrollUp, ScrollByDocument);
138         break;
139     case VK_END:
140         scroll(m_page.get(), ScrollDown, ScrollByDocument);
141         break;
142     case VK_PRIOR:
143         scroll(m_page.get(), ScrollUp, ScrollByPage);
144         break;
145     case VK_NEXT:
146         scroll(m_page.get(), ScrollDown, ScrollByPage);
147         break;
148     default:
149         return false;
150     }
151
152     return true;
153 }
154
155 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
156 {
157     notImplemented();
158     return false;
159 }
160
161 String WebPage::platformUserAgent(const URL& url) const
162 {
163     if (url.isNull() || !m_page->settings().needsSiteSpecificQuirks())
164         return String();
165
166     return WebCore::standardUserAgentForURL(url);
167 }
168
169 void WebPage::getCenterForZoomGesture(const IntPoint& centerInViewCoordinates, CompletionHandler<void(WebCore::IntPoint&&)>&& completionHandler)
170 {
171     IntPoint result = mainFrameView()->rootViewToContents(centerInViewCoordinates);
172     double scale = m_page->pageScaleFactor();
173     result.scale(1 / scale, 1 / scale);
174     completionHandler(WTFMove(result));
175 }
176
177 void WebPage::setInputMethodState(bool enabled)
178 {
179     if (m_inputMethodEnabled == enabled)
180         return;
181
182     m_inputMethodEnabled = enabled;
183     send(Messages::WebPageProxy::SetInputMethodState(enabled));
184 }
185
186 void WebPage::collapseSelectionInFrame(uint64_t frameID)
187 {
188     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
189     if (!frame || !frame->coreFrame())
190         return;
191
192     // Collapse the selection without clearing it.
193     const VisibleSelection& selection = frame->coreFrame()->selection().selection();
194     frame->coreFrame()->selection().setBase(selection.extent(), selection.affinity());
195 }
196
197 void WebPage::showEmojiPicker(Frame& frame)
198 {
199     CompletionHandler<void(String)> completionHandler = [frame = makeRef(frame)](String result) {
200         if (!result.isEmpty())
201             frame->editor().insertText(result, nullptr);
202     };
203     sendWithAsyncReply(Messages::WebPageProxy::ShowEmojiPicker(frame.selection().absoluteCaretBounds()), WTFMove(completionHandler));
204 }
205
206 void WebPage::effectiveAppearanceDidChange(bool useDarkAppearance, bool useInactiveAppearance)
207 {
208     if (auto* settings = gtk_settings_get_default())
209         g_object_set(settings, "gtk-application-prefer-dark-theme", useDarkAppearance, nullptr);
210     corePage()->effectiveAppearanceDidChange(useDarkAppearance, useInactiveAppearance);
211 }
212
213 } // namespace WebKit