tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CSSAlignUtils.h (3668B)


      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/EnumSet.h"
     13 #include "mozilla/WritingModes.h"
     14 
     15 namespace mozilla {
     16 
     17 struct ReflowInput;
     18 struct StyleAlignFlags;
     19 
     20 class CSSAlignUtils {
     21 public:
     22  /**
     23   * Map a raw StyleAlignFlags value to the used one.
     24   */
     25  static StyleAlignFlags UsedAlignmentForAbsPos(nsIFrame* aFrame,
     26                                                StyleAlignFlags aFlags,
     27                                                LogicalAxis aLogicalAxis,
     28                                                WritingMode aCBWM);
     29 
     30  /**
     31   * Flags to customize the behavior of AlignJustifySelf:
     32   */
     33  enum class AlignJustifyFlag {
     34    // Indicates that we have <overflow-position> = safe.
     35    OverflowSafe,
     36 
     37    // Indicates that the container's start side in aAxis is the same
     38    // as the child's start side in the child's parallel axis.
     39    SameSide,
     40 
     41    // Indicates that AlignJustifySelf() shouldn't expand "auto" margins.
     42    // (By default, AlignJustifySelf() *will* expand such margins, to fill the
     43    // available space before any alignment is done.)
     44    IgnoreAutoMargins,
     45 
     46    // We're aligning a margin box - the margin is already included in the
     47    // size. Implies `IgnoreAutoMargins`.
     48    AligningMarginBox,
     49 
     50    // If the item is baseline-aligned, this flag indicates that the item is in
     51    // the last baseline sharing group of the container, otherwise the item is
     52    // in the container's first baseline sharing group.
     53    LastBaselineSharingGroup,
     54  };
     55  using AlignJustifyFlags = EnumSet<AlignJustifyFlag>;
     56 
     57  /**
     58   * Additional information required to resolve anchor-center on a particular
     59   * axis.
     60   */
     61  struct AnchorAlignInfo {
     62    nscoord mAnchorStart;
     63    nscoord mAnchorSize;
     64  };
     65 
     66  /**
     67   * This computes the aligned offset of a CSS-aligned child within its
     68   * alignment container. The returned offset is distance between the
     69   * logical "start" edge of the alignment container & the logical "start" edge
     70   * of the aligned child (in terms of the alignment container's writing mode).
     71   *
     72   * @param aAlignment An enumerated value representing a keyword for
     73   *                   "align-self" or "justify-self". The values
     74   *                   StyleAlignFlags::{AUTO,LEFT,RIGHT} must *not* be
     75   *                   passed here; this method expects the caller to have
     76   *                   already resolved those to 'start', 'end', or 'stretch'.
     77   * @param aAxis The container's axis in which we're doing alignment.
     78   * @param aBaselineAdjust The amount to offset baseline-aligned children.
     79   * @param aCBSize The size of the alignment container, in its aAxis.
     80   * @param aRI A ReflowInput for the child.
     81   * @param aChildSize The child's LogicalSize (in its own writing mode).
     82   * @param aAnchorInfo When specified, an inset-modified anchor start and size
     83   * (in the child's writing mode) to use for anchor-center alignment.
     84   */
     85  static nscoord AlignJustifySelf(
     86      const StyleAlignFlags& aAlignment, LogicalAxis aAxis,
     87      AlignJustifyFlags aFlags, nscoord aBaselineAdjust, nscoord aCBSize,
     88      const ReflowInput& aRI, const LogicalSize& aChildSize,
     89      const Maybe<AnchorAlignInfo>& aAnchorRect = Nothing());
     90 };
     91 
     92 }  // namespace mozilla
     93 
     94 #endif  // mozilla_CSSAlignUtils_h