Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (c) 2012, Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      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
     13  * distribution.
     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.
     17  *
     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.
     29  */
     30 
     31 #include "config.h"
     32 #include "core/platform/graphics/LayoutBoxExtent.h"
     33 
     34 namespace WebCore {
     35 
     36 LayoutUnit LayoutBoxExtent::logicalTop(WritingMode writingMode) const
     37 {
     38     return isHorizontalWritingMode(writingMode) ? m_top : m_left;
     39 }
     40 
     41 LayoutUnit LayoutBoxExtent::logicalBottom(WritingMode writingMode) const
     42 {
     43     return isHorizontalWritingMode(writingMode) ? m_bottom : m_right;
     44 }
     45 
     46 LayoutUnit LayoutBoxExtent::logicalLeft(WritingMode writingMode) const
     47 {
     48     return isHorizontalWritingMode(writingMode) ? m_left : m_top;
     49 }
     50 
     51 LayoutUnit LayoutBoxExtent::logicalRight(WritingMode writingMode) const
     52 {
     53     return isHorizontalWritingMode(writingMode) ? m_right : m_bottom;
     54 }
     55 
     56 LayoutUnit LayoutBoxExtent::before(WritingMode writingMode) const
     57 {
     58     switch (writingMode) {
     59     case TopToBottomWritingMode:
     60         return m_top;
     61     case BottomToTopWritingMode:
     62         return m_bottom;
     63     case LeftToRightWritingMode:
     64         return m_left;
     65     case RightToLeftWritingMode:
     66         return m_right;
     67     }
     68     ASSERT_NOT_REACHED();
     69     return m_top;
     70 }
     71 
     72 LayoutUnit LayoutBoxExtent::after(WritingMode writingMode) const
     73 {
     74     switch (writingMode) {
     75     case TopToBottomWritingMode:
     76         return m_bottom;
     77     case BottomToTopWritingMode:
     78         return m_top;
     79     case LeftToRightWritingMode:
     80         return m_right;
     81     case RightToLeftWritingMode:
     82         return m_left;
     83     }
     84     ASSERT_NOT_REACHED();
     85     return m_bottom;
     86 }
     87 
     88 LayoutUnit LayoutBoxExtent::start(WritingMode writingMode, TextDirection direction) const
     89 {
     90     if (isHorizontalWritingMode(writingMode))
     91         return isLeftToRightDirection(direction) ? m_left : m_right;
     92     return isLeftToRightDirection(direction) ? m_top : m_bottom;
     93 }
     94 
     95 LayoutUnit LayoutBoxExtent::end(WritingMode writingMode, TextDirection direction) const
     96 {
     97     if (isHorizontalWritingMode(writingMode))
     98         return isLeftToRightDirection(direction) ? m_right : m_left;
     99     return isLeftToRightDirection(direction) ? m_bottom : m_top;
    100 }
    101 
    102 void LayoutBoxExtent::setBefore(WritingMode writingMode, LayoutUnit value)
    103 {
    104     switch (writingMode) {
    105     case TopToBottomWritingMode:
    106         m_top = value;
    107         break;
    108     case BottomToTopWritingMode:
    109         m_bottom = value;
    110         break;
    111     case LeftToRightWritingMode:
    112         m_left = value;
    113         break;
    114     case RightToLeftWritingMode:
    115         m_right = value;
    116         break;
    117     default:
    118         ASSERT_NOT_REACHED();
    119         m_top = value;
    120     }
    121 }
    122 
    123 void LayoutBoxExtent::setAfter(WritingMode writingMode, LayoutUnit value)
    124 {
    125     switch (writingMode) {
    126     case TopToBottomWritingMode:
    127         m_bottom = value;
    128         break;
    129     case BottomToTopWritingMode:
    130         m_top = value;
    131         break;
    132     case LeftToRightWritingMode:
    133         m_right = value;
    134         break;
    135     case RightToLeftWritingMode:
    136         m_left = value;
    137         break;
    138     default:
    139         ASSERT_NOT_REACHED();
    140         m_bottom = value;
    141     }
    142 }
    143 
    144 void LayoutBoxExtent::setStart(WritingMode writingMode, TextDirection direction, LayoutUnit value)
    145 {
    146     if (isHorizontalWritingMode(writingMode)) {
    147         if (isLeftToRightDirection(direction))
    148             m_left = value;
    149         else
    150             m_right = value;
    151     } else {
    152         if (isLeftToRightDirection(direction))
    153             m_top = value;
    154         else
    155             m_bottom = value;
    156     }
    157 }
    158 
    159 void LayoutBoxExtent::setEnd(WritingMode writingMode, TextDirection direction, LayoutUnit value)
    160 {
    161     if (isHorizontalWritingMode(writingMode)) {
    162         if (isLeftToRightDirection(direction))
    163             m_right = value;
    164         else
    165             m_left = value;
    166     } else {
    167         if (isLeftToRightDirection(direction))
    168             m_bottom = value;
    169         else
    170             m_top = value;
    171     }
    172 }
    173 
    174 LayoutUnit& LayoutBoxExtent::mutableLogicalLeft(WritingMode writingMode)
    175 {
    176     return isHorizontalWritingMode(writingMode) ? m_left : m_top;
    177 }
    178 
    179 LayoutUnit& LayoutBoxExtent::mutableLogicalRight(WritingMode writingMode)
    180 {
    181     return isHorizontalWritingMode(writingMode) ? m_right : m_bottom;
    182 }
    183 
    184 LayoutUnit& LayoutBoxExtent::mutableBefore(WritingMode writingMode)
    185 {
    186     return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(writingMode) ? m_bottom : m_top) :
    187                                                   (isFlippedBlocksWritingMode(writingMode) ? m_right: m_left);
    188 }
    189 
    190 LayoutUnit& LayoutBoxExtent::mutableAfter(WritingMode writingMode)
    191 {
    192     return isHorizontalWritingMode(writingMode) ? (isFlippedBlocksWritingMode(writingMode) ? m_top : m_bottom) :
    193                                                   (isFlippedBlocksWritingMode(writingMode) ? m_left: m_right);
    194 }
    195 
    196 } // namespace WebCore
    197