Remove <picture> and <source>.

R=ojan@chromium.org

Review URL: https://codereview.chromium.org/706093002
This commit is contained in:
Elliott Sprehn 2014-11-06 15:03:37 -08:00
parent 9eb275c267
commit f79b479bc4
11 changed files with 17 additions and 462 deletions

View File

@ -757,13 +757,10 @@ sky_core_files = [
"html/HTMLImageLoader.h",
"html/HTMLImportElement.cpp",
"html/HTMLImportElement.h",
"html/HTMLPictureElement.cpp",
"html/HTMLScriptElement.cpp",
"html/HTMLScriptElement.h",
"html/HTMLShadowElement.cpp",
"html/HTMLShadowElement.h",
"html/HTMLSourceElement.cpp",
"html/HTMLSourceElement.h",
"html/HTMLStyleElement.cpp",
"html/HTMLStyleElement.h",
"html/HTMLTemplateElement.cpp",
@ -1229,10 +1226,8 @@ core_idl_files = get_path_info([
"html/HTMLElement.idl",
"html/HTMLImageElement.idl",
"html/HTMLImportElement.idl",
"html/HTMLPictureElement.idl",
"html/HTMLScriptElement.idl",
"html/HTMLShadowElement.idl",
"html/HTMLSourceElement.idl",
"html/HTMLStyleElement.idl",
"html/HTMLTemplateElement.idl",
"html/HTMLTitleElement.idl",

View File

@ -26,6 +26,7 @@
#include "core/CSSPropertyNames.h"
#include "core/HTMLNames.h"
#include "core/MediaTypeNames.h"
#include "core/css/MediaQueryListListener.h"
#include "core/css/MediaQueryMatcher.h"
#include "core/css/MediaValuesDynamic.h"
#include "core/css/parser/SizesAttributeParser.h"
@ -35,7 +36,6 @@
#include "core/frame/UseCounter.h"
#include "core/html/HTMLAnchorElement.h"
#include "core/html/HTMLCanvasElement.h"
#include "core/html/HTMLSourceElement.h"
#include "core/html/canvas/CanvasRenderingContext.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html/parser/HTMLSrcsetParser.h"
@ -183,52 +183,6 @@ const AtomicString& HTMLImageElement::altText() const
return getAttribute(HTMLNames::titleAttr);
}
static bool supportedImageType(const String& type)
{
return MIMETypeRegistry::isSupportedImagePrefixedMIMEType(type);
}
// http://picture.responsiveimages.org/#update-source-set
ImageCandidate HTMLImageElement::findBestFitImageFromPictureParent()
{
ASSERT(isMainThread());
Node* parent = parentNode();
if (!parent || !isHTMLPictureElement(*parent))
return ImageCandidate();
for (Node* child = parent->firstChild(); child; child = child->nextSibling()) {
if (child == this)
return ImageCandidate();
if (!isHTMLSourceElement(*child))
continue;
HTMLSourceElement* source = toHTMLSourceElement(child);
if (!source->getAttribute(HTMLNames::srcAttr).isNull())
UseCounter::countDeprecation(document(), UseCounter::PictureSourceSrc);
String srcset = source->getAttribute(HTMLNames::srcsetAttr);
if (srcset.isEmpty())
continue;
String type = source->getAttribute(HTMLNames::typeAttr);
if (!type.isEmpty() && !supportedImageType(type))
continue;
if (!source->mediaQueryMatches())
continue;
String sizes = source->getAttribute(HTMLNames::sizesAttr);
if (!sizes.isNull())
UseCounter::count(document(), UseCounter::Sizes);
SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynamic::create(document()), sizes);
unsigned effectiveSize = parser.length();
m_effectiveSizeViewportDependant = parser.viewportDependant();
ImageCandidate candidate = bestFitSourceForSrcsetAttribute(document().devicePixelRatio(), effectiveSize, source->getAttribute(HTMLNames::srcsetAttr));
if (candidate.isEmpty())
continue;
return candidate;
}
return ImageCandidate();
}
RenderObject* HTMLImageElement::createRenderer(RenderStyle* style)
{
RenderImage* image = new RenderImage(this);
@ -270,18 +224,9 @@ Node::InsertionNotificationRequest HTMLImageElement::insertedInto(ContainerNode*
if (m_listener)
document().mediaQueryMatcher().addViewportListener(m_listener.get());
bool imageWasModified = false;
if (RuntimeEnabledFeatures::pictureEnabled()) {
ImageCandidate candidate = findBestFitImageFromPictureParent();
if (!candidate.isEmpty()) {
setBestFitURLAndDPRFromImageCandidate(candidate);
imageWasModified = true;
}
}
// If we have been inserted from a renderer-less document,
// our loader may have not fetched the image, so do it now.
if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModified)
if ((insertionPoint->inDocument() && !imageLoader().image()))
imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_elementCreatedByParser ? ImageLoader::ForceLoadImmediately : ImageLoader::LoadNormally);
return HTMLElement::insertedInto(insertionPoint);
@ -501,30 +446,19 @@ FloatSize HTMLImageElement::defaultDestinationSize() const
void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior behavior)
{
bool foundURL = false;
if (RuntimeEnabledFeatures::pictureEnabled()) {
ImageCandidate candidate = findBestFitImageFromPictureParent();
if (!candidate.isEmpty()) {
setBestFitURLAndDPRFromImageCandidate(candidate);
foundURL = true;
}
}
if (!foundURL) {
unsigned effectiveSize = 0;
if (RuntimeEnabledFeatures::pictureSizesEnabled()) {
String sizes = getAttribute(HTMLNames::sizesAttr);
if (!sizes.isNull())
UseCounter::count(document(), UseCounter::Sizes);
SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynamic::create(document()), sizes);
effectiveSize = parser.length();
m_effectiveSizeViewportDependant = parser.viewportDependant();
}
ImageCandidate candidate = bestFitSourceForImageAttributes(
document().devicePixelRatio(), effectiveSize,
getAttribute(HTMLNames::srcAttr), getAttribute(HTMLNames::srcsetAttr));
setBestFitURLAndDPRFromImageCandidate(candidate);
unsigned effectiveSize = 0;
if (RuntimeEnabledFeatures::pictureSizesEnabled()) {
String sizes = getAttribute(HTMLNames::sizesAttr);
if (!sizes.isNull())
UseCounter::count(document(), UseCounter::Sizes);
SizesAttributeParser parser = SizesAttributeParser(MediaValuesDynamic::create(document()), sizes);
effectiveSize = parser.length();
m_effectiveSizeViewportDependant = parser.viewportDependant();
}
ImageCandidate candidate = bestFitSourceForImageAttributes(
document().devicePixelRatio(), effectiveSize,
getAttribute(HTMLNames::srcAttr), getAttribute(HTMLNames::srcsetAttr));
setBestFitURLAndDPRFromImageCandidate(candidate);
if (m_intrinsicSizingViewportDependant && m_effectiveSizeViewportDependant && !m_listener.get()) {
m_listener = ViewportChangeListener::create(this);
document().mediaQueryMatcher().addViewportListener(m_listener.get());

View File

@ -90,8 +90,6 @@ public:
virtual FloatSize defaultDestinationSize() const override;
virtual const KURL& sourceURL() const override;
// public so that HTMLPictureElement can call this as well.
void selectSourceURL(ImageLoader::UpdateFromElementBehavior);
protected:
explicit HTMLImageElement(Document&, bool createdByParser = false);
@ -100,6 +98,8 @@ protected:
private:
virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
void selectSourceURL(ImageLoader::UpdateFromElementBehavior);
virtual void attach(const AttachContext& = AttachContext()) override;
virtual RenderObject* createRenderer(RenderStyle*) override;
@ -111,7 +111,6 @@ private:
virtual void removedFrom(ContainerNode*) override;
virtual Image* imageContents() override;
ImageCandidate findBestFitImageFromPictureParent();
void setBestFitURLAndDPRFromImageCandidate(const ImageCandidate&);
HTMLImageLoader& imageLoader() const { return *m_imageLoader; }
void notifyViewportChanged();

View File

@ -1,37 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/html/HTMLPictureElement.h"
#include "core/HTMLNames.h"
#include "core/dom/ElementTraversal.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLImageElement.h"
#include "core/loader/ImageLoader.h"
namespace blink {
inline HTMLPictureElement::HTMLPictureElement(Document& document)
: HTMLElement(HTMLNames::pictureTag, document)
{
ScriptWrappable::init(this);
}
DEFINE_NODE_FACTORY(HTMLPictureElement)
void HTMLPictureElement::sourceOrMediaChanged()
{
for (HTMLImageElement* imageElement = Traversal<HTMLImageElement>::firstChild(*this); imageElement; imageElement = Traversal<HTMLImageElement>::nextSibling(*imageElement)) {
imageElement->selectSourceURL(ImageLoader::UpdateNormal);
}
}
Node::InsertionNotificationRequest HTMLPictureElement::insertedInto(ContainerNode* insertionPoint)
{
UseCounter::count(document(), UseCounter::Picture);
return HTMLElement::insertedInto(insertionPoint);
}
} // namespace

View File

@ -1,28 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef HTMLPictureElement_h
#define HTMLPictureElement_h
#include "core/html/HTMLElement.h"
namespace blink {
class HTMLPictureElement final : public HTMLElement {
DEFINE_WRAPPERTYPEINFO();
public:
DECLARE_NODE_FACTORY(HTMLPictureElement);
void sourceOrMediaChanged();
protected:
explicit HTMLPictureElement(Document&);
private:
virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
};
} // namespace blink
#endif // HTMLPictureElement_h

View File

@ -1,10 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// http://picture.responsiveimages.org
[
RuntimeEnabled=Picture
] interface HTMLPictureElement : HTMLElement {
};

View File

@ -1,184 +0,0 @@
/*
* Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "core/html/HTMLSourceElement.h"
#include "core/HTMLNames.h"
#include "core/css/MediaList.h"
#include "core/css/MediaQueryList.h"
#include "core/css/MediaQueryMatcher.h"
#include "core/dom/Document.h"
#include "core/events/Event.h"
#include "core/events/EventSender.h"
#include "core/html/HTMLPictureElement.h"
#include "platform/Logging.h"
namespace blink {
static SourceEventSender& sourceErrorEventSender()
{
DEFINE_STATIC_LOCAL(SourceEventSender, sharedErrorEventSender, (EventTypeNames::error));
return sharedErrorEventSender;
}
class HTMLSourceElement::Listener final : public MediaQueryListListener {
public:
explicit Listener(HTMLSourceElement* element) : m_element(element) { }
virtual void notifyMediaQueryChanged() override
{
if (m_element)
m_element->notifyMediaQueryChanged();
}
void clearElement() { m_element = nullptr; }
virtual void trace(Visitor* visitor) override
{
visitor->trace(m_element);
MediaQueryListListener::trace(visitor);
}
private:
RawPtr<HTMLSourceElement> m_element;
};
inline HTMLSourceElement::HTMLSourceElement(Document& document)
: HTMLElement(HTMLNames::sourceTag, document)
, m_listener(adoptRef(new Listener(this)))
{
WTF_LOG(Media, "HTMLSourceElement::HTMLSourceElement - %p", this);
ScriptWrappable::init(this);
}
DEFINE_NODE_FACTORY(HTMLSourceElement)
HTMLSourceElement::~HTMLSourceElement()
{
sourceErrorEventSender().cancelEvent(this);
#if !ENABLE(OILPAN)
m_listener->clearElement();
#endif
}
Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
Element* parent = parentElement();
if (isHTMLPictureElement(parent))
toHTMLPictureElement(parent)->sourceOrMediaChanged();
return InsertionDone;
}
void HTMLSourceElement::removedFrom(ContainerNode* removalRoot)
{
Element* parent = parentElement();
if (!parent && removalRoot->isElementNode())
parent = toElement(removalRoot);
if (isHTMLPictureElement(parent))
toHTMLPictureElement(parent)->sourceOrMediaChanged();
HTMLElement::removedFrom(removalRoot);
}
void HTMLSourceElement::setSrc(const String& url)
{
setAttribute(HTMLNames::srcAttr, AtomicString(url));
}
const AtomicString& HTMLSourceElement::type() const
{
return getAttribute(HTMLNames::typeAttr);
}
void HTMLSourceElement::setType(const AtomicString& type)
{
setAttribute(HTMLNames::typeAttr, type);
}
void HTMLSourceElement::scheduleErrorEvent()
{
WTF_LOG(Media, "HTMLSourceElement::scheduleErrorEvent - %p", this);
sourceErrorEventSender().dispatchEventSoon(this);
}
void HTMLSourceElement::cancelPendingErrorEvent()
{
WTF_LOG(Media, "HTMLSourceElement::cancelPendingErrorEvent - %p", this);
sourceErrorEventSender().cancelEvent(this);
}
void HTMLSourceElement::dispatchPendingEvent(SourceEventSender* eventSender)
{
ASSERT_UNUSED(eventSender, eventSender == &sourceErrorEventSender());
WTF_LOG(Media, "HTMLSourceElement::dispatchPendingEvent - %p", this);
dispatchEvent(Event::createCancelable(EventTypeNames::error));
}
bool HTMLSourceElement::mediaQueryMatches() const
{
if (!m_mediaQueryList)
return true;
return m_mediaQueryList->matches();
}
bool HTMLSourceElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == HTMLNames::srcAttr || HTMLElement::isURLAttribute(attribute);
}
void HTMLSourceElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
HTMLElement::parseAttribute(name, value);
if (name == HTMLNames::mediaAttr) {
if (m_mediaQueryList)
m_mediaQueryList->removeListener(m_listener);
RefPtr<MediaQuerySet> set = MediaQuerySet::create(value);
m_mediaQueryList = MediaQueryList::create(&document(), &document().mediaQueryMatcher(), set.release());
m_mediaQueryList->addListener(m_listener);
}
if (name == HTMLNames::srcsetAttr
|| name == HTMLNames::sizesAttr
|| name == HTMLNames::mediaAttr
|| name == HTMLNames::typeAttr) {
Element* parent = parentElement();
if (isHTMLPictureElement(parent))
toHTMLPictureElement(parent)->sourceOrMediaChanged();
}
}
void HTMLSourceElement::notifyMediaQueryChanged()
{
Element* parent = parentElement();
if (isHTMLPictureElement(parent))
toHTMLPictureElement(parent)->sourceOrMediaChanged();
}
void HTMLSourceElement::trace(Visitor* visitor)
{
visitor->trace(m_mediaQueryList);
visitor->trace(m_listener);
HTMLElement::trace(visitor);
}
}

View File

@ -1,75 +0,0 @@
/*
* Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HTMLSourceElement_h
#define HTMLSourceElement_h
#include "core/css/MediaQueryListListener.h"
#include "core/html/HTMLElement.h"
#include "platform/Timer.h"
namespace blink {
template<typename T> class EventSender;
typedef EventSender<HTMLSourceElement> SourceEventSender;
class HTMLSourceElement final : public HTMLElement {
DEFINE_WRAPPERTYPEINFO();
public:
class Listener;
DECLARE_NODE_FACTORY(HTMLSourceElement);
virtual ~HTMLSourceElement();
const AtomicString& type() const;
void setSrc(const String&);
void setType(const AtomicString&);
void scheduleErrorEvent();
void cancelPendingErrorEvent();
void dispatchPendingEvent(SourceEventSender*);
bool mediaQueryMatches() const;
virtual void trace(Visitor*) override;
private:
explicit HTMLSourceElement(Document&);
virtual InsertionNotificationRequest insertedInto(ContainerNode*) override;
virtual void removedFrom(ContainerNode*) override;
virtual bool isURLAttribute(const Attribute&) const override;
virtual void parseAttribute(const QualifiedName&, const AtomicString&) override;
void notifyMediaQueryChanged();
RefPtr<MediaQueryList> m_mediaQueryList;
RefPtr<Listener> m_listener;
};
} // namespace blink
#endif // HTMLSourceElement_h

View File

@ -1,37 +0,0 @@
/*
* Copyright (C) 2007, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
[
RuntimeEnabled=Media
] interface HTMLSourceElement : HTMLElement {
[Reflect, URL] attribute DOMString src;
attribute DOMString type;
[Reflect, RuntimeEnabled=Picture] attribute DOMString srcset;
[Reflect, RuntimeEnabled=Picture] attribute DOMString sizes;
[Reflect, RuntimeEnabled=Picture] attribute DOMString media;
[Reflect, RuntimeEnabled=SubresourceIntegrity] attribute DOMString integrity;
};

View File

@ -6,10 +6,8 @@ canvas
content interfaceName=HTMLContentElement
img interfaceName=HTMLImageElement, constructorNeedsCreatedByParser
import
picture interfaceName=HTMLPictureElement
script
shadow interfaceName=HTMLShadowElement
source
style constructorNeedsCreatedByParser
template
title

View File

@ -214,7 +214,7 @@ void ImageLoader::doUpdateFromElement(UpdateFromElementBehavior updateBehavior)
// Unlike raw <img>, we block mixed content inside of <picture> or <img srcset>.
ResourceLoaderOptions resourceLoaderOptions = ResourceFetcher::defaultResourceOptions();
ResourceRequest resourceRequest(url);
if (isHTMLPictureElement(element()->parentNode()) || !element()->getAttribute(HTMLNames::srcsetAttr).isNull())
if (!element()->getAttribute(HTMLNames::srcsetAttr).isNull())
resourceRequest.setRequestContext(WebURLRequest::RequestContextImageSet);
FetchRequest request(ResourceRequest(url), element()->localName(), resourceLoaderOptions);