WebKit/gtk/webkit/webkithittestresult.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2009 Collabora Ltd.
       
     3  * Copyright (C) 2009 Igalia S.L.
       
     4  *
       
     5  * This library is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU Library General Public
       
     7  * License as published by the Free Software Foundation; either
       
     8  * version 2 of the License, or (at your option) any later version.
       
     9  *
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Library General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU Library General Public License
       
    16  * along with this library; see the file COPYING.LIB.  If not, write to
       
    17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
       
    18  * Boston, MA 02110-1301, USA.
       
    19  */
       
    20 
       
    21 #include "config.h"
       
    22 #include "webkithittestresult.h"
       
    23 
       
    24 #include "GOwnPtr.h"
       
    25 #include "WebKitDOMNode.h"
       
    26 #include "webkitenumtypes.h"
       
    27 #include "webkitprivate.h"
       
    28 #include <wtf/text/CString.h>
       
    29 
       
    30 #include <glib/gi18n-lib.h>
       
    31 
       
    32 /**
       
    33  * SECTION:webkithittestresult
       
    34  * @short_description: The target of a mouse event
       
    35  *
       
    36  * This class holds context information about the coordinates
       
    37  * specified by a GDK event.
       
    38  */
       
    39 
       
    40 G_DEFINE_TYPE(WebKitHitTestResult, webkit_hit_test_result, G_TYPE_OBJECT)
       
    41 
       
    42 struct _WebKitHitTestResultPrivate {
       
    43     guint context;
       
    44     char* linkURI;
       
    45     char* imageURI;
       
    46     char* mediaURI;
       
    47     WebKitDOMNode* innerNode;
       
    48 };
       
    49 
       
    50 #define WEBKIT_HIT_TEST_RESULT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResultPrivate))
       
    51 
       
    52 enum {
       
    53     PROP_0,
       
    54 
       
    55     PROP_CONTEXT,
       
    56     PROP_LINK_URI,
       
    57     PROP_IMAGE_URI,
       
    58     PROP_MEDIA_URI,
       
    59     PROP_INNER_NODE
       
    60 };
       
    61 
       
    62 static void webkit_hit_test_result_finalize(GObject* object)
       
    63 {
       
    64     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
       
    65     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
       
    66 
       
    67     g_free(priv->linkURI);
       
    68     g_free(priv->imageURI);
       
    69     g_free(priv->mediaURI);
       
    70 
       
    71     G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->finalize(object);
       
    72 }
       
    73 
       
    74 static void webkit_hit_test_result_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec)
       
    75 {
       
    76     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
       
    77     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
       
    78 
       
    79     switch(propertyID) {
       
    80     case PROP_CONTEXT:
       
    81         g_value_set_flags(value, priv->context);
       
    82         break;
       
    83     case PROP_LINK_URI:
       
    84         g_value_set_string(value, priv->linkURI);
       
    85         break;
       
    86     case PROP_IMAGE_URI:
       
    87         g_value_set_string(value, priv->imageURI);
       
    88         break;
       
    89     case PROP_MEDIA_URI:
       
    90         g_value_set_string(value, priv->mediaURI);
       
    91         break;
       
    92     case PROP_INNER_NODE:
       
    93         g_value_set_object(value, priv->innerNode);
       
    94         break;
       
    95     default:
       
    96         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
       
    97     }
       
    98 }
       
    99 
       
   100 static void webkit_hit_test_result_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec)
       
   101 {
       
   102     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
       
   103     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
       
   104 
       
   105     switch(propertyID) {
       
   106     case PROP_CONTEXT:
       
   107         priv->context = g_value_get_flags(value);
       
   108         break;
       
   109     case PROP_LINK_URI:
       
   110         g_free (priv->linkURI);
       
   111         priv->linkURI = g_value_dup_string(value);
       
   112         break;
       
   113     case PROP_IMAGE_URI:
       
   114         g_free (priv->imageURI);
       
   115         priv->imageURI = g_value_dup_string(value);
       
   116         break;
       
   117     case PROP_MEDIA_URI:
       
   118         g_free (priv->mediaURI);
       
   119         priv->mediaURI = g_value_dup_string(value);
       
   120         break;
       
   121     case PROP_INNER_NODE:
       
   122         priv->innerNode = static_cast<WebKitDOMNode*>(g_value_get_object(value));
       
   123         break;
       
   124     default:
       
   125         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
       
   126     }
       
   127 }
       
   128 
       
   129 static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* webHitTestResultClass)
       
   130 {
       
   131     GObjectClass* objectClass = G_OBJECT_CLASS(webHitTestResultClass);
       
   132 
       
   133     objectClass->finalize = webkit_hit_test_result_finalize;
       
   134     objectClass->get_property = webkit_hit_test_result_get_property;
       
   135     objectClass->set_property = webkit_hit_test_result_set_property;
       
   136 
       
   137     webkit_init();
       
   138 
       
   139     /**
       
   140      * WebKitHitTestResult:context:
       
   141      *
       
   142      * Flags indicating the kind of target that received the event.
       
   143      *
       
   144      * Since: 1.1.15
       
   145      */
       
   146     g_object_class_install_property(objectClass, PROP_CONTEXT,
       
   147                                     g_param_spec_flags("context",
       
   148                                                        _("Context"),
       
   149                                                        _("Flags indicating the kind of target that received the event."),
       
   150                                                        WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT,
       
   151                                                        WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
       
   152                                                        static_cast<GParamFlags>((WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))));
       
   153 
       
   154     /**
       
   155      * WebKitHitTestResult:link-uri:
       
   156      *
       
   157      * The URI to which the target that received the event points, if any.
       
   158      *
       
   159      * Since: 1.1.15
       
   160      */
       
   161     g_object_class_install_property(objectClass, PROP_LINK_URI,
       
   162                                     g_param_spec_string("link-uri",
       
   163                                                         _("Link URI"),
       
   164                                                         _("The URI to which the target that received the event points, if any."),
       
   165                                                         NULL,
       
   166                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
       
   167 
       
   168     /**
       
   169      * WebKitHitTestResult:image-uri:
       
   170      *
       
   171      * The URI of the image that is part of the target that received the event, if any.
       
   172      *
       
   173      * Since: 1.1.15
       
   174      */
       
   175     g_object_class_install_property(objectClass, PROP_IMAGE_URI,
       
   176                                     g_param_spec_string("image-uri",
       
   177                                                         _("Image URI"),
       
   178                                                         _("The URI of the image that is part of the target that received the event, if any."),
       
   179                                                         NULL,
       
   180                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
       
   181 
       
   182     /**
       
   183      * WebKitHitTestResult:media-uri:
       
   184      *
       
   185      * The URI of the media that is part of the target that received the event, if any.
       
   186      *
       
   187      * Since: 1.1.15
       
   188      */
       
   189     g_object_class_install_property(objectClass, PROP_MEDIA_URI,
       
   190                                     g_param_spec_string("media-uri",
       
   191                                                         _("Media URI"),
       
   192                                                         _("The URI of the media that is part of the target that received the event, if any."),
       
   193                                                         NULL,
       
   194                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
       
   195 
       
   196     /**
       
   197      * WebKitHitTestResult:inner-node:
       
   198      *
       
   199      * The DOM node at the coordinates where the hit test
       
   200      * happened. Keep in mind that the node might not be
       
   201      * representative of the information given in the context
       
   202      * property, since WebKit uses a series of heuristics to figure
       
   203      * out that information. One common example is inner-node having
       
   204      * the text node inside the anchor (<a>) tag; WebKit knows the
       
   205      * whole context and will put WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK
       
   206      * in the 'context' property, but the user might be confused by
       
   207      * the lack of any link tag in 'inner-node'.
       
   208      *
       
   209      * Since: 1.3.2
       
   210      */
       
   211     g_object_class_install_property(objectClass, PROP_INNER_NODE,
       
   212                                     g_param_spec_object("inner-node",
       
   213                                                         _("Inner node"),
       
   214                                                         _("The inner DOM node associated with the hit test result."),
       
   215                                                         WEBKIT_TYPE_DOM_NODE,
       
   216                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
       
   217 
       
   218     g_type_class_add_private(webHitTestResultClass, sizeof(WebKitHitTestResultPrivate));
       
   219 }
       
   220 
       
   221 static void webkit_hit_test_result_init(WebKitHitTestResult* web_hit_test_result)
       
   222 {
       
   223     web_hit_test_result->priv = WEBKIT_HIT_TEST_RESULT_GET_PRIVATE(web_hit_test_result);
       
   224 }