| Differences between
and this patch
- WebKit2/ChangeLog +75 lines
Lines 1-3 WebKit2/ChangeLog_sec1
1
2011-01-14  Amruth Raj  <amruthraj@motorola.com> and Ravi Phaneendra Kasibhatla  <ravi.kasibhatla@motorola.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [GTK] Implementation of WebView, WebKitWebView classes
6
        https://bugs.webkit.org/show_bug.cgi?id=48509
7
8
        * UIProcess/gtk/WebKitWebView.cpp: Added. The GObject interface for WebView. 
9
        The GObject is the GtkWidget handle which is used by WebView class for GTK port.
10
        (WebKit::webkitWebViewRealize):
11
        (WebKit::webkitWebViewContainerAdd):
12
        (WebKit::webkitWebViewDispose):
13
        (WebKit::webkitWebViewClassInit):
14
        (WebKit::webkitWebViewInit):
15
        (WebKit::webkitWebViewGetType):
16
        (WebKit::webkitWebViewGetParentClass):
17
        (WebKit::webkitWebViewGetWebViewInstance):
18
        (WebKit::webkitWebViewSetWebViewInstance):
19
        (WebKit::webkitWebViewGetWindow):
20
        (WebKit::webkitWebViewGetIMContext):
21
        * UIProcess/gtk/WebKitWebView.h: Added. The GObject interface declarations for GtkWidget handle for GTK port.
22
        * UIProcess/gtk/WebView.cpp: Added. The native GtkWidget handle for GTK port which is associated with each WKViewRef.
23
        (WebKit::WebView::webViewOnExpose):
24
        (WebKit::WebView::webViewOnDraw):
25
        (WebKit::WebView::webViewOnSizeAllocate):
26
        (WebKit::WebView::webViewFocusInEvent):
27
        (WebKit::WebView::webViewFocusOutEvent):
28
        (WebKit::WebView::webViewKeyPressEvent):
29
        (WebKit::WebView::webViewKeyReleaseEvent):
30
        (WebKit::WebView::webViewButtonPressEvent):
31
        (WebKit::WebView::webViewButtonReleaseEvent):
32
        (WebKit::WebView::webViewScrollEvent):
33
        (WebKit::WebView::webViewMotionNotifyEvent):
34
        (WebKit::WebView::WebView):
35
        (WebKit::WebView::~WebView):
36
        (WebKit::WebView::getWebViewWindow):
37
        (WebKit::WebView::setHostWindow):
38
        (WebKit::WebView::onPaintEvent):
39
        (WebKit::WebView::onSizeEvent):
40
        (WebKit::WebView::onSetFocusEvent):
41
        (WebKit::WebView::onKillFocusEvent):
42
        (WebKit::WebView::onKeyEvent):
43
        (WebKit::WebView::onMouseEvent):
44
        (WebKit::WebView::onWheelEvent):
45
        (WebKit::WebView::isActive):
46
        (WebKit::WebView::updateActiveState):
47
        (WebKit::WebView::close):
48
        (WebKit::WebView::processDidCrash):
49
        (WebKit::WebView::didRelaunchProcess):
50
        (WebKit::WebView::takeFocus):
51
        (WebKit::WebView::toolTipChanged):
52
        (WebKit::WebView::setCursor):
53
        (WebKit::WebView::setViewportArguments):
54
        (WebKit::WebView::registerEditCommand):
55
        (WebKit::WebView::clearAllEditCommands):
56
        (WebKit::WebView::setEditCommandState):
57
        (WebKit::WebView::convertToDeviceSpace):
58
        (WebKit::WebView::convertToUserSpace):
59
        (WebKit::WebView::didNotHandleKeyEvent):
60
        (WebKit::WebView::createPopupMenuProxy):
61
        (WebKit::WebView::createContextMenuProxy):
62
        (WebKit::WebView::setFindIndicator):
63
        (WebKit::WebView::pageDidEnterAcceleratedCompositing):
64
        (WebKit::WebView::pageDidLeaveAcceleratedCompositing):
65
        (WebKit::WebView::didCommitLoadForMainFrame):
66
        (WebKit::WebView::didFinishLoadingDataForCustomRepresentation):
67
        (WebKit::WebView::customRepresentationZoomFactor):
68
        (WebKit::WebView::setCustomRepresentationZoomFactor):
