ColumnUtils.cpp (1660B)
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 /* A namespace class for static muti-column utilities. */ 8 9 #include "mozilla/ColumnUtils.h" 10 11 #include <algorithm> 12 13 #include "nsContainerFrame.h" 14 #include "nsLayoutUtils.h" 15 16 namespace mozilla { 17 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(); 24 } 25 return nsLayoutUtils::ResolveGapToLength(columnGap, aPercentageBasis); 26 } 27 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(AppUnitsPerCSSPixel(), aColumnWidth.ToAppUnits()); 32 } 33 34 /* static */ 35 nscoord ColumnUtils::IntrinsicISize(uint32_t aColCount, nscoord aColGap, 36 nscoord aColISize) { 37 MOZ_ASSERT(aColCount > 0, "Cannot compute with zero columns!"); 38 39 // Column box's inline-size times number of columns (n), plus n-1 column gaps. 40 nscoord iSize = aColISize * aColCount + aColGap * (aColCount - 1); 41 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); 45 } 46 47 } // namespace mozilla