SVGFormattingContext.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * Copyright (c) 2021-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  5. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include <AK/Debug.h>
  10. #include <LibGfx/BoundingBox.h>
  11. #include <LibGfx/Font/ScaledFont.h>
  12. #include <LibGfx/TextLayout.h>
  13. #include <LibWeb/Layout/BlockFormattingContext.h>
  14. #include <LibWeb/Layout/SVGFormattingContext.h>
  15. #include <LibWeb/Layout/SVGGeometryBox.h>
  16. #include <LibWeb/Layout/SVGMaskBox.h>
  17. #include <LibWeb/Layout/SVGSVGBox.h>
  18. #include <LibWeb/Layout/SVGTextBox.h>
  19. #include <LibWeb/Layout/SVGTextPathBox.h>
  20. #include <LibWeb/SVG/SVGForeignObjectElement.h>
  21. #include <LibWeb/SVG/SVGGElement.h>
  22. #include <LibWeb/SVG/SVGMaskElement.h>
  23. #include <LibWeb/SVG/SVGSVGElement.h>
  24. #include <LibWeb/SVG/SVGSymbolElement.h>
  25. #include <LibWeb/SVG/SVGUseElement.h>
  26. namespace Web::Layout {
  27. SVGFormattingContext::SVGFormattingContext(LayoutState& state, Box const& box, FormattingContext* parent, Gfx::AffineTransform parent_viewbox_transform)
  28. : FormattingContext(Type::SVG, state, box, parent)
  29. , m_parent_viewbox_transform(parent_viewbox_transform)
  30. {
  31. }
  32. SVGFormattingContext::~SVGFormattingContext() = default;
  33. CSSPixels SVGFormattingContext::automatic_content_width() const
  34. {
  35. return 0;
  36. }
  37. CSSPixels SVGFormattingContext::automatic_content_height() const
  38. {
  39. return 0;
  40. }
  41. struct ViewBoxTransform {
  42. CSSPixelPoint offset;
  43. double scale_factor_x;
  44. double scale_factor_y;
  45. };
  46. // https://svgwg.org/svg2-draft/coords.html#PreserveAspectRatioAttribute
  47. static ViewBoxTransform scale_and_align_viewbox_content(SVG::PreserveAspectRatio const& preserve_aspect_ratio,
  48. SVG::ViewBox const& view_box, Gfx::FloatSize viewbox_scale, auto const& svg_box_state)
  49. {
  50. ViewBoxTransform viewbox_transform {};
  51. if (preserve_aspect_ratio.align == SVG::PreserveAspectRatio::Align::None) {
  52. viewbox_transform.scale_factor_x = viewbox_scale.width();
  53. viewbox_transform.scale_factor_y = viewbox_scale.height();
  54. viewbox_transform.offset = {};
  55. return viewbox_transform;
  56. }
  57. switch (preserve_aspect_ratio.meet_or_slice) {
  58. case SVG::PreserveAspectRatio::MeetOrSlice::Meet:
  59. // meet (the default) - Scale the graphic such that:
  60. // - aspect ratio is preserved
  61. // - the entire ‘viewBox’ is visible within the SVG viewport
  62. // - the ‘viewBox’ is scaled up as much as possible, while still meeting the other criteria
  63. viewbox_transform.scale_factor_x = viewbox_transform.scale_factor_y = min(viewbox_scale.width(), viewbox_scale.height());
  64. break;
  65. case SVG::PreserveAspectRatio::MeetOrSlice::Slice:
  66. // slice - Scale the graphic such that:
  67. // aspect ratio is preserved
  68. // the entire SVG viewport is covered by the ‘viewBox’
  69. // the ‘viewBox’ is scaled down as much as possible, while still meeting the other criteria
  70. viewbox_transform.scale_factor_x = viewbox_transform.scale_factor_y = max(viewbox_scale.width(), viewbox_scale.height());
  71. break;
  72. default:
  73. VERIFY_NOT_REACHED();
  74. }
  75. // Handle X alignment:
  76. if (svg_box_state.has_definite_width()) {
  77. switch (preserve_aspect_ratio.align) {
  78. case SVG::PreserveAspectRatio::Align::xMinYMin:
  79. case SVG::PreserveAspectRatio::Align::xMinYMid:
  80. case SVG::PreserveAspectRatio::Align::xMinYMax:
  81. // Align the <min-x> of the element's ‘viewBox’ with the smallest X value of the SVG viewport.
  82. viewbox_transform.offset.translate_by(0, 0);
  83. break;
  84. case SVG::PreserveAspectRatio::Align::None: {
  85. // Do not force uniform scaling. Scale the graphic content of the given element non-uniformly
  86. // if necessary such that the element's bounding box exactly matches the SVG viewport rectangle.
  87. // FIXME: None is unimplemented (treat as xMidYMid)
  88. [[fallthrough]];
  89. }
  90. case SVG::PreserveAspectRatio::Align::xMidYMin:
  91. case SVG::PreserveAspectRatio::Align::xMidYMid:
  92. case SVG::PreserveAspectRatio::Align::xMidYMax:
  93. // Align the midpoint X value of the element's ‘viewBox’ with the midpoint X value of the SVG viewport.
  94. viewbox_transform.offset.translate_by((svg_box_state.content_width() - CSSPixels::nearest_value_for(view_box.width * viewbox_transform.scale_factor_x)) / 2, 0);
  95. break;
  96. case SVG::PreserveAspectRatio::Align::xMaxYMin:
  97. case SVG::PreserveAspectRatio::Align::xMaxYMid:
  98. case SVG::PreserveAspectRatio::Align::xMaxYMax:
  99. // Align the <min-x>+<width> of the element's ‘viewBox’ with the maximum X value of the SVG viewport.
  100. viewbox_transform.offset.translate_by((svg_box_state.content_width() - CSSPixels::nearest_value_for(view_box.width * viewbox_transform.scale_factor_x)), 0);
  101. break;
  102. default:
  103. VERIFY_NOT_REACHED();
  104. }
  105. }
  106. if (svg_box_state.has_definite_width()) {
  107. switch (preserve_aspect_ratio.align) {
  108. case SVG::PreserveAspectRatio::Align::xMinYMin:
  109. case SVG::PreserveAspectRatio::Align::xMidYMin:
  110. case SVG::PreserveAspectRatio::Align::xMaxYMin:
  111. // Align the <min-y> of the element's ‘viewBox’ with the smallest Y value of the SVG viewport.
  112. viewbox_transform.offset.translate_by(0, 0);
  113. break;
  114. case SVG::PreserveAspectRatio::Align::None: {
  115. // Do not force uniform scaling. Scale the graphic content of the given element non-uniformly
  116. // if necessary such that the element's bounding box exactly matches the SVG viewport rectangle.
  117. // FIXME: None is unimplemented (treat as xMidYMid)
  118. [[fallthrough]];
  119. }
  120. case SVG::PreserveAspectRatio::Align::xMinYMid:
  121. case SVG::PreserveAspectRatio::Align::xMidYMid:
  122. case SVG::PreserveAspectRatio::Align::xMaxYMid:
  123. // Align the midpoint Y value of the element's ‘viewBox’ with the midpoint Y value of the SVG viewport.
  124. viewbox_transform.offset.translate_by(0, (svg_box_state.content_height() - CSSPixels::nearest_value_for(view_box.height * viewbox_transform.scale_factor_y)) / 2);
  125. break;
  126. case SVG::PreserveAspectRatio::Align::xMinYMax:
  127. case SVG::PreserveAspectRatio::Align::xMidYMax:
  128. case SVG::PreserveAspectRatio::Align::xMaxYMax:
  129. // Align the <min-y>+<height> of the element's ‘viewBox’ with the maximum Y value of the SVG viewport.
  130. viewbox_transform.offset.translate_by(0, (svg_box_state.content_height() - CSSPixels::nearest_value_for(view_box.height * viewbox_transform.scale_factor_y)));
  131. break;
  132. default:
  133. VERIFY_NOT_REACHED();
  134. }
  135. }
  136. return viewbox_transform;
  137. }
  138. static bool is_container_element(Node const& node)
  139. {
  140. // https://svgwg.org/svg2-draft/struct.html#GroupsOverview
  141. auto* dom_node = node.dom_node();
  142. if (!dom_node)
  143. return false;
  144. if (is<SVG::SVGUseElement>(dom_node))
  145. return true;
  146. if (is<SVG::SVGSymbolElement>(dom_node))
  147. return true;
  148. if (is<SVG::SVGGElement>(dom_node))
  149. return true;
  150. if (is<SVG::SVGMaskElement>(dom_node))
  151. return true;
  152. return false;
  153. }
  154. enum class TraversalDecision {
  155. Continue,
  156. SkipChildrenAndContinue,
  157. Break,
  158. };
  159. // FIXME: Add TraversalDecision::SkipChildrenAndContinue to TreeNode's implementation.
  160. template<typename Callback>
  161. static TraversalDecision for_each_in_inclusive_subtree(Layout::Node const& node, Callback callback)
  162. {
  163. if (auto decision = callback(node); decision != TraversalDecision::Continue)
  164. return decision;
  165. for (auto* child = node.first_child(); child; child = child->next_sibling()) {
  166. if (for_each_in_inclusive_subtree(*child, callback) == TraversalDecision::Break)
  167. return TraversalDecision::Break;
  168. }
  169. return TraversalDecision::Continue;
  170. }
  171. // FIXME: Add TraversalDecision::SkipChildrenAndContinue to TreeNode's implementation.
  172. template<typename Callback>
  173. static TraversalDecision for_each_in_subtree(Layout::Node const& node, Callback callback)
  174. {
  175. for (auto* child = node.first_child(); child; child = child->next_sibling()) {
  176. if (for_each_in_inclusive_subtree(*child, callback) == TraversalDecision::Break)
  177. return TraversalDecision::Break;
  178. }
  179. return TraversalDecision::Continue;
  180. }
  181. void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, AvailableSpace const& available_space)
  182. {
  183. // NOTE: SVG doesn't have a "formatting context" in the spec, but this is the most
  184. // obvious way to drive SVG layout in our engine at the moment.
  185. auto& svg_viewport = dynamic_cast<SVG::SVGViewport const&>(*box.dom_node());
  186. auto& svg_box_state = m_state.get_mutable(box);
  187. // NOTE: We consider all SVG root elements to have definite size in both axes.
  188. // I'm not sure if this is good or bad, but our viewport transform logic depends on it.
  189. svg_box_state.set_has_definite_width(true);
  190. svg_box_state.set_has_definite_height(true);
  191. auto viewbox = svg_viewport.view_box();
  192. // https://svgwg.org/svg2-draft/coords.html#ViewBoxAttribute
  193. if (viewbox.has_value()) {
  194. if (viewbox->width < 0 || viewbox->height < 0) {
  195. // A negative value for <width> or <height> is an error and invalidates the ‘viewBox’ attribute.
  196. viewbox = {};
  197. } else if (viewbox->width == 0 || viewbox->height == 0) {
  198. // A value of zero disables rendering of the element.
  199. return;
  200. }
  201. }
  202. auto viewbox_transform = [&] {
  203. if (!viewbox.has_value())
  204. return m_parent_viewbox_transform;
  205. // FIXME: This should allow just one of width or height to be specified.
  206. // E.g. We should be able to layout <svg width="100%"> where height is unspecified/auto.
  207. if (!svg_box_state.has_definite_width() || !svg_box_state.has_definite_height()) {
  208. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Attempting to layout indefinitely sized SVG with a viewbox -- this likely won't work!");
  209. }
  210. auto scale_width = svg_box_state.has_definite_width() ? svg_box_state.content_width() / viewbox->width : 1;
  211. auto scale_height = svg_box_state.has_definite_height() ? svg_box_state.content_height() / viewbox->height : 1;
  212. // The initial value for preserveAspectRatio is xMidYMid meet.
  213. auto preserve_aspect_ratio = svg_viewport.preserve_aspect_ratio().value_or(SVG::PreserveAspectRatio {});
  214. auto viewbox_offset_and_scale = scale_and_align_viewbox_content(preserve_aspect_ratio, *viewbox, { scale_width, scale_height }, svg_box_state);
  215. CSSPixelPoint offset = viewbox_offset_and_scale.offset;
  216. return Gfx::AffineTransform { m_parent_viewbox_transform }.multiply(Gfx::AffineTransform {}
  217. .translate(offset.to_type<float>())
  218. .scale(viewbox_offset_and_scale.scale_factor_x, viewbox_offset_and_scale.scale_factor_y)
  219. .translate({ -viewbox->min_x, -viewbox->min_y }));
  220. }();
  221. if (svg_box_state.has_definite_width() && svg_box_state.has_definite_height()) {
  222. // Scale the box of the viewport based on the parent's viewBox transform.
  223. // The viewBox transform is always just a simple scale + offset.
  224. // FIXME: Avoid converting SVG box to floats.
  225. Gfx::FloatRect svg_rect = { svg_box_state.offset.to_type<float>(),
  226. { float(svg_box_state.content_width()), float(svg_box_state.content_height()) } };
  227. svg_rect = m_parent_viewbox_transform.map(svg_rect);
  228. svg_box_state.set_content_offset(svg_rect.location().to_type<CSSPixels>());
  229. svg_box_state.set_content_width(CSSPixels(svg_rect.width()));
  230. svg_box_state.set_content_height(CSSPixels(svg_rect.height()));
  231. svg_box_state.set_has_definite_width(true);
  232. svg_box_state.set_has_definite_height(true);
  233. }
  234. auto root_offset = svg_box_state.offset;
  235. box.for_each_child_of_type<BlockContainer>([&](BlockContainer const& child_box) {
  236. if (is<SVG::SVGForeignObjectElement>(child_box.dom_node())) {
  237. Layout::BlockFormattingContext bfc(m_state, child_box, this);
  238. bfc.run(child_box, LayoutMode::Normal, available_space);
  239. auto& child_state = m_state.get_mutable(child_box);
  240. child_state.set_content_offset(child_state.offset.translated(root_offset));
  241. }
  242. return IterationDecision::Continue;
  243. });
  244. auto viewport_width = [&] {
  245. if (viewbox.has_value())
  246. return CSSPixels::nearest_value_for(viewbox->width);
  247. if (svg_box_state.has_definite_width())
  248. return svg_box_state.content_width();
  249. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Failed to resolve width of SVG viewport!");
  250. return CSSPixels {};
  251. }();
  252. auto viewport_height = [&] {
  253. if (viewbox.has_value())
  254. return CSSPixels::nearest_value_for(viewbox->height);
  255. if (svg_box_state.has_definite_height())
  256. return svg_box_state.content_height();
  257. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Failed to resolve height of SVG viewport!");
  258. return CSSPixels {};
  259. }();
  260. for_each_in_subtree(box, [&](Node const& descendant) {
  261. if (is<SVGMaskBox>(descendant))
  262. return TraversalDecision::SkipChildrenAndContinue;
  263. if (is<SVG::SVGViewport>(descendant.dom_node())) {
  264. // Layout for a nested SVG viewport.
  265. // https://svgwg.org/svg2-draft/coords.html#EstablishingANewSVGViewport.
  266. SVGFormattingContext nested_context(m_state, static_cast<Box const&>(descendant), this, viewbox_transform);
  267. auto& nested_viewport_state = m_state.get_mutable(static_cast<Box const&>(descendant));
  268. auto resolve_dimension = [](auto& node, auto size, auto reference_value) {
  269. // The value auto for width and height on the ‘svg’ element is treated as 100%.
  270. // https://svgwg.org/svg2-draft/geometry.html#Sizing
  271. if (size.is_auto())
  272. return reference_value;
  273. return size.to_px(node, reference_value);
  274. };
  275. auto nested_viewport_x = descendant.computed_values().x().to_px(descendant, viewport_width);
  276. auto nested_viewport_y = descendant.computed_values().y().to_px(descendant, viewport_height);
  277. auto nested_viewport_width = resolve_dimension(descendant, descendant.computed_values().width(), viewport_width);
  278. auto nested_viewport_height = resolve_dimension(descendant, descendant.computed_values().height(), viewport_height);
  279. nested_viewport_state.set_content_offset({ nested_viewport_x, nested_viewport_y });
  280. nested_viewport_state.set_content_width(nested_viewport_width);
  281. nested_viewport_state.set_content_height(nested_viewport_height);
  282. nested_viewport_state.set_has_definite_width(true);
  283. nested_viewport_state.set_has_definite_height(true);
  284. nested_context.run(static_cast<Box const&>(descendant), layout_mode, available_space);
  285. return TraversalDecision::SkipChildrenAndContinue;
  286. }
  287. if (is<SVGGraphicsBox>(descendant)) {
  288. auto const& graphics_box = static_cast<SVGGraphicsBox const&>(descendant);
  289. auto& dom_node = const_cast<SVGGraphicsBox&>(graphics_box).dom_node();
  290. auto& graphics_box_state = m_state.get_mutable(graphics_box);
  291. auto svg_transform = dom_node.get_transform();
  292. graphics_box_state.set_computed_svg_transforms(Painting::SVGGraphicsPaintable::ComputedTransforms(viewbox_transform, svg_transform));
  293. auto to_css_pixels_transform = Gfx::AffineTransform {}.multiply(viewbox_transform).multiply(svg_transform);
  294. Gfx::Path path;
  295. if (is<SVGGeometryBox>(descendant)) {
  296. path = static_cast<SVG::SVGGeometryElement&>(dom_node).get_path({ viewport_width, viewport_height });
  297. } else if (is<SVGTextBox>(descendant)) {
  298. auto& text_element = static_cast<SVG::SVGTextPositioningElement&>(dom_node);
  299. auto& font = graphics_box.first_available_font();
  300. auto text_contents = text_element.text_contents();
  301. Utf8View text_utf8 { text_contents };
  302. auto text_width = font.width(text_utf8);
  303. auto text_offset = text_element.get_offset();
  304. // https://svgwg.org/svg2-draft/text.html#TextAnchoringProperties
  305. switch (text_element.text_anchor().value_or(SVG::TextAnchor::Start)) {
  306. case SVG::TextAnchor::Start:
  307. // The rendered characters are aligned such that the start of the resulting rendered text is at the initial
  308. // current text position.
  309. break;
  310. case SVG::TextAnchor::Middle: {
  311. // The rendered characters are shifted such that the geometric middle of the resulting rendered text
  312. // (determined from the initial and final current text position before applying the text-anchor property)
  313. // is at the initial current text position.
  314. text_offset.translate_by(-text_width / 2, 0);
  315. break;
  316. }
  317. case SVG::TextAnchor::End: {
  318. // The rendered characters are shifted such that the end of the resulting rendered text (final current text
  319. // position before applying the text-anchor property) is at the initial current text position.
  320. text_offset.translate_by(-text_width, 0);
  321. break;
  322. }
  323. default:
  324. VERIFY_NOT_REACHED();
  325. }
  326. path.move_to(text_offset);
  327. path.text(text_utf8, font);
  328. } else if (is<SVGTextPathBox>(descendant)) {
  329. auto& text_path_element = static_cast<SVG::SVGTextPathElement&>(dom_node);
  330. auto path_or_shape = text_path_element.path_or_shape();
  331. if (!path_or_shape)
  332. return TraversalDecision::Continue;
  333. auto& font = graphics_box.first_available_font();
  334. auto text_contents = text_path_element.text_contents();
  335. Utf8View text_utf8 { text_contents };
  336. auto shape_path = const_cast<SVG::SVGGeometryElement&>(*path_or_shape).get_path({ viewport_width, viewport_height });
  337. path = shape_path.place_text_along(text_utf8, font);
  338. }
  339. auto path_bounding_box = to_css_pixels_transform.map(path.bounding_box()).to_type<CSSPixels>();
  340. // Stroke increases the path's size by stroke_width/2 per side.
  341. CSSPixels stroke_width = CSSPixels::nearest_value_for(graphics_box.dom_node().visible_stroke_width() * viewbox_transform.x_scale());
  342. path_bounding_box.inflate(stroke_width, stroke_width);
  343. graphics_box_state.set_content_offset(path_bounding_box.top_left());
  344. graphics_box_state.set_content_width(path_bounding_box.width());
  345. graphics_box_state.set_content_height(path_bounding_box.height());
  346. graphics_box_state.set_has_definite_width(true);
  347. graphics_box_state.set_has_definite_height(true);
  348. graphics_box_state.set_computed_svg_path(move(path));
  349. }
  350. return TraversalDecision::Continue;
  351. });
  352. // https://svgwg.org/svg2-draft/struct.html#Groups
  353. // 5.2. Grouping: the ‘g’ element
  354. // The ‘g’ element is a container element for grouping together related graphics elements.
  355. box.for_each_in_subtree_of_type<SVGBox>([&](SVGBox const& descendant) {
  356. if (is_container_element(descendant)) {
  357. Gfx::BoundingBox<CSSPixels> bounding_box;
  358. for_each_in_subtree(descendant, [&](Node const& child_of_svg_container) {
  359. if (!is<SVGBox>(child_of_svg_container))
  360. return TraversalDecision::Continue;
  361. // Masks do not change the bounding box of their parents.
  362. if (is<SVGMaskBox>(child_of_svg_container))
  363. return TraversalDecision::SkipChildrenAndContinue;
  364. auto& box_state = m_state.get(static_cast<SVGBox const&>(child_of_svg_container));
  365. bounding_box.add_point(box_state.offset);
  366. bounding_box.add_point(box_state.offset.translated(box_state.content_width(), box_state.content_height()));
  367. return TraversalDecision::Continue;
  368. });
  369. auto& box_state = m_state.get_mutable(descendant);
  370. box_state.set_content_x(bounding_box.x());
  371. box_state.set_content_y(bounding_box.y());
  372. box_state.set_content_width(bounding_box.width());
  373. box_state.set_content_height(bounding_box.height());
  374. box_state.set_has_definite_width(true);
  375. box_state.set_has_definite_height(true);
  376. }
  377. return IterationDecision::Continue;
  378. });
  379. // Lay out masks last (as their parent needs to be sized first).
  380. box.for_each_in_subtree_of_type<SVGMaskBox>([&](SVGMaskBox const& mask_box) {
  381. auto& mask_state = m_state.get_mutable(static_cast<Box const&>(mask_box));
  382. auto parent_viewbox_transform = viewbox_transform;
  383. if (mask_box.dom_node().mask_content_units() == SVG::MaskContentUnits::ObjectBoundingBox) {
  384. auto* masked_node = mask_box.parent();
  385. auto& masked_node_state = m_state.get(*masked_node);
  386. mask_state.set_content_width(masked_node_state.content_width());
  387. mask_state.set_content_height(masked_node_state.content_height());
  388. parent_viewbox_transform = Gfx::AffineTransform {}.translate(masked_node_state.offset.to_type<float>());
  389. } else {
  390. mask_state.set_content_width(viewport_width);
  391. mask_state.set_content_height(viewport_height);
  392. }
  393. // Pretend masks are a viewport so we can scale the contents depending on the `maskContentUnits`.
  394. SVGFormattingContext nested_context(m_state, static_cast<Box const&>(mask_box), this, parent_viewbox_transform);
  395. mask_state.set_has_definite_width(true);
  396. mask_state.set_has_definite_height(true);
  397. nested_context.run(static_cast<Box const&>(mask_box), layout_mode, available_space);
  398. return IterationDecision::Continue;
  399. });
  400. }
  401. }