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

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

Issue 2755733003: Implement relative utilities (Closed)
Patch Set: Created 3 years, 9 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
ikilpatrick 2017/03/16 19:08:36 2017
atotic 2017/03/20 17:31:45 done
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/style/ComputedStyle.h"
9 #include "platform/LengthFunctions.h"
10 #include "wtf/Optional.h"
11
12 namespace blink {
13
14 // Returns child's relative position wrt containing fragment.
15 NGLogicalOffset ComputeRelativeOffset(const ComputedStyle& child_style,
16 NGWritingMode container_writing_mode,
17 TextDirection container_direction,
18 NGLogicalSize container_size) {
19 NGLogicalOffset offset;
20 bool is_horizontal =
21 container_writing_mode == NGWritingMode::kHorizontalTopBottom;
22
23 Optional<LayoutUnit> left, right, top, bottom;
24
25 if (is_horizontal) {
26 if (!child_style.left().isAuto())
27 left = valueForLength(child_style.left(), container_size.inline_size);
ikilpatrick 2017/03/16 19:08:36 would it be easier to just convert the container_s
atotic 2017/03/20 17:31:45 done. Thanks.
28 if (!child_style.right().isAuto())
29 right = valueForLength(child_style.right(), container_size.inline_size);
30 if (!child_style.top().isAuto())
31 top = valueForLength(child_style.top(), container_size.block_size);
32 if (!child_style.bottom().isAuto())
33 bottom = valueForLength(child_style.bottom(), container_size.block_size);
34 } else {
35 if (!child_style.left().isAuto())
36 left = valueForLength(child_style.left(), container_size.block_size);
37 if (!child_style.right().isAuto())
38 right = valueForLength(child_style.right(), container_size.block_size);
39 if (!child_style.top().isAuto())
40 top = valueForLength(child_style.top(), container_size.inline_size);
41 if (!child_style.bottom().isAuto())
42 bottom = valueForLength(child_style.bottom(), container_size.inline_size);
43 }
44
45 // Implements confict resolution rules from spec:
46 // https://www.w3.org/TR/css-position-3/#rel-pos
47 if (!left && !right) {
48 left = LayoutUnit();
49 right = LayoutUnit();
50 }
51 if (!left)
52 left = -right.value();
53 if (!right)
54 right = -left.value();
55 if (!top && !bottom) {
56 top = LayoutUnit();
57 bottom = LayoutUnit();
58 }
59 if (!top)
60 top = -bottom.value();
61 if (!bottom)
62 bottom = -top.value();
63
64 bool is_ltr = container_direction == TextDirection::kLtr;
65
66 switch (container_writing_mode) {
67 case kHorizontalTopBottom:
68 offset.inline_offset = is_ltr ? left.value() : right.value();
69 offset.block_offset = top.value();
70 break;
71 case kVerticalRightLeft:
72 case kSidewaysRightLeft:
73 offset.inline_offset = is_ltr ? top.value() : bottom.value();
74 offset.block_offset = right.value();
75 break;
76 case kVerticalLeftRight:
77 offset.inline_offset = is_ltr ? top.value() : bottom.value();
78 offset.block_offset = left.value();
79 break;
80 case kSidewaysLeftRight:
81 offset.inline_offset = is_ltr ? bottom.value() : top.value();
82 offset.block_offset = left.value();
83 break;
84 }
85 return offset;
86 }
87
88 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698