layout/generic/AspectRatio.cpp
author Dragana Damjanovic <dd.mozilla@gmail.com>
Thu, 06 May 2021 18:10:45 +0000
changeset 578757 c9980e971a31b2bd47783dc4a9a26fca4a4c57d6
parent 561709 c86f4e7967e31ea0d0bcc67ff4127ee5b125fb66
permissions -rw-r--r--
Bug 1708678 - Adapt code to neqo 0.4.24 r=necko-reviewers,valentin Differential Revision: https://phabricator.services.mozilla.com/D114011

/* -*- 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/. */

#include "AspectRatio.h"

#include "mozilla/WritingModes.h"

namespace mozilla {

nscoord AspectRatio::ComputeRatioDependentSize(
    LogicalAxis aRatioDependentAxis, const WritingMode& aWM,
    nscoord aRatioDeterminingSize,
    const LogicalSize& aContentBoxSizeToBoxSizingAdjust) const {
  MOZ_ASSERT(*this,
             "Infinite or zero ratio may have undefined behavior when "
             "computing the size");
  const LogicalSize& boxSizingAdjust = mUseBoxSizing == UseBoxSizing::No
                                           ? LogicalSize(aWM)
                                           : aContentBoxSizeToBoxSizingAdjust;
  return aRatioDependentAxis == LogicalAxis::eLogicalAxisInline
             ? ConvertToWritingMode(aWM).ApplyTo(aRatioDeterminingSize +
                                                 boxSizingAdjust.BSize(aWM)) -
                   boxSizingAdjust.ISize(aWM)
             : ConvertToWritingMode(aWM).Inverted().ApplyTo(
                   aRatioDeterminingSize + boxSizingAdjust.ISize(aWM)) -
                   boxSizingAdjust.BSize(aWM);
}

}  // namespace mozilla