Index: third_party/WebKit/Source/core/layout/ng/geometry/ng_box_strut.cc |
diff --git a/third_party/WebKit/Source/core/layout/ng/geometry/ng_box_strut.cc b/third_party/WebKit/Source/core/layout/ng/geometry/ng_box_strut.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2fa722838ae83bc83ff9448805d7abcbe33872e6 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/layout/ng/geometry/ng_box_strut.cc |
@@ -0,0 +1,56 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "core/layout/ng/geometry/ng_box_strut.h" |
+ |
+#include "wtf/text/WTFString.h" |
+ |
+namespace blink { |
+ |
+bool NGBoxStrut::IsEmpty() const { |
+ return *this == NGBoxStrut(); |
+} |
+ |
+bool NGBoxStrut::operator==(const NGBoxStrut& other) const { |
+ return std::tie(other.inline_start, other.inline_end, other.block_start, |
+ other.block_end) == |
+ std::tie(inline_start, inline_end, block_start, block_end); |
+} |
+ |
+// Converts physical dimensions to logical ones per |
+// https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical |
+NGBoxStrut NGPhysicalBoxStrut::ConvertToLogical(NGWritingMode writing_mode, |
+ TextDirection direction) const { |
+ NGBoxStrut strut; |
+ switch (writing_mode) { |
+ case kHorizontalTopBottom: |
+ strut = {left, right, top, bottom}; |
+ break; |
+ case kVerticalRightLeft: |
+ case kSidewaysRightLeft: |
+ strut = {top, bottom, right, left}; |
+ break; |
+ case kVerticalLeftRight: |
+ strut = {top, bottom, left, right}; |
+ break; |
+ case kSidewaysLeftRight: |
+ strut = {bottom, top, left, right}; |
+ break; |
+ } |
+ if (direction == TextDirection::kRtl) |
+ std::swap(strut.inline_start, strut.inline_end); |
+ return strut; |
+} |
+ |
+String NGBoxStrut::ToString() const { |
+ return String::format("Inline: (%d %d) Block: (%d %d)", inline_start.toInt(), |
+ inline_end.toInt(), block_start.toInt(), |
+ block_end.toInt()); |
+} |
+ |
+std::ostream& operator<<(std::ostream& stream, const NGBoxStrut& value) { |
+ return stream << value.ToString(); |
+} |
+ |
+} // namespace blink |