net_instaweb::HtmlElement Class Reference

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

List of all members.

Classes

class  Attribute
struct  Data

Public Types

enum  CloseStyle {
  AUTO_CLOSE, IMPLICIT_CLOSE, EXPLICIT_CLOSE, BRIEF_CLOSE,
  UNCLOSED
}
enum  QuoteStyle { NO_QUOTE, SINGLE_QUOTE, DOUBLE_QUOTE }
 

Various ways things can be quoted (or not).


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.
void DeleteAttribute (int i)
bool DeleteAttribute (HtmlName::Keyword keyword)
const AttributeFindAttribute (HtmlName::Keyword keyword) const
AttributeFindAttribute (HtmlName::Keyword keyword)
const char * AttributeValue (HtmlName::Keyword name) const
const char * name_str () const
HtmlName::Keyword keyword () const
const HtmlNamename () const
void set_name (const HtmlName &new_tag)
int attribute_size () const
const Attributeattribute (int i) const
Attributeattribute (int i)
CloseStyle close_style () const
void set_close_style (CloseStyle style)
void ToString (GoogleString *buf) const
void DebugPrint () const
int begin_line_number () const
int end_line_number () const

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.

Friends

class HtmlParse
class HtmlLexer

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.


Member Function Documentation

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 docutmented.

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

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

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.

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

Look up 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.

void net_instaweb::HtmlElement::DeleteAttribute ( int  i  ) 

Removes the attribute at the given index, shifting higher-indexed attributes down. Note that this operation is linear in the number of attributes.

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 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.

const char* 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 
) [protected, virtual]

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.

void net_instaweb::HtmlElement::ToString ( GoogleString buf  )  const

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


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Tue May 29 16:33:49 2012 for Page Speed Optimization Libraries by  doxygen 1.6.3