webengine/osswebengine/WebKit/gtk/Api/webkitgtkframe.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2007 Holger Hans Peter Freyther
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     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  * 3.  Neither the name of Apple, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 #include "config.h"
       
    30 #include "webkitgtkframe.h"
       
    31 #include "webkitgtkpage.h"
       
    32 #include "webkitgtkprivate.h"
       
    33 
       
    34 #include "FrameLoader.h"
       
    35 #include "FrameLoaderClientGtk.h"
       
    36 #include "FrameView.h"
       
    37 #include "HTMLFrameOwnerElement.h"
       
    38 
       
    39 using namespace WebCore;
       
    40 
       
    41 extern "C" {
       
    42 
       
    43 extern void webkit_marshal_VOID__STRING_STRING (GClosure*     closure,
       
    44                                                     GValue*       return_value,
       
    45                                                     guint         n_param_values,
       
    46                                                     const GValue* param_values,
       
    47                                                     gpointer      invocation_hint,
       
    48                                                     gpointer      marshal_data);
       
    49 
       
    50 enum {
       
    51     CLEARED,
       
    52     LOAD_DONE,
       
    53     TITLE_CHANGED,
       
    54     HOVERING_OVER_LINK,
       
    55     LAST_SIGNAL
       
    56 };
       
    57 
       
    58 static guint webkit_frame_signals[LAST_SIGNAL] = { 0, };
       
    59 
       
    60 static void webkit_frame_real_title_changed(WebKitFrame* frame, gchar* title, gchar* location);
       
    61 
       
    62 G_DEFINE_TYPE(WebKitFrame, webkit_frame, G_TYPE_OBJECT)
       
    63 
       
    64 static void webkit_frame_finalize(GObject* object)
       
    65 {
       
    66     WebKitFramePrivate* privateData = WEBKIT_FRAME_GET_PRIVATE(WEBKIT_FRAME(object));
       
    67     privateData->frame->loader()->cancelAndClear();
       
    68     g_free(privateData->title);
       
    69     g_free(privateData->location);
       
    70     delete privateData->frame;
       
    71 
       
    72     G_OBJECT_CLASS(webkit_frame_parent_class)->finalize(object);
       
    73 }
       
    74 
       
    75 static void webkit_frame_class_init(WebKitFrameClass* frameClass)
       
    76 {
       
    77     g_type_class_add_private(frameClass, sizeof(WebKitFramePrivate));
       
    78 
       
    79     /*
       
    80      * signals
       
    81      */
       
    82     webkit_frame_signals[CLEARED] = g_signal_new("cleared",
       
    83             G_TYPE_FROM_CLASS(frameClass),
       
    84             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
       
    85             0,
       
    86             NULL,
       
    87             NULL,
       
    88             g_cclosure_marshal_VOID__VOID,
       
    89             G_TYPE_NONE, 0);
       
    90 
       
    91     webkit_frame_signals[LOAD_DONE] = g_signal_new("load_done",
       
    92             G_TYPE_FROM_CLASS(frameClass),
       
    93             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
       
    94             0,
       
    95             NULL,
       
    96             NULL,
       
    97             g_cclosure_marshal_VOID__BOOLEAN,
       
    98             G_TYPE_NONE, 1,
       
    99             G_TYPE_BOOLEAN);
       
   100 
       
   101     webkit_frame_signals[TITLE_CHANGED] = g_signal_new("title_changed",
       
   102             G_TYPE_FROM_CLASS(frameClass),
       
   103             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
       
   104             G_STRUCT_OFFSET(WebKitFrameClass, title_changed),
       
   105             NULL,
       
   106             NULL,
       
   107             webkit_marshal_VOID__STRING_STRING,
       
   108             G_TYPE_NONE, 2,
       
   109             G_TYPE_STRING, G_TYPE_STRING);
       
   110 
       
   111     webkit_frame_signals[HOVERING_OVER_LINK] = g_signal_new("hovering_over_link",
       
   112             G_TYPE_FROM_CLASS(frameClass),
       
   113             (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
       
   114             0,
       
   115             NULL,
       
   116             NULL,
       
   117             webkit_marshal_VOID__STRING_STRING,
       
   118             G_TYPE_NONE, 2,
       
   119             G_TYPE_STRING, G_TYPE_STRING);
       
   120 
       
   121     frameClass->title_changed = webkit_frame_real_title_changed;
       
   122 
       
   123     /*
       
   124      * implementations of virtual methods
       
   125      */
       
   126     G_OBJECT_CLASS(frameClass)->finalize = webkit_frame_finalize;
       
   127 }
       
   128 
       
   129 static void webkit_frame_real_title_changed(WebKitFrame* frame, gchar* title, gchar* location)
       
   130 {
       
   131     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   132     g_free(frameData->title);
       
   133     g_free(frameData->location);
       
   134     frameData->title = g_strdup(title);
       
   135     frameData->location = g_strdup(location);
       
   136 }
       
   137 
       
   138 static void webkit_frame_init(WebKitFrame* frame)
       
   139 {
       
   140 }
       
   141 
       
   142 GObject* webkit_frame_new(WebKitPage* page)
       
   143 {
       
   144     WebKitFrame* frame = WEBKIT_FRAME(g_object_new(WEBKIT_TYPE_FRAME, NULL));
       
   145     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   146     WebKitPagePrivate* pageData = WEBKIT_PAGE_GET_PRIVATE(page);
       
   147 
       
   148     frameData->client = new WebKit::FrameLoaderClient(frame);
       
   149     frameData->frame = new Frame(pageData->page, 0, frameData->client);
       
   150 
       
   151     FrameView* frameView = new FrameView(frameData->frame);
       
   152     frameView->setContainingWindow(GTK_CONTAINER(page));
       
   153     frameView->setGtkAdjustments(GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)),
       
   154                                  GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)));
       
   155     frameData->frame->setView(frameView);
       
   156     frameData->frame->init();
       
   157     frameData->page = page;
       
   158     frameData->title = 0;
       
   159     frameData->location = 0;
       
   160 
       
   161     return G_OBJECT(frame);
       
   162 }
       
   163 
       
   164 GObject* webkit_frame_init_with_page(WebKitPage* page, HTMLFrameOwnerElement* element)
       
   165 {
       
   166     WebKitFrame* frame = WEBKIT_FRAME(g_object_new(WEBKIT_TYPE_FRAME, NULL));
       
   167     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   168     WebKitPagePrivate* pageData = WEBKIT_PAGE_GET_PRIVATE(page);
       
   169 
       
   170     frameData->client = new WebKit::FrameLoaderClient(frame);
       
   171     frameData->frame = new Frame(pageData->page, element, frameData->client);
       
   172 
       
   173     FrameView* frameView = new FrameView(frameData->frame);
       
   174     frameView->setContainingWindow(GTK_CONTAINER(page));
       
   175     frameData->frame->setView(frameView);
       
   176     frameView->deref();
       
   177     frameData->frame->init();
       
   178     frameData->page = page;
       
   179 
       
   180     return G_OBJECT(frame);
       
   181 } 
       
   182 
       
   183 WebKitPage*
       
   184 webkit_frame_get_page(WebKitFrame* frame)
       
   185 {
       
   186     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   187     return frameData->page;
       
   188 }
       
   189 
       
   190 gchar* webkit_frame_get_title(WebKitFrame* frame)
       
   191 {
       
   192     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   193     return frameData->title;
       
   194 }
       
   195 
       
   196 gchar* webkit_frame_get_location(WebKitFrame* frame)
       
   197 {
       
   198     WebKitFramePrivate* frameData = WEBKIT_FRAME_GET_PRIVATE(frame);
       
   199     return frameData->location;
       
   200 }
       
   201 
       
   202 }