2006-01-21 Anders Carlsson <andersca@mac.com>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2006 21:58:03 +0000 (21:58 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2006 21:58:03 +0000 (21:58 +0000)
        Reviewed by Darin.

        http://bugzilla.opendarwin.org/show_bug.cgi?id=3869
        Should use HTML Image element instead of JS Image object

        * khtml/ecma/kjs_events.cpp:
        (KJS::ClipboardProtoFunc::callAsFunction):
        Don't check Image object. Instead, if the element passed in
        is an image element which isn't in any document, use its pixmap.

        * khtml/ecma/kjs_html.cpp:
        (KJS::HTMLElement::imageGetter):
        Add complete.

        (KJS::ImageConstructorImp::construct):
        Take a QPixmap instead of an Image.

        (KJS::KJS::Context2DFunction::callAsFunction):
        Remove usage of Image and use HTMLImageElementImpl instead.

        * khtml/ecma/kjs_html.h:
        Remove Image class.

        (KJS::HTMLElement::):
        Add ImgComplete.

        * khtml/html/html_imageimpl.cpp:
        (WebCore::HTMLImageElementImpl::width):
        (WebCore::HTMLImageElementImpl::height):
        If the element has no renderer but its image size is known
        return that instead.

        (WebCore::HTMLImageElementImpl::complete):
        New function, returns true if an image has finished loading.

        * khtml/html/html_imageimpl.h:
        Add complete.

        * manual-tests/drag-image.html: Added.

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/image-object-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/image-object-in-canvas-expected.checksum [new file with mode: 0644]
LayoutTests/fast/dom/image-object-in-canvas-expected.png [new file with mode: 0644]
LayoutTests/fast/dom/image-object-in-canvas-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/image-object-in-canvas.html [new file with mode: 0644]
LayoutTests/fast/dom/image-object.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/khtml/ecma/kjs_events.cpp
WebCore/khtml/ecma/kjs_html.cpp
WebCore/khtml/ecma/kjs_html.h
WebCore/khtml/html/html_imageimpl.cpp
WebCore/khtml/html/html_imageimpl.h
WebCore/manual-tests/drag-image.html [new file with mode: 0644]

index 3513785..45991c8 100644 (file)
@@ -1,5 +1,19 @@
 2006-01-21  Anders Carlsson  <andersca@mac.com>
 
+        Reviewed by Darin.
+
+        - tests for http://bugzilla.opendarwin.org/show_bug.cgi?id=3869
+        Should use HTML Image element instead of JS Image object
+
+        * fast/dom/image-object-expected.txt: Added.
+        * fast/dom/image-object-in-canvas-expected.checksum: Added.
+        * fast/dom/image-object-in-canvas-expected.png: Added.
+        * fast/dom/image-object-in-canvas-expected.txt: Added.
+        * fast/dom/image-object-in-canvas.html: Added.
+        * fast/dom/image-object.html: Added.
+
+2006-01-21  Anders Carlsson  <andersca@mac.com>
+
         * editing/editing.js:
         Fix typo which made editing test cases fail.
 
diff --git a/LayoutTests/fast/dom/image-object-expected.txt b/LayoutTests/fast/dom/image-object-expected.txt
new file mode 100644 (file)
index 0000000..c62ca11
--- /dev/null
@@ -0,0 +1,4 @@
+This tests that the Image JavaScript object works as expected. If the test is successful, the test "SUCCESS" should be shown below.
+
+SUCCESS!
+
diff --git a/LayoutTests/fast/dom/image-object-in-canvas-expected.checksum b/LayoutTests/fast/dom/image-object-in-canvas-expected.checksum
new file mode 100644 (file)
index 0000000..2d94c94
--- /dev/null
@@ -0,0 +1 @@
+61f3c3d1f7e2dfd0a6b6a3f87b463b31
\ No newline at end of file
diff --git a/LayoutTests/fast/dom/image-object-in-canvas-expected.png b/LayoutTests/fast/dom/image-object-in-canvas-expected.png
new file mode 100644 (file)
index 0000000..047249c
Binary files /dev/null and b/LayoutTests/fast/dom/image-object-in-canvas-expected.png differ
diff --git a/LayoutTests/fast/dom/image-object-in-canvas-expected.txt b/LayoutTests/fast/dom/image-object-in-canvas-expected.txt
new file mode 100644 (file)
index 0000000..f2611b3
--- /dev/null
@@ -0,0 +1,22 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x543
+  RenderBlock {HTML} at (0,0) size 800x543
+    RenderBody {BODY} at (8,16) size 784x514
+      RenderBlock {P} at (0,0) size 784x36
+        RenderText {TEXT} at (0,0) size 779x36
+          text run at (0,0) width 779: "This tests that the Image JavaScript object works as expected when used in a canvas. If the test is successful, the Apple logo"
+          text run at (0,18) width 354: "should appear scaled, normal and finally tiled in a circle."
+      RenderBlock {DIV} at (0,52) size 784x154
+        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderText {TEXT} at (150,136) size 117x18
+          text run at (150,136) width 117: "Using drawImage."
+      RenderBlock {DIV} at (0,206) size 784x154
+        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderText {TEXT} at (150,136) size 180x18
+          text run at (150,136) width 180: "Using drawImageFromRect."
+      RenderBlock {DIV} at (0,360) size 784x154
+        RenderCanvasImage {CANVAS} at (0,0) size 150x150
+        RenderText {TEXT} at (150,136) size 129x18
+          text run at (150,136) width 129: "Using ImagePattern."
+      RenderBlock {PRE} at (0,527) size 784x0
diff --git a/LayoutTests/fast/dom/image-object-in-canvas.html b/LayoutTests/fast/dom/image-object-in-canvas.html
new file mode 100644 (file)
index 0000000..9038ec0
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+        "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<script>
+function debug(str) {
+    var c = document.getElementById('console')
+    c.appendChild(document.createTextNode(str + '\n'));
+}
+
+var numErrs = 0;
+
+function getContext(id) {
+    return document.getElementById(id).getContext('2d');
+}
+
+function imageLoaded() {
+    var c1 = getContext('canvas1')
+    c1.drawImage(i, 0, 0, i.width * 2, i.height * 2)
+    
+    var c2 = getContext('canvas2');
+    c2.drawImageFromRect(i, 0, 0, i.width, i.height, 0, 0, i.width, i.height, 'over')
+    
+    var c3 = getContext('canvas3');
+    var pattern = c3.createPattern(i, 'repeat');
+    c3.fillStyle = pattern;
+    c3.arc(75, 75, 60, 0, 2*Math.PI, 0);
+    c3.fill();
+    
+    if (window.layoutTestController) { 
+        layoutTestController.notifyDone();
+    }
+}
+
+function runTests() {
+    if (window.layoutTestController) {
+        layoutTestController.waitUntilDone();
+    }
+    
+    i = new Image();
+    i.onload = imageLoaded;
+    i.src = 'resources/apple.gif';
+}
+
+</script>
+</head>
+<body onload="runTests();">
+<p>This tests that the Image JavaScript object works as expected when used in a canvas. If the test is successful, the Apple logo should appear scaled, normal and finally tiled in a circle.</p>
+<div><canvas id="canvas1" width="150" height="150"/>Using drawImage.</div>
+<div><canvas id="canvas2" width="150" height="150"/>Using drawImageFromRect.</div>
+<div><canvas id="canvas3" width="150" height="150"/>Using ImagePattern.</div>
+
+<pre id="console">
+</pre>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/image-object.html b/LayoutTests/fast/dom/image-object.html
new file mode 100644 (file)
index 0000000..d4f895e
--- /dev/null
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+        "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<script>
+function debug(str) {
+    var c = document.getElementById('console')
+    c.appendChild(document.createTextNode(str + '\n'));
+}
+
+var numErrs = 0;
+
+function imageLoaded() {
+    if (!i2.complete) {
+        debug('FAILURE: image loaded but complete is false!');
+        numErrs++;
+    }
+    
+    if (i2.width != 52) {
+        debug('FAILURE: image width should be 52, was ' + i2.width)
+        numErrs++;
+    }
+
+    if (i2.height != 64) {
+        debug('FAILURE: image width should be 64, was ' + i2.height)
+        numErrs++;
+    }
+
+    if (numErrs == 0) {
+        debug('SUCCESS!')
+    }
+    
+    if (window.layoutTestController) { 
+        layoutTestController.notifyDone();
+    }
+}
+
+function runTests() {
+    if (window.layoutTestController) {
+        layoutTestController.dumpAsText();
+        layoutTestController.waitUntilDone();
+    }
+    
+    i1 = new Image();
+    if (!i1.complete) {
+        debug('FAILURE: Empty image should have complete set to true.');
+        numErrs++;
+    }
+    
+    i2 = new Image()
+    i2.onload = imageLoaded;
+    i2.src = 'resources/apple.gif';
+}
+
+</script>
+</head>
+<body onload="runTests();">
+<p>
+This tests that the Image JavaScript object works as expected. If the test is successful, the test "SUCCESS" should be shown below.
+</p>
+<pre id="console">
+</pre>
+</body>
+</html>
index ede9e91..9e5b727 100644 (file)
@@ -2,6 +2,48 @@
 
         Reviewed by Darin.
 
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=3869
+        Should use HTML Image element instead of JS Image object
+
+        * khtml/ecma/kjs_events.cpp:
+        (KJS::ClipboardProtoFunc::callAsFunction):
+        Don't check Image object. Instead, if the element passed in
+        is an image element which isn't in any document, use its pixmap.
+        
+        * khtml/ecma/kjs_html.cpp:
+        (KJS::HTMLElement::imageGetter):
+        Add complete.
+        
+        (KJS::ImageConstructorImp::construct):
+        Take a QPixmap instead of an Image.
+        
+        (KJS::KJS::Context2DFunction::callAsFunction):
+        Remove usage of Image and use HTMLImageElementImpl instead.
+
+        * khtml/ecma/kjs_html.h:
+        Remove Image class.
+        
+        (KJS::HTMLElement::):
+        Add ImgComplete.
+        
+        * khtml/html/html_imageimpl.cpp:
+        (WebCore::HTMLImageElementImpl::width):
+        (WebCore::HTMLImageElementImpl::height):
+        If the element has no renderer but its image size is known
+        return that instead.
+        
+        (WebCore::HTMLImageElementImpl::complete):
+        New function, returns true if an image has finished loading.
+        
+        * khtml/html/html_imageimpl.h:
+        Add complete.
+        
+        * manual-tests/drag-image.html: Added.
+
+2006-01-21  Anders Carlsson  <andersca@mac.com>
+
+        Reviewed by Darin.
+
         - fixes http://bugzilla.opendarwin.org/show_bug.cgi?id=6691
         TinyMCE: strikethrough unimplemented
         
index 4a0a856..249f211 100644 (file)
 #include "kjs_window.h"
 #include "kjs_views.h"
 #include "kjs_proxy.h"
+#include "html/html_imageimpl.h"
 #include "DocumentImpl.h"
 #include "xml/dom2_eventsimpl.h"
 #include "xml/dom2_viewsimpl.h"
 #include "xml/EventNames.h"
 #include "rendering/render_object.h"
 #include "CachedImage.h"
+#include "htmlnames.h"
 
 #include <kdebug.h>
 
 using namespace DOM;
 using namespace EventNames;
 using namespace khtml;
+using namespace HTMLNames;
 
 namespace KJS {
 
@@ -1131,24 +1134,19 @@ JSValue *ClipboardProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj,
 
             // See if they passed us a node
             NodeImpl *node = toNode(args[0]);
-            if (node) {
-                if (node->isElementNode()) {
-                    cb->clipboard->setDragImageElement(node, IntPoint(x,y));                    
-                    return jsUndefined();
-                } else {
-                    return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");
-                }
-            }
-
-            // See if they passed us an Image object
-            JSObject *o = static_cast<JSObject*>(args[0]);
-            if (o->isObject() && o->inherits(&Image::info)) {
-                Image *JSImage = static_cast<Image*>(o);
-                cb->clipboard->setDragImage(JSImage->image()->pixmap(), IntPoint(x,y));                
-                return jsUndefined();
-            } else {
+            if (!node)
                 return throwError(exec, TypeError);
-            }
+            
+            if (!node->isElementNode())
+                return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");
+
+            if (static_cast<ElementImpl*>(node)->hasLocalName(imgTag) && 
+                !node->inDocument())
+                cb->clipboard->setDragImage(static_cast<HTMLImageElementImpl*>(node)->pixmap(), IntPoint(x, y));
+            else
+                cb->clipboard->setDragImageElement(node, IntPoint(x, y));                    
+                
+            return jsUndefined();
         }
     }
     return jsUndefined();
