dom_html.pp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. {
  2. This file is part of the Free Component Library
  3. Implementation of DOM HTML interfaces
  4. Copyright (c) 2002 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$mode objfpc}
  13. {$H+}
  14. unit DOM_HTML;
  15. interface
  16. uses DOM, htmldefs, xmlutils, SysUtils;
  17. type
  18. THTMLDocument = class;
  19. THTMLFormElement = class;
  20. THTMLTableCaptionElement = class;
  21. THTMLTableSectionElement = class;
  22. TFilterProc = function(aNode: TDOMNode): TFilterResult;
  23. // Tests cast Collection <-> OptionsCollection in arbitrary way...
  24. THTMLCollection = class(TDOMNodeList)
  25. protected
  26. FFilterProc: TFilterProc;
  27. function NodeFilter(aNode: TDOMNode): TFilterResult; override;
  28. public
  29. constructor Create(aNode: TDOMNode; Proc: TFilterProc);
  30. function NamedItem(const Index: DOMString): TDOMNode;
  31. end;
  32. // differs from HTMLCollection in that Length *may* be writable.
  33. // for now, let's pretend it's not...
  34. THTMLOptionsCollection = class(THTMLCollection)
  35. end;
  36. THTMLElement = class(TDOMElement)
  37. private
  38. function GetStrAttr(idx: THTMLAttributeTag): DOMString;
  39. procedure SetStrAttr(idx: THTMLAttributeTag; const value: DOMString);
  40. function GetIntAttr(idx: THTMLAttributeTag): Integer;
  41. procedure SetIntAttr(idx: THTMLAttributeTag; value: Integer);
  42. function GetUIntAttr(idx: THTMLAttributeTag): Cardinal;
  43. procedure SetUIntAttr(idx: THTMLAttributeTag; value: Cardinal);
  44. function GetBoolAttr(idx: THTMLAttributeTag): Boolean;
  45. procedure SetBoolAttr(idx: THTMLAttributeTag; value: Boolean);
  46. protected
  47. function GetForm: THTMLFormElement;
  48. public
  49. property ID: DOMString index atid read GetStrAttr write SetStrAttr;
  50. property Title: DOMString index attitle read GetStrAttr write SetStrAttr;
  51. property Lang: DOMString index atlang read GetStrAttr write SetStrAttr;
  52. property Dir: DOMString index atdir read GetStrAttr write SetStrAttr;
  53. property ClassName: DOMString index atclass read GetStrAttr write SetStrAttr;
  54. end;
  55. THTMLHtmlElement = class(THTMLElement)
  56. public
  57. property Version: DOMString index atversion read GetStrAttr write SetStrAttr;
  58. end;
  59. THTMLHeadElement = class(THTMLElement)
  60. public
  61. property Profile: DOMString index atprofile read GetStrAttr write SetStrAttr;
  62. end;
  63. THTMLLinkElement = class(THTMLElement)
  64. public
  65. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  66. property Charset: DOMString index atcharset read GetStrAttr write SetStrAttr;
  67. property HRef: DOMString index athref read GetStrAttr write SetStrAttr;
  68. property HRefLang: DOMString index athreflang read GetStrAttr write SetStrAttr;
  69. property Media: DOMString index atmedia read GetStrAttr write SetStrAttr;
  70. property Rel: DOMString index atrel read GetStrAttr write SetStrAttr;
  71. property Rev: DOMString index atrev read GetStrAttr write SetStrAttr;
  72. property Target: DOMString index attarget read GetStrAttr write SetStrAttr;
  73. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  74. end;
  75. THTMLTitleElement = class(THTMLElement)
  76. public
  77. property Text: DOMString read GetTextContent write SetTextContent;
  78. end;
  79. THTMLMetaElement = class(THTMLElement)
  80. public
  81. property Content: DOMString index atcontent read GetStrAttr write SetStrAttr;
  82. property HTTPEquiv: DOMString index athttpequiv read GetStrAttr write SetStrAttr;
  83. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  84. property Scheme: DOMString index atscheme read GetStrAttr write SetStrAttr;
  85. end;
  86. THTMLBaseElement = class(THTMLElement)
  87. public
  88. property HRef: DOMString index athref read GetStrAttr write SetStrAttr;
  89. property Target: DOMString index attarget read GetStrAttr write SetStrAttr;
  90. end;
  91. THTMLIsIndexElement = class(THTMLElement)
  92. public
  93. property Form: THTMLFormElement read GetForm;
  94. property Prompt: DOMString index atprompt read GetStrAttr write SetStrAttr; // 4.01 deprecated
  95. end;
  96. THTMLStyleElement = class(THTMLElement)
  97. public
  98. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  99. property Media: DOMString index atmedia read GetStrAttr write SetStrAttr;
  100. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  101. end;
  102. THTMLBodyElement = class(THTMLElement)
  103. public
  104. property ALink: DOMString index atalink read GetStrAttr write SetStrAttr;
  105. property Background: DOMString index atbackground read GetStrAttr write SetStrAttr;
  106. property BgColor: DOMString index atbgcolor read GetStrAttr write SetStrAttr;
  107. property Link: DOMString index atlink read GetStrAttr write SetStrAttr;
  108. property Text: DOMString index attext read GetStrAttr write SetStrAttr;
  109. property VLink: DOMString index atvlink read GetStrAttr write SetStrAttr;
  110. end;
  111. THTMLFormElement = class(THTMLElement)
  112. private
  113. function GetElements: THTMLCollection;
  114. function GetLength: Integer;
  115. public
  116. property Elements: THTMLCollection read GetElements;
  117. property Length: Integer read GetLength;
  118. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  119. property AcceptCharset: DOMString index atacceptcharset read GetStrAttr write SetStrAttr;
  120. property Action: DOMString index ataction read GetStrAttr write SetStrAttr;
  121. property EncType: DOMString index atenctype read GetStrAttr write SetStrAttr;
  122. property Method: DOMString index atmethod read GetStrAttr write SetStrAttr;
  123. property Target: DOMString index attarget read GetStrAttr write SetStrAttr;
  124. procedure Submit;
  125. procedure Reset;
  126. end;
  127. THTMLSelectElement = class(THTMLElement)
  128. private
  129. FSelectedIndex: Integer;
  130. function GetType: DOMString;
  131. function GetValue: DOMString;
  132. procedure SetValue(const value: DOMString);
  133. function GetOptions: THTMLOptionsCollection;
  134. function GetLength: Cardinal;
  135. procedure SetLength(aValue: Cardinal);
  136. public
  137. property HTMLType: DOMString read GetType;
  138. property SelectedIndex: Integer read FSelectedIndex write FSelectedIndex;
  139. property Value: DOMString read GetValue write SetValue;
  140. // maps to Options.Length
  141. property Length: Cardinal read GetLength write SetLength;
  142. property Form: THTMLFormElement read GetForm;
  143. property Options: THTMLOptionsCollection read GetOptions;
  144. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  145. property Multiple: Boolean index atmultiple read GetBoolAttr write SetBoolAttr;
  146. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  147. property Size: Integer index atsize read GetIntAttr write SetIntAttr;
  148. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  149. procedure Add(Element, Before: THTMLElement);
  150. procedure Remove(Index: Integer);
  151. procedure Blur;
  152. procedure Focus;
  153. end;
  154. THTMLOptGroupElement = class(THTMLElement)
  155. public
  156. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  157. property GroupLabel: DOMString index atlabel read GetStrAttr write SetStrAttr;
  158. end;
  159. THTMLOptionElement = class(THTMLElement)
  160. private
  161. function GetIndex: Integer;
  162. public
  163. property Form: THTMLFormElement read GetForm;
  164. property DefaultSelected: Boolean index atselected read GetBoolAttr write SetBoolAttr;
  165. property Text: DOMString read GetTextContent;
  166. property Index: Integer read GetIndex;
  167. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  168. // TODO: name? was 'label'
  169. property OptionLabel: DOMString index atlabel read GetStrAttr write SetStrAttr;
  170. // TODO: GUI state, must not be mapped to attribute
  171. property Selected: Boolean index atselected read GetBoolAttr write SetBoolAttr;
  172. property Value: DOMString index atvalue read GetStrAttr write SetStrAttr;
  173. end;
  174. THTMLInputElement = class(THTMLElement)
  175. private
  176. FChecked: Boolean; // !!! TEMP
  177. public
  178. property DefaultValue: DOMString index atvalue read GetStrAttr write SetStrAttr;
  179. property DefaultChecked: Boolean index atchecked read GetBoolAttr write SetBoolAttr;
  180. property Form: THTMLFormElement read GetForm;
  181. property Accept: DOMString index ataccept read GetStrAttr write SetStrAttr;
  182. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  183. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  184. property Alt: DOMString index atalt read GetStrAttr write SetStrAttr;
  185. // TODO: GUI state, not mapped to attribute
  186. property Checked: Boolean read FChecked write FChecked;
  187. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  188. property MaxLength: Integer index atmaxlength read GetIntAttr write SetIntAttr;
  189. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  190. property ReadOnly: Boolean index atreadonly read GetBoolAttr write SetBoolAttr;
  191. property Size: Cardinal index atsize read GetUIntAttr write SetUIntAttr;
  192. property Src: DOMString index atsrc read GetStrAttr write SetStrAttr;
  193. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  194. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  195. property UseMap: DOMString index atusemap read GetStrAttr write SetStrAttr;
  196. // TODO: GUI state, not mapped to attribute
  197. property Value: DOMString index atvalue read GetStrAttr write SetStrAttr;
  198. procedure Blur;
  199. procedure Focus;
  200. procedure Select;
  201. procedure Click;
  202. end;
  203. THTMLTextAreaElement = class(THTMLElement)
  204. private
  205. function GetType: DOMString;
  206. public
  207. property DefaultValue: DOMString read GetTextContent write SetTextContent;
  208. property Form: THTMLFormElement read GetForm;
  209. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  210. property Cols: Integer index atcols read GetIntAttr write SetIntAttr;
  211. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  212. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  213. property ReadOnly: Boolean index atreadonly read GetBoolAttr write SetBoolAttr;
  214. property Rows: Integer index atrows read GetIntAttr write SetIntAttr;
  215. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  216. property HTMLType: DOMString read GetType;
  217. // TODO: GUI state, not mapped to attribute
  218. property Value: DOMString read GetTextContent write SetTextContent;
  219. procedure Blur;
  220. procedure Focus;
  221. procedure Select;
  222. end;
  223. THTMLButtonElement = class(THTMLElement)
  224. public
  225. property Form: THTMLFormElement read GetForm;
  226. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  227. property Disabled: Boolean index atdisabled read GetBoolAttr write SetBoolAttr;
  228. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  229. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  230. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  231. property Value: DOMString index atvalue read GetStrAttr write SetStrAttr;
  232. end;
  233. THTMLLabelElement = class(THTMLElement)
  234. public
  235. property Form: THTMLFormElement read GetForm;
  236. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  237. property HtmlFor: DOMString index atfor read GetStrAttr write SetStrAttr;
  238. end;
  239. THTMLFieldSetElement = class(THTMLElement)
  240. public
  241. property Form: THTMLFormElement read GetForm;
  242. end;
  243. THTMLLegendElement = class(THTMLElement)
  244. public
  245. property Form: THTMLFormElement read GetForm;
  246. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  247. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  248. end;
  249. THTMLUListElement = class(THTMLElement)
  250. public
  251. property Compact: Boolean index atcompact read GetBoolAttr write SetBoolAttr; // 4.01 deprecated
  252. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  253. end;
  254. THTMLOListElement = class(THTMLElement)
  255. public
  256. property Compact: Boolean index atcompact read GetBoolAttr write SetBoolAttr; // 4.01 deprecated
  257. property Start: Integer index atstart read GetIntAttr write SetIntAttr; // 4.01 deprecated
  258. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr; // 4.01 deprecated
  259. end;
  260. THTMLDListElement = class(THTMLElement)
  261. public
  262. property Compact: Boolean index atcompact read GetBoolAttr write SetBoolAttr; // 4.01 deprecated
  263. end;
  264. THTMLDirectoryElement = class(THTMLElement) // 4.01 deprecated
  265. public
  266. property Compact: Boolean index atcompact read GetBoolAttr write SetBoolAttr;
  267. end;
  268. THTMLMenuElement = class(THTMLElement) // 4.01 deprecated
  269. public
  270. property Compact: Boolean index atcompact read GetBoolAttr write SetBoolAttr;
  271. end;
  272. THTMLLIElement = class(THTMLElement)
  273. public
  274. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr; // 4.01 deprecated
  275. property Value: Integer index atvalue read GetIntAttr write SetIntAttr; // 4.01 deprecated
  276. end;
  277. THTMLDivElement = class(THTMLElement)
  278. public
  279. property Align: DOMString index atalign read GetStrAttr write SetStrAttr; // 4.01 deprecated
  280. end;
  281. THTMLParagraphElement = class(THTMLElement)
  282. public
  283. property Align: DOMString index atalign read GetStrAttr write SetStrAttr; // 4.01 deprecated
  284. end;
  285. THTMLHeadingElement = class(THTMLElement)
  286. public
  287. property Align: DOMString index atalign read GetStrAttr write SetStrAttr; // 4.01 deprecated
  288. end;
  289. THTMLQuoteElement = class(THTMLElement)
  290. public
  291. property Cite: DOMString index atcite read GetStrAttr write SetStrAttr;
  292. end;
  293. THTMLPreElement = class(THTMLElement)
  294. public
  295. property Width: Integer index atwidth read GetIntAttr write SetIntAttr; // 4.01 deprecated
  296. end;
  297. THTMLBRElement = class(THTMLElement)
  298. public
  299. property Clear: DOMString index atclear read GetStrAttr write SetStrAttr; // 4.01 deprecated
  300. end;
  301. // yep, BaseFont.size is integer, but Font.size is a String
  302. THTMLBaseFontElement = class(THTMLElement) // 4.01 deprecated
  303. public
  304. property Color: DOMString index atcolor read GetStrAttr write SetStrAttr; // 4.01 deprecated
  305. property Face: DOMString index atface read GetStrAttr write SetStrAttr; // 4.01 deprecated
  306. property Size: Integer index atsize read GetIntAttr write SetIntAttr; // 4.01 deprecated
  307. end;
  308. THTMLFontElement = class(THTMLElement) // 4.01 deprecated
  309. public
  310. property Color: DOMString index atcolor read GetStrAttr write SetStrAttr;
  311. property Face: DOMString index atface read GetStrAttr write SetStrAttr;
  312. property Size: DOMString index atsize read GetStrAttr write SetStrAttr;
  313. end;
  314. THTMLHRElement = class(THTMLElement)
  315. public
  316. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  317. property NoShade: Boolean index atnoshade read GetBoolAttr write SetBoolAttr; // 4.01 deprecated
  318. property Size: DOMString index atsize read GetStrAttr write SetStrAttr;
  319. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  320. end;
  321. THTMLModElement = class(THTMLElement)
  322. public
  323. property Cite: DOMString index atcite read GetStrAttr write SetStrAttr;
  324. property DateTime: DOMString index atdatetime read GetStrAttr write SetStrAttr;
  325. end;
  326. THTMLAnchorElement = class(THTMLElement)
  327. public
  328. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  329. property Charset: DOMString index atcharset read GetStrAttr write SetStrAttr;
  330. property Coords: DOMString index atcoords read GetStrAttr write SetStrAttr;
  331. property HRef: DOMString index athref read GetStrAttr write SetStrAttr;
  332. property HRefLang: DOMString index athreflang read GetStrAttr write SetStrAttr;
  333. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  334. property Rel: DOMString index atrel read GetStrAttr write SetStrAttr;
  335. property Rev: DOMString index atrev read GetStrAttr write SetStrAttr;
  336. property Shape: DOMString index atshape read GetStrAttr write SetStrAttr;
  337. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  338. property Target: DOMString index attarget read GetStrAttr write SetStrAttr;
  339. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  340. procedure Blur;
  341. procedure Focus;
  342. end;
  343. THTMLImageElement = class(THTMLElement)
  344. public
  345. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  346. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  347. property Alt: DOMString index atalt read GetStrAttr write SetStrAttr;
  348. property Border: DOMString index atborder read GetStrAttr write SetStrAttr;
  349. property Height: Integer index atheight read GetIntAttr write SetIntAttr;
  350. property HSpace: Integer index athspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  351. property IsMap: Boolean index atismap read GetBoolAttr write SetBoolAttr;
  352. property LongDesc: DOMString index atlongdesc read GetStrAttr write SetStrAttr;
  353. property Src: DOMString index atsrc read GetStrAttr write SetStrAttr;
  354. property UseMap: DOMString index atusemap read GetStrAttr write SetStrAttr;
  355. property VSpace: Integer index atvspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  356. property Width: Integer index atwidth read GetIntAttr write SetIntAttr;
  357. end;
  358. THTMLObjectElement = class(THTMLElement)
  359. private
  360. function GetContentDocument: TDOMDocument;
  361. public
  362. property Form: THTMLFormElement read GetForm;
  363. property Code: DOMString index atcode read GetStrAttr write SetStrAttr; // 4.01 deprecated
  364. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  365. property Archive: DOMString index atarchive read GetStrAttr write SetStrAttr;
  366. property Border: DOMString index atborder read GetStrAttr write SetStrAttr;
  367. property CodeBase: DOMString index atcodebase read GetStrAttr write SetStrAttr;
  368. property CodeType: DOMString index atcodetype read GetStrAttr write SetStrAttr;
  369. property Data: DOMString index atdata read GetStrAttr write SetStrAttr;
  370. property Declare: Boolean index atdeclare read GetBoolAttr write SetBoolAttr;
  371. property Height: DOMString index atheight read GetStrAttr write SetStrAttr;
  372. property HSpace: Integer index athspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  373. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  374. property StandBy: DOMString index atstandby read GetStrAttr write SetStrAttr;
  375. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  376. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  377. property UseMap: DOMString index atusemap read GetStrAttr write SetStrAttr;
  378. property VSpace: Integer index atvspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  379. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  380. property ContentDocument: TDOMDocument read GetContentDocument;
  381. end;
  382. THTMLParamElement = class(THTMLElement)
  383. public
  384. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  385. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  386. property Value: DOMString index atvalue read GetStrAttr write SetStrAttr;
  387. property ValueType: DOMString index atvaluetype read GetStrAttr write SetStrAttr;
  388. end;
  389. THTMLAppletElement = class(THTMLElement)
  390. public
  391. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  392. property Alt: DOMString index atalt read GetStrAttr write SetStrAttr;
  393. property Archive: DOMString index atarchive read GetStrAttr write SetStrAttr;
  394. property Code: DOMString index atcode read GetStrAttr write SetStrAttr; // 4.01 deprecated
  395. property CodeBase: DOMString index atcodebase read GetStrAttr write SetStrAttr;
  396. property Height: DOMString index atheight read GetStrAttr write SetStrAttr;
  397. property HSpace: Integer index athspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  398. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  399. property AppletObject: DOMString index atobject read GetStrAttr write SetStrAttr;
  400. property VSpace: Integer index atvspace read GetIntAttr write SetIntAttr; // 4.01 deprecated
  401. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  402. end;
  403. THTMLMapElement = class(THTMLElement)
  404. private
  405. function GetAreas: THTMLCollection;
  406. public
  407. property Areas: THTMLCollection read GetAreas;
  408. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  409. end;
  410. THTMLAreaElement = class(THTMLElement)
  411. public
  412. property AccessKey: DOMString index ataccesskey read GetStrAttr write SetStrAttr;
  413. property Alt: DOMString index atalt read GetStrAttr write SetStrAttr;
  414. property Coords: DOMString index atcoords read GetStrAttr write SetStrAttr;
  415. property HRef: DOMString index athref read GetStrAttr write SetStrAttr;
  416. property NoHRef: Boolean index atnohref read GetBoolAttr write SetBoolAttr;
  417. property Shape: DOMString index atshape read GetStrAttr write SetStrAttr;
  418. property TabIndex: Integer index attabindex read GetIntAttr write SetIntAttr;
  419. property Target: DOMString index attarget read GetStrAttr write SetStrAttr;
  420. end;
  421. THTMLScriptElement = class(THTMLElement)
  422. private
  423. function GetEvent: DOMString;
  424. procedure SetEvent(const Value: DOMString);
  425. public
  426. property Text: DOMString read GetTextContent write SetTextContent;
  427. property HtmlFor: DOMString index atfor read GetStrAttr write SetStrAttr;
  428. { reserved for future use }
  429. property Event: DOMString read GetEvent write SetEvent;
  430. property Charset: DOMString index atcharset read GetStrAttr write SetStrAttr;
  431. property Defer: Boolean index atdefer read GetBoolAttr write SetBoolAttr;
  432. property Src: DOMString index atsrc read GetStrAttr write SetStrAttr;
  433. property HTMLType: DOMString index attype read GetStrAttr write SetStrAttr;
  434. end;
  435. THTMLTableElement = class(THTMLElement)
  436. private
  437. function GetRows: THTMLCollection;
  438. function GetBodies: THTMLCollection;
  439. function GetCaption: THTMLTableCaptionElement;
  440. procedure SetCaption(value: THTMLTableCaptionElement);
  441. function GetHead: THTMLTableSectionElement;
  442. procedure SetHead(value: THTMLTableSectionElement);
  443. function GetFoot: THTMLTableSectionElement;
  444. procedure SetFoot(value: THTMLTableSectionElement);
  445. public
  446. property Caption: THTMLTableCaptionElement read GetCaption write SetCaption;
  447. property THead: THTMLTableSectionElement read GetHead write SetHead;
  448. property TFoot: THTMLTableSectionElement read GetFoot write SetFoot;
  449. property Rows: THTMLCollection read GetRows;
  450. property TBodies: THTMLCollection read GetBodies;
  451. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  452. property BgColor: DOMString index atbgcolor read GetStrAttr write SetStrAttr; // 4.01 deprecated
  453. property Border: DOMString index atborder read GetStrAttr write SetStrAttr;
  454. property CellPadding: DOMString index atcellpadding read GetStrAttr write SetStrAttr;
  455. property CellSpacing: DOMString index atcellspacing read GetStrAttr write SetStrAttr;
  456. property Frame: DOMString index atframe read GetStrAttr write SetStrAttr;
  457. property Rules: DOMString index atrules read GetStrAttr write SetStrAttr;
  458. property Summary: DOMString index atsummary read GetStrAttr write SetStrAttr;
  459. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  460. function CreateTHead: THTMLElement;
  461. procedure DeleteTHead;
  462. function CreateTFoot: THTMLElement;
  463. procedure DeleteTFoot;
  464. function CreateCaption: THTMLElement;
  465. procedure DeleteCaption;
  466. function InsertRow(Index: Integer): THTMLElement;
  467. procedure DeleteRow(Index: Integer);
  468. end;
  469. THTMLTableCaptionElement = class(THTMLElement)
  470. public
  471. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  472. end;
  473. THTMLTableColElement = class(THTMLElement)
  474. public
  475. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  476. property Ch: DOMString index atchar read GetStrAttr write SetStrAttr;
  477. property ChOff: DOMString index atcharoff read GetStrAttr write SetStrAttr;
  478. property Span: Integer index atspan read GetIntAttr write SetIntAttr;
  479. property VAlign: DOMString index atvalign read GetStrAttr write SetStrAttr;
  480. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  481. end;
  482. THTMLTableSectionElement = class(THTMLElement)
  483. private
  484. function GetRows: THTMLCollection;
  485. public
  486. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  487. property Ch: DOMString index atchar read GetStrAttr write SetStrAttr;
  488. property ChOff: DOMString index atcharoff read GetStrAttr write SetStrAttr;
  489. property VAlign: DOMString index atvalign read GetStrAttr write SetStrAttr;
  490. property Rows: THTMLCollection read GetRows;
  491. function InsertRow(Index: Integer): THTMLElement;
  492. procedure DeleteRow(Index: Integer);
  493. end;
  494. THTMLTableRowElement = class(THTMLElement)
  495. private
  496. function GetRowIndex: Integer;
  497. function GetSectionRowIndex: Integer;
  498. function GetCells: THTMLCollection;
  499. public
  500. property RowIndex: Integer read GetRowIndex;
  501. property SectionRowIndex: Integer read GetSectionRowIndex;
  502. property Cells: THTMLCollection read GetCells;
  503. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  504. property BgColor: DOMString index atbgcolor read GetStrAttr write SetStrAttr; // 4.01 deprecated
  505. property Ch: DOMString index atchar read GetStrAttr write SetStrAttr;
  506. property ChOff: DOMString index atcharoff read GetStrAttr write SetStrAttr;
  507. property VAlign: DOMString index atvalign read GetStrAttr write SetStrAttr;
  508. function InsertCell(Index: Integer): THTMLElement;
  509. procedure DeleteCell(Index: Integer);
  510. end;
  511. THTMLTableCellElement = class(THTMLElement)
  512. private
  513. function GetCellIndex: Integer;
  514. public
  515. property CellIndex: Integer read GetCellIndex;
  516. property Abbr: DOMString index atabbr read GetStrAttr write SetStrAttr;
  517. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  518. property Axis: DOMString index ataxis read GetStrAttr write SetStrAttr;
  519. property BgColor: DOMString index atbgcolor read GetStrAttr write SetStrAttr; // 4.01 deprecated
  520. property Ch: DOMString index atchar read GetStrAttr write SetStrAttr;
  521. property ChOff: DOMString index atcharoff read GetStrAttr write SetStrAttr;
  522. property ColSpan: Integer index atcolspan read GetIntAttr write SetIntAttr;
  523. property Headers: DOMString index atheaders read GetStrAttr write SetStrAttr;
  524. property Height: DOMString index atheight read GetStrAttr write SetStrAttr;
  525. property NoWrap: Boolean index atnowrap read GetBoolAttr write SetBoolAttr; // 4.01 deprecated
  526. property RowSpan: Integer index atrowspan read GetIntAttr write SetIntAttr;
  527. property Scope: DOMString index atscope read GetStrAttr write SetStrAttr;
  528. property VAlign: DOMString index atvalign read GetStrAttr write SetStrAttr;
  529. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  530. end;
  531. THTMLFrameSetElement = class(THTMLElement)
  532. public
  533. property Cols: DOMString index atcols read GetStrAttr write SetStrAttr;
  534. property Rows: DOMString index atrows read GetStrAttr write SetStrAttr;
  535. end;
  536. THTMLFrameElement = class(THTMLElement)
  537. private
  538. FContentDocument: TDOMDocument; // !!! TEMP
  539. public
  540. property FrameBorder: DOMString index atframeborder read GetStrAttr write SetStrAttr;
  541. property LongDesc: DOMString index atlongdesc read GetStrAttr write SetStrAttr;
  542. property MarginHeight: DOMString index atmarginheight read GetStrAttr write SetStrAttr;
  543. property MarginWidth: DOMString index atmarginwidth read GetStrAttr write SetStrAttr;
  544. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  545. property NoResize: Boolean index atnoresize read GetBoolAttr write SetBoolAttr;
  546. property Scrolling: DOMString index atscrolling read GetStrAttr write SetStrAttr;
  547. property Src: DOMString index atsrc read GetStrAttr write SetStrAttr;
  548. property ContentDocument: TDOMDocument read FContentDocument;
  549. end;
  550. THTMLIFrameElement = class(THTMLElement)
  551. private
  552. FContentDocument: TDOMDocument; // !!! TEMP
  553. public
  554. property Align: DOMString index atalign read GetStrAttr write SetStrAttr;
  555. property FrameBorder: DOMString index atframeborder read GetStrAttr write SetStrAttr;
  556. property Height: DOMString index atheight read GetStrAttr write SetStrAttr;
  557. property LongDesc: DOMString index atlongdesc read GetStrAttr write SetStrAttr;
  558. property MarginHeight: DOMString index atmarginheight read GetStrAttr write SetStrAttr;
  559. property MarginWidth: DOMString index atmarginwidth read GetStrAttr write SetStrAttr;
  560. property Name: DOMString index atname read GetStrAttr write SetStrAttr;
  561. property Scrolling: DOMString index atscrolling read GetStrAttr write SetStrAttr;
  562. property Src: DOMString index atsrc read GetStrAttr write SetStrAttr;
  563. property Width: DOMString index atwidth read GetStrAttr write SetStrAttr;
  564. property ContentDocument: TDOMDocument read FContentDocument;
  565. end;
  566. THTMLDocument = class(TXMLDocument)
  567. private
  568. function GetTitle: DOMString;
  569. procedure SetTitle(const Value: DOMString);
  570. function GetBody: THTMLElement;
  571. procedure SetBody(value: THTMLElement);
  572. function GetAnchors: THTMLCollection;
  573. function GetApplets: THTMLCollection;
  574. function GetCookie: DOMString;
  575. procedure SetCookie(const Value: DOMString);
  576. function GetDomain: DOMString;
  577. function GetForms: THTMLCollection;
  578. function GetImages: THTMLCollection;
  579. function GetLinks: THTMLCollection;
  580. function GetReferrer: DOMString;
  581. public
  582. property Title: DOMString read GetTitle write SetTitle;
  583. property Referrer: DOMString read GetReferrer;
  584. property Domain: DOMString read GetDomain;
  585. property URL: DOMString read FURI;
  586. property Body: THTMLElement read GetBody write SetBody;
  587. property Images: THTMLCollection read GetImages;
  588. property Applets: THTMLCollection read GetApplets;
  589. property Links: THTMLCollection read GetLinks;
  590. property Forms: THTMLCollection read GetForms;
  591. property Anchors: THTMLCollection read GetAnchors;
  592. property Cookie: DOMString read GetCookie write SetCookie;
  593. procedure Open;
  594. procedure Close;
  595. procedure Write(const AText: DOMString);
  596. procedure WriteLn(const AText: DOMString);
  597. function GetElementsByName(const ElementName: DOMString): TDOMNodeList;
  598. function HashForName(const aName: DOMString): PHashItem;
  599. // Helper functions (not in DOM standard):
  600. function CreateElement(const tagName: DOMString; UseSpecificClass : Boolean = True): THTMLElement;
  601. function CreateSubElement: THTMLElement;
  602. function CreateSupElement: THTMLElement;
  603. function CreateSpanElement: THTMLElement;
  604. function CreateBDOElement: THTMLElement;
  605. function CreateTTElement: THTMLElement;
  606. function CreateIElement: THTMLElement;
  607. function CreateBElement: THTMLElement;
  608. function CreateUElement: THTMLElement;
  609. function CreateSElement: THTMLElement;
  610. function CreateStrikeElement: THTMLElement;
  611. function CreateBigElement: THTMLElement;
  612. function CreateSmallElement: THTMLElement;
  613. function CreateEmElement: THTMLElement;
  614. function CreateStrongElement: THTMLElement;
  615. function CreateDfnElement: THTMLElement;
  616. function CreateCodeElement: THTMLElement;
  617. function CreateSampElement: THTMLElement;
  618. function CreateKbdElement: THTMLElement;
  619. function CreateVarElement: THTMLElement;
  620. function CreateCiteElement: THTMLElement;
  621. function CreateAcronymElement: THTMLElement;
  622. function CreateAbbrElement: THTMLElement;
  623. function CreateDDElement: THTMLElement;
  624. function CreateDTElement: THTMLElement;
  625. function CreateNoFramesElement: THTMLElement;
  626. function CreateNoScriptElement: THTMLElement;
  627. function CreateAddressElement: THTMLElement;
  628. function CreateCenterElement: THTMLElement;
  629. function CreateHtmlElement: THTMLHtmlElement;
  630. function CreateHeadElement: THTMLHeadElement;
  631. function CreateLinkElement: THTMLLinkElement;
  632. function CreateTitleElement: THTMLTitleElement;
  633. function CreateMetaElement: THTMLMetaElement;
  634. {
  635. function CreateBaseElement: THTMLBaseElement;
  636. function CreateIsIndexElement: THTMLIsIndexElement;
  637. function CreateStyleElement: THTMLStyleElement;}
  638. function CreateBodyElement: THTMLBodyElement;
  639. { function CreateFormElement: THTMLFormElement;
  640. function CreateSelectElement: THTMLSelectElement;
  641. function CreateOptGroupElement: THTMLOptGroupElement;
  642. function CreateOptionElement: THTMLOptionElement;
  643. function CreateInputElement: THTMLInputElement;
  644. function CreateTextAreaElement: THTMLTextAreaElement;
  645. function CreateButtonElement: THTMLButtonElement;
  646. function CreateLabelElement: THTMLLabelElement;
  647. function CreateFieldSetElement: THTMLFieldSetElement;
  648. function CreateLegendElement: THTMLLegendElement;}
  649. function CreateUListElement: THTMLUListElement;
  650. function CreateOListElement: THTMLOListElement;
  651. function CreateDListElement: THTMLDListElement;
  652. { function CreateDirectoryElement: THTMLDirectoryElement;
  653. function CreateMenuElement: THTMLMenuElement;}
  654. function CreateLIElement: THTMLLIElement;
  655. { function CreateDivElement: THTMLDivElement;}
  656. function CreateParagraphElement: THTMLParagraphElement;
  657. { function CreateHeadingElement: THTMLHeadingElement;
  658. function CreateQuoteElement: THTMLQuoteElement;
  659. function CreatePreElement: THTMLPreElement;
  660. function CreateBRElement: THTMLBreElement;
  661. function CreateBaseFontElement: THTMLBaseFontElement;
  662. function CreateFontElement: THTMFontLElement;
  663. function CreateHRElement: THTMLHREElement;
  664. function CreateModElement: THTMLModElement;
  665. function CreateAnchorElement: THTMLAnchorElement;
  666. function CreateImageElement: THTMLImageElement;
  667. function CreateObjectElement: THTMLObjectElement;
  668. function CreateParamElement: THTMLParamElement;
  669. function CreateAppletElement: THTMLAppletElement;
  670. function CreateMapElement: THTMLMapElement;
  671. function CreateAreaElement: THTMLAreaElement;
  672. function CreateScriptElement: THTMLScriptElement;
  673. function CreateTableElement: THTMLTableElement;
  674. function CreateTableCaptionElement: THTMLTableCaptionElement;
  675. function CreateTableColElement: THTMLTableColElement;
  676. function CreateTableSectionElement: THTMLTableSectionElement;
  677. function CreateTableRowElement: THTMLTableRowElement;
  678. function CreateTableCellElement: THTMLTableCellElement;
  679. function CreateFrameSetElement: THTMLFrameSetElement;
  680. function CreateFrameElement: THTMLFrameElement;
  681. function CreateIFrameElement: THTMLIFrameElement;}
  682. end;
  683. implementation
  684. { THTMLCollection }
  685. constructor THTMLCollection.Create(aNode: TDOMNode; Proc: TFilterProc);
  686. begin
  687. inherited Create(aNode);
  688. FFilterProc := Proc;
  689. end;
  690. function THTMLCollection.NodeFilter(aNode: TDOMNode): TFilterResult;
  691. begin
  692. Result := FFilterProc(aNode);
  693. end;
  694. function THTMLCollection.NamedItem(const Index: DOMString): TDOMNode;
  695. var
  696. I: Cardinal;
  697. begin
  698. // Finds node with matching 'id' attribute
  699. for I := 0 to Length-1 do
  700. begin
  701. // TODO: could be improved when we're able to build ID table for HTML docs.
  702. Result := GetItem(I);
  703. if (Result.NodeType = ELEMENT_NODE) and (TDOMElement(Result)['id'] = Index) then
  704. Exit;
  705. end;
  706. // HTML4.01: additionally search for a node with matching 'name' attr
  707. Result := nil;
  708. end;
  709. { THTMLElement }
  710. function THTMLElement.GetForm: THTMLFormElement;
  711. var
  712. r: TDOMNode;
  713. begin
  714. // TODO: rewrite properly
  715. r := ParentNode;
  716. while Assigned(r) and (r.NodeName <> 'form') do
  717. r := r.ParentNode;
  718. result := THTMLFormElement(r);
  719. end;
  720. function THTMLElement.GetStrAttr(idx: THTMLAttributeTag): DOMString;
  721. begin
  722. // TODO: values of attributes that are value lists must be returned in lowercase
  723. result := GetAttribute(HTMLAttributeTag[idx]);
  724. end;
  725. procedure THTMLElement.SetStrAttr(idx: THTMLAttributeTag; const Value: DOMString);
  726. begin
  727. SetAttribute(HTMLAttributeTag[idx], Value);
  728. end;
  729. function THTMLElement.GetIntAttr(idx: THTMLAttributeTag): Integer;
  730. begin
  731. if not TryStrToInt(GetAttribute(HTMLAttributeTag[idx]), result) then
  732. result := 0;
  733. end;
  734. procedure THTMLElement.SetIntAttr(idx: THTMLAttributeTag; value: Integer);
  735. begin
  736. SetAttribute(HTMLAttributeTag[idx], IntToStr(value));
  737. end;
  738. function THTMLElement.GetUIntAttr(idx: THTMLAttributeTag): Cardinal;
  739. var
  740. tmp: DOMString;
  741. code: word;
  742. begin
  743. tmp := GetAttribute(HTMLAttributeTag[idx]);
  744. val(tmp, result, code);
  745. if code <> 0 then
  746. result := 0;
  747. end;
  748. procedure THTMLElement.SetUIntAttr(idx: THTMLAttributeTag; value: Cardinal);
  749. begin
  750. SetAttribute(HTMLAttributeTag[idx], IntToStr(value));
  751. end;
  752. function THTMLElement.GetBoolAttr(idx: THTMLAttributeTag): Boolean;
  753. begin
  754. // attribute value is irrelevant?
  755. result := HasAttribute(HTMLAttributeTag[idx]);
  756. end;
  757. procedure THTMLElement.SetBoolAttr(idx: THTMLAttributeTag; value: Boolean);
  758. begin
  759. if value then
  760. SetAttribute(HTMLAttributeTag[idx], HTMLAttributeTag[idx])
  761. else
  762. RemoveAttribute(HTMLAttributeTag[idx]);
  763. end;
  764. { THTMLTableElement }
  765. function TableRowFilter(aNode: TDOMNode): TFilterResult;
  766. begin
  767. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'tr') then
  768. Result := frNorecurseTrue
  769. else
  770. Result := frFalse;
  771. end;
  772. function TableBodyFilter(aNode: TDOMNode): TFilterResult;
  773. begin
  774. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'tbody') then
  775. Result := frNorecurseTrue
  776. else
  777. Result := frFalse;
  778. end;
  779. function THTMLTableElement.GetRows: THTMLCollection;
  780. begin
  781. result := THTMLCollection.Create(Self, @TableRowFilter);
  782. end;
  783. function THTMLTableElement.GetBodies: THTMLCollection;
  784. begin
  785. result := THTMLCollection.Create(Self, @TableBodyFilter);
  786. end;
  787. function THTMLTableElement.GetCaption: THTMLTableCaptionElement;
  788. var
  789. child: TDOMNode;
  790. begin
  791. child := FirstChild;
  792. while Assigned(child) do
  793. begin
  794. if child.NodeName = 'caption' then
  795. Break;
  796. child := child.NextSibling;
  797. end;
  798. result := THTMLTableCaptionElement(child);
  799. end;
  800. procedure THTMLTableElement.SetCaption(value: THTMLTableCaptionElement);
  801. begin
  802. // TODO: implement
  803. end;
  804. function THTMLTableElement.GetHead: THTMLTableSectionElement;
  805. var
  806. child: TDOMNode;
  807. begin
  808. child := FirstChild;
  809. while Assigned(child) do
  810. begin
  811. if child.NodeName = 'thead' then
  812. Break;
  813. child := child.NextSibling;
  814. end;
  815. result := THTMLTableSectionElement(child);
  816. end;
  817. procedure THTMLTableElement.SetHead(value: THTMLTableSectionElement);
  818. begin
  819. // TODO: implement
  820. end;
  821. function THTMLTableElement.GetFoot: THTMLTableSectionElement;
  822. var
  823. child: TDOMNode;
  824. begin
  825. child := FirstChild;
  826. while Assigned(child) do
  827. begin
  828. if child.NodeName = 'tfoot' then
  829. Break;
  830. child := child.NextSibling;
  831. end;
  832. result := THTMLTableSectionElement(child);
  833. end;
  834. procedure THTMLTableElement.SetFoot(value: THTMLTableSectionElement);
  835. begin
  836. // TODO: implement
  837. end;
  838. function THTMLTableElement.CreateTHead: THTMLElement;
  839. begin
  840. Result := GetHead;
  841. if Assigned(Result) then
  842. Exit;
  843. Result := THTMLTableSectionElement.Create(OwnerDocument);
  844. Result.FNSI.QName := THTMLDocument(OwnerDocument).HashForName('thead');
  845. AppendChild(Result);
  846. end;
  847. procedure THTMLTableElement.DeleteTHead;
  848. var
  849. node: TDOMNode;
  850. begin
  851. node := GetHead;
  852. if Assigned(node) then
  853. RemoveChild(node);
  854. end;
  855. function THTMLTableElement.CreateTFoot: THTMLElement;
  856. begin
  857. Result := GetFoot;
  858. if Assigned(Result) then
  859. Exit;
  860. Result := THTMLTableSectionElement.Create(OwnerDocument);
  861. Result.FNSI.QName := THTMLDocument(OwnerDocument).HashForName('tfoot');
  862. AppendChild(Result);
  863. end;
  864. procedure THTMLTableElement.DeleteTFoot;
  865. var
  866. node: TDOMNode;
  867. begin
  868. node := GetFoot;
  869. if Assigned(node) then
  870. RemoveChild(node);
  871. end;
  872. function THTMLTableElement.CreateCaption: THTMLElement;
  873. begin
  874. Result := GetCaption;
  875. if Assigned(Result) then
  876. Exit;
  877. Result := THTMLTableCaptionElement.Create(OwnerDocument);
  878. Result.FNSI.QName := THTMLDocument(OwnerDocument).HashForName('caption');
  879. AppendChild(Result);
  880. end;
  881. procedure THTMLTableElement.DeleteCaption;
  882. var
  883. node: TDOMNode;
  884. begin
  885. node := GetCaption;
  886. if Assigned(node) then
  887. RemoveChild(node);
  888. end;
  889. function THTMLTableElement.InsertRow(Index: Integer): THTMLElement;
  890. begin
  891. { Insert a new empty row in the table. The new row is inserted immediately
  892. before and in the same section as the current indexth row in the table.
  893. If index is -1 or equal to the number of rows, the new row is appended.
  894. In addition, when the table is empty the row is inserted into a TBODY which
  895. is created and inserted into the table. }
  896. Result := nil;
  897. end;
  898. procedure THTMLTableElement.DeleteRow(Index: Integer);
  899. begin
  900. end;
  901. { THTMLTableSectionElement }
  902. function THTMLTableSectionElement.GetRows: THTMLCollection;
  903. begin
  904. result := THTMLCollection.Create(Self, @TableRowFilter);
  905. end;
  906. function THTMLTableSectionElement.InsertRow(Index: Integer): THTMLElement;
  907. var
  908. row: TDOMNode;
  909. begin
  910. with GetRows do
  911. try
  912. if (Index < -1) or (Index > Integer(Length)) then
  913. raise EDOMIndexSize.Create('HTMLTableSectionElement.InsertRow');
  914. row := GetItem(LongWord(Index)); // may be nil
  915. Result := THTMLTableRowElement.Create(OwnerDocument);
  916. Result.FNSI.QName := THTMLDocument(OwnerDocument).HashForName('tr');
  917. InsertBefore(Result, row);
  918. finally
  919. Free;
  920. end;
  921. end;
  922. procedure THTMLTableSectionElement.DeleteRow(Index: Integer);
  923. var
  924. row: TDOMNode;
  925. begin
  926. with GetRows do
  927. try
  928. if Index = -1 then
  929. Index := Length-1;
  930. row := GetItem(LongWord(Index));
  931. if row = nil then
  932. raise EDOMIndexSize.Create('HTMLTableSectionElement.DeleteRow');
  933. RemoveChild(row);
  934. finally
  935. Free;
  936. end;
  937. end;
  938. { THTMLDocument }
  939. function THTMLDocument.GetTitle: DOMString;
  940. var
  941. Node: TDOMNode;
  942. begin
  943. Result := '';
  944. if not Assigned(DocumentElement) then
  945. exit;
  946. Node := DocumentElement.FirstChild;
  947. while Assigned(Node) and (Node.NodeName <> 'head') do
  948. Node := Node.NextSibling;
  949. if not Assigned(Node) then
  950. exit;
  951. Node := Node.FirstChild;
  952. while Assigned(Node) and (Node.NodeName <> 'title') do
  953. Node := Node.NextSibling;
  954. if not Assigned(Node) then
  955. exit;
  956. Node := Node.FirstChild;
  957. if Assigned(Node) and (Node.NodeType = TEXT_NODE) then
  958. Result := Node.NodeValue;
  959. end;
  960. procedure THTMLDocument.SetTitle(const Value: DOMString);
  961. var
  962. Node: TDOMNode;
  963. TitleEl: TDOMElement;
  964. begin
  965. if not Assigned(DocumentElement) then
  966. AppendChild(CreateHtmlElement);
  967. Node := DocumentElement.FirstChild;
  968. while Assigned(Node) and (Node.NodeName <> 'head') do
  969. Node := Node.NextSibling;
  970. if not Assigned(Node) then
  971. begin
  972. Node := CreateHeadElement;
  973. DocumentElement.InsertBefore(Node, DocumentElement.FirstChild);
  974. end;
  975. TitleEl := TDOMElement(Node.FirstChild);
  976. while Assigned(TitleEl) and (TitleEl.NodeName <> 'title') do
  977. TitleEl := TDOMElement(TitleEl.NextSibling);
  978. if not Assigned(TitleEl) then
  979. begin
  980. TitleEl := CreateElement('title');
  981. Node.AppendChild(TitleEl);
  982. end;
  983. while Assigned(TitleEl.FirstChild) do
  984. TitleEl.RemoveChild(TitleEl.FirstChild);
  985. TitleEl.AppendChild(CreateTextNode(Value));
  986. end;
  987. function THTMLDocument.GetBody: THTMLElement;
  988. var
  989. Node: TDOMNode;
  990. begin
  991. if not Assigned(DocumentElement) then
  992. AppendChild(CreateHtmlElement);
  993. Node := DocumentElement.FirstChild;
  994. while Assigned(Node) and (Node.NodeName <> 'body') do
  995. Node := Node.NextSibling;
  996. if not Assigned(Node) then
  997. begin
  998. Node := CreateBodyElement;
  999. DocumentElement.AppendChild(Node);
  1000. end;
  1001. result := THTMLElement(Node);
  1002. end;
  1003. procedure THTMLDocument.SetBody(value: THTMLElement);
  1004. begin
  1005. end;
  1006. function DocImageFilter(aNode: TDOMNode): TFilterResult;
  1007. begin
  1008. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'img') then
  1009. Result := frNorecurseTrue
  1010. else
  1011. Result := frFalse;
  1012. end;
  1013. function DocFormFilter(aNode: TDOMNode): TFilterResult;
  1014. begin
  1015. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'form') then
  1016. Result := frTrue
  1017. else
  1018. Result := frFalse;
  1019. end;
  1020. function DocAnchorFilter(aNode: TDOMNode): TFilterResult;
  1021. begin
  1022. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'a') and
  1023. TDOMElement(aNode).HasAttribute('name') then
  1024. Result := frTrue
  1025. else
  1026. Result := frFalse;
  1027. end;
  1028. function DocAppletFilter(aNode: TDOMNode): TFilterResult;
  1029. begin
  1030. if (aNode.NodeType = ELEMENT_NODE) and ((aNode.NodeName = 'applet') or
  1031. (aNode.NodeName = 'object')) then
  1032. Result := frTrue
  1033. else
  1034. Result := frFalse;
  1035. end;
  1036. function DocLinksFilter(aNode: TDOMNode): TFilterResult;
  1037. begin
  1038. if (aNode.NodeType = ELEMENT_NODE) and ((aNode.NodeName = 'area') or
  1039. ((aNode.NodeName = 'a') and TDOMElement(aNode).HasAttribute('href'))) then
  1040. Result := frTrue
  1041. else
  1042. Result := frFalse;
  1043. end;
  1044. type
  1045. TByNameNodeList = class(TDOMNodeList)
  1046. protected
  1047. FFilter: DOMString;
  1048. function NodeFilter(aNode: TDOMNode): TFilterResult; override;
  1049. public
  1050. constructor Create(aNode: TDOMNode; const aFilter: DOMString);
  1051. end;
  1052. constructor TByNameNodeList.Create(aNode: TDOMNode; const aFilter: DOMString);
  1053. begin
  1054. inherited Create(aNode);
  1055. FFilter := aFilter;
  1056. end;
  1057. function TByNameNodeList.NodeFilter(aNode: TDOMNode): TFilterResult;
  1058. begin
  1059. if (aNode.NodeType = ELEMENT_NODE) and (TDOMElement(aNode)['name'] = FFilter) then
  1060. Result := frTrue
  1061. else
  1062. Result := frFalse;
  1063. end;
  1064. function THTMLDocument.GetAnchors: THTMLCollection;
  1065. begin
  1066. Result := THTMLCollection.Create(Self, @DocAnchorFilter);
  1067. end;
  1068. function THTMLDocument.GetApplets: THTMLCollection;
  1069. begin
  1070. Result := THTMLCollection.Create(Self, @DocAppletFilter);
  1071. end;
  1072. function THTMLDocument.GetForms: THTMLCollection;
  1073. begin
  1074. Result := THTMLCollection.Create(Self, @DocFormFilter);
  1075. end;
  1076. function THTMLDocument.GetImages: THTMLCollection;
  1077. begin
  1078. Result := THTMLCollection.Create(Self, @DocImageFilter);
  1079. end;
  1080. function THTMLDocument.GetLinks: THTMLCollection;
  1081. begin
  1082. Result := THTMLCollection.Create(Self, @DocLinksFilter);
  1083. end;
  1084. function THTMLDocument.GetDomain: DOMString;
  1085. begin
  1086. Result := '';
  1087. end;
  1088. function THTMLDocument.GetReferrer: DOMString;
  1089. begin
  1090. Result := '';
  1091. end;
  1092. function THTMLDocument.GetCookie: DOMString;
  1093. begin
  1094. Result := '';
  1095. end;
  1096. procedure THTMLDocument.SetCookie(const Value: DOMString);
  1097. begin
  1098. end;
  1099. procedure THTMLDocument.Open;
  1100. begin
  1101. end;
  1102. procedure THTMLDocument.Close;
  1103. begin
  1104. end;
  1105. procedure THTMLDocument.Write(const AText: DOMString);
  1106. begin
  1107. end;
  1108. procedure THTMLDocument.WriteLn(const AText: DOMString);
  1109. begin
  1110. end;
  1111. function THTMLDocument.GetElementsByName(const ElementName: DOMString): TDOMNodeList;
  1112. begin
  1113. Result := TByNameNodeList.Create(Self, ElementName);
  1114. end;
  1115. function THTMLDocument.CreateElement(const tagName: DOMString; UseSpecificClass : Boolean = True): THTMLElement;
  1116. var
  1117. elClass: TDOMElementClass;
  1118. begin
  1119. elClass:=THTMLElement;
  1120. if UseSpecificClass then
  1121. case UpperCase(tagName) of
  1122. 'HTML' : elClass:= THTMLHtmlElement;
  1123. 'HEAD' : elClass:= THTMLHeadElement;
  1124. 'BODY' : elClass:= THTMLBodyElement;
  1125. 'P' : elClass:= THTMLParagraphElement;
  1126. 'LINK' : elClass:= THTMLLinkElement;
  1127. 'TITLE' : elClass:= THTMLTitleElement;
  1128. 'META' : elClass:= THTMLMetaElement;
  1129. 'BASE' : elClass:= THTMLBaseElement;
  1130. 'ISINDEX' : elClass:= THTMLIsIndexElement;
  1131. 'STYLE' : elClass:= THTMLStyleElement;
  1132. 'FORM' : elClass:= THTMLFormElement;
  1133. 'SELECT' : elClass:= THTMLSelectElement;
  1134. 'OPTGROUP' : elClass:= THTMLOptGroupElement;
  1135. 'OPTION' : elClass:= THTMLOptionElement;
  1136. 'INPUT' : elClass:= THTMLInputElement;
  1137. 'TEXTAREA' : elClass:= THTMLTextAreaElement;
  1138. 'BUTTON' : elClass:= THTMLButtonElement;
  1139. 'LABEL' : elClass:= THTMLLabelElement;
  1140. 'FIELDSET' : elClass:= THTMLFieldSetElement;
  1141. 'LEGEND' : elClass:= THTMLLegendElement;
  1142. 'UL' : elClass:= THTMLUListElement;
  1143. 'OL' : elClass:= THTMLOListElement;
  1144. 'DL' : elClass:= THTMLDListElement;
  1145. 'DIRECTORY' : elClass:= THTMLDirectoryElement;
  1146. 'MENU' : elClass:= THTMLMenuElement;
  1147. 'LI' : elClass:= THTMLLIElement;
  1148. 'DIV' : elClass:= THTMLDivElement;
  1149. 'H1','H2','H3','H4','H5',
  1150. 'H6','H7','H8','H9' : elClass:= THTMLHeadingElement;
  1151. 'QUOTE' : elClass:= THTMLQuoteElement;
  1152. 'PRE' : elClass:= THTMLPreElement;
  1153. 'BR' : elClass:= THTMLBRElement;
  1154. 'BASEFONT' : elClass:= THTMLBaseFontElement;
  1155. 'FONT' : elClass:= THTMLFontElement;
  1156. 'HR' : elClass:= THTMLHRElement;
  1157. 'MOD' : elClass:= THTMLModElement;
  1158. 'A' : elClass:= THTMLAnchorElement;
  1159. 'IMG' : elClass:= THTMLImageElement;
  1160. 'OBJECT' : elClass:= THTMLObjectElement;
  1161. 'PARAM' : elClass:= THTMLParamElement;
  1162. 'APPLET' : elClass:= THTMLAppletElement;
  1163. 'MAP' : elClass:= THTMLMapElement;
  1164. 'AREA' : elClass:= THTMLAreaElement;
  1165. 'SCRIPT' : elClass:= THTMLScriptElement;
  1166. 'TABLE' : elClass:= THTMLTableElement;
  1167. 'CAPTION' : elClass:= THTMLTableCaptionElement;
  1168. //'TABLECOL' : elClass:= THTMLTableColElement;
  1169. 'THEAD','TBODY',
  1170. 'TFOOT' : elClass:= THTMLTableSectionElement;
  1171. 'TR' : elClass:= THTMLTableRowElement;
  1172. 'TD','TH' : elClass:= THTMLTableCellElement;
  1173. 'FRAMESET' : elClass:= THTMLFrameSetElement;
  1174. 'FRAME' : elClass:= THTMLFrameElement;
  1175. 'IFRAME' : elClass:= THTMLIFrameElement;
  1176. end;
  1177. Result := THTMLElement(elClass.Create(Self));
  1178. Result.FNSI.QName:=HashForName(tagName);
  1179. end;
  1180. function THTMLDocument.HashForName(const aName: DOMString): PHashItem;
  1181. begin
  1182. Result := FNames.FindOrAdd(DOMPChar(aName), Length(aName));
  1183. end;
  1184. function THTMLDocument.CreateSubElement: THTMLElement; begin Result := CreateElement('sub') end;
  1185. function THTMLDocument.CreateSupElement: THTMLElement; begin Result := CreateElement('sup') end;
  1186. function THTMLDocument.CreateSpanElement: THTMLElement; begin Result := CreateElement('span') end;
  1187. function THTMLDocument.CreateBDOElement: THTMLElement; begin Result := CreateElement('bdo') end;
  1188. function THTMLDocument.CreateTTElement: THTMLElement; begin Result := CreateElement('tt') end;
  1189. function THTMLDocument.CreateIElement: THTMLElement; begin Result := CreateElement('i') end;
  1190. function THTMLDocument.CreateBElement: THTMLElement; begin Result := CreateElement('b') end;
  1191. function THTMLDocument.CreateUElement: THTMLElement; begin Result := CreateElement('u') end;
  1192. function THTMLDocument.CreateSElement: THTMLElement; begin Result := CreateElement('s') end;
  1193. function THTMLDocument.CreateStrikeElement: THTMLElement; begin Result := CreateElement('strike') end;
  1194. function THTMLDocument.CreateBigElement: THTMLElement; begin Result := CreateElement('big') end;
  1195. function THTMLDocument.CreateSmallElement: THTMLElement; begin Result := CreateElement('small') end;
  1196. function THTMLDocument.CreateEmElement: THTMLElement; begin Result := CreateElement('em') end;
  1197. function THTMLDocument.CreateStrongElement: THTMLElement; begin Result := CreateElement('strong') end;
  1198. function THTMLDocument.CreateDfnElement: THTMLElement; begin Result := CreateElement('dfn') end;
  1199. function THTMLDocument.CreateCodeElement: THTMLElement; begin Result := CreateElement('code') end;
  1200. function THTMLDocument.CreateSampElement: THTMLElement; begin Result := CreateElement('samp') end;
  1201. function THTMLDocument.CreateKbdElement: THTMLElement; begin Result := CreateElement('kbd') end;
  1202. function THTMLDocument.CreateVarElement: THTMLElement; begin Result := CreateElement('var') end;
  1203. function THTMLDocument.CreateCiteElement: THTMLElement; begin Result := CreateElement('cite') end;
  1204. function THTMLDocument.CreateAcronymElement: THTMLElement; begin Result := CreateElement('acronym') end;
  1205. function THTMLDocument.CreateAbbrElement: THTMLElement; begin Result := CreateElement('abbr') end;
  1206. function THTMLDocument.CreateDDElement: THTMLElement; begin Result := CreateElement('dd') end;
  1207. function THTMLDocument.CreateDTElement: THTMLElement; begin Result := CreateElement('dt') end;
  1208. function THTMLDocument.CreateNoFramesElement: THTMLElement; begin Result := CreateElement('noframes') end;
  1209. function THTMLDocument.CreateNoScriptElement: THTMLElement; begin Result := CreateElement('noscript') end;
  1210. function THTMLDocument.CreateAddressElement: THTMLElement; begin Result := CreateElement('address') end;
  1211. function THTMLDocument.CreateCenterElement: THTMLElement; begin Result := CreateElement('center') end;
  1212. function THTMLDocument.CreateHtmlElement: THTMLHtmlElement;
  1213. begin
  1214. Result := THTMLHtmlElement.Create(Self);
  1215. Result.FNSI.QName := HashForName('html');
  1216. end;
  1217. function THTMLDocument.CreateHeadElement: THTMLHeadElement;
  1218. begin
  1219. Result := THTMLHeadElement.Create(Self);
  1220. Result.FNSI.QName := HashForName('head');
  1221. end;
  1222. function THTMLDocument.CreateLinkElement: THTMLLinkElement;
  1223. begin
  1224. Result := THTMLLinkElement.Create(Self);
  1225. Result.FNSI.QName := HashForName('a');
  1226. end;
  1227. function THTMLDocument.CreateTitleElement: THTMLTitleElement;
  1228. begin
  1229. Result := THTMLTitleElement.Create(Self);
  1230. Result.FNSI.QName := HashForName('title');
  1231. end;
  1232. function THTMLDocument.CreateMetaElement: THTMLMetaElement;
  1233. begin
  1234. Result := THTMLMetaElement.Create(Self);
  1235. Result.FNSI.QName := HashForName('meta');
  1236. end;
  1237. function THTMLDocument.CreateBodyElement: THTMLBodyElement;
  1238. begin
  1239. Result := THTMLBodyElement.Create(Self);
  1240. Result.FNSI.QName := HashForName('body');
  1241. end;
  1242. function THTMLDocument.CreateUListElement: THTMLUListElement;
  1243. begin
  1244. Result := THTMLUListElement.Create(Self);
  1245. Result.FNSI.QName := HashForName('ul');
  1246. end;
  1247. function THTMLDocument.CreateOListElement: THTMLOListElement;
  1248. begin
  1249. Result := THTMLOListElement.Create(Self);
  1250. Result.FNSI.QName := HashForName('ol');
  1251. end;
  1252. function THTMLDocument.CreateDListElement: THTMLDListElement;
  1253. begin
  1254. Result := THTMLDListElement.Create(Self);
  1255. Result.FNSI.QName := HashForName('dl');
  1256. end;
  1257. function THTMLDocument.CreateLIElement: THTMLLIElement;
  1258. begin
  1259. Result := THTMLLIElement.Create(Self);
  1260. Result.FNSI.QName := HashForName('li');
  1261. end;
  1262. //...
  1263. function THTMLDocument.CreateParagraphElement: THTMLParagraphElement;
  1264. begin
  1265. Result := THTMLParagraphElement.Create(Self);
  1266. Result.FNSI.QName := HashForName('p');
  1267. end;
  1268. { THTMLFormElement }
  1269. function FormElementsFilter(aNode: TDOMNode): TFilterResult;
  1270. begin
  1271. if (aNode.NodeType = ELEMENT_NODE) and ((aNode.NodeName = 'input') or
  1272. (aNode.NodeName = 'select') or (aNode.NodeName = 'textarea') or
  1273. (aNode.NodeName = 'label') or (aNode.NodeName = 'button')) then
  1274. Result := frTrue
  1275. else
  1276. Result := frFalse;
  1277. end;
  1278. function THTMLFormElement.GetElements: THTMLCollection;
  1279. begin
  1280. result := THTMLCollection.Create(Self, @FormElementsFilter);
  1281. end;
  1282. function THTMLFormElement.GetLength: Integer;
  1283. begin
  1284. with GetElements do
  1285. try
  1286. Result := Length;
  1287. finally
  1288. Free;
  1289. end;
  1290. end;
  1291. procedure THTMLFormElement.Submit;
  1292. begin
  1293. end;
  1294. procedure THTMLFormElement.Reset;
  1295. begin
  1296. end;
  1297. { THTMLMapElement }
  1298. function MapAreasFilter(aNode: TDOMNode): TFilterResult;
  1299. begin
  1300. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'area') then
  1301. Result := frTrue
  1302. else
  1303. Result := frFalse;
  1304. end;
  1305. function THTMLMapElement.GetAreas: THTMLCollection;
  1306. begin
  1307. result := THTMLCollection.Create(Self, @MapAreasFilter);
  1308. end;
  1309. { THTMLSelectElement }
  1310. function SelectOptionFilter(aNode: TDOMNode): TFilterResult;
  1311. begin
  1312. if (aNode.NodeType = ELEMENT_NODE) and (aNode.NodeName = 'option') then
  1313. Result := frTrue
  1314. else
  1315. Result := frFalse;
  1316. end;
  1317. function THTMLSelectElement.GetType: DOMString;
  1318. begin
  1319. if HasAttribute(HTMLAttributeTag[atmultiple]) then
  1320. result := 'select-multiple'
  1321. else
  1322. result := 'select-one';
  1323. end;
  1324. function THTMLSelectElement.GetValue: DOMString;
  1325. begin
  1326. result := '';
  1327. end;
  1328. procedure THTMLSelectElement.SetValue(const value: DOMString);
  1329. begin
  1330. end;
  1331. function THTMLSelectElement.GetOptions: THTMLOptionsCollection;
  1332. begin
  1333. result := THTMLOptionsCollection.Create(Self, @SelectOptionFilter);
  1334. end;
  1335. procedure THTMLSelectElement.Add(Element, Before: THTMLElement);
  1336. begin
  1337. end;
  1338. procedure THTMLSelectElement.Remove(Index: Integer);
  1339. begin
  1340. end;
  1341. procedure THTMLSelectElement.Blur;
  1342. begin
  1343. end;
  1344. procedure THTMLSelectElement.Focus;
  1345. begin
  1346. end;
  1347. function THTMLSelectElement.GetLength: Cardinal;
  1348. begin
  1349. with GetOptions do
  1350. try
  1351. Result := Length;
  1352. finally
  1353. Free;
  1354. end;
  1355. end;
  1356. procedure THTMLSelectElement.SetLength(aValue: Cardinal);
  1357. begin
  1358. raise EDOMNotSupported.Create('HTMLSelectElement.SetLength');
  1359. end;
  1360. { THTMLTableRowElement }
  1361. function RowCellsFilter(aNode: TDOMNode): TFilterResult;
  1362. begin
  1363. if (aNode.NodeType = ELEMENT_NODE) and
  1364. ((aNode.NodeName = 'td') or (aNode.NodeName = 'th')) then
  1365. Result := frNorecurseTrue
  1366. else
  1367. Result := frFalse;
  1368. end;
  1369. function THTMLTableRowElement.GetCells: THTMLCollection;
  1370. begin
  1371. result := THTMLCollection.Create(Self, @RowCellsFilter);
  1372. end;
  1373. function THTMLTableRowElement.GetRowIndex: Integer;
  1374. begin
  1375. { result := SectionRowIndex;
  1376. if parent is 'tbody' then inc(result, table.head.rowcount);
  1377. if parent is 'tfoot' then inc(result, table.bodies.rowcount);
  1378. // what about multiple bodies?
  1379. }
  1380. result := -1;
  1381. end;
  1382. function THTMLTableRowElement.GetSectionRowIndex: Integer;
  1383. var
  1384. node: TDOMNode;
  1385. begin
  1386. result := 0;
  1387. node := PreviousSibling;
  1388. while Assigned(node) do
  1389. begin
  1390. // TODO: should we also check whether the name is same?
  1391. if node.NodeType = ELEMENT_NODE then
  1392. Inc(result);
  1393. node := node.PreviousSibling;
  1394. end;
  1395. end;
  1396. function THTMLTableRowElement.InsertCell(Index: Integer): THTMLElement;
  1397. var
  1398. cell: TDOMNode;
  1399. begin
  1400. with GetCells do
  1401. try
  1402. if (Index < -1) or (Index > Integer(Length)) then
  1403. raise EDOMIndexSize.Create('HTMLTableRowElement.InsertCell');
  1404. cell := GetItem(LongWord(Index)); // may be nil
  1405. Result := THTMLTableCellElement.Create(OwnerDocument);
  1406. Result.FNSI.QName := THTMLDocument(OwnerDocument).HashForName('td');
  1407. InsertBefore(Result, cell);
  1408. finally
  1409. Free;
  1410. end;
  1411. end;
  1412. procedure THTMLTableRowElement.DeleteCell(Index: Integer);
  1413. var
  1414. cell: TDOMNode;
  1415. begin
  1416. with GetCells do
  1417. try
  1418. if Index = -1 then
  1419. Index := Length-1;
  1420. cell := GetItem(LongWord(Index));
  1421. if cell = nil then
  1422. raise EDOMIndexSize.Create('HTMLTableRowElement.DeleteCell');
  1423. RemoveChild(cell);
  1424. finally
  1425. Free;
  1426. end;
  1427. end;
  1428. { THTMLTableCellElement }
  1429. function THTMLTableCellElement.GetCellIndex: Integer;
  1430. var
  1431. node: TDOMNode;
  1432. begin
  1433. result := 0;
  1434. node := PreviousSibling;
  1435. while Assigned(node) do
  1436. begin
  1437. // TODO: should we also check whether the name is same?
  1438. if node.NodeType = ELEMENT_NODE then
  1439. Inc(result);
  1440. node := node.PreviousSibling;
  1441. end;
  1442. end;
  1443. { THTMLOptionElement }
  1444. // TODO: probably should account for possible OPTGROUP elements (no tests)
  1445. function THTMLOptionElement.GetIndex: Integer;
  1446. var
  1447. node: TDOMNode;
  1448. begin
  1449. result := 0;
  1450. node := PreviousSibling;
  1451. while Assigned(node) do
  1452. begin
  1453. // TODO: should we also check whether the name is same?
  1454. if node.NodeType = ELEMENT_NODE then
  1455. Inc(result);
  1456. node := node.PreviousSibling;
  1457. end;
  1458. end;
  1459. { THTMLTextAreaElement }
  1460. function THTMLTextAreaElement.GetType: DOMString;
  1461. begin
  1462. result := 'textarea';
  1463. end;
  1464. procedure THTMLTextAreaElement.Blur;
  1465. begin
  1466. end;
  1467. procedure THTMLTextAreaElement.Focus;
  1468. begin
  1469. end;
  1470. procedure THTMLTextAreaElement.Select;
  1471. begin
  1472. end;
  1473. { THTMLInputElement }
  1474. procedure THTMLInputElement.Blur;
  1475. begin
  1476. end;
  1477. procedure THTMLInputElement.Focus;
  1478. begin
  1479. end;
  1480. procedure THTMLInputElement.Select;
  1481. begin
  1482. end;
  1483. procedure THTMLInputElement.Click;
  1484. begin
  1485. end;
  1486. { THTMLAnchorElement }
  1487. procedure THTMLAnchorElement.Blur;
  1488. begin
  1489. end;
  1490. procedure THTMLAnchorElement.Focus;
  1491. begin
  1492. end;
  1493. { THTMLObjectElement }
  1494. function THTMLObjectElement.GetContentDocument: TDOMDocument;
  1495. begin
  1496. result := nil;
  1497. end;
  1498. { THTMLScriptElement }
  1499. function THTMLScriptElement.GetEvent: DOMString;
  1500. begin
  1501. Result := '';
  1502. end;
  1503. procedure THTMLScriptElement.SetEvent(const Value: DOMString);
  1504. begin
  1505. end;
  1506. end.