tor-browser

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

nsIFrameInlines.h (7112B)


      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 #ifndef nsIFrameInlines_h___
      8 #define nsIFrameInlines_h___
      9 
     10 #include "mozilla/ComputedStyleInlines.h"
     11 #include "mozilla/dom/ElementInlines.h"
     12 #include "nsCSSAnonBoxes.h"
     13 #include "nsContainerFrame.h"
     14 #include "nsFrameManager.h"
     15 #include "nsIContentInlines.h"
     16 #include "nsLayoutUtils.h"
     17 #include "nsPlaceholderFrame.h"
     18 
     19 bool nsIFrame::IsFlexItem() const {
     20  return GetParent() && GetParent()->IsFlexContainerFrame() &&
     21         !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
     22 }
     23 
     24 bool nsIFrame::IsGridItem() const {
     25  return GetParent() && GetParent()->IsGridContainerFrame() &&
     26         !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW);
     27 }
     28 
     29 bool nsIFrame::IsFlexOrGridContainer() const {
     30  return IsFlexContainerFrame() || IsGridContainerFrame();
     31 }
     32 
     33 bool nsIFrame::IsFlexOrGridItem() const {
     34  return !HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) && GetParent() &&
     35         GetParent()->IsFlexOrGridContainer();
     36 }
     37 
     38 bool nsIFrame::IsLegacyWebkitBox() const {
     39  MOZ_ASSERT(
     40      IsFlexContainerFrame(),
     41      "The state-bit is meaningful when this is a nsFlexContainerFrame!");
     42  return HasAnyStateBits(NS_STATE_FLEX_IS_EMULATING_LEGACY_WEBKIT_BOX);
     43 }
     44 
     45 bool nsIFrame::IsMasonry(mozilla::WritingMode aWM,
     46                         mozilla::LogicalAxis aAxis) const {
     47  MOZ_DIAGNOSTIC_ASSERT(IsGridContainerFrame());
     48  const auto axisInOurWM = aWM.ConvertAxisTo(aAxis, GetWritingMode());
     49  return HasAnyStateBits(axisInOurWM == mozilla::LogicalAxis::Block
     50                             ? NS_STATE_GRID_IS_ROW_MASONRY
     51                             : NS_STATE_GRID_IS_COL_MASONRY);
     52 }
     53 
     54 bool nsIFrame::IsTableCaption() const {
     55  return StyleDisplay()->mDisplay == mozilla::StyleDisplay::TableCaption &&
     56         GetParent()->Style()->GetPseudoType() ==
     57             mozilla::PseudoStyleType::tableWrapper;
     58 }
     59 
     60 bool nsIFrame::IsFloating() const {
     61  return HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
     62         StyleDisplay()->IsFloating(this);
     63 }
     64 
     65 bool nsIFrame::IsAbsPosContainingBlock() const {
     66  return Style()->IsAbsPosContainingBlock(this);
     67 }
     68 
     69 bool nsIFrame::IsFixedPosContainingBlock() const {
     70  return Style()->IsFixedPosContainingBlock(this);
     71 }
     72 
     73 bool nsIFrame::IsRelativelyOrStickyPositioned() const {
     74  return StyleDisplay()->IsRelativelyOrStickyPositioned(this);
     75 }
     76 
     77 bool nsIFrame::HasAnchorPosName() const {
     78  return StyleDisplay()->HasAnchorName();
     79 }
     80 
     81 bool nsIFrame::IsRelativelyPositioned() const {
     82  return StyleDisplay()->IsRelativelyPositioned(this);
     83 }
     84 
     85 bool nsIFrame::IsStickyPositioned() const {
     86  return StyleDisplay()->IsStickyPositioned(this);
     87 }
     88 
     89 bool nsIFrame::IsAbsolutelyPositioned(
     90    const nsStyleDisplay* aStyleDisplay) const {
     91  return HasAnyStateBits(NS_FRAME_OUT_OF_FLOW) &&
     92         StyleDisplayWithOptionalParam(aStyleDisplay)
     93             ->IsAbsolutelyPositioned(this);
     94 }
     95 
     96 inline bool nsIFrame::IsTrueOverflowContainer() const {
     97  return HasAnyStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER) &&
     98         !IsAbsolutelyPositioned();
     99  // XXXfr This check isn't quite correct, because it doesn't handle cases
    100  //      where the out-of-flow has overflow.. but that's rare.
    101  //      We'll need to revisit the way abspos continuations are handled later
    102  //      for various reasons, this detail is one of them. See bug 154892
    103 }
    104 
    105 bool nsIFrame::IsBlockOutside() const {
    106  return StyleDisplay()->IsBlockOutside(this);
    107 }
    108 
    109 bool nsIFrame::IsInlineOutside() const {
    110  return StyleDisplay()->IsInlineOutside(this);
    111 }
    112 
    113 bool nsIFrame::IsColumnSpan() const {
    114  return IsBlockOutside() && StyleColumn()->IsColumnSpanStyle();
    115 }
    116 
    117 bool nsIFrame::IsColumnSpanInMulticolSubtree() const {
    118  return IsColumnSpan() &&
    119         (HasAnyStateBits(NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR) ||
    120          // A frame other than inline and block won't have
    121          // NS_FRAME_HAS_MULTI_COLUMN_ANCESTOR. We instead test its parent.
    122          (GetParent() && GetParent()->Style()->GetPseudoType() ==
    123                              mozilla::PseudoStyleType::columnSpanWrapper));
    124 }
    125 
    126 mozilla::StyleDisplay nsIFrame::GetDisplay() const {
    127  return StyleDisplay()->GetDisplay(this);
    128 }
    129 
    130 void nsIFrame::PropagateWritingModeToSelfAndAncestors(
    131    mozilla::WritingMode aWM) {
    132  MOZ_ASSERT(IsCanvasFrame());
    133  for (auto f = this; f; f = f->GetParent()) {
    134    f->mWritingMode = aWM;
    135  }
    136 }
    137 
    138 nsContainerFrame* nsIFrame::GetInFlowParent() const {
    139  if (HasAnyStateBits(NS_FRAME_OUT_OF_FLOW)) {
    140    nsIFrame* ph =
    141        FirstContinuation()->GetProperty(nsIFrame::PlaceholderFrameProperty());
    142    return ph->GetParent();
    143  }
    144 
    145  return GetParent();
    146 }
    147 
    148 // We generally want to follow the style tree for preserve-3d, jumping through
    149 // display: contents.
    150 //
    151 // There are various fun mismatches between the flattened tree and the frame
    152 // tree which makes this non-trivial to do looking at the frame tree state:
    153 //
    154 //  - Anon boxes. You'd have to step through them, because you generally want to
    155 //    ignore them.
    156 //
    157 //  - IB-splits, which produce a frame tree where frames for the block inside
    158 //    the inline are not children of any frame from the inline.
    159 //
    160 //  - display: contents, which makes DOM ancestors not have frames even when a
    161 //    descendant does.
    162 //
    163 // See GetFlattenedTreeParentElementForStyle for the difference between it and
    164 // plain GetFlattenedTreeParentElement.
    165 nsIFrame* nsIFrame::GetClosestFlattenedTreeAncestorPrimaryFrame() const {
    166  if (!mContent) {
    167    return nullptr;
    168  }
    169  mozilla::dom::Element* parent =
    170      mContent->GetFlattenedTreeParentElementForStyle();
    171  while (parent) {
    172    if (nsIFrame* frame = parent->GetPrimaryFrame()) {
    173      return frame;
    174    }
    175    // NOTE(emilio): This should be an assert except we have code in tree which
    176    // violates invariants like the <frameset> frame construction code.
    177    if (MOZ_UNLIKELY(!parent->IsDisplayContents())) {
    178      return nullptr;
    179    }
    180    parent = parent->GetFlattenedTreeParentElementForStyle();
    181  }
    182  return nullptr;
    183 }
    184 
    185 nsPoint nsIFrame::GetNormalPosition(bool* aHasProperty) const {
    186  bool hasProperty;
    187  nsPoint normalPosition = GetProperty(NormalPositionProperty(), &hasProperty);
    188  if (aHasProperty) {
    189    *aHasProperty = hasProperty;
    190  }
    191  return hasProperty ? normalPosition : GetPosition();
    192 }
    193 
    194 mozilla::LogicalPoint nsIFrame::GetLogicalNormalPosition(
    195    mozilla::WritingMode aWritingMode, const nsSize& aContainerSize) const {
    196  // Subtract the size of this frame from the container size to get
    197  // the correct position in rtl frames where the origin is on the
    198  // right instead of the left
    199  return mozilla::LogicalPoint(aWritingMode, GetNormalPosition(),
    200                               aContainerSize - mRect.Size());
    201 }
    202 
    203 bool nsIFrame::ContentIsEditable() const {
    204  return mContent && mContent->IsEditable();
    205 }
    206 
    207 inline bool nsIFrame::HasAnchorPosReference() const {
    208  return IsAbsolutelyPositioned() && Style()->HasAnchorPosReference();
    209 }
    210 
    211 #endif