Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes
nsXFormsRefreshElement Class Reference
Inheritance diagram for nsXFormsRefreshElement:
Inheritance graph
[legend]
Collaboration diagram for nsXFormsRefreshElement:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsXFormsRefreshElement ()
virtual nsresult HandleSingleAction (nsIDOMEvent *aEvent, nsIXFormsActionElement *aParentAction)
 With the while attribute, actions can potentially be iterated.
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIXFORMSACTIONMODULEELEMENT
NS_DECL_NSIXTFGENERICELEMENT
NS_DECL_NSIDOMEVENTLISTENER
NS_IMETHOD 
OnDestroyed ()
NS_IMETHOD WillChangeDocument (nsIDOMDocument *aNewDocument)
NS_IMETHOD DocumentChanged (nsIDOMDocument *aNewDocument)
NS_IMETHOD WillChangeParent (nsIDOMElement *aNewParent)
NS_IMETHOD ParentChanged (nsIDOMElement *aNewParent)
virtual nsIDOMElementGetElement ()
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.
virtual nsRepeatState GetRepeatState ()
 Get/Set the repeat state for the xforms control or action.
virtual void SetRepeatState (nsRepeatState aState)
void onCreated (in nsIXTFGenericElementWrapper wrapper)
void onDestroyed ()
void getScriptingInterfaces (out unsigned long count,[array, size_is(count), retval] out nsIIDPtr array)
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)
void beginAddingChildren ()
void doneAddingChildren ()
boolean handleDefault (in nsIDOMEvent aEvent)
void cloneState (in nsIDOMElement aElement)
void handleAction (in nsIDOMEvent aEvent, in nsIXFormsActionElement aParentAction)
nsIDOMEvent getCurrentEvent ()
 Get the event currently being processed in handleAction.
PRBool CanIterate ()
void SetCurrentEvent (nsIDOMEvent *aEvent)

Static Public Member Functions

static nsresult DoHandleAction (nsXFormsActionModuleHelper *aXFormsAction, nsIDOMEvent *aEvent, nsIXFormsActionElement *aParentAction)
static PRBool CanPerformAction (nsIDOMElement *aElement, PRBool *aUsesWhile, nsIDOMNode *aContextNode=nsnull, PRInt32 aContextSize=0, PRInt32 aContextPosition=0)
 Determine whether this action element should be executed, based upon optional if and while attributes.

Public Attributes

const unsigned long ELEMENT_TYPE_GENERIC_ELEMENT = 0
const unsigned long ELEMENT_TYPE_SVG_VISUAL = 1
const unsigned long ELEMENT_TYPE_XML_VISUAL = 2
const unsigned long ELEMENT_TYPE_XUL_VISUAL = 3
const unsigned long ELEMENT_TYPE_BINDABLE = 4
readonly attribute unsigned long elementType
readonly attribute boolean isAttributeHandler
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

Protected Member Functions

virtual nsRepeatState UpdateRepeatState (nsIDOMNode *aParent)
 This is processed when an XForms control or XForms action has been inserted under a parent node AND has been inserted into a document.

Protected Attributes

nsIDOMElementmElement
nsRepeatState mRepeatState
PRPackedBool mHasParent
 State that tells whether control has a parent or not.
PRPackedBool mHasDoc
 State that tells whether control has a document or not.
PRBool mCanIterate
 This signals whether or not this action can iterate.
nsCOMPtr< nsIDOMEventmCurrentEvent
 The event currently being processed.

Detailed Description

Definition at line 42 of file nsXFormsRefreshElement.cpp.


Constructor & Destructor Documentation

Definition at line 50 of file nsXFormsRefreshElement.cpp.

{
}

Member Function Documentation

void nsIXTFElement::attributeSet ( in nsIAtom  name,
in AString  newValue 
) [inherited]

Definition at line 65 of file nsXFormsActionModuleBase.h.

{ return mCanIterate; }

Here is the caller graph for this function:

PRBool nsXFormsActionModuleBase::CanPerformAction ( nsIDOMElement aElement,
PRBool aUsesWhile,
nsIDOMNode aContextNode = nsnull,
PRInt32  aContextSize = 0,
PRInt32  aContextPosition = 0 
) [static, inherited]

Determine whether this action element should be executed, based upon optional if and while attributes.

For each of these attributes that are present on an action element, the action is only performed if the boolean value of the XPath expression contained in the attribute is true. In addition, if the while attribute is used, the action is "executed repeatedly" until one of these attributes evaluates to false. This method indicates to the caller whether the action element uses a while attribute through the usesWhile parameter.

Definition at line 206 of file nsXFormsActionModuleBase.cpp.

{
  *aUsesWhile = PR_FALSE;

  nsAutoString ifExpr;
  nsAutoString whileExpr;
  aElement->GetAttribute(NS_LITERAL_STRING("if"), ifExpr);
  aElement->GetAttribute(NS_LITERAL_STRING("while"), whileExpr);

  if (whileExpr.IsEmpty() && ifExpr.IsEmpty()) {
    return PR_TRUE;
  }

  nsresult rv;
  nsCOMPtr<nsIDOMXPathResult> res;
  PRBool condTrue;

  nsCOMPtr<nsIDOMNode> contextNode;

  if (aContext) {
    contextNode = aContext;
  } else {
    // Determine evaluation context.
    nsCOMPtr<nsIModelElementPrivate> model;
    nsCOMPtr<nsIDOMElement> bindElement;
    nsCOMPtr<nsIXFormsControl> parentControl;
    PRBool outerBind;
    rv = nsXFormsUtils::GetNodeContext(aElement, 0,
                                       getter_AddRefs(model),
                                       getter_AddRefs(bindElement),
                                       &outerBind,
                                       getter_AddRefs(parentControl),
                                       getter_AddRefs(contextNode),
                                       &aContextPosition, &aContextSize, PR_FALSE);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);
  }

  if (!whileExpr.IsEmpty()) {
    *aUsesWhile = PR_TRUE;

    rv = nsXFormsUtils::EvaluateXPath(whileExpr, contextNode, aElement,
                                      nsIDOMXPathResult::BOOLEAN_TYPE,
                                      getter_AddRefs(res),
                                      aContextPosition, aContextSize);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);
    
    rv = res->GetBooleanValue(&condTrue);
    if (NS_FAILED(rv) || !condTrue) {
      return PR_FALSE;
    }
  }

  if (!ifExpr.IsEmpty()) {
    rv = nsXFormsUtils::EvaluateXPath(ifExpr, contextNode, aElement,
                                      nsIDOMXPathResult::BOOLEAN_TYPE,
                                      getter_AddRefs(res),
                                      aContextPosition, aContextSize);
    NS_ENSURE_SUCCESS(rv, PR_FALSE);
    
    rv = res->GetBooleanValue(&condTrue);
    if (NS_FAILED(rv) || !condTrue) {
      return PR_FALSE;
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIXTFElement::childInserted ( in nsIDOMNode  child,
in unsigned long  index 
) [inherited]
void nsIXTFElement::childRemoved ( in unsigned long  index) [inherited]
void nsIXTFElement::cloneState ( in nsIDOMElement  aElement) [inherited]

Definition at line 122 of file nsXFormsActionModuleBase.cpp.

Here is the call graph for this function:

nsresult nsXFormsActionModuleBase::DoHandleAction ( nsXFormsActionModuleHelper aXFormsAction,
nsIDOMEvent aEvent,
nsIXFormsActionElement aParentAction 
) [static, inherited]

Definition at line 151 of file nsXFormsActionModuleBase.cpp.

{
  nsCOMPtr<nsIDOMElement> element = aXFormsAction->GetElement();
  if (!element) {
    return NS_OK;
  }
  aXFormsAction->SetCurrentEvent(aEvent);

  // Set the maximum run time for the loop (in microseconds).
  PRTime microseconds = nsXFormsUtils::waitLimit * PR_USEC_PER_SEC;

  PRTime runTime = 0, start = PR_Now();

  while (PR_TRUE) {
    // Test the `if` and `while` attributes to determine whether this action
    // can be performed and should be repeated.
    PRBool usesWhile;
    if (!nsXFormsActionModuleBase::CanPerformAction(element, &usesWhile)) {
      return NS_OK;
    }

    nsresult rv = aXFormsAction->HandleSingleAction(aEvent, aParentAction);
    NS_ENSURE_SUCCESS(rv, rv);

    // Repeat this action if it can iterate and if it uses the `while`
    // attribute (the expression of which must have evaluated to true to
    // arrive here).
    if (!aXFormsAction->CanIterate() || !usesWhile) {
      return NS_OK;
    }

    // See if we've exceeded our time limit, and if so, prompt the user to
    // determine if she wants to cancel the loop.
    LL_SUB(runTime, PR_Now(), start);
    if (microseconds <= 0 || runTime < microseconds) {
      continue;
    }

    // The remaining part of the loop prompts the user about cancelling the
    // loop, and is only executed if we've gone over the time limit.
    PRBool stopWaiting = nsXFormsUtils::AskStopWaiting(element);

    if (stopWaiting) {
      // Stop the loop
      return NS_OK;
    } else {
      start = PR_Now();
    }
  }
}

Here is the call graph for this function:

Get the event currently being processed in handleAction.

The XPath event() method uses this method to get the context info for the current event.

virtual nsIDOMElement* nsXFormsActionModuleBase::GetElement ( ) [inline, virtual, inherited]

Implements nsXFormsActionModuleHelper.

Definition at line 111 of file nsXFormsActionModuleBase.h.

{ return mElement; }

Get/Set the repeat state for the xforms control or action.

The repeat state indicates whether the control or action lives inside a context container, a repeat element, an itemset or none of the above.

Definition at line 205 of file nsXFormsStubElement.cpp.

{
  return mRepeatState;
}
void nsIXTFElement::getScriptingInterfaces ( out unsigned long  count,
[array, size_is(count), retval] out nsIIDPtr  array 
) [inherited]

This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Parameters:
evtThe Event contains contextual information about the event. It also contains the stopPropagation and preventDefault methods which are used in determining the event's flow and default action.

With the while attribute, actions can potentially be iterated.

The HandleSingleAction method processes one iteration of an action (that is, the "body" of the action); it should be dispatched by the HandleAction method, which manages the conditional execution and iteration of the action.

Implements nsXFormsActionModuleHelper.

Definition at line 55 of file nsXFormsRefreshElement.cpp.

{
  nsCOMPtr<nsIModelElementPrivate> model = nsXFormsUtils::GetModel(mElement);
  NS_ENSURE_STATE(model);

  if (aParentAction) {
    aParentAction->SetRefresh(model, PR_FALSE);
  }
  return model->Refresh();
}

Definition at line 93 of file nsXFormsActionModuleBase.cpp.

{
  mElement = nsnull;
  return NS_OK;
}

Definition at line 107 of file nsXFormsActionModuleBase.cpp.

{
  nsXFormsStubElement::ParentChanged(aNewParent);
  UpdateRepeatState(aNewParent);
  return NS_OK;
}

Here is the call graph for this function:

void nsIXTFElement::parentChanged ( in nsIDOMElement  newParent) [inherited]

Definition at line 66 of file nsXFormsActionModuleBase.h.

{ mCurrentEvent = aEvent; }

Here is the caller graph for this function:

void nsXFormsStubElement::SetRepeatState ( nsRepeatState  aState) [virtual, inherited]

Definition at line 211 of file nsXFormsStubElement.cpp.

{
  mRepeatState = aState;
  return;
}

Here is the caller graph for this function:

nsRepeatState nsXFormsStubElement::UpdateRepeatState ( nsIDOMNode aParent) [protected, virtual, inherited]

This is processed when an XForms control or XForms action has been inserted under a parent node AND has been inserted into a document.

It checks the ancestors of the element and returns an nsRepeatState depending on the element's place in the document.

Parameters:
aParentThe new parent of the XForms control

Definition at line 218 of file nsXFormsStubElement.cpp.

{
  // Walk up the parent chain looking to see if the this control is contained
  // in an item.  If it is and that item is contained in a itemset, then we
  // know that this control was generated as a clone from the itemset's
  // template.  Similarly, we'll check to see if this control lives in a
  // contextcontainer (meaning it was cloned from a repeat's template).
  // Otherwise, if neither of these are the case but it lives under a repeat
  // or an itemset, then this control must be part of a template.  A template
  // is the content of a repeat or itemset that gets cloned once for every
  // node in the bound nodeset.
  //
  // If none of this applies, we'll return eType_NotApplicable to show that this
  // control isn't bound to a repeating nodeset.
  nsRepeatState repeatState = eType_NotApplicable;

  if (!mHasDoc || !mHasParent) {
    // If we don't have a document or a parent, none of these tests will work
    // correctly so no sense doing them now.  If either of these are false the
    // repeat state for the object should already be eType_Unknown so just
    // return that now.
    return eType_Unknown;
  }

  nsCOMPtr<nsIDOMNode> parent = aParent;
  PRBool childIsItem = PR_FALSE;
  while (parent) {
    if (nsXFormsUtils::IsXFormsElement(parent,
                                       NS_LITERAL_STRING("contextcontainer"))) {
      repeatState = eType_GeneratedContent;
      break;
    }
    if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("repeat"))) {
      repeatState = eType_Template;
      break;
    }
    if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("itemset"))) {
      if (childIsItem) {
        repeatState = eType_GeneratedContent;
        break;
      }
      repeatState = eType_Template;
      break;
    }

    if (nsXFormsUtils::IsXFormsElement(parent, NS_LITERAL_STRING("item"))) {
      childIsItem = PR_TRUE;
    } else {

      nsCOMPtr<nsIDOMElement> parentEle(do_QueryInterface(parent));
      if (!parentEle) {
        // I don't know how this can possibly happen, but if it does I guess
        // we should just ignore it and coninue on our way.
        break;
      }

      // if this control is contained underneath an element that contains
      // an xforms binding attribute that introduces an anonymous xf:repeat
      // then the control is part of a template
      PRBool repeatAttr = PR_FALSE;
      parentEle->HasAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
                                NS_LITERAL_STRING("repeat-bind"),
                                &repeatAttr);
      if (repeatAttr) {
        repeatState = eType_Template;
        break;
      }

      parentEle->HasAttributeNS(NS_LITERAL_STRING(NS_NAMESPACE_XFORMS),
                                NS_LITERAL_STRING("repeat-nodeset"),
                                &repeatAttr);
      if (repeatAttr) {
        repeatState = eType_Template;
        break;
      }
    }
    nsCOMPtr<nsIDOMNode> tmp;
    parent->GetParentNode(getter_AddRefs(tmp));
    parent = tmp;
  }

  SetRepeatState(repeatState);
  return repeatState;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 115 of file nsXFormsActionModuleBase.cpp.

