Added new interface nsITooltipTextProvider and service to chrome listener. b=90195 r=valeski:@netscape.com sr=rpotts@netscape.com
git-svn-id: svn://10.0.0.236/trunk@99180 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
807ce73f20
commit
d32df36e1d
@ -32,6 +32,7 @@
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsStyleCoord.h"
|
||||
#include "nsHTMLReflowState.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
// Interfaces needed to be included
|
||||
#include "nsIContextMenuListener.h"
|
||||
@ -828,6 +829,65 @@ nsDocShellTreeOwner :: RemoveChromeListeners ( )
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// DefaultTooltipTextProvider
|
||||
|
||||
class DefaultTooltipTextProvider : public nsITooltipTextProvider
|
||||
{
|
||||
public:
|
||||
DefaultTooltipTextProvider();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITOOLTIPTEXTPROVIDER
|
||||
};
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(DefaultTooltipTextProvider, nsITooltipTextProvider)
|
||||
|
||||
DefaultTooltipTextProvider::DefaultTooltipTextProvider()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
/* void getNodeText (in nsIDOMNode aNode, out wstring aText); */
|
||||
NS_IMETHODIMP DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, PRUnichar **aText, PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aNode);
|
||||
NS_ENSURE_ARG_POINTER(aText);
|
||||
|
||||
nsString outText;
|
||||
|
||||
PRBool found = PR_FALSE;
|
||||
nsCOMPtr<nsIDOMNode> current ( aNode );
|
||||
while ( !found && current ) {
|
||||
nsCOMPtr<nsIDOMElement> currElement ( do_QueryInterface(current) );
|
||||
if ( currElement ) {
|
||||
// first try the normal title attribute...
|
||||
currElement->GetAttribute(NS_LITERAL_STRING("title"), outText);
|
||||
if ( outText.Length() )
|
||||
found = PR_TRUE;
|
||||
else {
|
||||
// ...ok, that didn't work, try it in the XLink namespace
|
||||
currElement->GetAttributeNS(NS_LITERAL_STRING("http://www.w3.org/1999/xlink"), NS_LITERAL_STRING("title"), outText);
|
||||
if ( outText.Length() )
|
||||
found = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// not found here, walk up to the parent and keep trying
|
||||
if ( !found ) {
|
||||
nsCOMPtr<nsIDOMNode> temp ( current );
|
||||
temp->GetParentNode(getter_AddRefs(current));
|
||||
}
|
||||
} // while not found
|
||||
|
||||
*_retval = found;
|
||||
*aText = (found) ? outText.ToNewUnicode() : nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ADDREF(ChromeTooltipListener)
|
||||
NS_IMPL_RELEASE(ChromeTooltipListener)
|
||||
|
||||
@ -843,12 +903,19 @@ NS_INTERFACE_MAP_END
|
||||
//
|
||||
// ChromeTooltipListener ctor
|
||||
//
|
||||
|
||||
ChromeTooltipListener :: ChromeTooltipListener ( nsWebBrowser* inBrowser, nsIWebBrowserChrome* inChrome )
|
||||
: mWebBrowser(inBrowser), mWebBrowserChrome(inChrome),
|
||||
mTooltipListenerInstalled(PR_FALSE),
|
||||
mShowingTooltip(PR_FALSE), mMouseClientX(0), mMouseClientY(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mTooltipTextProvider = do_GetService(NS_TOOLTIPTEXTPROVIDER_CONTRACTID);
|
||||
if (!mTooltipTextProvider) {
|
||||
nsISupports *pProvider = (nsISupports *) new DefaultTooltipTextProvider;
|
||||
mTooltipTextProvider = do_QueryInterface(pProvider);
|
||||
}
|
||||
} // ctor
|
||||
|
||||
|
||||
@ -1170,45 +1237,6 @@ ChromeTooltipListener :: HideTooltip ( )
|
||||
} // HideTooltip
|
||||
|
||||
|
||||
//
|
||||
// FindTitleText
|
||||
//
|
||||
// Determine if there is a TITLE attribute. Checks both the XLINK namespace, and no
|
||||
// namespace. Returns |PR_TRUE| if there is, and sets the text in |outText|.
|
||||
//
|
||||
PRBool
|
||||
ChromeTooltipListener :: FindTitleText ( nsIDOMNode* inNode, nsAWritableString & outText )
|
||||
{
|
||||
PRBool found = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> current ( inNode );
|
||||
while ( !found && current ) {
|
||||
nsCOMPtr<nsIDOMElement> currElement ( do_QueryInterface(current) );
|
||||
if ( currElement ) {
|
||||
// first try the normal title attribute...
|
||||
currElement->GetAttribute(NS_LITERAL_STRING("title"), outText);
|
||||
if ( outText.Length() )
|
||||
found = PR_TRUE;
|
||||
else {
|
||||
// ...ok, that didn't work, try it in the XLink namespace
|
||||
currElement->GetAttributeNS(NS_LITERAL_STRING("http://www.w3.org/1999/xlink"), NS_LITERAL_STRING("title"), outText);
|
||||
if ( outText.Length() )
|
||||
found = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// not found here, walk up to the parent and keep trying
|
||||
if ( !found ) {
|
||||
nsCOMPtr<nsIDOMNode> temp ( current );
|
||||
temp->GetParentNode(getter_AddRefs(current));
|
||||
}
|
||||
} // while not found
|
||||
|
||||
return found;
|
||||
|
||||
} // FindTitleText
|
||||
|
||||
|
||||
//
|
||||
// sTooltipCallback
|
||||
//
|
||||
@ -1226,11 +1254,22 @@ ChromeTooltipListener :: sTooltipCallback (nsITimer *aTimer, void *aChromeToolti
|
||||
{
|
||||
ChromeTooltipListener* self = NS_STATIC_CAST(ChromeTooltipListener*, aChromeTooltipListener);
|
||||
if ( self && self->mPossibleTooltipNode ) {
|
||||
// if there is a TITLE tag, show the tip and fire off a timer to auto-hide it
|
||||
nsAutoString tooltipText;
|
||||
if ( self->FindTitleText(self->mPossibleTooltipNode, tooltipText) ) {
|
||||
self->CreateAutoHideTimer ( );
|
||||
self->ShowTooltip ( self->mMouseClientX, self->mMouseClientY, tooltipText );
|
||||
|
||||
// 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 ( );
|
||||
self->ShowTooltip (self->mMouseClientX, self->mMouseClientY, tipText);
|
||||
}
|
||||
}
|
||||
|
||||
// release tooltip target if there is one, NO MATTER WHAT
|
||||
|
||||
@ -45,6 +45,7 @@
|
||||
#include "nsITimer.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIAuthPrompt.h"
|
||||
#include "nsITooltipListener.h"
|
||||
|
||||
#include "nsCommandHandler.h"
|
||||
|
||||
@ -189,12 +190,9 @@ private:
|
||||
NS_IMETHOD ShowTooltip ( PRInt32 inXCoords, PRInt32 inYCoords, const nsAReadableString & inTipText ) ;
|
||||
NS_IMETHOD HideTooltip ( ) ;
|
||||
|
||||
// Determine if there is a TITLE attribute. Returns |PR_TRUE| if there is,
|
||||
// and sets the text in |outText|.
|
||||
PRBool FindTitleText ( nsIDOMNode* inNode, nsAWritableString & outText ) ;
|
||||
|
||||
nsWebBrowser* mWebBrowser;
|
||||
nsCOMPtr<nsIDOMEventReceiver> mEventReceiver;
|
||||
nsCOMPtr<nsITooltipTextProvider> mTooltipTextProvider;
|
||||
|
||||
// This must be a strong ref in order to make sure we can hide the tooltip
|
||||
// if the window goes away while we're displaying one. If we don't hold
|
||||
|
||||
@ -25,14 +25,30 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMNode;
|
||||
|
||||
//
|
||||
// nsITooltipTextProvider
|
||||
//
|
||||
// Interface implemented by a tooltip text provider service, returns
|
||||
// the text to display above a particular node (e.g. the TITLE tag).
|
||||
//
|
||||
[uuid(b128a1e6-44f3-4331-8fbe-5af360ff21ee)]
|
||||
interface nsITooltipTextProvider : nsISupports
|
||||
{
|
||||
boolean getNodeText(in nsIDOMNode aNode, out wstring aText);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_TOOLTIPTEXTPROVIDER_CONTRACTID \
|
||||
"@mozilla.org/embedcomp/tooltiptextprovider;1"
|
||||
%}
|
||||
|
||||
//
|
||||
// nsITooltipListener interface
|
||||
//
|
||||
// Used to tell an embedding client when a tooltip should be displayed or hidden.
|
||||
//
|
||||
|
||||
|
||||
[uuid(44b78386-1dd2-11b2-9ad2-e4eee2ca1916)]
|
||||
interface nsITooltipListener : nsISupports
|
||||
{
|
||||
@ -48,10 +64,10 @@ interface nsITooltipListener : nsISupports
|
||||
//
|
||||
// Returning any result other than NS_OK will cause Gecko to
|
||||
// behave as if no tooltip was displayed (no auto-timeout, etc).
|
||||
void OnShowTooltip ( in long aXCoords, in long aYCoords, in wstring aTipText ) ;
|
||||
void onShowTooltip ( in long aXCoords, in long aYCoords, in wstring aTipText ) ;
|
||||
|
||||
// Called when the tooltip should be hidden, either by a mouse move
|
||||
// or an auto-hide of the tooltip.
|
||||
void OnHideTooltip ( ) ;
|
||||
void onHideTooltip ( ) ;
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user