Page Speed Optimization Libraries  1.4.26.1
net/instaweb/rewriter/public/lazyload_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 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
00021 
00022 #include "net/instaweb/rewriter/public/common_filter.h"
00023 #include "net/instaweb/util/public/string.h"
00024 
00025 namespace net_instaweb {
00026 
00027 class HtmlElement;
00028 class RewriteDriver;
00029 class RewriteOptions;
00030 class StaticAssetManager;
00031 class Statistics;
00032 
00074 class LazyloadImagesFilter : public CommonFilter {
00075  public:
00076   static const char* kImageLazyloadCode;
00077   static const char* kImageOnloadCode;
00078   static const char* kLoadAllImages;
00079   static const char* kOverrideAttributeFunctions;
00080   static const char* kIsLazyloadScriptInsertedPropertyName;
00081 
00082   explicit LazyloadImagesFilter(RewriteDriver* driver);
00083   virtual ~LazyloadImagesFilter();
00084 
00085   virtual const char* Name() const { return "Lazyload Images"; }
00086 
00087   static void InitStats(Statistics* statistics);
00088   static void Terminate();
00089 
00091   static bool ShouldApply(RewriteDriver* driver);
00092   static GoogleString GetLazyloadJsSnippet(
00093       const RewriteOptions* options,
00094       StaticAssetManager* static_asset_manager);
00095 
00096  private:
00097   virtual void StartDocumentImpl();
00098   virtual void EndDocument();
00099   virtual void StartElementImpl(HtmlElement* element);
00100   virtual void EndElementImpl(HtmlElement* element);
00101   virtual void DetermineEnabled();
00102 
00104   void Clear();
00105 
00106   static GoogleString GetBlankImageSrc(
00107       const RewriteOptions* options,
00108       const StaticAssetManager* static_asset_manager);
00109 
00111   void InsertLazyloadJsCode(HtmlElement* element);
00112 
00115   void InsertOverrideAttributesScript(HtmlElement* element,
00116                                       bool is_before_script);
00117 
00119   GoogleString blank_image_url_;
00122   HtmlElement* skip_rewrite_;
00124   bool main_script_inserted_;
00126   bool abort_rewrite_;
00129   bool abort_script_inserted_;
00132   int num_images_lazily_loaded_;
00133 };
00134 
00135 }  
00136 
00137 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_LAZYLOAD_IMAGES_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines