Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
ChromeTooltipListener Class Reference

#include <nsDocShellTreeOwner.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS ChromeTooltipListener (nsWebBrowser *inBrowser, nsIWebBrowserChrome *inChrome)
virtual ~ChromeTooltipListener ()
NS_IMETHOD HandleEvent (nsIDOMEvent *aEvent)
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.
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.
NS_IMETHOD MouseMove (nsIDOMEvent *aMouseEvent)
 Processes a mouse move event.
NS_IMETHOD DragMove (nsIDOMEvent *aMouseEvent)
 Processes a drag move event.
NS_IMETHOD KeyDown (nsIDOMEvent *aKeyEvent)
 Processes a key pressed event.
NS_IMETHOD KeyUp (nsIDOMEvent *aKeyEvent)
 Processes a key release event.
NS_IMETHOD KeyPress (nsIDOMEvent *aKeyEvent)
 Processes a key typed event.
NS_IMETHOD AddChromeListeners ()
NS_IMETHOD RemoveChromeListeners ()
void handleEvent (in nsIDOMEvent event)
 This method is called whenever an event occurs of the type for which the EventListener interface was registered.

Private Types

enum  { kTooltipAutoHideTime = 5000, kTooltipShowTime = 500 }

Private Member Functions

NS_IMETHOD AddTooltipListener ()
NS_IMETHOD RemoveTooltipListener ()
NS_IMETHOD ShowTooltip (PRInt32 inXCoords, PRInt32 inYCoords, const nsAString &inTipText)
NS_IMETHOD HideTooltip ()
void CreateAutoHideTimer ()

Static Private Member Functions

static void sTooltipCallback (nsITimer *aTimer, void *aListener)
static void sAutoHideCallback (nsITimer *aTimer, void *aListener)

Private Attributes

nsWebBrowsermWebBrowser
nsCOMPtr< nsIDOMEventReceivermEventReceiver
nsCOMPtr< nsITooltipTextProvidermTooltipTextProvider
nsCOMPtr< nsIWebBrowserChromemWebBrowserChrome
PRPackedBool mTooltipListenerInstalled
nsCOMPtr< nsITimermTooltipTimer
PRInt32 mMouseClientX
PRInt32 mMouseClientY
PRInt32 mMouseScreenX
PRInt32 mMouseScreenY
PRBool mShowingTooltip
nsCOMPtr< nsITimermAutoHideTimer
nsCOMPtr< nsIDOMNodemPossibleTooltipNode

Detailed Description

Definition at line 182 of file nsDocShellTreeOwner.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
kTooltipAutoHideTime 
kTooltipShowTime 

Definition at line 218 of file nsDocShellTreeOwner.h.

       {
    kTooltipAutoHideTime = 5000,       // 5000ms = 5 seconds
    kTooltipShowTime = 500             // 500ms = 0.5 seconds
  };

Constructor & Destructor Documentation

Definition at line 1085 of file nsDocShellTreeOwner.cpp.

Here is the call graph for this function:

Definition at line 1103 of file nsDocShellTreeOwner.cpp.

{

} // dtor

Member Function Documentation

Definition at line 1116 of file nsDocShellTreeOwner.cpp.

{  
  if ( !mEventReceiver )
    GetEventReceiver(mWebBrowser, getter_AddRefs(mEventReceiver));
  
  // Register the appropriate events for tooltips, but only if
  // the embedding chrome cares.
  nsresult rv = NS_OK;
  nsCOMPtr<nsITooltipListener> tooltipListener ( do_QueryInterface(mWebBrowserChrome) );
  if ( tooltipListener && !mTooltipListenerInstalled ) {
    rv = AddTooltipListener();
    if ( NS_FAILED(rv) )
      return rv;
  }
  
  return rv;
  
} // AddChromeListeners

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1144 of file nsDocShellTreeOwner.cpp.

{
  if (mEventReceiver) {
    nsIDOMMouseListener *pListener = NS_STATIC_CAST(nsIDOMMouseListener *, this);
    nsresult rv = mEventReceiver->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseListener));
    nsresult rv2 = mEventReceiver->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseMotionListener));
    nsresult rv3 = mEventReceiver->AddEventListenerByIID(pListener, NS_GET_IID(nsIDOMKeyListener));
    
    // if all 3 succeed, we're a go!
    if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) && NS_SUCCEEDED(rv3)) 
      mTooltipListenerInstalled = PR_TRUE;
  }

  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 1492 of file nsDocShellTreeOwner.cpp.

{
  // just to be anal (er, safe)
  if ( mAutoHideTimer ) {
    mAutoHideTimer->Cancel();
    mAutoHideTimer = nsnull;
  }
  
  mAutoHideTimer = do_CreateInstance("@mozilla.org/timer;1");
  if ( mAutoHideTimer )
    mAutoHideTimer->InitWithFuncCallback(sAutoHideCallback, this, kTooltipAutoHideTime, 
                                         nsITimer::TYPE_ONE_SHOT);

} // CreateAutoHideTimer

Here is the call graph for this function:

NS_IMETHOD ChromeTooltipListener::DragMove ( nsIDOMEvent aMouseEvent) [inline, virtual]

Processes a drag move event.

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

Implements nsIDOMMouseMotionListener.

Definition at line 203 of file nsDocShellTreeOwner.h.

{ return NS_OK; };

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 193 of file nsDocShellTreeOwner.h.

{      return NS_OK; }

Definition at line 1375 of file nsDocShellTreeOwner.cpp.

{
  nsresult rv = NS_OK;
  
  // shut down the relevant timers
  if ( mTooltipTimer ) {
    mTooltipTimer->Cancel();
    mTooltipTimer = nsnull;
    // release tooltip target
    mPossibleTooltipNode = nsnull;
  }
  if ( mAutoHideTimer ) {
    mAutoHideTimer->Cancel();
    mAutoHideTimer = nsnull;
  }

  // if we're showing the tip, tell the chrome to hide it
  if ( mShowingTooltip ) {
    nsCOMPtr<nsITooltipListener> tooltipListener ( do_QueryInterface(mWebBrowserChrome) );
    if ( tooltipListener ) {
      rv = tooltipListener->OnHideTooltip ( );
      if ( NS_SUCCEEDED(rv) )
        mShowingTooltip = PR_FALSE;
    }
  }

  return rv;
  
} // HideTooltip

Here is the call graph for this function:

Here is the caller graph for this function:

Processes a key pressed event.

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

Implements nsIDOMKeyListener.

Definition at line 1211 of file nsDocShellTreeOwner.cpp.

{
  return HideTooltip();
} // KeyDown

Here is the call graph for this function:

Processes a key typed event.

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

Implements nsIDOMKeyListener.

Definition at line 1231 of file nsDocShellTreeOwner.cpp.

{
  return NS_OK;
    
} // KeyPress

Processes a key release event.

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

Implements nsIDOMKeyListener.

Definition at line 1224 of file nsDocShellTreeOwner.cpp.

{
  return NS_OK;
    
} // KeyUp

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 1258 of file nsDocShellTreeOwner.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

Implements nsIDOMMouseListener.

Definition at line 1264 of file nsDocShellTreeOwner.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

Implements nsIDOMMouseListener.

Definition at line 1244 of file nsDocShellTreeOwner.cpp.

{
  return HideTooltip();

} // MouseDown

Here is the call graph for this function:

Processes a mouse move event.

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

Implements nsIDOMMouseMotionListener.

Definition at line 1295 of file nsDocShellTreeOwner.cpp.

