dom_html.pp 60 KB

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