diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/platform/LengthBox.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/platform/LengthBox.h')
-rw-r--r-- | Source/WebCore/platform/LengthBox.h | 156 |
1 files changed, 106 insertions, 50 deletions
diff --git a/Source/WebCore/platform/LengthBox.h b/Source/WebCore/platform/LengthBox.h index 9addabd23..3e0f2184e 100644 --- a/Source/WebCore/platform/LengthBox.h +++ b/Source/WebCore/platform/LengthBox.h @@ -1,6 +1,6 @@ /* Copyright (C) 1999 Lars Knoll (knoll@kde.org) - Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + Copyright (C) 2006, 2008, 2015 Apple Inc. All rights reserved. Copyright (c) 2012, Google Inc. All rights reserved. This library is free software; you can redistribute it and/or @@ -19,88 +19,144 @@ Boston, MA 02110-1301, USA. */ -#ifndef LengthBox_h -#define LengthBox_h +#pragma once #include "Length.h" -#include "TextDirection.h" #include "WritingMode.h" +#include <array> namespace WebCore { -class RenderStyle; +template<typename T> class BoxExtent { +public: + BoxExtent() + : m_sides({ { { 0 }, { 0 }, { 0 }, { 0 } } }) + { + } -struct LengthBox { - LengthBox() + BoxExtent(const T& top, const T& right, const T& bottom, const T& left) + : m_sides({ { top, right, bottom, left } }) { } - LengthBox(LengthType t) - : m_left(t) - , m_right(t) - , m_top(t) - , m_bottom(t) + BoxExtent(T&& top, T&& right, T&& bottom, T&& left) + : m_sides({ { std::forward<T>(top), std::forward<T>(right), std::forward<T>(bottom), std::forward<T>(left) } }) { } - LengthBox(int v) - : m_left(Length(v, Fixed)) - , m_right(Length(v, Fixed)) - , m_top(Length(v, Fixed)) - , m_bottom(Length(v, Fixed)) + T& at(PhysicalBoxSide side) { return m_sides[side]; } + T& top() { return at(TopSide); } + T& right() { return at(RightSide); } + T& bottom() { return at(BottomSide); } + T& left() { return at(LeftSide); } + + const T& at(PhysicalBoxSide side) const { return m_sides[side]; } + const T& top() const { return at(TopSide); } + const T& right() const { return at(RightSide); } + const T& bottom() const { return at(BottomSide); } + const T& left() const { return at(LeftSide); } + + void setAt(PhysicalBoxSide side, const T& v) { at(side) = v; } + void setTop(const T& top) { setAt(TopSide, top); } + void setRight(const T& right) { setAt(RightSide, right); } + void setBottom(const T& bottom) { setAt(BottomSide, bottom); } + void setLeft(const T& left) { setAt(LeftSide, left); } + + T& before(WritingMode writingMode) { + return at(mapLogicalSideToPhysicalSide(writingMode, BeforeSide)); } - LengthBox(Length t, Length r, Length b, Length l) - : m_left(std::move(l)) - , m_right(std::move(r)) - , m_top(std::move(t)) - , m_bottom(std::move(b)) + T& after(WritingMode writingMode) { + return at(mapLogicalSideToPhysicalSide(writingMode, AfterSide)); } - - LengthBox(int t, int r, int b, int l) - : m_left(Length(l, Fixed)) - , m_right(Length(r, Fixed)) - , m_top(Length(t, Fixed)) - , m_bottom(Length(b, Fixed)) + + T& start(WritingMode writingMode, TextDirection direction = LTR) { + return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), StartSide)); } - const Length& left() const { return m_left; } - const Length& right() const { return m_right; } - const Length& top() const { return m_top; } - const Length& bottom() const { return m_bottom; } + T& end(WritingMode writingMode, TextDirection direction = LTR) + { + return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), EndSide)); + } - const Length& logicalLeft(WritingMode) const; - const Length& logicalRight(WritingMode) const; + const T& before(WritingMode writingMode) const + { + return at(mapLogicalSideToPhysicalSide(writingMode, BeforeSide)); + } - const Length& before(WritingMode) const; - const Length& after(WritingMode) const; - const Length& start(WritingMode, TextDirection) const; - const Length& end(WritingMode, TextDirection) const; + const T& after(WritingMode writingMode) const + { + return at(mapLogicalSideToPhysicalSide(writingMode, AfterSide)); + } - bool operator==(const LengthBox& o) const + const T& start(WritingMode writingMode, TextDirection direction = LTR) const { - return m_left == o.m_left && m_right == o.m_right && m_top == o.m_top && m_bottom == o.m_bottom; + return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), StartSide)); } - bool operator!=(const LengthBox& o) const + const T& end(WritingMode writingMode, TextDirection direction = LTR) const { - return !(*this == o); + return at(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), EndSide)); } - bool nonZero() const + void setBefore(const T& before, WritingMode writingMode) { this->before(writingMode) = before; } + void setAfter(const T& after, WritingMode writingMode) { this->after(writingMode) = after; } + void setStart(const T& start, WritingMode writingMode, TextDirection direction = LTR) { this->start(writingMode, direction) = start; } + void setEnd(const T& end, WritingMode writingMode, TextDirection direction = LTR) { this->end(writingMode, direction) = end; } + + bool operator==(const BoxExtent& other) const { - return !(m_left.isZero() && m_right.isZero() && m_top.isZero() && m_bottom.isZero()); + return m_sides == other.m_sides; } - Length m_left; - Length m_right; - Length m_top; - Length m_bottom; + bool operator!=(const BoxExtent& other) const + { + return m_sides != other.m_sides; + } + +protected: + std::array<T, 4> m_sides; }; -} // namespace WebCore +class LengthBox : public BoxExtent<Length> { +public: + LengthBox() + : LengthBox(Auto) + { + } -#endif // LengthBox_h + explicit LengthBox(LengthType type) + : BoxExtent(Length(type), Length(type), Length(type), Length(type)) + { + } + + explicit LengthBox(int v) + : BoxExtent(Length(v, Fixed), Length(v, Fixed), Length(v, Fixed), Length(v, Fixed)) + { + } + + LengthBox(int top, int right, int bottom, int left) + : BoxExtent(Length(top, Fixed), Length(right, Fixed), Length(bottom, Fixed), Length(left, Fixed)) + { + } + + LengthBox(Length&& top, Length&& right, Length&& bottom, Length&& left) + : BoxExtent { WTFMove(top), WTFMove(right), WTFMove(bottom), WTFMove(left) } + { + } + + bool isZero() const + { + return top().isZero() && right().isZero() && bottom().isZero() && left().isZero(); + } +}; + +using LayoutBoxExtent = BoxExtent<LayoutUnit>; +using FloatBoxExtent = BoxExtent<float>; + +TextStream& operator<<(TextStream&, const LengthBox&); + +} // namespace WebCore |