index 05a3b9d..b07785c 100644 (file)
@@ -999,6 +999,7 @@ const HTMLElement::Accessors* HTMLElement::accessors() const
   align         KJS::HTMLElement::ImageAlign            DontDelete
   alt           KJS::HTMLElement::ImageAlt              DontDelete
   border        KJS::HTMLElement::ImageBorder           DontDelete
+  complete      KJS::HTMLElement::ImageComplete         DontDelete|ReadOnly
   height        KJS::HTMLElement::ImageHeight           DontDelete
   hspace        KJS::HTMLElement::ImageHspace           DontDelete
   isMap         KJS::HTMLElement::ImageIsMap            DontDelete
@@ -1883,6 +1884,7 @@ JSValue *HTMLElement::imageGetter(ExecState* exec, int token) const
         case ImageAlign:           return jsString(image.align());
         case ImageAlt:             return jsString(image.alt());
         case ImageBorder:          return jsNumber(image.border());
+        case ImageComplete:        return jsBoolean(image.complete());
         case ImageHeight:          return jsNumber(image.height(true));
         case ImageHspace:          return jsNumber(image.hspace());
         case ImageIsMap:           return jsBoolean(image.isMap());
@@ -3543,131 +3545,16 @@ JSObject *ImageConstructorImp::construct(ExecState * exec, const List & list)
         height = h->toInt32(exec);
     }
         
