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 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
/*
* Copyright (C) 2012 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 "WebHitTestResult.h"
#include "WebKitHitTestResultPrivate.h"
#include <glib/gi18n-lib.h>
#include <wtf/text/CString.h>
using namespace WebKit;
/**
* SECTION: WebKitHitTestResult
* @Short_description: Result of a Hit Test
* @Title: WebKitHitTestResult
* @See_also: #WebKitWebView
*
* A Hit Test is an operation to get context information about a given
* point in a #WebKitWebView. #WebKitHitTestResult represents the
* result of a Hit Test. It provides context information about what is
* at the coordinates of the Hit Test, such as if there's a link,
* an image or a media.
*
* You can get the context of the HitTestResult with
* webkit_hit_test_result_get_context() that returns a bitmask of
* #WebKitHitTestResultContext flags. You can also use
* webkit_hit_test_result_context_is_link(), webkit_hit_test_result_context_is_image() and
* webkit_hit_test_result_context_is_media() to determine whether there's
* a link, image or a media element at the coordinates of the Hit Test.
* Note that it's possible that several #WebKitHitTestResultContext flags
* are active at the same time, for example if there's a link containing an image.
*
* When the mouse is moved over a #WebKitWebView a Hit Test is performed
* for the mouse coordinates and #WebKitWebView::mouse-target-changed
* signal is emitted with a #WebKitHitTestResult.
*
*/
enum {
PROP_0,
PROP_CONTEXT,
PROP_LINK_URI,
PROP_LINK_TITLE,
PROP_LINK_LABEL,
PROP_IMAGE_URI,
PROP_MEDIA_URI
};
struct _WebKitHitTestResultPrivate {
unsigned int context;
CString linkURI;
CString linkTitle;
CString linkLabel;
CString imageURI;
CString mediaURI;
};
WEBKIT_DEFINE_TYPE(WebKitHitTestResult, webkit_hit_test_result, G_TYPE_OBJECT)
static void webkitHitTestResultGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
{
WebKitHitTestResult* hitTestResult = WEBKIT_HIT_TEST_RESULT(object);
switch (propId) {
case PROP_CONTEXT:
g_value_set_uint(value, webkit_hit_test_result_get_context(hitTestResult));
break;
case PROP_LINK_URI:
g_value_set_string(value, webkit_hit_test_result_get_link_uri(hitTestResult));
break;
case PROP_LINK_TITLE:
g_value_set_string(value, webkit_hit_test_result_get_link_title(hitTestResult));
break;
case PROP_LINK_LABEL:
g_value_set_string(value, webkit_hit_test_result_get_link_label(hitTestResult));
break;
case PROP_IMAGE_URI:
g_value_set_string(value, webkit_hit_test_result_get_image_uri(hitTestResult));
break;
case PROP_MEDIA_URI:
g_value_set_string(value, webkit_hit_test_result_get_media_uri(hitTestResult));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void webkitHitTestResultSetProperty(GObject* object, guint propId, const GValue* value, GParamSpec* paramSpec)
{
WebKitHitTestResult* hitTestResult = WEBKIT_HIT_TEST_RESULT(object);
switch (propId) {
case PROP_CONTEXT:
hitTestResult->priv->context = g_value_get_uint(value);
break;
case PROP_LINK_URI:
hitTestResult->priv->linkURI = g_value_get_string(value);
break;
case PROP_LINK_TITLE:
hitTestResult->priv->linkTitle = g_value_get_string(value);
break;
case PROP_LINK_LABEL:
hitTestResult->priv->linkLabel = g_value_get_string(value);
break;
case PROP_IMAGE_URI:
hitTestResult->priv->imageURI = g_value_get_string(value);
break;
case PROP_MEDIA_URI:
hitTestResult->priv->mediaURI = g_value_get_string(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
}
}
static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* hitTestResultClass)
{
GObjectClass* objectClass = G_OBJECT_CLASS(hitTestResultClass);
objectClass->get_property = webkitHitTestResultGetProperty;
objectClass->set_property = webkitHitTestResultSetProperty;
GParamFlags paramFlags = static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
/**
* WebKitHitTestResult:context:
*
* Bitmask of #WebKitHitTestResultContext flags representing
* the context of the #WebKitHitTestResult.
*/
g_object_class_install_property(objectClass,
PROP_CONTEXT,
g_param_spec_uint("context",
_("Context"),
_("Flags with the context of the WebKitHitTestResult"),
0, G_MAXUINT, 0,
paramFlags));
/**
* WebKitHitTestResult:link-uri:
*
* The URI of the link if flag %WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK
* is present in #WebKitHitTestResult:context
*/
g_object_class_install_property(objectClass,
PROP_LINK_URI,
g_param_spec_string("link-uri",
_("Link URI"),
_("The link URI"),
0,
paramFlags));
/**
* WebKitHitTestResult:link-title:
*
* The title of the link if flag %WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK
* is present in #WebKitHitTestResult:context
*/
g_object_class_install_property(objectClass,
PROP_LINK_TITLE,
g_param_spec_string("link-title",
_("Link Title"),
_("The link title"),
0,
paramFlags));
/**
* WebKitHitTestResult:link-label:
*
* The label of the link if flag %WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK
* is present in #WebKitHitTestResult:context
*/
g_object_class_install_property(objectClass,
PROP_LINK_LABEL,
g_param_spec_string("link-label",
_("Link Label"),
_("The link label"),
0,
paramFlags));
/**
* WebKitHitTestResult:image-uri:
*
* The URI of the image if flag %WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE
* is present in #WebKitHitTestResult:context
*/
g_object_class_install_property(objectClass,
PROP_IMAGE_URI,
g_param_spec_string("image-uri",
_("Image URI"),
_("The image URI"),
0,
paramFlags));
/**
* WebKitHitTestResult:media-uri:
*
* The URI of the media if flag %WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA
* is present in #WebKitHitTestResult:context
*/
g_object_class_install_property(objectClass,
PROP_MEDIA_URI,
g_param_spec_string("media-uri",
_("Media URI"),
_("The media URI"),
0,
paramFlags));
}
WebKitHitTestResult* webkitHitTestResultCreate(WebHitTestResult* hitTestResult)
{
unsigned context = WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT;
const String& linkURL = hitTestResult->absoluteLinkURL();
if (!linkURL.isEmpty())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
const String& imageURL = hitTestResult->absoluteImageURL();
if (!imageURL.isEmpty())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
const String& mediaURL = hitTestResult->absoluteMediaURL();
if (!mediaURL.isEmpty())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
if (hitTestResult->isContentEditable())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
if (hitTestResult->isScrollbar())
context |= WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR;
const String& linkTitle = hitTestResult->linkTitle();
const String& linkLabel = hitTestResult->linkLabel();
return WEBKIT_HIT_TEST_RESULT(g_object_new(WEBKIT_TYPE_HIT_TEST_RESULT,
"context", context,
"link-uri", !linkURL.isEmpty() ? linkURL.utf8().data() : 0,
"image-uri", !imageURL.isEmpty() ? imageURL.utf8().data() : 0,
"media-uri", !mediaURL.isEmpty() ? mediaURL.utf8().data() : 0,
"link-title", !linkTitle.isEmpty() ? linkTitle.utf8().data() : 0,
"link-label", !linkLabel.isEmpty() ? linkLabel.utf8().data() : 0,
NULL));
}
static bool stringIsEqualToCString(const String& string, const CString& cString)
{
return ((string.isEmpty() && cString.isNull()) || (string.utf8() == cString));
}
bool webkitHitTestResultCompare(WebKitHitTestResult* hitTestResult, WebHitTestResult* webHitTestResult)
{
WebKitHitTestResultPrivate* priv = hitTestResult->priv;
return webHitTestResult->isContentEditable() == webkit_hit_test_result_context_is_editable(hitTestResult)
&& webHitTestResult->isScrollbar() == webkit_hit_test_result_context_is_scrollbar(hitTestResult)
&& stringIsEqualToCString(webHitTestResult->absoluteLinkURL(), priv->linkURI)
&& stringIsEqualToCString(webHitTestResult->linkTitle(), priv->linkTitle)
&& stringIsEqualToCString(webHitTestResult->linkLabel(), priv->linkLabel)
&& stringIsEqualToCString(webHitTestResult->absoluteImageURL(), priv->imageURI)
&& stringIsEqualToCString(webHitTestResult->absoluteMediaURL(), priv->mediaURI);
}
/**
* webkit_hit_test_result_get_context:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:context property.
*
* Returns: a bitmask of #WebKitHitTestResultContext flags
*/
guint webkit_hit_test_result_get_context(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->context;
}
/**
* webkit_hit_test_result_context_is_link:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK flag is present in
* #WebKitHitTestResult:context.
*
* Returns: %TRUE if there's a link element in the coordinates of the Hit Test,
* or %FALSE otherwise
*/
gboolean webkit_hit_test_result_context_is_link(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK;
}
/**
* webkit_hit_test_result_context_is_image:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE flag is present in
* #WebKitHitTestResult:context.
*
* Returns: %TRUE if there's an image element in the coordinates of the Hit Test,
* or %FALSE otherwise
*/
gboolean webkit_hit_test_result_context_is_image(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE;
}
/**
* webkit_hit_test_result_context_is_media:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA flag is present in
* #WebKitHitTestResult:context.
*
* Returns: %TRUE if there's a media element in the coordinates of the Hit Test,
* or %FALSE otherwise
*/
gboolean webkit_hit_test_result_context_is_media(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_MEDIA;
}
/**
* webkit_hit_test_result_context_is_editable:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE flag is present in
* #WebKitHitTestResult:context.
*
* Returns: %TRUE if there's an editable element at the coordinates of the @hit_test_result,
* or %FALSE otherwise
*/
gboolean webkit_hit_test_result_context_is_editable(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE;
}
/**
* webkit_hit_test_result_get_link_uri:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:link-uri property.
*
* Returns: the URI of the link element in the coordinates of the Hit Test,
* or %NULL if there ins't a link element in @hit_test_result context
*/
const gchar* webkit_hit_test_result_get_link_uri(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->linkURI.data();
}
/**
* webkit_hit_test_result_get_link_title:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:link-title property.
*
* Returns: the title of the link element in the coordinates of the Hit Test,
* or %NULL if there ins't a link element in @hit_test_result context or the
* link element doesn't have a title
*/
const gchar* webkit_hit_test_result_get_link_title(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->linkTitle.data();
}
/**
* webkit_hit_test_result_get_link_label:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:link-label property.
*
* Returns: the label of the link element in the coordinates of the Hit Test,
* or %NULL if there ins't a link element in @hit_test_result context or the
* link element doesn't have a label
*/
const gchar* webkit_hit_test_result_get_link_label(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->linkLabel.data();
}
/**
* webkit_hit_test_result_get_image_uri:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:image-uri property.
*
* Returns: the URI of the image element in the coordinates of the Hit Test,
* or %NULL if there ins't an image element in @hit_test_result context
*/
const gchar* webkit_hit_test_result_get_image_uri(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->imageURI.data();
}
/**
* webkit_hit_test_result_get_media_uri:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets the value of the #WebKitHitTestResult:media-uri property.
*
* Returns: the URI of the media element in the coordinates of the Hit Test,
* or %NULL if there ins't a media element in @hit_test_result context
*/
const gchar* webkit_hit_test_result_get_media_uri(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), 0);
return hitTestResult->priv->mediaURI.data();
}
/**
* webkit_hit_test_result_context_is_scrollbar:
* @hit_test_result: a #WebKitHitTestResult
*
* Gets whether %WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR flag is present in
* #WebKitHitTestResult:context.
*
* Returns: %TRUE if there's a scrollbar element at the coordinates of the @hit_test_result,
* or %FALSE otherwise
*/
gboolean webkit_hit_test_result_context_is_scrollbar(WebKitHitTestResult* hitTestResult)
{
g_return_val_if_fail(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult), FALSE);
return hitTestResult->priv->context & WEBKIT_HIT_TEST_RESULT_CONTEXT_SCROLLBAR;
}
|