1
namespace eval hv3 { set {version($Id: hv3_dom_style.tcl,v 1.15 2007/10/17 17:45:07 danielk1977 Exp $)} 1 }
3
#-------------------------------------------------------------------------
6
# This file contains the Hv3 implementation of the DOM Level 2 Style
9
# ElementCSSInlineStyle (mixed into Element)
10
# CSSStyleDeclaration (mixed into ElementCSSInlineStyle)
11
# CSS2Properties (mixed into CSSStyleDeclaration)
13
# http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html
17
# Set up an array of known "simple" properties. This is used during
18
# DOM compilation and at runtime.
20
set ::hv3::DOM::CSS2Properties_simple(width) width
21
set ::hv3::DOM::CSS2Properties_simple(height) height
22
set ::hv3::DOM::CSS2Properties_simple(display) display
23
set ::hv3::DOM::CSS2Properties_simple(position) position
24
set ::hv3::DOM::CSS2Properties_simple(top) top
25
set ::hv3::DOM::CSS2Properties_simple(left) left
26
set ::hv3::DOM::CSS2Properties_simple(bottom) bottom
27
set ::hv3::DOM::CSS2Properties_simple(right) right
28
set ::hv3::DOM::CSS2Properties_simple(z-index) zIndex
29
set ::hv3::DOM::CSS2Properties_simple(cursor) cursor
30
set ::hv3::DOM::CSS2Properties_simple(float) cssFloat
31
set ::hv3::DOM::CSS2Properties_simple(font-size) fontSize
32
set ::hv3::DOM::CSS2Properties_simple(clear) clear
33
set ::hv3::DOM::CSS2Properties_simple(border-top-width) borderTopWidth
34
set ::hv3::DOM::CSS2Properties_simple(border-right-width) borderRightWidth
35
set ::hv3::DOM::CSS2Properties_simple(border-left-width) borderLeftWidth
36
set ::hv3::DOM::CSS2Properties_simple(border-bottom-width) borderBottomWidth
37
set ::hv3::DOM::CSS2Properties_simple(margin-top) marginTop
38
set ::hv3::DOM::CSS2Properties_simple(margin-right) marginRight
39
set ::hv3::DOM::CSS2Properties_simple(margin-left) marginLeft
40
set ::hv3::DOM::CSS2Properties_simple(margin-bottom) marginBottom
41
set ::hv3::DOM::CSS2Properties_simple(visibility) visibility
43
set ::hv3::DOM::CSS2Properties_simple(background-color) backgroundColor
44
set ::hv3::DOM::CSS2Properties_simple(background-image) backgroundImage
47
set ::hv3::dom::code::ELEMENTCSSINLINESTYLE {
48
-- A reference to the [Ref CSSStyleDeclaration] object used to access
49
-- the HTML \"style\" attribute of this document element.
52
list object [list ::hv3::DOM::CSSStyleDeclaration $myDom $myNode]
56
set ::hv3::dom::code::CSS2PROPERTIES {
60
foreach {k v} [array get ::hv3::DOM::CSS2Properties_simple] {
61
if {$v eq ""} { set v $k }
63
CSSStyleDeclaration.getStyleProperty \$myNode $k
65
dom_put -string $v value "
66
CSSStyleDeclaration.setStyleProperty \$myNode $k \$value
72
dom_put -string border value {
73
set style [$myNode attribute -default {} style]
74
if {$style ne ""} {append style ";"}
75
append style "border: $value"
76
$myNode attribute style $style
79
dom_put -string background value {
80
array set current [$myNode prop -inline]
81
unset -nocomplain current(background-color)
82
unset -nocomplain current(background-image)
83
unset -nocomplain current(background-repeat)
84
unset -nocomplain current(background-attachment)
85
unset -nocomplain current(background-position)
86
unset -nocomplain current(background-position-y)
87
unset -nocomplain current(background-position-x)
89
set style "background:$value;"
90
foreach prop [array names current] {
91
append style "$prop:$current($prop);"
93
$myNode attribute style $style
97
# In a complete implementation of the DOM Level 2 style for an HTML
98
# browser, the CSSStyleDeclaration interface is used for two purposes:
100
# * As the ElementCSSInlineStyle.style property object. This
101
# represents the contents of an HTML "style" attribute.
103
# * As part of the DOM representation of a parsed stylesheet
104
# document. Hv3 does not implement this function.
106
::hv3::dom2::stateless CSSStyleDeclaration {
109
# cssText attribute - access the text of the style declaration.
110
# TODO: Setting this to a value that does not parse is supposed to
111
# throw a SYNTAX_ERROR exception.
113
dom_get cssText { list string [$myNode attribute -default "" style] }
114
dom_put -string cssText val {
115
$myNode attribute style $val
118
dom_call_todo getPropertyValue
119
dom_call_todo getPropertyCSSValue
120
dom_call_todo removeProperty
121
dom_call_todo getPropertyPriority
123
dom_call -string setProperty {THIS propertyName value priority} {
124
if {[info exists ::hv3::DOM::CSS2Properties_simple($propertyName)]} {
125
CSSStyleDeclaration_setStyleProperty $myNode $propertyName $value
128
error "DOMException SYNTAX_ERROR {unknown property $propertyName}"
131
# Interface to iterate through property names:
133
# readonly unsigned long length;
134
# DOMString item(in unsigned long index);
137
list number [expr {[llength [$myNode prop -inline]]/2}]
139
dom_call -string item {THIS index} {
140
set idx [expr {2*int([lindex $index 1])}]
141
list string [lindex [$myNode prop -inline] $idx]
144
# Read-only parentRule property. Always null in hv3.
146
dom_get parentRule { list null }
149
namespace eval ::hv3::DOM {
150
proc CSSStyleDeclaration.getStyleProperty {node css_property} {
151
set val [$node property -inline $css_property]
155
proc CSSStyleDeclaration.setStyleProperty {node css_property value} {
156
array set current [$node prop -inline]
159
set current($css_property) $value
161
unset -nocomplain current($css_property)
165
foreach prop [array names current] {
166
append style "$prop:$current($prop);"
169
$node attribute style $style