Page Speed Optimization Libraries
1.5.27.2
|
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 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: 00065 virtual void Summarize(Css::Stylesheet* stylesheet, 00066 GoogleString* out) const; 00067 virtual void RenderSummary(int pos, 00068 HtmlElement* element, 00069 HtmlCharactersNode* char_node); 00070 virtual void WillNotRenderSummary(int pos, 00071 HtmlElement* element, 00072 HtmlCharactersNode* char_node); 00073 00076 virtual GoogleString CacheKeySuffix() const; 00077 00079 virtual void StartDocumentImpl(); 00080 virtual void EndDocument(); 00081 virtual void RenderDone(); 00082 00084 virtual void DetermineEnabled(); 00085 00086 private: 00087 class CssElement; 00088 class CssStyleElement; 00089 typedef std::vector<CssElement*> CssElementVector; 00090 00091 void RememberFullCss(int pos, 00092 HtmlElement* element, 00093 HtmlCharactersNode* char_node); 00094 00098 StringSet critical_selectors_; 00099 00101 GoogleString cache_key_suffix_; 00102 00106 CssElementVector css_elements_; 00107 00109 bool saw_end_document_; 00110 00112 bool any_rendered_; 00113 00114 DISALLOW_COPY_AND_ASSIGN(CriticalSelectorFilter); 00115 }; 00116 00117 } 00118 00119 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CRITICAL_SELECTOR_FILTER_H_