Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
responsive_image_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 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 
19 
20 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESPONSIVE_IMAGE_FILTER_H_
21 #define NET_INSTAWEB_REWRITER_PUBLIC_RESPONSIVE_IMAGE_FILTER_H_
22 
23 #include <map>
24 #include <vector>
25 
33 
34 namespace net_instaweb {
35 
37  ResponsiveImageCandidate(HtmlElement* element_arg, double resolution_arg)
38  : element(element_arg), resolution(resolution_arg) {}
39  ResponsiveImageCandidate() : element(NULL), resolution(0) {}
40 
41  HtmlElement* element;
42  double resolution;
43 };
44 typedef std::vector<ResponsiveImageCandidate> ResponsiveImageCandidateVector;
45 
49  int width;
50  int height;
54  ResponsiveImageCandidateVector non_inlinable_candidates;
61 };
62 typedef std::map<HtmlElement*, ResponsiveVirtualImages>
63  ResponsiveImageCandidateMap;
64 
73  public:
75  static const char kOriginalImage[];
76  static const char kNonInlinableVirtualImage[];
77  static const char kInlinableVirtualImage[];
78  static const char kFullsizedVirtualImage[];
79 
80  explicit ResponsiveImageFirstFilter(RewriteDriver* driver);
81  virtual ~ResponsiveImageFirstFilter();
82 
83  virtual void StartElementImpl(HtmlElement* element) {}
84  virtual void StartDocumentImpl();
85  virtual void EndElementImpl(HtmlElement* element);
86 
87  virtual const char* Name() const { return "ResponsiveImageFirst"; }
88 
89  private:
90  void AddHiResImages(HtmlElement* element);
91  ResponsiveImageCandidate AddHiResVersion(
92  HtmlElement* img, const HtmlElement::Attribute& src_attr,
93  int orig_width, int orig_height, StringPiece responsive_attribute_value,
94  double resolution);
95 
96  friend class ResponsiveImageSecondFilter;
97 
98  std::vector<double> densities_;
99  ResponsiveImageCandidateMap candidate_map_;
100 
101 
102 };
103 
105  public:
107  RewriteDriver* driver, const ResponsiveImageFirstFilter* first_filter);
108  virtual ~ResponsiveImageSecondFilter();
109 
110  virtual void StartElementImpl(HtmlElement* element) {}
111  virtual void StartDocumentImpl();
112  virtual void EndElementImpl(HtmlElement* element);
113  virtual void EndDocument();
114 
115  virtual const char* Name() const { return "ResponsiveImageSecond"; }
116 
119  ScriptUsage GetScriptUsage() const override { return kMayInjectScripts; }
120 
121  private:
122  void CombineHiResImages(HtmlElement* orig_element,
123  const ResponsiveVirtualImages& candidates);
124  void Cleanup(HtmlElement* orig_element,
125  const ResponsiveVirtualImages& candidates);
126  void InsertPlaceholderDebugComment(
127  const ResponsiveImageCandidate& candidate, const char* qualifier);
128 
129  const GoogleString responsive_js_url_;
130  const ResponsiveImageFirstFilter* first_filter_;
132  bool zoom_filter_enabled_;
134  bool srcsets_added_;
135 
136 
137 };
138 
139 }
140 
141 #endif
Definition: common_filter.h:47
Definition: html_element.h:66
Definition: responsive_image_filter.h:104
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: responsive_image_filter.h:87
ResponsiveImageCandidateVector non_inlinable_candidates
Definition: responsive_image_filter.h:54
Definition: html_element.h:42
Definition: responsive_image_filter.h:48
ResponsiveImageCandidate inlinable_candidate
Definition: responsive_image_filter.h:57
static const char kOriginalImage[]
Labels for different images used by Responsive image filters.
Definition: responsive_image_filter.h:75
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: responsive_image_filter.h:115
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ResponsiveImageCandidate fullsized_candidate
Definition: responsive_image_filter.h:60
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
ScriptUsage GetScriptUsage() const override
Definition: responsive_image_filter.h:119
Definition: rewrite_driver.h:100
Definition: responsive_image_filter.h:36
Definition: responsive_image_filter.h:72