00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
00021
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/string.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025
00026 namespace Css {
00027 class Stylesheet;
00028 class Charsets;
00029 class Import;
00030 class Ruleset;
00031 class Selector;
00032 class SimpleSelector;
00033 class SimpleSelectors;
00034 class Declaration;
00035 class Declarations;
00036 class Value;
00037 class FunctionParameters;
00038 }
00039
00040 class UnicodeText;
00041
00042 namespace net_instaweb {
00043
00044 class GoogleUrl;
00045 class RewriteDriver;
00046 class MessageHandler;
00047 class Writer;
00048
00049 class CssMinify {
00050 public:
00052 static bool Stylesheet(const Css::Stylesheet& stylesheet,
00053 Writer* writer,
00054 MessageHandler* handler);
00055
00057 static bool Declarations(const Css::Declarations& declarations,
00058 Writer* writer,
00059 MessageHandler* handler);
00060
00064 static bool AbsolutifyImports(Css::Stylesheet* stylesheet,
00065 const GoogleUrl& base);
00066
00072 static bool AbsolutifyUrls(Css::Stylesheet* stylesheet,
00073 const GoogleUrl& base,
00074 bool handle_parseable_sections,
00075 bool handle_unparseable_sections,
00076 RewriteDriver* driver,
00077 MessageHandler* handler);
00078
00081 static GoogleString EscapeString(const StringPiece& src, bool in_url);
00082
00083 private:
00084 CssMinify(Writer* writer, MessageHandler* handler);
00085 ~CssMinify();
00086
00087 void Write(const StringPiece& str);
00088
00089 void WriteURL(const UnicodeText& url);
00090
00091 template<typename Container>
00092 void JoinMinify(const Container& container, const StringPiece& sep);
00093 template<typename Iterator>
00094 void JoinMinifyIter(const Iterator& begin, const Iterator& end,
00095 const StringPiece& sep);
00096 template<typename Container>
00097 void JoinMediaMinify(const Container& container, const StringPiece& sep);
00098
00101 void Minify(const Css::Stylesheet& stylesheet);
00102 void Minify(const Css::Charsets& charsets);
00103 void Minify(const Css::Import& import);
00104 void Minify(const Css::Selector& selector);
00105 void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false);
00106 void Minify(const Css::SimpleSelector& sselector);
00107 void Minify(const Css::Declaration& declaration);
00108 void Minify(const Css::Value& value);
00109 void Minify(const Css::FunctionParameters& parameters);
00110
00114
00117 void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset);
00119 void MinifyRulesetMediaStart(const Css::Ruleset& ruleset);
00121 void MinifyRulesetMediaEnd(const Css::Ruleset& ruleset);
00122
00123 Writer* writer_;
00124 MessageHandler* handler_;
00125 bool ok_;
00126
00127 DISALLOW_COPY_AND_ASSIGN(CssMinify);
00128 };
00129
00130 }
00131
00132 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_