Page Speed Optimization Libraries
1.7.30.3
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 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_util.h" 00024 00025 namespace Css { 00026 class Stylesheet; 00027 class Charsets; 00028 class Import; 00029 class MediaQuery; 00030 class MediaQueries; 00031 class MediaExpression; 00032 class Ruleset; 00033 class Selector; 00034 class SimpleSelector; 00035 class SimpleSelectors; 00036 class Declaration; 00037 class Declarations; 00038 class Value; 00039 class Values; 00040 class FunctionParameters; 00041 class UnparsedRegion; 00042 } 00043 00044 class UnicodeText; 00045 00046 namespace net_instaweb { 00047 00048 class GoogleUrl; 00049 class RewriteDriver; 00050 class MessageHandler; 00051 class Writer; 00052 00053 class CssMinify { 00054 public: 00056 static bool Stylesheet(const Css::Stylesheet& stylesheet, 00057 Writer* writer, 00058 MessageHandler* handler); 00059 00061 static bool Declarations(const Css::Declarations& declarations, 00062 Writer* writer, 00063 MessageHandler* handler); 00064 00068 static bool AbsolutifyImports(Css::Stylesheet* stylesheet, 00069 const GoogleUrl& base); 00070 00076 static bool AbsolutifyUrls(Css::Stylesheet* stylesheet, 00077 const GoogleUrl& base, 00078 bool handle_parseable_sections, 00079 bool handle_unparseable_sections, 00080 RewriteDriver* driver, 00081 MessageHandler* handler); 00082 00083 private: 00084 CssMinify(Writer* writer, MessageHandler* handler); 00085 ~CssMinify(); 00086 00087 void Write(const StringPiece& str); 00088 void WriteURL(const UnicodeText& url); 00089 00090 template<typename Container> 00091 void JoinMinify(const Container& container, const StringPiece& sep); 00092 template<typename Iterator> 00093 void JoinMinifyIter(const Iterator& begin, const Iterator& end, 00094 const StringPiece& sep); 00095 00098 void Minify(const Css::Stylesheet& stylesheet); 00099 void Minify(const Css::Charsets& charsets); 00100 void Minify(const Css::Import& import); 00101 void Minify(const Css::MediaQuery& media_query); 00102 void Minify(const Css::MediaExpression& expression); 00103 void Minify(const Css::Selector& selector); 00104 void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false); 00105 void Minify(const Css::SimpleSelector& sselector); 00106 void Minify(const Css::Declaration& declaration); 00107 void Minify(const Css::Value& value); 00108 void Minify(const Css::FunctionParameters& parameters); 00109 void Minify(const Css::UnparsedRegion& unparsed_region); 00110 00114 00117 void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset); 00119 void MinifyRulesetMediaStart(const Css::Ruleset& ruleset); 00121 void MinifyRulesetMediaEnd(const Css::Ruleset& ruleset); 00122 00124 void MinifyFont(const Css::Values& font_values); 00125 00126 bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const; 00127 bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const; 00128 bool Equals(const Css::MediaExpression& a, 00129 const Css::MediaExpression& b) const; 00130 00131 Writer* writer_; 00132 MessageHandler* handler_; 00133 bool ok_; 00134 00135 DISALLOW_COPY_AND_ASSIGN(CssMinify); 00136 }; 00137 00138 } 00139 00140 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_