Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_minify.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 NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
21 
24 
25 namespace Css {
26 class Stylesheet;
27 class Charsets;
28 class Import;
29 class MediaQuery;
30 class MediaQueries;
31 class MediaExpression;
32 class FontFace;
33 class Ruleset;
34 class Selector;
35 class SimpleSelector;
36 class SimpleSelectors;
37 class Declaration;
38 class Declarations;
39 class Value;
40 class Values;
41 class FunctionParameters;
42 class UnparsedRegion;
43 }
44 
45 class UnicodeText;
46 
47 namespace net_instaweb {
48 
49 class MessageHandler;
50 class Writer;
51 
53 class CssMinify {
54  public:
55  CssMinify(Writer* writer, MessageHandler* handler);
56  ~CssMinify();
57 
61  bool ParseStylesheet(StringPiece stylesheet_text);
62 
64  static bool Stylesheet(const Css::Stylesheet& stylesheet,
65  Writer* writer,
66  MessageHandler* handler);
67 
69  static bool Declarations(const Css::Declarations& declarations,
70  Writer* writer,
71  MessageHandler* handler);
72 
74  void set_url_collector(StringVector* urls) { url_collector_ = urls; }
75 
78  void set_error_writer(Writer* writer) { error_writer_ = writer; }
79 
80  private:
81  void Write(const StringPiece& str);
82  void WriteURL(const UnicodeText& url);
83 
84  template<typename Container>
85  void JoinMinify(const Container& container, const StringPiece& sep);
86  template<typename Iterator>
87  void JoinMinifyIter(const Iterator& begin, const Iterator& end,
88  const StringPiece& sep);
89 
92  void Minify(const Css::Stylesheet& stylesheet);
93  void Minify(const Css::Charsets& charsets);
94  void Minify(const Css::Import& import);
95  void Minify(const Css::MediaQuery& media_query);
96  void Minify(const Css::MediaExpression& expression);
97  void Minify(const Css::Selector& selector);
98  void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false);
99  void Minify(const Css::SimpleSelector& sselector);
100  void Minify(const Css::Declaration& declaration);
101  void Minify(const Css::Value& value);
102  void Minify(const Css::FunctionParameters& parameters);
103  void Minify(const Css::UnparsedRegion& unparsed_region);
104 
108 
110  void MinifyMediaStart(const Css::MediaQueries& media_queries);
112  void MinifyMediaEnd(const Css::MediaQueries& media_queries);
113 
115  void MinifyFontFaceIgnoringMedia(const Css::FontFace& font_face);
116  void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset);
117 
119  void MinifyFont(const Css::Values& font_values);
120 
121  bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const;
122  bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const;
123  bool Equals(const Css::MediaExpression& a,
124  const Css::MediaExpression& b) const;
125 
126  bool UnitsRequiredForValueZero(const GoogleString& unit);
127 
128  Writer* writer_;
129  Writer* error_writer_;
130  MessageHandler* handler_;
131  bool ok_;
132 
133  StringVector* url_collector_;
134  bool in_css_calc_function_;
135 
136 
137 };
138 
139 }
140 
141 #endif
bool ParseStylesheet(StringPiece stylesheet_text)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static bool Declarations(const Css::Declarations &declarations, Writer *writer, MessageHandler *handler)
Writes minified Declarations (style attribute contents).
static bool Stylesheet(const Css::Stylesheet &stylesheet, Writer *writer, MessageHandler *handler)
Writes minified Stylesheet from already-parsed stylesheet object.
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: css_minify.h:53
Definition: message_handler.h:39
void set_error_writer(Writer *writer)
Definition: css_minify.h:78
void set_url_collector(StringVector *urls)
Establishes a string-vector to collect all parsed URLs.
Definition: css_minify.h:74