Page Speed Optimization Libraries  1.4.26.1
net/instaweb/rewriter/public/critical_selector_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2013 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 
00024 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00025 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00026 
00027 #include <vector>
00028 
00029 #include "net/instaweb/rewriter/public/css_summarizer_base.h"
00030 #include "net/instaweb/util/public/basictypes.h"
00031 #include "net/instaweb/util/public/scoped_ptr.h"
00032 #include "net/instaweb/util/public/string.h"
00033 #include "net/instaweb/util/public/string_util.h"
00034 
00035 namespace Css {
00036 
00037 class Stylesheet;
00038 
00039 }  
00040 
00041 namespace net_instaweb {
00042 
00043 class CriticalSelectorSummarizedCss;
00044 class HtmlCharactersNode;
00045 class HtmlElement;
00046 class RewriteDriver;
00047 
00048 class CriticalSelectorFilter : public CssSummarizerBase {
00049  public:
00050   static const char kAddStylesScript[];
00051   static const char kSummarizedCssProperty[];
00052 
00053   explicit CriticalSelectorFilter(RewriteDriver* rewrite_driver);
00054   virtual ~CriticalSelectorFilter();
00055 
00056   virtual const char* Name() const { return "CriticalSelectorFilter"; }
00057   virtual const char* id() const { return "cl"; }
00058 
00059  protected:
00063   virtual void Summarize(Css::Stylesheet* stylesheet,
00064                          GoogleString* out) const;
00065   virtual void SummariesDone();
00066 
00069   virtual GoogleString CacheKeySuffix() const;
00070 
00073   virtual void NotifyInlineCss(HtmlElement* style_element,
00074                                HtmlCharactersNode* content);
00075   virtual void NotifyExternalCss(HtmlElement* link);
00076 
00078   virtual void StartDocumentImpl();
00079   virtual void EndDocument();
00080   virtual void EndElementImpl(HtmlElement* element);
00081 
00082  private:
00083   class CssElement;
00084   class CssStyleElement;
00085   typedef std::vector<CssElement*> CssElementVector;
00086 
00088   void InsertCriticalCssIfNeeded(HtmlElement* insert_before);
00089 
00092   scoped_ptr<CriticalSelectorSummarizedCss> critical_css_;
00093 
00097   StringSet critical_selectors_;
00098 
00100   GoogleString cache_key_suffix_;
00101 
00103   CssElementVector css_elements_;
00104 
00106   HtmlElement* style_element_to_delete_;
00107 
00109   bool inserted_critical_css_;
00110 
00111   DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter);
00112 };
00113 
00114 }  
00115 
00116 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines