datatypes w = "http://whattf.org/datatype-draft"

# #####################################################################
##  RELAX NG Schema for HTML 5: Web Application Features              #
# #####################################################################

## Additions to Common Attributes

	common.attrs.interact &=
		(	common.attrs.contextmenu?
		&	common.attrs.contenteditable?
		&	common.attrs.draggable?
		&	common.attrs.dropzone?
		&	common.attrs.hidden?
		&	common.attrs.spellcheck?
		)
		
	common.attrs.other &= common.attrs.interact

## Context Menu: contextmenu

	common.attrs.contextmenu =
		attribute contextmenu {
			common.data.idref
		}

## Editable Content: contenteditable

	common.attrs.contenteditable =
		attribute contenteditable {
			w:string "true" | w:string "false" | w:string ""
		}

## Draggable Element: draggable

	common.attrs.draggable =
		attribute draggable {
			w:string "true" | w:string "false"
		}

## Dropzone: dropzone

	common.attrs.dropzone =
		attribute dropzone {
			list {
				(	xsd:string { pattern = "[sS][tT][rR][iI][nN][gG]:.+" }
				|	xsd:string { pattern = "[fF][iI][lL][eE]:.+" }
				)*
				,
				(	w:string "copy"
				|	w:string "move"
				|	w:string "link"
				)?
				,
				(	xsd:string { pattern = "[sS][tT][rR][iI][nN][gG]:.+" }
				|	xsd:string { pattern = "[fF][iI][lL][eE]:.+" }
				)*
			}
		}

## Hidden Element: hidden

	common.attrs.hidden =
		attribute hidden {
			w:string "hidden" | w:string ""
		}

## Spellchecking and grammar checking: spellcheck

	common.attrs.spellcheck =
		attribute spellcheck{
			w:string "true" | w:string "false" | w:string ""
		}

## Application Cache: manifest

	html.attrs.manifest =
		attribute manifest {
			common.data.uri.non-empty
		}
		
	html.attrs &= html.attrs.manifest?

## Progess Indicator: <progress>

	progress.elem =
		element progress { progress.inner & progress.attrs }
	progress.attrs =
		(	common.attrs
		&	progress.attrs.value?
		&	progress.attrs.max?
		&	(	common.attrs.aria.role.progressbar
			|	common.attrs.aria.role.presentation
			|	common.attrs.aria.role.menuitem
			)?
		)
		progress.attrs.value =
			attribute value {
				common.data.float.non-negative
			}
		progress.attrs.max =
			attribute max {
				common.data.float.positive
			}
	progress.inner =
		( common.inner.phrasing ) #Cannot enforce textContent format here

	common.elem.phrasing |= progress.elem

## Dialog box, inspector, or window: <dialog>
	dialog.elem =
		element dialog { dialog.inner & dialog.attrs }
	dialog.attrs =
		(	common.attrs
		&	dialog.attrs.open?
		&	(	common.attrs.aria.role.alert
			|	common.attrs.aria.role.alertdialog
			|	common.attrs.aria.role.contentinfo
			|	common.attrs.aria.role.dialog
			|	common.attrs.aria.role.log
			|	common.attrs.aria.role.marquee
			|	common.attrs.aria.role.region
			|	common.attrs.aria.role.status
			|	common.attrs.aria.landmark.application
			|	common.attrs.aria.landmark.document
			|	common.attrs.aria.landmark.main
			|	common.attrs.aria.landmark.search
			)?
		)
		dialog.attrs.open =
			attribute open {
				w:string "open" | w:string ""
			}
	dialog.inner =
		( common.inner.flow )
	common.elem.flow |= dialog.elem

## Command with an associated action: <command type='command'>

	command.command.elem =
		element command { command.inner & command.command.attrs }
	command.command.attrs =
		(	common.attrs
		&	command.command.attrs.type?
		&	common-command.attrs
		&	(	common.attrs.aria.role.presentation
			|	common.attrs.aria.role.menuitem
			)?
		)
		command.command.attrs.type =
			attribute type {
				w:string "command"
			}
	command.elem = command.command.elem

## Selection of one item from a list of items: <command type='radio'>

	command.radio.elem =
		element command { command.inner & command.radio.attrs }
	command.radio.attrs =
		(	common.attrs
		&	(	command.radio.attrs.type
			&	command.radio.attrs.radiogroup #REVISIT taking liberties here
			&	command.radio.attrs.checked?
			)
		&	common-command.attrs
		&	(	common.attrs.aria.role.presentation
			|	common.attrs.aria.role.menuitem
			)?
		)
		command.radio.attrs.type =
			attribute type {
				w:string "radio"
			}
		command.radio.attrs.radiogroup =
			attribute radiogroup {
				string #REVISIT need special format here?
			}
		command.radio.attrs.checked =
			attribute checked {
				w:string "checked" | w:string ""
			}
	command.elem |= command.radio.elem

## State or option that can be toggled: <command type='checkbox'>

	command.checkbox.elem =
		element command { command.inner & command.checkbox.attrs }
	command.checkbox.attrs =
		(	common.attrs
		&	(	command.checkbox.attrs.type
			&	command.checkbox.attrs.checked?
			)
		&	common-command.attrs
		&	(	common.attrs.aria.role.presentation
			|	common.attrs.aria.role.menuitem
			)?
		)
		command.checkbox.attrs.type =
			attribute type {
				w:string "checkbox"
			}
		command.checkbox.attrs.checked =
			attribute checked {
				w:string "checked" | w:string ""
			}
	command.elem |= command.checkbox.elem

	common-command.attrs =
		(	command.attrs.label?
		&	command.attrs.icon?
		&	command.attrs.disabled?
		)
		command.attrs.label =
			attribute label {
				string
			}
		command.attrs.icon =
			attribute icon {
				common.data.uri.non-empty
			}
		command.attrs.disabled =
			attribute disabled {
				w:string "disabled" | w:string ""
			}
	command.inner =
		( empty )
	
	common.elem.metadata |=
		( command.elem & nonHTMLizable )
	common.elem.phrasing |= command.elem

## Menu: <menu>

	menu.elem =
		element menu { menu.inner & menu.attrs }
	menu.attrs =
		(	common.attrs
		&	menu.attrs.type?
		&	menu.attrs.label?
		&	common.attrs.aria? # some roles only allowed if type is "toolbar" state; check in assertions
		)
		menu.attrs.type =
			attribute type {
				w:string "toolbar" | w:string "popup"
			}
		menu.attrs.label =
			attribute label {
				string
			}
	menu.inner =
		(	mli.elem*
		|	common.inner.flow
		)
	
	common.elem.flow |= menu.elem
	# REVISIT allow nested menus

## Menu Item: <li>

	mli.elem =
		element li { mli.inner & mli.attrs }
	mli.attrs =
		(	common.attrs
		&	(	(	common.attrs.aria.role.listitem
				|	common.attrs.aria.role.menuitemcheckbox
				|	common.attrs.aria.role.menuitemradio
				|	common.attrs.aria.role.option
				|	common.attrs.aria.role.treeitem
				|	common.attrs.aria.role.presentation
				)
			)?
		)
	mli.inner =
		( common.inner.flow )
	
## Canvas for Dynamic Graphics: <canvas>

	canvas.elem.flow =
		element canvas { canvas.inner.flow & canvas.attrs }
	canvas.elem.phrasing =
		element canvas { canvas.inner.phrasing & canvas.attrs }
	canvas.attrs =
		(	common.attrs
		&	canvas.attrs.height?
		&	canvas.attrs.width?
		&	common.attrs.aria?
		)
		canvas.attrs.height =
			attribute height {
				common.data.integer.non-negative
			}
		canvas.attrs.width =
			attribute width {
				common.data.integer.non-negative
			}
	canvas.inner.flow =
		( common.inner.transparent.flow )
	canvas.inner.phrasing =
		( common.inner.phrasing )
	
	common.elem.flow |= canvas.elem.flow
	common.elem.phrasing |= canvas.elem.phrasing

## Additional On-Demand Information: <details>

	details.elem =
		element details { details.inner & details.attrs }
	details.attrs =
		(	common.attrs
		&	details.attrs.open?
		&	(	common.attrs.aria.implicit.region # aria-expanded must be true if open attr present; check by assertions
			|	common.attrs.aria.role.alertdialog
			|	common.attrs.aria.role.banner
			|	common.attrs.aria.role.button
			|	common.attrs.aria.role.combobox
			|	common.attrs.aria.role.dialog
			|	common.attrs.aria.role.directory
			|	common.attrs.aria.role.heading
			|	common.attrs.aria.role.img
			|	common.attrs.aria.role.link
			|	common.attrs.aria.role.list
			|	common.attrs.aria.role.listbox
			|	common.attrs.aria.role.listitem
			|	common.attrs.aria.role.log
			|	common.attrs.aria.role.marquee
			|	common.attrs.aria.role.menu
			|	common.attrs.aria.role.menubar
			|	common.attrs.aria.role.note
			|	common.attrs.aria.role.status
			|	common.attrs.aria.role.tab
			|	common.attrs.aria.role.tablist
			|	common.attrs.aria.role.tabpanel
			|	common.attrs.aria.role.toolbar
			|	common.attrs.aria.role.tree
			|	common.attrs.aria.role.treeitem
			|	common.attrs.aria.landmark.application
			|	common.attrs.aria.landmark.article
			|	common.attrs.aria.landmark.complementary
			|	common.attrs.aria.landmark.contentinfo
			|	common.attrs.aria.landmark.document
			|	common.attrs.aria.landmark.form
			|	common.attrs.aria.landmark.main
			|	common.attrs.aria.landmark.navigation
			|	common.attrs.aria.landmark.search
			)?
		)
		details.attrs.open =
			attribute open {
				w:string "open" | w:string ""
			}
	details.inner =
		(	summary.elem
		,	common.inner.flow
		)
	
	common.elem.flow |= details.elem

## Caption/summary for details element: <summary>

	summary.elem =
		element summary { summary.inner & summary.attrs }
	summary.attrs =
		(	common.attrs
		&	(	common.attrs.aria.role.presentation
			|	common.attrs.aria.role.menuitem
			)?
		)
	summary.inner =
		( common.inner.phrasing )
