Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
html_event.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_HTML_HTML_EVENT_H_
20 #define PAGESPEED_KERNEL_HTML_HTML_EVENT_H_
21 
28 
29 namespace net_instaweb {
30 
31 class HtmlEvent {
32  public:
33  explicit HtmlEvent(int line_number) : line_number_(line_number) {
34  }
35  virtual ~HtmlEvent();
36  virtual void Run(HtmlFilter* filter) = 0;
37  virtual GoogleString ToString() const = 0;
38 
41  virtual HtmlElement* GetElementIfStartEvent() { return NULL; }
42 
45  virtual HtmlElement* GetElementIfEndEvent() { return NULL; }
46 
47  virtual HtmlLeafNode* GetLeafNode() { return NULL; }
48  virtual HtmlNode* GetNode() { return NULL; }
49  virtual HtmlCharactersNode* GetCharactersNode() { return NULL; }
50  void DebugPrint();
51 
52  int line_number() const { return line_number_; }
53 
54  private:
55  int line_number_;
56 
57 
58 };
59 
61  public:
62  explicit HtmlStartDocumentEvent(int line_number) : HtmlEvent(line_number) {}
63  virtual void Run(HtmlFilter* filter) { filter->StartDocument(); }
64  virtual GoogleString ToString() const { return "StartDocument"; }
65 
66  private:
67 
68 };
69 
71  public:
72  explicit HtmlEndDocumentEvent(int line_number) : HtmlEvent(line_number) {}
73  virtual void Run(HtmlFilter* filter) { filter->EndDocument(); }
74  virtual GoogleString ToString() const { return "EndDocument"; }
75 
76  private:
77 
78 };
79 
81  public:
82  HtmlStartElementEvent(HtmlElement* element, int line_number)
83  : HtmlEvent(line_number),
84  element_(element) {
85  }
86  virtual void Run(HtmlFilter* filter) { filter->StartElement(element_); }
87  virtual GoogleString ToString() const {
88  return StrCat("StartElement ", element_->ToString());
89  }
90  virtual HtmlElement* GetElementIfStartEvent() { return element_; }
91  virtual HtmlElement* GetNode() { return element_; }
92  private:
93  HtmlElement* element_;
94 
95 
96 };
97 
99  public:
100  HtmlEndElementEvent(HtmlElement* element, int line_number)
101  : HtmlEvent(line_number),
102  element_(element) {
103  }
104  virtual void Run(HtmlFilter* filter) { filter->EndElement(element_); }
105  virtual GoogleString ToString() const {
106  return StrCat("EndElement ", element_->ToString());
107  }
108  virtual HtmlElement* GetElementIfEndEvent() { return element_; }
109  virtual HtmlElement* GetNode() { return element_; }
110  private:
111  HtmlElement* element_;
112 
113 
114 };
115 
117  public:
118  explicit HtmlLeafNodeEvent(int line_number) : HtmlEvent(line_number) { }
119  virtual HtmlNode* GetNode() { return GetLeafNode(); }
120 
121  private:
122 
123 };
124 
126  public:
127  HtmlIEDirectiveEvent(HtmlIEDirectiveNode* directive, int line_number)
128  : HtmlLeafNodeEvent(line_number),
129  directive_(directive) {
130  }
131  virtual void Run(HtmlFilter* filter) { filter->IEDirective(directive_); }
132  virtual GoogleString ToString() const {
133  return StrCat("IEDirective ", directive_->contents());
134  }
135  virtual HtmlLeafNode* GetLeafNode() { return directive_; }
136  private:
137  HtmlIEDirectiveNode* directive_;
138 
139 
140 };
141 
143  public:
144  HtmlCdataEvent(HtmlCdataNode* cdata, int line_number)
145  : HtmlLeafNodeEvent(line_number),
146  cdata_(cdata) {
147  }
148  virtual void Run(HtmlFilter* filter) { filter->Cdata(cdata_); }
149  virtual GoogleString ToString() const {
150  return StrCat("Cdata ", cdata_->contents());
151  }
152  virtual HtmlLeafNode* GetLeafNode() { return cdata_; }
153  private:
154  HtmlCdataNode* cdata_;
155 
156 
157 };
158 
160  public:
161  HtmlCommentEvent(HtmlCommentNode* comment, int line_number)
162  : HtmlLeafNodeEvent(line_number),
163  comment_(comment) {
164  }
165  virtual void Run(HtmlFilter* filter) { filter->Comment(comment_); }
166  virtual GoogleString ToString() const {
167  return StrCat("Comment ", comment_->contents());
168  }
169  virtual HtmlLeafNode* GetLeafNode() { return comment_; }
170 
171  private:
172  HtmlCommentNode* comment_;
173 
174 
175 };
176 
178  public:
179  HtmlCharactersEvent(HtmlCharactersNode* characters, int line_number)
180  : HtmlLeafNodeEvent(line_number),
181  characters_(characters) {
182  }
183  virtual void Run(HtmlFilter* filter) { filter->Characters(characters_); }
184  virtual GoogleString ToString() const {
185  return StrCat("Characters ", characters_->contents());
186  }
187  virtual HtmlLeafNode* GetLeafNode() { return characters_; }
188  virtual HtmlCharactersNode* GetCharactersNode() { return characters_; }
189  private:
190  HtmlCharactersNode* characters_;
191 
192 
193 };
194 
196  public:
197  HtmlDirectiveEvent(HtmlDirectiveNode* directive, int line_number)
198  : HtmlLeafNodeEvent(line_number),
199  directive_(directive) {
200  }
201  virtual void Run(HtmlFilter* filter) { filter->Directive(directive_); }
202  virtual GoogleString ToString() const {
203  return StrCat("Directive: ", directive_->contents());
204  }
205  virtual HtmlLeafNode* GetLeafNode() { return directive_; }
206  private:
207  HtmlDirectiveNode* directive_;
208 
209 
210 };
211 
212 }
213 
214 #endif
Definition: html_node.h:103
Definition: html_filter.h:35
virtual void EndDocument()=0
Definition: html_event.h:177
Definition: html_event.h:116
Definition: html_event.h:31
virtual GoogleString ToString() const
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
virtual void StartElement(HtmlElement *element)=0
virtual void Directive(HtmlDirectiveNode *directive)=0
Called for HTML directives (e.g. <!doctype foobar>).
virtual HtmlElement * GetElementIfStartEvent()
Definition: html_event.h:90
Definition: html_event.h:98
Definition: html_element.h:42
virtual void IEDirective(HtmlIEDirectiveNode *directive)=0
Definition: html_event.h:195
Leaf node representing an HTML comment.
Definition: html_node.h:193
virtual HtmlElement * GetElementIfEndEvent()
Definition: html_event.h:45
virtual void Comment(HtmlCommentNode *comment)=0
Called for HTML comments that aren't IE directives (e.g. ).
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual void Cdata(HtmlCdataNode *cdata)=0
Called for CDATA blocks (e.g. <![CDATA[foobar]]>)
virtual HtmlElement * GetElementIfEndEvent()
Definition: html_event.h:108
Definition: html_event.h:80
Definition: html_node.h:43
virtual void Characters(HtmlCharactersNode *characters)=0
Called for raw characters between tags.
Definition: html_event.h:142
Leaf node representing an HTML directive.
Definition: html_node.h:233
Definition: html_event.h:125
virtual void StartDocument()=0
Definition: html_event.h:60
Leaf node representing a CDATA section.
Definition: html_node.h:147
Leaf node representing an HTML IE directive.
Definition: html_node.h:213
Definition: html_event.h:159
Definition: html_event.h:70
virtual HtmlElement * GetElementIfStartEvent()
Definition: html_event.h:41