TEST_F(ImageBitmapTest, ImageResourceConsistency) { const ImageBitmapOptions defaultOptions; HTMLImageElement* imageElement = HTMLImageElement::create(*Document::create()); ImageResource* image = ImageResource::create(StaticBitmapImage::create(m_image).get()); imageElement->setImageResource(image); ImageBitmap* imageBitmapNoCrop = ImageBitmap::create(imageElement, IntRect(0, 0, m_image->width(), m_image->height()), &(imageElement->document()), defaultOptions); ImageBitmap* imageBitmapInteriorCrop = ImageBitmap::create(imageElement, IntRect(m_image->width() / 2, m_image->height() / 2, m_image->width() / 2, m_image->height() / 2), &(imageElement->document()), defaultOptions); ImageBitmap* imageBitmapExteriorCrop = ImageBitmap::create(imageElement, IntRect(-m_image->width() / 2, -m_image->height() / 2, m_image->width(), m_image->height()), &(imageElement->document()), defaultOptions); ImageBitmap* imageBitmapOutsideCrop = ImageBitmap::create(imageElement, IntRect(-m_image->width(), -m_image->height(), m_image->width(), m_image->height()), &(imageElement->document()), defaultOptions); ASSERT_EQ(imageBitmapNoCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame()); ASSERT_NE(imageBitmapInteriorCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame()); ASSERT_NE(imageBitmapExteriorCrop->bitmapImage()->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame()); StaticBitmapImage* emptyImage = imageBitmapOutsideCrop->bitmapImage(); ASSERT_NE(emptyImage->imageForCurrentFrame(), imageElement->cachedImage()->getImage()->imageForCurrentFrame()); }
void PageSerializer::serializeFrame(Frame* frame) { Document* document = frame->document(); URL url = document->url(); if (!url.isValid() || url.isBlankURL()) { // For blank frames we generate a fake URL so they can be referenced by their containing frame. url = urlForBlankFrame(frame); } if (m_resourceURLs.contains(url)) { // FIXME: We could have 2 frame with the same URL but which were dynamically changed and have now // different content. So we should serialize both and somehow rename the frame src in the containing // frame. Arg! return; } Vector<Node*> nodes; SerializerMarkupAccumulator accumulator(*this, *document, &nodes); TextEncoding textEncoding(document->charset()); CString data; if (!textEncoding.isValid()) { // FIXME: iframes used as images trigger this. We should deal with them correctly. return; } String text = accumulator.serializeNodes(*document->documentElement(), 0, IncludeNode); CString frameHTML = textEncoding.encode(text, EntitiesForUnencodables); m_resources->append(Resource(url, document->suggestedMIMEType(), SharedBuffer::create(frameHTML.data(), frameHTML.length()))); m_resourceURLs.add(url); for (Vector<Node*>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) { Node* node = *iter; if (!node->isElementNode()) continue; Element* element = toElement(node); // We have to process in-line style as it might contain some resources (typically background images). if (element->isStyledElement()) retrieveResourcesForProperties(toStyledElement(element)->inlineStyle(), document); if (isHTMLImageElement(element)) { HTMLImageElement* imageElement = toHTMLImageElement(element); URL url = document->completeURL(imageElement->getAttribute(HTMLNames::srcAttr)); CachedImage* cachedImage = imageElement->cachedImage(); addImageToResources(cachedImage, imageElement->renderer(), url); } else if (element->hasTagName(HTMLNames::linkTag)) { HTMLLinkElement* linkElement = toHTMLLinkElement(element); if (CSSStyleSheet* sheet = linkElement->sheet()) { URL url = document->completeURL(linkElement->getAttribute(HTMLNames::hrefAttr)); serializeCSSStyleSheet(sheet, url); ASSERT(m_resourceURLs.contains(url)); } } else if (isHTMLStyleElement(element)) { if (CSSStyleSheet* sheet = toHTMLStyleElement(element)->sheet()) serializeCSSStyleSheet(sheet, URL()); } } for (Frame* childFrame = frame->tree().firstChild(); childFrame; childFrame = childFrame->tree().nextSibling()) serializeFrame(childFrame); }
QVariant QtPixmapInstance::variantFromObject(JSObject* object, QMetaType::Type hint) { if (!object) goto returnEmptyVariant; if (object->inherits(&JSHTMLImageElement::s_info)) { JSHTMLImageElement* elementJSWrapper = static_cast<JSHTMLImageElement*>(object); HTMLImageElement* imageElement = static_cast<HTMLImageElement*>(elementJSWrapper->impl()); if (!imageElement) goto returnEmptyVariant; CachedImage* cachedImage = imageElement->cachedImage(); if (!cachedImage) goto returnEmptyVariant; Image* image = cachedImage->image(); if (!image) goto returnEmptyVariant; QPixmap* pixmap = image->nativeImageForCurrentFrame(); if (!pixmap) goto returnEmptyVariant; return (hint == static_cast<QMetaType::Type>(qMetaTypeId<QPixmap>())) ? QVariant::fromValue<QPixmap>(*pixmap) : QVariant::fromValue<QImage>(pixmap->toImage()); } if (object->inherits(&QtPixmapRuntimeObject::s_info)) { QtPixmapRuntimeObject* runtimeObject = static_cast<QtPixmapRuntimeObject*>(object); QtPixmapInstance* instance = static_cast<QtPixmapInstance*>(runtimeObject->getInternalInstance()); if (!instance) goto returnEmptyVariant; if (hint == qMetaTypeId<QPixmap>()) return QVariant::fromValue<QPixmap>(instance->toPixmap()); if (hint == qMetaTypeId<QImage>()) return QVariant::fromValue<QImage>(instance->toImage()); } returnEmptyVariant: if (hint == qMetaTypeId<QPixmap>()) return QVariant::fromValue<QPixmap>(QPixmap()); if (hint == qMetaTypeId<QImage>()) return QVariant::fromValue<QImage>(QImage()); return QVariant(); }
QVariant QtPixmapRuntime::toQt(JSContextRef context, JSObjectRef obj, QMetaType::Type hint, JSValueRef* exception) { if (!obj) return emptyVariantForHint(hint); if (JSValueIsObjectOfClass(context, obj, QtPixmapRuntime::getClassRef())) { QVariant* originalVariant = static_cast<QVariant*>(JSObjectGetPrivate(obj)); if (hint == qMetaTypeId<QPixmap>()) return QVariant::fromValue<QPixmap>(toPixmap(*originalVariant)); if (hint == qMetaTypeId<QImage>()) return QVariant::fromValue<QImage>(toImage(*originalVariant)); } JSObject* jsObject = ::toJS(obj); if (!jsObject->inherits(&JSHTMLImageElement::s_info)) return emptyVariantForHint(hint); JSHTMLImageElement* elementJSWrapper = static_cast<JSHTMLImageElement*>(jsObject); HTMLImageElement* imageElement = static_cast<HTMLImageElement*>(elementJSWrapper->impl()); if (!imageElement) return emptyVariantForHint(hint); CachedImage* cachedImage = imageElement->cachedImage(); if (!cachedImage) return emptyVariantForHint(hint); Image* image = cachedImage->imageForRenderer(imageElement->renderer()); if (!image) return emptyVariantForHint(hint); QImage* nativeImage = image->nativeImageForCurrentFrame(); if (!nativeImage) return emptyVariantForHint(hint); return (hint == static_cast<QMetaType::Type>(qMetaTypeId<QPixmap>())) ? QVariant::fromValue<QPixmap>(QPixmap::fromImage(*nativeImage)) : QVariant::fromValue<QImage>(*nativeImage); }