summaryrefslogtreecommitdiff
path: root/src/treebuilder/in_select_in_table.c
blob: 69d420393a78f469dc91fed45096334113488722 (plain)
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
/*
 * This file is part of Hubbub.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2008 Andrew Sidwell <takkaria@netsurf-browser.org>
 */

#include <assert.h>
#include <string.h>

#include "treebuilder/modes.h"
#include "treebuilder/internal.h"
#include "treebuilder/treebuilder.h"
#include "utils/utils.h"


/**
 * Handle token in "in select in table" insertion mode
 *
 * \param treebuilder  The treebuilder instance
 * \param token        The token to handle
 * \return True to reprocess token, false otherwise
 */
hubbub_error handle_in_select_in_table(hubbub_treebuilder *treebuilder,
		const hubbub_token *token)
{
	bool handled = false;
	hubbub_error err = HUBBUB_OK;

	if (token->type == HUBBUB_TOKEN_END_TAG ||
			token->type == HUBBUB_TOKEN_START_TAG) {
		element_type type = element_type_from_name(treebuilder,
				&token->data.tag.name);

		if (type == CAPTION || type == TABLE || type == TBODY ||
				type == TFOOT || type == THEAD || type == TR ||
				type == TD || type == TH) {
			/** \todo parse error */

			handled = true;

			if ((token->type == HUBBUB_TOKEN_END_TAG &&
					element_in_scope(treebuilder, type,
							true, false)) ||
					token->type == HUBBUB_TOKEN_START_TAG) {
				/** \todo fragment case */

				element_stack_pop_until(treebuilder, 
						SELECT);
				reset_insertion_mode(treebuilder);
				err = HUBBUB_REPROCESS;
			}
		}
	}

	if (!handled) {
		err = handle_in_select(treebuilder, token);
	}

	return err;
}