Page Speed Optimization Libraries  1.9.32.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 
22 #include "pagespeed/kernel/base/basictypes.h"
23 #include "pagespeed/kernel/base/string_util.h"
24 
25 namespace Css {
26 class Stylesheet;
27 class Charsets;
28 class Import;
29 class MediaQuery;
30 class MediaQueries;
31 class MediaExpression;
32 class Ruleset;
33 class Selector;
34 class SimpleSelector;
35 class SimpleSelectors;
36 class Declaration;
37 class Declarations;
38 class Value;
39 class Values;
40 class FunctionParameters;
41 class UnparsedRegion;
42 }
43 
44 class UnicodeText;
45 
46 namespace net_instaweb {
47 
48 class MessageHandler;
49 class Writer;
50 
52 class CssMinify {
53  public:
55  static bool Stylesheet(const Css::Stylesheet& stylesheet,
56  Writer* writer,
57  MessageHandler* handler);
58 
60  static bool Declarations(const Css::Declarations& declarations,
61  Writer* writer,
62  MessageHandler* handler);
63 
64  private:
65  CssMinify(Writer* writer, MessageHandler* handler);
66  ~CssMinify();
67 
68  void Write(const StringPiece& str);
69  void WriteURL(const UnicodeText& url);
70 
71  template<typename Container>
72  void JoinMinify(const Container& container, const StringPiece& sep);
73  template<typename Iterator>
74  void JoinMinifyIter(const Iterator& begin, const Iterator& end,
75  const StringPiece& sep);
76 
79  void Minify(const Css::Stylesheet& stylesheet);
80  void Minify(const Css::Charsets& charsets);
81  void Minify(const Css::Import& import);
82  void Minify(const Css::MediaQuery& media_query);
83  void Minify(const Css::MediaExpression& expression);
84  void Minify(const Css::Selector& selector);
85  void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false);
86  void Minify(const Css::SimpleSelector& sselector);
87  void Minify(const Css::Declaration& declaration);
88  void Minify(const Css::Value& value);
89  void Minify(const Css::FunctionParameters& parameters);
90  void Minify(const Css::UnparsedRegion& unparsed_region);
91 
95 
98  void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset);
100  void MinifyRulesetMediaStart(const Css::Ruleset& ruleset);
102  void MinifyRulesetMediaEnd(const Css::Ruleset& ruleset);
103 
105  void MinifyFont(const Css::Values& font_values);
106 
107  bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const;
108  bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const;
109  bool Equals(const Css::MediaExpression& a,
110  const Css::MediaExpression& b) const;
111 
112  Writer* writer_;
113  MessageHandler* handler_;
114  bool ok_;
115 
116  DISALLOW_COPY_AND_ASSIGN(CssMinify);
117 };
118 
119 }
120 
121 #endif
static bool Declarations(const Css::Declarations &declarations, Writer *writer, MessageHandler *handler)
Write minified Declarations (style attribute contents).
static bool Stylesheet(const Css::Stylesheet &stylesheet, Writer *writer, MessageHandler *handler)
Write minified Stylesheet.
Definition: css_minify.h:52