-    JSObject *result(new Image(m_doc.get(), widthSet, width, heightSet, height));
-  
-    /* TODO: do we need a prototype ? */
-    return result;
-}
-
-const ClassInfo KJS::Image::info = { "Image", 0, &ImageTable, 0 };
-
-/* Source for ImageTable. Use "make hashtables" to regenerate.
-@begin ImageTable 6
-  src           Image::Src              DontDelete
-  complete      Image::Complete         DontDelete|ReadOnly
-  onload        Image::OnLoad           DontDelete
-  width         Image::Width            DontDelete|ReadOnly
-  height        Image::Height           DontDelete|ReadOnly
-@end
-*/
-
-bool Image::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
-{
-  return getStaticValueSlot<Image,DOMObject>(exec, &ImageTable, this, propertyName, slot);
-}
-
-JSValue *Image::getValueProperty(ExecState *, int token) const
-{
-  switch (token) {
-  case Src:
-    return jsString(doc ? doc->completeURL(src.domString()) : src);
-  case Complete:
-    return jsBoolean(!img || img->status() >= khtml::CachedObject::Persistent);
-  case OnLoad:
-    if (onLoadListener && onLoadListener->listenerObj()) {
-      return onLoadListener->listenerObj();
-    } else {
-      return jsNull();
-    }
-  case Width: {
+    HTMLImageElementImpl *result = new HTMLImageElementImpl(m_doc.get());
+    
     if (widthSet)
-        return jsNumber(width);
-    int w = 0;
-    if (img) {
-      IntSize size = img->pixmap_size();
-      if (size.isValid())
-        w = size.width();
-    }
-    return jsNumber(w);
-  }
-  case Height: {
+        result->setWidth(width);
     if (heightSet)
-        return jsNumber(height);
-    int h = 0;
-    if (img) {
-      IntSize size = img->pixmap_size();
-      if (size.isValid())
-        h = size.height();
-    }
-    return jsNumber(h);
-  }
-  default:
-    kdWarning() << "Image::getValueProperty unhandled token " << token << endl;
-    return NULL;
-  }
-}
-
-void Image::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
-{
-  lookupPut<Image,DOMObject>(exec, propertyName, value, attr, &ImageTable, this );
-}
-
-void Image::putValueProperty(ExecState *exec, int token, JSValue *value, int /*attr*/)
-{
-  switch(token) {
-  case Src:
-  {
-    src = value->toString(exec);
-    if ( img ) img->deref(this);
-    img = doc ? doc->docLoader()->requestImage( src.domString() ) : 0;
-    if ( img ) img->ref(this);
-    break;
-  }
-  case OnLoad:
-    onLoadListener = Window::retrieveActive(exec)->getJSEventListener(value, true);
-    if (onLoadListener) onLoadListener->ref();
-    break;
-  case Width:
-    widthSet = true;
-    width = value->toInt32(exec);
-    break;
-  case Height:
-    heightSet = true;
-    height = value->toInt32(exec);
-    break;
-  default:
-    kdWarning() << "HTMLDocument::putValueProperty unhandled token " << token << endl;
-  }
-}
-
-void Image::notifyFinished(khtml::CachedObject *)
-{
-  if (onLoadListener && doc->frame()) {
-    int ignoreException;
-    EventImpl *ev = doc->createEvent("HTMLEvents", ignoreException);
-    ev->ref();
-    ev->initEvent(loadEvent, true, true);
-    onLoadListener->handleEventImpl(ev, true);
-    ev->deref();
-  }
-}
-
-Image::Image(DocumentImpl *d, bool ws, int w, bool hs, int h)
-  : doc(d), img(0), onLoadListener(0)
-{
-      widthSet = ws;
-      width = w;
-      heightSet = hs;
-      height = h;
-}
-
-Image::~Image()
-{
-  if ( img ) img->deref(this);
-  if ( onLoadListener ) onLoadListener->deref();
+        result->setHeight(height);
+    
+    return static_cast<JSObject*>(getDOMNode(exec, result));
 }
 
