content/html/document/src/ImageDocument.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/html/document/src/ImageDocument.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef mozilla_dom_ImageDocument_h
     1.9 +#define mozilla_dom_ImageDocument_h
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "imgINotificationObserver.h"
    1.13 +#include "MediaDocument.h"
    1.14 +#include "nsIDOMEventListener.h"
    1.15 +#include "nsIImageDocument.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace dom {
    1.19 +
    1.20 +class ImageDocument MOZ_FINAL : public MediaDocument,
    1.21 +                                public nsIImageDocument,
    1.22 +                                public imgINotificationObserver,
    1.23 +                                public nsIDOMEventListener
    1.24 +{
    1.25 +public:
    1.26 +  ImageDocument();
    1.27 +  virtual ~ImageDocument();
    1.28 +
    1.29 +  NS_DECL_ISUPPORTS_INHERITED
    1.30 +
    1.31 +  virtual nsresult Init() MOZ_OVERRIDE;
    1.32 +
    1.33 +  virtual nsresult StartDocumentLoad(const char*         aCommand,
    1.34 +                                     nsIChannel*         aChannel,
    1.35 +                                     nsILoadGroup*       aLoadGroup,
    1.36 +                                     nsISupports*        aContainer,
    1.37 +                                     nsIStreamListener** aDocListener,
    1.38 +                                     bool                aReset = true,
    1.39 +                                     nsIContentSink*     aSink = nullptr) MOZ_OVERRIDE;
    1.40 +
    1.41 +  virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject) MOZ_OVERRIDE;
    1.42 +  virtual void Destroy() MOZ_OVERRIDE;
    1.43 +  virtual void OnPageShow(bool aPersisted,
    1.44 +                          EventTarget* aDispatchStartTarget) MOZ_OVERRIDE;
    1.45 +
    1.46 +  NS_DECL_NSIIMAGEDOCUMENT
    1.47 +  NS_DECL_IMGINOTIFICATIONOBSERVER
    1.48 +
    1.49 +  // nsIDOMEventListener
    1.50 +  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE;
    1.51 +
    1.52 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImageDocument, MediaDocument)
    1.53 +
    1.54 +  friend class ImageListener;
    1.55 +
    1.56 +  void DefaultCheckOverflowing() { CheckOverflowing(mResizeImageByDefault); }
    1.57 +
    1.58 +  // WebIDL API
    1.59 +  virtual JSObject* WrapNode(JSContext* aCx)
    1.60 +    MOZ_OVERRIDE;
    1.61 +
    1.62 +  bool ImageResizingEnabled() const
    1.63 +  {
    1.64 +    return true;
    1.65 +  }
    1.66 +  bool ImageIsOverflowing() const
    1.67 +  {
    1.68 +    return mImageIsOverflowing;
    1.69 +  }
    1.70 +  bool ImageIsResized() const
    1.71 +  {
    1.72 +    return mImageIsResized;
    1.73 +  }
    1.74 +  already_AddRefed<imgIRequest> GetImageRequest(ErrorResult& aRv);
    1.75 +  void ShrinkToFit();
    1.76 +  void RestoreImage();
    1.77 +  void RestoreImageTo(int32_t aX, int32_t aY)
    1.78 +  {
    1.79 +    ScrollImageTo(aX, aY, true);
    1.80 +  }
    1.81 +  void ToggleImageSize();
    1.82 +
    1.83 +protected:
    1.84 +  virtual nsresult CreateSyntheticDocument();
    1.85 +
    1.86 +  nsresult CheckOverflowing(bool changeState);
    1.87 +
    1.88 +  void UpdateTitleAndCharset();
    1.89 +
    1.90 +  void ScrollImageTo(int32_t aX, int32_t aY, bool restoreImage);
    1.91 +
    1.92 +  float GetRatio() {
    1.93 +    return std::min(mVisibleWidth / mImageWidth,
    1.94 +                    mVisibleHeight / mImageHeight);
    1.95 +  }
    1.96 +
    1.97 +  void ResetZoomLevel();
    1.98 +  float GetZoomLevel();
    1.99 +
   1.100 +  void UpdateSizeFromLayout();
   1.101 +
   1.102 +  enum eModeClasses {
   1.103 +    eNone,
   1.104 +    eShrinkToFit,
   1.105 +    eOverflowing
   1.106 +  };
   1.107 +  void SetModeClass(eModeClasses mode);
   1.108 +
   1.109 +  nsresult OnStartContainer(imgIRequest* aRequest, imgIContainer* aImage);
   1.110 +  nsresult OnStopRequest(imgIRequest *aRequest, nsresult aStatus);
   1.111 +
   1.112 +  nsCOMPtr<nsIContent>          mImageContent;
   1.113 +
   1.114 +  float                         mVisibleWidth;
   1.115 +  float                         mVisibleHeight;
   1.116 +  int32_t                       mImageWidth;
   1.117 +  int32_t                       mImageHeight;
   1.118 +
   1.119 +  bool                          mResizeImageByDefault;
   1.120 +  bool                          mClickResizingEnabled;
   1.121 +  bool                          mImageIsOverflowing;
   1.122 +  // mImageIsResized is true if the image is currently resized
   1.123 +  bool                          mImageIsResized;
   1.124 +  // mShouldResize is true if the image should be resized when it doesn't fit
   1.125 +  // mImageIsResized cannot be true when this is false, but mImageIsResized
   1.126 +  // can be false when this is true
   1.127 +  bool                          mShouldResize;
   1.128 +  bool                          mFirstResize;
   1.129 +  // mObservingImageLoader is true while the observer is set.
   1.130 +  bool                          mObservingImageLoader;
   1.131 +
   1.132 +  float                         mOriginalZoomLevel;
   1.133 +};
   1.134 +
   1.135 +} // namespace dom
   1.136 +} // namespace mozilla
   1.137 +
   1.138 +#endif /* mozilla_dom_ImageDocument_h */

mercurial