Backed out 2 changesets (bug 1926145, bug 1924850) for causing bc failures @ browser_...
[gecko.git] / layout / generic / ColumnUtils.cpp
blob6f1f54824f1f48620c41a74e7bd90c8c7554f9b5
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/. */
7 /* A namespace class for static muti-column utilities. */
9 #include "mozilla/ColumnUtils.h"
11 #include <algorithm>
13 #include "nsContainerFrame.h"
14 #include "nsLayoutUtils.h"
16 namespace mozilla {
18 /* static */
19 nscoord ColumnUtils::GetColumnGap(const nsContainerFrame* aFrame,
20 nscoord aPercentageBasis) {
21 const auto& columnGap = aFrame->StylePosition()->mColumnGap;
22 if (columnGap.IsNormal()) {
23 return aFrame->StyleFont()->mFont.size.ToAppUnits();
25 return nsLayoutUtils::ResolveGapToLength(columnGap, aPercentageBasis);
28 /* static */
29 nscoord ColumnUtils::ClampUsedColumnWidth(const Length& aColumnWidth) {
30 // Per spec, used values will be clamped to a minimum of 1px.
31 return std::max(CSSPixel::ToAppUnits(1), aColumnWidth.ToAppUnits());
34 /* static */
35 nscoord ColumnUtils::IntrinsicISize(uint32_t aColCount, nscoord aColGap,
36 nscoord aColISize) {
37 MOZ_ASSERT(aColCount > 0, "Cannot compute with zero columns!");
39 // Column box's inline-size times number of columns (n), plus n-1 column gaps.
40 nscoord iSize = aColISize * aColCount + aColGap * (aColCount - 1);
42 // The multiplication above can make 'iSize' negative (integer overflow),
43 // so use std::max to protect against that.
44 return std::max(iSize, aColISize);
47 } // namespace mozilla