Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
nsXBLPrototypeHandler Class Reference

#include <nsXBLPrototypeHandler.h>

Collaboration diagram for nsXBLPrototypeHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsXBLPrototypeHandler (const PRUnichar *aEvent, const PRUnichar *aPhase, const PRUnichar *aAction, const PRUnichar *aCommand, const PRUnichar *aKeyCode, const PRUnichar *aCharCode, const PRUnichar *aModifiers, const PRUnichar *aButton, const PRUnichar *aClickCount, const PRUnichar *aGroup, const PRUnichar *aPreventDefault, const PRUnichar *aAllowUntrusted, nsXBLPrototypeBinding *aBinding)
 nsXBLPrototypeHandler (nsIContent *aKeyElement)
 ~nsXBLPrototypeHandler ()
PRBool KeyEventMatched (nsIDOMKeyEvent *aKeyEvent)
PRBool KeyEventMatched (nsIAtom *aEventType, nsIDOMKeyEvent *aEvent)
PRBool MouseEventMatched (nsIDOMMouseEvent *aMouseEvent)
PRBool MouseEventMatched (nsIAtom *aEventType, nsIDOMMouseEvent *aEvent)
already_AddRefed< nsIContentGetHandlerElement ()
void AppendHandlerText (const nsAString &aText)
void SetLineNumber (PRUint32 aLineNumber)
PRUint8 GetPhase ()
PRUint8 GetType ()
nsXBLPrototypeHandlerGetNextHandler ()
void SetNextHandler (nsXBLPrototypeHandler *aHandler)
nsresult ExecuteHandler (nsIDOMEventReceiver *aReceiver, nsIDOMEvent *aEvent)
already_AddRefed< nsIAtomGetEventName ()
void SetEventName (nsIAtom *aName)
nsXBLEventHandlerGetEventHandler ()
nsXBLEventHandlerGetCachedEventHandler ()
PRBool AllowUntrustedEvents ()

Static Public Attributes

static PRUint32 gRefCnt = 0

Protected Member Functions

already_AddRefed< nsIControllerGetController (nsIDOMEventReceiver *aReceiver)
PRInt32 GetMatchingKeyCode (const nsAString &aKeyName)
void ConstructPrototype (nsIContent *aKeyElement, const PRUnichar *aEvent=nsnull, const PRUnichar *aPhase=nsnull, const PRUnichar *aAction=nsnull, const PRUnichar *aCommand=nsnull, const PRUnichar *aKeyCode=nsnull, const PRUnichar *aCharCode=nsnull, const PRUnichar *aModifiers=nsnull, const PRUnichar *aButton=nsnull, const PRUnichar *aClickCount=nsnull, const PRUnichar *aGroup=nsnull, const PRUnichar *aPreventDefault=nsnull, const PRUnichar *aAllowUntrusted=nsnull)
void GetEventType (nsAString &type)
PRBool ModifiersMatchMask (nsIDOMUIEvent *aEvent)

Static Protected Member Functions

static PRInt32 KeyToMask (PRInt32 key)
static void InitAccessKeys ()

Protected Attributes

union {
nsIBoxObjectmBoxObjectForHandlerElement
PRUnicharmHandlerText
}; 
PRUint32 mLineNumber
PRUint8 mPhase
PRUint8 mKeyMask
PRUint8 mType
PRUint8 mMisc
PRInt32 mDetail
nsXBLPrototypeHandlermNextHandler
nsCOMPtr< nsIAtommEventName
nsRefPtr< nsXBLEventHandlermHandler
nsXBLPrototypeBindingmPrototypeBinding

Static Protected Attributes

static PRInt32 kAccelKey = -1
static PRInt32 kMenuAccessKey = -1
static const PRInt32 cShift = (1<<0)
static const PRInt32 cAlt = (1<<1)
static const PRInt32 cControl = (1<<2)
static const PRInt32 cMeta = (1<<3)
static const PRInt32 cShiftMask = (1<<4)
static const PRInt32 cAltMask = (1<<5)
static const PRInt32 cControlMask = (1<<6)
static const PRInt32 cMetaMask = (1<<7)
static const PRInt32 cAllModifiers = cShiftMask | cAltMask | cControlMask | cMetaMask

Detailed Description

Definition at line 72 of file nsXBLPrototypeHandler.h.


Constructor & Destructor Documentation

