Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
net_instaweb::HtmlElement Class Reference

#include "html_element.h"

Inheritance diagram for net_instaweb::HtmlElement:
net_instaweb::HtmlNode

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< AttributeAttributeList
 
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 AttributeFindAttribute (HtmlName::Keyword keyword) const
 
AttributeFindAttribute (HtmlName::Keyword keyword)
 
const AttributeFindAttribute (StringPiece name) const
 
AttributeFindAttribute (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 HtmlNamename () const
 
void set_name (const HtmlName &new_tag)
 
const AttributeListattributes () const
 
AttributeListmutable_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
HtmlElementparent () 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
 

Detailed Description

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.

Member Enumeration Documentation

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.

Member Function Documentation

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.

Todo:
TODO(sligocki): StringPiece(NULL) seems fragile because what it is or how it's treated is not documented.

Doesn't check for attribute duplication (which is illegal in html).

The value, if non-null, is assumed to be unescaped. See also AddEscapedAttribute.

const char* net_instaweb::HtmlElement::AttributeValue ( HtmlName::Keyword  name) const
inline

Look up decoded attribute value by name. Returns NULL if:

  1. no attribute exists
  2. the attribute has no value.
  3. the attribute has a value, but it cannot currently be safely decoded. If you care about this distinction, call FindAttribute. Use this only if you don't intend to change the attribute value; if you might change the attribute value, use FindAttribute instead (this avoids a double lookup).
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.

const char* net_instaweb::HtmlElement::EscapedAttributeValue ( HtmlName::Keyword  name) const
inline

Look up escaped attribute value by name. Returns NULL if:

  1. no attribute exists
  2. the attribute has no value. If you care about this distinction, call FindAttribute. Use this only if you don't intend to change the attribute value; if you might change the attribute value, use FindAttribute instead (this avoids a double lookup).
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.

HtmlName::Keyword net_instaweb::HtmlElement::keyword ( ) const
inline

Returns the HTML keyword enum. If this tag name is not recognized, returns HtmlName::kNotAKeyword, and you can examine name_str().

virtual bool net_instaweb::HtmlElement::live ( ) const
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 void net_instaweb::HtmlElement::MarkAsDead ( const HtmlEventListIterator &  end)
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.

StringPiece net_instaweb::HtmlElement::name_str ( ) const
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.

void net_instaweb::HtmlElement::set_name ( const HtmlName new_tag)
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.

virtual void net_instaweb::HtmlElement::SynthesizeEvents ( const HtmlEventListIterator &  iter,
HtmlEventList *  queue 
)
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 GoogleString net_instaweb::HtmlElement::ToString ( ) const
virtual

Render an element as a string for debugging. This is not intended as a fully legal serialization.

Implements net_instaweb::HtmlNode.


The documentation for this class was generated from the following file: