initial import
[vuplus_webkit] / Tools / WebKitTestRunner / gtk / PlatformWebViewGtk.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Copyright (C) 2010 University of Szeged. All rights reserved.
4  * Copyright (C) 2010 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "PlatformWebView.h"
30
31 #include <gtk/gtk.h>
32
33 namespace WTR {
34
35 PlatformWebView::PlatformWebView(WKContextRef context, WKPageGroupRef pageGroup)
36     : m_view(WKViewCreate(context, pageGroup))
37     , m_window(gtk_window_new(GTK_WINDOW_POPUP))
38 {
39     gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view));
40
41     GtkAllocation size = { 0, 0, 800, 600 };
42     gtk_widget_size_allocate(m_window, &size);
43     gtk_window_resize(GTK_WINDOW(m_window), 800, 600);
44     gtk_widget_show_all(m_window);
45
46     while (gtk_events_pending())
47         gtk_main_iteration();
48 }
49
50 PlatformWebView::~PlatformWebView()
51 {
52     gtk_widget_destroy(m_window);
53 }
54
55 void PlatformWebView::resizeTo(unsigned width, unsigned height)
56 {
57     GtkAllocation size = { 0, 0, width, height };
58     gtk_widget_size_allocate(m_window, &size);
59     gtk_window_resize(GTK_WINDOW(m_window), width, height);
60
61     while (gtk_events_pending())
62         gtk_main_iteration();
63 }
64
65 WKPageRef PlatformWebView::page()
66 {
67     return WKViewGetPage(m_view);
68 }
69
70 void PlatformWebView::focus()
71 {
72 }
73
74 WKRect PlatformWebView::windowFrame()
75 {
76     GtkAllocation geometry;
77 #ifdef GTK_API_VERSION_2
78     gint depth;
79     gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
80                             &geometry.x, &geometry.y, &geometry.width, &geometry.height, &depth);
81 #else
82     gdk_window_get_geometry(gtk_widget_get_window(GTK_WIDGET(m_window)),
83                             &geometry.x, &geometry.y, &geometry.width, &geometry.height);
84 #endif
85
86     WKRect frame;
87     frame.origin.x = geometry.x;
88     frame.origin.y = geometry.y;
89     frame.size.width = geometry.width;
90     frame.size.height = geometry.height;
91     return frame;
92 }
93
94 void PlatformWebView::setWindowFrame(WKRect frame)
95 {
96     gtk_window_move(GTK_WINDOW(m_window), frame.origin.x, frame.origin.y);
97     resizeTo(frame.size.width, frame.size.height);
98 }
99
100 } // namespace WTR
101