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