Page Speed Optimization Libraries  1.8.31.2
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 "pagespeed/kernel/base/basictypes.h"
00023 #include "pagespeed/kernel/base/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 MessageHandler;
00049 class Writer;
00050 
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 
00064  private:
00065   CssMinify(Writer* writer, MessageHandler* handler);
00066   ~CssMinify();
00067 
00068   void Write(const StringPiece& str);
00069   void WriteURL(const UnicodeText& url);
00070 
00071   template<typename Container>
00072   void JoinMinify(const Container& container, const StringPiece& sep);
00073   template<typename Iterator>
00074   void JoinMinifyIter(const Iterator& begin, const Iterator& end,
00075                       const StringPiece& sep);
00076 
00079   void Minify(const Css::Stylesheet& stylesheet);
00080   void Minify(const Css::Charsets& charsets);
00081   void Minify(const Css::Import& import);
00082   void Minify(const Css::MediaQuery& media_query);
00083   void Minify(const Css::MediaExpression& expression);
00084   void Minify(const Css::Selector& selector);
00085   void Minify(const Css::SimpleSelectors& sselectors, bool isfirst = false);
00086   void Minify(const Css::SimpleSelector& sselector);
00087   void Minify(const Css::Declaration& declaration);
00088   void Minify(const Css::Value& value);
00089   void Minify(const Css::FunctionParameters& parameters);
00090   void Minify(const Css::UnparsedRegion& unparsed_region);
00091 
00095 
00098   void MinifyRulesetIgnoringMedia(const Css::Ruleset& ruleset);
00100   void MinifyRulesetMediaStart(const Css::Ruleset& ruleset);
00102   void MinifyRulesetMediaEnd(const Css::Ruleset& ruleset);
00103 
00105   void MinifyFont(const Css::Values& font_values);
00106 
00107   bool Equals(const Css::MediaQueries& a, const Css::MediaQueries& b) const;
00108   bool Equals(const Css::MediaQuery& a, const Css::MediaQuery& b) const;
00109   bool Equals(const Css::MediaExpression& a,
00110               const Css::MediaExpression& b) const;
00111 
00112   Writer* writer_;
00113   MessageHandler* handler_;
00114   bool ok_;
00115 
00116   DISALLOW_COPY_AND_ASSIGN(CssMinify);
00117 };
00118 
00119 }  
00120 
00121 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_MINIFY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines