2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2007-08-20 06:39:49 +04:00
|
|
|
* Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
|
2003-06-30 16:44:03 +04:00
|
|
|
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
2005-03-26 04:12:27 +03:00
|
|
|
* Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2002-05-04 23:57:18 +04:00
|
|
|
*/
|
|
|
|
|
2004-07-19 18:31:31 +04:00
|
|
|
/** \file
|
2005-03-26 04:12:27 +03:00
|
|
|
* Box tree manipulation (implementation).
|
2004-07-19 18:31:31 +04:00
|
|
|
*/
|
|
|
|
|
2002-05-04 23:57:18 +04:00
|
|
|
#include <assert.h>
|
2003-07-15 02:57:45 +04:00
|
|
|
#include <stdbool.h>
|
2007-08-20 06:39:49 +04:00
|
|
|
#include <stdio.h>
|
2002-05-04 23:57:18 +04:00
|
|
|
#include <string.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/talloc.h"
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
2004-10-18 01:10:19 +04:00
|
|
|
static bool box_contains_point(struct box *box, int x, int y);
|
2003-07-05 01:17:53 +04:00
|
|
|
|
2004-08-02 00:28:02 +04:00
|
|
|
#define box_is_float(box) (box->type == BOX_FLOAT_LEFT || \
|
|
|
|
box->type == BOX_FLOAT_RIGHT)
|
|
|
|
|
2003-10-09 19:22:48 +04:00
|
|
|
|
2002-06-27 03:27:30 +04:00
|
|
|
/**
|
2003-10-09 19:22:48 +04:00
|
|
|
* Create a box tree node.
|
2004-12-10 01:22:13 +03:00
|
|
|
*
|
|
|
|
* \param style style for the box (not copied)
|
2005-04-09 13:47:37 +04:00
|
|
|
* \param href href for the box (not copied), or 0
|
2005-08-23 02:49:52 +04:00
|
|
|
* \param target target for the box (not copied), or 0
|
2005-04-09 13:47:37 +04:00
|
|
|
* \param title title for the box (not copied), or 0
|
|
|
|
* \param id id for the box (not copied), or 0
|
|
|
|
* \param context context for allocations
|
2004-12-10 01:22:13 +03:00
|
|
|
* \return allocated and initialised box, or 0 on memory exhaustion
|
2002-06-27 03:27:30 +04:00
|
|
|
*/
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
struct box * box_create(struct css_style *style,
|
2005-08-23 02:49:52 +04:00
|
|
|
char *href, const char *target, char *title, char *id,
|
2005-04-09 13:47:37 +04:00
|
|
|
void *context)
|
2002-06-27 03:27:30 +04:00
|
|
|
{
|
2004-02-02 03:22:59 +03:00
|
|
|
unsigned int i;
|
2004-08-14 16:57:02 +04:00
|
|
|
struct box *box;
|
2004-12-10 01:22:13 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
box = talloc(context, struct box);
|
2006-02-16 02:09:55 +03:00
|
|
|
if (!box) {
|
2004-12-10 01:22:13 +03:00
|
|
|
return 0;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
2004-08-14 16:57:02 +04:00
|
|
|
|
2003-07-05 20:16:15 +04:00
|
|
|
box->type = BOX_INLINE;
|
2002-06-27 03:27:30 +04:00
|
|
|
box->style = style;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->x = box->y = 0;
|
2002-09-19 23:54:43 +04:00
|
|
|
box->width = UNKNOWN_WIDTH;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->height = 0;
|
|
|
|
box->descendant_x0 = box->descendant_y0 = 0;
|
|
|
|
box->descendant_x1 = box->descendant_y1 = 0;
|
|
|
|
for (i = 0; i != 4; i++)
|
|
|
|
box->margin[i] = box->padding[i] = box->border[i] = 0;
|
2004-08-26 03:56:49 +04:00
|
|
|
box->scroll_x = box->scroll_y = 0;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->min_width = 0;
|
2002-09-18 23:36:28 +04:00
|
|
|
box->max_width = UNKNOWN_MAX_WIDTH;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->text = NULL;
|
|
|
|
box->length = 0;
|
2003-07-05 01:17:53 +04:00
|
|
|
box->space = 0;
|
2003-09-10 01:43:44 +04:00
|
|
|
box->clone = 0;
|
2006-04-04 14:56:21 +04:00
|
|
|
box->strip_leading_newline = 0;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->href = href;
|
2005-08-23 02:49:52 +04:00
|
|
|
box->target = target;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->title = title;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->columns = 1;
|
|
|
|
box->rows = 1;
|
2003-07-07 01:10:12 +04:00
|
|
|
box->start_column = 0;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->next = NULL;
|
|
|
|
box->prev = NULL;
|
|
|
|
box->children = NULL;
|
|
|
|
box->last = NULL;
|
|
|
|
box->parent = NULL;
|
2005-04-14 01:58:28 +04:00
|
|
|
box->fallback = NULL;
|
2005-06-06 00:54:37 +04:00
|
|
|
box->inline_end = NULL;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->float_children = NULL;
|
|
|
|
box->next_float = NULL;
|
2006-11-05 15:58:24 +03:00
|
|
|
box->list_marker = NULL;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->col = NULL;
|
|
|
|
box->gadget = NULL;
|
|
|
|
box->usemap = NULL;
|
2005-04-09 13:47:37 +04:00
|
|
|
box->id = id;
|
2004-08-14 16:57:02 +04:00
|
|
|
box->background = NULL;
|
|
|
|
box->object = NULL;
|
|
|
|
box->object_params = NULL;
|
|
|
|
|
2002-06-27 03:27:30 +04:00
|
|
|
return box;
|
|
|
|
}
|
2002-05-04 23:57:18 +04:00
|
|
|
|
2002-09-12 01:19:24 +04:00
|
|
|
|
2003-10-09 19:22:48 +04:00
|
|
|
/**
|
2005-03-26 04:12:27 +03:00
|
|
|
* Add a child to a box tree node.
|
2005-01-01 17:51:35 +03:00
|
|
|
*
|
2005-03-26 04:12:27 +03:00
|
|
|
* \param parent box giving birth
|
|
|
|
* \param child box to link as last child of parent
|
2002-08-18 20:46:45 +04:00
|
|
|
*/
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
void box_add_child(struct box *parent, struct box *child)
|
2002-08-18 20:46:45 +04:00
|
|
|
{
|
2005-06-06 00:54:37 +04:00
|
|
|
assert(parent);
|
|
|
|
assert(child);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
if (parent->children != 0) { /* has children already */
|
|
|
|
parent->last->next = child;
|
|
|
|
child->prev = parent->last;
|
|
|
|
} else { /* this is the first child */
|
|
|
|
parent->children = child;
|
|
|
|
child->prev = 0;
|
2003-01-02 16:26:43 +03:00
|
|
|
}
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
parent->last = child;
|
|
|
|
child->parent = parent;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
|
|
|
* Insert a new box as a sibling to a box in a tree.
|
|
|
|
*
|
|
|
|
* \param box box already in tree
|
|
|
|
* \param new_box box to link into tree as next sibling
|
|
|
|
*/
|
2005-01-01 17:51:35 +03:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
void box_insert_sibling(struct box *box, struct box *new_box)
|
|
|
|
{
|
|
|
|
new_box->parent = box->parent;
|
|
|
|
new_box->prev = box;
|
|
|
|
new_box->next = box->next;
|
|
|
|
box->next = new_box;
|
|
|
|
if (new_box->next)
|
|
|
|
new_box->next->prev = new_box;
|
|
|
|
else if (new_box->parent)
|
|
|
|
new_box->parent->last = new_box;
|
2002-08-18 20:46:45 +04:00
|
|
|
}
|
2002-09-08 22:11:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-04-20 16:24:41 +04:00
|
|
|
* Unlink a box from the box tree and then free it recursively.
|
|
|
|
*
|
|
|
|
* \param box box to unlink and free recursively.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_unlink_and_free(struct box *box)
|
|
|
|
{
|
|
|
|
struct box *parent = box->parent;
|
|
|
|
struct box *next = box->next;
|
|
|
|
struct box *prev = box->prev;
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
if (parent->children == box)
|
|
|
|
parent->children = next;
|
|
|
|
if (parent->last == box)
|
|
|
|
parent->last = next ? next : prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prev)
|
|
|
|
prev->next = next;
|
|
|
|
if (next)
|
|
|
|
next->prev = prev;
|
|
|
|
|
|
|
|
box_free(box);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a box tree recursively.
|
2005-03-26 04:12:27 +03:00
|
|
|
*
|
|
|
|
* \param box box to free recursively
|
|
|
|
*
|
2005-04-09 13:47:37 +04:00
|
|
|
* The box and all its children is freed.
|
2002-09-08 22:11:56 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void box_free(struct box *box)
|
|
|
|
{
|
2003-09-20 01:23:19 +04:00
|
|
|
struct box *child, *next;
|
2002-09-08 22:11:56 +04:00
|
|
|
|
2003-09-20 01:23:19 +04:00
|
|
|
/* free children first */
|
|
|
|
for (child = box->children; child; child = next) {
|
|
|
|
next = child->next;
|
|
|
|
box_free(child);
|
|
|
|
}
|
2006-06-27 00:16:24 +04:00
|
|
|
|
2002-09-08 22:11:56 +04:00
|
|
|
/* last this box */
|
2003-01-02 16:26:43 +03:00
|
|
|
box_free_box(box);
|
|
|
|
}
|
|
|
|
|
2004-05-21 18:26:59 +04:00
|
|
|
|
|
|
|
/**
|
2005-03-26 04:12:27 +03:00
|
|
|
* Free the data in a single box structure.
|
|
|
|
*
|
|
|
|
* \param box box to free
|
2004-05-21 18:26:59 +04:00
|
|
|
*/
|
|
|
|
|
2003-01-02 16:26:43 +03:00
|
|
|
void box_free_box(struct box *box)
|
|
|
|
{
|
2003-09-20 01:23:19 +04:00
|
|
|
if (!box->clone) {
|
2004-05-21 18:26:59 +04:00
|
|
|
if (box->gadget)
|
|
|
|
form_free_control(box->gadget);
|
2002-12-30 01:27:35 +03:00
|
|
|
}
|
2002-12-30 05:06:03 +03:00
|
|
|
|
2005-04-09 13:47:37 +04:00
|
|
|
talloc_free(box);
|
2002-09-08 22:11:56 +04:00
|
|
|
}
|
2002-12-30 01:27:35 +03:00
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
/**
|
|
|
|
* Find the absolute coordinates of a box.
|
|
|
|
*
|
|
|
|
* \param box the box to calculate coordinates of
|
|
|
|
* \param x updated to x coordinate
|
|
|
|
* \param y updated to y coordinate
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_coords(struct box *box, int *x, int *y)
|
|
|
|
{
|
|
|
|
*x = box->x;
|
|
|
|
*y = box->y;
|
|
|
|
while (box->parent) {
|
2004-08-02 00:28:02 +04:00
|
|
|
if (box_is_float(box)) {
|
2004-07-18 03:32:09 +04:00
|
|
|
do {
|
|
|
|
box = box->parent;
|
|
|
|
} while (!box->float_children);
|
|
|
|
} else
|
|
|
|
box = box->parent;
|
2004-10-18 01:10:19 +04:00
|
|
|
*x += box->x - box->scroll_x;
|
|
|
|
*y += box->y - box->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
/**
|
|
|
|
* Find the bounds of a box.
|
|
|
|
*
|
|
|
|
* \param box the box to calculate bounds of
|
|
|
|
* \param r receives bounds
|
|
|
|
*/
|
|
|
|
|
|
|
|
void box_bounds(struct box *box, struct rect *r)
|
|
|
|
{
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
box_coords(box, &r->x0, &r->y0);
|
|
|
|
|
|
|
|
width = box->padding[LEFT] + box->width + box->padding[RIGHT];
|
|
|
|
height = box->padding[TOP] + box->height + box->padding[BOTTOM];
|
|
|
|
|
|
|
|
r->x1 = r->x0 + width;
|
|
|
|
r->y1 = r->y0 + height;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
/**
|
|
|
|
* Find the boxes at a point.
|
|
|
|
*
|
|
|
|
* \param box box to search children of
|
2004-10-18 01:10:19 +04:00
|
|
|
* \param x point to find, in global document coordinates
|
2004-07-18 03:32:09 +04:00
|
|
|
* \param y point to find, in global document coordinates
|
|
|
|
* \param box_x position of box, in global document coordinates, updated
|
|
|
|
* to position of returned box, if any
|
|
|
|
* \param box_y position of box, in global document coordinates, updated
|
|
|
|
* to position of returned box, if any
|
|
|
|
* \param content updated to content of object that returned box is in, if any
|
|
|
|
* \return box at given point, or 0 if none found
|
|
|
|
*
|
2006-02-16 02:09:55 +03:00
|
|
|
* To find all the boxes in the hierarchy at a certain point, use code like
|
2004-07-18 03:32:09 +04:00
|
|
|
* this:
|
|
|
|
* \code
|
|
|
|
* struct box *box = top_of_document_to_search;
|
|
|
|
* int box_x = 0, box_y = 0;
|
|
|
|
* struct content *content = document_to_search;
|
|
|
|
*
|
|
|
|
* while ((box = box_at_point(box, x, y, &box_x, &box_y, &content))) {
|
|
|
|
* // process box
|
|
|
|
* }
|
|
|
|
* \endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box *box_at_point(struct box *box, int x, int y,
|
|
|
|
int *box_x, int *box_y,
|
|
|
|
struct content **content)
|
|
|
|
{
|
2004-08-02 00:28:02 +04:00
|
|
|
int bx = *box_x, by = *box_y;
|
|
|
|
struct box *child, *sibling;
|
2004-07-18 03:32:09 +04:00
|
|
|
|
|
|
|
assert(box);
|
|
|
|
|
|
|
|
/* drill into HTML objects */
|
|
|
|
if (box->object) {
|
|
|
|
if (box->object->type == CONTENT_HTML &&
|
|
|
|
box->object->data.html.layout) {
|
|
|
|
*content = box->object;
|
|
|
|
box = box->object->data.html.layout;
|
|
|
|
} else {
|
2004-08-02 00:28:02 +04:00
|
|
|
goto siblings;
|
2004-07-18 03:32:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-27 00:16:24 +04:00
|
|
|
/* consider floats second, since they will often overlap other boxes */
|
2004-07-18 03:32:09 +04:00
|
|
|
for (child = box->float_children; child; child = child->next_float) {
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(child, x - bx, y - by)) {
|
2006-05-25 02:55:37 +04:00
|
|
|
*box_x = bx + child->x - child->scroll_x;
|
|
|
|
*box_y = by + child->y - child->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 02:55:37 +04:00
|
|
|
non_float_children:
|
2004-07-18 03:32:09 +04:00
|
|
|
/* non-float children */
|
|
|
|
for (child = box->children; child; child = child->next) {
|
2004-08-02 00:28:02 +04:00
|
|
|
if (box_is_float(child))
|
2004-07-18 03:32:09 +04:00
|
|
|
continue;
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(child, x - bx, y - by)) {
|
2006-05-25 02:55:37 +04:00
|
|
|
*box_x = bx + child->x - child->scroll_x;
|
|
|
|
*box_y = by + child->y - child->scroll_y;
|
2004-07-18 03:32:09 +04:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-07 13:00:21 +04:00
|
|
|
/* marker boxes */
|
|
|
|
if (box->list_marker) {
|
|
|
|
if (box_contains_point(box->list_marker, x - bx, y - by)) {
|
|
|
|
*box_x = bx + box->list_marker->x -
|
|
|
|
box->list_marker->scroll_x;
|
|
|
|
*box_y = by + box->list_marker->y -
|
|
|
|
box->list_marker->scroll_y;
|
|
|
|
return box->list_marker;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-02 00:28:02 +04:00
|
|
|
siblings:
|
|
|
|
/* siblings and siblings of ancestors */
|
|
|
|
while (box) {
|
2006-05-25 02:55:37 +04:00
|
|
|
if (box_is_float(box)) {
|
2004-10-18 01:10:19 +04:00
|
|
|
bx -= box->x - box->scroll_x;
|
|
|
|
by -= box->y - box->scroll_y;
|
2006-05-25 02:55:37 +04:00
|
|
|
for (sibling = box->next_float; sibling;
|
|
|
|
sibling = sibling->next_float) {
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(sibling,
|
|
|
|
x - bx, y - by)) {
|
|
|
|
*box_x = bx + sibling->x -
|
|
|
|
sibling->scroll_x;
|
|
|
|
*box_y = by + sibling->y -
|
|
|
|
sibling->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
return sibling;
|
|
|
|
}
|
|
|
|
}
|
2006-05-25 02:55:37 +04:00
|
|
|
/* ascend to float's parent */
|
|
|
|
do {
|
|
|
|
box = box->parent;
|
|
|
|
} while (!box->float_children);
|
|
|
|
/* process non-float children of float's parent */
|
|
|
|
goto non_float_children;
|
|
|
|
|
2004-08-02 00:28:02 +04:00
|
|
|
} else {
|
2004-10-18 01:10:19 +04:00
|
|
|
bx -= box->x - box->scroll_x;
|
|
|
|
by -= box->y - box->scroll_y;
|
2006-05-25 02:55:37 +04:00
|
|
|
for (sibling = box->next; sibling;
|
|
|
|
sibling = sibling->next) {
|
|
|
|
if (box_is_float(sibling))
|
|
|
|
continue;
|
2004-10-18 01:10:19 +04:00
|
|
|
if (box_contains_point(sibling,
|
|
|
|
x - bx, y - by)) {
|
|
|
|
*box_x = bx + sibling->x -
|
|
|
|
sibling->scroll_x;
|
|
|
|
*box_y = by + sibling->y -
|
|
|
|
sibling->scroll_y;
|
2004-08-02 00:28:02 +04:00
|
|
|
return sibling;
|
|
|
|
}
|
|
|
|
}
|
2006-05-25 02:55:37 +04:00
|
|
|
box = box->parent;
|
2004-08-02 00:28:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-18 03:32:09 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2004-07-18 21:38:01 +04:00
|
|
|
|
|
|
|
|
2004-10-18 01:10:19 +04:00
|
|
|
/**
|
|
|
|
* Determine if a point lies within a box.
|
|
|
|
*
|
|
|
|
* \param box box to consider
|
|
|
|
* \param x coordinate relative to box parent
|
|
|
|
* \param y coordinate relative to box parent
|
|
|
|
* \return true if the point is within the box or a descendant box
|
|
|
|
*
|
|
|
|
* This is a helper function for box_at_point().
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool box_contains_point(struct box *box, int x, int y)
|
|
|
|
{
|
2005-08-15 01:43:36 +04:00
|
|
|
if ((box->style && box->style->overflow != CSS_OVERFLOW_VISIBLE) ||
|
|
|
|
box->inline_end) {
|
2005-03-19 17:23:47 +03:00
|
|
|
if (box->x <= x + box->border[LEFT] &&
|
|
|
|
x < box->x + box->padding[LEFT] + box->width +
|
2005-03-19 02:50:36 +03:00
|
|
|
box->border[RIGHT] + box->padding[RIGHT] &&
|
2005-03-19 17:23:47 +03:00
|
|
|
box->y <= y + box->border[TOP] &&
|
|
|
|
y < box->y + box->padding[TOP] + box->height +
|
2005-03-19 02:50:36 +03:00
|
|
|
box->border[BOTTOM] + box->padding[BOTTOM])
|
2004-10-18 01:10:19 +04:00
|
|
|
return true;
|
2008-04-07 13:00:21 +04:00
|
|
|
if (box->list_marker && box->list_marker->x <= x +
|
|
|
|
box->list_marker->border[LEFT] &&
|
|
|
|
x < box->list_marker->x +
|
|
|
|
box->list_marker->padding[LEFT] +
|
|
|
|
box->list_marker->width +
|
|
|
|
box->list_marker->border[RIGHT] +
|
|
|
|
box->list_marker->padding[RIGHT] &&
|
|
|
|
box->list_marker->y <= y +
|
|
|
|
box->list_marker->border[TOP] &&
|
|
|
|
y < box->list_marker->y +
|
|
|
|
box->list_marker->padding[TOP] +
|
|
|
|
box->list_marker->height +
|
|
|
|
box->list_marker->border[BOTTOM] +
|
|
|
|
box->list_marker->padding[BOTTOM]) {
|
|
|
|
return true;
|
|
|
|
}
|
2004-10-18 01:10:19 +04:00
|
|
|
} else {
|
|
|
|
if (box->x + box->descendant_x0 <= x &&
|
|
|
|
x < box->x + box->descendant_x1 &&
|
|
|
|
box->y + box->descendant_y0 <= y &&
|
|
|
|
y < box->y + box->descendant_y1)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-18 21:38:01 +04:00
|
|
|
/**
|
|
|
|
* Find the box containing an object at the given coordinates, if any.
|
|
|
|
*
|
|
|
|
* \param c content to search, must have type CONTENT_HTML
|
|
|
|
* \param x coordinates in document units
|
|
|
|
* \param y coordinates in document units
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct box *box_object_at_point(struct content *c, int x, int y)
|
|
|
|
{
|
|
|
|
struct box *box = c->data.html.layout;
|
|
|
|
int box_x = 0, box_y = 0;
|
|
|
|
struct content *content = c;
|
|
|
|
struct box *object_box = 0;
|
|
|
|
|
|
|
|
assert(c->type == CONTENT_HTML);
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
while ((box = box_at_point(box, x, y, &box_x, &box_y, &content))) {
|
2004-07-18 21:38:01 +04:00
|
|
|
if (box->style &&
|
|
|
|
box->style->visibility == CSS_VISIBILITY_HIDDEN)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (box->object)
|
|
|
|
object_box = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
return object_box;
|
|
|
|
}
|
2004-08-07 02:19:13 +04:00
|
|
|
|
2004-08-26 02:11:38 +04:00
|
|
|
|
2004-08-07 02:19:13 +04:00
|
|
|
/**
|
2004-08-26 02:11:38 +04:00
|
|
|
* Find a box based upon its id attribute.
|
2004-08-07 02:19:13 +04:00
|
|
|
*
|
2005-03-26 04:12:27 +03:00
|
|
|
* \param box box tree to search
|
|
|
|
* \param id id to look for
|
|
|
|
* \return the box or 0 if not found
|
2004-08-07 02:19:13 +04:00
|
|
|
*/
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
struct box *box_find_by_id(struct box *box, const char *id)
|
2004-08-07 02:19:13 +04:00
|
|
|
{
|
|
|
|
struct box *a, *b;
|
|
|
|
|
2004-08-26 02:11:38 +04:00
|
|
|
if (box->id != NULL && strcmp(id, box->id) == 0)
|
2004-08-07 02:19:13 +04:00
|
|
|
return box;
|
|
|
|
|
|
|
|
for (a = box->children; a; a = a->next) {
|
2004-08-26 02:11:38 +04:00
|
|
|
if ((b = box_find_by_id(a, id)) != NULL)
|
2004-08-07 02:19:13 +04:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
2004-08-14 18:30:12 +04:00
|
|
|
return NULL;
|
2004-08-07 02:19:13 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
|
2007-01-01 02:47:17 +03:00
|
|
|
/**
|
|
|
|
* Determine if a box is visible when the tree is rendered.
|
|
|
|
*
|
|
|
|
* \param box box to check
|
|
|
|
* \return true iff the box is rendered
|
|
|
|
*/
|
|
|
|
|
2007-01-14 16:02:09 +03:00
|
|
|
bool box_visible(struct box *box)
|
2007-01-01 02:47:17 +03:00
|
|
|
{
|
|
|
|
struct box *fallback;
|
|
|
|
|
|
|
|
/* visibility: hidden */
|
|
|
|
if (box->style && box->style->visibility == CSS_VISIBILITY_HIDDEN)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* check if a fallback */
|
|
|
|
while (box->parent) {
|
|
|
|
for (fallback = box->parent->fallback; fallback;
|
|
|
|
fallback = fallback->next)
|
|
|
|
if (fallback == box)
|
|
|
|
return false;
|
|
|
|
box = box->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-26 04:12:27 +03:00
|
|
|
/**
|
2007-08-20 06:39:49 +04:00
|
|
|
* Print a box tree to a file.
|
2005-03-26 04:12:27 +03:00
|
|
|
*/
|
|
|
|
|
2007-08-20 06:39:49 +04:00
|
|
|
void box_dump(FILE *stream, struct box *box, unsigned int depth)
|
2005-03-26 04:12:27 +03:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2005-04-14 01:58:28 +04:00
|
|
|
struct box *c, *prev;
|
2005-03-26 04:12:27 +03:00
|
|
|
|
|
|
|
for (i = 0; i != depth; i++)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " ");
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "%p ", box);
|
|
|
|
fprintf(stream, "x%i y%i w%i h%i ", box->x, box->y,
|
2005-03-26 04:12:27 +03:00
|
|
|
box->width, box->height);
|
|
|
|
if (box->max_width != UNKNOWN_MAX_WIDTH)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "min%i max%i ", box->min_width, box->max_width);
|
|
|
|
fprintf(stream, "(%i %i %i %i) ",
|
2005-03-26 04:12:27 +03:00
|
|
|
box->descendant_x0, box->descendant_y0,
|
|
|
|
box->descendant_x1, box->descendant_y1);
|
|
|
|
|
|
|
|
switch (box->type) {
|
2007-08-20 06:39:49 +04:00
|
|
|
case BOX_BLOCK: fprintf(stream, "BLOCK "); break;
|
|
|
|
case BOX_INLINE_CONTAINER: fprintf(stream, "INLINE_CONTAINER "); break;
|
|
|
|
case BOX_INLINE: fprintf(stream, "INLINE "); break;
|
|
|
|
case BOX_INLINE_END: fprintf(stream, "INLINE_END "); break;
|
|
|
|
case BOX_INLINE_BLOCK: fprintf(stream, "INLINE_BLOCK "); break;
|
|
|
|
case BOX_TABLE: fprintf(stream, "TABLE [columns %i] ",
|
2005-03-26 04:12:27 +03:00
|
|
|
box->columns); break;
|
2007-08-20 06:39:49 +04:00
|
|
|
case BOX_TABLE_ROW: fprintf(stream, "TABLE_ROW "); break;
|
|
|
|
case BOX_TABLE_CELL: fprintf(stream, "TABLE_CELL [columns %i, "
|
2005-03-26 04:12:27 +03:00
|
|
|
"start %i, rows %i] ", box->columns,
|
|
|
|
box->start_column, box->rows); break;
|
2007-08-20 06:39:49 +04:00
|
|
|
case BOX_TABLE_ROW_GROUP: fprintf(stream, "TABLE_ROW_GROUP "); break;
|
|
|
|
case BOX_FLOAT_LEFT: fprintf(stream, "FLOAT_LEFT "); break;
|
|
|
|
case BOX_FLOAT_RIGHT: fprintf(stream, "FLOAT_RIGHT "); break;
|
|
|
|
case BOX_BR: fprintf(stream, "BR "); break;
|
|
|
|
case BOX_TEXT: fprintf(stream, "TEXT "); break;
|
|
|
|
default: fprintf(stream, "Unknown box type ");
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (box->text)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "%li '%.*s' ", (unsigned long) box->byte_offset,
|
2006-05-25 02:55:37 +04:00
|
|
|
(int) box->length, box->text);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->space)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "space ");
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->object)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "(object '%s') ", box->object->url);
|
2008-01-28 16:48:59 +03:00
|
|
|
if (box->gadget)
|
|
|
|
fprintf(stream, "(gadget) ");
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->style)
|
|
|
|
css_dump_style(box->style);
|
2005-08-21 02:52:20 +04:00
|
|
|
if (box->href)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " -> '%s'", box->href);
|
2005-08-21 02:52:20 +04:00
|
|
|
if (box->target)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " |%s|", box->target);
|
2005-08-21 02:52:20 +04:00
|
|
|
if (box->title)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " [%s]", box->title);
|
2005-08-21 02:52:20 +04:00
|
|
|
if (box->id)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " <%s>", box->id);
|
2005-06-06 00:54:37 +04:00
|
|
|
if (box->type == BOX_INLINE || box->type == BOX_INLINE_END)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " inline_end %p", box->inline_end);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->float_children)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " float_children %p", box->float_children);
|
2005-03-26 04:12:27 +03:00
|
|
|
if (box->next_float)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " next_float %p", box->next_float);
|
2005-07-02 21:49:40 +04:00
|
|
|
if (box->col) {
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " (columns");
|
2005-07-02 21:49:40 +04:00
|
|
|
for (i = 0; i != box->columns; i++)
|
2008-04-20 19:49:25 +04:00
|
|
|
fprintf(stream, " (%s %s %i %i %i)",
|
2005-07-02 21:49:40 +04:00
|
|
|
((const char *[]) {"UNKNOWN", "FIXED",
|
|
|
|
"AUTO", "PERCENT", "RELATIVE"})
|
|
|
|
[box->col[i].type],
|
2008-04-20 19:49:25 +04:00
|
|
|
((const char *[]) {"normal",
|
|
|
|
"positioned"})
|
|
|
|
[box->col[i].positioned],
|
2005-07-02 21:49:40 +04:00
|
|
|
box->col[i].width,
|
|
|
|
box->col[i].min, box->col[i].max);
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, ")");
|
2005-07-02 21:49:40 +04:00
|
|
|
}
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "\n");
|
2005-03-26 04:12:27 +03:00
|
|
|
|
2006-11-05 15:58:24 +03:00
|
|
|
if (box->list_marker) {
|
|
|
|
for (i = 0; i != depth; i++)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " ");
|
|
|
|
fprintf(stream, "list_marker:\n");
|
|
|
|
box_dump(stream, box->list_marker, depth + 1);
|
2006-11-05 15:58:24 +03:00
|
|
|
}
|
|
|
|
|
2005-04-17 20:42:37 +04:00
|
|
|
for (c = box->children; c && c->next; c = c->next)
|
2005-04-14 01:58:28 +04:00
|
|
|
;
|
|
|
|
if (box->last != c)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "warning: box->last %p (should be %p) "
|
2005-04-14 01:58:28 +04:00
|
|
|
"(box %p)\n", box->last, c, box);
|
|
|
|
for (prev = 0, c = box->children; c; prev = c, c = c->next) {
|
|
|
|
if (c->parent != box)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "warning: box->parent %p (should be "
|
2005-04-14 01:58:28 +04:00
|
|
|
"%p) (box on next line)\n",
|
|
|
|
c->parent, box);
|
|
|
|
if (c->prev != prev)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, "warning: box->prev %p (should be "
|
2005-04-14 01:58:28 +04:00
|
|
|
"%p) (box on next line)\n",
|
|
|
|
c->prev, prev);
|
2007-08-20 06:39:49 +04:00
|
|
|
box_dump(stream, c, depth + 1);
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
|
|
|
if (box->fallback) {
|
|
|
|
for (i = 0; i != depth; i++)
|
2007-08-20 06:39:49 +04:00
|
|
|
fprintf(stream, " ");
|
|
|
|
fprintf(stream, "fallback:\n");
|
2005-04-14 01:58:28 +04:00
|
|
|
for (c = box->fallback; c; c = c->next)
|
2007-08-20 06:39:49 +04:00
|
|
|
box_dump(stream, c, depth + 1);
|
2005-04-14 01:58:28 +04:00
|
|
|
}
|
2005-03-26 04:12:27 +03:00
|
|
|
}
|