| 1 | /* |
| 2 | * Copyright (C) 2018 Apple 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 |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "DisplayBox.h" |
| 28 | |
| 29 | #if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 30 | |
| 31 | #include "RenderStyle.h" |
| 32 | #include <wtf/IsoMallocInlines.h> |
| 33 | |
| 34 | namespace WebCore { |
| 35 | namespace Display { |
| 36 | |
| 37 | WTF_MAKE_ISO_ALLOCATED_IMPL(Box); |
| 38 | |
| 39 | Box::Rect::Rect(LayoutUnit top, LayoutUnit left, LayoutUnit width, LayoutUnit height) |
| 40 | : m_rect(left, top, width, height) |
| 41 | { |
| 42 | #if !ASSERT_DISABLED |
| 43 | m_hasValidTop = true; |
| 44 | m_hasValidLeft = true; |
| 45 | m_hasValidWidth = true; |
| 46 | m_hasValidHeight = true; |
| 47 | #endif |
| 48 | } |
| 49 | |
| 50 | Box::Box(const RenderStyle& style) |
| 51 | : m_style(style) |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | Box::Box(const Box& other) |
| 56 | : m_style(other.m_style) |
| 57 | , m_topLeft(other.m_topLeft) |
| 58 | , m_contentWidth(other.m_contentWidth) |
| 59 | , m_contentHeight(other.m_contentHeight) |
| 60 | , m_horizontalMargin(other.m_horizontalMargin) |
| 61 | , m_verticalMargin(other.m_verticalMargin) |
| 62 | , m_horizontalComputedMargin(other.m_horizontalComputedMargin) |
| 63 | , m_hasClearance(other.m_hasClearance) |
| 64 | , m_border(other.m_border) |
| 65 | , m_padding(other.m_padding) |
| 66 | #if !ASSERT_DISABLED |
| 67 | , m_hasValidTop(other.m_hasValidTop) |
| 68 | , m_hasValidLeft(other.m_hasValidLeft) |
| 69 | , m_hasValidHorizontalMargin(other.m_hasValidHorizontalMargin) |
| 70 | , m_hasValidVerticalMargin(other.m_hasValidVerticalMargin) |
| 71 | , m_hasValidVerticalNonCollapsedMargin(other.m_hasValidVerticalNonCollapsedMargin) |
| 72 | , m_hasValidHorizontalComputedMargin(other.m_hasValidHorizontalComputedMargin) |
| 73 | , m_hasValidBorder(other.m_hasValidBorder) |
| 74 | , m_hasValidPadding(other.m_hasValidPadding) |
| 75 | , m_hasValidContentHeight(other.m_hasValidContentHeight) |
| 76 | , m_hasValidContentWidth(other.m_hasValidContentWidth) |
| 77 | , m_hasEstimatedMarginBefore(other.m_hasEstimatedMarginBefore) |
| 78 | #endif |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | Box::~Box() |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | Box::Style::Style(const RenderStyle& style) |
| 87 | : boxSizing(style.boxSizing()) |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | Box::Rect Box::marginBox() const |
| 92 | { |
| 93 | auto borderBox = this->borderBox(); |
| 94 | |
| 95 | Rect marginBox; |
| 96 | marginBox.setTop(borderBox.top() - marginBefore()); |
| 97 | marginBox.setLeft(borderBox.left() - marginStart()); |
| 98 | marginBox.setHeight(borderBox.height() + marginBefore() + marginAfter()); |
| 99 | marginBox.setWidth(borderBox.width() + marginStart() + marginEnd()); |
| 100 | return marginBox; |
| 101 | } |
| 102 | |
| 103 | Box::Rect Box::nonCollapsedMarginBox() const |
| 104 | { |
| 105 | auto borderBox = this->borderBox(); |
| 106 | |
| 107 | Rect marginBox; |
| 108 | marginBox.setTop(borderBox.top() - nonCollapsedMarginBefore()); |
| 109 | marginBox.setLeft(borderBox.left() - marginStart()); |
| 110 | marginBox.setHeight(borderBox.height() + nonCollapsedMarginBefore() + nonCollapsedMarginAfter()); |
| 111 | marginBox.setWidth(borderBox.width() + marginStart() + marginEnd()); |
| 112 | return marginBox; |
| 113 | } |
| 114 | |
| 115 | Box::Rect Box::borderBox() const |
| 116 | { |
| 117 | Rect borderBox; |
| 118 | borderBox.setTopLeft({ }); |
| 119 | borderBox.setSize({ width(), height() }); |
| 120 | return borderBox; |
| 121 | } |
| 122 | |
| 123 | Box::Rect Box::paddingBox() const |
| 124 | { |
| 125 | auto borderBox = this->borderBox(); |
| 126 | |
| 127 | Rect paddingBox; |
| 128 | paddingBox.setTop(borderBox.top() + borderTop()); |
| 129 | paddingBox.setLeft(borderBox.left() + borderLeft()); |
| 130 | paddingBox.setHeight(borderBox.bottom() - borderTop() - borderBottom()); |
| 131 | paddingBox.setWidth(borderBox.width() - borderLeft() - borderRight()); |
| 132 | return paddingBox; |
| 133 | } |
| 134 | |
| 135 | Box::Rect Box::contentBox() const |
| 136 | { |
| 137 | Rect contentBox; |
| 138 | contentBox.setTop(contentBoxTop()); |
| 139 | contentBox.setLeft(contentBoxLeft()); |
| 140 | contentBox.setWidth(contentBoxWidth()); |
| 141 | contentBox.setHeight(contentBoxHeight()); |
| 142 | return contentBox; |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | #endif |
| 149 | |