Here is the call graph for this function:

Definition at line 100 of file nsXFormsActionModuleBase.cpp.

Here is the call graph for this function:

void nsIXTFElement::willInsertChild ( in nsIDOMNode  child,
in unsigned long  index 
) [inherited]
void nsIXTFElement::willRemoveChild ( in unsigned long  index) [inherited]
void nsIXTFElement::willSetAttribute ( in nsIAtom  name,
in AString  newValue 
) [inherited]

Member Data Documentation

Definition at line 72 of file nsIXTFElement.idl.

Definition at line 56 of file nsIXTFElement.idl.

Definition at line 60 of file nsIXTFElement.idl.

Definition at line 64 of file nsIXTFElement.idl.

Definition at line 68 of file nsIXTFElement.idl.

readonly attribute unsigned long nsIXTFElement::elementType [inherited]

Definition at line 78 of file nsIXTFElement.idl.

Definition at line 86 of file nsIXTFElement.idl.

This signals whether or not this action can iterate.

Technically, all XForms 1.1 actions are allowed to iterate, but for some of them it may not make sense. Currently, this is set to PR_TRUE for all actions, but we can optionally disable iteration for specific actions based upon additional information in the future.

Definition at line 85 of file nsXFormsActionModuleBase.h.

The event currently being processed.

