Blame layout/base/MobileViewportManager.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#ifndef MobileViewportManager_h_
Packit f0b94e
#define MobileViewportManager_h_
Packit f0b94e
Packit f0b94e
#include "mozilla/Maybe.h"
Packit f0b94e
#include "nsCOMPtr.h"
Packit f0b94e
#include "nsIDOMEventListener.h"
Packit f0b94e
#include "nsIObserver.h"
Packit f0b94e
#include "Units.h"
Packit f0b94e
Packit f0b94e
class nsIDOMEventTarget;
Packit f0b94e
class nsIDocument;
Packit f0b94e
class nsIPresShell;
Packit f0b94e
class nsViewportInfo;
Packit f0b94e
Packit f0b94e
class MobileViewportManager final : public nsIDOMEventListener,
Packit f0b94e
                                    public nsIObserver {
Packit f0b94e
 public:
Packit f0b94e
  NS_DECL_ISUPPORTS
Packit f0b94e
  NS_DECL_NSIDOMEVENTLISTENER
Packit f0b94e
  NS_DECL_NSIOBSERVER
Packit f0b94e
Packit f0b94e
  MobileViewportManager(nsIPresShell* aPresShell, nsIDocument* aDocument);
Packit f0b94e
  void Destroy();
Packit f0b94e
Packit f0b94e
  /* Provide a resolution to use during the first paint instead of the default
Packit f0b94e
   * resolution computed from the viewport info metadata. This is in the same
Packit f0b94e
   * "units" as the argument to nsDOMWindowUtils::SetResolutionAndScaleTo.
Packit f0b94e
   * Also takes the previous display dimensions as they were at the time the
Packit f0b94e
   * resolution was stored in order to correctly adjust the resolution if the
Packit f0b94e
   * device was rotated in the meantime. */
Packit f0b94e
  void SetRestoreResolution(float aResolution,
Packit f0b94e
                            mozilla::LayoutDeviceIntSize aDisplaySize);
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  void SetRestoreResolution(float aResolution);
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  /* Notify the MobileViewportManager that a reflow was requested in the
Packit f0b94e
   * presShell.*/
Packit f0b94e
  void RequestReflow();
Packit f0b94e
Packit f0b94e
  /* Notify the MobileViewportManager that the resolution on the presShell was
Packit f0b94e
   * updated, and the SPCSPS needs to be updated. */
Packit f0b94e
  void ResolutionUpdated();
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  ~MobileViewportManager();
Packit f0b94e
Packit f0b94e
  /* Called to compute the initial viewport on page load or before-first-paint,
Packit f0b94e
   * whichever happens first. */
Packit f0b94e
  void SetInitialViewport();
Packit f0b94e
Packit f0b94e
  /* Main helper method to update the CSS viewport and any other properties that
Packit f0b94e
   * need updating. */
Packit f0b94e
  void RefreshViewportSize(bool aForceAdjustResolution);
Packit f0b94e
Packit f0b94e
  /* Secondary main helper method to update just the SPCSPS. */
Packit f0b94e
  void RefreshSPCSPS();
Packit f0b94e
Packit f0b94e
  /* Helper to clamp the given zoom by the min/max in the viewport info. */
Packit f0b94e
  mozilla::CSSToScreenScale ClampZoom(const mozilla::CSSToScreenScale& aZoom,
Packit f0b94e
                                      const nsViewportInfo& aViewportInfo);
Packit f0b94e
Packit f0b94e
  /* Helper to update the given resolution according to changed display and
Packit f0b94e
   * viewport widths. */
Packit f0b94e
  mozilla::LayoutDeviceToLayerScale ScaleResolutionWithDisplayWidth(
Packit f0b94e
      const mozilla::LayoutDeviceToLayerScale& aRes,
Packit f0b94e
      const float& aDisplayWidthChangeRatio,
Packit f0b94e
      const mozilla::CSSSize& aNewViewport,
Packit f0b94e
      const mozilla::CSSSize& aOldViewport);
Packit f0b94e
Packit f0b94e
  /* Updates the presShell resolution and returns the new zoom. */
Packit f0b94e
  mozilla::CSSToScreenScale UpdateResolution(
Packit f0b94e
      const nsViewportInfo& aViewportInfo,
Packit f0b94e
      const mozilla::ScreenIntSize& aDisplaySize,
Packit f0b94e
      const mozilla::CSSSize& aViewport,
Packit f0b94e
      const mozilla::Maybe<float>& aDisplayWidthChangeRatio);
Packit f0b94e
Packit f0b94e
  /* Updates the scroll-position-clamping scrollport size */
Packit f0b94e
  void UpdateSPCSPS(const mozilla::ScreenIntSize& aDisplaySize,
Packit f0b94e
                    const mozilla::CSSToScreenScale& aZoom);
Packit f0b94e
Packit f0b94e
  /* Updates the displayport margins for the presShell's root scrollable frame
Packit f0b94e
   */
Packit f0b94e
  void UpdateDisplayPortMargins();
Packit f0b94e
Packit f0b94e
  nsCOMPtr<nsIDocument> mDocument;
Packit f0b94e
  nsIPresShell* MOZ_NON_OWNING_REF
Packit f0b94e
      mPresShell;  // raw ref since the presShell owns this
Packit f0b94e
  nsCOMPtr<nsIDOMEventTarget> mEventTarget;
Packit f0b94e
  bool mIsFirstPaint;
Packit f0b94e
  bool mPainted;
Packit f0b94e
  mozilla::LayoutDeviceIntSize mDisplaySize;
Packit f0b94e
  mozilla::CSSSize mMobileViewportSize;
Packit f0b94e
  mozilla::Maybe<float> mRestoreResolution;
Packit f0b94e
  mozilla::Maybe<mozilla::ScreenIntSize> mRestoreDisplaySize;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
#endif