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 /* Utility code for performing CSS Box Alignment */
8 
9 #ifndef mozilla_CSSAlignUtils_h
10 #define mozilla_CSSAlignUtils_h
11 
12 #include "mozilla/WritingModes.h"
13 
14 namespace mozilla {
15 
16 struct ReflowInput;
17 struct StyleAlignFlags;
18 
19 class CSSAlignUtils {
20  public:
21   /**
22    * Flags to customize the behavior of AlignJustifySelf:
23    */
24   enum class AlignJustifyFlags {
25     NoFlags = 0,
26     // Indicates that we have <overflow-position> = safe.
27     OverflowSafe = 1 << 0,
28     // Indicates that the container's start side in aAxis is the same
29     // as the child's start side in the child's parallel axis.
30     SameSide = 1 << 1,
31     // Indicates that AlignJustifySelf() shouldn't expand "auto" margins.
32     // (By default, AlignJustifySelf() *will* expand such margins, to fill the
33     // available space before any alignment is done.)
34     IgnoreAutoMargins = 1 << 2,
35   };
36 
37   /**
38    * This computes the aligned offset of a CSS-aligned child within its
39    * alignment container. The returned offset is distance between the
40    * logical "start" edge of the alignment container & the logical "start" edge
41    * of the aligned child (in terms of the alignment container's writing mode).
42    *
43    * @param aAlignment An enumerated value representing a keyword for
44    *                   "align-self" or "justify-self". The values
45    *                   StyleAlignFlags::{AUTO,LEFT,RIGHT} must *not* be
46    *                   passed here; this method expects the caller to have
47    *                   already resolved those to 'start', 'end', or 'stretch'.
48    * @param aAxis The container's axis in which we're doing alignment.
49    * @param aBaselineAdjust The amount to offset baseline-aligned children.
50    * @param aCBSize The size of the alignment container, in its aAxis.
51    * @param aRI A ReflowInput for the child.
52    * @param aChildSize The child's LogicalSize (in its own writing mode).
53    */
54   static nscoord AlignJustifySelf(const StyleAlignFlags& aAlignment,
55                                   LogicalAxis aAxis, AlignJustifyFlags aFlags,
56                                   nscoord aBaselineAdjust, nscoord aCBSize,
57                                   const ReflowInput& aRI,
58                                   const LogicalSize& aChildSize);
59 };
60 
61 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CSSAlignUtils::AlignJustifyFlags)
62 
63 }  // namespace mozilla
64 
65 #endif  // mozilla_CSSAlignUtils_h
66