{
  nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
  if (!mouseEvent)
    return NS_OK;

  // stash the coordinates of the event so that we can still get back to it from within the 
  // timer callback. On win32, we'll get a MouseMove event even when a popup goes away --
  // even when the mouse doesn't change position! To get around this, we make sure the
  // mouse has really moved before proceeding.
  PRInt32 newMouseX, newMouseY;
  mouseEvent->GetClientX(&newMouseX);
  mouseEvent->GetClientY(&newMouseY);
  if ( mMouseClientX == newMouseX && mMouseClientY == newMouseY )
    return NS_OK;
  mMouseClientX = newMouseX; mMouseClientY = newMouseY;
  mouseEvent->GetScreenX(&mMouseScreenX);
  mouseEvent->GetScreenY(&mMouseScreenY);

  // We want to close the tip if it is being displayed and the mouse moves. Recall 
  // that |mShowingTooltip| is set when the popup is showing. Furthermore, as the mouse
  // moves, we want to make sure we reset the timer to show it, so that the delay
  // is from when the mouse stops moving, not when it enters the element.
  if ( mShowingTooltip )
    return HideTooltip();
  if ( mTooltipTimer )
    mTooltipTimer->Cancel();

  mTooltipTimer = do_CreateInstance("@mozilla.org/timer;1");
  if ( mTooltipTimer ) {
    nsCOMPtr<nsIDOMEventTarget> eventTarget;
    aMouseEvent->GetTarget(getter_AddRefs(eventTarget));
    if ( eventTarget )
      mPossibleTooltipNode = do_QueryInterface(eventTarget);
    if ( mPossibleTooltipNode ) {
      nsresult rv = mTooltipTimer->InitWithFuncCallback(sTooltipCallback, this, kTooltipShowTime, 
                                                        nsITimer::TYPE_ONE_SHOT);
      if (NS_FAILED(rv))
        mPossibleTooltipNode = nsnull;
    }
  }
  else
    NS_WARNING ( "Could not create a timer for tooltip tracking" );
    
  return NS_OK;
  
} // MouseMove

Here is the call graph for this function:

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 1282 of file nsDocShellTreeOwner.cpp.

{
  return HideTooltip();
}

Here is the call graph for this function:

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 1270 of file nsDocShellTreeOwner.cpp.

{
    return NS_OK; 
}
nsresult ChromeTooltipListener::MouseUp ( nsIDOMEvent aMouseEvent) [virtual]

Processes a mouse up event.

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

Implements nsIDOMMouseListener.

Definition at line 1252 of file nsDocShellTreeOwner.cpp.

{
    return NS_OK; 
}

Definition at line 1167 of file nsDocShellTreeOwner.cpp.

{
  HideTooltip();

  if ( mTooltipListenerInstalled )
    RemoveTooltipListener();
  
  mEventReceiver = nsnull;
  
  // it really doesn't matter if these fail...
  return NS_OK;
  
} // RemoveChromeTooltipListeners

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1189 of file nsDocShellTreeOwner.cpp.

{
  if (mEventReceiver) {
    nsIDOMMouseListener *pListener = NS_STATIC_CAST(nsIDOMMouseListener *, this);
    nsresult rv = mEventReceiver->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseListener));
    nsresult rv2 = mEventReceiver->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMMouseMotionListener));
    nsresult rv3 = mEventReceiver->RemoveEventListenerByIID(pListener, NS_GET_IID(nsIDOMKeyListener));
    if (NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) && NS_SUCCEEDED(rv3))
      mTooltipListenerInstalled = PR_FALSE;
  }

  return NS_OK;
}

Here is the caller graph for this function:

void ChromeTooltipListener::sAutoHideCallback ( nsITimer aTimer,
void aListener 
) [static, private]

Definition at line 1516 of file nsDocShellTreeOwner.cpp.

{
  ChromeTooltipListener* self = NS_STATIC_CAST(ChromeTooltipListener*, aListener);
  if ( self )
    self->HideTooltip();

  // NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
  
} // sAutoHideCallback

Here is the caller graph for this function:

NS_IMETHODIMP ChromeTooltipListener::ShowTooltip ( PRInt32  inXCoords,
PRInt32  inYCoords,
const nsAString &  inTipText 
) [private]

