/*
 * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved.
 * Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

module core {

    interface [
        CustomToJSObject,
        JSGenerateToNativeObject,
        JSInlineGetOwnPropertySlot
    ] Document : Node {

        // DOM Level 1 Core
        readonly attribute DocumentType doctype;
        readonly attribute DOMImplementation implementation;
        readonly attribute Element documentElement;

        [ReturnNewObject] Element createElement(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString tagName)
            raises (DOMException);
        DocumentFragment   createDocumentFragment();
        [ReturnNewObject] Text createTextNode(in [Optional=DefaultIsUndefined] DOMString data);
        [ReturnNewObject] Comment createComment(in [Optional=DefaultIsUndefined] DOMString data);
        [ReturnNewObject] CDATASection createCDATASection(in [Optional=DefaultIsUndefined] DOMString data)
            raises(DOMException);
        [ObjCLegacyUnnamedParameters, ReturnNewObject] ProcessingInstruction createProcessingInstruction(in [Optional=DefaultIsUndefined] DOMString target,
                                                                                     in [Optional=DefaultIsUndefined] DOMString data)
            raises (DOMException);
        [ReturnNewObject] Attr createAttribute(in [Optional=DefaultIsUndefined] DOMString name)
            raises (DOMException);
        [ReturnNewObject] EntityReference createEntityReference(in [Optional=DefaultIsUndefined] DOMString name)
            raises(DOMException);
        NodeList           getElementsByTagName(in [Optional=DefaultIsUndefined] DOMString tagname);

        // Introduced in DOM Level 2:

        [ObjCLegacyUnnamedParameters, ReturnNewObject] Node importNode(in [Optional=DefaultIsUndefined] Node importedNode,
                                                   in [Optional] boolean deep)
            raises (DOMException);
        [ObjCLegacyUnnamedParameters, ReturnNewObject] Element createElementNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI,
                                                           in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName)
            raises (DOMException);
        [ObjCLegacyUnnamedParameters, ReturnNewObject] Attr createAttributeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI,
                                                          in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName)
            raises (DOMException);
        [ObjCLegacyUnnamedParameters] NodeList getElementsByTagNameNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI,
                                                       in [Optional=DefaultIsUndefined] DOMString localName);
        Element            getElementById(in [Optional=DefaultIsUndefined] DOMString elementId);

        // DOM Level 3 Core

        readonly attribute [TreatReturnedNullStringAs=Null] DOMString inputEncoding;

        readonly attribute [TreatReturnedNullStringAs=Null] DOMString xmlEncoding;
                 attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString xmlVersion
                    setter raises (DOMException);
                 attribute boolean xmlStandalone
                    setter raises (DOMException);

        Node               adoptNode(in [Optional=DefaultIsUndefined] Node source)
            raises (DOMException);

                 attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString documentURI;

        // DOM Level 2 Events (DocumentEvents interface)

        Event              createEvent(in [Optional=DefaultIsUndefined] DOMString eventType)
            raises(DOMException);

        // DOM Level 2 Tranversal and Range (DocumentRange interface)

        Range              createRange();

        // DOM Level 2 Tranversal and Range (DocumentTraversal interface)

        [ObjCLegacyUnnamedParameters] NodeIterator createNodeIterator(in [Optional=DefaultIsUndefined] Node root,
                                                       in [Optional=DefaultIsUndefined] unsigned long whatToShow,
                                                       in [Optional=DefaultIsUndefined] NodeFilter filter,
                                                       in [Optional=DefaultIsUndefined] boolean expandEntityReferences)
            raises(DOMException);
        [ObjCLegacyUnnamedParameters] TreeWalker createTreeWalker(in [Optional=DefaultIsUndefined] Node root,
                                                   in [Optional=DefaultIsUndefined] unsigned long whatToShow,
                                                   in [Optional=DefaultIsUndefined] NodeFilter filter,
                                                   in [Optional=DefaultIsUndefined] boolean expandEntityReferences)
            raises(DOMException);

        // DOM Level 2 Abstract Views (DocumentView interface)

        readonly attribute DOMWindow defaultView;

        // DOM Level 2 Style (DocumentStyle interface)

        readonly attribute StyleSheetList styleSheets;

        // DOM Level 2 Style (DocumentCSS interface)

        [ObjCLegacyUnnamedParameters] CSSStyleDeclaration getOverrideStyle(in [Optional=DefaultIsUndefined] Element element,
                                                            in [Optional=DefaultIsUndefined] DOMString pseudoElement);

        // DOM Level 3 XPath (XPathEvaluator interface)
        [ObjCLegacyUnnamedParameters] XPathExpression createExpression(in [Optional=DefaultIsUndefined] DOMString expression,
                                                        in [Optional=DefaultIsUndefined] XPathNSResolver resolver)
            raises(DOMException);
        XPathNSResolver    createNSResolver(in Node nodeResolver);
        [ObjCLegacyUnnamedParameters, V8Custom] XPathResult evaluate(in [Optional=DefaultIsUndefined] DOMString expression,
                                                      in [Optional=DefaultIsUndefined] Node contextNode,
                                                      in [Optional=DefaultIsUndefined] XPathNSResolver resolver,
                                                      in [Optional=DefaultIsUndefined] unsigned short type,
                                                      in [Optional=DefaultIsUndefined] XPathResult inResult)
            raises(DOMException);

        // Common extensions

        boolean            execCommand(in [Optional=DefaultIsUndefined] DOMString command,
                                       in [Optional=DefaultIsUndefined] boolean userInterface,
                                       in [TreatNullAs=NullString, TreatUndefinedAs=NullString,Optional=DefaultIsUndefined] DOMString value);

#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
        // FIXME: remove the these two versions once [Optional] is implemented for Objective-C.
        boolean            execCommand(in DOMString command,
                                       in boolean userInterface);
        boolean            execCommand(in DOMString command);
#endif

        boolean            queryCommandEnabled(in [Optional=DefaultIsUndefined] DOMString command);
        boolean            queryCommandIndeterm(in [Optional=DefaultIsUndefined] DOMString command);
        boolean            queryCommandState(in [Optional=DefaultIsUndefined] DOMString command);
        boolean            queryCommandSupported(in [Optional=DefaultIsUndefined] DOMString command);
        [TreatReturnedNullStringAs=False] DOMString queryCommandValue(in [Optional=DefaultIsUndefined] DOMString command);

        // Moved down from HTMLDocument

                 attribute [TreatNullAs=NullString] DOMString title;
        readonly attribute DOMString referrer;
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
                 attribute [TreatNullAs=NullString] DOMString domain
                     setter raises (DOMException);
#else
        readonly attribute DOMString domain;
#endif
        readonly attribute DOMString URL;

                 attribute [TreatNullAs=NullString] DOMString cookie
                     setter raises (DOMException),
                     getter raises (DOMException);

        // FIXME: the DOM spec does NOT have this attribute
        // raising an exception.
                 attribute HTMLElement body
                     setter raises (DOMException);

        readonly attribute HTMLHeadElement head;
        readonly attribute HTMLCollection images;
        readonly attribute HTMLCollection applets;
        readonly attribute HTMLCollection links;
        readonly attribute HTMLCollection forms;
        readonly attribute HTMLCollection anchors;
        readonly attribute DOMString lastModified;

        NodeList getElementsByName(in [Optional=DefaultIsUndefined] DOMString elementName);

#if defined(ENABLE_MICRODATA) && ENABLE_MICRODATA
        NodeList getItems(in [TreatNullAs=NullString, TreatUndefinedAs=NullString, Optional=DefaultIsUndefined] DOMString typeNames);
#endif

#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
                 attribute [Custom] Location location;
#endif

        // IE extensions

                 attribute [TreatReturnedNullStringAs=Undefined, TreatNullAs=NullString] DOMString charset;
        readonly attribute [TreatReturnedNullStringAs=Undefined] DOMString defaultCharset;
        readonly attribute [TreatReturnedNullStringAs=Undefined] DOMString readyState;

        Element            elementFromPoint(in [Optional=DefaultIsUndefined] long x, 
                                            in [Optional=DefaultIsUndefined] long y);
        Range              caretRangeFromPoint(in [Optional=DefaultIsUndefined] long x, 
                                               in [Optional=DefaultIsUndefined] long y);

        // Mozilla extensions
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
        DOMSelection       getSelection();
#endif
        readonly attribute [TreatReturnedNullStringAs=Null] DOMString characterSet;

        // WebKit extensions

        readonly attribute [TreatReturnedNullStringAs=Null] DOMString preferredStylesheetSet;
                 attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString selectedStylesheetSet;

#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT
        CSSStyleDeclaration createCSSStyleDeclaration();
#endif

#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
        // DOM Level 2 Style Interface
        [ObjCLegacyUnnamedParameters, ObjCUseDefaultView] CSSStyleDeclaration getComputedStyle(in Element element,
                                                                      in DOMString pseudoElement);

        // WebKit extension
        // FIXME: remove the first version once [Optional] is implemented for Objective-C.
        [ObjCUseDefaultView] CSSRuleList getMatchedCSSRules(in Element element,
                                                  in DOMString pseudoElement);
        [ObjCUseDefaultView] CSSRuleList getMatchedCSSRules(in Element element,
                                                  in DOMString pseudoElement,
                                                  in [Optional] boolean authorOnly);
                                                  
#endif

#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP
#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C
        [V8Custom] DOMObject getCSSCanvasContext(in DOMString contextId, in DOMString name, in long width, in long height);
#endif
#endif

        // HTML 5
        NodeList getElementsByClassName(in [Optional=DefaultIsUndefined] DOMString tagname);

        readonly attribute DOMString compatMode;

        // NodeSelector - Selector API
        Element querySelector(in DOMString selectors)
            raises(DOMException);
        NodeList querySelectorAll(in DOMString selectors)
            raises(DOMException);

#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
        readonly attribute [V8EnabledAtRuntime] boolean webkitIsFullScreen;
        readonly attribute [V8EnabledAtRuntime] boolean webkitFullScreenKeyboardInputAllowed;
        readonly attribute [V8EnabledAtRuntime] Element webkitCurrentFullScreenElement;
        [V8EnabledAtRuntime] void webkitCancelFullScreen();
#endif

        WebKitNamedFlow webkitGetFlowByName(in DOMString name);

#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C
        // Event handler DOM attributes
        attribute [NotEnumerable] EventListener onabort;
        attribute [NotEnumerable] EventListener onblur;
        attribute [NotEnumerable] EventListener onchange;
        attribute [NotEnumerable] EventListener onclick;
        attribute [NotEnumerable] EventListener oncontextmenu;
        attribute [NotEnumerable] EventListener ondblclick;
        attribute [NotEnumerable] EventListener ondrag;
        attribute [NotEnumerable] EventListener ondragend;
        attribute [NotEnumerable] EventListener ondragenter;
        attribute [NotEnumerable] EventListener ondragleave;
        attribute [NotEnumerable] EventListener ondragover;
        attribute [NotEnumerable] EventListener ondragstart;
        attribute [NotEnumerable] EventListener ondrop;
        attribute [NotEnumerable] EventListener onerror;
        attribute [NotEnumerable] EventListener onfocus;
        attribute [NotEnumerable] EventListener oninput;
        attribute [NotEnumerable] EventListener oninvalid;
        attribute [NotEnumerable] EventListener onkeydown;
        attribute [NotEnumerable] EventListener onkeypress;
        attribute [NotEnumerable] EventListener onkeyup;
        attribute [NotEnumerable] EventListener onload;
        attribute [NotEnumerable] EventListener onmousedown;
        attribute [NotEnumerable] EventListener onmousemove;
        attribute [NotEnumerable] EventListener onmouseout;
        attribute [NotEnumerable] EventListener onmouseover;
        attribute [NotEnumerable] EventListener onmouseup;
        attribute [NotEnumerable] EventListener onmousewheel;
        attribute [NotEnumerable] EventListener onreadystatechange;
        attribute [NotEnumerable] EventListener onscroll;
        attribute [NotEnumerable] EventListener onselect;
        attribute [NotEnumerable] EventListener onsubmit;

        // attribute [NotEnumerable] EventListener oncanplay;
        // attribute [NotEnumerable] EventListener oncanplaythrough;
        // attribute [NotEnumerable] EventListener ondurationchange;
        // attribute [NotEnumerable] EventListener onemptied;
        // attribute [NotEnumerable] EventListener onended;
        // attribute [NotEnumerable] EventListener onloadeddata;
        // attribute [NotEnumerable] EventListener onloadedmetadata;
        // attribute [NotEnumerable] EventListener onloadstart;
        // attribute [NotEnumerable] EventListener onpause;
        // attribute [NotEnumerable] EventListener onplay;
        // attribute [NotEnumerable] EventListener onplaying;
        // attribute [NotEnumerable] EventListener onprogress;
        // attribute [NotEnumerable] EventListener onratechange;
        // attribute [NotEnumerable] EventListener onseeked;
        // attribute [NotEnumerable] EventListener onseeking;
        // attribute [NotEnumerable] EventListener onshow;
        // attribute [NotEnumerable] EventListener onstalled;
        // attribute [NotEnumerable] EventListener onsuspend;
        // attribute [NotEnumerable] EventListener ontimeupdate;
        // attribute [NotEnumerable] EventListener onvolumechange;
        // attribute [NotEnumerable] EventListener onwaiting;

        // WebKit extensions
        attribute [NotEnumerable] EventListener onbeforecut;
        attribute [NotEnumerable] EventListener oncut;
        attribute [NotEnumerable] EventListener onbeforecopy;
        attribute [NotEnumerable] EventListener oncopy;
        attribute [NotEnumerable] EventListener onbeforepaste;
        attribute [NotEnumerable] EventListener onpaste;
        attribute [NotEnumerable] EventListener onreset;
        attribute [NotEnumerable] EventListener onsearch;
        attribute [NotEnumerable] EventListener onselectstart;
        attribute [NotEnumerable] EventListener onselectionchange;
        attribute [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] EventListener ontouchstart;
        attribute [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] EventListener ontouchmove;
        attribute [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] EventListener ontouchend;
        attribute [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] EventListener ontouchcancel;
        attribute [NotEnumerable, Conditional=FULLSCREEN_API] EventListener onwebkitfullscreenchange;
        attribute [NotEnumerable, Conditional=FULLSCREEN_API] EventListener onwebkitfullscreenerror;
#endif

#if defined(ENABLE_TOUCH_EVENTS) && ENABLE_TOUCH_EVENTS
        [ReturnNewObject, V8EnabledAtRuntime] Touch createTouch(in [Optional=DefaultIsUndefined] DOMWindow window,
                                                         in [Optional=DefaultIsUndefined] EventTarget target,
                                                         in [Optional=DefaultIsUndefined] long identifier,
                                                         in [Optional=DefaultIsUndefined] long pageX,
                                                         in [Optional=DefaultIsUndefined] long pageY,
                                                         in [Optional=DefaultIsUndefined] long screenX,
                                                         in [Optional=DefaultIsUndefined] long screenY,
                                                         in [Optional=DefaultIsUndefined] long webkitRadiusX,
                                                         in [Optional=DefaultIsUndefined] long webkitRadiusY,
                                                         in [Optional=DefaultIsUndefined] float webkitRotationAngle,
                                                         in [Optional=DefaultIsUndefined] float webkitForce)
            raises (DOMException);
        [ReturnNewObject, V8EnabledAtRuntime, Custom] TouchList createTouchList()
            raises (DOMException);
#endif

#if defined(LANGUAGE_CPP) && LANGUAGE_CPP
        // Extra WebCore methods exposed to allow compile-time casting in C++
        boolean isHTMLDocument();
#endif

        // Page visibility API.
        readonly attribute [Conditional=PAGE_VISIBILITY_API] DOMString webkitVisibilityState;
        readonly attribute [Conditional=PAGE_VISIBILITY_API] boolean webkitHidden;

    };

}
