File: space_utils.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (117 lines) | stat: -rw-r--r-- 4,707 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/layout/space_utils.h"

#include "third_party/blink/renderer/core/html/forms/html_button_element.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/forms/html_select_element.h"
#include "third_party/blink/renderer/core/html/forms/html_text_area_element.h"
#include "third_party/blink/renderer/core/layout/box_fragment_builder.h"
#include "third_party/blink/renderer/core/layout/constraint_space.h"
#include "third_party/blink/renderer/core/layout/constraint_space_builder.h"
#include "third_party/blink/renderer/core/layout/geometry/bfc_offset.h"
#include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/length_utils.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/text/writing_mode.h"

namespace blink {

bool AdjustToClearance(LayoutUnit clearance_offset, BfcOffset* offset) {
  DCHECK(offset);
  if (clearance_offset > offset->block_offset) {
    offset->block_offset = clearance_offset;
    return true;
  }

  return false;
}

void SetOrthogonalFallbackInlineSize(const ComputedStyle& parent_style,
                                     const LayoutInputNode child,
                                     ConstraintSpaceBuilder* builder) {
  DCHECK(!IsParallelWritingMode(parent_style.GetWritingMode(),
                                child.Style().GetWritingMode()));

  PhysicalSize orthogonal_children_containing_block_size =
      child.InitialContainingBlockSize();

  LayoutUnit fallback_size =
      parent_style.IsHorizontalWritingMode()
          ? orthogonal_children_containing_block_size.height
          : orthogonal_children_containing_block_size.width;

  LayoutUnit size(LayoutUnit::Max());
  if (parent_style.LogicalHeight().IsFixed()) {
    // Note that during layout, fixed size will already be taken care of (and
    // set in the constraint space), but when calculating intrinsic sizes of
    // orthogonal children, that won't be the case.
    size = LayoutUnit(parent_style.LogicalHeight().Pixels());
  }
  if (parent_style.LogicalMaxHeight().IsFixed()) {
    size = std::min(size, LayoutUnit(parent_style.LogicalMaxHeight().Pixels()));
  }
  if (parent_style.LogicalMinHeight().IsFixed()) {
    size = std::max(size, LayoutUnit(parent_style.LogicalMinHeight().Pixels()));
  }
  // Calculate the content-box size.
  if (parent_style.BoxSizing() == EBoxSizing::kBorderBox) {
    // We're unable to resolve percentages at this point, so make sure we're
    // only dealing with fixed-size values.
    if (!parent_style.PaddingBlockStart().IsFixed() ||
        !parent_style.PaddingBlockEnd().IsFixed()) {
      builder->SetOrthogonalFallbackInlineSize(fallback_size);
      return;
    }

    LayoutUnit border_padding(parent_style.BorderBlockStartWidth() +
                              parent_style.BorderBlockEndWidth() +
                              parent_style.PaddingBlockStart().Pixels() +
                              parent_style.PaddingBlockEnd().Pixels());

    size -= border_padding;
    size = size.ClampNegativeToZero();
  }

  fallback_size = std::min(fallback_size, size);
  builder->SetOrthogonalFallbackInlineSize(fallback_size);
}

bool ShouldBlockContainerChildStretchAutoInlineSize(const BlockNode& child) {
  if (child.IsReplaced()) {
    return false;
  }
  if (child.IsTable()) {
    return false;
  }
  if (const auto* node = child.GetDOMNode()) {
    if (IsA<HTMLButtonElement>(node) || IsA<HTMLInputElement>(node) ||
        IsA<HTMLSelectElement>(node) || IsA<HTMLTextAreaElement>(node)) {
      return false;
    }
  }
  return true;
}

void SetTextBoxTrimOnChildSpaceBuilder(
    const BoxFragmentBuilder& fragment_builder,
    bool known_to_have_successive_content,
    ConstraintSpaceBuilder* space_builder) {
  space_builder->SetShouldTextBoxTrimNodeStart(
      fragment_builder.ShouldTextBoxTrimNodeStart());
  space_builder->SetShouldTextBoxTrimFragmentainerStart(
      fragment_builder.ShouldTextBoxTrimFragmentainerStart());
  space_builder->SetShouldTextBoxTrimFragmentainerEnd(
      fragment_builder.ShouldTextBoxTrimFragmentainerEnd());
  if (fragment_builder.ShouldTextBoxTrimEnd()) {
    // Attempt to trim the end unless we know for sure that there's content to
    // follow.
    space_builder->SetShouldTextBoxTrimNodeEnd(
        fragment_builder.ShouldTextBoxTrimNodeEnd() &&
        !known_to_have_successive_content);
  }
}

}  // namespace blink