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 /* constants used throughout the Layout module */ 8 9 #ifndef LayoutConstants_h___ 10 #define LayoutConstants_h___ 11 12 #include "mozilla/EnumSet.h" 13 #include "nsSize.h" // for NS_MAXSIZE 14 #include "Units.h" 15 16 /** 17 * Constant used to indicate an unconstrained size. 18 * 19 * NOTE: The constants defined in this file are semantically used as symbolic 20 * values, so user should not depend on the underlying numeric values. If 21 * new specific use cases arise, define a new constant here. 22 */ 23 #define NS_UNCONSTRAINEDSIZE NS_MAXSIZE 24 25 // NS_AUTOOFFSET is assumed to have the same value as NS_UNCONSTRAINEDSIZE. 26 #define NS_AUTOOFFSET NS_UNCONSTRAINEDSIZE 27 28 // +1 is to avoid clamped huge margin values being processed as auto margins 29 #define NS_AUTOMARGIN (NS_UNCONSTRAINEDSIZE + 1) 30 31 #define NS_INTRINSIC_ISIZE_UNKNOWN nscoord_MIN 32 33 namespace mozilla { 34 35 /** 36 * Bit-flags to pass to various functions that compute sizes like 37 * nsIFrame::ComputeSize(). 38 */ 39 enum class ComputeSizeFlag : uint8_t { 40 /** 41 * Set if the frame is in a context where non-replaced blocks should 42 * shrink-wrap (e.g., it's floating, absolutely positioned, or 43 * inline-block). 44 */ 45 ShrinkWrap, 46 47 /** 48 * Set if we'd like to compute our 'auto' bsize, regardless of our actual 49 * corresponding computed value. (e.g. to get an intrinsic bsize for flex 50 * items when resolving automatic minimum size in the main axis during flexbox 51 * layout.) 52 */ 53 UseAutoBSize, 54 55 /** 56 * Indicates that we should clamp the margin-box min-size to the given CB 57 * size. This is used for implementing the grid area clamping here: 58 * https://drafts.csswg.org/css-grid/#min-size-auto 59 */ 60 IClampMarginBoxMinSize, // clamp in our inline axis 61 BClampMarginBoxMinSize, // clamp in our block axis 62 63 /** 64 * The frame is stretching (per CSS Box Alignment) and doesn't have an 65 * Automatic Minimum Size in the indicated axis. 66 * (may be used for both flex/grid items, but currently only used for Grid) 67 * https://drafts.csswg.org/css-grid/#min-size-auto 68 * https://drafts.csswg.org/css-align-3/#valdef-justify-self-stretch 69 */ 70 IApplyAutoMinSize, // only has an effect when eShrinkWrap is false 71 }; 72 using ComputeSizeFlags = mozilla::EnumSet<ComputeSizeFlag>; 73 74 /** 75 * The fallback size of width is 300px and the aspect-ratio is 2:1, based on 76 * CSS2 section 10.3.2 and CSS Sizing Level 3 section 5.1: 77 * https://drafts.csswg.org/css2/visudet.html#inline-replaced-width 78 * https://drafts.csswg.org/css-sizing-3/#intrinsic-sizes 79 */ 80 inline constexpr CSSIntCoord kFallbackIntrinsicWidthInPixels(300); 81 inline constexpr CSSIntCoord kFallbackIntrinsicHeightInPixels(150); 82 inline constexpr CSSIntSize kFallbackIntrinsicSizeInPixels( 83 kFallbackIntrinsicWidthInPixels, kFallbackIntrinsicHeightInPixels); 84 85 inline constexpr nscoord kFallbackIntrinsicWidth = 86 kFallbackIntrinsicWidthInPixels * AppUnitsPerCSSPixel(); 87 inline constexpr nscoord kFallbackIntrinsicHeight = 88 kFallbackIntrinsicHeightInPixels * AppUnitsPerCSSPixel(); 89 inline constexpr nsSize kFallbackIntrinsicSize(kFallbackIntrinsicWidth, 90 kFallbackIntrinsicHeight); 91 92 /** 93 * This is used in some nsLayoutUtils functions. 94 * Declared here so that fewer files need to include nsLayoutUtils.h. 95 */ 96 enum class IntrinsicISizeType { MinISize, PrefISize }; 97 98 } // namespace mozilla 99 100 #endif // LayoutConstants_h___ 101