69
        * UIProcess/gtk/WebView.h: Added. Class which implements the PageClient interface. 
70
        It is a wrapper over the native GtkWidget handle associated with each WKViewRef for GTK port.
71
        (WebKit::WebView::create):
72
        (WebKit::WebView::window):
73
        (WebKit::WebView::hostWindow):
74
        (WebKit::WebView::page):
75
1
2011-01-14  Pavel Feldman  <pfeldman@chromium.org>
76
2011-01-14  Pavel Feldman  <pfeldman@chromium.org>
2
77
3
        Reviewed by Yury Semikhatsky.
78
        Reviewed by Yury Semikhatsky.
- WebKit2/UIProcess/gtk/WebKitWebView.cpp +199 lines
Line 0 WebKit2/UIProcess/gtk/WebKitWebView.cpp_sec1
1
/*
2
 * Copyright (C) 2010 Apple Inc. All rights reserved.
3
 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "WebKitWebView.h"
28
29
#include "WebView.h"
30
31
namespace WebKit {
32
33
static gpointer webkitWebViewParentClass = NULL;
34
35
struct _WebKitWebViewPrivate {
36
    WebView* webViewInstance;
37
    GtkIMContext* imContext;
38
    gboolean disposeHasRun;
39
};
40
41
static void webkitWebViewRealize(GtkWidget* widget)
42
{
43
    gtk_widget_set_realized(widget, TRUE);
44
45
    GtkAllocation allocation;
46
    guint borderWidth = gtk_container_get_border_width(GTK_CONTAINER(widget));
47
#if GTK_CHECK_VERSION(2, 18, 0)
48
    gtk_widget_get_allocation(widget, &allocation);
49
#else
50
    allocation = widget->allocation;
51
#endif
52
53
    GdkWindowAttr attributes;
54
    attributes.window_type = GDK_WINDOW_CHILD;
55
    attributes.x = allocation.x + borderWidth;
56
    attributes.y = allocation.y + borderWidth;
57
    attributes.width = allocation.width - borderWidth * 2;
58
    attributes.height = allocation.height - borderWidth * 2;
59
    attributes.wclass = GDK_INPUT_OUTPUT;
60
    attributes.visual = gtk_widget_get_visual(widget);
61
#ifdef GTK_API_VERSION_2
62
    attributes.colormap = gtk_widget_get_colormap(widget);
63
#endif
64
    attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK 
65
                            | GDK_EXPOSURE_MASK 
66
                            | GDK_BUTTON_PRESS_MASK 
67
                            | GDK_BUTTON_RELEASE_MASK 
68
                            | GDK_POINTER_MOTION_MASK 
69
                            | GDK_KEY_PRESS_MASK 
70
                            | GDK_KEY_RELEASE_MASK
71
                            | GDK_BUTTON_MOTION_MASK 
72
                            | GDK_BUTTON1_MOTION_MASK 
73
                            | GDK_BUTTON2_MOTION_MASK 
74
                            | GDK_BUTTON3_MOTION_MASK;
75
76
    gint attributesMask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
77
#ifdef GTK_API_VERSION_2
78
    attributesMask |= GDK_WA_COLORMAP;
79
#endif
80
    GdkWindow* window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributesMask);
81
    gtk_widget_set_window(widget, window);
82
    gdk_window_set_user_data(window, widget);
83
84
#if GTK_CHECK_VERSION(2, 20, 0)
85
    gtk_widget_style_attach(widget);
86
#else
87
    widget->style = gtk_style_attach(gtk_widget_get_style(widget), window);
88
#endif
89
    gtk_style_set_background(gtk_widget_get_style(widget), window, GTK_STATE_NORMAL);
90
91
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(widget);
92
    gtk_im_context_set_client_window(webkitWebView->priv->imContext, window);
93
}
94
95
static void webkitWebViewContainerAdd(GtkContainer* container, GtkWidget* widget)
96
{
97
    gtk_widget_set_parent(widget, GTK_WIDGET(container));
98
}
99
100
static void webkitWebViewDispose(GObject* gobject)
101
{
102
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(gobject);
103
    if (webkitWebView->priv->disposeHasRun)
104
        return;
105
106
    g_object_unref(webkitWebView->priv->imContext);
107
    webkitWebView->priv->disposeHasRun = TRUE;
108
    G_OBJECT_CLASS(webkitWebViewParentClass)->dispose(gobject);
109
}
110
111
static void webkitWebViewClassInit(WebKitWebViewClass* webkitWebViewClass)
112
{
113
    webkitWebViewParentClass = g_type_class_peek_parent(webkitWebViewClass);
114
115
    GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(webkitWebViewClass);
116
    widgetClass->realize = webkitWebViewRealize;
117
#ifdef GTK_API_VERSION_2
118
    widgetClass->expose_event = WebKit::WebView::webViewOnExpose;
119
#else
120
    widgetClass->draw = WebKit::WebView::webViewOnDraw;
121
#endif
122
    widgetClass->size_allocate = WebKit::WebView::webViewOnSizeAllocate;
123
    widgetClass->focus_in_event = WebKit::WebView::webViewFocusInEvent;
124
    widgetClass->focus_out_event = WebKit::WebView::webViewFocusOutEvent;
125
    widgetClass->key_press_event = WebKit::WebView::webViewKeyPressEvent;
126
    widgetClass->key_release_event = WebKit::WebView::webViewKeyReleaseEvent;
127
    widgetClass->button_press_event = WebKit::WebView::webViewButtonPressEvent;
128
    widgetClass->button_release_event = WebKit::WebView::webViewButtonReleaseEvent;
129
    widgetClass->scroll_event = WebKit::WebView::webViewScrollEvent;
130
    widgetClass->motion_notify_event = WebKit::WebView::webViewMotionNotifyEvent;
131
132
    GObjectClass* gobjectClass = G_OBJECT_CLASS(webkitWebViewClass);
133
    gobjectClass->dispose = webkitWebViewDispose;
134
135
    GtkContainerClass* containerClass = GTK_CONTAINER_CLASS(webkitWebViewClass);
136
    containerClass->add = webkitWebViewContainerAdd;
137
138
    g_type_class_add_private(webkitWebViewClass, sizeof(WebKitWebViewPrivate));
139
}
140
141
static void webkitWebViewInit(WebKitWebView* webkitWebView)
142
{
143
    WebKitWebViewPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(webkitWebView, WEBKIT_TYPE_WEB_VIEW, WebKitWebViewPrivate);
144
    webkitWebView->priv = priv;
145
146
    GTK_WIDGET_SET_FLAGS(webkitWebView, GTK_CAN_FOCUS);
147
    priv->imContext = gtk_im_multicontext_new();
148
    priv->disposeHasRun = FALSE;
149
}
150
151
GType webkitWebViewGetType()
152
{
153
    static GType type = 0; 
154
    if (type)
155
        return type;
156
157
    static const GTypeInfo info = {
158
            sizeof(WebKitWebViewClass),          /* class structure size */
159
            0,                                  /* base_init */
160
            0,                                  /* base_finalize */
161
            reinterpret_cast<GClassInitFunc>(webkitWebViewClassInit), /* class initializer */
162
            0,                                  /* class_finalize */
163
            0,                                  /* class_data */
164
            sizeof(WebKitWebView),               /* instance structure size */
165
            0,                                  /* preallocated instances */
166
            reinterpret_cast<GInstanceInitFunc>(webkitWebViewInit),   /* instance initializer */
167
            0                                   /* function table */
168
    };   
169
    type = g_type_register_static(GTK_TYPE_CONTAINER, "WebKitWebView", &info, static_cast<GTypeFlags>(0));
170
171
    return type;
172
}
173
174
gpointer webkitWebViewGetParentClass()
175
{
176
    return webkitWebViewParentClass;
177
}
178
179
WebView* webkitWebViewGetWebViewInstance(WebKitWebView* webkitWebView)
180
{
181
    return webkitWebView->priv->webViewInstance;
182
}
183
184
void webkitWebViewSetWebViewInstance(WebKitWebView* webkitWebView, WebView* webViewInstance)
185
{
186
    webkitWebView->priv->webViewInstance = webViewInstance;
187
}
188
189
GdkWindow* webkitWebViewGetWindow(WebKitWebView* webkitWebView)
190
{
191
    return gtk_widget_get_window(GTK_WIDGET(webkitWebView));
192
}
193
194
GtkIMContext* webkitWebViewGetIMContext(WebKitWebView* webkitWebView)
195
{
196
    return webkitWebView->priv->imContext;
197
}
198
199
} // namespace WebKit
- WebKit2/UIProcess/gtk/WebKitWebView.h +72 lines
Line 0 WebKit2/UIProcess/gtk/WebKitWebView.h_sec1
1
/*
2
 * Copyright (C) 2010 Apple Inc. All rights reserved.
3
 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef WebKitWebView_h
28
#define WebKitWebView_h
29
30
#include <gtk/gtk.h>
31
32
namespace WebKit {
33
34
#define WEBKIT_TYPE_WEB_VIEW                (webkitWebViewGetType())
35
#define WEBKIT_WEB_VIEW(obj)                (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebView))
36
#define WEBKIT_WEB_VIEW_CLASS(klass)        (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
37
#define WEBKIT_IS_WEB_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEB_VIEW))
38
#define WEBKIT_IS_WEB_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_WEB_VIEW))
39
#define WEBKIT_WEB_VIEW_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_WEB_VIEW, WebKitWebViewClass))
40
#define WEBKIT_WEB_VIEW_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_WEB_VIEW, WebKitWebViewPrivate))
41
42
class WebView;
43
44
typedef struct _WebKitWebView WebKitWebView;
45
typedef struct _WebKitWebViewClass WebKitWebViewClass;
46
typedef struct _WebKitWebViewPrivate WebKitWebViewPrivate;
47
48
struct _WebKitWebView {
49
    GtkContainer parentInstance;
50
    /*< private >*/ 
