tor-browser

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

Baseline.h (3141B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef LAYOUT_BASE_BASELINE_H_
      6 #define LAYOUT_BASE_BASELINE_H_
      7 
      8 #include "mozilla/WritingModes.h"
      9 #include "nsCoord.h"
     10 
     11 class nsIFrame;
     12 
     13 namespace mozilla {
     14 
     15 // https://drafts.csswg.org/css-align-3/#baseline-sharing-group
     16 enum class BaselineSharingGroup : uint8_t {
     17  // NOTE Used as an array index so must be 0 and 1.
     18  First = 0,
     19  Last = 1,
     20 };
     21 
     22 inline BaselineSharingGroup GetOppositeBaselineSharingGroup(
     23    BaselineSharingGroup aBaselineSharingGroup) {
     24  return aBaselineSharingGroup == BaselineSharingGroup::First
     25             ? BaselineSharingGroup::Last
     26             : BaselineSharingGroup::First;
     27 }
     28 
     29 // Layout context under which the baseline is being exported to.
     30 enum class BaselineExportContext : uint8_t {
     31  LineLayout = 0,
     32  Other = 1,
     33 };
     34 
     35 class Baseline {
     36 public:
     37  /**
     38   * Synthesize a first(last) inline-axis baseline in aWM based on aFrame's
     39   * margin-box.
     40   *
     41   * An alphabetical baseline is at the end edge of aFrame's margin-box with
     42   * respect to aWM's block-axis, and a central baseline is halfway between the
     43   * start and end edges. (aWM tells which baseline to use.)
     44   * https://drafts.csswg.org/css-align-3/#synthesize-baseline
     45   *
     46   * @note This works only when aFrame's writing-mode is parallel to aWM.
     47   * @param aWM the writing-mode of the alignment context.
     48   * @return an offset from aFrame's border-box start(end) edge in aWM's
     49   *         block-axis for a first(last) baseline, respectively.
     50   */
     51  static nscoord SynthesizeBOffsetFromMarginBox(const nsIFrame* aFrame,
     52                                                WritingMode aWM,
     53                                                BaselineSharingGroup);
     54 
     55  /**
     56   * Synthesize a first(last) inline-axis baseline in aWM based on aFrame's
     57   * border-box.
     58   *
     59   * An alphabetical baseline is at the end edge of aFrame's border-box with
     60   * respect to aWM's block-axis, and a central baseline is halfway between the
     61   * start and end edges. (aWM tells which baseline to use.)
     62   * https://drafts.csswg.org/css-align-3/#synthesize-baseline
     63   *
     64   * @param aWM the writing-mode of the alignment context.
     65   * @return an offset from aFrame's border-box start(end) edge in aWM's
     66   *         block-axis for a first(last) baseline, respectively.
     67   */
     68  static nscoord SynthesizeBOffsetFromBorderBox(const nsIFrame* aFrame,
     69                                                WritingMode aWM,
     70                                                BaselineSharingGroup);
     71  /**
     72   * As above, but using the content box.
     73   */
     74  static nscoord SynthesizeBOffsetFromContentBox(const nsIFrame*, WritingMode,
     75                                                 BaselineSharingGroup);
     76  /**
     77   * As above, but using the padding box.
     78   */
     79  static nscoord SynthesizeBOffsetFromPaddingBox(const nsIFrame*, WritingMode,
     80                                                 BaselineSharingGroup);
     81 };
     82 
     83 }  // namespace mozilla
     84 
     85 #endif  // LAYOUT_BASE_BASELINE_H_