tree: 3304ac48a56df09ac41660dd332ec83d6bd5adfe [path history] [tgz]
  1. custom/
  2. exclusions/
  3. flex/
  4. geometry/
  5. grid/
  6. inline/
  7. list/
  8. mathml/
  9. table/
  10. BlockLayout.md
  11. layout_box_utils.cc
  12. layout_box_utils.h
  13. layout_ng_block_flow.cc
  14. layout_ng_block_flow.h
  15. layout_ng_block_flow_mixin.cc
  16. layout_ng_block_flow_mixin.h
  17. layout_ng_button.cc
  18. layout_ng_button.h
  19. layout_ng_fieldset.cc
  20. layout_ng_fieldset.h
  21. layout_ng_mixin.cc
  22. layout_ng_mixin.h
  23. layout_ng_progress.cc
  24. layout_ng_progress.h
  25. layout_ng_ruby_as_block.cc
  26. layout_ng_ruby_as_block.h
  27. layout_ng_ruby_base.cc
  28. layout_ng_ruby_base.h
  29. layout_ng_ruby_run.cc
  30. layout_ng_ruby_run.h
  31. layout_ng_ruby_text.cc
  32. layout_ng_ruby_text.h
  33. legacy_layout_tree_walking.h
  34. ng_absolute_utils.cc
  35. ng_absolute_utils.h
  36. ng_absolute_utils_test.cc
  37. ng_base_layout_algorithm_test.cc
  38. ng_base_layout_algorithm_test.h
  39. ng_block_break_token.cc
  40. ng_block_break_token.h
  41. ng_block_child_iterator.cc
  42. ng_block_child_iterator.h
  43. ng_block_child_iterator_test.cc
  44. ng_block_layout_algorithm.cc
  45. ng_block_layout_algorithm.h
  46. ng_block_layout_algorithm_test.cc
  47. ng_block_layout_algorithm_utils.cc
  48. ng_block_layout_algorithm_utils.h
  49. ng_block_node.cc
  50. ng_block_node.h
  51. ng_block_node_test.cc
  52. ng_box_fragment.cc
  53. ng_box_fragment.h
  54. ng_box_fragment_builder.cc
  55. ng_box_fragment_builder.h
  56. ng_break_appeal.h
  57. ng_break_token.cc
  58. ng_break_token.h
  59. ng_column_layout_algorithm.cc
  60. ng_column_layout_algorithm.h
  61. ng_column_layout_algorithm_test.cc
  62. ng_constraint_space.cc
  63. ng_constraint_space.h
  64. ng_constraint_space_builder.cc
  65. ng_constraint_space_builder.h
  66. ng_constraint_space_builder_test.cc
  67. ng_container_fragment_builder.cc
  68. ng_container_fragment_builder.h
  69. ng_early_break.h
  70. ng_fieldset_layout_algorithm.cc
  71. ng_fieldset_layout_algorithm.h
  72. ng_fieldset_layout_algorithm_test.cc
  73. ng_floats_utils.cc
  74. ng_floats_utils.h
  75. ng_fragment.h
  76. ng_fragment_builder.h
  77. ng_fragment_child_iterator.cc
  78. ng_fragment_child_iterator.h
  79. ng_fragment_child_iterator_test.cc
  80. ng_fragmentation_test.cc
  81. ng_fragmentation_utils.cc
  82. ng_fragmentation_utils.h
  83. ng_ink_overflow.cc
  84. ng_ink_overflow.h
  85. ng_ink_overflow_test.cc
  86. ng_inline_layout_test.cc
  87. ng_layout_algorithm.h
  88. ng_layout_input_node.cc
  89. ng_layout_input_node.h
  90. ng_layout_result.cc
  91. ng_layout_result.h
  92. ng_layout_result_caching_test.cc
  93. ng_layout_test.h
  94. ng_layout_utils.cc
  95. ng_layout_utils.h
  96. ng_length_utils.cc
  97. ng_length_utils.h
  98. ng_length_utils_test.cc
  99. ng_link.h
  100. ng_out_of_flow_layout_part.cc
  101. ng_out_of_flow_layout_part.h
  102. ng_out_of_flow_layout_part_test.cc
  103. ng_out_of_flow_positioned_node.h
  104. ng_outline_type.h
  105. ng_outline_utils.cc
  106. ng_outline_utils.h
  107. ng_page_layout_algorithm.cc
  108. ng_page_layout_algorithm.h
  109. ng_physical_box_fragment.cc
  110. ng_physical_box_fragment.h
  111. ng_physical_box_fragment_test.cc
  112. ng_physical_container_fragment.cc
  113. ng_physical_container_fragment.h
  114. ng_physical_fragment.cc
  115. ng_physical_fragment.h
  116. ng_positioned_float.h
  117. ng_relative_utils.cc
  118. ng_relative_utils.h
  119. ng_relative_utils_test.cc
  120. ng_simplified_layout_algorithm.cc
  121. ng_simplified_layout_algorithm.h
  122. ng_simplified_oof_layout_algorithm.cc
  123. ng_simplified_oof_layout_algorithm.h
  124. ng_space_utils.cc
  125. ng_space_utils.h
  126. ng_style_variant.h
  127. ng_text_decoration_offset.cc
  128. ng_text_decoration_offset.h
  129. ng_unpositioned_float.h
  130. OWNERS
  131. README.md
third_party/blink/renderer/core/layout/ng/README.md

LayoutNG

This directory contains the implementation of Blink's new layout engine “LayoutNG”.

This README can be viewed in formatted form here.

The original design document can be seen here.

High level overview

CSS has many different types of layout modes, controlled by the display property. (In addition to this specific HTML elements have custom layout modes as well). For each different type of layout, we have a NGLayoutAlgorithm.

The input to an NGLayoutAlgorithm is the same tuple for every kind of layout:

  • The NGBlockNode which we are currently performing layout for. The following information is accessed:

    • The ComputedStyle for the node which we are currently performing laying for.

    • The list of children NGBlockNodees to perform layout upon, and their respective style objects.

  • The NGConstraintSpace which represents the “space” in which the current layout should produce a NGPhysicalFragment.

  • TODO(layout-dev): BreakTokens should go here once implemented.

The current layout should not access any information outside this set, this will break invariants in the system. (As a concrete example we intend to cache NGPhysicalFragments based on this set, accessing additional information outside this set will break caching behaviour).

Box Tree

TODO(layout-dev): Document with lots of pretty pictures.

Inline Layout

Please refer to the inline layout README.

Fragment Tree

TODO(layout-dev): Document with lots of pretty pictures.

Constraint Spaces

TODO(layout-dev): Document with lots of pretty pictures.

Block Flow Algorithm

Please refer to the block flow layout docs.

Collapsing Margins

TODO(layout-dev): Document with lots of pretty pictures.

Float Positioning

TODO(layout-dev): Document with lots of pretty pictures.

Fragment Caching

After layout, we cache the resulting fragment to avoid redoing all of layout the next time. You can read the full design document.

Here's how it works:

  • We store the input constraint space and the resulting fragment on the LayoutNGBlockFlow. However, we only do that if we have no break token to simplify the initial implementation. We call LayoutNGBlockFlow::SetCachedLayoutResult from NGBlockNode::Layout.
  • Once cached, NGBlockNode::Layout checks at the beginning if we already have a cached result by calling LayoutNGBlockFlow::CachedLayoutResult. If that returns a layout result, we return it and are done.
  • CachedLayoutResult will always clone the fragment (but without the offset) so that the parent algorithm can position this fragment.
  • We only reuse a layout result if the constraint space is identical (using operator==), if there was no break token (a current limitation, we may lift this eventually), and if the node is not marked for layout. We need the NeedsLayout() check because we currently have no other way to ensure that relayout happens when style or children change. Eventually we need to rethink this part as we transition away from legacy layout.

Code coverage

The latest code coverage (from Feb 14 2017) can be found here. Here is the instruction how to generate a new result.

Environment setup

  1. Set up Chromium development environment for Windows
  2. Download DynamoRIO from www.dynamorio.org
  3. Extract downloaded DynamoRIO package into your chromium/src folder.
  4. Get dynamorio.git and extract it into your chromium/src folder git clone https://github.com/DynamoRIO/dynamorio.git
  5. Install Node js from https://nodejs.org/en/download/
  6. Install lcov-merger dependencies: npm install vinyl, npm install vinyl-fs
  7. Install Perl from https://www.perl.org/get.html#win32
  8. Get lcov-result-merger and extract into your chromium/src folder git clone https://github.com/mweibel/lcov-result-merger

Generating code coverage

  • Build the unit tets target with debug information chromium\src> ninja -C out\Debug blink_unittests
  • Run DynamoRIO with drcov tool chromium\src>DynamoRIO\bin64\drrun.exe -t drcov -- .\out\Debug\blink_unittests.exe --gtest_filter=NG*
  • Convert the output information to lcov format chromium\src>for %file in (*.log) do DynamoRIO\tools\bin64\drcov2lcov.exe -input %file -output %file.info -src_filter layout/ng -src_skip_filter _test
  • Merge all lcov files into one file chromium\src>node lcov-result-merger\bin\lcov-result-merger.js *.info output.info
  • Generate the coverage html from the lcov file chromium\src>C:\Perl64\bin\perl.exe dynamorio.git\third_party\lcov\genhtml output.info -o output

Debugging, logging and testing

Both layout input node subtrees and layout output physical fragment subtrees may be dumped, for debugging, logging and testing purposes.

For layout input node subtree

Call NGLayoutInputNode::ShowNodeTree() to dump the tree to stderr.

For physical fragment subtree

Call NGPhysicalFragment::ShowFragmentTree() to dump the tree to stderr. Fragments in the subtree are not required to be marked as placed (i.e. know their offset).

A fragment tree may also be dumped to a String, by calling NGPhysicalFragment::DumpFragmentTree(). It takes a flag parameter, so that the output can be customized to only contain what's relevant for a given purpose.