Page Speed Optimization Libraries
1.2.24.1
|
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.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 MediaQuery; 00031 class MediaQueries; 00032 class MediaExpression; 00033 class Ruleset; 00034 class Selector; 00035 class SimpleSelector; 00036 class SimpleSelectors; 00037 class Declaration; 00038 class Declarations; 00039 class Value; 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 00123 bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const; 00124 bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const; 00125 bool Equals(const Css::MediaExpression& a, 00126 const Css::MediaExpression& b) const; 00127 00128 Writer* writer_; 00129 MessageHandler* handler_; 00130 bool ok_; 00131 00132 DISALLOW_COPY_AND_ASSIGN(CssMinify); 00133 }; 00134 00135 } 00136 00137 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_