OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "core/layout/ng/ng_space_utils.h" |
| 6 |
| 7 namespace blink { |
| 8 namespace { |
| 9 |
| 10 // Returns max of 2 {@code WTF::Optional} values. |
| 11 template <typename T> |
| 12 WTF::Optional<T> OptionalMax(const WTF::Optional<T>& value1, |
| 13 const WTF::Optional<T>& value2) { |
| 14 if (value1 && value2) { |
| 15 return std::max(value1.value(), value2.value()); |
| 16 } else if (value1) { |
| 17 return value1; |
| 18 } |
| 19 return value2; |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 bool IsNewFormattingContextForInFlowBlockLevelChild( |
| 25 const NGConstraintSpace& space, |
| 26 const ComputedStyle& style) { |
| 27 // TODO(layout-dev): This doesn't capture a few cases which can't be computed |
| 28 // directly from style yet: |
| 29 // - The child is a <fieldset>. |
| 30 // - "column-span: all" is set on the child (requires knowledge that we are |
| 31 // in a multi-col formatting context). |
| 32 // (https://drafts.csswg.org/css-multicol-1/#valdef-column-span-all) |
| 33 |
| 34 if (style.specifiesColumns() || style.containsPaint() || |
| 35 style.containsLayout()) |
| 36 return true; |
| 37 |
| 38 if (!style.isOverflowVisible()) |
| 39 return true; |
| 40 |
| 41 EDisplay display = style.display(); |
| 42 if (display == EDisplay::kGrid || display == EDisplay::kFlex || |
| 43 display == EDisplay::kWebkitBox) |
| 44 return true; |
| 45 |
| 46 if (space.WritingMode() != FromPlatformWritingMode(style.getWritingMode())) |
| 47 return true; |
| 48 |
| 49 return false; |
| 50 } |
| 51 |
| 52 WTF::Optional<LayoutUnit> GetClearanceOffset( |
| 53 const std::shared_ptr<NGExclusions>& exclusions, |
| 54 const ComputedStyle& style) { |
| 55 const NGExclusion* right_exclusion = exclusions->last_right_float; |
| 56 const NGExclusion* left_exclusion = exclusions->last_left_float; |
| 57 |
| 58 WTF::Optional<LayoutUnit> left_offset; |
| 59 if (left_exclusion) { |
| 60 left_offset = left_exclusion->rect.BlockEndOffset(); |
| 61 } |
| 62 WTF::Optional<LayoutUnit> right_offset; |
| 63 if (right_exclusion) { |
| 64 right_offset = right_exclusion->rect.BlockEndOffset(); |
| 65 } |
| 66 |
| 67 switch (style.clear()) { |
| 68 case EClear::kNone: |
| 69 return WTF::nullopt; // nothing to do here. |
| 70 case EClear::kLeft: |
| 71 return left_offset; |
| 72 case EClear::kRight: |
| 73 return right_offset; |
| 74 case EClear::kBoth: |
| 75 return OptionalMax<LayoutUnit>(left_offset, right_offset); |
| 76 default: |
| 77 ASSERT_NOT_REACHED(); |
| 78 } |
| 79 return WTF::nullopt; |
| 80 } |
| 81 |
| 82 } // namespace blink |
OLD | NEW |