/
536.txt
192 lines (144 loc) · 9.43 KB
/
536.txt
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
[18] いくつかの [[HTML要素]]には、 [DFN[[CODE(DOMa)@en[[[text]]]]]]
[[IDL属性]]があります。これは[[要素]]の[[内容]]から[[テキスト]]を抽出するものです。
;; [19] [CODE(DOMa)@en[[[textContent]]]] [[IDL属性]]と似ていますが、
動作が微妙に異なっていますし、すべての[[要素]]に存在するわけでもありません。
* 仕様書
[REFS[
- [32] '''[CITE@en[DOM Standard]] ([TIME[2017-06-29 02:44:54 +09:00]]) <https://dom.spec.whatwg.org/#concept-child-text-content>'''
- [9] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-02-21 07:50:23 +09:00]] 版) <https://html.spec.whatwg.org/#dom-script-text>
]REFS]
* 子供テキスト内容
[23] [[要素]]の[DFN[[F[[RUBYB[子供テキスト内容]@en[child text content]]]]]]は、
当該[[要素]]の[[子供]]である [CODE(DOMi)@en[Text]] [[節点]]すべての[F[データ]]を、
[[木順]]に連結したものです [SRC[>>32, >>26]]。
[28] [[子供テキスト内容]]は、次の場面で使われます。
[FIG(list middle)[
- [CODE(HTMLe)@en[title]] [[要素]]
-- [CODE(JS)@en[document.title]]
-- [CODE(DOMa)@en[text][Node.text]] [[IDL属性]]
-- [[文書の題名]]
- [CODE(HTMLe)@en[style]] [[要素]]
-- [CODE(DOMa)@en[text][Node.text]] [[IDL属性]]
-- [[CSS]] [[ソーステキスト]]
- [CODE(HTMLe)@en[script]] [[要素]]
-- [CODE(DOMa)@en[text][Node.text]] [[IDL属性]]
--- [[JavaScript]] [[ソーステキスト]]
- [CODE(HTMLe)@en[time]] [[要素]]の[[日時値]]
- [CODE(HTMLe)@en[noscript]] [[要素]]の[[内容モデル]]
- [CODE(HTMLe)@en[textarea]]
-- [[再設定アルゴリズム]]
-- [CODE(DOMa)@en[defaultValue]] [[IDL属性]]の[[取得器]]
[HISTORY[
- [CODE(HTMLe)@en[menuitem]] [[要素]]の[[ラベル][ラベル (menuitem)]]
]HISTORY]
]FIG]
[25] このうち [CODE(HTMLe)@en[title]], [CODE(HTMLe)@en[style]], [CODE(HTMLe)@en[script]]
については、[[HTML構文解析器]]は[[内容]]部分で[[タグ]]を認識しないので、
[[子要素]]を持つことはありません。 ([[DOM]] 操作により[[子要素]]を[[挿入]]することはできますが。)
[24] 似たものに [CODE(DOMa)@en[textContent]] がありますが、
[[子孫]]すべての[[テキスト]]を[[連結]]するものですから、
常時最新値を使う処理の場合に、
[[子孫]]のあらゆる[[変異]]を観測して適宜更新する必要があります。
それは必ずしも低コストな処理ではないため、[[子要素]]が特に必要なければ、
[[子テキストの連結]]が使われることがあります [SRC[>>21]]。
[29] [CODE(HTMLe)@en[option]] [[要素]]は[[子供テキスト内容]]と [CODE(DOMa)@en[textContent]]
の中間のようなものを使っています。
* [CODE(DOMi)@en[HTMLScriptElement]] インターフェイス
[10] [CODE(DOMi)@en[[[HTMLScriptElement]]]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[[[text]]]]]] [[IDL属性]]は、
[[取得時]]、次のようにしなければ[['''なりません''']] [SRC[>>9]]。
[FIG(steps)[
= [12] [VAR[テキスト]]を、[[空文字列]]に設定します。
= [11] [[文脈オブジェクト]]の[F[[[子供]]]]リストに含まれる[[節点]][VAR[節点]]について[[木順]]に、
== [13] [VAR[節点]]が [CODE(DOMi)@en[[[Text]]]] なら、
=== [14] [VAR[テキスト]]の末尾に[VAR[節点]]の[F[[[データ]]]]を追加します。
= [15] [VAR[テキスト]]を返します。
]FIG]
;; [17] これは [CODE(DOMa)@en[[[textContent]]]] とは違って[[子要素]]を無視します。
[[HTML構文]]では [CODE(HTMLe)@en[[[script]]]] [[要素]]に[[子要素]]を含めることはできませんが、
[[XHTML]] や[[スクリプト]]を使えば可能です。しかし[[スクリプト]]の実行時には
[CODE(DOMa)@en[[[textContent]]]] ではなく [CODE(DOMa)@en[[[text]]]]
の値が使われ、[[子要素]]の[[内容]]は[[スクリプト]]の[[ソースコード]]の一部とはみなされません。
[16] [[設定時]]には、 [CODE(DOMa)@en[[[textContent]]]]
[[IDL属性]]の[[設定器]]と同じようにしなければ[['''なりません''']] [SRC[>>9]]。
* 変更手順群
[34] [[要素]]の[[子供]]が変化すると[[挿入手順群]]や[[削除手順群]]などが実行されますが、
それとは別に、[F[子供テキスト内容]]が変化したときには[DFN[[RUBYB[子供テキスト内容変更手順群]@en[child text content change steps]]]]
[SRC[>>32]] が実行されます。
[41]
現在[[子供テキスト内容変更手順群]]が定義されているのは、次の場面です。
[FIG(short list)[ [43] [[子供テキスト内容変更手順群]]のある[[要素]]
- [CODE(HTMLe)@en[textarea]]
- [CODE(HTMLe)@en[style]]
]FIG]
[35] これは[[要素の挿入]]、[[要素の削除]]、[[データの置換]]といった操作から呼び出されます。
[37] [[DOM木]]に[[変更][DOM変異]]があった場合でも、[F[子供テキスト内容]]が変化していない場合、
[[子供テキスト内容変更手順群]]は実行されるとは限りません。
現在規定されているいずれの操作も、[F[子供テキスト内容]]が変化しない場合、
実行されたかどうかは観測できません。
* 歴史
[20] [CODE(DOMa)@en[[[text]]]] [[IDL属性]]は [[IE4 DOM]] に由来します。
** [CODE(DOMi)@en[Node]] インターフェイス
[8] [[MSXML]] では [CODE(DOMi)@en[[[Node]]]] [[インターフェイス]]相当に [CODE(DOMa)@en[[[text]]]]
[[属性]]があるようです。
[REFS[
- [6] [CITE@en-us[text Property ''''''[''''''DOM'''''']'''''']]
( ([TIME[2013-05-12 05:15:17 +09:00]] 版))
<http://msdn.microsoft.com/en-us/library/ms762687(v=vs.85).aspx>
]REFS]
[7] >>6 によると標準の [[DOM]] の [CODE(DOMa)@en[[[textContent]]]] に近いですが、
[CODE(XMLa)@en[[[xml:space]]]] [[属性]]などによって挙動が変わるようです。
** HTML5
[REFS[
- [1] [CITE@en[(X)HTML5 Tracking]]
([TIME[2010-01-11 13:57:26 +09:00]] 版)
<http://html5.org/tools/web-apps-tracker?from=4561&to=4562>
- [3] [CITE['''['''whatwg''']''' a element and .text]]
([TIME[2010-08-10 09:24:47 +09:00]] 版)
<http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-August/027781.html>
]REFS]
[2] >>1 で [CODE(DOMi)@en[[[HTMLAnchorElement]]]] の [CODE(DOMa)@en[[[text]]]] [[属性]]が定義されました。
[REFS[
- [4] [CITE@en[Web Applications 1.0 r7763 Match reality, and factor out an algorithm.]]
( ([TIME[2013-03-22 03:47:00 +09:00]] 版))
<http://html5.org/tools/web-apps-tracker?from=7762&to=7763>
]REFS]
[5] >>4 で [CODE(DOMi)@en[[[HTMLOptionElement]]]] の [CODE(DOMa)@en[[[text]]]] [[属性]]の定義が改められています。
** 共通化
[33]
[TIME[2016年][year:2016]]、従来個別に定義されていた本概念に[[子供テキスト内容]]という名前が与えられました。
[21] [CITE@en[Validity and processing should be aligned for <time> · Issue #644 · whatwg/html]]
([TIME[2016-03-05 11:20:24 +09:00]] 版)
<https://github.com/whatwg/html/issues/644>
[22] [CITE@en[Fix #644: Only look at child Text nodes in <time> · whatwg/html@b437a80]]
([TIME[2016-03-05 18:11:27 +09:00]] 版)
<https://github.com/whatwg/html/commit/b437a803c2310d8fb2e05aef343ea24166afb9fd>
[27] [CITE@en[Refactor child Text nodes to a new concept · whatwg/html@0dd609f]] ([TIME[2016-03-10 21:01:01 +09:00]] 版) <https://github.com/whatwg/html/commit/0dd609fddc08dab337d24da874c787e51e851efc>
[30] [CITE@en[Formalize custom element reactions · whatwg/html@27aa7bc]]
([TIME[2016-04-26 18:53:24 +09:00]] 版)
<https://github.com/whatwg/html/commit/27aa7bc4fa6f168654a8c858f0773e611f679b39>
- [26] '''[CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-03-10 07:13:01 +09:00]] 版) <https://html.spec.whatwg.org/#child-text-content>'''
[31] [CITE@en[Add child text content and its change steps]]
([[domenic]]著, [TIME[2017-06-28 01:07:56 +09:00]])
<https://github.com/whatwg/dom/commit/93db3408c360a958c2f1c00fbb99bf6c5d6fa5b2>
[36] [CITE@en[Add child text content and its change steps by domenic · Pull Request #466 · whatwg/dom]]
([TIME[2017-06-29 17:05:00 +09:00]])
<https://github.com/whatwg/dom/pull/466>
[38] [CITE@en[Update textarea textContent/defaultValue/value interaction]]
([[domenic]]著, [TIME[2017-06-16 05:46:10 +09:00]])
<https://github.com/whatwg/html/commit/5afbba1cf62ee01bc6af3fd220d01f3f7591a0fc>
[39] [CITE@en["When the textarea element's textContent IDL attribute changes" · Issue #2750 · whatwg/html]]
([TIME[2017-06-29 17:18:36 +09:00]])
<https://github.com/whatwg/html/issues/2750>
[40] [CITE@en[Textarea defaultValue handling doesn't really match UAs (who don't match each other) when there are child elements · Issue #2752 · whatwg/html]]
([TIME[2017-06-29 17:19:46 +09:00]])
<https://github.com/whatwg/html/issues/2752>
[42] [CITE@en[Update textarea textContent/defaultValue/value interaction by domenic · Pull Request #2766 · whatwg/html]]
([TIME[2017-06-29 17:21:00 +09:00]])
<https://github.com/whatwg/html/pull/2766>
[44] [CITE@en[Improve <style> and <script> processing and conformance]]
([[domenic]]著, [TIME[2017-09-14 18:42:48 +09:00]])
<https://github.com/whatwg/html/commit/9c612ac8641b5174849a2d3cb924fe662a8d3a09>
[45] [CITE@en[<style> should use child text content changed steps · Issue #2996 · whatwg/html]]
([TIME[2017-09-19 22:42:21 +09:00]])
<https://github.com/whatwg/html/issues/2996>