51
    WebKitWebViewPrivate* priv;
52
};
53
54
struct _WebKitWebViewClass {
55
    GtkContainerClass parentClass;
56
};
57
58
GType webkitWebViewGetType();
59
60
gpointer webkitWebViewGetParentClass();
61
62
WebView* webkitWebViewGetWebViewInstance(WebKitWebView*);
63
64
void webkitWebViewSetWebViewInstance(WebKitWebView*, WebView*);
65
66
GdkWindow* webkitWebViewGetWindow(WebKitWebView*);
67
68
GtkIMContext* webkitWebViewGetIMContext(WebKitWebView*);
69
70
} // namespace WebKit
71
72
#endif // WebKitWebView_h 
- WebKit2/UIProcess/gtk/WebView.cpp +345 lines
Line 0 WebKit2/UIProcess/gtk/WebView.cpp_sec1
1
/*
2
 * Copyright (C) 2010 Apple Inc. All rights reserved.
3
 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "WebView.h"
28
29
#include "ChunkedUpdateDrawingAreaProxy.h"
30
#include "NativeWebKeyboardEvent.h"
31
#include "NotImplemented.h"
32
#include "WebContext.h"
33
#include "WebContextMenuProxy.h"
34
#include "WebEventFactory.h"
35
#include "WebKitWebView.h"
36
#include "WebPageProxy.h"
37
#include <wtf/text/WTFString.h>
38
39
using namespace WebCore;
40
41
namespace WebKit {
42
43
#ifdef GTK_API_VERSION_2
44
gboolean WebView::webViewOnExpose(GtkWidget* widget, GdkEventExpose* event)
45
{
46
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
47
    GdkRectangle clipRect;
48
    gdk_region_get_clipbox(event->region, &clipRect);
49
    webView->onPaintEvent(widget, IntRect(clipRect));
50
51
    return FALSE;
52
}
53
#else
54
gboolean WebView::webViewOnDraw(GtkWidget*, cairo_t*)
55
{
56
    return FALSE;
57
}
58
#endif
59
60
void WebView::webViewOnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation)
61
{
62
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
63
    GTK_WIDGET_CLASS(G_OBJECT_CLASS(webkitWebViewGetParentClass()))->size_allocate(widget, allocation);
64
    webView->onSizeEvent(widget, IntSize(allocation->width, allocation->height));
65
}
66
67
gboolean WebView::webViewFocusInEvent(GtkWidget* widget, GdkEventFocus* event)
68
{
69
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(widget);
70
    WebView* webView = webkitWebViewGetWebViewInstance(webkitWebView);
71
    
72
    GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
73
    if (GTK_WIDGET_TOPLEVEL(toplevel) && gtk_window_has_toplevel_focus(GTK_WINDOW(toplevel))) {
74
        gtk_im_context_focus_in(webkitWebViewGetIMContext(webkitWebView));
75
        if (!(webView->m_isPageActive)) {
76
            webView->m_isPageActive = true;
77
            webView->updateActiveState();
78
        }
79
        webView->onSetFocusEvent(widget);
80
    }
81
82
    return GTK_WIDGET_CLASS(G_OBJECT_CLASS(webkitWebViewGetParentClass()))->focus_in_event(widget, event);
83
}
84
85
gboolean WebView::webViewFocusOutEvent(GtkWidget* widget, GdkEventFocus* event)
86
{
87
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(widget);
88
    WebView* webView = webkitWebViewGetWebViewInstance(webkitWebView);
89
90
    webView->onKillFocusEvent(widget);
91
    webView->m_isPageActive = false; 
92
    webView->updateActiveState();
93
    GtkIMContext* imContext = webkitWebViewGetIMContext(webkitWebView);
94
    if (imContext)
95
        gtk_im_context_focus_out(imContext);
96
    
97
    return GTK_WIDGET_CLASS(G_OBJECT_CLASS(webkitWebViewGetParentClass()))->focus_out_event(widget, event);
98
}
99
100
gboolean WebView::webViewKeyPressEvent(GtkWidget* widget, GdkEventKey* event)
101
{
102
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
103
    webView->onKeyEvent(event);
104
    
105
    return GTK_WIDGET_CLASS(G_OBJECT_CLASS(webkitWebViewGetParentClass()))->key_press_event(widget, event);
106
}
107
108
gboolean WebView::webViewKeyReleaseEvent(GtkWidget* widget, GdkEventKey* event)
109
{
110
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(widget);
111
    WebView* webView = webkitWebViewGetWebViewInstance(webkitWebView);
112
113
    if (gtk_im_context_filter_keypress(webkitWebViewGetIMContext(webkitWebView), event))
114
        return TRUE;
115
    
116
    webView->onKeyEvent(event);
117
    return GTK_WIDGET_CLASS(G_OBJECT_CLASS(webkitWebViewGetParentClass()))->key_release_event(widget, event);
118
}
119
120
gboolean WebView::webViewButtonPressEvent(GtkWidget* widget, GdkEventButton* event)
121
{
122
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
123
    gtk_widget_grab_focus(widget);
124
    webView->onMouseEvent(reinterpret_cast<GdkEventAny*>(event));
125
126
    return FALSE;
127
}
128
129
gboolean WebView::webViewButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event)
130
{
131
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
132
    gtk_widget_grab_focus(widget);
133
    webView->onMouseEvent(reinterpret_cast<GdkEventAny*>(event));
134
135
    return FALSE;
136
}
137
138
gboolean WebView::webViewScrollEvent(GtkWidget* widget, GdkEventScroll* event)
139
{
140
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
141
    webView->onWheelEvent(event);
142
143
    return FALSE;
144
}
145
146
gboolean WebView::webViewMotionNotifyEvent(GtkWidget* widget, GdkEventMotion* event)
147
{
148
    WebView* webView = webkitWebViewGetWebViewInstance(WEBKIT_WEB_VIEW(widget));
149
    webView->onMouseEvent(reinterpret_cast<GdkEventAny*>(event));
150
151
    return FALSE;
152
}
153
154
WebView::WebView(GdkRectangle windowRect, WebContext* context, WebPageGroup* pageGroup, GtkWidget* hostWindow)
155
    : m_windowRect(windowRect)
156
    , m_hostWindow(hostWindow)
157
    , m_isPageActive(true)
158
{
159
    m_page = context->createWebPage(pageGroup);
160
    m_page->setPageClient(this);
161
    m_page->setDrawingArea(ChunkedUpdateDrawingAreaProxy::create(this, m_page.get()));
162
    m_page->initializeWebPage(IntRect(windowRect).size());
163
164
    m_window = static_cast<GtkWidget*>(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL)); 
165
    ASSERT(m_window);
166
    WebKitWebView* webkitWebView = WEBKIT_WEB_VIEW(m_window);
167
    webkitWebViewSetWebViewInstance(webkitWebView, this);
168
}
169
170
WebView::~WebView()
171
{
172
}
173
174
GdkWindow* WebView::getWebViewWindow()
175
{
176
    return webkitWebViewGetWindow(WEBKIT_WEB_VIEW(m_window));
177
}
178
179
void WebView::setHostWindow(GtkWidget* hostWindow)
180
{
181
    m_hostWindow = hostWindow;
182
}
183
184
void WebView::onPaintEvent(GtkWidget* widget, IntRect windowRect)
185
{
186
    GdkWindow* window = gtk_widget_get_window(widget);
187
    ASSERT(window);
188
    m_page->drawingArea()->paint(windowRect, window);
189
}
190
191
void WebView::onSizeEvent(GtkWidget*, IntSize windowSize)
192
{
193
    m_page->drawingArea()->setSize(windowSize);
194
}
195
196
void WebView::onSetFocusEvent(GtkWidget*)
197
{
198
    m_page->setFocused(true);
199
}
200
201
void WebView::onKillFocusEvent(GtkWidget*)
202
{
203
    m_page->setFocused(false);
204
}
205
206
void WebView::onKeyEvent(GdkEventKey* event)
207
{
208
    m_page->handleKeyboardEvent(NativeWebKeyboardEvent(event));
209
}
210
211
void WebView::onMouseEvent(GdkEventAny* event)
212
{
213
    m_page->handleMouseEvent(WebEventFactory::createWebMouseEvent(event));
214
}
215
216
void WebView::onWheelEvent(GdkEventScroll* event)
217
{
218
    m_page->handleWheelEvent(WebEventFactory::createWebWheelEvent(event));
219
}
220
221
bool WebView::isActive()
222
{
223
    return m_isPageActive;
224
}
225
226
void WebView::updateActiveState()
227
{
228
    m_page->setActive(isActive());
229
}
230
231
void WebView::close()
232
{
233
    m_page->close();
234
}
235
236
// PageClient's pure virtual functions
237
void WebView::processDidCrash()
238
{
239
    notImplemented();
240
}
241
242
void WebView::didRelaunchProcess()
243
{
244
    notImplemented();
245
}
246
247
void WebView::takeFocus(bool)
248
{
249
    notImplemented();
250
}
251
252
void WebView::toolTipChanged(const String&, const String&)
253
{
254
    notImplemented();
255
}
256
257
void WebView::setCursor(const Cursor&)
258
{
259
    notImplemented();
260
}
261
262
void WebView::setViewportArguments(const WebCore::ViewportArguments&)
263
{
264
    notImplemented();
265
}
266
267
void WebView::registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo)
268
{
269
    notImplemented();
270
}
271
272
void WebView::clearAllEditCommands()
273
{
274
    notImplemented();
275
}
276
277
void WebView::setEditCommandState(const String&, bool, int)
278
{
279
    notImplemented();
280
}
281
282
FloatRect WebView::convertToDeviceSpace(const FloatRect& viewRect)
283
{
284
    notImplemented();
285
    return viewRect;
286
}
287
288
FloatRect WebView::convertToUserSpace(const FloatRect& viewRect)
289
{
290
    notImplemented();
291
    return viewRect;
292
}
293
294
void WebView::didNotHandleKeyEvent(const NativeWebKeyboardEvent& event)
295
{
296
    notImplemented();
297
}
298
299
PassRefPtr<WebPopupMenuProxy> WebView::createPopupMenuProxy(WebPageProxy*)
300
{
301
    notImplemented();
302
    return 0;
303
}
304
305
PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy*)
306
{
307
    notImplemented();
308
    return 0;
309
}
310
311
void WebView::setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut)
312
{
313
    notImplemented();
314
}
315
316
#if USE(ACCELERATED_COMPOSITING)
317
void WebView::pageDidEnterAcceleratedCompositing()
318
{
319
    notImplemented();
320
}
321
322
void WebView::pageDidLeaveAcceleratedCompositing()
323
{
324
    notImplemented();
325
}
326
#endif // USE(ACCELERATED_COMPOSITING)
327
328
void WebView::didCommitLoadForMainFrame(bool useCustomRepresentation)
329
{
330
}
331
332
void WebView::didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference&)
333
{
334
}
335
336
double WebView::customRepresentationZoomFactor()
337
{
338
    return 1.0;
339
}
340
341
void WebView::setCustomRepresentationZoomFactor(double)
342
{
343
}
344
345
} // namespace WebKit
- WebKit2/UIProcess/gtk/WebView.h +127 lines
Line 0 WebKit2/UIProcess/gtk/WebView.h_sec1
1
/*
2
 * Copyright (C) 2010 Apple Inc. All rights reserved.
3
 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24
 * THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#ifndef WebView_h
28
#define WebView_h
29
30
#include "PageClient.h"
31
#include "WebPageProxy.h"
32
#include <WebCore/IntSize.h>
33
#include <gdk/gdk.h>
34
#include <glib.h>
35
#include <gtk/gtk.h>
36
#include <wtf/PassRefPtr.h>
37
#include <wtf/RefCounted.h>
38
#include <wtf/RefPtr.h>
39
40
namespace WebKit {
41
42
class DrawingAreaProxy;
43
class WebPageNamespace;
44
45
class WebView : public RefCounted<WebView>, public PageClient {
46
public:
47
    virtual ~WebView();
48
#ifdef GTK_API_VERSION_2
49
    static gboolean webViewOnExpose(GtkWidget*, GdkEventExpose*);
50
#else
51
    static gboolean webViewOnDraw(GtkWidget*, cairo_t*);
52
#endif
53
    static void webViewOnSizeAllocate(GtkWidget*, GtkAllocation*);
54
    static gboolean webViewFocusInEvent(GtkWidget*, GdkEventFocus*);
55
    static gboolean webViewFocusOutEvent(GtkWidget*, GdkEventFocus*);
56
    static gboolean webViewKeyPressEvent(GtkWidget*, GdkEventKey*);
57
    static gboolean webViewKeyReleaseEvent(GtkWidget*, GdkEventKey*);
58
    static gboolean webViewButtonPressEvent(GtkWidget*, GdkEventButton*);
59
    static gboolean webViewButtonReleaseEvent(GtkWidget*, GdkEventButton*);
60
    static gboolean webViewScrollEvent(GtkWidget*, GdkEventScroll*);
61
    static gboolean webViewMotionNotifyEvent(GtkWidget*, GdkEventMotion*);
62
63
    static PassRefPtr<WebView> create(GdkRectangle windowRect, WebContext* context, WebPageGroup* pageGroup, GtkWidget* hostWindow)
64
    {
65
        return adoptRef(new WebView(windowRect, context, pageGroup, hostWindow));
66
    }
67
68
    GtkWidget* window() const { return m_window; }
69
    GtkWidget* hostWindow() const { return m_hostWindow; }
70
    void setHostWindow(GtkWidget*);
71
72
    WebPageProxy* page() const { return m_page.get(); }
73
74
private:
75
    WebView(GdkRectangle, WebContext*, WebPageGroup*, GtkWidget*);
76
77
    GdkWindow* getWebViewWindow();
78
    void onPaintEvent(GtkWidget*, WebCore::IntRect);
79
    void onSizeEvent(GtkWidget*, WebCore::IntSize);
80
    void onSetFocusEvent(GtkWidget*);
81
    void onKillFocusEvent(GtkWidget*);
82
    void onKeyEvent(GdkEventKey*);
83
    void onMouseEvent(GdkEventAny*);
84
    void onWheelEvent(GdkEventScroll*);
85
86
    bool isActive();
87
    void updateActiveState();
88
    void close();
89
90
    // PageClient
91
    virtual void processDidCrash();
92
    virtual void didRelaunchProcess();
93
    virtual void takeFocus(bool direction);
94
    virtual void toolTipChanged(const WTF::String&, const WTF::String&);
95
    virtual void setCursor(const WebCore::Cursor&);
96
    virtual void setViewportArguments(const WebCore::ViewportArguments&);
97
    virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
98
    virtual void clearAllEditCommands();
99
    virtual void setEditCommandState(const WTF::String&, bool, int);
100
    virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
101
    virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
102
    virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
103
    virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*);
104
    virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
105
    virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
106
107
#if USE(ACCELERATED_COMPOSITING)
108
    virtual void pageDidEnterAcceleratedCompositing();
109
    virtual void pageDidLeaveAcceleratedCompositing();
110
#endif
111
112
    virtual void didCommitLoadForMainFrame(bool useCustomRepresentation);
113
    virtual void didFinishLoadingDataForCustomRepresentation(const CoreIPC::DataReference&);
114
    virtual double customRepresentationZoomFactor();
115
    virtual void setCustomRepresentationZoomFactor(double);
116
117
    // Members of WebView class
118
    GdkRectangle m_windowRect;
119
    GtkWidget* m_window;
120
    GtkWidget* m_hostWindow;
121
    bool m_isPageActive;
122
    RefPtr<WebPageProxy> m_page;
123
};
124
125
} // namespace WebKit
126
127
#endif // WebView_h

Return to Bug 48509