[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    [PATCH] fix imagemap titles (#66722)
From:       bj () altern ! org
Date:       2004-06-27 22:55:28
Message-ID: 200406280102.03446.bj () altern ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hello!

The following patch fixes bug 66722: image map titles are not shown 
(http://bugs.kde.org/show_bug.cgi?id=66722)

You can test it on http://www.ader.ch/abc/effet.php
Country names should now pop up correctly with the patch.
It also works when there are several images with the same map on a page.

There may be a better way to fix it, but I am not familiar with khtml.
Anybody wants to review/correct/commit ?

["maptitle.diff" (text/x-diff)]

Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.639
diff -u -3 -r1.639 khtmlview.cpp
--- khtmlview.cpp	19 Jun 2004 20:47:34 -0000	1.639
+++ khtmlview.cpp	27 Jun 2004 22:46:40 -0000
@@ -111,7 +111,7 @@
     };
 
 protected:
-    virtual void maybeTip(const QPoint &);
+    virtual void maybeTip(const QPoint &p);
 
 private:
     KHTMLView *m_view;
@@ -326,18 +326,26 @@
 
 #ifndef QT_NO_TOOLTIP
 
-void KHTMLToolTip::maybeTip(const QPoint& /*p*/)
+void KHTMLToolTip::maybeTip(const QPoint& p)
 {
     DOM::NodeImpl *node = m_viewprivate->underMouse;
+    int vx,vy;
+    m_view->contentsToViewport(0,0,vx,vy);
     QRect region;
     while ( node ) {
         if ( node->isElementNode() ) {
             QString s = static_cast<DOM::ElementImpl*>( node )->getAttribute( \
                ATTR_TITLE ).string();
-            QRect r = node->getRect();
+	    QRect r=QRect();
+	    if (node->id()==ID_AREA)
+            r = static_cast<DOM::HTMLAreaElementImpl*>(node)->getRect(QPoint(p.x()-vx,p.y()-vy));
 +	    else r=node->getRect();
+	    if (!r.isEmpty())
+	    {
             region |= QRect( m_view->contentsToViewport( r.topLeft() ), r.size() );
-            if ( !s.isEmpty() ) {
+            if ( !s.isEmpty()) {
                 tip( region, QStyleSheet::convertFromPlainText( s, \
QStyleSheetItem::WhiteSpaceNormal ) );  break;
+		}
             }
         }
         node = node->parentNode();
Index: html/html_imageimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_imageimpl.cpp,v
retrieving revision 1.146
diff -u -3 -r1.146 html_imageimpl.cpp
--- html/html_imageimpl.cpp	25 Feb 2004 00:41:34 -0000	1.146
+++ html/html_imageimpl.cpp	27 Jun 2004 22:46:42 -0000
@@ -387,13 +387,29 @@
     return inside;
 }
 
-QRect HTMLAreaElementImpl::getRect() const
+QRect HTMLAreaElementImpl::getRect(const QPoint& p) const
 {
-    if (parentNode()->renderer()==0)
-        return QRect();
-    int dx, dy;
-    if (!parentNode()->renderer()->absolutePosition(dx, dy))
+    if (!parentNode())
         return QRect();
+
+    int dx=0, dy=0;
+    QString mapName=static_cast<DOM::ElementImpl*>(parentNode())->getAttribute(ATTR_NAME).string();
 +     NodeImpl *de = static_cast<DOM::DocumentImpl*>(getDocument());      
+	for (NodeImpl* n = de->firstChild(); n; n = n->traverseNextNode())
+                if ((n->id() == ID_IMG))
+		if (static_cast<DOM::ElementImpl*>(n)->getAttribute( ATTR_USEMAP \
).string().section("#",-1)==mapName) +			{
+			QRect rec=static_cast<DOM::ElementImpl*>(n)->getRect();
+			if (!rec.isNull())
+			{
+			dx=rec.x();
+			dy=rec.y();
+			if (QRect(dx,dy,lastw,lasth).contains(p)) break;
+			}
+		   }
+    
+    //if (!parentNode()->renderer()->absolutePosition(dx, dy))
+    //    return QRect();
     QRegion region = getRegion(lastw,lasth);
     region.translate(dx, dy);
     return region.boundingRect();
Index: html/html_imageimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_imageimpl.h,v
retrieving revision 1.66
diff -u -3 -r1.66 html_imageimpl.h
--- html/html_imageimpl.h	24 Jun 2003 21:56:04 -0000	1.66
+++ html/html_imageimpl.h	27 Jun 2004 22:46:42 -0000
@@ -87,7 +87,7 @@
     bool mapMouseEvent(int x_, int y_, int width_, int height_,
                        khtml::RenderObject::NodeInfo& info);
 
-    virtual QRect getRect() const;
+    virtual QRect getRect(const QPoint& p) const;
 
 protected:
     QRegion getRegion(int width_, int height) const;


[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic