content/html/document/src/ImageDocument.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_dom_ImageDocument_h
     6 #define mozilla_dom_ImageDocument_h
     8 #include "mozilla/Attributes.h"
     9 #include "imgINotificationObserver.h"
    10 #include "MediaDocument.h"
    11 #include "nsIDOMEventListener.h"
    12 #include "nsIImageDocument.h"
    14 namespace mozilla {
    15 namespace dom {
    17 class ImageDocument MOZ_FINAL : public MediaDocument,
    18                                 public nsIImageDocument,
    19                                 public imgINotificationObserver,
    20                                 public nsIDOMEventListener
    21 {
    22 public:
    23   ImageDocument();
    24   virtual ~ImageDocument();
    26   NS_DECL_ISUPPORTS_INHERITED
    28   virtual nsresult Init() MOZ_OVERRIDE;
    30   virtual nsresult StartDocumentLoad(const char*         aCommand,
    31                                      nsIChannel*         aChannel,
    32                                      nsILoadGroup*       aLoadGroup,
    33                                      nsISupports*        aContainer,
    34                                      nsIStreamListener** aDocListener,
    35                                      bool                aReset = true,
    36                                      nsIContentSink*     aSink = nullptr) MOZ_OVERRIDE;
    38   virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE;
    39   virtual void Destroy() MOZ_OVERRIDE;
    40   virtual void OnPageShow(bool aPersisted,
    41                           EventTarget* aDispatchStartTarget) MOZ_OVERRIDE;
    43   NS_DECL_NSIIMAGEDOCUMENT
    44   NS_DECL_IMGINOTIFICATIONOBSERVER
    46   // nsIDOMEventListener
    47   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
    49   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
    51   friend class ImageListener;
    53   void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
    55   // WebIDL API
    56   virtual JSObject* WrapNode(JSContext* aCx)
    57     MOZ_OVERRIDE;
    59   bool ImageResizingEnabled() const
    60   {
    61     return true;
    62   }
    63   bool ImageIsOverflowing() const
    64   {
    65     return mImageIsOverflowing;
    66   }
    67   bool ImageIsResized() const
    68   {
    69     return mImageIsResized;
    70   }
    71   already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv);
    72   void ShrinkToFit();
    73   void RestoreImage();
    74   void RestoreImageTo(int32_t aX, int32_t aY)
    75   {
    76     ScrollImageTo(aX, aY, true);
    77   }
    78   void ToggleImageSize();
    80 protected:
    81   virtual nsresult CreateSyntheticDocument();
    83   nsresult CheckOverflowing(bool changeState);
    85   void UpdateTitleAndCharset();
    87   void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
    89   float GetRatio() {
    90     return std::min(mVisibleWidth / mImageWidth,
    91                     mVisibleHeight / mImageHeight);
    92   }
    94   void ResetZoomLevel();
    95   float GetZoomLevel();
    97   void UpdateSizeFromLayout();
    99   enum eModeClasses {
   100     eNone,
   101     eShrinkToFit,
   102     eOverflowing
   103   };
   104   void SetModeClass(eModeClasses mode);
   106   nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage);
   107   nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus);
   109   nsCOMPtr<nsIContent>          mImageContent;
   111   float                         mVisibleWidth;
   112   float                         mVisibleHeight;
   113   int32_t                       mImageWidth;
   114   int32_t                       mImageHeight;
   116   bool                          mResizeImageByDefault;
   117   bool                          mClickResizingEnabled;
   118   bool                          mImageIsOverflowing;
   119   // mImageIsResized is true if the image is currently resized
   120   bool                          mImageIsResized;
   121   // mShouldResize is true if the image should be resized when it doesn't fit
   122   // mImageIsResized cannot be true when this is false, but mImageIsResized
   123   // can be false when this is true
   124   bool                          mShouldResize;
   125   bool                          mFirstResize;
   126   // mObservingImageLoader is true while the observer is set.
   127   bool                          mObservingImageLoader;
   129   float                         mOriginalZoomLevel;
   130 };
   132 } // namespace dom
   133 } // namespace mozilla
   135 #endif /* mozilla_dom_ImageDocument_h */

mercurial