tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ScrollLinkedEffectDetector.cpp (1434B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "ScrollLinkedEffectDetector.h"
      8 
      9 #include "mozilla/dom/Document.h"
     10 #include "nsThreadUtils.h"
     11 
     12 namespace mozilla {
     13 namespace layers {
     14 
     15 uint32_t ScrollLinkedEffectDetector::sDepth = 0;
     16 bool ScrollLinkedEffectDetector::sFoundScrollLinkedEffect = false;
     17 
     18 /* static */
     19 void ScrollLinkedEffectDetector::PositioningPropertyMutated() {
     20  MOZ_ASSERT(NS_IsMainThread());
     21 
     22  if (sDepth > 0) {
     23    // We are inside a scroll event dispatch
     24    sFoundScrollLinkedEffect = true;
     25  }
     26 }
     27 
     28 ScrollLinkedEffectDetector::ScrollLinkedEffectDetector(
     29    dom::Document* aDoc, const TimeStamp& aTimeStamp)
     30    : mDocument(aDoc), mTimeStamp(aTimeStamp) {
     31  MOZ_ASSERT(NS_IsMainThread());
     32  sDepth++;
     33 }
     34 
     35 ScrollLinkedEffectDetector::~ScrollLinkedEffectDetector() {
     36  sDepth--;
     37  if (sDepth == 0) {
     38    // We have exited all (possibly-nested) scroll event dispatches,
     39    // record whether or not we found an effect, and reset state
     40    if (sFoundScrollLinkedEffect) {
     41      mDocument->ReportHasScrollLinkedEffect(mTimeStamp);
     42      sFoundScrollLinkedEffect = false;
     43    }
     44  }
     45 }
     46 
     47 }  // namespace layers
     48 }  // namespace mozilla