Back to index

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

#include <nsHTMLEditorMouseListener.h>

Inheritance diagram for nsHTMLEditorMouseListener:
Inheritance graph
[legend]
Collaboration diagram for nsHTMLEditorMouseListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsHTMLEditorMouseListener (nsHTMLEditor *aHTMLEditor)
 default constructor
virtual ~nsHTMLEditorMouseListener ()
 default destructor
NS_DECL_ISUPPORTS_INHERITED
NS_IMETHOD 
MouseDown (nsIDOMEvent *aMouseEvent)
 Processes a mouse down event.
NS_IMETHOD MouseUp (nsIDOMEvent *aMouseEvent)
 Processes a mouse up event.
NS_IMETHOD MouseClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
void SetEditor (nsIEditor *aEditor)
 SetEditor gives an address to the editor that will be accessed.
NS_DECL_ISUPPORTS NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
NS_IMETHOD MouseDblClick (nsIDOMEvent *aMouseEvent)
 Processes a mouse click event.
NS_IMETHOD MouseOver (nsIDOMEvent *aMouseEvent)
 Processes a mouse enter event.
NS_IMETHOD MouseOut (nsIDOMEvent *aMouseEvent)
 Processes a mouse leave event.
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Protected Attributes

nsHTMLEditormHTMLEditor
nsIEditormEditor

Detailed Description

Definition at line 54 of file nsHTMLEditorMouseListener.h.


Constructor & Destructor Documentation

default constructor

Definition at line 70 of file nsHTMLEditorMouseListener.cpp.

  : mHTMLEditor(aHTMLEditor)
{
  SetEditor(mHTMLEditor); // Tell the base class about the editor.
}

Here is the call graph for this function:

default destructor

Definition at line 76 of file nsHTMLEditorMouseListener.cpp.

{
}

Member Function Documentation

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.

Definition at line 273 of file nsEditorEventListeners.cpp.

{
  return NS_OK;
}

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Reimplemented from nsTextEditorMouseListener.

Definition at line 286 of file nsHTMLEditorMouseListener.cpp.

{
  nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
  if (!mouseEvent) {
    //non-ui event passed in.  bad things.
    return NS_OK;
  }

  // Don't do anything special if not an HTML inline table editor
  nsCOMPtr<nsIHTMLInlineTableEditor> inlineTableEditing = do_QueryInterface(mEditor);
  if (inlineTableEditing)
  {
    nsCOMPtr<nsIDOMEventTarget> target;
    nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
    if (NS_FAILED(res)) return res;
    if (!target) return NS_ERROR_NULL_POINTER;
    nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);

    inlineTableEditing->DoInlineTableEditingAction(element);
  }

  return nsTextEditorMouseListener::MouseClick(aMouseEvent);
}

Here is the call graph for this function:

nsresult nsTextEditorMouseListener::MouseDblClick ( nsIDOMEvent aMouseEvent) [virtual, inherited]

Processes a mouse click event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 379 of file nsEditorEventListeners.cpp.

{
  return NS_OK;
}

Processes a mouse down event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Reimplemented from nsTextEditorMouseListener.

Definition at line 112 of file nsHTMLEditorMouseListener.cpp.

{
  nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
  if (!mouseEvent) {
    //non-ui event passed in.  bad things.
    return NS_OK;
  }

  // Don't do anything special if not an HTML editor
  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
  if (htmlEditor)
  {
    // Detect only "context menu" click
    //XXX This should be easier to do!
    // But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event interface :-(
    PRUint16 buttonNumber;
    nsresult res = mouseEvent->GetButton(&buttonNumber);
    if (NS_FAILED(res)) return res;

    PRBool isContextClick;

#if defined(XP_MAC) || defined(XP_MACOSX)
    // Ctrl+Click for context menu
    res = mouseEvent->GetCtrlKey(&isContextClick);
    if (NS_FAILED(res)) return res;
#else
    // Right mouse button for Windows, UNIX
    isContextClick = buttonNumber == 2;
#endif
    
    PRInt32 clickCount;
    res = mouseEvent->GetDetail(&clickCount);
    if (NS_FAILED(res)) return res;

    nsCOMPtr<nsIDOMEventTarget> target;
    nsCOMPtr<nsIDOMNSEvent> internalEvent = do_QueryInterface(aMouseEvent);
    res = internalEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
    if (NS_FAILED(res)) return res;
    if (!target) return NS_ERROR_NULL_POINTER;
    nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);

    if (isContextClick || (buttonNumber == 0 && clickCount == 2))
    {
      nsCOMPtr<nsISelection> selection;
      mEditor->GetSelection(getter_AddRefs(selection));
      if (!selection) return NS_OK;

      // Get location of mouse within target node
      nsCOMPtr<nsIDOMNSUIEvent> uiEvent = do_QueryInterface(aMouseEvent);
      if (!uiEvent) return NS_ERROR_FAILURE;

      nsCOMPtr<nsIDOMNode> parent;
      PRInt32 offset = 0;

      res = uiEvent->GetRangeParent(getter_AddRefs(parent));
      if (NS_FAILED(res)) return res;
      if (!parent) return NS_ERROR_FAILURE;

      res = uiEvent->GetRangeOffset(&offset);
      if (NS_FAILED(res)) return res;

      // Detect if mouse point is within current selection for context click
      PRBool nodeIsInSelection = PR_FALSE;
      if (isContextClick)
      {
        PRBool isCollapsed;
        selection->GetIsCollapsed(&isCollapsed);
        if (!isCollapsed)
        {
          PRInt32 rangeCount;
          res = selection->GetRangeCount(&rangeCount);
          if (NS_FAILED(res)) return res;

          for (PRInt32 i = 0; i < rangeCount; i++)
          {
            nsCOMPtr<nsIDOMRange> range;

            res = selection->GetRangeAt(i, getter_AddRefs(range));
            if (NS_FAILED(res) || !range) 
              continue;//dont bail yet, iterate through them all

            nsCOMPtr<nsIDOMNSRange> nsrange(do_QueryInterface(range));
            if (NS_FAILED(res) || !nsrange) 
              continue;//dont bail yet, iterate through them all

            res = nsrange->IsPointInRange(parent, offset, &nodeIsInSelection);

            // Done when we find a range that we are in
            if (nodeIsInSelection)
              break;
          }
        }
      }
      nsCOMPtr<nsIDOMNode> node = do_QueryInterface(target);
      if (node && !nodeIsInSelection)
      {
        if (!element)
        {
          if (isContextClick)
          {
            // Set the selection to the point under the mouse cursor:
            selection->Collapse(parent, offset);
          }
          else
          {
            // Get enclosing link if in text so we can select the link
            nsCOMPtr<nsIDOMElement> linkElement;
            res = htmlEditor->GetElementOrParentByTagName(NS_LITERAL_STRING("href"), node, getter_AddRefs(linkElement));
            if (NS_FAILED(res)) return res;
            if (linkElement)
              element = linkElement;
          }
        }
        // Select entire element clicked on if NOT within an existing selection
        //   and not the entire body, or table-related elements
        if (element)
        {
          nsCOMPtr<nsIDOMNode> selectAllNode = mHTMLEditor->FindUserSelectAllNode(element);

          if (selectAllNode)
          {
            nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(selectAllNode);
            if (newElement)
            {
              node = selectAllNode;
              element = newElement;
            }
          }

// XXX: should we call nsHTMLEditUtils::IsTableElement here?
// that also checks for thead, tbody, tfoot
          if (nsTextEditUtils::IsBody(node) ||
              nsHTMLEditUtils::IsTableCellOrCaption(node) ||
              nsHTMLEditUtils::IsTableRow(node) ||
              nsHTMLEditUtils::IsTable(node))
          {
            // This will place caret just inside table cell or at start of body
            selection->Collapse(parent, offset);
          }
          else
          {
            htmlEditor->SelectElement(element);
          }
        }
      }
      // HACK !!! Context click places the caret but the context menu consumes
      // the event; so we need to check resizing state ourselves
      htmlEditor->CheckSelectionStateForAnonymousButtons(selection);

      // Prevent bubbling if we changed selection or 
      //   for all context clicks
      if (element || isContextClick)
      {
      #ifndef XP_OS2
        mouseEvent->PreventDefault();
      #endif
        return NS_OK;
      }
    }
    else if (!isContextClick && buttonNumber == 0 && clickCount == 1)
    {
      // if the target element is an image, we have to display resizers
      nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryInterface(htmlEditor);
      PRInt32 clientX, clientY;
      mouseEvent->GetClientX(&clientX);
      mouseEvent->GetClientY(&clientY);
      objectResizer->MouseDown(clientX, clientY, element);
    }
  }

  return nsTextEditorMouseListener::MouseDown(aMouseEvent);
}

Here is the call graph for this function:

nsresult nsTextEditorMouseListener::MouseOut ( nsIDOMEvent aMouseEvent) [virtual, inherited]

Processes a mouse leave event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 395 of file nsEditorEventListeners.cpp.

{
  return NS_OK;
}
nsresult nsTextEditorMouseListener::MouseOver ( nsIDOMEvent aMouseEvent) [virtual, inherited]

Processes a mouse enter event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Implements nsIDOMMouseListener.

Definition at line 387 of file nsEditorEventListeners.cpp.

{
  return NS_OK;
}

Processes a mouse up event.

Parameters:
aMouseEvent
See also:
nsIDOMEvent.h
Returns:
whether the event was consumed or ignored.
See also:
nsresult

Reimplemented from nsTextEditorMouseListener.

Definition at line 83 of file nsHTMLEditorMouseListener.cpp.

{
  nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
  if (!mouseEvent) {
    //non-ui event passed in.  bad things.
    return NS_OK;
  }

  // Don't do anything special if not an HTML editor
  nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
  if (htmlEditor)
  {
    nsCOMPtr<nsIDOMEventTarget> target;
    nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
    if (NS_FAILED(res)) return res;
    if (!target) return NS_ERROR_NULL_POINTER;
    nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);

    nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryInterface(htmlEditor);
    PRInt32 clientX, clientY;
    mouseEvent->GetClientX(&clientX);
    mouseEvent->GetClientY(&clientY);
    objectResizer->MouseUp(clientX, clientY, element);
  }

  return nsTextEditorMouseListener::MouseUp(aMouseEvent);
}

Here is the call graph for this function:

void nsTextEditorMouseListener::SetEditor ( nsIEditor aEditor) [inline, inherited]

SetEditor gives an address to the editor that will be accessed.

Parameters:
aEditorthe editor this listener calls for editing operations

Definition at line 175 of file nsEditorEventListeners.h.

{mEditor = aEditor;}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 191 of file nsEditorEventListeners.h.

Definition at line 77 of file nsHTMLEditorMouseListener.h.


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