Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org>
      3  * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) kde.org>
      4  * Copyright (C) 2008 Apple Inc. All rights reserved.
      5  * Copyright (C) 2011 Torch Mobile (Beijing) Co. Ltd. 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 
     25 #if ENABLE(SVG_FONTS)
     26 #include "core/svg/SVGAltGlyphElement.h"
     27 
     28 #include "SVGNames.h"
     29 #include "XLinkNames.h"
     30 #include "bindings/v8/ExceptionState.h"
     31 #include "core/dom/ExceptionCode.h"
     32 #include "core/dom/NodeRenderingContext.h"
     33 #include "core/rendering/svg/RenderSVGTSpan.h"
     34 #include "core/svg/SVGAltGlyphDefElement.h"
     35 
     36 namespace WebCore {
     37 
     38 // Animated property definitions
     39 DEFINE_ANIMATED_STRING(SVGAltGlyphElement, XLinkNames::hrefAttr, Href, href)
     40 
     41 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGAltGlyphElement)
     42     REGISTER_LOCAL_ANIMATED_PROPERTY(href)
     43     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTextPositioningElement)
     44 END_REGISTER_ANIMATED_PROPERTIES
     45 
     46 inline SVGAltGlyphElement::SVGAltGlyphElement(const QualifiedName& tagName, Document* document)
     47     : SVGTextPositioningElement(tagName, document)
     48 {
     49     ASSERT(hasTagName(SVGNames::altGlyphTag));
     50     ScriptWrappable::init(this);
     51     registerAnimatedPropertiesForSVGAltGlyphElement();
     52 }
     53 
     54 PassRefPtr<SVGAltGlyphElement> SVGAltGlyphElement::create(const QualifiedName& tagName, Document* document)
     55 {
     56     return adoptRef(new SVGAltGlyphElement(tagName, document));
     57 }
     58 
     59 void SVGAltGlyphElement::setGlyphRef(const AtomicString&, ExceptionState& es)
     60 {
     61     es.throwDOMException(NoModificationAllowedError);
     62 }
     63 
     64 const AtomicString& SVGAltGlyphElement::glyphRef() const
     65 {
     66     return fastGetAttribute(SVGNames::glyphRefAttr);
     67 }
     68 
     69 void SVGAltGlyphElement::setFormat(const AtomicString&, ExceptionState& es)
     70 {
     71     es.throwDOMException(NoModificationAllowedError);
     72 }
     73 
     74 const AtomicString& SVGAltGlyphElement::format() const
     75 {
     76     return fastGetAttribute(SVGNames::formatAttr);
     77 }
     78 
     79 bool SVGAltGlyphElement::childShouldCreateRenderer(const NodeRenderingContext& childContext) const
     80 {
     81     if (childContext.node()->isTextNode())
     82         return true;
     83     return false;
     84 }
     85 
     86 RenderObject* SVGAltGlyphElement::createRenderer(RenderStyle*)
     87 {
     88     return new RenderSVGTSpan(this);
     89 }
     90 
     91 bool SVGAltGlyphElement::hasValidGlyphElements(Vector<String>& glyphNames) const
     92 {
     93     String target;
     94     Element* element = targetElementFromIRIString(getAttribute(XLinkNames::hrefAttr), document(), &target);
     95     if (!element)
     96         return false;
     97 
     98     if (element->hasTagName(SVGNames::glyphTag)) {
     99         glyphNames.append(target);
    100         return true;
    101     }
    102 
    103     if (element->hasTagName(SVGNames::altGlyphDefTag)
    104         && static_cast<SVGAltGlyphDefElement*>(element)->hasValidGlyphElements(glyphNames))
    105         return true;
    106 
    107     return false;
    108 }
    109 
    110 }
    111 
    112 #endif
    113