/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
interface nsIAtom;
interface nsIDOMDocument;
interface nsIDOMElement;
interface nsIDOMNode;
interface nsIDOMAttr;
interface nsIDOMEvent;
interface nsIXTFElementWrapper;

[scriptable, uuid(4f144387-796d-4baf-8641-5db45dba1808)]
interface nsIXTFElement : nsISupports
{
  // onCreated will be called before any notifications are sent to
  // the xtf element.
  //
  // @param wrapper is a weak proxy to the wrapping element
  // (i.e. holding a reference to this will not create a cycle).
  void onCreated(in nsIXTFElementWrapper wrapper);

  // called when the wrapper object is being destroyed.
  void onDestroyed();

  // If isAttributeHandler is set to 'true', the xtf element indicates
  // that it wants to manage its own attributes. In this case it needs
  // to implement the nsIXTFAttributeHandler interface in addition to
  // its other interfaces. 'isAttributeHandler' must remain constant
  // for the entire lifetime of the xtf element (i.e. before any
  // onCreated()-calls until after onDestroyed()-calls).
  readonly attribute boolean isAttributeHandler;
  
  // getScriptingInterfaces: This array serves 2 purposes: a) All
  // interfaces in this array will automatically be accessible when
  // our wrapper element is used from JS (other interfaces need to be
  // explicitly QI'ed for), and b) All these interfaces are callable
  // from unpriviliged script.
  // @note 'Normal' DOM interfaces are always automatically scriptable.
  void getScriptingInterfaces(out unsigned long count,
                              [array, size_is(count), retval] out nsIIDPtr array);

  // Notification mask constants:
  // To receive a given event set the corresponding bit in
  // nsIXTFElementWrapper::notificationMask.
  const unsigned long NOTIFY_WILL_CHANGE_DOCUMENT  = 0x00000001;
  const unsigned long NOTIFY_DOCUMENT_CHANGED      = 0x00000002;
  
  const unsigned long NOTIFY_WILL_CHANGE_PARENT    = 0x00000004;
  const unsigned long NOTIFY_PARENT_CHANGED        = 0x00000008;
  
  const unsigned long NOTIFY_WILL_INSERT_CHILD     = 0x00000010;
  const unsigned long NOTIFY_CHILD_INSERTED        = 0x00000020;
  
  const unsigned long NOTIFY_WILL_APPEND_CHILD     = 0x00000040;
  const unsigned long NOTIFY_CHILD_APPENDED        = 0x00000080;
  
  const unsigned long NOTIFY_WILL_REMOVE_CHILD     = 0x00000100;
  const unsigned long NOTIFY_CHILD_REMOVED         = 0x00000200;
  
  const unsigned long NOTIFY_WILL_SET_ATTRIBUTE    = 0x00000400;
  const unsigned long NOTIFY_ATTRIBUTE_SET         = 0x00000800;
  
  const unsigned long NOTIFY_WILL_REMOVE_ATTRIBUTE = 0x00001000;
  const unsigned long NOTIFY_ATTRIBUTE_REMOVED     = 0x00002000;
  
  const unsigned long NOTIFY_BEGIN_ADDING_CHILDREN = 0x00004000;
  const unsigned long NOTIFY_DONE_ADDING_CHILDREN  = 0x00008000;
  
  const unsigned long NOTIFY_HANDLE_DEFAULT        = 0x00010000;

  const unsigned long NOTIFY_PERFORM_ACCESSKEY     = 0x00020000;

  // Event notifications:

  void willChangeDocument(in nsIDOMDocument newDoc);
  void documentChanged(in nsIDOMDocument newDoc);
  
  void willChangeParent(in nsIDOMElement newParent);
  void parentChanged(in nsIDOMElement newParent);

  void willInsertChild(in nsIDOMNode child, in unsigned long index);
  void childInserted(in nsIDOMNode child, in unsigned long index);

  void willAppendChild(in nsIDOMNode child);
  void childAppended(in nsIDOMNode child);

  void willRemoveChild(in unsigned long index);
  void childRemoved(in unsigned long index);

  void willSetAttribute(in nsIAtom name, in AString newValue);
  void attributeSet(in nsIAtom name, in AString newValue);

  void willRemoveAttribute(in nsIAtom name);
  void attributeRemoved(in nsIAtom name);

  // These are for batching of child insertions during document load

  // beginAddingChildren is called before any attributes or child nodes are
  // added to the element.
  void beginAddingChildren();
  void doneAddingChildren();

  // The default handler for DOM Events.
  // This method is called after the normal DOM event flow.
  // If the return value is true, the event is marked as handled and
  // other default handlers won't be able to handle it again.
  boolean handleDefault(in nsIDOMEvent aEvent);

  // Set this element to be equivalent to |aElement|.  This does not need
  // to worry about copying attributes or child nodes, but should copy any
  // other needed state.
  void cloneState(in nsIDOMElement aElement);

  /**
   * Returns accesskey attribute node.
   */
  readonly attribute nsIDOMAttr accesskeyNode;

  /**
   * Performs accesskey. The method is called when accesskey is activated.
   */
  void performAccesskey();
};

