Page Speed Optimization Libraries  1.8.31.3
net/instaweb/rewriter/public/delay_images_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 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 
00070 
00071 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_
00072 #define NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_
00073 
00074 #include "net/instaweb/rewriter/public/common_filter.h"
00075 #include "net/instaweb/util/public/basictypes.h"
00076 #include "net/instaweb/util/public/string_util.h"
00077 
00078 namespace net_instaweb {
00079 
00080 class HtmlElement;
00081 class RewriteDriver;
00082 class StaticAssetManager;
00083 class Statistics;
00084 
00085 class DelayImagesFilter : public CommonFilter {
00086  public:
00087   static const char kDelayImagesSuffix[];
00088   static const char kDelayImagesInlineSuffix[];
00089   static const char kImageOnloadCode[];
00090   static const char kImageOnloadJsSnippet[];
00091 
00092   explicit DelayImagesFilter(RewriteDriver* driver);
00093   virtual ~DelayImagesFilter();
00094 
00095   virtual void StartDocumentImpl();
00096   virtual void StartElementImpl(HtmlElement* element) { }
00097   virtual void EndElementImpl(HtmlElement* element);
00098 
00099   virtual void EndDocument();
00100 
00101   virtual const char* Name() const { return "DelayImages"; }
00102 
00103   virtual void DetermineEnabled();
00104 
00105   static void InitStats(Statistics* statistics);
00106   static void Terminate();
00107 
00108  private:
00111   void MaybeAddImageOnloadJsSnippet(HtmlElement* element);
00112 
00114   void InsertLowResImagesAndJs(HtmlElement* element, bool insert_after_element);
00115 
00117   void InsertHighResJs(HtmlElement* element);
00118 
00121   bool ShouldRewriteInplace() const;
00122 
00123   RewriteDriver* driver_;
00124   StaticAssetManager* static_asset_manager_;
00125 
00126   int num_low_res_inlined_images_;
00127   StringStringMap low_res_data_map_;
00128 
00132   bool insert_low_res_images_inplace_;
00133 
00138   bool lazyload_highres_images_;
00139 
00140   bool is_script_inserted_;
00141 
00142   bool added_image_onload_js_;
00143 
00144   DISALLOW_COPY_AND_ASSIGN(DelayImagesFilter);
00145 };
00146 
00147 }  
00148 
00149 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_DELAY_IMAGES_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines