| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/layout/ng/ng_absolute_utils.h" | 5 #include "core/layout/ng/ng_absolute_utils.h" |
| 6 | 6 |
| 7 #include "core/layout/ng/ng_constraint_space.h" | 7 #include "core/layout/ng/ng_constraint_space.h" |
| 8 #include "core/layout/ng/ng_length_utils.h" | 8 #include "core/layout/ng/ng_length_utils.h" |
| 9 #include "core/style/ComputedStyle.h" | 9 #include "core/style/ComputedStyle.h" |
| 10 #include "platform/LengthFunctions.h" | 10 #include "platform/LengthFunctions.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Solving the equation: | 78 // Solving the equation: |
| 79 // left + marginLeft + width + marginRight + right = container width | 79 // left + marginLeft + width + marginRight + right = container width |
| 80 if (!left && !right && !width) { | 80 if (!left && !right && !width) { |
| 81 // Standard: "If all three of left, width, and right are auto:" | 81 // Standard: "If all three of left, width, and right are auto:" |
| 82 if (!margin_left) | 82 if (!margin_left) |
| 83 margin_left = LayoutUnit(); | 83 margin_left = LayoutUnit(); |
| 84 if (!margin_right) | 84 if (!margin_right) |
| 85 margin_right = LayoutUnit(); | 85 margin_right = LayoutUnit(); |
| 86 DCHECK(child_minmax.has_value()); | 86 DCHECK(child_minmax.has_value()); |
| 87 width = child_minmax->ShrinkToFit(container_size.width); | 87 width = child_minmax->ShrinkToFit(container_size.width); |
| 88 if (space.Direction() == TextDirection::Ltr) { | 88 if (space.Direction() == TextDirection::kLtr) { |
| 89 left = static_position.LeftPosition(container_size.width, *width, | 89 left = static_position.LeftPosition(container_size.width, *width, |
| 90 *margin_left, *margin_right); | 90 *margin_left, *margin_right); |
| 91 } else { | 91 } else { |
| 92 right = static_position.RightPosition(container_size.width, *width, | 92 right = static_position.RightPosition(container_size.width, *width, |
| 93 *margin_left, *margin_right); | 93 *margin_left, *margin_right); |
| 94 } | 94 } |
| 95 } else if (left && right && width) { | 95 } else if (left && right && width) { |
| 96 // Standard: "If left, right, and width are not auto:" | 96 // Standard: "If left, right, and width are not auto:" |
| 97 // Compute margins. | 97 // Compute margins. |
| 98 LayoutUnit margin_space = container_size.width - *left - *right - *width; | 98 LayoutUnit margin_space = container_size.width - *left - *right - *width; |
| 99 // When both margins are auto. | 99 // When both margins are auto. |
| 100 if (!margin_left && !margin_right) { | 100 if (!margin_left && !margin_right) { |
| 101 if (margin_space > 0) { | 101 if (margin_space > 0) { |
| 102 margin_left = margin_space / 2; | 102 margin_left = margin_space / 2; |
| 103 margin_right = margin_space / 2; | 103 margin_right = margin_space / 2; |
| 104 } else { | 104 } else { |
| 105 // Margins are negative. | 105 // Margins are negative. |
| 106 if (space.Direction() == TextDirection::Ltr) { | 106 if (space.Direction() == TextDirection::kLtr) { |
| 107 margin_left = LayoutUnit(); | 107 margin_left = LayoutUnit(); |
| 108 margin_right = margin_space; | 108 margin_right = margin_space; |
| 109 } else { | 109 } else { |
| 110 margin_right = LayoutUnit(); | 110 margin_right = LayoutUnit(); |
| 111 margin_left = margin_space; | 111 margin_left = margin_space; |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 } else if (!margin_left) { | 114 } else if (!margin_left) { |
| 115 margin_left = margin_space; | 115 margin_left = margin_space; |
| 116 } else if (!margin_right) { | 116 } else if (!margin_right) { |
| 117 margin_right = margin_space; | 117 margin_right = margin_space; |
| 118 } else { | 118 } else { |
| 119 // Are values overconstrained? | 119 // Are values overconstrained? |
| 120 if (*margin_left + *margin_right != margin_space) { | 120 if (*margin_left + *margin_right != margin_space) { |
| 121 // Relax the end. | 121 // Relax the end. |
| 122 if (space.Direction() == TextDirection::Ltr) | 122 if (space.Direction() == TextDirection::kLtr) |
| 123 right = *right - *margin_left + *margin_right - margin_space; | 123 right = *right - *margin_left + *margin_right - margin_space; |
| 124 else | 124 else |
| 125 left = *left - *margin_left + *margin_right - margin_space; | 125 left = *left - *margin_left + *margin_right - margin_space; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Set unknown margins. | 130 // Set unknown margins. |
| 131 if (!margin_left) | 131 if (!margin_left) |
| 132 margin_left = LayoutUnit(); | 132 margin_left = LayoutUnit(); |
| 133 if (!margin_right) | 133 if (!margin_right) |
| 134 margin_right = LayoutUnit(); | 134 margin_right = LayoutUnit(); |
| 135 | 135 |
| 136 // Rules 1 through 3, 2 out of 3 are unknown. | 136 // Rules 1 through 3, 2 out of 3 are unknown. |
| 137 if (!left && !width) { | 137 if (!left && !width) { |
| 138 // Rule 1: left/width are unknown. | 138 // Rule 1: left/width are unknown. |
| 139 DCHECK(right.has_value()); | 139 DCHECK(right.has_value()); |
| 140 DCHECK(child_minmax.has_value()); | 140 DCHECK(child_minmax.has_value()); |
| 141 width = child_minmax->ShrinkToFit(container_size.width); | 141 width = child_minmax->ShrinkToFit(container_size.width); |
| 142 } else if (!left && !right) { | 142 } else if (!left && !right) { |
| 143 // Rule 2. | 143 // Rule 2. |
| 144 DCHECK(width.has_value()); | 144 DCHECK(width.has_value()); |
| 145 if (space.Direction() == TextDirection::Ltr) | 145 if (space.Direction() == TextDirection::kLtr) |
| 146 left = static_position.LeftPosition(container_size.width, *width, | 146 left = static_position.LeftPosition(container_size.width, *width, |
| 147 *margin_left, *margin_right); | 147 *margin_left, *margin_right); |
| 148 else | 148 else |
| 149 right = static_position.RightPosition(container_size.width, *width, | 149 right = static_position.RightPosition(container_size.width, *width, |
| 150 *margin_left, *margin_right); | 150 *margin_left, *margin_right); |
| 151 } else if (!width && !right) { | 151 } else if (!width && !right) { |
| 152 // Rule 3. | 152 // Rule 3. |
| 153 DCHECK(child_minmax.has_value()); | 153 DCHECK(child_minmax.has_value()); |
| 154 width = child_minmax->ShrinkToFit(container_size.width); | 154 width = child_minmax->ShrinkToFit(container_size.width); |
| 155 } | 155 } |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 if (style.isHorizontalWritingMode()) | 369 if (style.isHorizontalWritingMode()) |
| 370 ComputeAbsoluteVertical(space, style, static_position, child_minmax, | 370 ComputeAbsoluteVertical(space, style, static_position, child_minmax, |
| 371 position); | 371 position); |
| 372 else { | 372 else { |
| 373 ComputeAbsoluteHorizontal(space, style, static_position, child_minmax, | 373 ComputeAbsoluteHorizontal(space, style, static_position, child_minmax, |
| 374 position); | 374 position); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace blink | 378 } // namespace blink |
| OLD | NEW |