author Mike Hommey <>
Thu, 17 Jan 2019 13:18:37 +0000
changeset 454358 c28522aaf3918c5f556c65432f8bf14a65bff65a
parent 451701 1f867de12312ea29fe968e7b23f743d3e9da87d5
child 468846 4d0388ce7f1addfbea33f535d2ffc8719b1e42f5
permissions -rw-r--r--
Bug 1520149 - Also disable the machine outliner on Android when LTO is enabled. r=dmajor Differential Revision:

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef mozilla_dom_VisualViewport_h
#define mozilla_dom_VisualViewport_h

#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/VisualViewportBinding.h"
#include "Units.h"
#include "nsIPresShell.h"

namespace mozilla {
namespace dom {

/* Visual Viewport API spec:
 * */
class VisualViewport final : public mozilla::DOMEventTargetHelper {
  explicit VisualViewport(nsPIDOMWindowInner* aWindow);

  double OffsetLeft() const;
  double OffsetTop() const;
  double PageLeft() const;
  double PageTop() const;
  double Width() const;
  double Height() const;
  double Scale() const;

  virtual JSObject* WrapObject(JSContext* aCx,
                               JS::Handle<JSObject*> aGivenProto) override;
  void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;

  void PostResizeEvent();
  void PostScrollEvent(const nsPoint& aPrevVisualOffset,
                       const nsPoint& aPrevLayoutOffset);

  // These two events are modelled after the ScrollEvent class in
  // nsGfxScrollFrame.h.
  class VisualViewportResizeEvent : public Runnable {
    VisualViewportResizeEvent(VisualViewport* aViewport,
                              nsPresContext* aPresContext);
    void Revoke() { mViewport = nullptr; }

    VisualViewport* mViewport;

  class VisualViewportScrollEvent : public Runnable {
    VisualViewportScrollEvent(VisualViewport* aViewport,
                              nsPresContext* aPresContext,
                              const nsPoint& aPrevVisualOffset,
                              const nsPoint& aPrevLayoutOffset);
    void Revoke() { mViewport = nullptr; }
    nsPoint PrevVisualOffset() const { return mPrevVisualOffset; }
    nsPoint PrevLayoutOffset() const { return mPrevLayoutOffset; }

    VisualViewport* mViewport;
    // The VisualViewport "scroll" event is supposed to be fired only when the
    // *relative* offset between visual and layout viewport changes. The two
    // viewports are updated independently from each other, though, so the only
    // thing we can do is note the fact that one of the inputs into the relative
    // visual viewport offset changed and then check the offset again at the
    // next refresh driver tick, just before the event is going to fire.
    // Hopefully, at this point both visual and layout viewport positions have
    // been updated, so that we're able to tell whether the relative offset did
    // in fact change or not.
    const nsPoint mPrevVisualOffset;
    const nsPoint mPrevLayoutOffset;

  virtual ~VisualViewport();

  CSSSize VisualViewportSize() const;
  CSSPoint VisualViewportOffset() const;
  CSSPoint LayoutViewportOffset() const;
  nsIPresShell* GetPresShell() const;
  nsPresContext* GetPresContext() const;

  void FireResizeEvent();
  void FireScrollEvent();

  RefPtr<VisualViewportResizeEvent> mResizeEvent;
  RefPtr<VisualViewportScrollEvent> mScrollEvent;

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_VisualViewport_h