nsXBLPrototypeHandler::nsXBLPrototypeHandler ( const PRUnichar aEvent,
const PRUnichar aPhase,
const PRUnichar aAction,
const PRUnichar aCommand,
const PRUnichar aKeyCode,
const PRUnichar aCharCode,
const PRUnichar aModifiers,
const PRUnichar aButton,
const PRUnichar aClickCount,
const PRUnichar aGroup,
const PRUnichar aPreventDefault,
const PRUnichar aAllowUntrusted,
nsXBLPrototypeBinding aBinding 
)

Definition at line 108 of file nsXBLPrototypeHandler.cpp.

  : mHandlerText(nsnull),
    mLineNumber(0),
    mNextHandler(nsnull),
    mPrototypeBinding(aBinding)
{
  ++gRefCnt;
  if (gRefCnt == 1)
    // Get the primary accelerator key.
    InitAccessKeys();

  ConstructPrototype(nsnull, aEvent, aPhase, aAction, aCommand, aKeyCode,
                     aCharCode, aModifiers, aButton, aClickCount,
                     aGroup, aPreventDefault, aAllowUntrusted);
}

Here is the call graph for this function:

Definition at line 136 of file nsXBLPrototypeHandler.cpp.

  : mBoxObjectForHandlerElement(nsnull),
    mLineNumber(0),
    mNextHandler(nsnull),
    mPrototypeBinding(nsnull)
{
  ++gRefCnt;
  if (gRefCnt == 1)
    // Get the primary accelerator key.
    InitAccessKeys();

  // Make sure our prototype is initialized.
  ConstructPrototype(aHandlerElement);
}

Here is the call graph for this function:

Definition at line 151 of file nsXBLPrototypeHandler.cpp.

{
  --gRefCnt;
  if (mType & NS_HANDLER_TYPE_XUL) {
    NS_IF_RELEASE(mBoxObjectForHandlerElement);
  } else if (mHandlerText) {
    nsMemory::Free(mHandlerText);
  }

  // We own the next handler in the chain, so delete it now.
  delete mNextHandler;
}

Member Function Documentation

Definition at line 144 of file nsXBLPrototypeHandler.h.

  {
    return (mType & NS_HANDLER_ALLOW_UNTRUSTED) != 0;
  }

Here is the caller graph for this function:

Definition at line 179 of file nsXBLPrototypeHandler.cpp.

