OSDN Git Service

0538d99b87d06b3979ab07a7966b270b3203ab3b
[android-x86/external-webkit.git] / WebCore / rendering / RenderView.cpp
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "RenderView.h"
23
24 #include "Document.h"
25 #include "Element.h"
26 #include "FloatQuad.h"
27 #include "Frame.h"
28 #include "FrameView.h"
29 #include "GraphicsContext.h"
30 #include "HTMLFrameOwnerElement.h"
31 #include "HitTestResult.h"
32 #include "RenderLayer.h"
33 #include "RenderSelectionInfo.h"
34 #include "RenderWidget.h"
35 #include "RenderWidgetProtector.h"
36 #include "TransformState.h"
37
38 #if USE(ACCELERATED_COMPOSITING)
39 #include "RenderLayerCompositor.h"
40 #endif
41
42 #if defined(ANDROID_LAYOUT) || defined(ANDROID_FIXED_ELEMENTS)
43 #include "Settings.h"
44 #endif
45
46 namespace WebCore {
47
48 RenderView::RenderView(Node* node, FrameView* view)
49     : RenderBlock(node)
50     , m_frameView(view)
51     , m_selectionStart(0)
52     , m_selectionEnd(0)
53     , m_selectionStartPos(-1)
54     , m_selectionEndPos(-1)
55     , m_maximalOutlineSize(0)
56     , m_pageHeight(0)
57     , m_pageHeightChanged(false)
58     , m_layoutState(0)
59     , m_layoutStateDisableCount(0)
60 {
61     // Clear our anonymous bit, set because RenderObject assumes
62     // any renderer with document as the node is anonymous.
63     setIsAnonymous(false);
64
65     // init RenderObject attributes
66     setInline(false);
67     
68     m_minPreferredLogicalWidth = 0;
69     m_maxPreferredLogicalWidth = 0;
70
71     setPreferredLogicalWidthsDirty(true, false);
72     
73     setPositioned(true); // to 0,0 :)
74 }
75
76 RenderView::~RenderView()
77 {
78 }
79
80 void RenderView::computeLogicalHeight()
81 {
82     if (!printing() && m_frameView)
83         setLogicalHeight(viewLogicalHeight());
84 }
85
86 void RenderView::computeLogicalWidth()
87 {
88     if (!printing() && m_frameView)
89         setLogicalWidth(viewLogicalWidth());
90 #ifdef ANDROID_LAYOUT
91     setVisibleWidth(m_frameView->textWrapWidth());
92     const Settings * settings = document()->settings();
93     ASSERT(settings);
94     if (settings->useWideViewport() && settings->viewportWidth() == -1 && width() < minPreferredLogicalWidth())
95         setWidth(m_minPreferredLogicalWidth);
96 #endif
97 }
98
99 void RenderView::computePreferredLogicalWidths()
100 {
101     ASSERT(preferredLogicalWidthsDirty());
102
103     RenderBlock::computePreferredLogicalWidths();
104
105     m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth;
106 }
107
108 void RenderView::layout()
109 {
110     if (!document()->paginated())
111         setPageHeight(0);
112
113     if (printing())
114         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = width();
115
116     // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
117     bool relayoutChildren = !printing() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
118     if (relayoutChildren) {
119         setChildNeedsLayout(true, false);
120         for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
121             if (child->style()->logicalHeight().isPercent() || child->style()->logicalMinHeight().isPercent() || child->style()->logicalMaxHeight().isPercent())
122                 child->setChildNeedsLayout(true, false);
123         }
124     }
125
126     ASSERT(!m_layoutState);
127     LayoutState state;
128     // FIXME: May be better to push a clip and avoid issuing offscreen repaints.
129     state.m_clipped = false;
130     state.m_pageHeight = m_pageHeight;
131     state.m_pageHeightChanged = m_pageHeightChanged;
132     m_pageHeightChanged = false;
133     m_layoutState = &state;
134
135     if (needsLayout())
136         RenderBlock::layout();
137
138     // Reset overflow and then replace it with docWidth and docHeight.
139     m_overflow.clear();
140     addLayoutOverflow(IntRect(0, 0, docWidth(), docHeight()));
141
142     ASSERT(layoutDelta() == IntSize());
143     ASSERT(m_layoutStateDisableCount == 0);
144     ASSERT(m_layoutState == &state);
145     m_layoutState = 0;
146     setNeedsLayout(false);
147 }
148
149 void RenderView::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool /*useTransforms*/, TransformState& transformState) const
150 {
151     // If a container was specified, and was not 0 or the RenderView,
152     // then we should have found it by now.
153     ASSERT_UNUSED(repaintContainer, !repaintContainer || repaintContainer == this);
154
155 #ifdef ANDROID_FIXED_ELEMENTS
156 #if ENABLE(COMPOSITED_FIXED_ELEMENTS)
157     const Settings * settings = document()->settings();
158     if (settings && (settings->viewportWidth() == -1 || settings->viewportWidth() == 0) &&
159         !settings->viewportUserScalable())
160 #else
161     if (false)
162 #endif
163 #endif
164     if (fixed && m_frameView)
165         transformState.move(m_frameView->scrollOffset());
166 }
167
168 void RenderView::mapAbsoluteToLocalPoint(bool fixed, bool /*useTransforms*/, TransformState& transformState) const
169 {
170 #ifdef ANDROID_FIXED_ELEMENTS
171 #if ENABLE(COMPOSITED_FIXED_ELEMENTS)
172     const Settings * settings = document()->settings();
173     if (settings && (settings->viewportWidth() == -1 || settings->viewportWidth() == 0) &&
174         !settings->viewportUserScalable())
175 #else
176     if (false)
177 #endif
178 #endif
179     if (fixed && m_frameView)
180         transformState.move(-m_frameView->scrollOffset());
181 }
182
183 void RenderView::paint(PaintInfo& paintInfo, int tx, int ty)
184 {
185     // If we ever require layout but receive a paint anyway, something has gone horribly wrong.
186     ASSERT(!needsLayout());
187     paintObject(paintInfo, tx, ty);
188 }
189
190 static inline bool isComposited(RenderObject* object)
191 {
192     return object->hasLayer() && toRenderBoxModelObject(object)->layer()->isComposited();
193 }
194
195 static inline bool rendererObscuresBackground(RenderObject* object)
196 {
197     return object && object->style()->visibility() == VISIBLE
198         && object->style()->opacity() == 1
199         && !object->style()->hasTransform()
200         && !isComposited(object);
201 }
202     
203 void RenderView::paintBoxDecorations(PaintInfo& paintInfo, int, int)
204 {
205     // Check to see if we are enclosed by a layer that requires complex painting rules.  If so, we cannot blit
206     // when scrolling, and we need to use slow repaints.  Examples of layers that require this are transparent layers,
207     // layers with reflections, or transformed layers.
208     // FIXME: This needs to be dynamic.  We should be able to go back to blitting if we ever stop being inside
209     // a transform, transparency layer, etc.
210     Element* elt;
211     for (elt = document()->ownerElement(); view() && elt && elt->renderer(); elt = elt->document()->ownerElement()) {
212         RenderLayer* layer = elt->renderer()->enclosingLayer();
213         if (layer->requiresSlowRepaints()) {
214             frameView()->setUseSlowRepaints();
215             break;
216         }
217
218 #if USE(ACCELERATED_COMPOSITING)
219         if (RenderLayer* compositingLayer = layer->enclosingCompositingLayer()) {
220             if (!compositingLayer->backing()->paintingGoesToWindow()) {
221                 frameView()->setUseSlowRepaints();
222                 break;
223             }
224         }
225 #endif
226     }
227
228     if (document()->ownerElement() || !view())
229         return;
230
231     bool rootFillsViewport = false;
232     Node* documentElement = document()->documentElement();
233     if (RenderObject* rootRenderer = documentElement ? documentElement->renderer() : 0) {
234         // The document element's renderer is currently forced to be a block, but may not always be.
235         RenderBox* rootBox = rootRenderer->isBox() ? toRenderBox(rootRenderer) : 0;
236         rootFillsViewport = rootBox && !rootBox->x() && !rootBox->y() && rootBox->width() >= width() && rootBox->height() >= height();
237     }
238     
239     // If painting will entirely fill the view, no need to fill the background.
240     if (rootFillsViewport && rendererObscuresBackground(firstChild()))
241         return;
242
243     // This code typically only executes if the root element's visibility has been set to hidden,
244     // or there is a transform on the <html>.
245     // Only fill with the base background color (typically white) if we're the root document, 
246     // since iframes/frames with no background in the child document should show the parent's background.
247     if (frameView()->isTransparent()) // FIXME: This needs to be dynamic.  We should be able to go back to blitting if we ever stop being transparent.
248         frameView()->setUseSlowRepaints(); // The parent must show behind the child.
249     else {
250         Color baseColor = frameView()->baseBackgroundColor();
251         if (baseColor.alpha() > 0) {
252             paintInfo.context->save();
253             paintInfo.context->setCompositeOperation(CompositeCopy);
254             paintInfo.context->fillRect(paintInfo.rect, baseColor, style()->colorSpace());
255             paintInfo.context->restore();
256         } else
257             paintInfo.context->clearRect(paintInfo.rect);
258     }
259 }
260
261 bool RenderView::shouldRepaint(const IntRect& r) const
262 {
263     if (printing() || r.width() == 0 || r.height() == 0)
264         return false;
265
266     if (!m_frameView)
267         return false;
268     
269     return true;
270 }
271
272 void RenderView::repaintViewRectangle(const IntRect& ur, bool immediate)
273 {
274     if (!shouldRepaint(ur))
275         return;
276
277     // We always just invalidate the root view, since we could be an iframe that is clipped out
278     // or even invisible.
279     Element* elt = document()->ownerElement();
280     if (!elt)
281         m_frameView->repaintContentRectangle(ur, immediate);
282     else if (RenderBox* obj = elt->renderBox()) {
283         IntRect vr = viewRect();
284         IntRect r = intersection(ur, vr);
285         
286         // Subtract out the contentsX and contentsY offsets to get our coords within the viewing
287         // rectangle.
288         r.move(-vr.x(), -vr.y());
289         
290         // FIXME: Hardcoded offsets here are not good.
291         r.move(obj->borderLeft() + obj->paddingLeft(),
292                obj->borderTop() + obj->paddingTop());
293         obj->repaintRectangle(r, immediate);
294     }
295 }
296
297 void RenderView::repaintRectangleInViewAndCompositedLayers(const IntRect& ur, bool immediate)
298 {
299     if (!shouldRepaint(ur))
300         return;
301
302     repaintViewRectangle(ur, immediate);
303     
304 #if USE(ACCELERATED_COMPOSITING)
305     // If we're a frame, repaintViewRectangle will have repainted via a RenderObject in the
306     // parent document.
307     if (document()->ownerElement())
308         return;
309
310     if (compositor()->inCompositingMode())
311         compositor()->repaintCompositedLayersAbsoluteRect(ur);
312 #endif
313 }
314
315 void RenderView::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed)
316 {
317     // If a container was specified, and was not 0 or the RenderView,
318     // then we should have found it by now.
319     ASSERT_UNUSED(repaintContainer, !repaintContainer || repaintContainer == this);
320
321     if (printing())
322         return;
323
324 #ifdef ANDROID_FIXED_ELEMENTS
325 #if ENABLE(COMPOSITED_FIXED_ELEMENTS)
326     const Settings * settings = document()->settings();
327     if (settings && (settings->viewportWidth() == -1 || settings->viewportWidth() == 0) &&
328         !settings->viewportUserScalable())
329 #else
330     if (false)
331 #endif
332 #endif
333     if (fixed && m_frameView)
334         rect.move(m_frameView->scrollX(), m_frameView->scrollY());
335         
336     // Apply our transform if we have one (because of full page zooming).
337     if (m_layer && m_layer->transform())
338         rect = m_layer->transform()->mapRect(rect);
339 }
340
341 void RenderView::absoluteRects(Vector<IntRect>& rects, int tx, int ty)
342 {
343     rects.append(IntRect(tx, ty, m_layer->width(), m_layer->height()));
344 }
345
346 void RenderView::absoluteQuads(Vector<FloatQuad>& quads)
347 {
348     quads.append(FloatRect(0, 0, m_layer->width(), m_layer->height()));
349 }
350
351 static RenderObject* rendererAfterPosition(RenderObject* object, unsigned offset)
352 {
353     if (!object)
354         return 0;
355
356     RenderObject* child = object->childAt(offset);
357     return child ? child : object->nextInPreOrderAfterChildren();
358 }
359
360 IntRect RenderView::selectionBounds(bool clipToVisibleContent) const
361 {
362     document()->updateStyleIfNeeded();
363
364     typedef HashMap<RenderObject*, RenderSelectionInfo*> SelectionMap;
365     SelectionMap selectedObjects;
366
367     RenderObject* os = m_selectionStart;
368     RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
369     while (os && os != stop) {
370         if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
371             // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
372             selectedObjects.set(os, new RenderSelectionInfo(os, clipToVisibleContent));
373             RenderBlock* cb = os->containingBlock();
374             while (cb && !cb->isRenderView()) {
375                 RenderSelectionInfo* blockInfo = selectedObjects.get(cb);
376                 if (blockInfo)
377                     break;
378                 selectedObjects.set(cb, new RenderSelectionInfo(cb, clipToVisibleContent));
379                 cb = cb->containingBlock();
380             }
381         }
382
383         os = os->nextInPreOrder();
384     }
385
386     // Now create a single bounding box rect that encloses the whole selection.
387     IntRect selRect;
388     SelectionMap::iterator end = selectedObjects.end();
389     for (SelectionMap::iterator i = selectedObjects.begin(); i != end; ++i) {
390         RenderSelectionInfo* info = i->second;
391         // RenderSelectionInfo::rect() is in the coordinates of the repaintContainer, so map to page coordinates.
392         IntRect currRect = info->rect();
393         if (RenderBoxModelObject* repaintContainer = info->repaintContainer()) {
394             FloatQuad absQuad = repaintContainer->localToAbsoluteQuad(FloatRect(currRect));
395             currRect = absQuad.enclosingBoundingBox(); 
396         }
397         selRect.unite(currRect);
398         delete info;
399     }
400     return selRect;
401 }
402
403 #if USE(ACCELERATED_COMPOSITING)
404 // Compositing layer dimensions take outline size into account, so we have to recompute layer
405 // bounds when it changes.
406 // FIXME: This is ugly; it would be nice to have a better way to do this.
407 void RenderView::setMaximalOutlineSize(int o)
408 {
409     if (o != m_maximalOutlineSize) {
410         m_maximalOutlineSize = o;
411
412         // maximalOutlineSize affects compositing layer dimensions.
413         compositor()->setCompositingLayersNeedRebuild();    // FIXME: this really just needs to be a geometry update.
414     }
415 }
416 #endif
417
418 void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
419 {
420     // Make sure both our start and end objects are defined.
421     // Check www.msnbc.com and try clicking around to find the case where this happened.
422     if ((start && !end) || (end && !start))
423         return;
424
425     // Just return if the selection hasn't changed.
426     if (m_selectionStart == start && m_selectionStartPos == startPos &&
427         m_selectionEnd == end && m_selectionEndPos == endPos)
428         return;
429
430     // Record the old selected objects.  These will be used later
431     // when we compare against the new selected objects.
432     int oldStartPos = m_selectionStartPos;
433     int oldEndPos = m_selectionEndPos;
434
435     // Objects each have a single selection rect to examine.
436     typedef HashMap<RenderObject*, RenderSelectionInfo*> SelectedObjectMap;
437     SelectedObjectMap oldSelectedObjects;
438     SelectedObjectMap newSelectedObjects;
439
440     // Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks.
441     // In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise
442     // the union of those rects might remain the same even when changes have occurred.
443     typedef HashMap<RenderBlock*, RenderBlockSelectionInfo*> SelectedBlockMap;
444     SelectedBlockMap oldSelectedBlocks;
445     SelectedBlockMap newSelectedBlocks;
446
447     RenderObject* os = m_selectionStart;
448     RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
449     while (os && os != stop) {
450         if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
451             // Blocks are responsible for painting line gaps and margin gaps.  They must be examined as well.
452             oldSelectedObjects.set(os, new RenderSelectionInfo(os, true));
453             if (blockRepaintMode == RepaintNewXOROld) {
454                 RenderBlock* cb = os->containingBlock();
455                 while (cb && !cb->isRenderView()) {
456                     RenderBlockSelectionInfo* blockInfo = oldSelectedBlocks.get(cb);
457                     if (blockInfo)
458                         break;
459                     oldSelectedBlocks.set(cb, new RenderBlockSelectionInfo(cb));
460                     cb = cb->containingBlock();
461                 }
462             }
463         }
464
465         os = os->nextInPreOrder();
466     }
467
468     // Now clear the selection.
469     SelectedObjectMap::iterator oldObjectsEnd = oldSelectedObjects.end();
470     for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i)
471         i->first->setSelectionState(SelectionNone);
472
473     // set selection start and end
474     m_selectionStart = start;
475     m_selectionStartPos = startPos;
476     m_selectionEnd = end;
477     m_selectionEndPos = endPos;
478
479     // Update the selection status of all objects between m_selectionStart and m_selectionEnd
480     if (start && start == end)
481         start->setSelectionState(SelectionBoth);
482     else {
483         if (start)
484             start->setSelectionState(SelectionStart);
485         if (end)
486             end->setSelectionState(SelectionEnd);
487     }
488
489     RenderObject* o = start;
490     stop = rendererAfterPosition(end, endPos);
491
492     while (o && o != stop) {
493         if (o != start && o != end && o->canBeSelectionLeaf())
494             o->setSelectionState(SelectionInside);
495         o = o->nextInPreOrder();
496     }
497
498     m_layer->clearBlockSelectionGapsBounds();
499
500     // Now that the selection state has been updated for the new objects, walk them again and
501     // put them in the new objects list.
502     o = start;
503     while (o && o != stop) {
504         if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) {
505             newSelectedObjects.set(o, new RenderSelectionInfo(o, true));
506             RenderBlock* cb = o->containingBlock();
507             while (cb && !cb->isRenderView()) {
508                 RenderBlockSelectionInfo* blockInfo = newSelectedBlocks.get(cb);
509                 if (blockInfo)
510                     break;
511                 newSelectedBlocks.set(cb, new RenderBlockSelectionInfo(cb));
512                 cb = cb->containingBlock();
513             }
514         }
515
516         o = o->nextInPreOrder();
517     }
518
519     if (!m_frameView) {
520         // We built the maps, but we aren't going to use them.
521         // We need to delete the values, otherwise they'll all leak!
522         deleteAllValues(oldSelectedObjects);
523         deleteAllValues(newSelectedObjects);
524         deleteAllValues(oldSelectedBlocks);
525         deleteAllValues(newSelectedBlocks);
526         return;
527     }
528
529     m_frameView->beginDeferredRepaints();
530
531     // Have any of the old selected objects changed compared to the new selection?
532     for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i) {
533         RenderObject* obj = i->first;
534         RenderSelectionInfo* newInfo = newSelectedObjects.get(obj);
535         RenderSelectionInfo* oldInfo = i->second;
536         if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state() ||
537             (m_selectionStart == obj && oldStartPos != m_selectionStartPos) ||
538             (m_selectionEnd == obj && oldEndPos != m_selectionEndPos)) {
539             oldInfo->repaint();
540             if (newInfo) {
541                 newInfo->repaint();
542                 newSelectedObjects.remove(obj);
543                 delete newInfo;
544             }
545         }
546         delete oldInfo;
547     }
548
549     // Any new objects that remain were not found in the old objects dict, and so they need to be updated.
550     SelectedObjectMap::iterator newObjectsEnd = newSelectedObjects.end();
551     for (SelectedObjectMap::iterator i = newSelectedObjects.begin(); i != newObjectsEnd; ++i) {
552         RenderSelectionInfo* newInfo = i->second;
553         newInfo->repaint();
554         delete newInfo;
555     }
556
557     // Have any of the old blocks changed?
558     SelectedBlockMap::iterator oldBlocksEnd = oldSelectedBlocks.end();
559     for (SelectedBlockMap::iterator i = oldSelectedBlocks.begin(); i != oldBlocksEnd; ++i) {
560         RenderBlock* block = i->first;
561         RenderBlockSelectionInfo* newInfo = newSelectedBlocks.get(block);
562         RenderBlockSelectionInfo* oldInfo = i->second;
563         if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) {
564             oldInfo->repaint();
565             if (newInfo) {
566                 newInfo->repaint();
567                 newSelectedBlocks.remove(block);
568                 delete newInfo;
569             }
570         }
571         delete oldInfo;
572     }
573
574     // Any new blocks that remain were not found in the old blocks dict, and so they need to be updated.
575     SelectedBlockMap::iterator newBlocksEnd = newSelectedBlocks.end();
576     for (SelectedBlockMap::iterator i = newSelectedBlocks.begin(); i != newBlocksEnd; ++i) {
577         RenderBlockSelectionInfo* newInfo = i->second;
578         newInfo->repaint();
579         delete newInfo;
580     }
581
582     m_frameView->endDeferredRepaints();
583 }
584
585 void RenderView::clearSelection()
586 {
587     m_layer->repaintBlockSelectionGaps();
588     setSelection(0, -1, 0, -1, RepaintNewMinusOld);
589 }
590
591 void RenderView::selectionStartEnd(int& startPos, int& endPos) const
592 {
593     startPos = m_selectionStartPos;
594     endPos = m_selectionEndPos;
595 }
596
597 bool RenderView::printing() const
598 {
599     return document()->printing();
600 }
601
602 void RenderView::updateWidgetPositions()
603 {
604     // updateWidgetPosition() can possibly cause layout to be re-entered (via plug-ins running
605     // scripts in response to NPP_SetWindow, for example), so we need to keep the Widgets
606     // alive during enumeration.    
607
608     size_t size = m_widgets.size();
609
610     Vector<RenderWidget*> renderWidgets;
611     renderWidgets.reserveCapacity(size);
612
613     RenderWidgetSet::const_iterator end = m_widgets.end();
614     for (RenderWidgetSet::const_iterator it = m_widgets.begin(); it != end; ++it) {
615         renderWidgets.uncheckedAppend(*it);
616         (*it)->ref();
617     }
618     
619     for (size_t i = 0; i < size; ++i)
620         renderWidgets[i]->updateWidgetPosition();
621
622     for (size_t i = 0; i < size; ++i)
623         renderWidgets[i]->widgetPositionsUpdated();
624
625     for (size_t i = 0; i < size; ++i)
626         renderWidgets[i]->deref(renderArena());
627 }
628
629 void RenderView::addWidget(RenderWidget* o)
630 {
631     m_widgets.add(o);
632 }
633
634 void RenderView::removeWidget(RenderWidget* o)
635 {
636     m_widgets.remove(o);
637 }
638
639 IntRect RenderView::viewRect() const
640 {
641     if (printing())
642         return IntRect(0, 0, width(), height());
643     if (m_frameView)
644         return m_frameView->visibleContentRect();
645     return IntRect();
646 }
647
648 int RenderView::docHeight() const
649 {
650     int h = lowestPosition();
651
652     // FIXME: This doesn't do any margin collapsing.
653     // Instead of this dh computation we should keep the result
654     // when we call RenderBlock::layout.
655     int dh = 0;
656     for (RenderBox* c = firstChildBox(); c; c = c->nextSiblingBox())
657         dh += c->height() + c->marginTop() + c->marginBottom();
658
659     if (dh > h)
660         h = dh;
661
662     return h;
663 }
664
665 int RenderView::docWidth() const
666 {
667     int w = rightmostPosition();
668
669     for (RenderBox* c = firstChildBox(); c; c = c->nextSiblingBox()) {
670         int dw = c->width() + c->marginLeft() + c->marginRight();
671         if (dw > w)
672             w = dw;
673     }
674
675     return w;
676 }
677
678 int RenderView::viewHeight() const
679 {
680     int height = 0;
681     if (!printing() && m_frameView) {
682         height = m_frameView->layoutHeight();
683         height = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(height)) : height;
684     }
685     return height;
686 }
687
688 int RenderView::viewWidth() const
689 {
690     int width = 0;
691     if (!printing() && m_frameView) {
692         width = m_frameView->layoutWidth();
693         width = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(width)) : width;
694     }
695     return width;
696 }
697
698 float RenderView::zoomFactor() const
699 {
700     Frame* frame = m_frameView->frame();
701     return frame ? frame->pageZoomFactor() : 1;
702 }
703
704 void RenderView::pushLayoutState(RenderObject* root)
705 {
706     ASSERT(m_layoutStateDisableCount == 0);
707     ASSERT(m_layoutState == 0);
708
709     m_layoutState = new (renderArena()) LayoutState(root);
710 }
711
712 bool RenderView::shouldDisableLayoutStateForSubtree(RenderObject* renderer) const
713 {
714     RenderObject* o = renderer;
715     while (o) {
716         if (o->hasColumns() || o->hasTransform() || o->hasReflection())
717             return true;
718         o = o->container();
719     }
720     return false;
721 }
722
723 void RenderView::updateHitTestResult(HitTestResult& result, const IntPoint& point)
724 {
725     if (result.innerNode())
726         return;
727
728     Node* node = document()->documentElement();
729     if (node) {
730         result.setInnerNode(node);
731         if (!result.innerNonSharedNode())
732             result.setInnerNonSharedNode(node);
733         result.setLocalPoint(point);
734     }
735 }
736
737 // FIXME: This function is obsolete and only used by embedded WebViews inside AppKit NSViews.
738 // Do not add callers of this function!
739 // The idea here is to take into account what object is moving the pagination point, and
740 // thus choose the best place to chop it.
741 void RenderView::setBestTruncatedAt(int y, RenderBoxModelObject* forRenderer, bool forcedBreak)
742 {
743     // Nobody else can set a page break once we have a forced break.
744     if (m_legacyPrinting.m_forcedPageBreak)
745         return;
746
747     // Forced breaks always win over unforced breaks.
748     if (forcedBreak) {
749         m_legacyPrinting.m_forcedPageBreak = true;
750         m_legacyPrinting.m_bestTruncatedAt = y;
751         return;
752     }
753
754     // Prefer the widest object that tries to move the pagination point
755     IntRect boundingBox = forRenderer->borderBoundingBox();
756     if (boundingBox.width() > m_legacyPrinting.m_truncatorWidth) {
757         m_legacyPrinting.m_truncatorWidth = boundingBox.width();
758         m_legacyPrinting.m_bestTruncatedAt = y;
759     }
760 }
761
762 #if USE(ACCELERATED_COMPOSITING)
763 bool RenderView::usesCompositing() const
764 {
765     return m_compositor && m_compositor->inCompositingMode();
766 }
767
768 RenderLayerCompositor* RenderView::compositor()
769 {
770     if (!m_compositor)
771         m_compositor.set(new RenderLayerCompositor(this));
772
773     return m_compositor.get();
774 }
775 #endif
776
777 void RenderView::didMoveOnscreen()
778 {
779 #if USE(ACCELERATED_COMPOSITING)
780     if (m_compositor)
781         m_compositor->didMoveOnscreen();
782 #endif
783 }
784
785 void RenderView::willMoveOffscreen()
786 {
787 #if USE(ACCELERATED_COMPOSITING)
788     if (m_compositor)
789         m_compositor->willMoveOffscreen();
790 #endif
791 }
792
793 } // namespace WebCore