summaryrefslogtreecommitdiffstats
path: root/Source/WebKit2/UIProcess/gtk
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2011-05-24 11:24:40 +0100
committerBen Murdoch <benm@google.com>2011-06-02 09:53:15 +0100
commit81bc750723a18f21cd17d1b173cd2a4dda9cea6e (patch)
tree7a9e5ed86ff429fd347a25153107221543909b19 /Source/WebKit2/UIProcess/gtk
parent94088a6d336c1dd80a1e734af51e96abcbb689a7 (diff)
downloadexternal_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.zip
external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.gz
external_webkit-81bc750723a18f21cd17d1b173cd2a4dda9cea6e.tar.bz2
Merge WebKit at r80534: Intial merge by Git
Change-Id: Ia7a83357124c9e1cdb1debf55d9661ec0bd09a61
Diffstat (limited to 'Source/WebKit2/UIProcess/gtk')
-rw-r--r--Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp7
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp49
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp9
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp2
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp2
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebView.cpp297
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebView.h122
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebViewWidget.cpp377
-rw-r--r--Source/WebKit2/UIProcess/gtk/WebViewWidget.h70
9 files changed, 929 insertions, 6 deletions
diff --git a/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp b/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp
index 711783a..6a6715a 100644
--- a/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp
+++ b/Source/WebKit2/UIProcess/gtk/TextCheckerGtk.cpp
@@ -27,8 +27,8 @@
#include "config.h"
#include "TextChecker.h"
-#include "NotImplemented.h"
#include "TextCheckerState.h"
+#include <WebCore/NotImplemented.h>
using namespace WebCore;
@@ -80,6 +80,11 @@ void TextChecker::updateSpellingUIWithMisspelledWord(const String& misspelledWor
notImplemented();
}
+void TextChecker::updateSpellingUIWithGrammarString(const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
+{
+ notImplemented();
+}
+
void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses)
{
notImplemented();
diff --git a/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp
new file mode 100644
index 0000000..d67726c
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebContextGtk.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebContext.h"
+
+#include "ApplicationCacheStorage.h"
+#include "NotImplemented.h"
+
+namespace WebKit {
+
+WTF::String WebContext::applicationCacheDirectory()
+{
+ return WebCore::cacheStorage().cacheDirectory();
+}
+
+void WebContext::platformInitializeWebProcess(WebProcessCreationParameters&)
+{
+}
+
+String WebContext::platformDefaultDatabaseDirectory() const
+{
+ return WTF::String::fromUTF8(g_build_filename(g_get_user_data_dir(), "webkit", "databases", NULL));
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp
index 8d6b515..ee12bac 100644
--- a/Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp
+++ b/Source/WebKit2/UIProcess/gtk/WebInspectorGtk.cpp
@@ -29,11 +29,9 @@
#if ENABLE(INSPECTOR)
+#include <WebCore/NotImplemented.h>
#include <wtf/text/WTFString.h>
-#define DISABLE_NOT_IMPLEMENTED_WARNINGS 1
-#include "NotImplemented.h"
-
namespace WebKit {
WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
@@ -52,6 +50,11 @@ void WebInspectorProxy::platformClose()
notImplemented();
}
+void WebInspectorProxy::platformInspectedURLChanged(const String&)
+{
+ notImplemented();
+}
+
String WebInspectorProxy::inspectorPageURL() const
{
notImplemented();
diff --git a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
index a36bd0c..838de97 100644
--- a/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
+++ b/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
@@ -32,7 +32,7 @@ namespace WebKit {
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
// FIXME: This should not be hard coded.
- return "Mozilla/5.0 (X11; U; Linux i686; en-us) AppleWebKit/534.7 (KHTML, like Gecko) Version/5.0 Safari/534.7";
+ return "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.7 (KHTML, like Gecko) Version/5.0 Safari/534.7";
}
} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp b/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp
index f7caee8..c698204 100644
--- a/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp
+++ b/Source/WebKit2/UIProcess/gtk/WebPreferencesGtk.cpp
@@ -27,7 +27,7 @@
#include "config.h"
#include "WebPreferences.h"
-#include "NotImplemented.h"
+#include <WebCore/NotImplemented.h>
namespace WebKit {
diff --git a/Source/WebKit2/UIProcess/gtk/WebView.cpp b/Source/WebKit2/UIProcess/gtk/WebView.cpp
new file mode 100644
index 0000000..5063922
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebView.cpp
@@ -0,0 +1,297 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebView.h"
+
+#include "ChunkedUpdateDrawingAreaProxy.h"
+#include "NativeWebKeyboardEvent.h"
+#include "NotImplemented.h"
+#include "WebContext.h"
+#include "WebContextMenuProxy.h"
+#include "WebEventFactory.h"
+#include "WebViewWidget.h"
+#include "WebPageProxy.h"
+#include <wtf/text/WTFString.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+
+void WebView::handleFocusInEvent(GtkWidget* widget)
+{
+ if (!(m_isPageActive)) {
+ m_isPageActive = true;
+ m_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
+ }
+
+ m_page->viewStateDidChange(WebPageProxy::ViewIsFocused);
+}
+
+void WebView::handleFocusOutEvent(GtkWidget* widget)
+{
+ m_isPageActive = false;
+ m_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive);
+}
+
+WebView::WebView(WebContext* context, WebPageGroup* pageGroup)
+ : m_isPageActive(true)
+{
+ m_page = context->createWebPage(this, pageGroup);
+
+ m_viewWidget = static_cast<GtkWidget*>(g_object_new(WEB_VIEW_TYPE_WIDGET, NULL));
+ ASSERT(m_viewWidget);
+
+ m_page->initializeWebPage();
+
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(m_viewWidget);
+ webViewWidgetSetWebViewInstance(webViewWidget, this);
+}
+
+WebView::~WebView()
+{
+}
+
+GdkWindow* WebView::getWebViewWindow()
+{
+ return gtk_widget_get_window(m_viewWidget);
+}
+
+void WebView::paint(GtkWidget* widget, GdkRectangle rect, cairo_t* cr)
+{
+ m_page->drawingArea()->paint(IntRect(rect), cr);
+}
+
+void WebView::setSize(GtkWidget*, IntSize windowSize)
+{
+ m_page->drawingArea()->setSize(windowSize, IntSize());
+}
+
+void WebView::handleKeyboardEvent(GdkEventKey* event)
+{
+ m_page->handleKeyboardEvent(NativeWebKeyboardEvent(reinterpret_cast<GdkEvent*>(event)));
+}
+
+void WebView::handleMouseEvent(GdkEvent* event, int currentClickCount)
+{
+ m_page->handleMouseEvent(WebEventFactory::createWebMouseEvent(event, currentClickCount));
+}
+
+void WebView::handleWheelEvent(GdkEventScroll* event)
+{
+ m_page->handleWheelEvent(WebEventFactory::createWebWheelEvent(event));
+}
+
+bool WebView::isActive()
+{
+ return m_isPageActive;
+}
+
+void WebView::close()
+{
+ m_page->close();
+}
+
+// PageClient's pure virtual functions
+PassOwnPtr<DrawingAreaProxy> WebView::createDrawingAreaProxy()
+{
+ return ChunkedUpdateDrawingAreaProxy::create(this, m_page.get());
+}
+
+void WebView::setViewNeedsDisplay(const WebCore::IntRect&)
+{
+ notImplemented();
+}
+
+void WebView::displayView()
+{
+ notImplemented();
+}
+
+void WebView::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset)
+{
+ notImplemented();
+}
+
+WebCore::IntSize WebView::viewSize()
+{
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(m_viewWidget, &allocation);
+ return IntSize(allocation.width, allocation.height);
+}
+
+bool WebView::isViewWindowActive()
+{
+ notImplemented();
+ return true;
+}
+
+bool WebView::isViewFocused()
+{
+ notImplemented();
+ return true;
+}
+
+bool WebView::isViewVisible()
+{
+ notImplemented();
+ return true;
+}
+
+bool WebView::isViewInWindow()
+{
+ notImplemented();
+ return true;
+}
+
+void WebView::WebView::processDidCrash()
+{
+ notImplemented();
+}
+
+void WebView::didRelaunchProcess()
+{
+ notImplemented();
+}
+
+void WebView::takeFocus(bool)
+{
+ notImplemented();
+}
+
+void WebView::toolTipChanged(const String&, const String&)
+{
+ notImplemented();
+}
+
+void WebView::setCursor(const Cursor&)
+{
+ notImplemented();
+}
+
+void WebView::setViewportArguments(const WebCore::ViewportArguments&)
+{
+ notImplemented();
+}
+
+void WebView::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo)
+{
+ notImplemented();
+}
+
+void WebView::clearAllEditCommands()
+{
+ notImplemented();
+}
+
+FloatRect WebView::convertToDeviceSpace(const FloatRect& viewRect)
+{
+ notImplemented();
+ return viewRect;
+}
+
+FloatRect WebView::convertToUserSpace(const FloatRect& viewRect)
+{
+ notImplemented();
+ return viewRect;
+}
+
+void WebView::doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled)
+{
+ notImplemented();
+}
+
+void WebView::didNotHandleKeyEvent(const NativeWebKeyboardEvent& event)
+{
+ notImplemented();
+}
+
+PassRefPtr<WebPopupMenuProxy> WebView::createPopupMenuProxy(WebPageProxy*)
+{
+ notImplemented();
+ return 0;
+}
+
+PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy*)
+{
+ notImplemented();
+ return 0;
+}
+
+void WebView::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)
+{
+ notImplemented();
+}
+
+#if USE(ACCELERATED_COMPOSITING)
+void WebView::pageDidEnterAcceleratedCompositing()
+{
+ notImplemented();
+}
+
+void WebView::pageDidLeaveAcceleratedCompositing()
+{
+ notImplemented();
+}
+#endif // USE(ACCELERATED_COMPOSITING)
+
+void WebView::didCommitLoadForMainFrame(bool useCustomRepresentation)
+{
+}
+
+void WebView::didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&)
+{
+}
+
+double WebView::customRepresentationZoomFactor()
+{
+ notImplemented();
+ return 0;
+}
+
+void WebView::setCustomRepresentationZoomFactor(double)
+{
+ notImplemented();
+}
+
+void WebView::pageClosed()
+{
+ notImplemented();
+}
+
+void WebView::didChangeScrollbarsForMainFrame() const
+{
+}
+
+void WebView::flashBackingStoreUpdates(const Vector<IntRect>&)
+{
+ notImplemented();
+}
+
+
+} // namespace WebKit
diff --git a/Source/WebKit2/UIProcess/gtk/WebView.h b/Source/WebKit2/UIProcess/gtk/WebView.h
new file mode 100644
index 0000000..256dc04
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebView.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebView_h
+#define WebView_h
+
+#include "PageClient.h"
+#include "WebPageProxy.h"
+#include <WebCore/IntSize.h>
+#include <gdk/gdk.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebKit {
+
+class DrawingAreaProxy;
+class WebPageNamespace;
+
+class WebView : public RefCounted<WebView>, public PageClient {
+public:
+ ~WebView();
+ static PassRefPtr<WebView> create(WebContext* context, WebPageGroup* pageGroup)
+ {
+ return adoptRef(new WebView(context, pageGroup));
+ }
+
+ GtkWidget* window() const { return m_viewWidget; }
+
+ WebPageProxy* page() const { return m_page.get(); }
+
+ void handleFocusInEvent(GtkWidget*);
+ void handleFocusOutEvent(GtkWidget*);
+
+ void paint(GtkWidget*, GdkRectangle, cairo_t*);
+ void setSize(GtkWidget*, WebCore::IntSize);
+ void handleKeyboardEvent(GdkEventKey*);
+ void handleWheelEvent(GdkEventScroll*);
+ void handleMouseEvent(GdkEvent*, int);
+
+private:
+ WebView(WebContext*, WebPageGroup*);
+
+ GdkWindow* getWebViewWindow();
+
+ bool isActive();
+ void close();
+
+ // PageClient
+ virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
+ virtual void setViewNeedsDisplay(const WebCore::IntRect&);
+ virtual void displayView();
+ virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
+ virtual WebCore::IntSize viewSize();
+ virtual bool isViewWindowActive();
+ virtual bool isViewFocused();
+ virtual bool isViewVisible();
+ virtual bool isViewInWindow();
+ virtual void processDidCrash();
+ virtual void didRelaunchProcess();
+ virtual void pageClosed();
+ virtual void takeFocus(bool direction);
+ virtual void toolTipChanged(const WTF::String&, const WTF::String&);
+ virtual void setCursor(const WebCore::Cursor&);
+ virtual void setViewportArguments(const WebCore::ViewportArguments&);
+ virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
+ virtual void clearAllEditCommands();
+ virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
+ virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
+ virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled);
+ virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
+ virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*);
+ virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
+ virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
+ virtual void didChangeScrollbarsForMainFrame() const;
+ virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
+
+#if USE(ACCELERATED_COMPOSITING)
+ virtual void pageDidEnterAcceleratedCompositing();
+ virtual void pageDidLeaveAcceleratedCompositing();
+#endif
+
+ virtual void didCommitLoadForMainFrame(bool useCustomRepresentation);
+ virtual void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&);
+ virtual double customRepresentationZoomFactor();
+ virtual void setCustomRepresentationZoomFactor(double);
+
+ // Members of WebView class
+ GtkWidget* m_viewWidget;
+ bool m_isPageActive;
+ RefPtr<WebPageProxy> m_page;
+};
+
+} // namespace WebKit
+
+#endif // WebView_h
diff --git a/Source/WebKit2/UIProcess/gtk/WebViewWidget.cpp b/Source/WebKit2/UIProcess/gtk/WebViewWidget.cpp
new file mode 100644
index 0000000..dfdd3b2
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebViewWidget.cpp
@@ -0,0 +1,377 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebViewWidget.h"
+
+#include "GOwnPtrGtk.h"
+#include "GtkVersioning.h"
+#include "NotImplemented.h"
+#include "RefPtrCairo.h"
+
+using namespace WebKit;
+using namespace WebCore;
+
+static gpointer webViewWidgetParentClass = 0;
+
+struct _WebViewWidgetPrivate {
+ WebView* webViewInstance;
+ GtkIMContext* imContext;
+ gint currentClickCount;
+ IntPoint previousClickPoint;
+ guint previousClickButton;
+ guint32 previousClickTime;
+};
+
+static void webViewWidgetRealize(GtkWidget* widget)
+{
+ gtk_widget_set_realized(widget, TRUE);
+
+ GtkAllocation allocation;
+ gtk_widget_get_allocation(widget, &allocation);
+
+ GdkWindowAttr attributes;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual(widget);
+#ifdef GTK_API_VERSION_2
+ attributes.colormap = gtk_widget_get_colormap(widget);
+#endif
+ attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_POINTER_MOTION_MASK
+ | GDK_KEY_PRESS_MASK
+ | GDK_KEY_RELEASE_MASK
+ | GDK_BUTTON_MOTION_MASK
+ | GDK_BUTTON1_MOTION_MASK
+ | GDK_BUTTON2_MOTION_MASK
+ | GDK_BUTTON3_MOTION_MASK;
+
+ gint attributesMask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+#ifdef GTK_API_VERSION_2
+ attributesMask |= GDK_WA_COLORMAP;
+#endif
+ GdkWindow* window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributesMask);
+ gtk_widget_set_window(widget, window);
+ gdk_window_set_user_data(window, widget);
+
+#ifdef GTK_API_VERSION_2
+#if GTK_CHECK_VERSION(2, 20, 0)
+ gtk_widget_style_attach(widget);
+#else
+ widget->style = gtk_style_attach(gtk_widget_get_style(widget), window);
+#endif
+ gtk_style_set_background(gtk_widget_get_style(widget), window, GTK_STATE_NORMAL);
+#else
+ gtk_style_context_set_background(gtk_widget_get_style_context(widget), window);
+#endif
+
+ WebViewWidget* webView = WEB_VIEW_WIDGET(widget);
+ WebViewWidgetPrivate* priv = webView->priv;
+ gtk_im_context_set_client_window(priv->imContext, window);
+}
+
+static void webViewWidgetContainerAdd(GtkContainer* container, GtkWidget* widget)
+{
+ gtk_widget_set_parent(widget, GTK_WIDGET(container));
+}
+
+static void webViewWidgetDispose(GObject* gobject)
+{
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(gobject);
+ WebViewWidgetPrivate* priv = webViewWidget->priv;
+
+ if (priv->imContext) {
+ g_object_unref(priv->imContext);
+ priv->imContext = 0;
+ }
+
+ G_OBJECT_CLASS(webViewWidgetParentClass)->dispose(gobject);
+}
+
+static void webViewWidgetInit(WebViewWidget* webViewWidget)
+{
+ WebViewWidgetPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(webViewWidget, WEB_VIEW_TYPE_WIDGET, WebViewWidgetPrivate);
+ webViewWidget->priv = priv;
+
+ gtk_widget_set_can_focus(GTK_WIDGET(webViewWidget), TRUE);
+ priv->imContext = gtk_im_multicontext_new();
+
+ priv->currentClickCount = 0;
+ priv->previousClickButton = 0;
+ priv->previousClickTime = 0;
+}
+
+#ifdef GTK_API_VERSION_2
+static gboolean webViewExpose(GtkWidget* widget, GdkEventExpose* event)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ GdkRectangle clipRect;
+ gdk_region_get_clipbox(event->region, &clipRect);
+
+ GdkWindow* window = gtk_widget_get_window(widget);
+ RefPtr<cairo_t> cr = adoptRef(gdk_cairo_create(window));
+
+ webView->paint(widget, clipRect, cr.get());
+
+ return FALSE;
+}
+#else
+static gboolean webViewDraw(GtkWidget* widget, cairo_t* cr)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ GdkRectangle clipRect;
+
+ if (!gdk_cairo_get_clip_rectangle(cr, &clipRect))
+ return FALSE;
+
+ webView->paint(widget, clipRect, cr);
+
+ return FALSE;
+}
+#endif
+
+static void webViewSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ GTK_WIDGET_CLASS(webViewWidgetParentClass)->size_allocate(widget, allocation);
+ webView->setSize(widget, IntSize(allocation->width, allocation->height));
+}
+
+static gboolean webViewFocusInEvent(GtkWidget* widget, GdkEventFocus* event)
+{
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(widget);
+ WebView* webView = webViewWidgetGetWebViewInstance(webViewWidget);
+
+ GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
+ if (gtk_widget_is_toplevel(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
+ gtk_im_context_focus_in(webViewWidgetGetIMContext(webViewWidget));
+ webView->handleFocusInEvent(widget);
+ }
+
+ return GTK_WIDGET_CLASS(webViewWidgetParentClass)->focus_in_event(widget, event);
+}
+
+static gboolean webViewFocusOutEvent(GtkWidget* widget, GdkEventFocus* event)
+{
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(widget);
+ WebView* webView = webViewWidgetGetWebViewInstance(webViewWidget);
+
+ webView->handleFocusOutEvent(widget);
+ GtkIMContext* imContext = webViewWidgetGetIMContext(webViewWidget);
+ if (imContext)
+ gtk_im_context_focus_out(imContext);
+
+ return GTK_WIDGET_CLASS(webViewWidgetParentClass)->focus_out_event(widget, event);
+}
+
+static gboolean webViewKeyPressEvent(GtkWidget* widget, GdkEventKey* event)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ webView->handleKeyboardEvent(event);
+
+ return GTK_WIDGET_CLASS(webViewWidgetParentClass)->key_press_event(widget, event);
+}
+
+static gboolean webViewKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event)
+{
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(widget);
+ WebView* webView = webViewWidgetGetWebViewInstance(webViewWidget);
+
+ if (gtk_im_context_filter_keypress(webViewWidgetGetIMContext(webViewWidget), event))
+ return TRUE;
+
+ webView->handleKeyboardEvent(event);
+
+ return GTK_WIDGET_CLASS(webViewWidgetParentClass)->key_release_event(widget, event);
+}
+
+// Copied from webkitwebview.cpp
+static guint32 getEventTime(GdkEvent* event)
+{
+ guint32 time = gdk_event_get_time(event);
+ if (time)
+ return time;
+
+ // Real events always have a non-zero time, but events synthesized
+ // by the DRT do not and we must calculate a time manually. This time
+ // is not calculated in the DRT, because GTK+ does not work well with
+ // anything other than GDK_CURRENT_TIME on synthesized events.
+ GTimeVal timeValue;
+ g_get_current_time(&timeValue);
+ return (timeValue.tv_sec * 1000) + (timeValue.tv_usec / 1000);
+}
+
+static gboolean webViewButtonPressEvent(GtkWidget* widget, GdkEventButton* buttonEvent)
+{
+ if (buttonEvent->button == 3) {
+ // FIXME: [GTK] Add context menu support for Webkit2.
+ // https://bugs.webkit.org/show_bug.cgi?id=54827
+ notImplemented();
+ return FALSE;
+ }
+
+ gtk_widget_grab_focus(widget);
+
+ // For double and triple clicks GDK sends both a normal button press event
+ // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press
+ // coming up, ignore this event as it certainly generated the double or triple
+ // click. The consequence of not eating this event is two DOM button press events
+ // are generated.
+ GOwnPtr<GdkEvent> nextEvent(gdk_event_peek());
+ if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS))
+ return TRUE;
+
+ gint doubleClickDistance = 250;
+ gint doubleClickTime = 5;
+ GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
+ g_object_get(settings,
+ "gtk-double-click-distance", &doubleClickDistance,
+ "gtk-double-click-time", &doubleClickTime, NULL);
+
+ // GTK+ only counts up to triple clicks, but WebCore wants to know about
+ // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the
+ // GDK logic for counting clicks.
+ GdkEvent* event(reinterpret_cast<GdkEvent*>(buttonEvent));
+ guint32 eventTime = getEventTime(event);
+ WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(widget);
+ WebViewWidgetPrivate* priv = webViewWidget->priv;
+ if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
+ || ((abs(buttonEvent->x - priv->previousClickPoint.x()) < doubleClickDistance)
+ && (abs(buttonEvent->y - priv->previousClickPoint.y()) < doubleClickDistance)
+ && (eventTime - priv->previousClickTime < static_cast<guint>(doubleClickTime))
+ && (buttonEvent->button == priv->previousClickButton)))
+ priv->currentClickCount++;
+ else
+ priv->currentClickCount = 1;
+
+ WebView* webView = webViewWidgetGetWebViewInstance(webViewWidget);
+ webView->handleMouseEvent(event, priv->currentClickCount);
+
+ gdouble x, y;
+ gdk_event_get_coords(event, &x, &y);
+ priv->previousClickPoint = IntPoint(x, y);
+ priv->previousClickButton = buttonEvent->button;
+ priv->previousClickTime = eventTime;
+
+ return FALSE;
+}
+
+static gboolean webViewButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ gtk_widget_grab_focus(widget);
+ webView->handleMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */);
+
+ return FALSE;
+}
+
+static gboolean webViewScrollEvent(GtkWidget* widget, GdkEventScroll* event)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ webView->handleWheelEvent(event);
+
+ return FALSE;
+}
+
+static gboolean webViewMotionNotifyEvent(GtkWidget* widget, GdkEventMotion* event)
+{
+ WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
+ webView->handleMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */);
+
+ return FALSE;
+}
+
+static void webViewWidgetClassInit(WebViewWidgetClass* webViewWidgetClass)
+{
+ webViewWidgetParentClass = g_type_class_peek_parent(webViewWidgetClass);
+
+ GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webViewWidgetClass);
+ widgetClass->realize = webViewWidgetRealize;
+#ifdef GTK_API_VERSION_2
+ widgetClass->expose_event = webViewExpose;
+#else
+ widgetClass->draw = webViewDraw;
+#endif
+ widgetClass->size_allocate = webViewSizeAllocate;
+ widgetClass->focus_in_event = webViewFocusInEvent;
+ widgetClass->focus_out_event = webViewFocusOutEvent;
+ widgetClass->key_press_event = webViewKeyPressEvent;
+ widgetClass->key_release_event = webViewKeyReleaseEvent;
+ widgetClass->button_press_event = webViewButtonPressEvent;
+ widgetClass->button_release_event = webViewButtonReleaseEvent;
+ widgetClass->scroll_event = webViewScrollEvent;
+ widgetClass->motion_notify_event = webViewMotionNotifyEvent;
+
+ GObjectClass* gobjectClass = G_OBJECT_CLASS(webViewWidgetClass);
+ gobjectClass->dispose = webViewWidgetDispose;
+
+ GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webViewWidgetClass);
+ containerClass->add = webViewWidgetContainerAdd;
+
+ g_type_class_add_private(webViewWidgetClass, sizeof(WebViewWidgetPrivate));
+}
+
+GType webViewWidgetGetType()
+{
+ static volatile gsize gDefineTypeIdVolatile = 0;
+
+ if (!g_once_init_enter(&gDefineTypeIdVolatile))
+ return gDefineTypeIdVolatile;
+
+ GType gDefineTypeId = g_type_register_static_simple(GTK_TYPE_CONTAINER,
+ g_intern_static_string("WebViewWidget"),
+ sizeof(WebViewWidgetClass),
+ reinterpret_cast<GClassInitFunc>(webViewWidgetClassInit),
+ sizeof(WebViewWidget),
+ reinterpret_cast<GInstanceInitFunc>(webViewWidgetInit),
+ static_cast<GTypeFlags>(0));
+ g_once_init_leave(&gDefineTypeIdVolatile, gDefineTypeId);
+
+ return gDefineTypeIdVolatile;
+}
+
+WebView* webViewWidgetGetWebViewInstance(WebViewWidget* webViewWidget)
+{
+ return webViewWidget->priv->webViewInstance;
+}
+
+void webViewWidgetSetWebViewInstance(WebViewWidget* webViewWidget, WebView* webViewInstance)
+{
+ webViewWidget->priv->webViewInstance = webViewInstance;
+}
+
+GtkIMContext* webViewWidgetGetIMContext(WebViewWidget* webViewWidget)
+{
+ return webViewWidget->priv->imContext;
+}
diff --git a/Source/WebKit2/UIProcess/gtk/WebViewWidget.h b/Source/WebKit2/UIProcess/gtk/WebViewWidget.h
new file mode 100644
index 0000000..ef1d87f
--- /dev/null
+++ b/Source/WebKit2/UIProcess/gtk/WebViewWidget.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Portions Copyright (c) 2010 Motorola Mobility, Inc. All rights reserved.
+ * Copyright (C) 2011 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebViewWidget_h
+#define WebViewWidget_h
+
+#include "WebView.h"
+
+#include <gtk/gtk.h>
+
+using namespace WebKit;
+
+G_BEGIN_DECLS
+
+#define WEB_VIEW_TYPE_WIDGET (webViewWidgetGetType())
+#define WEB_VIEW_WIDGET(object) (G_TYPE_CHECK_INSTANCE_CAST((object), WEB_VIEW_TYPE_WIDGET, WebViewWidget))
+#define WEB_VIEW_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEB_VIEW_TYPE_WIDGET, WebViewWidgetClass))
+#define WEB_VIEW_IS_WIDGET(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), WEB_VIEW_TYPE_WIDGET))
+#define WEB_VIEW_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEB_VIEW_TYPE_WIDGET))
+#define WEB_VIEW_WIDGET_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), WEB_VIEW_TYPE_WIDGET, WebViewWidgetClass))
+
+typedef struct _WebViewWidget WebViewWidget;
+typedef struct _WebViewWidgetClass WebViewWidgetClass;
+typedef struct _WebViewWidgetPrivate WebViewWidgetPrivate;
+
+struct _WebViewWidget {
+ GtkContainer parentInstance;
+ /*< private >*/
+ WebViewWidgetPrivate* priv;
+};
+
+struct _WebViewWidgetClass {
+ GtkContainerClass parentClass;
+};
+
+GType webViewWidgetGetType();
+
+WebView* webViewWidgetGetWebViewInstance(WebViewWidget*);
+
+void webViewWidgetSetWebViewInstance(WebViewWidget*, WebView*);
+
+GtkIMContext* webViewWidgetGetIMContext(WebViewWidget*);
+
+G_END_DECLS
+
+#endif // WebViewWidget_h