• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "CString.h"
25 #include "GOwnPtr.h"
26 #include "webkitenumtypes.h"
27 #include "webkitprivate.h"
28 
29 #include <glib/gi18n-lib.h>
30 
31 /**
32  * SECTION:webkithittestresult
33  * @short_description: The target of a mouse event
34  *
35  * This class holds context information about the coordinates
36  * specified by a GDK event.
37  */
38 
39 G_DEFINE_TYPE(WebKitHitTestResult, webkit_hit_test_result, G_TYPE_OBJECT)
40 
41 struct _WebKitHitTestResultPrivate {
42     guint context;
43     char* linkURI;
44     char* imageURI;
45     char* mediaURI;
46 };
47 
48 #define WEBKIT_HIT_TEST_RESULT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResultPrivate))
49 
50 enum {
51     PROP_0,
52 
53     PROP_CONTEXT,
54     PROP_LINK_URI,
55     PROP_IMAGE_URI,
56     PROP_MEDIA_URI
57 };
58 
webkit_hit_test_result_finalize(GObject * object)59 static void webkit_hit_test_result_finalize(GObject* object)
60 {
61     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
62     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
63 
64     g_free(priv->linkURI);
65     g_free(priv->imageURI);
66     g_free(priv->mediaURI);
67 
68     G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->finalize(object);
69 }
70 
webkit_hit_test_result_get_property(GObject * object,guint propertyID,GValue * value,GParamSpec * pspec)71 static void webkit_hit_test_result_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec)
72 {
73     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
74     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
75 
76     switch(propertyID) {
77     case PROP_CONTEXT:
78         g_value_set_flags(value, priv->context);
79         break;
80     case PROP_LINK_URI:
81         g_value_set_string(value, priv->linkURI);
82         break;
83     case PROP_IMAGE_URI:
84         g_value_set_string(value, priv->imageURI);
85         break;
86     case PROP_MEDIA_URI:
87         g_value_set_string(value, priv->mediaURI);
88         break;
89     default:
90         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
91     }
92 }
93 
webkit_hit_test_result_set_property(GObject * object,guint propertyID,const GValue * value,GParamSpec * pspec)94 static void webkit_hit_test_result_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec)
95 {
96     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
97     WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
98 
99     switch(propertyID) {
100     case PROP_CONTEXT:
101         priv->context = g_value_get_flags(value);
102         break;
103     case PROP_LINK_URI:
104         g_free (priv->linkURI);
105         priv->linkURI = g_value_dup_string(value);
106         break;
107     case PROP_IMAGE_URI:
108         g_free (priv->imageURI);
109         priv->imageURI = g_value_dup_string(value);
110         break;
111     case PROP_MEDIA_URI:
112         g_free (priv->mediaURI);
113         priv->mediaURI = g_value_dup_string(value);
114         break;
115     default:
116         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
117     }
118 }
119 
webkit_hit_test_result_class_init(WebKitHitTestResultClass * webHitTestResultClass)120 static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* webHitTestResultClass)
121 {
122     GObjectClass* objectClass = G_OBJECT_CLASS(webHitTestResultClass);
123 
124     objectClass->finalize = webkit_hit_test_result_finalize;
125     objectClass->get_property = webkit_hit_test_result_get_property;
126     objectClass->set_property = webkit_hit_test_result_set_property;
127 
128     webkit_init();
129 
130     /**
131      * WebKitHitTestResult:context:
132      *
133      * Flags indicating the kind of target that received the event.
134      *
135      * Since: 1.1.15
136      */
137     g_object_class_install_property(objectClass, PROP_CONTEXT,
138                                     g_param_spec_flags("context",
139                                                        _("Context"),
140                                                        _("Flags indicating the kind of target that received the event."),
141                                                        WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT,
142                                                        WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
143                                                        static_cast<GParamFlags>((WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))));
144 
145     /**
146      * WebKitHitTestResult:link-uri:
147      *
148      * The URI to which the target that received the event points, if any.
149      *
150      * Since: 1.1.15
151      */
152     g_object_class_install_property(objectClass, PROP_LINK_URI,
153                                     g_param_spec_string("link-uri",
154                                                         _("Link URI"),
155                                                         _("The URI to which the target that received the event points, if any."),
156                                                         NULL,
157                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
158 
159     /**
160      * WebKitHitTestResult:image-uri:
161      *
162      * The URI of the image that is part of the target that received the event, if any.
163      *
164      * Since: 1.1.15
165      */
166     g_object_class_install_property(objectClass, PROP_IMAGE_URI,
167                                     g_param_spec_string("image-uri",
168                                                         _("Image URI"),
169                                                         _("The URI of the image that is part of the target that received the event, if any."),
170                                                         NULL,
171                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
172 
173     /**
174      * WebKitHitTestResult:media-uri:
175      *
176      * The URI of the media that is part of the target that received the event, if any.
177      *
178      * Since: 1.1.15
179      */
180     g_object_class_install_property(objectClass, PROP_MEDIA_URI,
181                                     g_param_spec_string("media-uri",
182                                                         _("Media URI"),
183                                                         _("The URI of the media that is part of the target that received the event, if any."),
184                                                         NULL,
185                                                         static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
186 
187     g_type_class_add_private(webHitTestResultClass, sizeof(WebKitHitTestResultPrivate));
188 }
189 
webkit_hit_test_result_init(WebKitHitTestResult * web_hit_test_result)190 static void webkit_hit_test_result_init(WebKitHitTestResult* web_hit_test_result)
191 {
192     web_hit_test_result->priv = WEBKIT_HIT_TEST_RESULT_GET_PRIVATE(web_hit_test_result);
193 }
194