LayoutState.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*
  2. * Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Debug.h>
  7. #include <LibWeb/Layout/AvailableSpace.h>
  8. #include <LibWeb/Layout/BlockContainer.h>
  9. #include <LibWeb/Layout/LayoutState.h>
  10. #include <LibWeb/Layout/TextNode.h>
  11. #include <LibWeb/Layout/Viewport.h>
  12. #include <LibWeb/Painting/SVGGeometryPaintable.h>
  13. namespace Web::Layout {
  14. LayoutState::LayoutState(LayoutState const* parent)
  15. : m_parent(parent)
  16. , m_root(find_root())
  17. {
  18. }
  19. LayoutState::~LayoutState()
  20. {
  21. }
  22. LayoutState::UsedValues& LayoutState::get_mutable(NodeWithStyle const& node)
  23. {
  24. if (auto* used_values = used_values_per_layout_node.get(&node).value_or(nullptr))
  25. return *used_values;
  26. for (auto const* ancestor = m_parent; ancestor; ancestor = ancestor->m_parent) {
  27. if (auto* ancestor_used_values = ancestor->used_values_per_layout_node.get(&node).value_or(nullptr)) {
  28. auto cow_used_values = adopt_own(*new UsedValues(*ancestor_used_values));
  29. auto* cow_used_values_ptr = cow_used_values.ptr();
  30. used_values_per_layout_node.set(&node, move(cow_used_values));
  31. return *cow_used_values_ptr;
  32. }
  33. }
  34. auto const* containing_block_used_values = node.is_viewport() ? nullptr : &get(*node.containing_block());
  35. auto new_used_values = adopt_own(*new UsedValues);
  36. auto* new_used_values_ptr = new_used_values.ptr();
  37. new_used_values->set_node(const_cast<NodeWithStyle&>(node), containing_block_used_values);
  38. used_values_per_layout_node.set(&node, move(new_used_values));
  39. return *new_used_values_ptr;
  40. }
  41. LayoutState::UsedValues const& LayoutState::get(NodeWithStyle const& node) const
  42. {
  43. if (auto const* used_values = used_values_per_layout_node.get(&node).value_or(nullptr))
  44. return *used_values;
  45. for (auto const* ancestor = m_parent; ancestor; ancestor = ancestor->m_parent) {
  46. if (auto const* ancestor_used_values = ancestor->used_values_per_layout_node.get(&node).value_or(nullptr))
  47. return *ancestor_used_values;
  48. }
  49. auto const* containing_block_used_values = node.is_viewport() ? nullptr : &get(*node.containing_block());
  50. auto new_used_values = adopt_own(*new UsedValues);
  51. auto* new_used_values_ptr = new_used_values.ptr();
  52. new_used_values->set_node(const_cast<NodeWithStyle&>(node), containing_block_used_values);
  53. const_cast<LayoutState*>(this)->used_values_per_layout_node.set(&node, move(new_used_values));
  54. return *new_used_values_ptr;
  55. }
  56. // https://www.w3.org/TR/css-overflow-3/#scrollable-overflow
  57. static CSSPixelRect measure_scrollable_overflow(Box const& box)
  58. {
  59. if (!box.paintable_box())
  60. return {};
  61. auto& paintable_box = const_cast<Painting::PaintableBox&>(*box.paintable_box());
  62. if (paintable_box.scrollable_overflow_rect().has_value())
  63. return paintable_box.scrollable_overflow_rect().value();
  64. // The scrollable overflow area is the union of:
  65. // - The scroll container’s own padding box.
  66. auto scrollable_overflow_rect = paintable_box.absolute_padding_box_rect();
  67. // - All line boxes directly contained by the scroll container.
  68. if (is<Painting::PaintableWithLines>(box.paintable())) {
  69. auto const& line_boxes = static_cast<Painting::PaintableWithLines const&>(*box.paintable()).line_boxes();
  70. for (auto const& line_box : line_boxes) {
  71. scrollable_overflow_rect = scrollable_overflow_rect.united(line_box.absolute_rect());
  72. }
  73. }
  74. // - The border boxes of all boxes for which it is the containing block
  75. // and whose border boxes are positioned not wholly in the negative scrollable overflow region,
  76. // FIXME: accounting for transforms by projecting each box onto the plane of the element that establishes its 3D rendering context. [CSS3-TRANSFORMS]
  77. if (!box.children_are_inline()) {
  78. box.for_each_child_of_type<Box>([&box, &scrollable_overflow_rect](Box const& child) {
  79. if (!child.paintable_box())
  80. return IterationDecision::Continue;
  81. auto child_border_box = child.paintable_box()->absolute_border_box_rect();
  82. // NOTE: Here we check that the child is not wholly in the negative scrollable overflow region.
  83. if (child_border_box.bottom() > 0 && child_border_box.right() > 0)
  84. scrollable_overflow_rect = scrollable_overflow_rect.united(child_border_box);
  85. // - The scrollable overflow areas of all of the above boxes
  86. // (including zero-area boxes and accounting for transforms as described above),
  87. // provided they themselves have overflow: visible (i.e. do not themselves trap the overflow)
  88. // and that scrollable overflow is not already clipped (e.g. by the clip property or the contain property).
  89. if (is<Viewport>(box) || child.computed_values().overflow_x() == CSS::Overflow::Visible || child.computed_values().overflow_y() == CSS::Overflow::Visible) {
  90. auto child_scrollable_overflow = measure_scrollable_overflow(child);
  91. if (is<Viewport>(box) || child.computed_values().overflow_x() == CSS::Overflow::Visible)
  92. scrollable_overflow_rect.unite_horizontally(child_scrollable_overflow);
  93. if (is<Viewport>(box) || child.computed_values().overflow_y() == CSS::Overflow::Visible)
  94. scrollable_overflow_rect.unite_vertically(child_scrollable_overflow);
  95. }
  96. return IterationDecision::Continue;
  97. });
  98. }
  99. // FIXME: - The margin areas of grid item and flex item boxes for which the box establishes a containing block.
  100. // FIXME: - Additional padding added to the end-side of the scrollable overflow rectangle as necessary
  101. // to enable a scroll position that satisfies the requirements of place-content: end alignment.
  102. paintable_box.set_overflow_data(Painting::PaintableBox::OverflowData {
  103. .scrollable_overflow_rect = scrollable_overflow_rect,
  104. .has_scrollable_overflow = !paintable_box.absolute_padding_box_rect().contains(scrollable_overflow_rect),
  105. });
  106. return scrollable_overflow_rect;
  107. }
  108. void LayoutState::resolve_relative_positions(Vector<Painting::PaintableWithLines&> const& paintables_with_lines)
  109. {
  110. // This function resolves relative position offsets of all the boxes & fragments in the paint tree.
  111. // It runs *after* the paint tree has been constructed, so it modifies paintable node & fragment offsets directly.
  112. // Regular boxes (not line box fragments):
  113. for (auto& it : used_values_per_layout_node) {
  114. auto& used_values = *it.value;
  115. auto& node = const_cast<NodeWithStyle&>(used_values.node());
  116. if (!node.is_box())
  117. continue;
  118. auto& paintable = static_cast<Painting::PaintableBox&>(*node.paintable());
  119. CSSPixelPoint offset;
  120. if (used_values.containing_line_box_fragment.has_value()) {
  121. // Atomic inline case:
  122. // We know that `node` is an atomic inline because `containing_line_box_fragments` refers to the
  123. // line box fragment in the parent block container that contains it.
  124. auto const& containing_line_box_fragment = used_values.containing_line_box_fragment.value();
  125. auto const& containing_block = *node.containing_block();
  126. auto const& containing_block_paintable = verify_cast<Painting::PaintableWithLines>(*containing_block.paintable_box());
  127. auto const& fragment = containing_block_paintable.line_boxes()[containing_line_box_fragment.line_box_index].fragments()[containing_line_box_fragment.fragment_index];
  128. // The fragment has the final offset for the atomic inline, so we just need to copy it from there.
  129. offset = fragment.offset();
  130. } else {
  131. // Not an atomic inline, much simpler case.
  132. offset = used_values.offset;
  133. }
  134. // Apply relative position inset if appropriate.
  135. if (node.computed_values().position() == CSS::Positioning::Relative && is<NodeWithStyleAndBoxModelMetrics>(node)) {
  136. auto& inset = static_cast<NodeWithStyleAndBoxModelMetrics const&>(node).box_model().inset;
  137. offset.translate_by(inset.left, inset.top);
  138. }
  139. paintable.set_offset(offset);
  140. }
  141. // Line box fragments:
  142. for (auto const& paintable_with_lines : paintables_with_lines) {
  143. for (auto const& line_box : paintable_with_lines.line_boxes()) {
  144. for (auto& fragment : line_box.fragments()) {
  145. auto const& fragment_node = fragment.layout_node();
  146. if (!is<Layout::NodeWithStyleAndBoxModelMetrics>(*fragment_node.parent()))
  147. continue;
  148. // Collect effective relative position offset from inline-flow parent chain.
  149. CSSPixelPoint offset;
  150. for (auto* ancestor = fragment_node.parent(); ancestor; ancestor = ancestor->parent()) {
  151. if (!is<Layout::NodeWithStyleAndBoxModelMetrics>(*ancestor))
  152. break;
  153. if (!ancestor->display().is_inline_outside() || !ancestor->display().is_flow_inside())
  154. break;
  155. if (ancestor->computed_values().position() == CSS::Positioning::Relative) {
  156. auto const& ancestor_node = static_cast<Layout::NodeWithStyleAndBoxModelMetrics const&>(*ancestor);
  157. auto const& inset = ancestor_node.box_model().inset;
  158. offset.translate_by(inset.left, inset.top);
  159. }
  160. }
  161. const_cast<LineBoxFragment&>(fragment).set_offset(fragment.offset().translated(offset));
  162. }
  163. }
  164. }
  165. }
  166. static void build_paint_tree(Node& node, Painting::Paintable* parent_paintable = nullptr)
  167. {
  168. Painting::Paintable* paintable = nullptr;
  169. if (node.paintable()) {
  170. paintable = const_cast<Painting::Paintable*>(node.paintable());
  171. if (parent_paintable && !paintable->forms_unconnected_subtree()) {
  172. VERIFY(!paintable->parent());
  173. parent_paintable->append_child(*paintable);
  174. }
  175. paintable->set_dom_node(node.dom_node());
  176. if (node.dom_node())
  177. node.dom_node()->set_paintable(paintable);
  178. }
  179. for (auto* child = node.first_child(); child; child = child->next_sibling()) {
  180. build_paint_tree(*child, paintable);
  181. }
  182. }
  183. void LayoutState::commit(Box& root)
  184. {
  185. // Only the top-level LayoutState should ever be committed.
  186. VERIFY(!m_parent);
  187. // NOTE: In case this is a relayout of an existing tree, we start by detaching the old paint tree
  188. // from the layout tree. This is done to ensure that we don't end up with any old-tree pointers
  189. // when text paintables shift around in the tree.
  190. root.for_each_in_inclusive_subtree_of_type<Layout::TextNode>([&](Layout::TextNode& text_node) {
  191. text_node.set_paintable(nullptr);
  192. return IterationDecision::Continue;
  193. });
  194. HashTable<Layout::TextNode*> text_nodes;
  195. Vector<Painting::PaintableWithLines&> paintables_with_lines;
  196. for (auto& it : used_values_per_layout_node) {
  197. auto& used_values = *it.value;
  198. auto& node = const_cast<NodeWithStyle&>(used_values.node());
  199. if (is<NodeWithStyleAndBoxModelMetrics>(node)) {
  200. // Transfer box model metrics.
  201. auto& box_model = static_cast<NodeWithStyleAndBoxModelMetrics&>(node).box_model();
  202. box_model.inset = { used_values.inset_top, used_values.inset_right, used_values.inset_bottom, used_values.inset_left };
  203. box_model.padding = { used_values.padding_top, used_values.padding_right, used_values.padding_bottom, used_values.padding_left };
  204. box_model.border = { used_values.border_top, used_values.border_right, used_values.border_bottom, used_values.border_left };
  205. box_model.margin = { used_values.margin_top, used_values.margin_right, used_values.margin_bottom, used_values.margin_left };
  206. }
  207. auto paintable = node.create_paintable();
  208. node.set_paintable(paintable);
  209. // For boxes, transfer all the state needed for painting.
  210. if (paintable && is<Painting::PaintableBox>(*paintable)) {
  211. auto& paintable_box = static_cast<Painting::PaintableBox&>(*paintable);
  212. paintable_box.set_offset(used_values.offset);
  213. paintable_box.set_content_size(used_values.content_width(), used_values.content_height());
  214. if (used_values.override_borders_data().has_value()) {
  215. paintable_box.set_override_borders_data(used_values.override_borders_data().value());
  216. }
  217. if (used_values.table_cell_coordinates().has_value()) {
  218. paintable_box.set_table_cell_coordinates(used_values.table_cell_coordinates().value());
  219. }
  220. if (is<Painting::PaintableWithLines>(paintable_box)) {
  221. auto& paintable_with_lines = static_cast<Painting::PaintableWithLines&>(paintable_box);
  222. paintable_with_lines.set_line_boxes(move(used_values.line_boxes));
  223. paintables_with_lines.append(paintable_with_lines);
  224. }
  225. if (used_values.computed_svg_transforms().has_value() && is<Painting::SVGGraphicsPaintable>(paintable_box)) {
  226. auto& svg_graphics_paintable = static_cast<Painting::SVGGraphicsPaintable&>(paintable_box);
  227. svg_graphics_paintable.set_computed_transforms(*used_values.computed_svg_transforms());
  228. }
  229. if (used_values.computed_svg_path().has_value() && is<Painting::SVGGeometryPaintable>(paintable_box)) {
  230. auto& svg_geometry_paintable = static_cast<Painting::SVGGeometryPaintable&>(paintable_box);
  231. svg_geometry_paintable.set_computed_path(move(*used_values.computed_svg_path()));
  232. }
  233. }
  234. }
  235. resolve_relative_positions(paintables_with_lines);
  236. // Make a pass over all the line boxes to:
  237. // - Measure absolute rect of each line box.
  238. // - Collect all text nodes, so we can create paintables for them later.
  239. for (auto& paintable_with_lines : paintables_with_lines) {
  240. for (auto& line_box : paintable_with_lines.line_boxes()) {
  241. CSSPixelRect line_box_absolute_rect;
  242. for (auto const& fragment : line_box.fragments()) {
  243. line_box_absolute_rect = line_box_absolute_rect.united(fragment.absolute_rect());
  244. if (fragment.layout_node().is_text_node())
  245. text_nodes.set(static_cast<Layout::TextNode*>(const_cast<Layout::Node*>(&fragment.layout_node())));
  246. }
  247. const_cast<LineBox&>(line_box).set_absolute_rect(line_box_absolute_rect);
  248. }
  249. }
  250. for (auto* text_node : text_nodes)
  251. text_node->set_paintable(text_node->create_paintable());
  252. build_paint_tree(root);
  253. // Measure overflow in scroll containers.
  254. for (auto& it : used_values_per_layout_node) {
  255. auto& used_values = *it.value;
  256. if (!used_values.node().is_box())
  257. continue;
  258. auto const& box = static_cast<Layout::Box const&>(used_values.node());
  259. measure_scrollable_overflow(box);
  260. }
  261. }
  262. void LayoutState::UsedValues::set_node(NodeWithStyle& node, UsedValues const* containing_block_used_values)
  263. {
  264. m_node = &node;
  265. // NOTE: In the code below, we decide if `node` has definite width and/or height.
  266. // This attempts to cover all the *general* cases where CSS considers sizes to be definite.
  267. // If `node` has definite values for min/max-width or min/max-height and a definite
  268. // preferred size in the same axis, we clamp the preferred size here as well.
  269. //
  270. // There are additional cases where CSS considers values to be definite. We model all of
  271. // those by having our engine consider sizes to be definite *once they are assigned to
  272. // the UsedValues by calling set_content_width() or set_content_height().
  273. auto const& computed_values = node.computed_values();
  274. auto adjust_for_box_sizing = [&](CSSPixels unadjusted_pixels, CSS::Size const& computed_size, bool width) -> CSSPixels {
  275. // box-sizing: content-box and/or automatic size don't require any adjustment.
  276. if (computed_values.box_sizing() == CSS::BoxSizing::ContentBox || computed_size.is_auto())
  277. return unadjusted_pixels;
  278. // box-sizing: border-box requires us to subtract the relevant border and padding from the size.
  279. CSSPixels border_and_padding;
  280. if (width) {
  281. border_and_padding = computed_values.border_left().width
  282. + computed_values.padding().left().to_px(*m_node, containing_block_used_values->content_width())
  283. + computed_values.border_right().width
  284. + computed_values.padding().right().to_px(*m_node, containing_block_used_values->content_width());
  285. } else {
  286. border_and_padding = computed_values.border_top().width
  287. + computed_values.padding().top().to_px(*m_node, containing_block_used_values->content_width())
  288. + computed_values.border_bottom().width
  289. + computed_values.padding().bottom().to_px(*m_node, containing_block_used_values->content_width());
  290. }
  291. return unadjusted_pixels - border_and_padding;
  292. };
  293. auto is_definite_size = [&](CSS::Size const& size, CSSPixels& resolved_definite_size, bool width) {
  294. // A size that can be determined without performing layout; that is,
  295. // a <length>,
  296. // a measure of text (without consideration of line-wrapping),
  297. // a size of the initial containing block,
  298. // or a <percentage> or other formula (such as the “stretch-fit” sizing of non-replaced blocks [CSS2]) that is resolved solely against definite sizes.
  299. auto containing_block_has_definite_size = containing_block_used_values ? (width ? containing_block_used_values->has_definite_width() : containing_block_used_values->has_definite_height()) : false;
  300. if (size.is_auto()) {
  301. // NOTE: The width of a non-flex-item block is considered definite if it's auto and the containing block has definite width.
  302. if (width
  303. && !node.is_floating()
  304. && !node.is_absolutely_positioned()
  305. && node.display().is_block_outside()
  306. && node.parent()
  307. && !node.parent()->is_floating()
  308. && (node.parent()->display().is_flow_root_inside()
  309. || node.parent()->display().is_flow_inside())) {
  310. if (containing_block_has_definite_size) {
  311. CSSPixels available_width = containing_block_used_values->content_width();
  312. resolved_definite_size = available_width
  313. - margin_left
  314. - margin_right
  315. - padding_left
  316. - padding_right
  317. - border_left
  318. - border_right;
  319. return true;
  320. }
  321. return false;
  322. }
  323. return false;
  324. }
  325. if (size.is_calculated()) {
  326. if (size.calculated().contains_percentage()) {
  327. if (!containing_block_has_definite_size)
  328. return false;
  329. auto containing_block_size_as_length = width ? containing_block_used_values->content_width() : containing_block_used_values->content_height();
  330. resolved_definite_size = adjust_for_box_sizing(size.calculated().resolve_length_percentage(node, containing_block_size_as_length).value_or(CSS::Length::make_auto()).to_px(node), size, width);
  331. return true;
  332. }
  333. resolved_definite_size = adjust_for_box_sizing(size.calculated().resolve_length(node)->to_px(node), size, width);
  334. return true;
  335. }
  336. if (size.is_length()) {
  337. VERIFY(!size.is_auto()); // This should have been covered by the Size::is_auto() branch above.
  338. resolved_definite_size = adjust_for_box_sizing(size.length().to_px(node), size, width);
  339. return true;
  340. }
  341. if (size.is_percentage()) {
  342. if (containing_block_has_definite_size) {
  343. auto containing_block_size = width ? containing_block_used_values->content_width() : containing_block_used_values->content_height();
  344. resolved_definite_size = adjust_for_box_sizing(containing_block_size.scaled(size.percentage().as_fraction()), size, width);
  345. return true;
  346. }
  347. return false;
  348. }
  349. // FIXME: Determine if calc() value is definite.
  350. return false;
  351. };
  352. CSSPixels min_width = 0;
  353. bool has_definite_min_width = is_definite_size(computed_values.min_width(), min_width, true);
  354. CSSPixels max_width = 0;
  355. bool has_definite_max_width = is_definite_size(computed_values.max_width(), max_width, true);
  356. CSSPixels min_height = 0;
  357. bool has_definite_min_height = is_definite_size(computed_values.min_height(), min_height, false);
  358. CSSPixels max_height = 0;
  359. bool has_definite_max_height = is_definite_size(computed_values.max_height(), max_height, false);
  360. m_has_definite_width = is_definite_size(computed_values.width(), m_content_width, true);
  361. m_has_definite_height = is_definite_size(computed_values.height(), m_content_height, false);
  362. if (m_has_definite_width) {
  363. if (has_definite_min_width)
  364. m_content_width = max(min_width, m_content_width);
  365. if (has_definite_max_width)
  366. m_content_width = min(max_width, m_content_width);
  367. }
  368. if (m_has_definite_height) {
  369. if (has_definite_min_height)
  370. m_content_height = max(min_height, m_content_height);
  371. if (has_definite_max_height)
  372. m_content_height = min(max_height, m_content_height);
  373. }
  374. }
  375. void LayoutState::UsedValues::set_content_width(CSSPixels width)
  376. {
  377. VERIFY(!width.might_be_saturated());
  378. if (width < 0) {
  379. // Negative widths are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
  380. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative width for {}: {}", m_node->debug_description(), width);
  381. width = 0;
  382. }
  383. m_content_width = width;
  384. m_has_definite_width = true;
  385. }
  386. void LayoutState::UsedValues::set_content_height(CSSPixels height)
  387. {
  388. VERIFY(!height.might_be_saturated());
  389. if (height < 0) {
  390. // Negative heights are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
  391. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative height for {}: {}", m_node->debug_description(), height);
  392. height = 0;
  393. }
  394. m_content_height = height;
  395. m_has_definite_height = true;
  396. }
  397. void LayoutState::UsedValues::set_temporary_content_width(CSSPixels width)
  398. {
  399. m_content_width = width;
  400. }
  401. void LayoutState::UsedValues::set_temporary_content_height(CSSPixels height)
  402. {
  403. m_content_height = height;
  404. }
  405. AvailableSize LayoutState::UsedValues::available_width_inside() const
  406. {
  407. if (width_constraint == SizeConstraint::MinContent)
  408. return AvailableSize::make_min_content();
  409. if (width_constraint == SizeConstraint::MaxContent)
  410. return AvailableSize::make_max_content();
  411. if (has_definite_width())
  412. return AvailableSize::make_definite(m_content_width);
  413. return AvailableSize::make_indefinite();
  414. }
  415. AvailableSize LayoutState::UsedValues::available_height_inside() const
  416. {
  417. if (height_constraint == SizeConstraint::MinContent)
  418. return AvailableSize::make_min_content();
  419. if (height_constraint == SizeConstraint::MaxContent)
  420. return AvailableSize::make_max_content();
  421. if (has_definite_height())
  422. return AvailableSize::make_definite(m_content_height);
  423. return AvailableSize::make_indefinite();
  424. }
  425. AvailableSpace LayoutState::UsedValues::available_inner_space_or_constraints_from(AvailableSpace const& outer_space) const
  426. {
  427. auto inner_width = available_width_inside();
  428. auto inner_height = available_height_inside();
  429. if (inner_width.is_indefinite() && outer_space.width.is_intrinsic_sizing_constraint())
  430. inner_width = outer_space.width;
  431. if (inner_height.is_indefinite() && outer_space.height.is_intrinsic_sizing_constraint())
  432. inner_height = outer_space.height;
  433. return AvailableSpace(inner_width, inner_height);
  434. }
  435. void LayoutState::UsedValues::set_content_offset(CSSPixelPoint new_offset)
  436. {
  437. set_content_x(new_offset.x());
  438. set_content_y(new_offset.y());
  439. }
  440. void LayoutState::UsedValues::set_content_x(CSSPixels x)
  441. {
  442. offset.set_x(x);
  443. }
  444. void LayoutState::UsedValues::set_content_y(CSSPixels y)
  445. {
  446. offset.set_y(y);
  447. }
  448. void LayoutState::UsedValues::set_indefinite_content_width()
  449. {
  450. m_has_definite_width = false;
  451. }
  452. void LayoutState::UsedValues::set_indefinite_content_height()
  453. {
  454. m_has_definite_height = false;
  455. }
  456. }