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