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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc
diff --git a/third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..56fd109bd7b18116bacba34c5f1ed73e738ea050
--- /dev/null
+++ b/third_party/WebKit/Source/core/layout/ng/ng_relative_utils.cc
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
ikilpatrick 2017/03/16 19:08:36 2017
atotic 2017/03/20 17:31:45 done
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/layout/ng/ng_relative_utils.h"
+
+#include "core/layout/ng/geometry/ng_logical_offset.h"
+#include "core/style/ComputedStyle.h"
+#include "platform/LengthFunctions.h"
+#include "wtf/Optional.h"
+
+namespace blink {
+
+// Returns child's relative position wrt containing fragment.
+NGLogicalOffset ComputeRelativeOffset(const ComputedStyle& child_style,
+ NGWritingMode container_writing_mode,
+ TextDirection container_direction,
+ NGLogicalSize container_size) {
+ NGLogicalOffset offset;
+ bool is_horizontal =
+ container_writing_mode == NGWritingMode::kHorizontalTopBottom;
+
+ Optional<LayoutUnit> left, right, top, bottom;
+
+ if (is_horizontal) {
+ if (!child_style.left().isAuto())
+ 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.
+ if (!child_style.right().isAuto())
+ right = valueForLength(child_style.right(), container_size.inline_size);
+ if (!child_style.top().isAuto())
+ top = valueForLength(child_style.top(), container_size.block_size);
+ if (!child_style.bottom().isAuto())
+ bottom = valueForLength(child_style.bottom(), container_size.block_size);
+ } else {
+ if (!child_style.left().isAuto())
+ left = valueForLength(child_style.left(), container_size.block_size);
+ if (!child_style.right().isAuto())
+ right = valueForLength(child_style.right(), container_size.block_size);
+ if (!child_style.top().isAuto())
+ top = valueForLength(child_style.top(), container_size.inline_size);
+ if (!child_style.bottom().isAuto())
+ bottom = valueForLength(child_style.bottom(), container_size.inline_size);
+ }
+
+ // Implements confict resolution rules from spec:
+ // https://www.w3.org/TR/css-position-3/#rel-pos
+ if (!left && !right) {
+ left = LayoutUnit();
+ right = LayoutUnit();
+ }
+ if (!left)
+ left = -right.value();
+ if (!right)
+ right = -left.value();
+ if (!top && !bottom) {
+ top = LayoutUnit();
+ bottom = LayoutUnit();
+ }
+ if (!top)
+ top = -bottom.value();
+ if (!bottom)
+ bottom = -top.value();
+
+ bool is_ltr = container_direction == TextDirection::kLtr;
+
+ switch (container_writing_mode) {
+ case kHorizontalTopBottom:
+ offset.inline_offset = is_ltr ? left.value() : right.value();
+ offset.block_offset = top.value();
+ break;
+ case kVerticalRightLeft:
+ case kSidewaysRightLeft:
+ offset.inline_offset = is_ltr ? top.value() : bottom.value();
+ offset.block_offset = right.value();
+ break;
+ case kVerticalLeftRight:
+ offset.inline_offset = is_ltr ? top.value() : bottom.value();
+ offset.block_offset = left.value();
+ break;
+ case kSidewaysLeftRight:
+ offset.inline_offset = is_ltr ? bottom.value() : top.value();
+ offset.block_offset = left.value();
+ break;
+ }
+ return offset;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698