1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_LAYOUT_UTILS_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_LAYOUT_UTILS_H_ 7 8 #include "third_party/blink/renderer/core/layout/ng/ng_block_node.h" 9 10 namespace blink { 11 12 class NGConstraintSpace; 13 class NGLayoutResult; 14 15 // NGLayoutCacheStatus indicates what type of cache hit/miss occurred. For 16 // various types of misses we may be able to perform less work than a full 17 // layout. 18 // 19 // See |NGSimplifiedLayoutAlgorithm| for details about the 20 // |kNeedsSimplifiedLayout| cache miss type. 21 enum class NGLayoutCacheStatus { 22 kHit, // Cache hit, no additional work required. 23 kNeedsLayout, // Cache miss, full layout required. 24 kNeedsSimplifiedLayout, // Cache miss, simplified layout required. 25 kCanReuseLines // Cache miss, may be possible to reuse lines. 26 }; 27 28 // Calculates the |NGLayoutCacheStatus| based on sizing information. Returns: 29 // - |NGLayoutCacheStatus::kHit| if the size will be the same as 30 // |cached_layout_result|, and therefore might be able to skip layout. 31 // - |NGLayoutCacheStatus::kNeedsSimplifiedLayout| if a simplified layout may 32 // be possible (just based on the sizing information at this point). 33 // - |NGLayoutCacheStatus::kNeedsLayout| if a full layout is required. 34 // 35 // May pre-compute the |fragment_geometry| while calculating this status. 36 NGLayoutCacheStatus CalculateSizeBasedLayoutCacheStatus( 37 const NGBlockNode& node, 38 const NGLayoutResult& cached_layout_result, 39 const NGConstraintSpace& new_space, 40 base::Optional<NGFragmentGeometry>* fragment_geometry); 41 42 // Similar to |MaySkipLayout| but for legacy layout roots. Doesn't attempt to 43 // pre-compute the geometry of the fragment. 44 bool MaySkipLegacyLayout(const NGBlockNode& node, 45 const NGLayoutResult& cached_layout_result, 46 const NGConstraintSpace& new_space); 47 48 // Returns true if for a given |new_space|, the |cached_layout_result| won't be 49 // affected by clearance, or floats, and therefore might be able to skip 50 // layout. 51 // Additionally (if this function returns true) it will calculate the new 52 // |bfc_block_offset|, |block_offset_delta|, and |end_margin_strut| for the 53 // layout result. 54 // 55 // |bfc_block_offset| may still be |base::nullopt| if not previously set. 56 // 57 // If this function returns false, |bfc_block_offset|, |block_offset_delta|, 58 // and |end_margin_strut| are in an undefined state and should not be used. 59 bool MaySkipLayoutWithinBlockFormattingContext( 60 const NGLayoutResult& cached_layout_result, 61 const NGConstraintSpace& new_space, 62 base::Optional<LayoutUnit>* bfc_block_offset, 63 LayoutUnit* block_offset_delta, 64 NGMarginStrut* end_margin_strut); 65 66 } // namespace blink 67 68 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_LAYOUT_UTILS_H_ 69