Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_util.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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 
22 
23 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_UTIL_H_
24 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_UTIL_H_
25 
26 #include <vector>
27 
32 
33 namespace Css {
34 class Declarations;
35 class MediaQueries;
36 class MediaQuery;
37 class Selector;
38 }
39 
40 namespace net_instaweb {
41 
42 class HtmlElement;
43 
46 namespace css_util {
47 
48 static const char kAllMedia[] = "all";
49 static const int kNoValue = -1;
50 
57 };
58 
66 DimensionState GetDimensions(Css::Declarations* decls, int* width, int* height);
67 
69  public:
70  explicit StyleExtractor(HtmlElement* element);
71  virtual ~StyleExtractor();
72 
73 
74  DimensionState state() const { return state_; }
75 
77  int width() const { return width_px_; }
78  int height() const { return height_px_; }
79 
82  bool HasAnyDimensions() { return (state_ != kNoDimensions); }
83 
84  DimensionState dimension_state() { return state_; }
85 
86  private:
87  static Css::Declarations* GetDeclsFromElement(HtmlElement* element);
89  int width_px_;
90  int height_px_;
91  DimensionState state_;
92 
93 };
94 
99 
104 void VectorizeMediaAttribute(const StringPiece& input_media,
105  StringVector* output_vector);
106 
111 GoogleString StringifyMediaVector(const StringVector& import_media);
112 
115 bool IsComplexMediaQuery(const Css::MediaQuery& query);
116 
122 bool ConvertMediaQueriesToStringVector(const Css::MediaQueries& in_vector,
123  StringVector* out_vector);
124 
129 void ConvertStringVectorToMediaQueries(const StringVector& in_vector,
130  Css::MediaQueries* out_vector);
131 
134 void ClearVectorIfContainsMediaAll(StringVector* media);
135 
137 bool CanMediaAffectScreen(const StringPiece& media);
138 
141 GoogleString JsDetectableSelector(const Css::Selector& selector);
142 
149 template<typename T>
150 void EliminateElementsNotIn(std::vector<T>* sorted_inner,
151  const std::vector<T>& sorted_outer) {
152  if (!sorted_outer.empty()) {
153  if (sorted_inner->empty()) {
154  *sorted_inner = sorted_outer;
155  } else {
156  typename std::vector<T>::const_iterator outer_iter = sorted_outer.begin();
157  typename std::vector<T>::iterator inner_iter = sorted_inner->begin();
158 
159  while (inner_iter != sorted_inner->end()) {
160  if (outer_iter == sorted_outer.end()) {
162  inner_iter = sorted_inner->erase(inner_iter, sorted_inner->end());
163  } else if (*outer_iter == *inner_iter) {
165  ++outer_iter;
166  ++inner_iter;
167  } else if (*outer_iter < *inner_iter) {
169  ++outer_iter;
170  } else {
172  inner_iter = sorted_inner->erase(inner_iter);
173  }
174  }
175  }
176  }
177 }
178 
179 }
180 
181 }
182 
183 #endif
Found height only.
Definition: css_util.h:53
void ClearVectorIfContainsMediaAll(StringVector *media)
void EliminateElementsNotIn(std::vector< T > *sorted_inner, const std::vector< T > &sorted_outer)
Definition: css_util.h:150
Found both width and height.
Definition: css_util.h:55
void ConvertStringVectorToMediaQueries(const StringVector &in_vector, Css::MediaQueries *out_vector)
GoogleString JsDetectableSelector(const Css::Selector &selector)
No dimensions found.
Definition: css_util.h:52
void VectorizeMediaAttribute(const StringPiece &input_media, StringVector *output_vector)
Definition: html_element.h:42
Found width only.
Definition: css_util.h:54
DimensionState
Definition: css_util.h:51
DimensionState GetDimensions(Css::Declarations *decls, int *width, int *height)
bool HasAnyDimensions()
Definition: css_util.h:82
bool IsComplexMediaQuery(const Css::MediaQuery &query)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
GoogleString StringifyMediaVector(const StringVector &import_media)
int width() const
If a value was not found, it will be populated with kNoValue.
Definition: css_util.h:77
Found a dimension, but couldn't extract a value.
Definition: css_util.h:56
bool ConvertMediaQueriesToStringVector(const Css::MediaQueries &in_vector, StringVector *out_vector)
bool CanMediaAffectScreen(const StringPiece &media)
Can this media attribute include some kind of screen?