|
1 /* |
|
2 * Copyright (C) 2007 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. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #include "config.h" |
|
27 #include "LayoutState.h" |
|
28 |
|
29 #include "RenderArena.h" |
|
30 #include "RenderInline.h" |
|
31 #include "RenderLayer.h" |
|
32 #include "RenderView.h" |
|
33 |
|
34 namespace WebCore { |
|
35 |
|
36 LayoutState::LayoutState(LayoutState* prev, RenderBox* renderer, const IntSize& offset) |
|
37 : m_next(prev) |
|
38 #ifndef NDEBUG |
|
39 , m_renderer(renderer) |
|
40 #endif |
|
41 { |
|
42 ASSERT(m_next); |
|
43 |
|
44 bool fixed = renderer->isPositioned() && renderer->style()->position() == FixedPosition; |
|
45 if (fixed) { |
|
46 // FIXME: This doesn't work correctly with transforms. |
|
47 FloatPoint fixedOffset = renderer->view()->localToAbsolute(FloatPoint(), true); |
|
48 m_offset = IntSize(fixedOffset.x(), fixedOffset.y()) + offset; |
|
49 } else |
|
50 m_offset = prev->m_offset + offset; |
|
51 |
|
52 if (renderer->isRelPositioned()) { |
|
53 if (renderer->hasLayer()) |
|
54 m_offset += renderer->layer()->relativePositionOffset(); |
|
55 } else if (renderer->isPositioned() && !fixed) { |
|
56 if (RenderObject* container = renderer->container()) { |
|
57 if (container->isRelPositioned() && container->isRenderInline()) |
|
58 m_offset += toRenderInline(container)->relativePositionedInlineOffset(renderer); |
|
59 } |
|
60 } |
|
61 |
|
62 m_clipped = !fixed && prev->m_clipped; |
|
63 if (m_clipped) |
|
64 m_clipRect = prev->m_clipRect; |
|
65 |
|
66 if (renderer->hasOverflowClip()) { |
|
67 RenderLayer* layer = renderer->layer(); |
|
68 IntRect clipRect(toPoint(m_offset) + renderer->view()->layoutDelta(), layer->size()); |
|
69 if (m_clipped) |
|
70 m_clipRect.intersect(clipRect); |
|
71 else { |
|
72 m_clipRect = clipRect; |
|
73 m_clipped = true; |
|
74 } |
|
75 m_offset -= layer->scrolledContentOffset(); |
|
76 } |
|
77 |
|
78 m_layoutDelta = m_next->m_layoutDelta; |
|
79 |
|
80 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. |
|
81 } |
|
82 |
|
83 LayoutState::LayoutState(RenderObject* root) |
|
84 : m_clipped(false) |
|
85 , m_next(0) |
|
86 #ifndef NDEBUG |
|
87 , m_renderer(root) |
|
88 #endif |
|
89 { |
|
90 RenderObject* container = root->container(); |
|
91 FloatPoint absContentPoint = container->localToAbsolute(FloatPoint(), false, true); |
|
92 m_offset = IntSize(absContentPoint.x(), absContentPoint.y()); |
|
93 |
|
94 if (container->hasOverflowClip()) { |
|
95 RenderLayer* layer = toRenderBoxModelObject(container)->layer(); |
|
96 m_clipped = true; |
|
97 m_clipRect = IntRect(toPoint(m_offset), layer->size()); |
|
98 m_offset -= layer->scrolledContentOffset(); |
|
99 } |
|
100 } |
|
101 |
|
102 #ifndef NDEBUG |
|
103 static bool inLayoutStateDestroy; |
|
104 #endif |
|
105 |
|
106 void LayoutState::destroy(RenderArena* renderArena) |
|
107 { |
|
108 #ifndef NDEBUG |
|
109 inLayoutStateDestroy = true; |
|
110 #endif |
|
111 delete this; |
|
112 #ifndef NDEBUG |
|
113 inLayoutStateDestroy = false; |
|
114 #endif |
|
115 renderArena->free(*(size_t*)this, this); |
|
116 } |
|
117 |
|
118 void* LayoutState::operator new(size_t sz, RenderArena* renderArena) throw() |
|
119 { |
|
120 return renderArena->allocate(sz); |
|
121 } |
|
122 |
|
123 void LayoutState::operator delete(void* ptr, size_t sz) |
|
124 { |
|
125 ASSERT(inLayoutStateDestroy); |
|
126 *(size_t*)ptr = sz; |
|
127 } |
|
128 |
|
129 } // namespace WebCore |