Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
split_html_config.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 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 NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_CONFIG_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_SPLIT_HTML_CONFIG_H_
21 
22 #include <map>
23 #include <vector>
24 
27 
28 namespace net_instaweb {
29 
30 class CriticalLineInfo;
31 class HtmlElement;
32 class Panel;
33 class RewriteDriver;
34 
35 struct XpathUnit {
36  XpathUnit() : child_number(0) {}
37 
38  GoogleString tag_name;
39  GoogleString attribute_value;
40  int child_number;
41 };
42 
43 typedef std::map<GoogleString, const Panel*> PanelIdToSpecMap;
44 typedef std::vector<XpathUnit> XpathUnits;
46 typedef std::map<GoogleString, XpathUnits*> XpathMap;
47 
51  public:
55  explicit SplitHtmlConfig(RewriteDriver* driver);
56  ~SplitHtmlConfig();
57 
59  static void Initialize();
60  static void Terminate();
61 
62  const CriticalLineInfo* critical_line_info() const {
63  return critical_line_info_;
64  }
65 
66  const XpathMap* xpath_map() const {
67  return &xpath_map_;
68  }
69 
70  const PanelIdToSpecMap* panel_id_to_spec() const {
71  return &panel_id_to_spec_;
72  }
73 
74  const RewriteDriver* driver() const { return driver_; }
75 
76  private:
78  RewriteDriver* driver_;
79 
80  const CriticalLineInfo* critical_line_info_;
81 
83  XpathMap xpath_map_;
84 
86  PanelIdToSpecMap panel_id_to_spec_;
87 
88  DISALLOW_COPY_AND_ASSIGN(SplitHtmlConfig);
89 };
90 
93  public:
94  explicit SplitHtmlState(const SplitHtmlConfig* config);
95  ~SplitHtmlState();
96 
97  std::vector<int>* num_children_stack() { return &num_children_stack_; }
98 
99  bool ElementMatchesXpath(
100  const HtmlElement* element,
101  const std::vector<XpathUnit>& xpath_units) const;
102 
104  GoogleString MatchPanelIdForElement(HtmlElement* element) const;
105 
108  bool IsElementSiblingOfCurrentPanel(HtmlElement* element) const;
109 
111  bool IsElementParentOfCurrentPanel(HtmlElement* element) const;
112 
115  bool IsEndMarkerForCurrentPanel(HtmlElement* element) const;
116 
117  const HtmlElement* current_panel_parent_element() const {
118  return current_panel_parent_element_;
119  }
120 
121  void set_current_panel_parent_element(HtmlElement* element) {
122  current_panel_parent_element_ = element;
123  }
124 
125  const GoogleString& current_panel_id() const {
126  return current_panel_id_;
127  }
128 
129  void set_current_panel_id(const GoogleString& panel_id) {
130  current_panel_id_ = panel_id;
131  }
132 
133  void UpdateNumChildrenStack(const HtmlElement* element);
134 
135  private:
137  const SplitHtmlConfig* config_;
138 
140  std::vector<int> num_children_stack_;
141 
143  HtmlElement* current_panel_parent_element_;
144 
145  GoogleString current_panel_id_;
146 
147  DISALLOW_COPY_AND_ASSIGN(SplitHtmlState);
148 };
149 
150 }
151 
152 #endif
std::map< GoogleString, XpathUnits * > XpathMap
Map of xpath to XpathUnits.
Definition: split_html_config.h:46
SplitHtmlConfig(RewriteDriver *driver)
bool IsEndMarkerForCurrentPanel(HtmlElement *element) const
GoogleString MatchPanelIdForElement(HtmlElement *element) const
Returns the panel id of the panel whose xpath matched with element.
bool IsElementParentOfCurrentPanel(HtmlElement *element) const
Returns true if element is the parent of current panel.
Definition: split_html_config.h:50
Definition: rewrite_driver.h:98
Represents the filter state necessary to perform the split.
Definition: split_html_config.h:92
static void Initialize()
Initialize & Terminate must be paired.
bool IsElementSiblingOfCurrentPanel(HtmlElement *element) const
Definition: split_html_config.h:35