Bug 1478776 - Part 10: Add internal VisualViewport resize/scroll events. r=botond,nika
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 20 Dec 2018 22:14:42 +0000
changeset 451701 1f867de12312ea29fe968e7b23f743d3e9da87d5
parent 451700 4d4e9b8110451b9393b44078e32d1c36b7c31968
child 451702 a5756686b400e8274b8395fa9365aed9f776cbd9
push id35251
push userccoroiu@mozilla.com
push dateFri, 21 Dec 2018 21:54:30 +0000
treeherdermozilla-central@74101900e7d4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond, nika
bugs1478776, 1498812
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1478776 - Part 10: Add internal VisualViewport resize/scroll events. r=botond,nika The VisualViewport events are all nice and shiny, but unfortunately not quite what is needed for the session store. Firstly, the spec wants the "scroll" event to be fired only when the *relative* offset between visual and layout viewport changes. The session store however records the absolute offset and as such is interested in when *that* changes. Secondly, again as per the spec the events don't bubble, and with the default DOMEventTargetHelper implementation they don't escape the VisualViewport during capturing, either. This means that any event listener must be added directly on the VisualViewport itself in order to capture any events. This might have been intended because the events use the same names as the normal "scroll"/"resize" events, and as such you cannot specify separate event listeners for VisualViewport and non-VisualViewport "scroll" events if both events end up being dispatched to the same element (you can only try to filter after the fact by looking at the originalTarget of the event). At the same time, the VisualViewport is attached to the inner Window, and so each time you navigate, you also get a different VisualViewport object. All of this might be totally fine from the perspective of a page script, because in that case you won't care anyway about what happens when the current page goes away. From the session store perspective on the other hand (especially Fennec's non- e10s session store design), this is rather unfortunate because we don't want to have to keep registering event listeners a) manually for each subframe b) each time the page navigates The event target chain problem could be solved by letting the scroll events escape the VisualViewport during the capturing phase (which the spec doesn't say anything about), but this would mean that any scroll listener attached to a window/browser/... that uses capturing will now catch both layout and visual viewport scroll events. In some cases this might even be beneficial, but in others (e.g. bug 1498812 comment 21) I'd like to specifically decide which kind of scroll event to capture. Having to look at event.originalTarget to distinguish the two kinds might be defensible in test code, but in case this distinction would be needed in production code as well, given the existence of a C++-based filtering helper in nsSessionStoreUtils for another use case where (scroll) events need to be filtered, JS-based scroll event filtering might be a bad idea. Additionally, in any case this wouldn't solve the fundamental conflict between the spec and the session store about *when* the "scroll" event should be fired in the first place. Hence I'd like to introduce a separate set of events with distinct event names, which will be dispatched according to the requirements of our internal users (i.e. currently the session store). To avoid potential web compatibility issues down the road, for now these events will be dispatched only to event listeners registered in the system group (allowing *all* Chrome event listeners cannot be done because checking the Chrome status of each event target might be too expensive for frequently dispatched events). Differential Revision: https://phabricator.services.mozilla.com/D14046
dom/base/VisualViewport.cpp
dom/base/VisualViewport.h
dom/events/EventNameList.h
gfx/layers/apz/test/mochitest/helper_basic_pan.html
gfx/layers/apz/test/mochitest/helper_basic_zoom.html
gfx/layers/apz/util/APZCCallbackHelper.cpp
layout/base/PresShell.cpp
layout/base/nsIPresShell.h
layout/generic/nsGfxScrollFrame.cpp
widget/BasicEvents.h
widget/EventMessageList.h
xpcom/ds/StaticAtoms.py
--- a/dom/base/VisualViewport.cpp
+++ b/dom/base/VisualViewport.cpp
@@ -33,16 +33,34 @@ VisualViewport::~VisualViewport() {
 }
 
 /* virtual */
 JSObject* VisualViewport::WrapObject(JSContext* aCx,
                                      JS::Handle<JSObject*> aGivenProto) {
   return VisualViewport_Binding::Wrap(aCx, this, aGivenProto);
 }
 
+/* virtual */
+void VisualViewport::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
+  EventMessage msg = aVisitor.mEvent->mMessage;
+
+  aVisitor.mCanHandle = true;
+  EventTarget* parentTarget = nullptr;
+  // Only our special internal events are allowed to escape the
+  // Visual Viewport and be dispatched further up the DOM tree.
+  if (msg == eMozVisualScroll || msg == eMozVisualResize) {
+    if (nsPIDOMWindowInner* win = GetOwner()) {
+      if (nsIDocument* doc = win->GetExtantDoc()) {
+        parentTarget = doc;
+      }
+    }
+  }
+  aVisitor.SetParentTarget(parentTarget, false);
+}
+
 CSSSize VisualViewport::VisualViewportSize() const {
   CSSSize size = CSSSize(0, 0);
 
   nsIPresShell* presShell = GetPresShell();
   if (presShell) {
     if (presShell->IsVisualViewportSizeSet()) {
       size = CSSRect::FromAppUnits(presShell->GetVisualViewportSize());
     } else {
@@ -158,70 +176,87 @@ VisualViewport::VisualViewportResizeEven
   return NS_OK;
 }
 
 void VisualViewport::FireResizeEvent() {
   MOZ_ASSERT(mResizeEvent);
   mResizeEvent->Revoke();
   mResizeEvent = nullptr;
 
+  VVP_LOG("%p, FireResizeEvent, fire mozvisualresize\n", this);
+  WidgetEvent mozEvent(true, eMozVisualResize);
+  mozEvent.mFlags.mOnlySystemGroupDispatch = true;
+  EventDispatcher::Dispatch(this, GetPresContext(), &mozEvent);
+
   VVP_LOG("%p, FireResizeEvent, fire VisualViewport resize\n", this);
   WidgetEvent event(true, eResize);
   event.mFlags.mBubbles = false;
   event.mFlags.mCancelable = false;
   EventDispatcher::Dispatch(this, GetPresContext(), &event);
 }
 
 /* ================= Scroll event handling ================= */
 
-void VisualViewport::PostScrollEvent(const nsPoint& aPrevRelativeOffset) {
-  VVP_LOG("%p: PostScrollEvent, prevRelativeOffset %s\n", this,
-          ToString(aPrevRelativeOffset).c_str());
+void VisualViewport::PostScrollEvent(const nsPoint& aPrevVisualOffset,
+                                     const nsPoint& aPrevLayoutOffset) {
+  VVP_LOG("%p: PostScrollEvent, prevRelativeOffset=%s\n", this,
+          ToString(aPrevVisualOffset - aPrevLayoutOffset).c_str());
   if (mScrollEvent) {
     return;
   }
 
   // The event constructor will register itself with the refresh driver.
   if (nsPresContext* presContext = GetPresContext()) {
-    mScrollEvent =
-        new VisualViewportScrollEvent(this, presContext, aPrevRelativeOffset);
+    mScrollEvent = new VisualViewportScrollEvent(
+        this, presContext, aPrevVisualOffset, aPrevLayoutOffset);
     VVP_LOG("%p: PostScrollEvent, created new event\n", this);
   }
 }
 
 VisualViewport::VisualViewportScrollEvent::VisualViewportScrollEvent(
     VisualViewport* aViewport, nsPresContext* aPresContext,
-    const nsPoint& aPrevRelativeOffset)
+    const nsPoint& aPrevVisualOffset, const nsPoint& aPrevLayoutOffset)
     : Runnable("VisualViewport::VisualViewportScrollEvent"),
       mViewport(aViewport),
-      mPrevRelativeOffset(aPrevRelativeOffset) {
+      mPrevVisualOffset(aPrevVisualOffset),
+      mPrevLayoutOffset(aPrevLayoutOffset) {
   aPresContext->RefreshDriver()->PostVisualViewportScrollEvent(this);
 }
 
 NS_IMETHODIMP
 VisualViewport::VisualViewportScrollEvent::Run() {
   if (mViewport) {
     mViewport->FireScrollEvent();
   }
   return NS_OK;
 }
 
 void VisualViewport::FireScrollEvent() {
   MOZ_ASSERT(mScrollEvent);
-  nsPoint prevRelativeOffset = mScrollEvent->PrevRelativeOffset();
+  nsPoint prevVisualOffset = mScrollEvent->PrevVisualOffset();
+  nsPoint prevLayoutOffset = mScrollEvent->PrevLayoutOffset();
   mScrollEvent->Revoke();
   mScrollEvent = nullptr;
 
-  nsIPresShell* presShell = GetPresShell();
-  // Check whether the relative visual viewport offset actually changed - maybe
-  // both visual and layout viewport scrolled together and there was no change
-  // after all.
-  if (presShell) {
+  if (nsIPresShell* presShell = GetPresShell()) {
+    if (presShell->GetVisualViewportOffset() != prevVisualOffset) {
+      // The internal event will be fired whenever the visual viewport's
+      // *absolute* offset changed, i.e. relative to the page.
+      VVP_LOG("%p: FireScrollEvent, fire mozvisualscroll\n", this);
+      WidgetEvent mozEvent(true, eMozVisualScroll);
+      mozEvent.mFlags.mOnlySystemGroupDispatch = true;
+      EventDispatcher::Dispatch(this, GetPresContext(), &mozEvent);
+    }
+
+    // Check whether the relative visual viewport offset actually changed -
+    // maybe both visual and layout viewport scrolled together and there was no
+    // change after all.
     nsPoint curRelativeOffset =
         presShell->GetVisualViewportOffsetRelativeToLayoutViewport();
+    nsPoint prevRelativeOffset = prevVisualOffset - prevLayoutOffset;
     VVP_LOG(
         "%p: FireScrollEvent, curRelativeOffset %s, "
         "prevRelativeOffset %s\n",
         this, ToString(curRelativeOffset).c_str(),
         ToString(prevRelativeOffset).c_str());
     if (curRelativeOffset != prevRelativeOffset) {
       VVP_LOG("%p, FireScrollEvent, fire VisualViewport scroll\n", this);
       WidgetGUIEvent event(true, eScroll, nullptr);
--- a/dom/base/VisualViewport.h
+++ b/dom/base/VisualViewport.h
@@ -28,19 +28,21 @@ class VisualViewport final : public mozi
   double Width() const;
   double Height() const;
   double Scale() const;
   IMPL_EVENT_HANDLER(resize)
   IMPL_EVENT_HANDLER(scroll)
 
   virtual JSObject* WrapObject(JSContext* aCx,
                                JS::Handle<JSObject*> aGivenProto) override;
+  void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
 
   void PostResizeEvent();
-  void PostScrollEvent(const nsPoint& aPrevRelativeOffset);
+  void PostScrollEvent(const nsPoint& aPrevVisualOffset,
+                       const nsPoint& aPrevLayoutOffset);
 
   // 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);
@@ -50,32 +52,35 @@ class VisualViewport final : public mozi
     VisualViewport* mViewport;
   };
 
   class VisualViewportScrollEvent : public Runnable {
    public:
     NS_DECL_NSIRUNNABLE
     VisualViewportScrollEvent(VisualViewport* aViewport,
                               nsPresContext* aPresContext,
-                              const nsPoint& aPrevRelativeOffset);
+                              const nsPoint& aPrevVisualOffset,
+                              const nsPoint& aPrevLayoutOffset);
     void Revoke() { mViewport = nullptr; }
-    nsPoint PrevRelativeOffset() const { return mPrevRelativeOffset; }
+    nsPoint PrevVisualOffset() const { return mPrevVisualOffset; }
+    nsPoint PrevLayoutOffset() const { return mPrevLayoutOffset; }
 
    private:
     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 mPrevRelativeOffset;
+    const nsPoint mPrevVisualOffset;
+    const nsPoint mPrevLayoutOffset;
   };
 
  private:
   virtual ~VisualViewport();
 
   CSSSize VisualViewportSize() const;
   CSSPoint VisualViewportOffset() const;
   CSSPoint LayoutViewportOffset() const;
--- a/dom/events/EventNameList.h
+++ b/dom/events/EventNameList.h
@@ -260,16 +260,20 @@ FORWARDED_EVENT(blur, eBlur, EventNameTy
 ERROR_EVENT(error, eLoadError, EventNameType_All, eBasicEventClass)
 FORWARDED_EVENT(focus, eFocus, EventNameType_HTMLXUL, eFocusEventClass)
 FORWARDED_EVENT(focusin, eFocusIn, EventNameType_HTMLXUL, eFocusEventClass)
 FORWARDED_EVENT(focusout, eFocusOut, EventNameType_HTMLXUL, eFocusEventClass)
 FORWARDED_EVENT(load, eLoad, EventNameType_All, eBasicEventClass)
 FORWARDED_EVENT(resize, eResize, EventNameType_All, eBasicEventClass)
 FORWARDED_EVENT(scroll, eScroll, (EventNameType_HTMLXUL | EventNameType_SVGSVG),
                 eBasicEventClass)
+NON_IDL_EVENT(mozvisualresize, eMozVisualResize, EventNameType_None,
+              eBasicEventClass)
+NON_IDL_EVENT(mozvisualscroll, eMozVisualScroll, EventNameType_None,
+              eBasicEventClass)
 
 WINDOW_EVENT(afterprint, eAfterPrint,
              EventNameType_XUL | EventNameType_HTMLBodyOrFramesetOnly,
              eBasicEventClass)
 WINDOW_EVENT(beforeprint, eBeforePrint,
              EventNameType_XUL | EventNameType_HTMLBodyOrFramesetOnly,
              eBasicEventClass)
 BEFOREUNLOAD_EVENT(beforeunload, eBeforeUnload,
--- a/gfx/layers/apz/test/mochitest/helper_basic_pan.html
+++ b/gfx/layers/apz/test/mochitest/helper_basic_pan.html
@@ -55,17 +55,17 @@ function* test(testDriver) {
   // a constant zero and therefore not cause any visual viewport scroll events
   // to fire.
   visScrEvt.unregister();
   is(visScrEvt.count, 0, "Got no visual viewport scroll events");
   visScrEvtInternal.unregister();
   // Our internal visual viewport scroll event on the other hand only cares
   // about the absolute offset of the visual viewport and should therefore
   // definitively fire.
-  todo(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
+  ok(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
 }
 
 waitUntilApzStable()
 .then(runContinuation(test))
 .then(subtestDone);
 
   </script>
 </head>
--- a/gfx/layers/apz/test/mochitest/helper_basic_zoom.html
+++ b/gfx/layers/apz/test/mochitest/helper_basic_zoom.html
@@ -55,26 +55,26 @@ function* test(testDriver) {
   let final_resolution = getResolution();
   ok(final_resolution > initial_resolution, 'The final resolution (' + final_resolution + ') is greater after zooming in');
 
   // Check we've got the expected events.
   // Pinch-zooming the page should fire visual viewport resize events:
   visResEvt.unregister();
   ok(visResEvt.count > 0, "Got some visual viewport resize events");
   visResEvtInternal.unregister();
-  todo(visResEvtInternal.count > 0, "Got some mozvisualresize events");
+  ok(visResEvtInternal.count > 0, "Got some mozvisualresize events");
 
   // We're pinch-zooming somewhere in the middle of the page, so the visual
   // viewport's coordinates change, too.
   // This is true both relative to the page (mozvisualscroll), as well as
   // relative to the layout viewport (visual viewport "scroll" event).
   visScrEvt.unregister();
   ok(visScrEvt.count > 0, "Got some visual viewport scroll events");
   visScrEvtInternal.unregister();
-  todo(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
+  ok(visScrEvtInternal.count > 0, "Got some mozvisualscroll events");
 
   // Our internal events shouldn't leak to normal content.
   visResEvtContent.unregister();
   is(visResEvtContent.count, 0, "Got no mozvisualresize events in content");
   visScrEvtContent.unregister();
   is(visScrEvtContent.count, 0, "Got no mozvisualscroll events in content");
 }
 
--- a/gfx/layers/apz/util/APZCCallbackHelper.cpp
+++ b/gfx/layers/apz/util/APZCCallbackHelper.cpp
@@ -171,17 +171,17 @@ static ScreenMargin ScrollFrame(nsIConte
       nsLayoutUtils::FindScrollableFrameFor(aRequest.GetScrollId());
   if (sf) {
     sf->ResetScrollInfoIfGeneration(aRequest.GetScrollGeneration());
     sf->SetScrollableByAPZ(!aRequest.IsScrollInfoLayer());
     if (sf->IsRootScrollFrameOfDocument()) {
       if (nsCOMPtr<nsIPresShell> shell = GetPresShell(aContent)) {
         shell->SetVisualViewportOffset(
             CSSPoint::ToAppUnits(aRequest.GetScrollOffset()),
-            shell->GetVisualViewportOffsetRelativeToLayoutViewport());
+            shell->GetLayoutViewportOffset());
       }
     }
   }
   bool scrollUpdated = false;
   ScreenMargin displayPortMargins = aRequest.GetDisplayPortMargins();
   CSSPoint apzScrollOffset = aRequest.GetScrollOffset();
   CSSPoint actualScrollOffset = ScrollFrameTo(sf, aRequest, scrollUpdated);
 
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -10037,23 +10037,25 @@ void nsIPresShell::SetVisualViewportSize
     MarkFixedFramesForReflow(nsIPresShell::eResize);
 
     if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) {
       window->VisualViewport()->PostResizeEvent();
     }
   }
 }
 
-void nsIPresShell::SetVisualViewportOffset(const nsPoint& aScrollOffset,
-                                           const nsPoint& aPrevRelativeOffset) {
+void nsIPresShell::SetVisualViewportOffset(
+    const nsPoint& aScrollOffset, const nsPoint& aPrevLayoutScrollPos) {
   if (mVisualViewportOffset != aScrollOffset) {
+    nsPoint prevOffset = mVisualViewportOffset;
     mVisualViewportOffset = aScrollOffset;
 
     if (auto* window = nsGlobalWindowInner::Cast(mDocument->GetInnerWindow())) {
-      window->VisualViewport()->PostScrollEvent(aPrevRelativeOffset);
+      window->VisualViewport()->PostScrollEvent(prevOffset,
+                                                aPrevLayoutScrollPos);
     }
   }
 }
 
 nsPoint nsIPresShell::GetVisualViewportOffsetRelativeToLayoutViewport() const {
   return GetVisualViewportOffset() - GetLayoutViewportOffset();
 }
 
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -1643,17 +1643,17 @@ class nsIPresShell : public nsStubDocume
   bool IsVisualViewportSizeSet() { return mVisualViewportSizeSet; }
   nsSize GetVisualViewportSize() {
     NS_ASSERTION(mVisualViewportSizeSet,
                  "asking for visual viewport size when its not set?");
     return mVisualViewportSize;
   }
 
   void SetVisualViewportOffset(const nsPoint& aScrollOffset,
-                               const nsPoint& aPrevRelativeOffset);
+                               const nsPoint& aPrevLayoutScrollPos);
 
   nsPoint GetVisualViewportOffset() const { return mVisualViewportOffset; }
 
   nsPoint GetVisualViewportOffsetRelativeToLayoutViewport() const;
 
   nsPoint GetLayoutViewportOffset() const;
 
   virtual void WindowSizeMoveDone() = 0;
--- a/layout/generic/nsGfxScrollFrame.cpp
+++ b/layout/generic/nsGfxScrollFrame.cpp
@@ -2671,19 +2671,16 @@ void ScrollFrameHelper::ScrollToImpl(nsP
       std::max(visualViewportSize.width / std::max(sHorzScrollFraction, 1),
                AppUnitsPerCSSPixel());
   nscoord vertAllowance =
       std::max(visualViewportSize.height / std::max(sVertScrollFraction, 1),
                AppUnitsPerCSSPixel());
   if (dist.x >= horzAllowance || dist.y >= vertAllowance) {
     needFrameVisibilityUpdate = true;
   }
-  nsPoint prevVVRelativeOffset =
-      presContext->PresShell()
-          ->GetVisualViewportOffsetRelativeToLayoutViewport();
 
   // notify the listeners.
   for (uint32_t i = 0; i < mListeners.Length(); i++) {
     mListeners[i]->ScrollPositionWillChange(pt.x, pt.y);
   }
 
   nsRect oldDisplayPort;
   nsIContent* content = mOuter->GetContent();
@@ -2735,17 +2732,17 @@ void ScrollFrameHelper::ScrollToImpl(nsP
     content->SetProperty(nsGkAtoms::apzCallbackTransform, new CSSPoint(),
                          nsINode::DeleteProperty<CSSPoint>);
 
     // Similarly, update the main thread's view of the visual viewport
     // offset. Otherwise, if we perform calculations that depend on this
     // offset (e.g. by using nsIDOMWindowUtils.getVisualViewportOffset()
     // in chrome JS code) before it's updated by the next APZ repaint,
     // we could get incorrect results.
-    presContext->PresShell()->SetVisualViewportOffset(pt, prevVVRelativeOffset);
+    presContext->PresShell()->SetVisualViewportOffset(pt, curPos);
   }
 
   ScrollVisual();
 
   bool schedulePaint = true;
   if (nsLayoutUtils::AsyncPanZoomEnabled(mOuter) &&
       !nsLayoutUtils::ShouldDisableApzForElement(content) &&
       gfxPrefs::APZPaintSkipping()) {
@@ -2861,17 +2858,18 @@ void ScrollFrameHelper::ScrollToImpl(nsP
 
   PostScrollEvent();
   // If this is a viewport scroll, this could affect the relative offset
   // between layout and visual viewport, so we might have to fire a visual
   // viewport scroll event as well.
   if (mIsRoot) {
     if (auto* window = nsGlobalWindowInner::Cast(
             mOuter->PresContext()->Document()->GetInnerWindow())) {
-      window->VisualViewport()->PostScrollEvent(prevVVRelativeOffset);
+      window->VisualViewport()->PostScrollEvent(
+          presContext->PresShell()->GetVisualViewportOffset(), curPos);
     }
   }
 
   // notify the listeners.
   for (uint32_t i = 0; i < mListeners.Length(); i++) {
     mListeners[i]->ScrollPositionDidChange(pt.x, pt.y);
   }
 
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -452,17 +452,18 @@ class WidgetEvent : public WidgetEventTi
       case eCompositionEventClass:
         // XXX compositionstart is cancelable in draft of DOM3 Events.
         //     However, it doesn't make sense for us, we cannot cancel
         //     composition when we send compositionstart event.
         mFlags.mCancelable = false;
         mFlags.mBubbles = true;
         break;
       default:
-        if (mMessage == eResize || mMessage == eEditorInput) {
+        if (mMessage == eResize || mMessage == eMozVisualResize ||
+            mMessage == eMozVisualScroll || mMessage == eEditorInput) {
           mFlags.mCancelable = false;
         } else {
           mFlags.mCancelable = true;
         }
         mFlags.mBubbles = true;
         break;
     }
   }
--- a/widget/EventMessageList.h
+++ b/widget/EventMessageList.h
@@ -50,16 +50,18 @@ NS_EVENT_MESSAGE(eKeyUpOnPlugin)
 // This message is sent after a content process handles a key event or accesskey
 // to indicate that an potential accesskey was not found. The parent process may
 // then respond by, for example, opening menus and processing other shortcuts.
 // It inherits its properties from a keypress event.
 NS_EVENT_MESSAGE(eAccessKeyNotFound)
 
 NS_EVENT_MESSAGE(eResize)
 NS_EVENT_MESSAGE(eScroll)
+NS_EVENT_MESSAGE(eMozVisualResize)
+NS_EVENT_MESSAGE(eMozVisualScroll)
 
 // Application installation
 NS_EVENT_MESSAGE(eInstall)
 NS_EVENT_MESSAGE(eAppInstalled)
 
 // A plugin was clicked or otherwise focused. ePluginActivate should be
 // used when the window is not active. ePluginFocus should be used when
 // the window is active. In the latter case, the dispatcher of the event
--- a/xpcom/ds/StaticAtoms.py
+++ b/xpcom/ds/StaticAtoms.py
@@ -1876,16 +1876,20 @@ STATIC_ATOMS = [
     Atom("onuserproximity", "onuserproximity"),
 
     # light sensor support
     Atom("ondevicelight", "ondevicelight"),
 
     # MediaDevices device change event
     Atom("ondevicechange", "ondevicechange"),
 
+    # Internal Visual Viewport events
+    Atom("onmozvisualresize", "onmozvisualresize"),
+    Atom("onmozvisualscroll", "onmozvisualscroll"),
+
     # WebExtensions
     Atom("moz_extension", "moz-extension"),
     Atom("all_urlsPermission", "<all_urls>"),
     Atom("clipboardRead", "clipboardRead"),
     Atom("clipboardWrite", "clipboardWrite"),
     Atom("debugger", "debugger"),
     Atom("mozillaAddons", "mozillaAddons"),
     Atom("tabs", "tabs"),