OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. |
| 5 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 6 * |
| 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. |
| 11 * |
| 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. |
| 16 * |
| 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. |
| 21 */ |
| 22 |
| 23 #include "config.h" |
| 24 #if ENABLE(PICTURE) |
| 25 #include "HTMLPictureElement.h" |
| 26 |
| 27 #include "HTMLImageElement.h" |
| 28 |
| 29 #include "MediaList.h" |
| 30 #include "MediaQueryEvaluator.h" |
| 31 #include "StyleResolver.h" |
| 32 |
| 33 using namespace std; |
| 34 |
| 35 namespace WebCore { |
| 36 |
| 37 using namespace HTMLNames; |
| 38 |
| 39 PassRefPtr<HTMLPictureElement> HTMLPictureElement::create(Document* document) |
| 40 { |
| 41 return adoptRef(new HTMLPictureElement(imgTag, document)); |
| 42 } |
| 43 |
| 44 PassRefPtr<HTMLPictureElement> HTMLPictureElement::create(const QualifiedName& t
agName, Document* document) |
| 45 { |
| 46 return adoptRef(new HTMLPictureElement(tagName, document)); |
| 47 } |
| 48 |
| 49 HTMLPictureElement::~HTMLPictureElement() |
| 50 { |
| 51 } |
| 52 |
| 53 PassRefPtr<HTMLPictureElement> HTMLPictureElement::createForJSConstructor(Docume
nt* document, const int* optionalWidth, const int* optionalHeight) |
| 54 { |
| 55 RefPtr<HTMLPictureElement> picture = adoptRef(new HTMLPictureElement(imgTag,
document)); |
| 56 if (optionalWidth) |
| 57 picture->setWidth(*optionalWidth); |
| 58 if (optionalHeight) |
| 59 picture->setHeight(*optionalHeight); |
| 60 return picture.release(); |
| 61 } |
| 62 |
| 63 const Element* HTMLPictureElement::getMatchingSource() const |
| 64 { |
| 65 if (!m_hasSrc) { |
| 66 NodeVector potentialSourceNodes; |
| 67 getChildNodes(this, potentialSourceNodes); |
| 68 for (NodeVector::iterator it = potentialSourceNodes.begin(); |
| 69 it != potentialSourceNodes.end(); |
| 70 it++) { |
| 71 RefPtr<Node> nodePtr = *it; |
| 72 Node* node = nodePtr.get(); |
| 73 if (node && (node->hasTagName(sourceTag)) && (node->parentNode() ==
this)) { |
| 74 HTMLSourceElement* source = static_cast<HTMLSourceElement*>(node
); |
| 75 Document* document = documentInternal(); |
| 76 if (source->fastHasAttribute(srcAttr)) { |
| 77 if (!source->fastHasAttribute(mediaAttr)) |
| 78 return source; |
| 79 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createAl
lowingDescriptionSyntax(source->media()); |
| 80 RefPtr<RenderStyle> documentStyle = StyleResolver::styleForD
ocument(document, 0); |
| 81 MediaQueryEvaluator mediaQueryEvaluator("screen", document->
frame(), documentStyle.get()); |
| 82 if (mediaQueryEvaluator.eval(mediaQueries.get())) |
| 83 return source; |
| 84 } |
| 85 } |
| 86 } |
| 87 } |
| 88 return this; |
| 89 } |
| 90 |
| 91 void HTMLPictureElement::sourceWasAdded() |
| 92 { |
| 93 updateResources(); |
| 94 } |
| 95 |
| 96 void HTMLPictureElement::parseAttribute(const QualifiedName& name, const AtomicS
tring& value) |
| 97 { |
| 98 if (name == srcAttr) |
| 99 m_hasSrc = true; |
| 100 |
| 101 HTMLImageElement::parseAttribute(name, value); |
| 102 } |
| 103 |
| 104 } |
| 105 #endif |
OLD | NEW |