Page Speed Optimization Libraries  1.4.26.1
net/instaweb/rewriter/public/css_minify.h
Go to the documentation of this file.
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 FunctionParameters;
00040 class UnparsedRegion;
00041 }  
00042 
00043 class UnicodeText;
00044 
00045 namespace net_instaweb {
00046 
00047 class GoogleUrl;
00048 class RewriteDriver;
00049 class MessageHandler;
00050 class Writer;
00051 
00052 class CssMinify {
00053  public:
00055   static bool Stylesheet(const Css::Stylesheet& stylesheet,
00056                          Writer* writer,
00057                          MessageHandler* handler);
00058 
00060   static bool Declarations(const Css::Declarations& declarations,
00061                            Writer* writer,
00062                            MessageHandler* handler);
00063 
00067   static bool AbsolutifyImports(Css::Stylesheet* stylesheet,
00068                                 const GoogleUrl& base);
00069 
00075   static bool AbsolutifyUrls(Css::Stylesheet* stylesheet,
00076                              const GoogleUrl& base,
00077                              bool handle_parseable_sections,
00078                              bool handle_unparseable_sections,
00079                              RewriteDriver* driver,
00080                              MessageHandler* handler);
00081 
00082  private:
00083   CssMinify(Writer* writer, MessageHandler* handler);
00084   ~CssMinify();
00085 
00086   void Write(const StringPiece& str);
00087   void WriteURL(const UnicodeText& url);
00088 
00089   template<typename Container>
00090   void JoinMinify(const Container& container, const StringPiece& sep);
00091   template<typename Iterator>
00092   void JoinMinifyIter(const Iterator& begin, const Iterator& end,
00093                       const StringPiece& sep);
00094 
00097   void Minify(const Css::Stylesheet& stylesheet);
00098   void Minify(const Css::Charsets& charsets);
00099   void Minify(const Css::Import& import);
00100   void Minify(const Css::MediaQuery& media_query);
00101   void Minify(const Css::MediaExpression& expression);
00102   void Minify(const Css::Selector& selector);
00103   void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false);
00104   void Minify(const Css::SimpleSelector& sselector);
00105   void Minify(const Css::Declaration& declaration);
00106   void Minify(const Css::Value& value);
00107   void Minify(const Css::FunctionParameters& parameters);
00108   void Minify(const Css::UnparsedRegion& unparsed_region);
00109 
00113 
00116   void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset);
00118   void MinifyRulesetMediaStart(const Css::Ruleset& ruleset);
00120   void MinifyRulesetMediaEnd(const Css::Ruleset& ruleset);
00121 
00122   bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const;
00123   bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const;
00124   bool Equals(const Css::MediaExpression& a,
00125               const Css::MediaExpression& b) const;
00126 
00127   Writer* writer_;
00128   MessageHandler* handler_;
00129   bool ok_;
00130 
00131   DISALLOW_COPY_AND_ASSIGN(CssMinify);
00132 };
00133 
00134 }  
00135 
00136 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines