tor-browser

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

FlexItemValues.cpp (3762B)


      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 "FlexItemValues.h"
      8 
      9 #include "mozilla/dom/DOMRect.h"
     10 #include "mozilla/dom/FlexBinding.h"
     11 #include "mozilla/dom/FlexLineValues.h"
     12 #include "nsFlexContainerFrame.h"
     13 
     14 namespace mozilla::dom {
     15 
     16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItemValues, mParent, mNode,
     17                                      mFrameRect)
     18 NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItemValues)
     19 NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItemValues)
     20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItemValues)
     21  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     22  NS_INTERFACE_MAP_ENTRY(nsISupports)
     23 NS_INTERFACE_MAP_END
     24 
     25 /**
     26 * Utility function to convert a nscoord size to CSS pixel values, with
     27 * graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to
     28 * the double "positive infinity" value).
     29 *
     30 * This function is suitable for converting quantities that are expected to
     31 * sometimes legitimately (rather than arbitrarily/accidentally) contain the
     32 * sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none".
     33 */
     34 static double ToPossiblyUnconstrainedPixels(nscoord aSize) {
     35  if (aSize == NS_UNCONSTRAINEDSIZE) {
     36    return std::numeric_limits<double>::infinity();
     37  }
     38  return nsPresContext::AppUnitsToDoubleCSSPixels(aSize);
     39 }
     40 
     41 FlexItemValues::FlexItemValues(FlexLineValues* aParent,
     42                               const ComputedFlexItemInfo* aItem)
     43    : mParent(aParent) {
     44  MOZ_ASSERT(aItem,
     45             "Should never be instantiated with a null ComputedFlexLineInfo.");
     46 
     47  // Eagerly copy values from aItem, because we're not
     48  // going to keep it around.
     49  mNode = aItem->mNode;
     50 
     51  // Since mNode might be null, we associate the mFrameRect with
     52  // our parent.
     53  mFrameRect = new DOMRectReadOnly(
     54      mParent, nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.X()),
     55      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Y()),
     56      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Width()),
     57      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mFrameRect.Height()));
     58 
     59  // Convert app unit sizes to css pixel sizes.
     60  mMainBaseSize =
     61      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainBaseSize);
     62  mMainDeltaSize =
     63      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainDeltaSize);
     64  mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mMainMinSize);
     65  mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize);
     66  mCrossMinSize =
     67      nsPresContext::AppUnitsToDoubleCSSPixels(aItem->mCrossMinSize);
     68  mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize);
     69 
     70  mClampState = aItem->mClampState;
     71 }
     72 
     73 JSObject* FlexItemValues::WrapObject(JSContext* aCx,
     74                                     JS::Handle<JSObject*> aGivenProto) {
     75  return FlexItemValues_Binding::Wrap(aCx, this, aGivenProto);
     76 }
     77 
     78 nsINode* FlexItemValues::GetNode() const { return mNode; }
     79 
     80 DOMRectReadOnly* FlexItemValues::FrameRect() const { return mFrameRect; }
     81 
     82 double FlexItemValues::MainBaseSize() const { return mMainBaseSize; }
     83 
     84 double FlexItemValues::MainDeltaSize() const { return mMainDeltaSize; }
     85 
     86 double FlexItemValues::MainMinSize() const { return mMainMinSize; }
     87 
     88 double FlexItemValues::MainMaxSize() const { return mMainMaxSize; }
     89 
     90 double FlexItemValues::CrossMinSize() const { return mCrossMinSize; }
     91 
     92 double FlexItemValues::CrossMaxSize() const { return mCrossMaxSize; }
     93 
     94 FlexItemClampState FlexItemValues::ClampState() const { return mClampState; }
     95 
     96 }  // namespace mozilla::dom