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_relative_utils.h" |
| 6 |
| 7 #include "core/layout/ng/geometry/ng_logical_offset.h" |
| 8 #include "core/layout/ng/geometry/ng_physical_size.h" |
| 9 #include "core/style/ComputedStyle.h" |
| 10 #include "platform/LengthFunctions.h" |
| 11 #include "wtf/Optional.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 // Returns the child's relative position wrt the containing fragment. |
| 16 NGLogicalOffset ComputeRelativeOffset(const ComputedStyle& child_style, |
| 17 NGWritingMode container_writing_mode, |
| 18 TextDirection container_direction, |
| 19 NGLogicalSize container_logical_size) { |
| 20 NGLogicalOffset offset; |
| 21 NGPhysicalSize container_size = |
| 22 container_logical_size.ConvertToPhysical(container_writing_mode); |
| 23 |
| 24 Optional<LayoutUnit> left, right, top, bottom; |
| 25 |
| 26 if (!child_style.left().isAuto()) |
| 27 left = valueForLength(child_style.left(), container_size.width); |
| 28 if (!child_style.right().isAuto()) |
| 29 right = valueForLength(child_style.right(), container_size.width); |
| 30 if (!child_style.top().isAuto()) |
| 31 top = valueForLength(child_style.top(), container_size.height); |
| 32 if (!child_style.bottom().isAuto()) |
| 33 bottom = valueForLength(child_style.bottom(), container_size.height); |
| 34 |
| 35 // Implements confict resolution rules from spec: |
| 36 // https://www.w3.org/TR/css-position-3/#rel-pos |
| 37 if (!left && !right) { |
| 38 left = LayoutUnit(); |
| 39 right = LayoutUnit(); |
| 40 } |
| 41 if (!left) |
| 42 left = -right.value(); |
| 43 if (!right) |
| 44 right = -left.value(); |
| 45 if (!top && !bottom) { |
| 46 top = LayoutUnit(); |
| 47 bottom = LayoutUnit(); |
| 48 } |
| 49 if (!top) |
| 50 top = -bottom.value(); |
| 51 if (!bottom) |
| 52 bottom = -top.value(); |
| 53 |
| 54 bool is_ltr = container_direction == TextDirection::kLtr; |
| 55 |
| 56 switch (container_writing_mode) { |
| 57 case kHorizontalTopBottom: |
| 58 offset.inline_offset = is_ltr ? left.value() : right.value(); |
| 59 offset.block_offset = top.value(); |
| 60 break; |
| 61 case kVerticalRightLeft: |
| 62 case kSidewaysRightLeft: |
| 63 offset.inline_offset = is_ltr ? top.value() : bottom.value(); |
| 64 offset.block_offset = right.value(); |
| 65 break; |
| 66 case kVerticalLeftRight: |
| 67 offset.inline_offset = is_ltr ? top.value() : bottom.value(); |
| 68 offset.block_offset = left.value(); |
| 69 break; |
| 70 case kSidewaysLeftRight: |
| 71 offset.inline_offset = is_ltr ? bottom.value() : top.value(); |
| 72 offset.block_offset = left.value(); |
| 73 break; |
| 74 } |
| 75 return offset; |
| 76 } |
| 77 |
| 78 } // namespace blink |
OLD | NEW |