1------------------------------------------------------------------------------
2--                                                                          --
3--                            Matreshka Project                             --
4--                                                                          --
5--                               Web Framework                              --
6--                                                                          --
7--                            Web API Definition                            --
8--                                                                          --
9------------------------------------------------------------------------------
10--                                                                          --
11-- Copyright © 2014-2015, Vadim Godunko <vgodunko@gmail.com>                --
12-- All rights reserved.                                                     --
13--                                                                          --
14-- Redistribution and use in source and binary forms, with or without       --
15-- modification, are permitted provided that the following conditions       --
16-- are met:                                                                 --
17--                                                                          --
18--  * Redistributions of source code must retain the above copyright        --
19--    notice, this list of conditions and the following disclaimer.         --
20--                                                                          --
21--  * Redistributions in binary form must reproduce the above copyright     --
22--    notice, this list of conditions and the following disclaimer in the   --
23--    documentation and/or other materials provided with the distribution.  --
24--                                                                          --
25--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
26--    contributors may be used to endorse or promote products derived from  --
27--    this software without specific prior written permission.              --
28--                                                                          --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
40--                                                                          --
41------------------------------------------------------------------------------
42--  $Revision: 5324 $ $Date: 2015-05-20 16:26:45 +0300 (Wed, 20 May 2015) $
43------------------------------------------------------------------------------
44--  This package provides binding to interface Document.
45------------------------------------------------------------------------------
46with League.Strings;
47
48with WebAPI.DOM.Comments;
49with WebAPI.DOM.Document_Fragments;
50with WebAPI.DOM.Document_Types;
51with WebAPI.DOM.Elements;
52with WebAPI.DOM.HTML_Collections;
53with WebAPI.DOM.Nodes;
54with WebAPI.DOM.Non_Element_Parent_Nodes;
55with WebAPI.DOM.Parent_Nodes;
56with WebAPI.DOM.Processing_Instructions;
57with WebAPI.DOM.Texts;
58
59package WebAPI.DOM.Documents is
60
61   pragma Preelaborate;
62
63   type Document is limited interface
64     and WebAPI.DOM.Nodes.Node
65     and WebAPI.DOM.Non_Element_Parent_Nodes.Non_Element_Parent_Node
66     and WebAPI.DOM.Parent_Nodes.Parent_Node;
67
68   type Document_Access is access all Document'Class
69     with Storage_Size => 0;
70
71   --  XXX Not binded yet:
72   --    [SameObject] readonly attribute DOMImplementation implementation;
73
74   not overriding function Get_URL
75    (Self : not null access constant Document)
76       return League.Strings.Universal_String is abstract
77         with Import        => True,
78              Convention    => JavaScript_Property_Getter,
79              External_Name => "URL";
80   --  Returns document's URL.
81
82   not overriding function Get_Document_URI
83    (Self : not null access constant Document)
84       return League.Strings.Universal_String is abstract
85         with Import        => True,
86              Convention    => JavaScript_Property_Getter,
87              External_Name => "documentURI";
88   --  Returns document's URL.
89
90   not overriding function Get_Compat_Mode
91    (Self : not null access constant Document)
92       return League.Strings.Universal_String is abstract
93         with Import        => True,
94              Convention    => JavaScript_Property_Getter,
95              External_Name => "compatMode";
96   --  Returns the string "CSS1Compat" if document is in no-quirks mode or
97   --  limited-quirks mode, and "BackCompat", if document is in quirks mode.
98
99   not overriding function Get_Character_Set
100    (Self : not null access constant Document)
101       return League.Strings.Universal_String is abstract
102         with Import        => True,
103              Convention    => JavaScript_Property_Getter,
104              External_Name => "characterSet";
105   --  Returns document's encoding.
106
107   not overriding function Get_Content_Type
108    (Self : not null access constant Document)
109       return League.Strings.Universal_String is abstract
110         with Import        => True,
111              Convention    => JavaScript_Property_Getter,
112              External_Name => "contentType";
113   --  Returns document's content type.
114
115   not overriding function Get_Doctype
116    (Self : not null access constant Document)
117       return WebAPI.DOM.Document_Types.Document_Type_Access is abstract
118         with Import        => True,
119              Convention    => JavaScript_Property_Getter,
120              External_Name => "doctype";
121   --  Returns the doctype or null if there is none.
122
123   not overriding function Get_Document_Element
124    (Self : not null access constant Document)
125       return WebAPI.DOM.Elements.Element_Access is abstract
126         with Import        => True,
127              Convention    => JavaScript_Property_Getter,
128              External_Name => "documentElement";
129   --  Returns the document element.
130
131   not overriding function Get_Elements_By_Tag_Name
132    (Self       : not null access constant Document;
133     Local_Name : League.Strings.Universal_String)
134       return WebAPI.DOM.HTML_Collections.HTML_Collection is abstract
135         with Import        => True,
136              Convention    => JavaScript_Function,
137              External_Name => "getElementsByTagName";
138   --  If localName is "*" returns a HTMLCollection of all descendant elements.
139   --
140   --  Otherwise, returns a HTMLCollection of all descendant elements whose
141   --  local name is localName. (Matches case-insensitively against elements in
142   --  the HTML namespace within an HTML document.)
143
144   not overriding function Get_Elements_By_Tag_Name_NS
145    (Self          : not null access constant Document;
146     Namespace_URI : League.Strings.Universal_String;
147     Local_Name    : League.Strings.Universal_String)
148       return WebAPI.DOM.HTML_Collections.HTML_Collection is abstract
149         with Import        => True,
150              Convention    => JavaScript_Function,
151              External_Name => "getElementsByTagNameNS";
152   --  If namespace and localName are "*" returns a HTMLCollection of all
153   --  descendant elements.
154   --
155   --  If only namespace is "*" returns a HTMLCollection of all descendant
156   --  elements whose local name is localName.
157   --
158   --  If only localName is "*" returns a HTMLCollection of all descendant
159   --  elements whose namespace is namespace.
160   --
161   --  Otherwise, returns a HTMLCollection of all descendant elements whose
162   --  namespace is namespace and local name is localName.
163
164   not overriding function Get_Elements_By_Class_Name
165    (Self        : not null access constant Document;
166     Class_Names : League.Strings.Universal_String)
167       return WebAPI.DOM.HTML_Collections.HTML_Collection is abstract
168         with Import        => True,
169              Convention    => JavaScript_Function,
170              External_Name => "getElementsByClassName";
171   --  Returns a HTMLCollection of the elements in the object on which the
172   --  method was invoked (a document or an element) that have all the classes
173   --  given by classes.
174   --
175   --  The classes argument is interpreted as a space-separated list of
176   --  classes.
177
178   not overriding function Create_Element
179    (Self       : not null access Document;
180     Local_Name : League.Strings.Universal_String)
181       return not null WebAPI.DOM.Elements.Element_Access is abstract
182         with Import     => True,
183              Convention => JavaScript_Function,
184              Link_Name  => "createElement";
185   --  Returns an element in the HTML namespace with localName as local name.
186   --  (In an HTML document localName is lowercased.)
187   --
188   --  If localName does not match the Name production an
189   --  "InvalidCharacterError" exception will be thrown.
190
191   not overriding function Create_Element_NS
192    (Self           : not null access Document;
193     Namespace_URI  : League.Strings.Universal_String;
194     Qialified_Name : League.Strings.Universal_String)
195       return not null WebAPI.DOM.Elements.Element_Access is abstract
196         with Import     => True,
197              Convention => JavaScript_Function,
198              Link_Name  => "createElementNS";
199   --  Returns an element with namespace namespace. Its namespace prefix will
200   --  be everything before ":" (U+003E) in qualifiedName or null. Its local
201   --  name will be everything after ":" (U+003E) in qualifiedName or
202   --  qualifiedName.
203   --
204   --  If localName does not match the Name production an
205   --  "InvalidCharacterError" exception will be thrown.
206   --
207   --  If one of the following conditions is true a "NamespaceError" exception
208   --  will be thrown:
209   --
210   --   - localName does not match the QName production.
211   --   - Namespace prefix is not null and namespace is the empty string.
212   --   - Namespace prefix is "xml" and namespace is not the XML namespace.
213   --   - qualifiedName or namespace prefix is "xmlns" and namespace is not the
214   --     XMLNS namespace.
215   --   - namespace is the XMLNS namespace and neither qualifiedName nor
216   --     namespace prefix is "xmlns".
217
218   not overriding function Create_Document_Fragment
219    (Self : not null access Document)
220       return not null WebAPI.DOM.Document_Fragments.Document_Fragment_Access
221         is abstract
222           with Import     => True,
223                Convention => JavaScript_Function,
224                Link_Name  => "createDocumentFragment";
225   --  Returns a DocumentFragment node.
226
227   not overriding function Create_Text_Node
228    (Self : not null access Document;
229     Data : League.Strings.Universal_String)
230       return not null WebAPI.DOM.Texts.Text_Access is abstract
231         with Import     => True,
232              Convention => JavaScript_Function,
233              Link_Name  => "createTextNode";
234   --  Returns a Text node whose data is data.
235
236   not overriding function Create_Comment
237    (Self : not null access Document;
238     Data : League.Strings.Universal_String)
239       return WebAPI.DOM.Comments.Comment_Access is abstract
240         with Import     => True,
241              Convention => JavaScript_Function,
242              Link_Name  => "createComment";
243   --  Returns a Comment node whose data is data.
244
245   not overriding function Create_Processing_Instruction
246    (Self   : not null access Document;
247     Target : League.Strings.Universal_String;
248     Data   : League.Strings.Universal_String)
249       return WebAPI.DOM.Processing_Instructions.Processing_Instruction_Access
250         is abstract
251           with Import     => True,
252                Convention => JavaScript_Function,
253                Link_Name  => "createProcessingInstruction";
254   --  Returns a ProcessingInstruction node whose target is target and data is
255   --  data.
256   --
257   --  If target does not match the Name production an "InvalidCharacterError"
258   --  exception will be thrown.
259   --
260   --  If data contains "?>" an "InvalidCharacterError" exception will be
261   --  thrown.
262
263   not overriding function Import_Node
264    (Self : not null access Document;
265     Node : not null access WebAPI.DOM.Nodes.Node'Class;
266     Deep : Boolean := False)
267       return WebAPI.DOM.Nodes.Node_Access is abstract
268         with Import     => True,
269              Convention => JavaScript_Function,
270              Link_Name  => "importNode";
271   --  Returns a copy of node. If deep is true, the copy also includes the
272   --  node's descendants.
273   --
274   --  If node is a document throws a "NotSupportedError" exception.
275
276   not overriding function Adopt_Node
277    (Self : not null access Document;
278     Node : not null access WebAPI.DOM.Nodes.Node'Class)
279       return WebAPI.DOM.Nodes.Node_Access is abstract
280         with Import     => True,
281              Convention => JavaScript_Function,
282              Link_Name  => "adoptNode";
283   procedure Adopt_Node
284    (Self : not null access Document'Class;
285     Node : not null access WebAPI.DOM.Nodes.Node'Class)
286       with Import     => True,
287            Convention => JavaScript_Function,
288            Link_Name  => "adoptNode";
289   --  Moves node from another document and returns it.
290   --
291   --  If node is a document throws a "NotSupportedError" exception.
292
293   --  XXX Not binded yet:
294   --    [NewObject] Event createEvent(DOMString interface);
295
296   --  XXX Not binded yet:
297   --    [NewObject] Range createRange();
298
299   --  XXX Not binded yet:
300   --    // NodeFilter.SHOW_ALL = 0xFFFFFFFF
301   --    [NewObject] NodeIterator createNodeIterator(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
302   --    [NewObject] TreeWalker createTreeWalker(Node root, optional unsigned long whatToShow = 0xFFFFFFFF, optional NodeFilter? filter = null);
303
304end WebAPI.DOM.Documents;
305