hookup tooltips in PPEmbed. fix embedding tooltip impl to check window/dialog tag before groveling for title attribute. r=pink/sr=beard. bug# 142814.

This commit is contained in:
pinkerton%netscape.com 2002-05-28 20:31:39 +00:00
parent a5b81dcacf
commit 5367483734
3 changed files with 82 additions and 23 deletions

View File

@ -1209,9 +1209,9 @@ Boolean CBrowserShell::FindNext()
}
NS_METHOD CBrowserShell::OnShowContextMenu(PRUint32 aContextFlags,
nsIDOMEvent *aEvent,
nsIDOMNode *aNode)
NS_IMETHODIMP CBrowserShell::OnShowContextMenu(PRUint32 aContextFlags,
nsIDOMEvent *aEvent,
nsIDOMNode *aNode)
{
// Find our CWebBrowserCMAttachment, if any
CWebBrowserCMAttachment *aCMAttachment = nsnull;
@ -1244,16 +1244,55 @@ NS_METHOD CBrowserShell::OnShowContextMenu(PRUint32 aContextFlags,
return NS_OK;
}
NS_METHOD CBrowserShell::OnShowTooltip(PRInt32 aXCoords,
PRInt32 aYCoords,
const PRUnichar *aTipText)
NS_IMETHODIMP CBrowserShell::OnShowTooltip(PRInt32 aXCoords,
PRInt32 aYCoords,
const PRUnichar *aTipText)
{
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
#if TARGET_CARBON
if ((Ptr)HMDisplayTag != (Ptr)kUnresolvedCFragSymbolAddress &&
(Ptr)HMHideTag != (Ptr)kUnresolvedCFragSymbolAddress)
{
HMHelpContentRec contentRec;
Point location;
location.h = aXCoords; location.v = aYCoords;
FocusDraw();
LocalToPortPoint(location);
PortToGlobalPoint(location);
contentRec.version = kMacHelpVersion;
contentRec.absHotRect.top = contentRec.absHotRect.bottom = location.v;
contentRec.absHotRect.left = contentRec.absHotRect.right = location.h;
::InsetRect(&contentRec.absHotRect, -4, -4);
contentRec.tagSide = kHMOutsideBottomScriptAligned;
contentRec.content[kHMMinimumContentIndex].contentType = kHMCFStringContent;
contentRec.content[kHMMinimumContentIndex].u.tagCFString =
::CFStringCreateWithCharactersNoCopy(NULL, (const UniChar *)aTipText, nsCRT::strlen(aTipText), kCFAllocatorNull);
contentRec.content[kHMMaximumContentIndex].contentType = kHMNoContent;
::HMDisplayTag(&contentRec);
rv = NS_OK;
}
#endif
return rv;
}
NS_METHOD CBrowserShell::OnHideTooltip()
NS_IMETHODIMP CBrowserShell::OnHideTooltip()
{
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
#if TARGET_CARBON
if ((Ptr)HMHideTag != (Ptr)kUnresolvedCFragSymbolAddress)
{
::HMHideTag();
rv = NS_OK;
}
#endif
return rv;
}

View File

@ -179,14 +179,14 @@ protected:
virtual void LeaveDropArea( DragReference inDragRef );
virtual void DoDragReceive( DragReference inDragRef );
NS_METHOD OnShowContextMenu(PRUint32 aContextFlags,
NS_IMETHOD OnShowContextMenu(PRUint32 aContextFlags,
nsIDOMEvent *aEvent,
nsIDOMNode *aNode);
NS_METHOD OnShowTooltip(PRInt32 aXCoords,
NS_IMETHOD OnShowTooltip(PRInt32 aXCoords,
PRInt32 aYCoords,
const PRUnichar *aTipText);
NS_METHOD OnHideTooltip();
NS_IMETHOD OnHideTooltip();
NS_METHOD CommonConstruct();

View File

@ -66,7 +66,7 @@
#include "nsRect.h"
#include "nsIWebBrowserChromeFocus.h"
#include "nsIDragDropOverride.h"
#include "nsIContent.h"
static const char sWindowWatcherContractID[] = "@mozilla.org/embedcomp/window-watcher;1";
@ -872,6 +872,11 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSITOOLTIPTEXTPROVIDER
protected:
nsCOMPtr<nsIAtom> mTag_dialog;
nsCOMPtr<nsIAtom> mTag_dialogheader;
nsCOMPtr<nsIAtom> mTag_window;
};
NS_IMPL_THREADSAFE_ISUPPORTS1(DefaultTooltipTextProvider, nsITooltipTextProvider)
@ -879,6 +884,12 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(DefaultTooltipTextProvider, nsITooltipTextProvider
DefaultTooltipTextProvider::DefaultTooltipTextProvider()
{
NS_INIT_REFCNT();
// There are certain element types which we don't want to use
// as tool tip text.
mTag_dialog = getter_AddRefs(NS_NewAtom("dialog"));
mTag_dialogheader = getter_AddRefs(NS_NewAtom("dialogheader"));
mTag_window = getter_AddRefs(NS_NewAtom("window"));
}
/* void getNodeText (in nsIDOMNode aNode, out wstring aText); */
@ -886,7 +897,7 @@ NS_IMETHODIMP DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, PRUnich
{
NS_ENSURE_ARG_POINTER(aNode);
NS_ENSURE_ARG_POINTER(aText);
nsString outText;
PRBool found = PR_FALSE;
@ -894,15 +905,24 @@ NS_IMETHODIMP DefaultTooltipTextProvider::GetNodeText(nsIDOMNode *aNode, PRUnich
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;
nsCOMPtr<nsIContent> content(do_QueryInterface(currElement));
if (content) {
nsCOMPtr<nsIAtom> tagAtom;
content->GetTag(*getter_AddRefs(tagAtom));
if (tagAtom != mTag_dialog &&
tagAtom != mTag_dialogheader &&
tagAtom != mTag_window) {
// 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;
}
}
}
}