2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/html5parser/phase'
|
2007-05-30 17:45:52 +02:00
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
module HTML5
|
2007-05-30 17:45:52 +02:00
|
|
|
class InSelectPhase < Phase
|
|
|
|
|
|
|
|
# http://www.whatwg.org/specs/web-apps/current-work/#in-select
|
|
|
|
|
|
|
|
handle_start 'html', 'option', 'optgroup', 'select'
|
|
|
|
|
|
|
|
handle_end 'option', 'optgroup', 'select', %w( caption table tbody tfoot thead tr td th ) => 'TableElements'
|
|
|
|
|
|
|
|
def processCharacters(data)
|
|
|
|
@tree.insertText(data)
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOption(name, attributes)
|
|
|
|
# We need to imply </option> if <option> is the current node.
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.pop if @tree.open_elements.last.name == 'option'
|
|
|
|
@tree.insert_element(name, attributes)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOptgroup(name, attributes)
|
2007-08-30 19:19:10 +02:00
|
|
|
@tree.open_elements.pop if @tree.open_elements.last.name == 'option'
|
|
|
|
@tree.open_elements.pop if @tree.open_elements.last.name == 'optgroup'
|
|
|
|
@tree.insert_element(name, attributes)
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def startTagSelect(name, attributes)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-select-in-select")
|
2007-05-30 17:45:52 +02:00
|
|
|
endTagSelect('select')
|
|
|
|
end
|
|
|
|
|
|
|
|
def startTagOther(name, attributes)
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-start-tag-in-select", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def endTagOption(name)
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.open_elements.last.name == 'option'
|
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag-in-select", {"name" => "option"})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagOptgroup(name)
|
|
|
|
# </optgroup> implicitly closes <option>
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.open_elements.last.name == 'option' and @tree.open_elements[-2].name == 'optgroup'
|
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
# It also closes </optgroup>
|
2007-08-30 19:19:10 +02:00
|
|
|
if @tree.open_elements.last.name == 'optgroup'
|
|
|
|
@tree.open_elements.pop
|
2007-05-30 17:45:52 +02:00
|
|
|
# But nothing else
|
|
|
|
else
|
2007-09-10 05:26:19 +02:00
|
|
|
parse_error("unexpected-end-tag-in-select",
|
|
|
|
{"name" => "optgroup"})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagSelect(name)
|
|
|
|
if in_scope?('select', true)
|
|
|
|
remove_open_elements_until('select')
|
|
|
|
|
2007-08-30 19:19:10 +02:00
|
|
|
@parser.reset_insertion_mode
|
2007-05-30 17:45:52 +02:00
|
|
|
else
|
2007-08-30 19:19:10 +02:00
|
|
|
# inner_html case
|
|
|
|
parse_error
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagTableElements(name)
|
2007-10-06 18:55:58 +02:00
|
|
|
parse_error("unexpected-end-tag-in-select", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
|
|
|
|
if in_scope?(name, true)
|
|
|
|
endTagSelect('select')
|
|
|
|
@parser.phase.processEndTag(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def endTagOther(name)
|
2007-10-06 18:55:58 +02:00
|
|
|
parse_error("unexpected-end-tag-in-select", {"name" => name})
|
2007-05-30 17:45:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|