Fix for alt text not working on images.
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Jul 2004 21:54:13 +0000 (21:54 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Jul 2004 21:54:13 +0000 (21:54 +0000)
        Reviewed by john

        * khtml/rendering/render_image.cpp:
        (RenderImage::RenderImage):
        (RenderImage::setPixmap):
        (RenderImage::paint):
        (RenderImage::calcReplacedWidth):
        (RenderImage::calcReplacedHeight):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@7069 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog-2005-08-23
WebCore/khtml/rendering/render_image.cpp

index 8bcdfaa..77164e7 100644 (file)
@@ -1,3 +1,16 @@
+2004-07-20  David Hyatt  <hyatt@apple.com>
+
+       Fix for alt text not working on images.
+       
+        Reviewed by john
+
+        * khtml/rendering/render_image.cpp:
+        (RenderImage::RenderImage):
+        (RenderImage::setPixmap):
+        (RenderImage::paint):
+        (RenderImage::calcReplacedWidth):
+        (RenderImage::calcReplacedHeight):
+
 2004-07-20  Maciej Stachowiak  <mjs@apple.com>
 
         Reviewed by Dave.
index c89c128..db232cd 100644 (file)
@@ -58,6 +58,8 @@ RenderImage::RenderImage(NodeImpl *_node)
 
     setIntrinsicWidth( 0 );
     setIntrinsicHeight( 0 );
+    if (element())
+        updateAltText();
 }
 
 RenderImage::~RenderImage()
@@ -101,11 +103,11 @@ void RenderImage::setPixmap( const QPixmap &p, const QRect& r, CachedImage *o)
     bool iwchanged = false;
 
     if(o->isErrorImage()) {
-        int iw = p.width() + 8;
-        int ih = p.height() + 8;
+        int iw = p.width() + 4;
+        int ih = p.height() + 4;
 
         // we have an alt and the user meant it (its not a text we invented)
-        if ( element() && !alt.isEmpty() && !element()->getAttribute( ATTR_ALT ).isNull()) {
+        if (!alt.isEmpty()) {
             const QFontMetrics &fm = style()->fontMetrics();
             QRect br = fm.boundingRect (  0, 0, 1024, 256, Qt::AlignAuto|Qt::WordBreak, alt.string() );
             if ( br.width() > iw )
@@ -278,11 +280,10 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
             
             bool errorPictureDrawn = false;
             int imageX = 0, imageY = 0;
-            int usableWidth = cWidth - leftBorder - borderRight() - leftPad - paddingRight();
-            int usableHeight = cHeight - topBorder - borderBottom() - topPad - paddingBottom();
+            int usableWidth = cWidth;
+            int usableHeight = cHeight;
             
-            if(berrorPic && !pix.isNull() && (usableWidth >= pix.width()) && (usableHeight >= pix.height()) )
-            {
+            if (berrorPic && !pix.isNull() && (usableWidth >= pix.width()) && (usableHeight >= pix.height())) {
                 // Center the error image, accounting for border and padding.
                 int centerX = (usableWidth - pix.width())/2;
                 if (centerX < 0)
@@ -292,11 +293,11 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
                     centerY = 0;
                 imageX = leftBorder + leftPad + centerX;
                 imageY = topBorder + topPad + centerY;
-                p->drawPixmap( QPoint(_tx + imageX, _ty + imageY), pix, pix.rect() );
+                p->drawPixmap(QPoint(_tx + imageX, _ty + imageY), pix, pix.rect());
                 errorPictureDrawn = true;
             }
             
-            if(!alt.isEmpty()) {
+            if (!alt.isEmpty()) {
                 QString text = alt.string();
                 text.replace('\\', backslashAsCurrencySymbol());
                 p->setFont (style()->font());
@@ -309,11 +310,11 @@ void RenderImage::paint(PaintInfo& i, int _tx, int _ty)
                 // Only draw the alt text if it'll fit within the content box,
                 // and only if it fits above the error image.
                 int textWidth = fm.width (text, text.length());
-                if (errorPictureDrawn){
-                    if (usableWidth > textWidth && fm.height() <= imageY)
+                if (errorPictureDrawn) {
+                    if (usableWidth >= textWidth && fm.height() <= imageY)
                         p->drawText(ax, ay+ascent, 0 /* ignored */, 0 /* ignored */, Qt::WordBreak  /* not supported */, text );
                 }
-                else if (usableWidth >= textWidth && cHeight>=fm.height())
+                else if (usableWidth >= textWidth && cHeight >= fm.height())
                     p->drawText(ax, ay+ascent, 0 /* ignored */, 0 /* ignored */, Qt::WordBreak  /* not supported */, text );
             }
 #else /* not APPLE_CHANGES */
@@ -605,9 +606,10 @@ int RenderImage::calcReplacedWidth() const
 {
     // If height is specified and not width, preserve aspect ratio.
     if (isHeightSpecified() && !isWidthSpecified()) {
-        if (intrinsicHeight() == 0){
+        if (intrinsicHeight() == 0)
             return 0;
-        }
+        if (!image || image->isErrorImage())
+            return intrinsicWidth(); // Don't bother scaling.
         return calcReplacedHeight() * intrinsicWidth() / intrinsicHeight();
     }
     return RenderReplaced::calcReplacedWidth();
@@ -617,9 +619,10 @@ int RenderImage::calcReplacedHeight() const
 {
     // If width is specified and not height, preserve aspect ratio.
     if (isWidthSpecified() && !isHeightSpecified()) {
-        if (intrinsicWidth() == 0){
+        if (intrinsicWidth() == 0)
             return 0;
-        }
+        if (!image || image->isErrorImage())
+            return intrinsicHeight(); // Don't bother scaling.
         return calcReplacedWidth() * intrinsicHeight() / intrinsicWidth();
     }
     return RenderReplaced::calcReplacedHeight();