tor-browser

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

ScrollStyles.cpp (1819B)


      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 "mozilla/ScrollStyles.h"
      8 
      9 #include "nsStyleStruct.h"  // for nsStyleDisplay
     10 
     11 namespace mozilla {
     12 
     13 // https://drafts.csswg.org/css-overflow/#overflow-propagation
     14 // "If `visible` is applied to the viewport, it must be interpreted as `auto`.
     15 //  If `clip` is applied to the viewport, it must be interpreted as `hidden`."
     16 static StyleOverflow MapOverflowValueForViewportPropagation(
     17    StyleOverflow aOverflow) {
     18  switch (aOverflow) {
     19    case StyleOverflow::Visible:
     20      return StyleOverflow::Auto;
     21    case StyleOverflow::Clip:
     22      return StyleOverflow::Hidden;
     23    default:
     24      return aOverflow;
     25  }
     26 }
     27 
     28 ScrollStyles::ScrollStyles(StyleOverflow aH, StyleOverflow aV)
     29    : mHorizontal(aH), mVertical(aV) {
     30  MOZ_ASSERT(mHorizontal == StyleOverflow::Auto ||
     31             mHorizontal == StyleOverflow::Hidden ||
     32             mHorizontal == StyleOverflow::Scroll);
     33  MOZ_ASSERT(mVertical == StyleOverflow::Auto ||
     34             mVertical == StyleOverflow::Hidden ||
     35             mVertical == StyleOverflow::Scroll);
     36 }
     37 
     38 ScrollStyles::ScrollStyles(const nsStyleDisplay& aDisplay,
     39                           MapOverflowToValidScrollStyleTag)
     40    : ScrollStyles(
     41          MapOverflowValueForViewportPropagation(aDisplay.mOverflowX),
     42          MapOverflowValueForViewportPropagation(aDisplay.mOverflowY)) {}
     43 
     44 bool ScrollStyles::IsHiddenInBothDirections() const {
     45  return mHorizontal == StyleOverflow::Hidden &&
     46         mVertical == StyleOverflow::Hidden;
     47 }
     48 
     49 }  // namespace mozilla