Definition at line 90 of file nsXFormsActionModuleBase.h.

Definition at line 132 of file nsXFormsActionModuleBase.h.

State that tells whether control has a document or not.

This could be false even if the control has a document. Just means that the element doesn't need to track whether it has a document or not (i.e. xf:choices)

Definition at line 109 of file nsXFormsStubElement.h.

State that tells whether control has a parent or not.

This could be false even if the control has a parent. Just means that the element doesn't need to track whether it has a parent or not (i.e. xf:choices)

Definition at line 102 of file nsXFormsStubElement.h.

Definition at line 95 of file nsXFormsStubElement.h.

const unsigned long nsIXTFElement::NOTIFY_ATTRIBUTE_REMOVED = 0x00002000 [inherited]

Definition at line 118 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_ATTRIBUTE_SET = 0x00000800 [inherited]

Definition at line 115 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_BEGIN_ADDING_CHILDREN = 0x00004000 [inherited]

Definition at line 120 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_CHILD_APPENDED = 0x00000080 [inherited]

Definition at line 109 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_CHILD_INSERTED = 0x00000020 [inherited]

Definition at line 106 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_CHILD_REMOVED = 0x00000200 [inherited]

Definition at line 112 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_DOCUMENT_CHANGED = 0x00000002 [inherited]

Definition at line 100 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_DONE_ADDING_CHILDREN = 0x00008000 [inherited]

Definition at line 121 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_HANDLE_DEFAULT = 0x00010000 [inherited]

Definition at line 123 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_PARENT_CHANGED = 0x00000008 [inherited]

Definition at line 103 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_APPEND_CHILD = 0x00000040 [inherited]

Definition at line 108 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_CHANGE_DOCUMENT = 0x00000001 [inherited]

Definition at line 99 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_CHANGE_PARENT = 0x00000004 [inherited]

Definition at line 102 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_INSERT_CHILD = 0x00000010 [inherited]

Definition at line 105 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_REMOVE_ATTRIBUTE = 0x00001000 [inherited]

Definition at line 117 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_REMOVE_CHILD = 0x00000100 [inherited]

Definition at line 111 of file nsIXTFElement.idl.

const unsigned long nsIXTFElement::NOTIFY_WILL_SET_ATTRIBUTE = 0x00000400 [inherited]

Definition at line 114 of file nsIXTFElement.idl.


The documentation for this class was generated from the following file: