Page Speed Optimization Libraries
1.13.35.1
|
#include "html_element.h"
Classes | |
class | Attribute |
Public Types | |
enum | Style { AUTO_CLOSE, IMPLICIT_CLOSE, EXPLICIT_CLOSE, BRIEF_CLOSE, UNCLOSED, INVISIBLE } |
enum | QuoteStyle { NO_QUOTE, SINGLE_QUOTE, DOUBLE_QUOTE } |
Various ways things can be quoted (or not) | |
typedef InlineSList< Attribute > | AttributeList |
typedef InlineSList< Attribute > ::Iterator | AttributeIterator |
typedef InlineSList< Attribute > ::ConstIterator | AttributeConstIterator |
Public Member Functions | |
virtual bool | live () const |
virtual void | MarkAsDead (const HtmlEventListIterator &end) |
void | AddAttribute (const Attribute &attr) |
void | AddAttribute (const HtmlName &name, const StringPiece &decoded_value, QuoteStyle quote_style) |
void | AddEscapedAttribute (const HtmlName &name, const StringPiece &escaped_value, QuoteStyle quote_style) |
As AddAttribute, but assumes value has been escaped for html output. | |
bool | DeleteAttribute (HtmlName::Keyword keyword) |
bool | DeleteAttribute (StringPiece name) |
const Attribute * | FindAttribute (HtmlName::Keyword keyword) const |
Attribute * | FindAttribute (HtmlName::Keyword keyword) |
const Attribute * | FindAttribute (StringPiece name) const |
Attribute * | FindAttribute (StringPiece name) |
bool | HasAttribute (HtmlName::Keyword keyword) const |
const char * | AttributeValue (HtmlName::Keyword name) const |
const char * | EscapedAttributeValue (HtmlName::Keyword name) const |
StringPiece | name_str () const |
HtmlName::Keyword | keyword () const |
const HtmlName & | name () const |
void | set_name (const HtmlName &new_tag) |
const AttributeList & | attributes () const |
AttributeList * | mutable_attributes () |
Style | style () const |
void | set_style (Style style) |
virtual GoogleString | ToString () const |
void | DebugPrint () const |
int | begin_line_number () const |
int | end_line_number () const |
Public Member Functions inherited from net_instaweb::HtmlNode | |
HtmlElement * | parent () const |
void * | operator new (size_t size, Arena< HtmlNode > *arena) |
void | operator delete (void *ptr, Arena< HtmlNode > *arena) |
Protected Member Functions | |
virtual void | SynthesizeEvents (const HtmlEventListIterator &iter, HtmlEventList *queue) |
virtual HtmlEventListIterator | begin () const |
Return an iterator pointing to the first event associated with this node. | |
virtual HtmlEventListIterator | end () const |
Return an iterator pointing to the last event associated with this node. | |
Protected Member Functions inherited from net_instaweb::HtmlNode | |
HtmlNode (HtmlElement *parent) | |
void | operator delete (void *ptr) |
Version that affects visibility of the destructor. | |
Friends | |
class | HtmlParse |
class | HtmlLexer |
Represents an HTML tag, including all its attributes. These are never constructed independently, but are managed by class HtmlParse. They are constructed when parsing an HTML document, and they can also be synthesized via methods in HtmlParse::NewElement.
Note that HtmlElement* saved during filter execution are valid only until a Flush occurs. HtmlElement* can still be fully accessed during a Flush, but after that, to save memory, the contents of the HtmlElement* are cleared. After that, the only method it's legal to do is to call is HtmlParse::IsRewriteable(), which will return false.
Tags can be closed in three ways: implicitly (e.g. <img ..>), briefly (e.g.
), or explicitly (<a...>...). The Lexer will always record the way it parsed a tag, but synthesized elements will have AUTO_CLOSE, and rewritten elements may no longer qualify for the closing style with which they were parsed.
Enumerator | |
---|---|
AUTO_CLOSE |
synthesized tag, or not yet closed in source |
IMPLICIT_CLOSE |
E.g. <img...> <meta...> <link...> <br...> <input...> |
EXPLICIT_CLOSE |
E.g. anchor |
BRIEF_CLOSE |
E.g. <head> |
UNCLOSED |
Was never closed in source, so don't serialize close-tag. |
INVISIBLE |
Programatically hidden element. |
void net_instaweb::HtmlElement::AddAttribute | ( | const Attribute & | attr | ) |
Add a copy of an attribute to this element. The attribute may come from this element, or another one.
void net_instaweb::HtmlElement::AddAttribute | ( | const HtmlName & | name, |
const StringPiece & | decoded_value, | ||
QuoteStyle | quote_style | ||
) |
Unconditionally add attribute, copying value. For binary attributes (those without values) use value=NULL.
Doesn't check for attribute duplication (which is illegal in html).
The value, if non-null, is assumed to be unescaped. See also AddEscapedAttribute.
|
inline |
Look up decoded attribute value by name. Returns NULL if:
bool net_instaweb::HtmlElement::DeleteAttribute | ( | HtmlName::Keyword | keyword | ) |
Remove the attribute with the given name. Return true if the attribute was deleted, false if it wasn't there to begin with.
|
inline |
Look up escaped attribute value by name. Returns NULL if:
const Attribute* net_instaweb::HtmlElement::FindAttribute | ( | HtmlName::Keyword | keyword | ) | const |
Look up attribute by name. NULL if no attribute exists. Use this for attributes whose value you might want to change after lookup.
|
inline |
Returns the HTML keyword enum. If this tag name is not recognized, returns HtmlName::kNotAKeyword, and you can examine name_str().
|
inlinevirtual |
Determines whether this node is still accessible via API. Note that when a FLUSH occurs after an open-element, the element will be live() but will not be rewritable. Specifically, node->live() can be true when html_parse->IsRewritable(node) is false. Once a node is closed, a FLUSH will cause the node's data to be freed, which triggers this method returning false.
Implements net_instaweb::HtmlNode.
|
virtual |
Marks a node as dead. The queue's end iterator should be passed in, to remove references to stale iterators, and to force IsRewritable to return false.
Implements net_instaweb::HtmlNode.
|
inline |
Returns the element tag name, which is not guaranteed to be case-folded. Compare keyword() to the Keyword constant found in html_name.h for fast tag name comparisons.
|
inline |
Changing that tag of an element should only occur if the caller knows that the old attributes make sense for the new tag. E.g. a div could be changed to a span.
|
protectedvirtual |
Create new event object(s) representing this node, and insert them into the queue just before the given iterator; also, update this node object as necessary so that begin() and end() will return iterators pointing to the new event(s). The line number for each event should probably be -1.
Implements net_instaweb::HtmlNode.
|
virtual |
Render an element as a string for debugging. This is not intended as a fully legal serialization.
Implements net_instaweb::HtmlNode.