-
 ////////////////////// Context2D Object ////////////////////////
 
 KJS_IMPLEMENT_PROTOFUNC(Context2DFunction)
@@ -4198,21 +4085,8 @@ JSValue *KJS::Context2DFunction::callAsFunction(ExecState *exec, JSObject *thisO
             QPixmap pixmap;
             CGContextRef sourceContext = 0;
             
-            // Check for JavaScript Image, <img> or <canvas>.
-            if (o->inherits(&Image::info)) {
-                Image *i = static_cast<Image*>(o);
-                khtml::CachedImage *ci = i->image();
-                if (ci) {
-                    pixmap = ci->pixmap();
-                }
-                else {
-                    // No image.
-                    return jsUndefined();
-                }
-                w = pixmap.width();
-                h = pixmap.height();
-            }
-            else if (o->inherits(&KJS::HTMLElement::img_info)){
+            // Check for <img> or <canvas>.
+            if (o->inherits(&KJS::HTMLElement::img_info)){
                 NodeImpl *n = static_cast<HTMLElement *>(args[0])->impl();
                 HTMLImageElementImpl *e = static_cast<HTMLImageElementImpl*>(n);
                 pixmap = e->pixmap();
@@ -4312,9 +4186,12 @@ JSValue *KJS::Context2DFunction::callAsFunction(ExecState *exec, JSObject *thisO
             if (args.size() != 10)
                 return throwError(exec, SyntaxError);
             JSObject *o = static_cast<JSObject*>(args[0]);
-            if (!o->isObject() || !o->inherits(&Image::info))
+            if (!o->inherits(&KJS::HTMLElement::img_info))
                 return throwError(exec, TypeError);
-            Image *i = static_cast<Image*>(o);
+            NodeImpl *n = static_cast<HTMLElement *>(args[0])->impl();
+            HTMLImageElementImpl *e = static_cast<HTMLImageElementImpl*>(n);
+            
+            QPixmap pixmap = e->pixmap();
             float sx = args[1]->toNumber(exec);
             float sy = args[2]->toNumber(exec);
             float sw = args[3]->toNumber(exec);
@@ -4324,18 +4201,15 @@ JSValue *KJS::Context2DFunction::callAsFunction(ExecState *exec, JSObject *thisO
             float dw = args[7]->toNumber(exec);
             float dh = args[8]->toNumber(exec);
             QString compositeOperator = args[9]->toString(exec).qstring().lower();
-            khtml::CachedImage *ci = i->image();
-            if (ci) {
-                QPixmap pixmap = ci->pixmap();
-                QPainter p;
+            
+            QPainter p;
 
-                p.drawFloatPixmap (dx, dy, dw, dh, pixmap, sx, sy, sw, sh, QPainter::compositeOperatorFromString(compositeOperator), drawingContext);
+            p.drawFloatPixmap (dx, dy, dw, dh, pixmap, sx, sy, sw, sh, QPainter::compositeOperatorFromString(compositeOperator), drawingContext);
                 
-                if (contextObject->_needsFlushRasterCache)
-                    pixmap.flushRasterCache();
+            if (contextObject->_needsFlushRasterCache)
+                pixmap.flushRasterCache();
 
-                renderer->setNeedsImageUpdate();
-            }
+            renderer->setNeedsImageUpdate();
             break;
         }
         case Context2D::SetAlpha: {
@@ -4381,7 +4255,7 @@ JSValue *KJS::Context2DFunction::callAsFunction(ExecState *exec, JSObject *thisO
             if (args.size() != 2)
                 return throwError(exec, SyntaxError);
             JSObject *o = static_cast<JSObject*>(args[0]);
-            if (!o->isObject() || !o->inherits(&Image::info))
+            if (!o->inherits(&KJS::HTMLElement::img_info))
                 return throwError(exec, TypeError);
             int repetitionType = ImagePattern::Repeat;
             DOMString repetitionString = args[1]->toString(exec).domString().lower();
@@ -4391,7 +4265,8 @@ JSValue *KJS::Context2DFunction::callAsFunction(ExecState *exec, JSObject *thisO
                 repetitionType = ImagePattern::RepeatY;
             else if (repetitionString == "no-repeat")
                 repetitionType = ImagePattern::NoRepeat;
-            return new ImagePattern(static_cast<Image*>(o), repetitionType);
+            NodeImpl *n = static_cast<HTMLElement *>(args[0])->impl();
+            return new ImagePattern(static_cast<HTMLImageElementImpl *>(n)->pixmap(), repetitionType);
         }
     }
 #endif
@@ -5194,29 +5069,26 @@ static void drawPattern (void * info, CGContextRef context)
 CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
 #endif
 
-ImagePattern::ImagePattern(Image *i, int repetitionType)
+ImagePattern::ImagePattern(const QPixmap& pixmap, int repetitionType)
     :_rw(0), _rh(0)
 {
-    khtml::CachedImage *ci = i->image();
-    if (ci) {
-        _pixmap = ci->pixmap();
-        float w = _pixmap.width();
-        float h = _pixmap.height();
+    _pixmap = pixmap;
+    float w = _pixmap.width();
+    float h = _pixmap.height();
 #if __APPLE__
-        _bounds = CGRectMake (0, 0, w, h);
+    _bounds = CGRectMake (0, 0, w, h);
 #endif
-        if (repetitionType == Repeat) {
-            _rw = w; _rh = h;
-        }
-        else if (repetitionType == RepeatX) {
-            _rw = w; _rh = 0;
-        }
-        else if (repetitionType == RepeatY) {
-            _rw = 0; _rh = h;
-        }
-        else if (repetitionType == NoRepeat) {
-            _rw = 0; _rh = 0;
-        }
+    if (repetitionType == Repeat) {
+        _rw = w; _rh = h;
+    }
+    else if (repetitionType == RepeatX) {
+        _rw = w; _rh = 0;
+    }
+    else if (repetitionType == RepeatY) {
+        _rw = 0; _rh = h;
+    }
+    else if (repetitionType == NoRepeat) {
+        _rw = 0; _rh = 0;
     }
 }
 
index 9cb9c65..d81a7ce 100644 (file)
@@ -249,7 +249,7 @@ namespace KJS {
            AnchorPort, AnchorPathName, AnchorHash, AnchorSearch, AnchorName,
            AnchorRev, AnchorTabIndex, AnchorTarget, AnchorText, AnchorBlur, AnchorToString, 
            ImageName, ImageAlign, ImageHspace, ImageVspace, ImageUseMap, ImageAlt,
-           ImageLowSrc, ImageWidth, ImageIsMap, ImageBorder, ImageHeight,
+           ImageLowSrc, ImageWidth, ImageIsMap, ImageBorder, ImageHeight, ImageComplete,
            ImageLongDesc, ImageSrc, ImageX, ImageY, ObjectHspace, ObjectHeight, ObjectAlign,
            ObjectBorder, ObjectCode, ObjectType, ObjectVspace, ObjectArchive,
            ObjectDeclare, ObjectForm, ObjectCodeBase, ObjectCodeType, ObjectData,
@@ -363,33 +363,6 @@ namespace KJS {
     RefPtr<DOM::DocumentImpl> m_doc;
   };
 
-  class Image : public DOMObject, public khtml::CachedObjectClient {
-  public:
-    Image(DOM::DocumentImpl *d, bool ws, int w, bool hs, int h);
-    ~Image();
-    virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
-    JSValue *getValueProperty(ExecState *exec, int token) const;
-    virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
-    void putValueProperty(ExecState *exec, int token, JSValue *value, int /*attr*/);
-    void notifyFinished(khtml::CachedObject *);
-    virtual bool toBoolean(ExecState *) const { return true; }
-    virtual const ClassInfo* classInfo() const { return &info; }
-    static const ClassInfo info;
-    enum { Src, Complete, OnLoad, Width, Height };
-    
-    khtml::CachedImage* image() { return img; }
-    
-  private:
-    UString src;
-    QGuardedPtr<DOM::DocumentImpl> doc;
-    khtml::CachedImage* img;
-    JSAbstractEventListener *onLoadListener;
-    bool widthSet;
-    bool heightSet;
-    int width;
-    int height;
-  };
-
   ////////////////////// Context2D Object ////////////////////////
   class Context2D : public DOMObject {
   friend class Context2DFunction;
@@ -542,7 +515,7 @@ private:
 
   class ImagePattern : public DOMObject {
   public:
-    ImagePattern(Image *i, int type);
+    ImagePattern(const QPixmap& pixmap, int repetitionType);
     virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
     JSValue *getValueProperty(ExecState *exec, int token) const;
     virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
index d6a843f..12d2c29 100644 (file)
@@ -264,6 +264,10 @@ int HTMLImageElementImpl::width(bool ignorePendingStylesheets) const
         int width = getAttribute(widthAttr).qstring().toInt(&ok);
         if (ok)
             return width;
+        
+        // if the image has been loaded, use its width
+        if (m_imageLoader.imageComplete())
+            return m_imageLoader.image()->valid_rect().width();
     }
 
     if (DocumentImpl* doc = getDocument()) {
@@ -284,6 +288,10 @@ int HTMLImageElementImpl::height(bool ignorePendingStylesheets) const
         int height = getAttribute(heightAttr).qstring().toInt(&ok);
         if (ok)
             return height;
+        
+        // if the image has been loaded, use its height
+        if (m_imageLoader.imageComplete())
+            return m_imageLoader.image()->valid_rect().height();        
     }
 
     if (DocumentImpl* doc = getDocument()) {
@@ -434,6 +442,11 @@ int HTMLImageElementImpl::y() const
     return y;
 }
 
+bool HTMLImageElementImpl::complete() const
+{
+    return m_imageLoader.imageComplete();
+}
+
 // -------------------------------------------------------------------------
 
 HTMLMapElementImpl::HTMLMapElementImpl(DocumentImpl *doc)
index 5f5a04e..39aef70 100644 (file)
@@ -137,6 +137,8 @@ public:
     int x() const;
     int y() const;
 
+    bool complete() const;
+    
 protected:
     HTMLImageLoader m_imageLoader;
     DOMString usemap;
diff --git a/WebCore/manual-tests/drag-image.html b/WebCore/manual-tests/drag-image.html
new file mode 100644 (file)
index 0000000..580d5e5
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+        "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<script>
+function debug(str) {
+    var c = document.getElementById('console')
+    c.appendChild(document.createTextNode(str + '\n'));
+}
+
+var i = new Image()
+i.src ="resources/webkit-background.png";
+
+function dragStartHandler() {  
+    event.dataTransfer.setDragImage(i, 10, 10);
+}
+
+</script>
+</head>
+<body onload="runTests();">
+<p>This tests that setting the drag image works. If this is successful, the drag icon when dragging the text below around should look like the image below.</p>
+<img src="resources/webkit-background.png">
+<div ondragstart="dragStartHandler()" style="-khtml-user-select:none; -khtml-user-drag:element;">Try dragging me around!</div>
+<pre id="console">
+</pre>
+</body>
+</html>