~ubuntu-branches/debian/sid/tk-html3/sid

« back to all changes in this revision

Viewing changes to hv/hv3_dom_style.tcl

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2012-03-02 18:45:00 UTC
  • Revision ID: package-import@ubuntu.com-20120302184500-np17d7d6gd1jedj0
Tags: upstream-3.0~fossil20110109
ImportĀ upstreamĀ versionĀ 3.0~fossil20110109

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace eval hv3 { set {version($Id: hv3_dom_style.tcl,v 1.15 2007/10/17 17:45:07 danielk1977 Exp $)} 1 }
 
2
 
 
3
#-------------------------------------------------------------------------
 
4
# DOM Level 2 Style.
 
5
#
 
6
# This file contains the Hv3 implementation of the DOM Level 2 Style
 
7
# specification.
 
8
#
 
9
#     ElementCSSInlineStyle        (mixed into Element)
 
10
#     CSSStyleDeclaration          (mixed into ElementCSSInlineStyle)
 
11
#     CSS2Properties               (mixed into CSSStyleDeclaration)
 
12
#
 
13
# http://www.w3.org/TR/2000/REC-DOM-Level-2-Style-20001113/css.html
 
14
#
 
15
#
 
16
 
 
17
# Set up an array of known "simple" properties. This is used during
 
18
# DOM compilation and at runtime.
 
19
#
 
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
 
42
 
 
43
set ::hv3::DOM::CSS2Properties_simple(background-color) backgroundColor
 
44
set ::hv3::DOM::CSS2Properties_simple(background-image) backgroundImage
 
45
 
 
46
 
 
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.
 
50
  --
 
51
  dom_get style {
 
52
    list object [list ::hv3::DOM::CSSStyleDeclaration $myDom $myNode]
 
53
  }
 
54
}
 
55
 
 
56
set ::hv3::dom::code::CSS2PROPERTIES {
 
57
 
 
58
  dom_parameter myNode
 
59
 
 
60
  foreach {k v} [array get ::hv3::DOM::CSS2Properties_simple] {
 
61
    if {$v eq ""} { set v $k }
 
62
    dom_get $v "
 
63
      CSSStyleDeclaration.getStyleProperty \$myNode $k
 
64
    "
 
65
    dom_put -string $v value "
 
66
      CSSStyleDeclaration.setStyleProperty \$myNode $k \$value
 
67
    "
 
68
  }
 
69
  unset -nocomplain k
 
70
  unset -nocomplain v
 
71
 
 
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
 
77
  }
 
78
 
 
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)
 
88
 
 
89
    set style "background:$value;"
 
90
    foreach prop [array names current] {
 
91
      append style "$prop:$current($prop);"
 
92
    }
 
93
    $myNode attribute style $style
 
94
  }
 
95
}
 
96
 
 
97
# In a complete implementation of the DOM Level 2 style for an HTML 
 
98
# browser, the CSSStyleDeclaration interface is used for two purposes:
 
99
#
 
100
#     * As the ElementCSSInlineStyle.style property object. This 
 
101
#       represents the contents of an HTML "style" attribute.
 
102
#
 
103
#     * As part of the DOM representation of a parsed stylesheet 
 
104
#       document. Hv3 does not implement this function.
 
105
#
 
106
::hv3::dom2::stateless CSSStyleDeclaration {
 
107
  %CSS2PROPERTIES%
 
108
 
 
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.
 
112
  #
 
113
  dom_get cssText { list string [$myNode attribute -default "" style] }
 
114
  dom_put -string cssText val { 
 
115
    $myNode attribute style $val
 
116
  }
 
117
 
 
118
  dom_call_todo getPropertyValue
 
119
  dom_call_todo getPropertyCSSValue
 
120
  dom_call_todo removeProperty
 
121
  dom_call_todo getPropertyPriority
 
122
 
 
123
  dom_call -string setProperty {THIS propertyName value priority} {
 
124
    if {[info exists ::hv3::DOM::CSS2Properties_simple($propertyName)]} {
 
125
      CSSStyleDeclaration_setStyleProperty $myNode $propertyName $value
 
126
      return
 
127
    }
 
128
    error "DOMException SYNTAX_ERROR {unknown property $propertyName}"
 
129
  }
 
130
  
 
131
  # Interface to iterate through property names:
 
132
  #
 
133
  #     readonly unsigned long length;
 
134
  #     DOMString              item(in unsigned long index);
 
135
  #
 
136
  dom_get length {
 
137
    list number [expr {[llength [$myNode prop -inline]]/2}]
 
138
  }
 
139
  dom_call -string item {THIS index} {
 
140
    set idx [expr {2*int([lindex $index 1])}]
 
141
    list string [lindex [$myNode prop -inline] $idx]
 
142
  }
 
143
 
 
144
  # Read-only parentRule property. Always null in hv3.
 
145
  #
 
146
  dom_get parentRule { list null }
 
147
}
 
148
 
 
149
namespace eval ::hv3::DOM {
 
150
  proc CSSStyleDeclaration.getStyleProperty {node css_property} {
 
151
    set val [$node property -inline $css_property]
 
152
    list string $val
 
153
  }
 
154
 
 
155
  proc CSSStyleDeclaration.setStyleProperty {node css_property value} {
 
156
    array set current [$node prop -inline]
 
157
 
 
158
    if {$value ne ""} {
 
159
      set current($css_property) $value
 
160
    } else {
 
161
      unset -nocomplain current($css_property)
 
162
    }
 
163
 
 
164
    set style ""
 
165
    foreach prop [array names current] {
 
166
      append style "$prop:$current($prop);"
 
167
    }
 
168
 
 
169
    $node attribute style $style
 
170
  }
 
171
}