|
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 "RenderLayer.h" |
|
31 #include "RenderView.h" |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 LayoutState::LayoutState(LayoutState* prev, RenderBox* renderer, const IntSize& offset) |
|
36 { |
|
37 ASSERT(prev); |
|
38 |
|
39 m_next = prev; |
|
40 |
|
41 bool fixed = renderer->isPositioned() && renderer->style()->position() == FixedPosition; |
|
42 if (fixed) { |
|
43 int fixedX = 0; |
|
44 int fixedY = 0; |
|
45 renderer->view()->absolutePosition(fixedX, fixedY, true); |
|
46 m_offset = IntSize(fixedX, fixedY) + offset; |
|
47 } else |
|
48 m_offset = prev->m_offset + offset; |
|
49 |
|
50 if (renderer->isRelPositioned()) { |
|
51 int relX = 0; |
|
52 int relY = 0; |
|
53 renderer->layer()->relativePositionOffset(relX, relY); |
|
54 m_offset += IntSize(relX, relY); |
|
55 } else if (renderer->isPositioned() && !fixed) { |
|
56 if (RenderObject* container = renderer->container()) |
|
57 m_offset += renderer->offsetForPositionedInContainer(container); |
|
58 } |
|
59 |
|
60 m_clipped = !fixed && prev->m_clipped; |
|
61 if (m_clipped) |
|
62 m_clipRect = prev->m_clipRect; |
|
63 if (renderer->hasOverflowClip()) { |
|
64 int x = m_offset.width(); |
|
65 int y = m_offset.height(); |
|
66 RenderLayer* layer = renderer->layer(); |
|
67 IntRect clipRect(x, y, layer->width(), layer->height()); |
|
68 if (m_clipped) |
|
69 m_clipRect.intersect(clipRect); |
|
70 else { |
|
71 m_clipRect = clipRect; |
|
72 m_clipped = true; |
|
73 } |
|
74 layer->subtractScrollOffset(x, y); |
|
75 m_offset = IntSize(x, y); |
|
76 } |
|
77 // FIXME: <http://bugs.webkit.org/show_bug.cgi?id=13443> Apply control clip if present. |
|
78 } |
|
79 |
|
80 LayoutState::LayoutState(RenderObject* root) |
|
81 { |
|
82 RenderObject* container = root->container(); |
|
83 m_clipped = true; |
|
84 m_clipRect = container->absoluteClippedOverflowRect(); |
|
85 int x = 0; |
|
86 int y = 0; |
|
87 container->absolutePosition(x, y); |
|
88 m_offset = IntSize(x, y); |
|
89 m_next = 0; |
|
90 } |
|
91 |
|
92 #ifndef NDEBUG |
|
93 static bool inLayoutStateDestroy; |
|
94 #endif |
|
95 |
|
96 void LayoutState::destroy(RenderArena* renderArena) |
|
97 { |
|
98 #ifndef NDEBUG |
|
99 inLayoutStateDestroy = true; |
|
100 #endif |
|
101 delete this; |
|
102 #ifndef NDEBUG |
|
103 inLayoutStateDestroy = false; |
|
104 #endif |
|
105 renderArena->free(*(size_t*)this, this); |
|
106 } |
|
107 |
|
108 void* LayoutState::operator new(size_t sz, RenderArena* renderArena) throw() |
|
109 { |
|
110 return renderArena->allocate(sz); |
|
111 } |
|
112 |
|
113 void LayoutState::operator delete(void* ptr, size_t sz) |
|
114 { |
|
115 ASSERT(inLayoutStateDestroy); |
|
116 *(size_t*)ptr = sz; |
|
117 } |
|
118 |
|
119 } // namespace WebCore |