Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_absolute_utils.cc

Issue 2555923002: Changed TextDirection to an enum class and renamed its members (Closed)
Patch Set: Rebase after reopen Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // left + marginLeft + width + marginRight + right = container width 77 // left + marginLeft + width + marginRight + right = container width
78 if (left == NGSizeIndefinite && right == NGSizeIndefinite && 78 if (left == NGSizeIndefinite && right == NGSizeIndefinite &&
79 width == NGSizeIndefinite) { 79 width == NGSizeIndefinite) {
80 // Standard: "If all three of left, width, and right are auto:" 80 // Standard: "If all three of left, width, and right are auto:"
81 if (margin_left == NGSizeIndefinite) 81 if (margin_left == NGSizeIndefinite)
82 margin_left = LayoutUnit(); 82 margin_left = LayoutUnit();
83 if (margin_right == NGSizeIndefinite) 83 if (margin_right == NGSizeIndefinite)
84 margin_right = LayoutUnit(); 84 margin_right = LayoutUnit();
85 DCHECK(child_auto_width.has_value()); 85 DCHECK(child_auto_width.has_value());
86 width = *child_auto_width; 86 width = *child_auto_width;
87 if (space.Direction() == LTR) { 87 if (space.Direction() == TextDirection::Ltr) {
88 left = static_position.LeftPosition(container_size.width, width, 88 left = static_position.LeftPosition(container_size.width, width,
89 margin_left, margin_right); 89 margin_left, margin_right);
90 } else { 90 } else {
91 right = static_position.RightPosition(container_size.width, width, 91 right = static_position.RightPosition(container_size.width, width,
92 margin_left, margin_right); 92 margin_left, margin_right);
93 } 93 }
94 } else if (left != NGSizeIndefinite && right != NGSizeIndefinite && 94 } else if (left != NGSizeIndefinite && right != NGSizeIndefinite &&
95 width != NGSizeIndefinite) { 95 width != NGSizeIndefinite) {
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 == NGSizeIndefinite && margin_right == NGSizeIndefinite) { 100 if (margin_left == NGSizeIndefinite && margin_right == NGSizeIndefinite) {
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() == LTR) { 106 if (space.Direction() == TextDirection::Ltr) {
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 == NGSizeIndefinite) { 114 } else if (margin_left == NGSizeIndefinite) {
115 margin_left = margin_space; 115 margin_left = margin_space;
116 } else if (margin_right == NGSizeIndefinite) { 116 } else if (margin_right == NGSizeIndefinite) {
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() == LTR) 122 if (space.Direction() == TextDirection::Ltr)
123 right -= margin_left + margin_right - margin_space; 123 right -= margin_left + margin_right - margin_space;
124 else 124 else
125 left -= margin_left + margin_right - margin_space; 125 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 == NGSizeIndefinite) 131 if (margin_left == NGSizeIndefinite)
132 margin_left = LayoutUnit(); 132 margin_left = LayoutUnit();
133 if (margin_right == NGSizeIndefinite) 133 if (margin_right == NGSizeIndefinite)
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 == NGSizeIndefinite && width == NGSizeIndefinite) { 137 if (left == NGSizeIndefinite && width == NGSizeIndefinite) {
138 // Rule 1: left/width are unknown. 138 // Rule 1: left/width are unknown.
139 DCHECK_NE(right, NGSizeIndefinite); 139 DCHECK_NE(right, NGSizeIndefinite);
140 DCHECK(child_auto_width.has_value()); 140 DCHECK(child_auto_width.has_value());
141 width = *child_auto_width; 141 width = *child_auto_width;
142 } else if (left == NGSizeIndefinite && right == NGSizeIndefinite) { 142 } else if (left == NGSizeIndefinite && right == NGSizeIndefinite) {
143 // Rule 2. 143 // Rule 2.
144 DCHECK_NE(width, NGSizeIndefinite); 144 DCHECK_NE(width, NGSizeIndefinite);
145 if (space.Direction() == LTR) 145 if (space.Direction() == TextDirection::Ltr)
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 == NGSizeIndefinite && right == NGSizeIndefinite) { 151 } else if (width == NGSizeIndefinite && right == NGSizeIndefinite) {
152 // Rule 3. 152 // Rule 3.
153 DCHECK(child_auto_width.has_value()); 153 DCHECK(child_auto_width.has_value());
154 width = *child_auto_width; 154 width = *child_auto_width;
155 } 155 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 NGAbsolutePhysicalPosition* position) { 342 NGAbsolutePhysicalPosition* position) {
343 if (style.isHorizontalWritingMode()) 343 if (style.isHorizontalWritingMode())
344 ComputeAbsoluteVertical(space, style, static_position, child_block_size, 344 ComputeAbsoluteVertical(space, style, static_position, child_block_size,
345 position); 345 position);
346 else 346 else
347 ComputeAbsoluteHorizontal(space, style, static_position, child_block_size, 347 ComputeAbsoluteHorizontal(space, style, static_position, child_block_size,
348 position); 348 position);
349 } 349 }
350 350
351 } // namespace blink 351 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698