1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
/*
* Copyright (C) 2009 Collabora Ltd.
* Copyright (C) 2009 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "webkithittestresult.h"
#include "Frame.h"
#include "FrameView.h"
#include "HitTestResult.h"
#include "KURL.h"
#include "WebKitDOMNodePrivate.h"
#include "webkitenumtypes.h"
#include "webkitglobals.h"
#include "webkitglobalsprivate.h"
#include <glib/gi18n-lib.h>
#include <wtf/gobject/GOwnPtr.h>
#include <wtf/gobject/GRefPtr.h>
#include <wtf/text/CString.h>
/**
* SECTION:webkithittestresult
* @short_description: The target of a mouse event
*
* This class holds context information about the coordinates
* specified by a GDK event.
*/
G_DEFINE_TYPE(WebKitHitTestResult, webkit_hit_test_result, G_TYPE_OBJECT)
struct _WebKitHitTestResultPrivate {
guint context;
char* linkURI;
char* imageURI;
char* mediaURI;
GRefPtr<WebKitDOMNode> innerNode;
WebCore::IntPoint position;
};
enum {
PROP_0,
PROP_CONTEXT,
PROP_LINK_URI,
PROP_IMAGE_URI,
PROP_MEDIA_URI,
PROP_INNER_NODE,
PROP_X,
PROP_Y
};
static void webkit_hit_test_result_finalize(GObject* object)
{
WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
g_free(priv->linkURI);
g_free(priv->imageURI);
g_free(priv->mediaURI);
G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->finalize(object);
}
static void webkit_hit_test_result_dispose(GObject* object)
{
WEBKIT_HIT_TEST_RESULT(object)->priv->~WebKitHitTestResultPrivate();
G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->dispose(object);
}
static void webkit_hit_test_result_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec)
{
WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
switch(propertyID) {
case PROP_CONTEXT:
g_value_set_flags(value, priv->context);
break;
case PROP_LINK_URI:
g_value_set_string(value, priv->linkURI);
break;
case PROP_IMAGE_URI:
g_value_set_string(value, priv->imageURI);
break;
case PROP_MEDIA_URI:
g_value_set_string(value, priv->mediaURI);
break;
case PROP_INNER_NODE:
g_value_set_object(value, priv->innerNode.get());
break;
case PROP_X:
g_value_set_int(value, priv->position.x());
break;
case PROP_Y:
g_value_set_int(value, priv->position.y());
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
}
}
static void webkit_hit_test_result_set_property(GObject* object, guint propertyID, const GValue* value, GParamSpec* pspec)
{
WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
WebKitHitTestResultPrivate* priv = web_hit_test_result->priv;
switch(propertyID) {
case PROP_CONTEXT:
priv->context = g_value_get_flags(value);
break;
case PROP_LINK_URI:
g_free (priv->linkURI);
priv->linkURI = g_value_dup_string(value);
break;
case PROP_IMAGE_URI:
g_free (priv->imageURI);
priv->imageURI = g_value_dup_string(value);
break;
case PROP_MEDIA_URI:
g_free (priv->mediaURI);
priv->mediaURI = g_value_dup_string(value);
break;
case PROP_INNER_NODE:
priv->innerNode = static_cast<WebKitDOMNode*>(g_value_get_object(value));
break;
case PROP_X:
priv->position.setX(g_value_get_int(value));
break;
case PROP_Y:
priv->position.setY(g_value_get_int(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyID, pspec);
}
}
static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* webHitTestResultClass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(webHitTestResultClass);
objectClass->finalize = webkit_hit_test_result_finalize;
objectClass->dispose = webkit_hit_test_result_dispose;
objectClass->get_property = webkit_hit_test_result_get_property;
objectClass->set_property = webkit_hit_test_result_set_property;
webkitInit();
/**
* WebKitHitTestResult:context:
*
* Flags indicating the kind of target that received the event.
*
* Since: 1.1.15
*/
g_object_class_install_property(objectClass, PROP_CONTEXT,
g_param_spec_flags("context",
_("Context"),
_("Flags indicating the kind of target that received the event."),
WEBKIT_TYPE_HIT_TEST_RESULT_CONTEXT,
WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT,
static_cast<GParamFlags>((WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY))));
/**
* WebKitHitTestResult:link-uri:
*
* The URI to which the target that received the event points, if any.
*
* Since: 1.1.15
*/
g_object_class_install_property(objectClass, PROP_LINK_URI,
g_param_spec_string("link-uri",
_("Link URI"),
_("The URI to which the target that received the event points, if any."),
NULL,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
/**
* WebKitHitTestResult:image-uri:
*
* The URI of the image that is part of the target that received the event, if any.
*
* Since: 1.1.15
*/
g_object_class_install_property(objectClass, PROP_IMAGE_URI,
g_param_spec_string("image-uri",
_("Image URI"),
_("The URI of the image that is part of the target that received the event, if any."),
NULL,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
/**
* WebKitHitTestResult:media-uri:
*
* The URI of the media that is part of the target that received the event, if any.
*
* Since: 1.1.15
*/
g_object_class_install_property(objectClass, PROP_MEDIA_URI,
g_param_spec_string("media-uri",
_("Media URI"),
_("The URI of the media that is part of the target that received the event, if any."),
NULL,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY)));
/**
* WebKitHitTestResult:inner-node:
*
* The DOM node at the coordinates where the hit test
* happened. Keep in mind that the node might not be
* representative of the information given in the context
* property, since WebKit uses a series of heuristics to figure
* out that information. One common example is inner-node having
* the text node inside the anchor (<a>) tag; WebKit knows the
* whole context and will put WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK
* in the 'context' property, but the user might be confused by
* the lack of any link tag in 'inner-node'.
*
* Since: 1.3.2
*/
g_object_class_install_property(objectClass, PROP_INNER_NODE,
g_param_spec_object("inner-node",
_("Inner node"),
_("The inner DOM node associated with the hit test result."),
WEBKIT_TYPE_DOM_NODE,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
/**
* WebKitHitTestResult:x:
*
* The x coordinate of the event relative to the view's window.
*
* Since: 1.10
*/
g_object_class_install_property(objectClass, PROP_X,
g_param_spec_int("x",
_("X coordinate"),
_("The x coordinate of the event relative to the view's window."),
G_MININT, G_MAXINT, 0,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
/**
* WebKitHitTestResult:y:
*
* The x coordinate of the event relative to the view's window.
*
* Since: 1.10
*/
g_object_class_install_property(objectClass, PROP_Y,
g_param_spec_int("y",
_("Y coordinate"),
_("The y coordinate of the event relative to the view's window."),
G_MININT, G_MAXINT, 0,
static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
g_type_class_add_private(webHitTestResultClass, sizeof(WebKitHitTestResultPrivate));
}
static void webkit_hit_test_result_init(WebKitHitTestResult* web_hit_test_result)
{
web_hit_test_result->priv = G_TYPE_INSTANCE_GET_PRIVATE(web_hit_test_result, WEBKIT_TYPE_HIT_TEST_RESULT, WebKitHitTestResultPrivate);
new (web_hit_test_result->priv) WebKitHitTestResultPrivate();
}
namespace WebKit {
WebKitHitTestResult* kit(const WebCore::HitTestResult& result)
{
guint context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
GOwnPtr<char> linkURI(0);
GOwnPtr<char> imageURI(0);
GOwnPtr<char> mediaURI(0);
WebKitDOMNode* node = 0;
WebCore::Frame* innerNodeFrame;
WebCore::IntPoint point;
if (!result.absoluteLinkURL().isEmpty()) {
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
linkURI.set(g_strdup(result.absoluteLinkURL().string().utf8().data()));
}
if (!result.absoluteImageURL().isEmpty()) {
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
imageURI.set(g_strdup(result.absoluteImageURL().string().utf8().data()));
}
if (!result.absoluteMediaURL().isEmpty()) {
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
mediaURI.set(g_strdup(result.absoluteMediaURL().string().utf8().data()));
}
if (result.isSelected())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SELECTION;
if (result.isContentEditable())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
if (result.innerNonSharedNode())
node = kit(result.innerNonSharedNode());
innerNodeFrame = result.innerNodeFrame();
if (innerNodeFrame && innerNodeFrame->view()) {
// Convert document coords to widget coords.
point = innerNodeFrame->view()->contentsToWindow(result.roundedPointInInnerNodeFrame());
} else {
// FIXME: Main frame coords is not the same as window coords,
// but we do not have pointer to mainframe view here.
point = result.roundedPointInMainFrame();
}
return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
"link-uri", linkURI.get(),
"image-uri", imageURI.get(),
"media-uri", mediaURI.get(),
"context", context,
"inner-node", node,
"x", point.x(),
"y", point.y(),
NULL));
}
}
|