/*
 * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
 * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
 *
 * 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.
 */

[
	JSCustomHeader,
    JSGenerateToNativeObject,
] interface Element : Node {

    // DOM Level 1 Core

    readonly attribute DOMString? tagName;
    
	DOMString? getAttribute(DOMString name);
	
	void setAttribute(DOMString name, DOMString value)
        raises(DOMException);
        
    void removeAttribute(DOMString name);
    Attr getAttributeNode(DOMString name);
    
    Attr? setAttributeNode(in Attr newAttr)
        raises(DOMException);
    Attr removeAttributeNode(in Attr oldAttr)
        raises(DOMException);
        
    HTMLCollection getElementsByTagName(DOMString name);

#if !defined(LANGUAGE_OBJECTIVE_C)
    // For ObjC this is defined on Node for legacy support.
    readonly attribute NamedNodeMap     attributes;
    boolean            hasAttributes();
#endif

    // DOM Level 2 Core

    [ObjCLegacyUnnamedParameters] DOMString? getAttributeNS(DOMString? namespaceURI, DOMString localName);
    
    // FIXME: Using "undefined" as default parameter value is wrong.
	void setAttributeNS(DOMString? namespaceURI, DOMString qualifiedName, DOMString value)
        raises(DOMException);
   
    [ObjCLegacyUnnamedParameters] void removeAttributeNS(DOMString? namespaceURI, DOMString localName);
    
    [ObjCLegacyUnnamedParameters] HTMLCollection getElementsByTagNameNS(DOMString? namespaceURI, DOMString localName);    
    [ObjCLegacyUnnamedParameters] Attr? getAttributeNodeNS(DOMString? namespaceURI, DOMString localName);
    Attr? setAttributeNodeNS(in Attr newAttr)
        raises(DOMException);
    boolean hasAttribute(in DOMString name);
    [ObjCLegacyUnnamedParameters] boolean hasAttributeNS(DOMString? namespaceURI, DOMString localName);

#if defined(ENABLE_BML) && ENABLE_BML
    readonly attribute CSSStyleDeclaration normalStyle;
    readonly attribute CSSStyleDeclaration focusStyle;
    readonly attribute CSSStyleDeclaration activeStyle;
#endif

    // DOM 4
#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C
    [Reflect] attribute DOMString id;
#endif

    readonly attribute DOMString? namespaceURI;
    readonly attribute DOMString? prefix;
    readonly attribute DOMString localName;

    // Common extensions
    
    readonly attribute long clientTop;
    readonly attribute long clientLeft;
    readonly attribute long clientWidth;
    readonly attribute long clientHeight;
    
    attribute long scrollLeft; // FIXME: should be unrestricted double
    attribute long scrollTop; // FIXME: should be unrestricted double
    readonly attribute long scrollWidth;
    readonly attribute long scrollHeight;

#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C || defined(LANGUAGE_GOBJECT) && LANGUAGE_GOBJECT
    void focus();
    void blur();
#endif

    void scrollIntoView(in optional boolean alignWithTop = true);

    void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);

    [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options);
    [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y);

    void scrollTo(optional ScrollToOptions options);
    void scrollTo(unrestricted double x, unrestricted double y);

    void scrollBy(optional ScrollToOptions option);
    void scrollBy(unrestricted double x, unrestricted double y);

    void scrollByLines(in optional long lines = 0);
    void scrollByPages(in optional long pages = 0);

    sequence<DOMString> getAttributeNames();

    // HTML 5
    
    HTMLCollection getElementsByClassName(DOMString name);
	[TreatNullAs=EmptyString] attribute DOMString innerHTML setter raises(DOMException);
	[TreatNullAs=EmptyString] attribute DOMString outerHTML setter raises(DOMException);
	     
    [Reflect=class] attribute DOMString className;
    [PutForwards=value] readonly attribute DOMTokenList classList;

    // WebKit extension, pending specification.
    // FIXME: Using "undefined" as default parameter value is wrong.
    boolean matches(DOMString selectors)
        raises(DOMException);
    [RaisesException] Element closest(DOMString selectors);   
    boolean webkitMatchesSelector(DOMString selectors)
        raises(DOMException);

    // CSSOM View Module API
    DOMRectList getClientRects();
    [NewObject] DOMRect getBoundingClientRect();

#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
    // Objective-C extensions
    readonly attribute DOMString innerText;
#endif

#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API
    // Mozilla version
    const unsigned short ALLOW_KEYBOARD_INPUT = 1;
    void webkitRequestFullScreen(in optional unsigned short flags = 0);

    // W3C version
    void webkitRequestFullscreen();
#endif

    Element insertAdjacentElement(DOMString where, Element element)
        raises(DOMException);        
    void insertAdjacentHTML(DOMString where, DOMString html)
        raises(DOMException);
    void insertAdjacentText(DOMString where, DOMString text)
        raises(DOMException);
        
    [Conditional=POINTER_LOCK] void requestPointerLock();

    // Shadow DOM API
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
    [Conditional=SHADOW_DOM, RaisesException] ShadowRoot attachShadow(ShadowRootInit init);
    [Conditional=SHADOW_DOM, ImplementedAs=bindingShadowRoot] readonly attribute ShadowRoot shadowRoot;
    [Conditional=SHADOW_DOM, Reflect, Unscopable] attribute DOMString slot;
    [Conditional=SHADOW_DOM, SameObject, PutForwards=value] readonly attribute DOMTokenList part;
#endif
    
    // Event Handlers

    // Non standard.   
    [NotEnumerable] attribute EventHandler onselectstart;
    [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventHandler onwebkitfullscreenchange;
    [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventHandler onwebkitfullscreenerror;
    
    [NotEnumerable, Conditional=IOS_GESTURE_EVENTS] attribute EventHandler ongesturechange;
    [NotEnumerable, Conditional=IOS_GESTURE_EVENTS] attribute EventHandler ongestureend;
    [NotEnumerable, Conditional=IOS_GESTURE_EVENTS] attribute EventHandler ongesturestart;

    // Unique to Element, HTMLBodyElement and HTMLFrameSetElement
    [NotEnumerable] attribute EventHandler onfocusin;
    [NotEnumerable] attribute EventHandler onfocusout;

    // Unique to Element
    [NotEnumerable] attribute EventHandler onbeforeload;    
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onkeyadded;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onkeyerror;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onkeymessage;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onwebkitkeyadded;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onwebkitkeyerror;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA] attribute EventHandler onwebkitkeymessage;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA|LEGACY_ENCRYPTED_MEDIA_V2] attribute EventHandler onneedkey;
    [NotEnumerable, Conditional=LEGACY_ENCRYPTED_MEDIA|LEGACY_ENCRYPTED_MEDIA_V2] attribute EventHandler onwebkitneedkey;
    [NotEnumerable, Conditional=VIDEO_PRESENTATION_MODE] attribute EventHandler onwebkitpresentationmodechanged;
    [NotEnumerable, Conditional=WIRELESS_PLAYBACK_TARGET] attribute EventHandler onwebkitcurrentplaybacktargetiswirelesschanged;
    [NotEnumerable, Conditional=WIRELESS_PLAYBACK_TARGET] attribute EventHandler onwebkitplaybacktargetavailabilitychanged;
};

Element implements Animatable;
Element implements ChildNode;
Element implements ParentNode;
Element implements NonDocumentTypeChildNode;
Element implements DocumentAndElementEventHandlers;