Definition at line 1350 of file nsDocShellTreeOwner.cpp.

{
  nsresult rv = NS_OK;
  
  // do the work to call the client
  nsCOMPtr<nsITooltipListener> tooltipListener ( do_QueryInterface(mWebBrowserChrome) );
  if ( tooltipListener ) {
    rv = tooltipListener->OnShowTooltip ( inXCoords, inYCoords, PromiseFlatString(inTipText).get() ); 
    if ( NS_SUCCEEDED(rv) )
      mShowingTooltip = PR_TRUE;
  }

  return rv;
  
} // ShowTooltip

Here is the call graph for this function:

void ChromeTooltipListener::sTooltipCallback ( nsITimer aTimer,
void aListener 
) [static, private]

Definition at line 1419 of file nsDocShellTreeOwner.cpp.

{
  ChromeTooltipListener* self = NS_STATIC_CAST(ChromeTooltipListener*,
                                               aChromeTooltipListener);
  if ( self && self->mPossibleTooltipNode ){
    // The actual coordinates we want to put the tooltip at are relative to the
    // toplevel docshell of our mWebBrowser.  We know what the screen
    // coordinates of the mouse event were, which means we just need the screen
    // coordinates of the docshell.  Unfortunately, there is no good way to
    // find those short of groveling for the presentation in that docshell and
    // finding the screen coords of its toplevel widget...
    nsCOMPtr<nsIDocShell> docShell =
      do_GetInterface(NS_STATIC_CAST(nsIWebBrowser*, self->mWebBrowser));
    nsCOMPtr<nsIPresShell> shell;
    if (docShell) {
      docShell->GetPresShell(getter_AddRefs(shell));
    }

    nsIWidget* widget = nsnull;
    if (shell) {
      nsIViewManager* vm = shell->GetViewManager();
      if (vm) {
        nsIView* view;
        vm->GetRootView(view);
        if (view) {
          nsPoint offset;
          widget = view->GetNearestWidget(&offset);
        }
      }
    }

    if (!widget) {
      // release tooltip target if there is one, NO MATTER WHAT
      self->mPossibleTooltipNode = nsnull;
      return;
    }

    // if there is text associated with the node, show the tip and fire
    // off a timer to auto-hide it.

    nsXPIDLString tooltipText;
    if (self->mTooltipTextProvider) {
      PRBool textFound = PR_FALSE;

      self->mTooltipTextProvider->GetNodeText(
          self->mPossibleTooltipNode, getter_Copies(tooltipText), &textFound);
      
      if (textFound) {
        nsString tipText(tooltipText);
        self->CreateAutoHideTimer();
        nsRect widgetDot(0, 0, 1, 1);
        nsRect screenDot;
        widget->WidgetToScreen(widgetDot, screenDot);
        self->ShowTooltip (self->mMouseScreenX - screenDot.x,
                           self->mMouseScreenY - screenDot.y,
                           tipText);
      }
    }
    
    // release tooltip target if there is one, NO MATTER WHAT
    self->mPossibleTooltipNode = nsnull;
  } // if "self" data valid
  
} // sTooltipCallback

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 248 of file nsDocShellTreeOwner.h.

Definition at line 230 of file nsDocShellTreeOwner.h.

Definition at line 243 of file nsDocShellTreeOwner.h.

Definition at line 243 of file nsDocShellTreeOwner.h.

Definition at line 244 of file nsDocShellTreeOwner.h.

Definition at line 244 of file nsDocShellTreeOwner.h.

Definition at line 259 of file nsDocShellTreeOwner.h.

Definition at line 245 of file nsDocShellTreeOwner.h.

Definition at line 239 of file nsDocShellTreeOwner.h.

Definition at line 231 of file nsDocShellTreeOwner.h.

Definition at line 241 of file nsDocShellTreeOwner.h.

Definition at line 229 of file nsDocShellTreeOwner.h.

Definition at line 237 of file nsDocShellTreeOwner.h.


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