[webkit-changes] cvs commit: WebCore/khtml/html html_imageimpl.cpp
html_imageimpl.h
Anders
andersca at opensource.apple.com
Sat Dec 3 12:26:02 PST 2005
andersca 05/12/03 12:26:02
Modified: khtml/ecma kjs_events.cpp kjs_html.cpp kjs_html.h
khtml/html html_imageimpl.cpp html_imageimpl.h
Log:
Didn't mean to commit this.
Revision Changes Path
1.73 +11 -12 WebCore/khtml/ecma/kjs_events.cpp
Index: kjs_events.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_events.cpp,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- kjs_events.cpp 3 Dec 2005 20:16:36 -0000 1.72
+++ kjs_events.cpp 3 Dec 2005 20:26:00 -0000 1.73
@@ -26,7 +26,6 @@
#include "kjs_window.h"
#include "kjs_views.h"
#include "kjs_proxy.h"
-#include "html/html_imageimpl.h"
#include "xml/dom_nodeimpl.h"
#include "xml/dom_docimpl.h"
#include "xml/dom2_eventsimpl.h"
@@ -43,11 +42,8 @@
using DOM::ClipboardEventImpl;
using DOM::DocumentImpl;
using DOM::DOMString;
-using DOM::ElementImpl;
using DOM::EventImpl;
using DOM::EventListenerEvent;
-using DOM::HTMLImageElementImpl;
-using DOM::HTMLNames::imgTag;
using DOM::KeyboardEventImpl;
using DOM::MouseEventImpl;
using DOM::UIEventImpl;
@@ -1250,19 +1246,22 @@
NodeImpl *node = toNode(args[0]);
if (node) {
if (node->isElementNode()) {
- if (static_cast<ElementImpl*>(node)->hasLocalName(imgTag) &&
- !node->inDocument()) {
- HTMLImageElementImpl *image = static_cast<HTMLImageElementImpl*>(node);
-
- cb->clipboard->setDragImage(image->pixmap(), QPoint(x, y));
- } else {
- cb->clipboard->setDragImageElement(node, QPoint(x,y));
- }
+ cb->clipboard->setDragImageElement(node, QPoint(x,y));
return Undefined();
} else {
return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");
}
}
+
+ // See if they passed us an Image object
+ ObjectImp *o = static_cast<ObjectImp*>(args[0]);
+ if (o->isObject() && o->inherits(&Image::info)) {
+ Image *JSImage = static_cast<Image*>(o);
+ cb->clipboard->setDragImage(JSImage->image()->pixmap(), QPoint(x,y));
+ return Undefined();
+ } else {
+ return throwError(exec, TypeError);
+ }
}
}
return Undefined();
1.151 +169 -35 WebCore/khtml/ecma/kjs_html.cpp
Index: kjs_html.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -r1.150 -r1.151
--- kjs_html.cpp 3 Dec 2005 20:16:36 -0000 1.150
+++ kjs_html.cpp 3 Dec 2005 20:26:00 -0000 1.151
@@ -1052,12 +1052,11 @@
focus KJS::HTMLElement::AnchorFocus DontDelete|Function 0
toString KJS::HTMLElement::AnchorToString DontDelete|Function 0
@end
- at begin HTMLImageElementTable 15
+ at begin HTMLImageElementTable 14
name KJS::HTMLElement::ImageName DontDelete
align KJS::HTMLElement::ImageAlign DontDelete
alt KJS::HTMLElement::ImageAlt DontDelete
border KJS::HTMLElement::ImageBorder DontDelete
- complete KJS::HTMLElement::ImageComplete DontDelete
height KJS::HTMLElement::ImageHeight DontDelete
hspace KJS::HTMLElement::ImageHspace DontDelete
isMap KJS::HTMLElement::ImageIsMap DontDelete
@@ -1947,7 +1946,6 @@
case ImageAlign: return String(image.align());
case ImageAlt: return String(image.alt());
case ImageBorder: return Number(image.border());
- case ImageComplete: return Boolean(image.complete());
case ImageHeight: return Number(image.height(true));
case ImageHspace: return Number(image.hspace());
case ImageIsMap: return Boolean(image.isMap());
@@ -3622,18 +3620,132 @@
ValueImp *h = list.at(1);
height = h->toInt32(exec);
}
+
+ ObjectImp *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.
+ at 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
+ at end
+*/
- HTMLImageElementImpl *image = new HTMLImageElementImpl(m_doc.get());
+bool Image::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<Image,DOMObject>(exec, &ImageTable, this, propertyName, slot);
+}
+ValueImp *Image::getValueProperty(ExecState *, int token) const
+{
+ switch (token) {
+ case Src:
+ return jsString(doc ? doc->completeURL(src.domString()) : src);
+ case Complete:
+ return Boolean(!img || img->status() >= khtml::CachedObject::Persistent);
+ case OnLoad:
+ if (onLoadListener && onLoadListener->listenerObjImp()) {
+ return onLoadListener->listenerObj();
+ } else {
+ return Null();
+ }
+ case Width: {
if (widthSet)
- image->setWidth(width);
-
+ return Number(width);
+ int w = 0;
+ if (img) {
+ QSize size = img->pixmap_size();
+ if (size.isValid())
+ w = size.width();
+ }
+ return Number(w);
+ }
+ case Height: {
if (heightSet)
- image->setHeight(height);
-
- return static_cast<ObjectImp*>(getDOMNode(exec, image));
+ return Number(height);
+ int h = 0;
+ if (img) {
+ QSize size = img->pixmap_size();
+ if (size.isValid())
+ h = size.height();
+ }
+ return Number(h);
+ }
+ default:
+ kdWarning() << "Image::getValueProperty unhandled token " << token << endl;
+ return NULL;
+ }
+}
+
+void Image::put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr)
+{
+ lookupPut<Image,DOMObject>(exec, propertyName, value, attr, &ImageTable, this );
+}
+
+void Image::putValueProperty(ExecState *exec, int token, ValueImp *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->part()) {
+ 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();
}
+
////////////////////// Context2D Object ////////////////////////
IMPLEMENT_PROTOFUNC(Context2DFunction)
@@ -4163,8 +4275,21 @@
QPixmap pixmap;
CGContextRef sourceContext = 0;
- // Check for img> or <canvas>.
- if (o->inherits(&KJS::HTMLElement::img_info)){
+ // 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 Undefined();
+ }
+ w = pixmap.width();
+ h = pixmap.height();
+ }
+ else if (o->inherits(&KJS::HTMLElement::img_info)){
NodeImpl *n = static_cast<HTMLElement *>(args[0])->impl();
HTMLImageElementImpl *e = static_cast<HTMLImageElementImpl*>(n);
pixmap = e->pixmap();
@@ -4264,9 +4389,9 @@
if (args.size() != 10)
return throwError(exec, SyntaxError);
ObjectImp *o = static_cast<ObjectImp*>(args[0]);
- if (!o->isObject(&HTMLElement::img_info))
+ if (!o->isObject() || !o->inherits(&Image::info))
return throwError(exec, TypeError);
- HTMLImageElementImpl *i = static_cast<HTMLImageElementImpl*>(static_cast<HTMLElement*>(o)->impl());
+ Image *i = static_cast<Image*>(o);
float sx = args[1]->toNumber(exec);
float sy = args[2]->toNumber(exec);
float sw = args[3]->toNumber(exec);
@@ -4276,15 +4401,18 @@
float dw = args[7]->toNumber(exec);
float dh = args[8]->toNumber(exec);
QString compositeOperator = args[9]->toString(exec).qstring().lower();
- QPixmap pixmap = i->pixmap();
- QPainter p;
+ khtml::CachedImage *ci = i->image();
+ if (ci) {
+ QPixmap pixmap = ci->pixmap();
+ 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: {
@@ -4330,7 +4458,7 @@
if (args.size() != 2)
return throwError(exec, SyntaxError);
ObjectImp *o = static_cast<ObjectImp*>(args[0]);
- if (!o->isObject() || !o->inherits(&HTMLElement::img_info))
+ if (!o->isObject() || !o->inherits(&Image::info))
return throwError(exec, TypeError);
int repetitionType = ImagePattern::Repeat;
QString repetitionString = args[1]->toString(exec).qstring().lower();
@@ -4340,7 +4468,7 @@
repetitionType = ImagePattern::RepeatY;
else if (repetitionString == "no-repeat")
repetitionType = ImagePattern::NoRepeat;
- return new ImagePattern(static_cast<HTMLImageElementImpl*>(static_cast<HTMLElement*>(o)->impl()), repetitionType);
+ return new ImagePattern(static_cast<Image*>(o), repetitionType);
}
}
@@ -5120,22 +5248,28 @@
}
CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
-ImagePattern::ImagePattern(HTMLImageElementImpl *i, int repetitionType)
+ImagePattern::ImagePattern(Image *i, int repetitionType)
:_rw(0), _rh(0)
{
- _pixmap = i->pixmap();
- float w = _pixmap.width();
- float h = _pixmap.height();
- _bounds = CGRectMake (0, 0, w, h);
-
- 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;
+ khtml::CachedImage *ci = i->image();
+ if (ci) {
+ _pixmap = ci->pixmap();
+ float w = _pixmap.width();
+ float h = _pixmap.height();
+ _bounds = CGRectMake (0, 0, w, h);
+
+ 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;
+ }
}
}
1.62 +29 -3 WebCore/khtml/ecma/kjs_html.h
Index: kjs_html.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_html.h,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- kjs_html.h 3 Dec 2005 20:16:37 -0000 1.61
+++ kjs_html.h 3 Dec 2005 20:26:00 -0000 1.62
@@ -33,7 +33,6 @@
class HTMLCollectionImpl;
class HTMLDocumentImpl;
class HTMLElementImpl;
- class HTMLImageElementImpl;
class HTMLSelectElementImpl;
class HTMLTableCaptionElementImpl;
class HTMLTableSectionElementImpl;
@@ -247,7 +246,7 @@
AnchorPort, AnchorPathName, AnchorHash, AnchorSearch, AnchorName,
AnchorRev, AnchorTabIndex, AnchorTarget, AnchorText, AnchorBlur, AnchorToString,
ImageName, ImageAlign, ImageHspace, ImageVspace, ImageUseMap, ImageAlt,
- ImageLowSrc, ImageWidth, ImageIsMap, ImageBorder, ImageComplete, ImageHeight,
+ ImageLowSrc, ImageWidth, ImageIsMap, ImageBorder, ImageHeight,
ImageLongDesc, ImageSrc, ImageX, ImageY, ObjectHspace, ObjectHeight, ObjectAlign,
ObjectBorder, ObjectCode, ObjectType, ObjectVspace, ObjectArchive,
ObjectDeclare, ObjectForm, ObjectCodeBase, ObjectCodeType, ObjectData,
@@ -353,6 +352,33 @@
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&);
+ ValueImp *getValueProperty(ExecState *exec, int token) const;
+ virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None);
+ void putValueProperty(ExecState *exec, int token, ValueImp *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 {
@@ -497,7 +523,7 @@
class ImagePattern : public DOMObject {
public:
- ImagePattern(DOM::HTMLImageElementImpl *i, int type);
+ ImagePattern(Image *i, int type);
virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
ValueImp *getValueProperty(ExecState *exec, int token) const;
virtual void put(ExecState *exec, const Identifier &propertyName, ValueImp *value, int attr = None);
1.59 +0 -15 WebCore/khtml/html/html_imageimpl.cpp
Index: html_imageimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_imageimpl.cpp,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- html_imageimpl.cpp 3 Dec 2005 20:16:39 -0000 1.58
+++ html_imageimpl.cpp 3 Dec 2005 20:26:01 -0000 1.59
@@ -280,10 +280,6 @@
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()) {
@@ -304,10 +300,6 @@
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()) {
@@ -458,13 +450,6 @@
return y;
}
-bool HTMLImageElementImpl::complete() const
-{
- CachedImage *img = m_imageLoader.image();
-
- return !img || img->status() >= khtml::CachedObject::Persistent;
-}
-
// -------------------------------------------------------------------------
HTMLMapElementImpl::HTMLMapElementImpl(DocumentImpl *doc)
1.31 +0 -2 WebCore/khtml/html/html_imageimpl.h
Index: html_imageimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_imageimpl.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- html_imageimpl.h 3 Dec 2005 20:16:39 -0000 1.30
+++ html_imageimpl.h 3 Dec 2005 20:26:01 -0000 1.31
@@ -140,8 +140,6 @@
int x() const;
int y() const;
- bool complete() const;
-
protected:
HTMLImageLoader m_imageLoader;
DOMString usemap;
More information about the webkit-changes
mailing list