{
  if (mHandlerText) {
    // Append our text to the existing text.
    PRUnichar* temp = mHandlerText;
    mHandlerText = ToNewUnicode(nsDependentString(temp) + aText);
    nsMemory::Free(temp);
  }
  else
    mHandlerText = ToNewUnicode(aText);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXBLPrototypeHandler::ConstructPrototype ( nsIContent aKeyElement,
const PRUnichar aEvent = nsnull,
const PRUnichar aPhase = nsnull,
const PRUnichar aAction = nsnull,
const PRUnichar aCommand = nsnull,
const PRUnichar aKeyCode = nsnull,
const PRUnichar aCharCode = nsnull,
const PRUnichar aModifiers = nsnull,
const PRUnichar aButton = nsnull,
const PRUnichar aClickCount = nsnull,
const PRUnichar aGroup = nsnull,
const PRUnichar aPreventDefault = nsnull,
const PRUnichar aAllowUntrusted = nsnull 
) [protected]

Definition at line 788 of file nsXBLPrototypeHandler.cpp.

{
  mType = 0;

  if (aKeyElement) {
    mType |= NS_HANDLER_TYPE_XUL;

    nsCOMPtr<nsIDOMNSDocument> nsDomDoc =
      do_QueryInterface(aKeyElement->GetOwnerDoc());
    if (nsDomDoc) {
      nsCOMPtr<nsIDOMElement> el = do_QueryInterface(aKeyElement);
      nsCOMPtr<nsIBoxObject> box;
      nsDomDoc->GetBoxObjectFor(el, getter_AddRefs(box));
      box.swap(mBoxObjectForHandlerElement);
      NS_WARN_IF_FALSE(mBoxObjectForHandlerElement,
                       "Couldn't get a box object for the key element!");
    }
  }
  else {
    mType |= aCommand ? NS_HANDLER_TYPE_XBL_COMMAND : NS_HANDLER_TYPE_XBL_JS;
    mHandlerText = nsnull;

    if (mPrototypeBinding && !mPrototypeBinding->IsChrome()) {
      mType |= NS_HANDLER_ALLOW_UNTRUSTED;
    }
  }

  mDetail = -1;
  mMisc = 0;
  mKeyMask = 0;
  mPhase = NS_PHASE_BUBBLING;

  if (aAction)
    mHandlerText = ToNewUnicode(nsDependentString(aAction));
  else if (aCommand)
    mHandlerText = ToNewUnicode(nsDependentString(aCommand));

  nsAutoString event(aEvent);
  if (event.IsEmpty()) {
    if (mType & NS_HANDLER_TYPE_XUL)
      GetEventType(event);
    if (event.IsEmpty())
      return;
  }

  mEventName = do_GetAtom(event);

  if (aPhase) {
    const nsDependentString phase(aPhase);
    if (phase.EqualsLiteral("capturing"))
      mPhase = NS_PHASE_CAPTURING;
    else if (phase.EqualsLiteral("target"))
      mPhase = NS_PHASE_TARGET;
  }

  // Button and clickcount apply only to XBL handlers and don't apply to XUL key
  // handlers.  
  if (aButton && *aButton)
    mDetail = *aButton - '0';

  if (aClickCount && *aClickCount)
    mMisc = *aClickCount - '0';

  // Modifiers are supported by both types of handlers (XUL and XBL).  
  nsAutoString modifiers(aModifiers);
  if (mType & NS_HANDLER_TYPE_XUL)
    aKeyElement->GetAttr(kNameSpaceID_None, nsXBLAtoms::modifiers, modifiers);
  
  if (!modifiers.IsEmpty()) {
    mKeyMask = cAllModifiers;
    char* str = ToNewCString(modifiers);
    char* newStr;
    char* token = nsCRT::strtok( str, ", ", &newStr );
    while( token != NULL ) {
      if (PL_strcmp(token, "shift") == 0)
        mKeyMask |= cShift | cShiftMask;
      else if (PL_strcmp(token, "alt") == 0)
        mKeyMask |= cAlt | cAltMask;
      else if (PL_strcmp(token, "meta") == 0)
        mKeyMask |= cMeta | cMetaMask;
      else if (PL_strcmp(token, "control") == 0)
        mKeyMask |= cControl | cControlMask;
      else if (PL_strcmp(token, "accel") == 0)
        mKeyMask |= KeyToMask(kAccelKey);
      else if (PL_strcmp(token, "access") == 0)
        mKeyMask |= KeyToMask(kMenuAccessKey);
      else if (PL_strcmp(token, "any") == 0)
        mKeyMask &= ~(mKeyMask << 4);
    
      token = nsCRT::strtok( newStr, ", ", &newStr );
    }

    nsMemory::Free(str);
  }

  nsAutoString key(aCharCode);
  if (key.IsEmpty()) {
    if (mType & NS_HANDLER_TYPE_XUL) {
      aKeyElement->GetAttr(kNameSpaceID_None, nsXBLAtoms::key, key);
      if (key.IsEmpty()) 
        aKeyElement->GetAttr(kNameSpaceID_None, nsXBLAtoms::charcode, key);
    }
  }

  if (!key.IsEmpty()) {
    if (mKeyMask == 0)
      mKeyMask = cAllModifiers;
    if (!(mKeyMask & cShift))
      mKeyMask &= ~cShiftMask;
    if ((mKeyMask & cShift) != 0)
      ToUpperCase(key);
    else
      ToLowerCase(key);

    // We have a charcode.
    mMisc = 1;
    mDetail = key[0];
  }
  else {
    key.Assign(aKeyCode);
    if (mType & NS_HANDLER_TYPE_XUL)
      aKeyElement->GetAttr(kNameSpaceID_None, nsXBLAtoms::keycode, key);
    
    if (!key.IsEmpty()) {
      if (mKeyMask == 0)
        mKeyMask = cAllModifiers;
      mDetail = GetMatchingKeyCode(key);
    }
  }

  if (aGroup && nsDependentString(aGroup).EqualsLiteral("system"))
    mType |= NS_HANDLER_TYPE_SYSTEM;

  nsAutoString preventDefault(aPreventDefault);
  if (preventDefault.EqualsLiteral("true"))
    mType |= NS_HANDLER_TYPE_PREVENTDEFAULT;

  if (aAllowUntrusted) {
    if (nsDependentString(aAllowUntrusted).EqualsLiteral("true")) {
      mType |= NS_HANDLER_ALLOW_UNTRUSTED;
    } else {
      mType &= ~NS_HANDLER_ALLOW_UNTRUSTED;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 217 of file nsXBLPrototypeHandler.cpp.

{
  nsresult rv = NS_ERROR_FAILURE;

  // Prevent default action?
  if (mType & NS_HANDLER_TYPE_PREVENTDEFAULT) {
    aEvent->PreventDefault();
    // If we prevent default, then it's okay for
    // mBoxObjectForHandlerElement and mHandlerText to be null
    rv = NS_OK;
  }

  if (!mBoxObjectForHandlerElement) // This works for both types of handlers.  In both cases, the union's var should be defined.
    return rv;

  // See if our event receiver is a content node (and not us).
  PRBool isXULKey = (mType & NS_HANDLER_TYPE_XUL);
  PRBool isXBLCommand = (mType & NS_HANDLER_TYPE_XBL_COMMAND);
  NS_ASSERTION(!(isXULKey && isXBLCommand),
               "can't be both a key and xbl command handler");

  // XUL handlers and commands shouldn't be triggered by non-trusted
  // events.
  if (isXULKey || isXBLCommand) {
    nsCOMPtr<nsIDOMNSEvent> domNSEvent = do_QueryInterface(aEvent);
    PRBool trustedEvent = PR_FALSE;
    if (domNSEvent) {
      domNSEvent->GetIsTrusted(&trustedEvent);
    }

    if (!trustedEvent)
      return NS_OK;
  }
    
  if (isXBLCommand) {
    // This is a special-case optimization to make command handling fast.
    // It isn't really a part of XBL, but it helps speed things up.

    // See if preventDefault has been set.  If so, don't execute.
    PRBool preventDefault = PR_FALSE;
    nsCOMPtr<nsIDOMNSUIEvent> nsUIEvent(do_QueryInterface(aEvent));
    if (nsUIEvent)
      nsUIEvent->GetPreventDefault(&preventDefault);

    if (preventDefault)
      return NS_OK;

    nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(aEvent);
    if (privateEvent) {
      PRBool dispatchStopped;
      privateEvent->IsDispatchStopped(&dispatchStopped);
      if (dispatchStopped)
        return NS_OK;
    }

    // Instead of executing JS, let's get the controller for the bound
    // element and call doCommand on it.
    nsCOMPtr<nsIController> controller;
    nsCOMPtr<nsIFocusController> focusController;

    nsCOMPtr<nsPIWindowRoot> windowRoot(do_QueryInterface(aReceiver));
    if (windowRoot) {
      windowRoot->GetFocusController(getter_AddRefs(focusController));
    }
    else {
      nsCOMPtr<nsPIDOMWindow> privateWindow(do_QueryInterface(aReceiver));
      if (!privateWindow) {
        nsCOMPtr<nsIContent> elt(do_QueryInterface(aReceiver));
        nsCOMPtr<nsIDocument> doc;
        if (elt)
          doc = elt->GetOwnerDoc();

        if (!doc)
          doc = do_QueryInterface(aReceiver);

        if (!doc)
          return NS_ERROR_FAILURE;

        privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
        if (!privateWindow)
          return NS_ERROR_FAILURE;
      }

      focusController = privateWindow->GetRootFocusController();
    }

    NS_LossyConvertUCS2toASCII command(mHandlerText);
    if (focusController)
      focusController->GetControllerForCommand(command.get(), getter_AddRefs(controller));
    else
      controller = GetController(aReceiver); // We're attached to the receiver possibly.

    nsAutoString type;
    mEventName->ToString(type);

    if (type.EqualsLiteral("keypress") &&
        mDetail == nsIDOMKeyEvent::DOM_VK_SPACE &&
        mMisc == 1) {
      // get the focused element so that we can pageDown only at
      // certain times.
      nsCOMPtr<nsIDOMElement> focusedElement;
      focusController->GetFocusedElement(getter_AddRefs(focusedElement));
      PRBool isLink = PR_FALSE;
      nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
      nsIContent *content = focusedContent;

      // if the focused element is a link then we do want space to 
      // scroll down. focused element may be an element in a link,
      // we need to check the parent node too.
      if (focusedContent) {
        while (content) {
          if (content->Tag() == nsHTMLAtoms::a &&
              content->IsContentOfType(nsIContent::eHTML)) {
            isLink = PR_TRUE;
            break;
          }

          if (content->HasAttr(kNameSpaceID_XLink, nsHTMLAtoms::type)) {
            nsAutoString type;
            content->GetAttr(kNameSpaceID_XLink, nsHTMLAtoms::type, type);

            isLink = type.EqualsLiteral("simple");

            if (isLink) {
              break;
            }
          }

          content = content->GetParent();
        }

        if (!isLink)
          return NS_OK;
      }
    }

    // We are the default action for this command.
    // Stop any other default action from executing.
    aEvent->PreventDefault();
    
    if (controller)
      controller->DoCommand(command.get());

    return NS_OK;
  }

  // If we're executing on a XUL key element, just dispatch a command
  // event at the element.  It will take care of retargeting it to its
  // command element, if applicable, and executing the event handler.
  if (isXULKey) {
    aEvent->PreventDefault();

    nsEventStatus status = nsEventStatus_eIgnore;
    nsXULCommandEvent event(PR_TRUE, NS_XUL_COMMAND, nsnull);

    // Copy the modifiers from the key event.
    nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aEvent);
    if (!keyEvent) {
      NS_ERROR("Trying to execute a key handler for a non-key event!");
      return NS_ERROR_FAILURE;
    }

    keyEvent->GetAltKey(&event.isAlt);
    keyEvent->GetCtrlKey(&event.isControl);
    keyEvent->GetShiftKey(&event.isShift);
    keyEvent->GetMetaKey(&event.isMeta);
    
    nsCOMPtr<nsIContent> handlerElement = GetHandlerElement();
    NS_ENSURE_STATE(handlerElement);
    nsPresContext *pc = nsnull;
    nsIDocument *doc = handlerElement->GetCurrentDoc();
    if (doc) {
      nsIPresShell *shell = doc->GetShellAt(0);
      if (shell) {
        pc = shell->GetPresContext();
      }
    }

    handlerElement->HandleDOMEvent(pc, &event, nsnull,
                                   NS_EVENT_FLAG_INIT, &status);
    return NS_OK;
  }

  // Look for a compiled handler on the element. 
  // Should be compiled and bound with "on" in front of the name.
  nsAutoString onEvent(NS_LITERAL_STRING("onxbl"));
  nsAutoString str;
  mEventName->ToString(str);
  onEvent += str;
  nsCOMPtr<nsIAtom> onEventAtom = do_GetAtom(onEvent);

  void* handler = nsnull;
  
  // Compile the handler and bind it to the element.
  nsCOMPtr<nsIScriptGlobalObject> boundGlobal;
  nsCOMPtr<nsPIWindowRoot> winRoot(do_QueryInterface(aReceiver));
  nsCOMPtr<nsIDOMWindowInternal> focusedWin;

  if (winRoot) {
    nsCOMPtr<nsIFocusController> focusController;
    winRoot->GetFocusController(getter_AddRefs(focusController));
    focusController->GetFocusedWindow(getter_AddRefs(focusedWin));
  }

  // if the focused window was found get our script global object from
  // that.
  if (focusedWin) {
    NS_ASSERTION(isXULKey, "We should only use the focused window for "
                 "XUL key handlers!");
    nsCOMPtr<nsPIDOMWindow> piWin(do_QueryInterface(focusedWin));

    if (piWin) {
      piWin = piWin->GetCurrentInnerWindow();
      NS_ENSURE_TRUE(piWin, NS_ERROR_UNEXPECTED);
    }

    boundGlobal = do_QueryInterface(piWin->GetPrivateRoot());
  }
  else boundGlobal = do_QueryInterface(aReceiver);

  if (!boundGlobal) {
    nsCOMPtr<nsIDocument> boundDocument(do_QueryInterface(aReceiver));
    if (!boundDocument) {
      // We must be an element.
      nsCOMPtr<nsIContent> content(do_QueryInterface(aReceiver));
      if (!content)
        return NS_OK;
      boundDocument = content->GetOwnerDoc();
      if (!boundDocument)
        return NS_OK;
    }

    boundGlobal = boundDocument->GetScriptGlobalObject();
  }

  // If we still don't have a 'boundGlobal', we're doomed. bug 95465.
  NS_ASSERTION(boundGlobal, "failed to get the nsIScriptGlobalObject. bug 95465?");
  if (!boundGlobal)
    return NS_OK;

  nsIScriptContext *boundContext = boundGlobal->GetContext();
  if (!boundContext) return NS_OK;

  JSObject* scriptObject = nsnull;

  // strong ref to a GC root we'll need to protect scriptObject in the case
  // where it is not the global object (!winRoot).
  nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;

  if (winRoot) {
    scriptObject = boundGlobal->GetGlobalJSObject();
  } else {
    JSObject *global = boundGlobal->GetGlobalJSObject();
    JSContext *cx = (JSContext *)boundContext->GetNativeContext();

    // XXX: Don't use the global object!
    rv = nsContentUtils::XPConnect()->WrapNative(cx, global, aReceiver,
                                                 NS_GET_IID(nsISupports),
                                                 getter_AddRefs(wrapper));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = wrapper->GetJSObject(&scriptObject);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  const char *eventName = nsContentUtils::GetEventArgName(kNameSpaceID_XBL);

  nsDependentString handlerText(mHandlerText);
  if (handlerText.IsEmpty())
    return NS_ERROR_FAILURE;
  
  nsCAutoString bindingURI;
  mPrototypeBinding->DocURI()->GetSpec(bindingURI);

  rv = boundContext->CompileEventHandler(scriptObject, onEventAtom, eventName,
                                         handlerText, bindingURI.get(),
                                         mLineNumber, PR_TRUE, &handler);
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoGCRoot root(&handler, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Temporarily bind it to the bound element
  boundContext->BindCompiledEventHandler(scriptObject, onEventAtom, handler);

  // Execute it.
  nsCOMPtr<nsIDOMEventListener> eventListener;
  NS_NewJSEventListener(boundContext, boundGlobal->GetGlobalJSObject(),
                        aReceiver, getter_AddRefs(eventListener));

  nsCOMPtr<nsIJSEventListener> jsListener(do_QueryInterface(eventListener));
  jsListener->SetEventName(onEventAtom);
  
  // Handle the event.
  eventListener->HandleEvent(aEvent);
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 139 of file nsXBLPrototypeHandler.h.

  {
    return mHandler;
  }

Here is the caller graph for this function:

Definition at line 525 of file nsXBLPrototypeHandler.cpp.

{
  // XXX Fix this so there's a generic interface that describes controllers, 
  // This code should have no special knowledge of what objects might have controllers.
  nsCOMPtr<nsIControllers> controllers;

  nsCOMPtr<nsIDOMXULElement> xulElement(do_QueryInterface(aReceiver));
  if (xulElement)
    xulElement->GetControllers(getter_AddRefs(controllers));

  if (!controllers) {
    nsCOMPtr<nsIDOMNSHTMLTextAreaElement> htmlTextArea(do_QueryInterface(aReceiver));
    if (htmlTextArea)
      htmlTextArea->GetControllers(getter_AddRefs(controllers));
  }

  if (!controllers) {
    nsCOMPtr<nsIDOMNSHTMLInputElement> htmlInputElement(do_QueryInterface(aReceiver));
    if (htmlInputElement)
      htmlInputElement->GetControllers(getter_AddRefs(controllers));
  }

  if (!controllers) {
    nsCOMPtr<nsIDOMWindowInternal> domWindow(do_QueryInterface(aReceiver));
    if (domWindow)
      domWindow->GetControllers(getter_AddRefs(controllers));
  }

  // Return the first controller.
  // XXX This code should be checking the command name and using supportscommand and
  // iscommandenabled.
  nsIController* controller;
  if (controllers) {
    controllers->GetControllerAt(0, &controller);  // return reference
  }
  else controller = nsnull;

  return controller;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 129 of file nsXBLPrototypeHandler.h.

  {
    if (!mHandler) {
      NS_NewXBLEventHandler(this, mEventName, getter_AddRefs(mHandler));
      // XXX Need to signal out of memory?
    }

    return mHandler;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 517 of file nsXBLPrototypeHandler.cpp.

{
  nsIAtom* eventName = mEventName;
  NS_IF_ADDREF(eventName);
  return eventName;
}

Here is the caller graph for this function:

void nsXBLPrototypeHandler::GetEventType ( nsAString &  type) [protected]

Definition at line 773 of file nsXBLPrototypeHandler.cpp.

{
  nsCOMPtr<nsIContent> handlerElement = GetHandlerElement();
  if (!handlerElement) {
    aEvent.Truncate();
    return;
  }
  handlerElement->GetAttr(kNameSpaceID_None, nsXBLAtoms::event, aEvent);
  
  if (aEvent.IsEmpty() && (mType & NS_HANDLER_TYPE_XUL))
    // If no type is specified for a XUL <key> element, let's assume that we're "keypress".
    aEvent.AssignLiteral("keypress");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 165 of file nsXBLPrototypeHandler.cpp.

{
  if (!mBoxObjectForHandlerElement || !(mType & NS_HANDLER_TYPE_XUL)) {
    return nsnull;
  }
  nsCOMPtr<nsIDOMElement> element;
  mBoxObjectForHandlerElement->GetElement(getter_AddRefs(element));
  nsCOMPtr<nsIContent> content = do_QueryInterface(element);
  nsIContent* handler = nsnull;
  content.swap(handler);
  return handler;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsXBLPrototypeHandler::GetMatchingKeyCode ( const nsAString &  aKeyName) [inline, protected]

Definition at line 736 of file nsXBLPrototypeHandler.cpp.

{
  nsCAutoString keyName;
  keyName.AssignWithConversion(aKeyName);
  ToUpperCase(keyName); // We want case-insensitive comparison with data
                        // stored as uppercase.

  PRUint32 keyNameLength = keyName.Length();
  const char* keyNameStr = keyName.get();
  for (PRUint16 i = 0; i < (sizeof(gKeyCodes) / sizeof(gKeyCodes[0])); ++i)
    if (keyNameLength == gKeyCodes[i].strlength &&
        !nsCRT::strcmp(gKeyCodes[i].str, keyNameStr))
      return gKeyCodes[i].keycode;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 121 of file nsXBLPrototypeHandler.h.

{ return mNextHandler; }

Here is the caller graph for this function:

Definition at line 118 of file nsXBLPrototypeHandler.h.

{ return mPhase; }

Here is the caller graph for this function:

Definition at line 119 of file nsXBLPrototypeHandler.h.

{ return mType; }

Here is the caller graph for this function:

Definition at line 195 of file nsXBLPrototypeHandler.cpp.

{
  if (kAccelKey >= 0 && kMenuAccessKey >= 0)
    return;

  // Compiled-in defaults, in case we can't get the pref --
  // mac doesn't have menu shortcuts, other platforms use alt.
#if defined(XP_MAC) || defined(XP_MACOSX)
  kMenuAccessKey = 0;
  kAccelKey = nsIDOMKeyEvent::DOM_VK_META;
#else
  kMenuAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
  kAccelKey = nsIDOMKeyEvent::DOM_VK_CONTROL;
#endif

  // Get the menu access key value from prefs, overriding the default:
  kMenuAccessKey =
    nsContentUtils::GetIntPref("ui.key.menuAccessKey", kMenuAccessKey);
  kAccelKey = nsContentUtils::GetIntPref("ui.key.accelKey", kAccelKey);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 566 of file nsXBLPrototypeHandler.cpp.

{
  if (mDetail == -1)
    return PR_TRUE; // No filters set up. It's generic.

  // Get the keycode or charcode of the key event.
  PRUint32 code;
  if (mMisc)
    aKeyEvent->GetCharCode(&code);
  else
    aKeyEvent->GetKeyCode(&code);

  if (code != PRUint32(mDetail))
    return PR_FALSE;

  return ModifiersMatchMask(aKeyEvent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsXBLPrototypeHandler::KeyEventMatched ( nsIAtom aEventType,
nsIDOMKeyEvent aEvent 
) [inline]

Definition at line 91 of file nsXBLPrototypeHandler.h.

  {
    if (aEventType != mEventName)
      return PR_FALSE;

    return KeyEventMatched(aEvent);
  }

Here is the call graph for this function:

PRInt32 nsXBLPrototypeHandler::KeyToMask ( PRInt32  key) [static, protected]

Definition at line 753 of file nsXBLPrototypeHandler.cpp.

{
  switch (key)
  {
    case nsIDOMKeyEvent::DOM_VK_META:
      return cMeta | cMetaMask;
      break;

    case nsIDOMKeyEvent::DOM_VK_ALT:
      return cAlt | cAltMask;
      break;

    case nsIDOMKeyEvent::DOM_VK_CONTROL:
    default:
      return cControl | cControlMask;
  }
  return cControl | cControlMask;  // for warning avoidance
}

Here is the caller graph for this function:

Definition at line 947 of file nsXBLPrototypeHandler.cpp.

{
  nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
  nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));

  PRBool keyPresent;
  if (mKeyMask & cMetaMask) {
    key ? key->GetMetaKey(&keyPresent) : mouse->GetMetaKey(&keyPresent);
    if (keyPresent != ((mKeyMask & cMeta) != 0))
      return PR_FALSE;
  }

  if (mKeyMask & cShiftMask) {
    key ? key->GetShiftKey(&keyPresent) : mouse->GetShiftKey(&keyPresent);
    if (keyPresent != ((mKeyMask & cShift) != 0))
      return PR_FALSE;
  }

  if (mKeyMask & cAltMask) {
    key ? key->GetAltKey(&keyPresent) : mouse->GetAltKey(&keyPresent);
    if (keyPresent != ((mKeyMask & cAlt) != 0))
      return PR_FALSE;
  }

  if (mKeyMask & cControlMask) {
    key ? key->GetCtrlKey(&keyPresent) : mouse->GetCtrlKey(&keyPresent);
    if (keyPresent != ((mKeyMask & cControl) != 0))
      return PR_FALSE;
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 585 of file nsXBLPrototypeHandler.cpp.

{
  if (mDetail == -1 && mMisc == 0 && (mKeyMask & cAllModifiers) == 0)
    return PR_TRUE; // No filters set up. It's generic.

  unsigned short button;
  aMouseEvent->GetButton(&button);
  if (mDetail != -1 && (button != mDetail))
    return PR_FALSE;

  PRInt32 clickcount;
  aMouseEvent->GetDetail(&clickcount);
  if (mMisc != 0 && (clickcount != mMisc))
    return PR_FALSE;

  return ModifiersMatchMask(aMouseEvent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsXBLPrototypeHandler::MouseEventMatched ( nsIAtom aEventType,
nsIDOMMouseEvent aEvent 
) [inline]

Definition at line 101 of file nsXBLPrototypeHandler.h.

  {
    if (aEventType != mEventName)
      return PR_FALSE;

    return MouseEventMatched(aEvent);
  }

Here is the call graph for this function:

Definition at line 127 of file nsXBLPrototypeHandler.h.

Definition at line 114 of file nsXBLPrototypeHandler.h.

                                           {
    mLineNumber = aLineNumber;
  }

Here is the caller graph for this function:

Definition at line 122 of file nsXBLPrototypeHandler.h.

{ mNextHandler = aHandler; }

Here is the caller graph for this function:


Member Data Documentation

union { ... } [protected]

Definition at line 184 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cAlt = (1<<1) [static, protected]

Definition at line 175 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cAltMask = (1<<5) [static, protected]

Definition at line 180 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cControl = (1<<2) [static, protected]

Definition at line 176 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cControlMask = (1<<6) [static, protected]

Definition at line 181 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cMeta = (1<<3) [static, protected]

Definition at line 177 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cMetaMask = (1<<7) [static, protected]

Definition at line 182 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cShift = (1<<0) [static, protected]

Definition at line 174 of file nsXBLPrototypeHandler.h.

const PRInt32 nsXBLPrototypeHandler::cShiftMask = (1<<4) [static, protected]

Definition at line 179 of file nsXBLPrototypeHandler.h.

Definition at line 150 of file nsXBLPrototypeHandler.h.

PRInt32 nsXBLPrototypeHandler::kAccelKey = -1 [static, protected]

Definition at line 170 of file nsXBLPrototypeHandler.h.

Definition at line 171 of file nsXBLPrototypeHandler.h.

Definition at line 210 of file nsXBLPrototypeHandler.h.

Definition at line 217 of file nsXBLPrototypeHandler.h.

Definition at line 218 of file nsXBLPrototypeHandler.h.

Definition at line 199 of file nsXBLPrototypeHandler.h.

Definition at line 195 of file nsXBLPrototypeHandler.h.

Definition at line 205 of file nsXBLPrototypeHandler.h.

Definition at line 216 of file nsXBLPrototypeHandler.h.

Definition at line 198 of file nsXBLPrototypeHandler.h.

Definition at line 219 of file nsXBLPrototypeHandler.h.

Definition at line 201 of file nsXBLPrototypeHandler.h.


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