#if ENABLE(SVG_FONTS)
#include "core/svg/SVGFontFaceElement.h"
-#include <math.h>
-#include "CSSPropertyNames.h"
-#include "CSSValueKeywords.h"
+#include "core/CSSPropertyNames.h"
+#include "core/CSSValueKeywords.h"
#include "core/css/CSSFontFaceSrcValue.h"
+#include "core/css/CSSFontSelector.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/CSSValueList.h"
#include "core/css/StylePropertySet.h"
#include "core/css/StyleRule.h"
#include "core/dom/Attribute.h"
#include "core/dom/Document.h"
+#include "core/dom/StyleEngine.h"
#include "core/svg/SVGDocumentExtensions.h"
#include "core/svg/SVGFontElement.h"
#include "core/svg/SVGFontFaceSrcElement.h"
#include "core/svg/SVGGlyphElement.h"
#include "platform/fonts/Font.h"
+#include <math.h>
-namespace WebCore {
+namespace blink {
using namespace SVGNames;
inline SVGFontFaceElement::SVGFontFaceElement(Document& document)
: SVGElement(font_faceTag, document)
, m_fontFaceRule(StyleRuleFontFace::create())
- , m_fontElement(0)
+ , m_fontElement(nullptr)
+ , m_weakFactory(this)
{
- ScriptWrappable::init(this);
- RefPtr<MutableStylePropertySet> styleDeclaration = MutableStylePropertySet::create(HTMLStandardMode);
+ RefPtrWillBeRawPtr<MutableStylePropertySet> styleDeclaration = MutableStylePropertySet::create(HTMLStandardMode);
m_fontFaceRule->setProperties(styleDeclaration.release());
}
-PassRefPtr<SVGFontFaceElement> SVGFontFaceElement::create(Document& document)
-{
- return adoptRef(new SVGFontFaceElement(document));
-}
+DEFINE_NODE_FACTORY(SVGFontFaceElement)
static CSSPropertyID cssPropertyIdForFontFaceAttributeName(const QualifiedName& attrName)
{
{
CSSPropertyID propId = cssPropertyIdForFontFaceAttributeName(name);
if (propId > 0) {
- m_fontFaceRule->mutableProperties()->setProperty(propId, value, false);
+ m_fontFaceRule->mutableProperties().setProperty(propId, value, false);
rebuildFontFace();
return;
}
String SVGFontFaceElement::fontFamily() const
{
- return m_fontFaceRule->properties()->getPropertyValue(CSSPropertyFontFamily);
+ return m_fontFaceRule->properties().getPropertyValue(CSSPropertyFontFamily);
}
SVGFontElement* SVGFontFaceElement::associatedFontElement() const
{
ASSERT(parentNode() == m_fontElement);
- ASSERT(!parentNode() || parentNode()->hasTagName(SVGNames::fontTag));
+ ASSERT(!parentNode() || isSVGFontElement(*parentNode()));
return m_fontElement;
}
return;
}
- bool describesParentFont = parentNode()->hasTagName(SVGNames::fontTag);
- RefPtr<CSSValueList> list;
+ bool describesParentFont = isSVGFontElement(*parentNode());
+ RefPtrWillBeRawPtr<CSSValueList> list = nullptr;
if (describesParentFont) {
m_fontElement = toSVGFontElement(parentNode());
list = CSSValueList::createCommaSeparated();
list->append(CSSFontFaceSrcValue::createLocal(fontFamily()));
} else {
- m_fontElement = 0;
+ m_fontElement = nullptr;
// we currently ignore all but the last src element, alternatively we could concat them
- for (Node* child = lastChild(); child && !list; child = child->previousSibling()) {
- if (child->hasTagName(font_face_srcTag)) {
- list = toSVGFontFaceSrcElement(child)->srcValue();
- break;
- }
- }
+ if (SVGFontFaceSrcElement* element = Traversal<SVGFontFaceSrcElement>::lastChild(*this))
+ list = element->srcValue();
}
if (!list || !list->length())
return;
// Parse in-memory CSS rules
- m_fontFaceRule->mutableProperties()->addParsedProperty(CSSProperty(CSSPropertySrc, list));
+ m_fontFaceRule->mutableProperties().addParsedProperty(CSSProperty(CSSPropertySrc, list));
if (describesParentFont) {
// Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves.
- RefPtr<CSSValue> src = m_fontFaceRule->properties()->getPropertyCSSValue(CSSPropertySrc);
+ RefPtrWillBeRawPtr<CSSValue> src = m_fontFaceRule->properties().getPropertyCSSValue(CSSPropertySrc);
CSSValueList* srcList = toCSSValueList(src.get());
unsigned srcLength = srcList ? srcList->length() : 0;
for (unsigned i = 0; i < srcLength; i++) {
- if (CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBoundsCheck(i)))
+ if (CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i)))
item->setSVGFontFaceElement(this);
}
}
- document().styleResolverChanged(RecalcStyleDeferred);
+ document().styleResolverChanged();
}
Node::InsertionNotificationRequest SVGFontFaceElement::insertedInto(ContainerNode* rootParent)
ASSERT(!m_fontElement);
return InsertionDone;
}
- document().accessSVGExtensions()->registerSVGFontFaceElement(this);
+ document().accessSVGExtensions().registerSVGFontFaceElement(this);
rebuildFontFace();
return InsertionDone;
SVGElement::removedFrom(rootParent);
if (rootParent->inDocument()) {
- m_fontElement = 0;
- document().accessSVGExtensions()->unregisterSVGFontFaceElement(this);
- m_fontFaceRule->mutableProperties()->clear();
-
- document().styleResolverChanged(RecalcStyleDeferred);
+ m_fontElement = nullptr;
+ document().accessSVGExtensions().unregisterSVGFontFaceElement(this);
+
+ // FIXME: HTMLTemplateElement's document or imported document can be active?
+ // If so, we also need to check whether fontSelector() is nullptr or not.
+ // Otherwise, we will use just document().isActive() here.
+ if (document().isActive() && document().styleEngine()->fontSelector()) {
+ document().styleEngine()->fontSelector()->fontFaceCache()->remove(m_fontFaceRule.get());
+ document().accessSVGExtensions().registerPendingSVGFontFaceElementsForRemoval(this);
+ }
+ m_fontFaceRule->mutableProperties().clear();
+ document().styleResolverChanged();
} else
ASSERT(!m_fontElement);
}
-void SVGFontFaceElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
+void SVGFontFaceElement::childrenChanged(const ChildrenChange& change)
{
- SVGElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
+ SVGElement::childrenChanged(change);
rebuildFontFace();
}
-} // namespace WebCore
+void SVGFontFaceElement::trace(Visitor* visitor)
+{
+ visitor->trace(m_fontFaceRule);
+ visitor->trace(m_fontElement);
+ SVGElement::trace(visitor);
+}
+
+} // namespace blink
#endif // ENABLE(SVG_FONTS)