Page Speed Optimization Libraries  1.6.29.3
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 
00025 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00026 #define NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
00027 
00028 #include <vector>
00029 
00030 #include "net/instaweb/rewriter/public/css_summarizer_base.h"
00031 #include "net/instaweb/util/public/basictypes.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 HtmlCharactersNode;
00044 class HtmlElement;
00045 class RewriteDriver;
00046 
00047 class CriticalSelectorFilter : public CssSummarizerBase {
00048  public:
00049   static const char kAddStylesFunction[];
00050   static const char kAddStylesInvocation[];
00051 
00052   explicit CriticalSelectorFilter(RewriteDriver* rewrite_driver);
00053   virtual ~CriticalSelectorFilter();
00054 
00055   virtual const char* Name() const { return "CriticalSelectorFilter"; }
00056   virtual const char* id() const { return "cl"; }
00057 
00058  protected:
00064   virtual void Summarize(Css::Stylesheet* stylesheet,
00065                          GoogleString* out) const;
00066   virtual void RenderSummary(int pos,
00067                              HtmlElement* element,
00068                              HtmlCharactersNode* char_node);
00069   virtual void WillNotRenderSummary(int pos,
00070                                     HtmlElement* element,
00071                                     HtmlCharactersNode* char_node);
00072 
00075   virtual GoogleString CacheKeySuffix() const;
00076 
00078   virtual void StartDocumentImpl();
00079   virtual void EndDocument();
00080   virtual void RenderDone();
00081 
00083   virtual void DetermineEnabled();
00084 
00085  private:
00086   class CssElement;
00087   class CssStyleElement;
00088   typedef std::vector<CssElement*> CssElementVector;
00089 
00090   void RememberFullCss(int pos,
00091                        HtmlElement* element,
00092                        HtmlCharactersNode* char_node);
00093 
00097   StringSet critical_selectors_;
00098 
00100   GoogleString cache_key_suffix_;
00101 
00105   CssElementVector css_elements_;
00106 
00108   bool saw_end_document_;
00109 
00111   bool any_rendered_;
00112 
00113   DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter);
00114 };
00115 
00116 }  
00117 
00118 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines