[GTK] Use XDamage to simplify RedirectedXCompositeWindow
[WebKit-https.git] / Source / WebKit2 / 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 "NotImplemented.h"
32 #include "WebEvent.h"
33 #include "WebPageAccessibilityObject.h"
34 #include "WebPageProxyMessages.h"
35 #include "WindowsKeyboardCodes.h"
36 #include <WebCore/FocusController.h>
37 #include <WebCore/Frame.h>
38 #include <WebCore/KeyboardEvent.h>
39 #include <WebCore/Page.h>
40 #include <WebCore/PasteboardHelper.h>
41 #include <WebCore/PlatformKeyboardEvent.h>
42 #include <WebCore/Settings.h>
43 #include <wtf/gobject/GOwnPtr.h>
44
45 using namespace WebCore;
46
47 namespace WebKit {
48
49 void WebPage::platformInitialize()
50 {
51     // Create the accessible object (the plug) that will serve as the
52     // entry point to the Web process, and send a message to the UI
53     // process to connect the two worlds through the accessibility
54     // object there specifically placed for that purpose (the socket).
55     m_accessibilityObject = webPageAccessibilityObjectNew(this);
56     GOwnPtr<gchar> plugID(atk_plug_get_id(ATK_PLUG(m_accessibilityObject)));
57     send(Messages::WebPageProxy::BindAccessibilityTree(String(plugID.get())));
58
59 #if USE(TEXTURE_MAPPER_GL)
60     m_nativeWindowHandle = 0;
61 #endif
62 }
63
64 void WebPage::updateAccessibilityTree()
65 {
66     if (!m_accessibilityObject)
67         return;
68
69     webPageAccessibilityObjectRefresh(m_accessibilityObject);
70 }
71
72 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
73 {
74     notImplemented();
75 }
76
77 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
78 {
79     page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
80 }
81
82 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
83 {
84     if (keyboardEvent.type() != WebEvent::KeyDown && keyboardEvent.type() != WebEvent::RawKeyDown)
85         return false;
86
87     switch (keyboardEvent.windowsVirtualKeyCode()) {
88     case VK_BACK:
89         if (keyboardEvent.shiftKey())
90             m_page->goForward();
91         else
92             m_page->goBack();
93         break;
94     case VK_SPACE:
95         scroll(m_page.get(), keyboardEvent.shiftKey() ? ScrollUp : ScrollDown, ScrollByPage);
96         break;
97     case VK_LEFT:
98         scroll(m_page.get(), ScrollLeft, ScrollByLine);
99         break;
100     case VK_RIGHT:
101         scroll(m_page.get(), ScrollRight, ScrollByLine);
102         break;
103     case VK_UP:
104         scroll(m_page.get(), ScrollUp, ScrollByLine);
105         break;
106     case VK_DOWN:
107         scroll(m_page.get(), ScrollDown, ScrollByLine);
108         break;
109     case VK_HOME:
110         scroll(m_page.get(), ScrollUp, ScrollByDocument);
111         break;
112     case VK_END:
113         scroll(m_page.get(), ScrollDown, ScrollByDocument);
114         break;
115     case VK_PRIOR:
116         scroll(m_page.get(), ScrollUp, ScrollByPage);
117         break;
118     case VK_NEXT:
119         scroll(m_page.get(), ScrollDown, ScrollByPage);
120         break;
121     default:
122         return false;
123     }
124
125     return true;
126 }
127
128 bool WebPage::platformHasLocalDataForURL(const KURL&)
129 {
130     notImplemented();
131     return false;
132 }
133
134 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
135 {
136     notImplemented();
137     return String();
138 }
139
140 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
141 {
142     notImplemented();
143     return true;
144 }
145
146 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
147 {
148     notImplemented();
149     return String();
150 }
151
152 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
153 {
154     notImplemented();
155     return 0;
156 }
157
158 #if USE(TEXTURE_MAPPER_GL)
159 void WebPage::setAcceleratedCompositingWindowId(int64_t nativeWindowHandle)
160 {
161     m_nativeWindowHandle = nativeWindowHandle;
162 }
163 #endif
164
165 bool WebPage::handleMousePressedEvent(const PlatformMouseEvent& platformMouseEvent)
166 {
167     bool returnValue = false;
168     if (platformMouseEvent.button() != WebCore::MiddleButton)
169         return returnValue;
170
171 #if PLATFORM(X11)
172     Frame* frame = m_page->focusController()->focusedOrMainFrame();
173     if (!frame)
174         return returnValue;
175
176     PasteboardHelper* pasteboardHelper = PasteboardHelper::defaultPasteboardHelper();
177     bool wasUsingPrimary = pasteboardHelper->usePrimarySelectionClipboard();
178     pasteboardHelper->setUsePrimarySelectionClipboard(true);
179
180     Editor* editor = frame->editor();
181     returnValue = editor->canPaste() || editor->canDHTMLPaste();
182     editor->paste();
183
184     pasteboardHelper->setUsePrimarySelectionClipboard(wasUsingPrimary);
185 #endif
186
187     return returnValue;
188 }
189
190 } // namespace WebKit