Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / dom / Attribute.h
blobced213efa2c537a75e5c48353883f3760008305c
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
25 #ifndef Attribute_h
26 #define Attribute_h
28 #include "core/dom/QualifiedName.h"
29 #include "wtf/Allocator.h"
31 namespace blink {
33 // This is the internal representation of an attribute, consisting of a name and
34 // value. It is distinct from the web-exposed Attr, which also knows of the
35 // element to which it attached, if any.
36 class Attribute {
37 ALLOW_ONLY_INLINE_ALLOCATION();
38 public:
39 Attribute(const QualifiedName& name, const AtomicString& value)
40 : m_name(name)
41 , m_value(value)
45 // NOTE: The references returned by these functions are only valid for as long
46 // as the Attribute stays in place. For example, calling a function that mutates
47 // an Element's internal attribute storage may invalidate them.
48 const AtomicString& value() const { return m_value; }
49 const AtomicString& prefix() const { return m_name.prefix(); }
50 const AtomicString& localName() const { return m_name.localName(); }
51 const AtomicString& namespaceURI() const { return m_name.namespaceURI(); }
53 const QualifiedName& name() const { return m_name; }
55 bool isEmpty() const { return m_value.isEmpty(); }
56 bool matches(const QualifiedName&) const;
58 void setValue(const AtomicString& value) { m_value = value; }
60 // Note: This API is only for HTMLTreeBuilder. It is not safe to change the
61 // name of an attribute once parseAttribute has been called as DOM
62 // elements may have placed the Attribute in a hash by name.
63 void parserSetName(const QualifiedName& name) { m_name = name; }
65 #if COMPILER(MSVC)
66 // NOTE: This constructor is not actually implemented, it's just defined so MSVC
67 // will let us use a zero-length array of Attributes.
68 Attribute();
69 #endif
71 private:
72 QualifiedName m_name;
73 AtomicString m_value;
76 inline bool Attribute::matches(const QualifiedName& qualifiedName) const
78 if (qualifiedName.localName() != localName())
79 return false;
80 return qualifiedName.prefix() == starAtom || qualifiedName.namespaceURI() == namespaceURI();
83 } // namespace blink
85 #endif // Attribute_h