2018-08-20 23:28:42 +03:00
|
|
|
/* -*- 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#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:
|
|
|
|
* https://wicg.github.io/visual-viewport/#the-visualviewport-interface */
|
|
|
|
class VisualViewport final : public mozilla::DOMEventTargetHelper {
|
|
|
|
public:
|
|
|
|
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;
|
2018-12-21 20:08:47 +03:00
|
|
|
IMPL_EVENT_HANDLER(resize)
|
|
|
|
IMPL_EVENT_HANDLER(scroll)
|
2018-08-20 23:28:42 +03:00
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2018-12-21 00:35:26 +03:00
|
|
|
void PostResizeEvent();
|
|
|
|
void PostScrollEvent();
|
|
|
|
|
|
|
|
// These two events are modelled after the ScrollEvent class in
|
|
|
|
// nsGfxScrollFrame.h.
|
|
|
|
class VisualViewportResizeEvent : public Runnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
VisualViewportResizeEvent(VisualViewport* aViewport,
|
|
|
|
nsPresContext* aPresContext);
|
|
|
|
void Revoke() { mViewport = nullptr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
VisualViewport* mViewport;
|
|
|
|
};
|
|
|
|
|
|
|
|
class VisualViewportScrollEvent : public Runnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
VisualViewportScrollEvent(VisualViewport* aViewport,
|
|
|
|
nsPresContext* aPresContext);
|
|
|
|
void Revoke() { mViewport = nullptr; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
VisualViewport* mViewport;
|
|
|
|
};
|
|
|
|
|
2018-08-20 23:28:42 +03:00
|
|
|
private:
|
|
|
|
virtual ~VisualViewport();
|
|
|
|
|
|
|
|
CSSSize VisualViewportSize() const;
|
|
|
|
CSSPoint VisualViewportOffset() const;
|
|
|
|
CSSPoint LayoutViewportOffset() const;
|
|
|
|
nsIPresShell* GetPresShell() const;
|
2018-12-21 00:35:26 +03:00
|
|
|
nsPresContext* GetPresContext() const;
|
|
|
|
|
|
|
|
void FireResizeEvent();
|
|
|
|
void FireScrollEvent();
|
|
|
|
|
|
|
|
RefPtr<VisualViewportResizeEvent> mResizeEvent;
|
|
|
|
RefPtr<VisualViewportScrollEvent> mScrollEvent;
|
2018-08-20 23:28:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_VisualViewport_h
|