2 * Copyright (c) 2012, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "FractionalLayoutBoxExtent.h"
34 #include "RenderStyle.h"
38 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalTop(const RenderStyle* style) const
40 return style->isHorizontalWritingMode() ? m_top : m_left;
43 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalBottom(const RenderStyle* style) const
45 return style->isHorizontalWritingMode() ? m_bottom : m_right;
48 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalLeft(const RenderStyle* style) const
50 return style->isHorizontalWritingMode() ? m_left : m_top;
53 FractionalLayoutUnit FractionalLayoutBoxExtent::logicalRight(const RenderStyle* style) const
55 return style->isHorizontalWritingMode() ? m_right : m_bottom;
58 FractionalLayoutUnit FractionalLayoutBoxExtent::before(const RenderStyle* style) const
60 switch (style->writingMode()) {
61 case TopToBottomWritingMode:
63 case BottomToTopWritingMode:
65 case LeftToRightWritingMode:
67 case RightToLeftWritingMode:
74 FractionalLayoutUnit FractionalLayoutBoxExtent::after(const RenderStyle* style) const
76 switch (style->writingMode()) {
77 case TopToBottomWritingMode:
79 case BottomToTopWritingMode:
81 case LeftToRightWritingMode:
83 case RightToLeftWritingMode:
90 FractionalLayoutUnit FractionalLayoutBoxExtent::start(const RenderStyle* style) const
92 if (style->isHorizontalWritingMode())
93 return style->isLeftToRightDirection() ? m_left : m_right;
94 return style->isLeftToRightDirection() ? m_top : m_bottom;
97 FractionalLayoutUnit FractionalLayoutBoxExtent::end(const RenderStyle* style) const
99 if (style->isHorizontalWritingMode())
100 return style->isLeftToRightDirection() ? m_right : m_left;
101 return style->isLeftToRightDirection() ? m_bottom : m_top;
104 void FractionalLayoutBoxExtent::setBefore(const RenderStyle* style, FractionalLayoutUnit value)
106 switch (style->writingMode()) {
107 case TopToBottomWritingMode:
110 case BottomToTopWritingMode:
113 case LeftToRightWritingMode:
116 case RightToLeftWritingMode:
120 ASSERT_NOT_REACHED();
125 void FractionalLayoutBoxExtent::setAfter(const RenderStyle* style, FractionalLayoutUnit value)
127 switch (style->writingMode()) {
128 case TopToBottomWritingMode:
131 case BottomToTopWritingMode:
134 case LeftToRightWritingMode:
137 case RightToLeftWritingMode:
141 ASSERT_NOT_REACHED();
146 void FractionalLayoutBoxExtent::setStart(const RenderStyle* style, FractionalLayoutUnit value)
148 if (style->isHorizontalWritingMode()) {
149 if (style->isLeftToRightDirection())
154 if (style->isLeftToRightDirection())
161 void FractionalLayoutBoxExtent::setEnd(const RenderStyle* style, FractionalLayoutUnit value)
163 if (style->isHorizontalWritingMode()) {
164 if (style->isLeftToRightDirection())
169 if (style->isLeftToRightDirection())
176 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalLeft(const RenderStyle* style)
178 return style->isHorizontalWritingMode() ? m_left : m_top;
181 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableLogicalRight(const RenderStyle* style)
183 return style->isHorizontalWritingMode() ? m_right : m_bottom;
186 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableBefore(const RenderStyle* style)
188 return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_bottom : m_top) :
189 (style->isFlippedBlocksWritingMode() ? m_right: m_left);
192 FractionalLayoutUnit& FractionalLayoutBoxExtent::mutableAfter(const RenderStyle* style)
194 return style->isHorizontalWritingMode() ? (style->isFlippedBlocksWritingMode() ? m_top : m_bottom) :
195 (style->isFlippedBlocksWritingMode() ? m_left: m_right);
198 } // namespace WebCore