|
1 /* |
|
2 * Copyright (C) 2003 Apple Computer, Inc. |
|
3 * |
|
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. |
|
5 * |
|
6 * Other contributors: |
|
7 * Robert O'Callahan <roc+@cs.cmu.edu> |
|
8 * David Baron <dbaron@fas.harvard.edu> |
|
9 * Christian Biesinger <cbiesinger@web.de> |
|
10 * Randall Jesup <rjesup@wgate.com> |
|
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de> |
|
12 * Josh Soref <timeless@mac.com> |
|
13 * Boris Zbarsky <bzbarsky@mit.edu> |
|
14 * |
|
15 * This library is free software; you can redistribute it and/or |
|
16 * modify it under the terms of the GNU Lesser General Public |
|
17 * License as published by the Free Software Foundation; either |
|
18 * version 2.1 of the License, or (at your option) any later version. |
|
19 * |
|
20 * This library is distributed in the hope that it will be useful, |
|
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
23 * Lesser General Public License for more details. |
|
24 * |
|
25 * You should have received a copy of the GNU Lesser General Public |
|
26 * License along with this library; if not, write to the Free Software |
|
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
28 * |
|
29 * Alternatively, the contents of this file may be used under the terms |
|
30 * of either the Mozilla Public License Version 1.1, found at |
|
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public |
|
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html |
|
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are |
|
34 * applicable instead of those above. If you wish to allow use of your |
|
35 * version of this file only under the terms of one of those two |
|
36 * licenses (the MPL or the GPL) and not to allow others to use your |
|
37 * version of this file under the LGPL, indicate your decision by |
|
38 * deletingthe provisions above and replace them with the notice and |
|
39 * other provisions required by the MPL or the GPL, as the case may be. |
|
40 * If you do not delete the provisions above, a recipient may use your |
|
41 * version of this file under any of the LGPL, the MPL or the GPL. |
|
42 */ |
|
43 |
|
44 #ifndef RenderLayer_h |
|
45 #define RenderLayer_h |
|
46 |
|
47 #include "RenderObject.h" |
|
48 #include "ScrollBar.h" |
|
49 #include "Timer.h" |
|
50 |
|
51 namespace WebCore { |
|
52 |
|
53 class CachedResource; |
|
54 class HitTestResult; |
|
55 class PlatformScrollbar; |
|
56 class RenderFrameSet; |
|
57 class RenderObject; |
|
58 class RenderStyle; |
|
59 class RenderTable; |
|
60 class RenderText; |
|
61 class RenderView; |
|
62 class Scrollbar; |
|
63 |
|
64 struct HitTestRequest; |
|
65 |
|
66 class ClipRects { |
|
67 public: |
|
68 ClipRects(const IntRect& r) |
|
69 : m_overflowClipRect(r) |
|
70 , m_fixedClipRect(r) |
|
71 , m_posClipRect(r) |
|
72 , m_refCnt(0) |
|
73 , m_fixed(false) |
|
74 { |
|
75 } |
|
76 |
|
77 ClipRects(const IntRect& overflowRect, const IntRect& fixedRect, const IntRect& posRect, bool fixed) |
|
78 : m_overflowClipRect(overflowRect) |
|
79 , m_fixedClipRect(fixedRect) |
|
80 , m_posClipRect(posRect) |
|
81 , m_refCnt(0) |
|
82 , m_fixed(fixed) |
|
83 { |
|
84 } |
|
85 |
|
86 const IntRect& overflowClipRect() { return m_overflowClipRect; } |
|
87 const IntRect& fixedClipRect() { return m_fixedClipRect; } |
|
88 const IntRect& posClipRect() { return m_posClipRect; } |
|
89 bool fixed() const { return m_fixed; } |
|
90 |
|
91 void ref() { m_refCnt++; } |
|
92 void deref(RenderArena* renderArena) { if (--m_refCnt == 0) destroy(renderArena); } |
|
93 |
|
94 void destroy(RenderArena*); |
|
95 |
|
96 // Overloaded new operator. |
|
97 void* operator new(size_t, RenderArena*) throw(); |
|
98 |
|
99 // Overridden to prevent the normal delete from being called. |
|
100 void operator delete(void*, size_t); |
|
101 |
|
102 private: |
|
103 // The normal operator new is disallowed on all render objects. |
|
104 void* operator new(size_t) throw(); |
|
105 |
|
106 private: |
|
107 IntRect m_overflowClipRect; |
|
108 IntRect m_fixedClipRect; |
|
109 IntRect m_posClipRect; |
|
110 unsigned m_refCnt : 31; |
|
111 bool m_fixed : 1; |
|
112 }; |
|
113 |
|
114 |
|
115 // FIXME: move this to its own file |
|
116 // This class handles the auto-scrolling of layers with overflow: marquee. |
|
117 class Marquee { |
|
118 public: |
|
119 Marquee(RenderLayer*); |
|
120 |
|
121 int speed() const { return m_speed; } |
|
122 int marqueeSpeed() const; |
|
123 |
|
124 EMarqueeDirection reverseDirection() const { return static_cast<EMarqueeDirection>(-direction()); } |
|
125 EMarqueeDirection direction() const; |
|
126 |
|
127 bool isHorizontal() const; |
|
128 |
|
129 int computePosition(EMarqueeDirection, bool stopAtClientEdge); |
|
130 |
|
131 void setEnd(int end) { m_end = end; } |
|
132 |
|
133 void start(); |
|
134 void suspend(); |
|
135 void stop(); |
|
136 |
|
137 void updateMarqueeStyle(); |
|
138 void updateMarqueePosition(); |
|
139 |
|
140 private: |
|
141 void timerFired(Timer<Marquee>*); |
|
142 |
|
143 RenderLayer* m_layer; |
|
144 int m_currentLoop; |
|
145 int m_totalLoops; |
|
146 Timer<Marquee> m_timer; |
|
147 int m_start; |
|
148 int m_end; |
|
149 int m_speed; |
|
150 Length m_height; |
|
151 bool m_reset: 1; |
|
152 bool m_suspended : 1; |
|
153 bool m_stopped : 1; |
|
154 EMarqueeDirection m_direction : 4; |
|
155 }; |
|
156 |
|
157 class RenderLayer : public ScrollbarClient { |
|
158 public: |
|
159 enum ScrollBehavior { |
|
160 noScroll, |
|
161 alignCenter, |
|
162 alignTop, |
|
163 alignBottom, |
|
164 alignLeft, |
|
165 alignRight, |
|
166 alignToClosestEdge |
|
167 }; |
|
168 |
|
169 struct ScrollAlignment { |
|
170 ScrollBehavior m_rectVisible; |
|
171 ScrollBehavior m_rectHidden; |
|
172 ScrollBehavior m_rectPartial; |
|
173 }; |
|
174 |
|
175 static const ScrollAlignment gAlignCenterIfNeeded; |
|
176 static const ScrollAlignment gAlignToEdgeIfNeeded; |
|
177 static const ScrollAlignment gAlignCenterAlways; |
|
178 static const ScrollAlignment gAlignTopAlways; |
|
179 static const ScrollAlignment gAlignBottomAlways; |
|
180 |
|
181 static ScrollBehavior getVisibleBehavior(const ScrollAlignment& s) { return s.m_rectVisible; } |
|
182 static ScrollBehavior getPartialBehavior(const ScrollAlignment& s) { return s.m_rectPartial; } |
|
183 static ScrollBehavior getHiddenBehavior(const ScrollAlignment& s) { return s.m_rectHidden; } |
|
184 |
|
185 RenderLayer(RenderObject*); |
|
186 ~RenderLayer(); |
|
187 |
|
188 RenderObject* renderer() const { return m_object; } |
|
189 RenderLayer* parent() const { return m_parent; } |
|
190 RenderLayer* previousSibling() const { return m_previous; } |
|
191 RenderLayer* nextSibling() const { return m_next; } |
|
192 RenderLayer* firstChild() const { return m_first; } |
|
193 RenderLayer* lastChild() const { return m_last; } |
|
194 |
|
195 void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0); |
|
196 RenderLayer* removeChild(RenderLayer*); |
|
197 |
|
198 void removeOnlyThisLayer(); |
|
199 void insertOnlyThisLayer(); |
|
200 |
|
201 void repaintIncludingDescendants(); |
|
202 |
|
203 void styleChanged(); |
|
204 |
|
205 Marquee* marquee() const { return m_marquee; } |
|
206 void suspendMarquees(); |
|
207 |
|
208 bool isOverflowOnly() const { return m_isOverflowOnly; } |
|
209 |
|
210 bool isTransparent() const; |
|
211 RenderLayer* transparentAncestor(); |
|
212 void beginTransparencyLayers(GraphicsContext*, const IntRect&); |
|
213 |
|
214 const RenderLayer* root() const |
|
215 { |
|
216 const RenderLayer* curr = this; |
|
217 while (curr->parent()) |
|
218 curr = curr->parent(); |
|
219 return curr; |
|
220 } |
|
221 |
|
222 int xPos() const { return m_x; } |
|
223 int yPos() const { return m_y; } |
|
224 void setPos(int xPos, int yPos) |
|
225 { |
|
226 m_x = xPos; |
|
227 m_y = yPos; |
|
228 } |
|
229 |
|
230 int width() const { return m_width; } |
|
231 int height() const { return m_height; } |
|
232 void setWidth(int w) { m_width = w; } |
|
233 void setHeight(int h) { m_height = h; } |
|
234 |
|
235 int scrollWidth(); |
|
236 int scrollHeight(); |
|
237 |
|
238 // Scrolling methods for layers that can scroll their overflow. |
|
239 void scrollOffset(int& x, int& y); |
|
240 void subtractScrollOffset(int& x, int& y); |
|
241 int scrollXOffset() const { return m_scrollX + m_scrollOriginX; } |
|
242 int scrollYOffset() const { return m_scrollY; } |
|
243 void scrollToOffset(int x, int y, bool updateScrollbars = true, bool repaint = true); |
|
244 void scrollToXOffset(int x) { scrollToOffset(x, m_scrollY); } |
|
245 void scrollToYOffset(int y) { scrollToOffset(m_scrollX + m_scrollOriginX, y); } |
|
246 void scrollRectToVisible(const IntRect&, const ScrollAlignment& alignX = gAlignCenterIfNeeded, const ScrollAlignment& alignY = gAlignCenterIfNeeded); |
|
247 |
|
248 IntRect getRectToExpose(const IntRect& visibleRect, const IntRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY); |
|
249 |
|
250 void setHasHorizontalScrollbar(bool); |
|
251 void setHasVerticalScrollbar(bool); |
|
252 |
|
253 PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation); |
|
254 void destroyScrollbar(ScrollbarOrientation); |
|
255 |
|
256 Scrollbar* horizontalScrollbar() { return m_hBar.get(); } |
|
257 Scrollbar* verticalScrollbar() { return m_vBar.get(); } |
|
258 |
|
259 PlatformScrollbar* horizontalScrollbarWidget() const; |
|
260 PlatformScrollbar* verticalScrollbarWidget() const; |
|
261 |
|
262 int verticalScrollbarWidth() const; |
|
263 int horizontalScrollbarHeight() const; |
|
264 |
|
265 void positionOverflowControls(); |
|
266 bool isPointInResizeControl(const IntPoint&); |
|
267 bool hitTestOverflowControls(HitTestResult&); |
|
268 IntSize offsetFromResizeCorner(const IntPoint&) const; |
|
269 |
|
270 void paintOverflowControls(GraphicsContext*, int tx, int ty, const IntRect& damageRect); |
|
271 |
|
272 void updateScrollInfoAfterLayout(); |
|
273 |
|
274 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f); |
|
275 void autoscroll(); |
|
276 |
|
277 void resize(const PlatformMouseEvent&, const IntSize&); |
|
278 bool inResizeMode() const { return m_inResizeMode; } |
|
279 void setInResizeMode(bool b) { m_inResizeMode = b; } |
|
280 |
|
281 void updateLayerPosition(); |
|
282 void updateLayerPositions(bool doFullRepaint = false, bool checkForRepaint = true); |
|
283 |
|
284 void relativePositionOffset(int& relX, int& relY) { relX += m_relX; relY += m_relY; } |
|
285 |
|
286 void clearClipRects(); |
|
287 void clearClipRect(); |
|
288 |
|
289 // Get the enclosing stacking context for this layer. A stacking context is a layer |
|
290 // that has a non-auto z-index. |
|
291 RenderLayer* stackingContext() const; |
|
292 bool isStackingContext() const { return !hasAutoZIndex() || renderer()->isRenderView(); } |
|
293 |
|
294 void dirtyZOrderLists(); |
|
295 void updateZOrderLists(); |
|
296 Vector<RenderLayer*>* posZOrderList() const { return m_posZOrderList; } |
|
297 Vector<RenderLayer*>* negZOrderList() const { return m_negZOrderList; } |
|
298 |
|
299 void dirtyOverflowList(); |
|
300 void updateOverflowList(); |
|
301 Vector<RenderLayer*>* overflowList() const { return m_overflowList; } |
|
302 |
|
303 bool hasVisibleContent() const { return m_hasVisibleContent; } |
|
304 void setHasVisibleContent(bool); |
|
305 void dirtyVisibleContentStatus(); |
|
306 |
|
307 // Gets the nearest enclosing positioned ancestor layer (also includes |
|
308 // the <html> layer and the root layer). |
|
309 RenderLayer* enclosingPositionedAncestor() const; |
|
310 |
|
311 void convertToLayerCoords(const RenderLayer* ancestorLayer, int& x, int& y) const; |
|
312 |
|
313 bool hasAutoZIndex() const { return renderer()->style()->hasAutoZIndex(); } |
|
314 int zIndex() const { return renderer()->style()->zIndex(); } |
|
315 |
|
316 // The two main functions that use the layer system. The paint method |
|
317 // paints the layers that intersect the damage rect from back to |
|
318 // front. The hitTest method looks for mouse events by walking |
|
319 // layers that intersect the point from front to back. |
|
320 void paint(GraphicsContext*, const IntRect& damageRect, PaintRestriction = PaintRestrictionNone, RenderObject* paintingRoot = 0); |
|
321 bool hitTest(const HitTestRequest&, HitTestResult&); |
|
322 |
|
323 // This method figures out our layerBounds in coordinates relative to |
|
324 // |rootLayer}. It also computes our background and foreground clip rects |
|
325 // for painting/event handling. |
|
326 void calculateRects(const RenderLayer* rootLayer, const IntRect& paintDirtyRect, IntRect& layerBounds, |
|
327 IntRect& backgroundRect, IntRect& foregroundRect, IntRect& outlineRect) const; |
|
328 void calculateClipRects(const RenderLayer* rootLayer); |
|
329 ClipRects* clipRects() const { return m_clipRects; } |
|
330 IntRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space. |
|
331 IntRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space. |
|
332 |
|
333 bool intersectsDamageRect(const IntRect& layerBounds, const IntRect& damageRect) const; |
|
334 |
|
335 // Returns a bounding box for this layer only. |
|
336 IntRect absoluteBoundingBox() const; |
|
337 |
|
338 void updateHoverActiveState(const HitTestRequest&, HitTestResult&); |
|
339 |
|
340 IntRect repaintRect() const { return m_repaintRect; } |
|
341 void setNeedsFullRepaint(bool f = true) { m_needsFullRepaint = f; } |
|
342 |
|
343 int staticX() const { return m_staticX; } |
|
344 int staticY() const { return m_staticY; } |
|
345 void setStaticX(int staticX) { m_staticX = staticX; } |
|
346 void setStaticY(int staticY) { m_staticY = staticY; } |
|
347 |
|
348 void destroy(RenderArena*); |
|
349 |
|
350 // Overloaded new operator. Derived classes must override operator new |
|
351 // in order to allocate out of the RenderArena. |
|
352 void* operator new(size_t, RenderArena*) throw(); |
|
353 |
|
354 // Overridden to prevent the normal delete from being called. |
|
355 void operator delete(void*, size_t); |
|
356 |
|
357 private: |
|
358 // The normal operator new is disallowed on all render objects. |
|
359 void* operator new(size_t) throw(); |
|
360 |
|
361 private: |
|
362 void setNextSibling(RenderLayer* next) { m_next = next; } |
|
363 void setPreviousSibling(RenderLayer* prev) { m_previous = prev; } |
|
364 void setParent(RenderLayer* parent) { m_parent = parent; } |
|
365 void setFirstChild(RenderLayer* first) { m_first = first; } |
|
366 void setLastChild(RenderLayer* last) { m_last = last; } |
|
367 |
|
368 void collectLayers(Vector<RenderLayer*>*&, Vector<RenderLayer*>*&); |
|
369 |
|
370 void paintLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect, |
|
371 bool haveTransparency, PaintRestriction, RenderObject* paintingRoot); |
|
372 RenderLayer* hitTestLayer(RenderLayer* rootLayer, const HitTestRequest&, HitTestResult&, const IntRect& hitTestRect); |
|
373 void computeScrollDimensions(bool* needHBar = 0, bool* needVBar = 0); |
|
374 |
|
375 bool shouldBeOverflowOnly() const; |
|
376 |
|
377 virtual void valueChanged(Scrollbar*); |
|
378 virtual IntRect windowClipRect() const; |
|
379 |
|
380 void updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow); |
|
381 |
|
382 void childVisibilityChanged(bool newVisibility); |
|
383 void dirtyVisibleDescendantStatus(); |
|
384 void updateVisibilityStatus(); |
|
385 |
|
386 Node* enclosingElement() const; |
|
387 |
|
388 protected: |
|
389 RenderObject* m_object; |
|
390 |
|
391 RenderLayer* m_parent; |
|
392 RenderLayer* m_previous; |
|
393 RenderLayer* m_next; |
|
394 RenderLayer* m_first; |
|
395 RenderLayer* m_last; |
|
396 |
|
397 IntRect m_repaintRect; // Cached repaint rects. Used by layout. |
|
398 IntRect m_outlineBox; |
|
399 |
|
400 // Our current relative position offset. |
|
401 int m_relX; |
|
402 int m_relY; |
|
403 |
|
404 // Our (x,y) coordinates are in our parent layer's coordinate space. |
|
405 int m_x; |
|
406 int m_y; |
|
407 |
|
408 // The layer's width/height |
|
409 int m_width; |
|
410 int m_height; |
|
411 |
|
412 // Our scroll offsets if the view is scrolled. |
|
413 int m_scrollX; |
|
414 int m_scrollY; |
|
415 int m_scrollOriginX; |
|
416 int m_scrollLeftOverflow; |
|
417 |
|
418 // The width/height of our scrolled area. |
|
419 int m_scrollWidth; |
|
420 int m_scrollHeight; |
|
421 |
|
422 // For layers with overflow, we have a pair of scrollbars. |
|
423 RefPtr<Scrollbar> m_hBar; |
|
424 RefPtr<Scrollbar> m_vBar; |
|
425 |
|
426 // Keeps track of whether the layer is currently resizing, so events can cause resizing to start and stop. |
|
427 bool m_inResizeMode; |
|
428 |
|
429 // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the |
|
430 // descendant layers within the stacking context that have z-indices of 0 or greater |
|
431 // (auto will count as 0). m_negZOrderList holds descendants within our stacking context with negative |
|
432 // z-indices. |
|
433 Vector<RenderLayer*>* m_posZOrderList; |
|
434 Vector<RenderLayer*>* m_negZOrderList; |
|
435 |
|
436 // This list contains our overflow child layers. |
|
437 Vector<RenderLayer*>* m_overflowList; |
|
438 |
|
439 ClipRects* m_clipRects; // Cached clip rects used when painting and hit testing. |
|
440 |
|
441 bool m_scrollDimensionsDirty : 1; |
|
442 bool m_zOrderListsDirty : 1; |
|
443 bool m_overflowListDirty: 1; |
|
444 bool m_isOverflowOnly: 1; |
|
445 |
|
446 bool m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether |
|
447 // we ended up painting this layer or any descendants (and therefore need to |
|
448 // blend). |
|
449 bool m_inOverflowRelayout : 1; |
|
450 bool m_needsFullRepaint : 1; |
|
451 |
|
452 bool m_overflowStatusDirty : 1; |
|
453 bool m_horizontalOverflow : 1; |
|
454 bool m_verticalOverflow : 1; |
|
455 bool m_visibleContentStatusDirty : 1; |
|
456 bool m_hasVisibleContent : 1; |
|
457 bool m_visibleDescendantStatusDirty : 1; |
|
458 bool m_hasVisibleDescendant : 1; |
|
459 |
|
460 Marquee* m_marquee; // Used by layers with overflow:marquee |
|
461 |
|
462 // Cached normal flow values for absolute positioned elements with static left/top values. |
|
463 int m_staticX; |
|
464 int m_staticY; |
|
465 }; |
|
466 |
|
467 } // namespace WebCore |
|
468 |
|
469 #endif // RenderLayer_h |