OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "RenderBoxModelObject.h" | 22 #include "RenderBoxModelObject.h" |
23 | 23 |
| 24 #include "RenderBlock.h" |
| 25 #include "RenderLayer.h" |
| 26 #include "RenderView.h" |
| 27 |
24 namespace WebCore { | 28 namespace WebCore { |
25 | 29 |
| 30 bool RenderBoxModelObject::s_wasFloating = false; |
| 31 |
26 RenderBoxModelObject::RenderBoxModelObject(Node* node) | 32 RenderBoxModelObject::RenderBoxModelObject(Node* node) |
27 : RenderObject(node) | 33 : RenderObject(node) |
| 34 , m_layer(0) |
28 { | 35 { |
29 } | 36 } |
30 | 37 |
31 RenderBoxModelObject::~RenderBoxModelObject() | 38 RenderBoxModelObject::~RenderBoxModelObject() |
32 { | 39 { |
33 } | 40 } |
34 | 41 |
| 42 void RenderBoxModelObject::destroy() |
| 43 { |
| 44 // This must be done before we destroy the RenderObject. |
| 45 if (m_layer) |
| 46 m_layer->clearClipRects(); |
| 47 RenderObject::destroy(); |
| 48 } |
| 49 |
| 50 void RenderBoxModelObject::styleWillChange(StyleDifference diff, const RenderSty
le* newStyle) |
| 51 { |
| 52 s_wasFloating = isFloating(); |
| 53 RenderObject::styleWillChange(diff, newStyle); |
| 54 } |
| 55 |
| 56 void RenderBoxModelObject::styleDidChange(StyleDifference diff, const RenderStyl
e* oldStyle) |
| 57 { |
| 58 RenderObject::styleDidChange(diff, oldStyle); |
| 59 updateBoxModelInfoFromStyle(); |
| 60 |
| 61 if (requiresLayer()) { |
| 62 if (!layer()) { |
| 63 if (s_wasFloating && isFloating()) |
| 64 setChildNeedsLayout(true); |
| 65 m_layer = new (renderArena()) RenderLayer(this); |
| 66 setHasLayer(true); |
| 67 m_layer->insertOnlyThisLayer(); |
| 68 if (parent() && !needsLayout() && containingBlock()) |
| 69 m_layer->updateLayerPositions(); |
| 70 } |
| 71 } else if (layer() && layer()->parent()) { |
| 72 |
| 73 RenderLayer* layer = m_layer; |
| 74 m_layer = 0; |
| 75 setHasLayer(false); |
| 76 setHasTransform(false); // Either a transform wasn't specified or the ob
ject doesn't support transforms, so just null out the bit. |
| 77 setHasReflection(false); |
| 78 layer->removeOnlyThisLayer(); |
| 79 if (s_wasFloating && isFloating()) |
| 80 setChildNeedsLayout(true); |
| 81 } |
| 82 |
| 83 if (m_layer) |
| 84 m_layer->styleChanged(diff, oldStyle); |
| 85 } |
| 86 |
| 87 void RenderBoxModelObject::updateBoxModelInfoFromStyle() |
| 88 { |
| 89 // Set the appropriate bits for a box model object. Since all bits are clea
red in styleWillChange, |
| 90 // we only check for bits that could possibly be set to true. |
| 91 setHasBoxDecorations(style()->hasBorder() || style()->hasBackground() || sty
le()->hasAppearance() || style()->boxShadow()); |
| 92 setInline(style()->isDisplayInlineType()); |
| 93 setRelPositioned(style()->position() == RelativePosition); |
| 94 } |
| 95 |
| 96 int RenderBoxModelObject::relativePositionOffsetX() const |
| 97 { |
| 98 if (!style()->left().isAuto()) { |
| 99 if (!style()->right().isAuto() && containingBlock()->style()->direction(
) == RTL) |
| 100 return -style()->right().calcValue(containingBlockWidth()); |
| 101 return style()->left().calcValue(containingBlockWidth()); |
| 102 } |
| 103 if (!style()->right().isAuto()) |
| 104 return -style()->right().calcValue(containingBlockWidth()); |
| 105 return 0; |
| 106 } |
| 107 |
| 108 int RenderBoxModelObject::relativePositionOffsetY() const |
| 109 { |
| 110 if (!style()->top().isAuto()) { |
| 111 if (!style()->top().isPercent() || containingBlock()->style()->height().
isFixed()) |
| 112 return style()->top().calcValue(containingBlockHeight()); |
| 113 } else if (!style()->bottom().isAuto()) { |
| 114 if (!style()->bottom().isPercent() || containingBlock()->style()->height
().isFixed()) |
| 115 return -style()->bottom().calcValue(containingBlockHeight()); |
| 116 } |
| 117 return 0; |
| 118 } |
| 119 |
35 } // namespace WebCore | 120 } // namespace WebCore |
OLD | NEW |