2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
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.
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.
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.
22 #include "core/rendering/RenderView.h"
24 #include "RuntimeEnabledFeatures.h"
25 #include "core/dom/Document.h"
26 #include "core/dom/Element.h"
27 #include "core/frame/LocalFrame.h"
28 #include "core/html/HTMLDialogElement.h"
29 #include "core/html/HTMLFrameOwnerElement.h"
30 #include "core/html/HTMLIFrameElement.h"
31 #include "core/page/Page.h"
32 #include "core/rendering/ColumnInfo.h"
33 #include "core/rendering/FlowThreadController.h"
34 #include "core/rendering/GraphicsContextAnnotator.h"
35 #include "core/rendering/HitTestResult.h"
36 #include "core/rendering/RenderFlowThread.h"
37 #include "core/rendering/RenderGeometryMap.h"
38 #include "core/rendering/RenderLayer.h"
39 #include "core/rendering/RenderSelectionInfo.h"
40 #include "core/rendering/compositing/CompositedLayerMapping.h"
41 #include "core/rendering/compositing/RenderLayerCompositor.h"
42 #include "core/svg/SVGDocumentExtensions.h"
43 #include "platform/geometry/FloatQuad.h"
44 #include "platform/geometry/TransformState.h"
45 #include "platform/graphics/GraphicsContext.h"
49 RenderView::RenderView(Document* document)
50 : RenderBlockFlow(document)
51 , m_frameView(document->view())
54 , m_selectionStartPos(-1)
55 , m_selectionEndPos(-1)
56 , m_pageLogicalHeight(0)
57 , m_pageLogicalHeightChanged(false)
59 , m_layoutStateDisableCount(0)
60 , m_renderQuoteHead(0)
61 , m_renderCounterCount(0)
63 // init RenderObject attributes
66 m_minPreferredLogicalWidth = 0;
67 m_maxPreferredLogicalWidth = 0;
69 setPreferredLogicalWidthsDirty(MarkOnlyThis);
71 setPositionState(AbsolutePosition); // to 0,0 :)
74 RenderView::~RenderView()
78 bool RenderView::hitTest(const HitTestRequest& request, HitTestResult& result)
80 return hitTest(request, result.hitTestLocation(), result);
83 bool RenderView::hitTest(const HitTestRequest& request, const HitTestLocation& location, HitTestResult& result)
85 // We have to recursively update layout/style here because otherwise, when the hit test recurses
86 // into a child document, it could trigger a layout on the parent document, which can destroy RenderLayers
87 // that are higher up in the call stack, leading to crashes.
88 // Note that Document::updateLayout calls its parent's updateLayout.
89 // FIXME: It should be the caller's responsibility to ensure an up-to-date layout.
90 frameView()->updateLayoutAndStyleIfNeededRecursive();
91 return layer()->hitTest(request, location, result);
94 void RenderView::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit, LogicalExtentComputedValues& computedValues) const
96 computedValues.m_extent = (!shouldUsePrintingLayout() && m_frameView) ? LayoutUnit(viewLogicalHeight()) : logicalHeight;
99 void RenderView::updateLogicalWidth()
101 if (!shouldUsePrintingLayout() && m_frameView)
102 setLogicalWidth(viewLogicalWidth());
105 LayoutUnit RenderView::availableLogicalHeight(AvailableLogicalHeightType heightType) const
107 // If we have columns, then the available logical height is reduced to the column height.
109 return columnInfo()->columnHeight();
110 return RenderBlockFlow::availableLogicalHeight(heightType);
113 bool RenderView::isChildAllowed(RenderObject* child, RenderStyle*) const
115 return child->isBox();
118 static bool canCenterDialog(const RenderStyle* style)
120 // FIXME: We must center for FixedPosition as well.
121 return style->position() == AbsolutePosition && style->hasAutoTopAndBottom();
124 void RenderView::positionDialog(RenderBox* box)
126 HTMLDialogElement* dialog = toHTMLDialogElement(box->node());
127 if (dialog->centeringMode() == HTMLDialogElement::NotCentered)
129 if (dialog->centeringMode() == HTMLDialogElement::Centered) {
130 if (canCenterDialog(box->style()))
131 box->setY(dialog->centeredPosition());
135 ASSERT(dialog->centeringMode() == HTMLDialogElement::NeedsCentering);
136 if (!canCenterDialog(box->style())) {
137 dialog->setNotCentered();
140 FrameView* frameView = document().view();
141 int scrollTop = frameView->scrollOffset().height();
142 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height();
143 LayoutUnit top = scrollTop;
144 if (box->height() < visibleHeight)
145 top += (visibleHeight - box->height()) / 2;
147 dialog->setCentered(top);
150 void RenderView::positionDialogs()
152 TrackedRendererListHashSet* positionedDescendants = positionedObjects();
153 if (!positionedDescendants)
155 TrackedRendererListHashSet::iterator end = positionedDescendants->end();
156 for (TrackedRendererListHashSet::iterator it = positionedDescendants->begin(); it != end; ++it) {
157 RenderBox* box = *it;
158 if (isHTMLDialogElement(box->node()))
163 void RenderView::layoutContent()
165 ASSERT(needsLayout());
167 RenderBlockFlow::layout();
169 if (RuntimeEnabledFeatures::dialogElementEnabled())
178 void RenderView::checkLayoutState()
180 if (!RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) {
181 ASSERT(layoutDeltaMatches(LayoutSize()));
183 ASSERT(!m_layoutStateDisableCount);
184 ASSERT(!m_layoutState->next());
188 void RenderView::layout()
190 if (!document().paginated())
191 setPageLogicalHeight(0);
193 if (shouldUsePrintingLayout())
194 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();
196 SubtreeLayoutScope layoutScope(*this);
198 // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
199 bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
200 if (relayoutChildren) {
201 layoutScope.setChildNeedsLayout(this);
202 for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
203 if (child->isSVGRoot())
206 if ((child->isBox() && toRenderBox(child)->hasRelativeLogicalHeight())
207 || child->style()->logicalHeight().isPercent()
208 || child->style()->logicalMinHeight().isPercent()
209 || child->style()->logicalMaxHeight().isPercent())
210 layoutScope.setChildNeedsLayout(child);
213 if (document().svgExtensions())
214 document().accessSVGExtensions().invalidateSVGRootsWithRelativeLengthDescendents(&layoutScope);
217 ASSERT(!m_layoutState);
221 RootLayoutStateScope rootLayoutStateScope(*this);
223 m_pageLogicalHeightChanged = false;
233 void RenderView::mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState& transformState, MapCoordinatesFlags mode, bool* wasFixed) const
235 ASSERT_UNUSED(wasFixed, !wasFixed || *wasFixed == static_cast<bool>(mode & IsFixed));
237 if (!repaintContainer && mode & UseTransforms && shouldUseTransformFromContainer(0)) {
238 TransformationMatrix t;
239 getTransformFromContainer(0, LayoutSize(), t);
240 transformState.applyTransform(t);
243 if (mode & IsFixed && m_frameView)
244 transformState.move(m_frameView->scrollOffsetForFixedPosition());
246 if (repaintContainer == this)
249 if (mode & TraverseDocumentBoundaries) {
250 if (RenderObject* parentDocRenderer = frame()->ownerRenderer()) {
251 transformState.move(-frame()->view()->scrollOffset());
252 if (parentDocRenderer->isBox())
253 transformState.move(toLayoutSize(toRenderBox(parentDocRenderer)->contentBoxRect().location()));
254 parentDocRenderer->mapLocalToContainer(repaintContainer, transformState, mode, wasFixed);
259 // If a container was specified, and was not 0 or the RenderView,
260 // then we should have found it by now.
261 ASSERT_ARG(repaintContainer, !repaintContainer);
264 const RenderObject* RenderView::pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap& geometryMap) const
266 LayoutSize offsetForFixedPosition;
268 RenderObject* container = 0;
271 offsetForFixedPosition = m_frameView->scrollOffsetForFixedPosition();
273 if (geometryMap.mapCoordinatesFlags() & TraverseDocumentBoundaries) {
274 if (RenderPart* parentDocRenderer = frame()->ownerRenderer()) {
275 offset = -m_frameView->scrollOffset();
276 offset += toLayoutSize(parentDocRenderer->contentBoxRect().location());
277 container = parentDocRenderer;
281 // If a container was specified, and was not 0 or the RenderView, then we
282 // should have found it by now unless we're traversing to a parent document.
283 ASSERT_ARG(ancestorToStopAt, !ancestorToStopAt || ancestorToStopAt == this || container);
285 if ((!ancestorToStopAt || container) && shouldUseTransformFromContainer(container)) {
286 TransformationMatrix t;
287 getTransformFromContainer(container, LayoutSize(), t);
288 geometryMap.push(this, t, false, false, false, true, offsetForFixedPosition);
290 geometryMap.push(this, offset, false, false, false, false, offsetForFixedPosition);
296 void RenderView::mapAbsoluteToLocalPoint(MapCoordinatesFlags mode, TransformState& transformState) const
298 if (mode & IsFixed && m_frameView)
299 transformState.move(m_frameView->scrollOffsetForFixedPosition());
301 if (mode & UseTransforms && shouldUseTransformFromContainer(0)) {
302 TransformationMatrix t;
303 getTransformFromContainer(0, LayoutSize(), t);
304 transformState.applyTransform(t);
308 void RenderView::computeSelfHitTestRects(Vector<LayoutRect>& rects, const LayoutPoint&) const
310 // Record the entire size of the contents of the frame. Note that we don't just
311 // use the viewport size (containing block) here because we want to ensure this includes
312 // all children (so we can avoid walking them explicitly).
313 rects.append(LayoutRect(LayoutPoint::zero(), frameView()->contentsSize()));
316 void RenderView::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
318 // If we ever require layout but receive a paint anyway, something has gone horribly wrong.
319 ASSERT(!needsLayout());
320 // RenderViews should never be called to paint with an offset not on device pixels.
321 ASSERT(LayoutPoint(IntPoint(paintOffset.x(), paintOffset.y())) == paintOffset);
323 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this);
325 // This avoids painting garbage between columns if there is a column gap.
326 if (m_frameView && style()->isOverflowPaged())
327 paintInfo.context->fillRect(paintInfo.rect, m_frameView->baseBackgroundColor());
329 paintObject(paintInfo, paintOffset);
332 static inline bool rendererObscuresBackground(RenderBox* rootBox)
335 RenderStyle* style = rootBox->style();
336 if (style->visibility() != VISIBLE
337 || style->opacity() != 1
338 || style->hasFilter()
339 || style->hasTransform())
342 if (rootBox->compositingState() == PaintsIntoOwnBacking)
345 const RenderObject* rootRenderer = rootBox->rendererForRootBackground();
346 if (rootRenderer->style()->backgroundClip() == TextFillBox)
352 bool RenderView::rootFillsViewportBackground(RenderBox* rootBox) const
355 // CSS Boxes always fill the viewport background (see paintRootBoxFillLayers)
356 if (!rootBox->isSVG())
359 return rootBox->frameRect().contains(frameRect());
362 void RenderView::paintBoxDecorations(PaintInfo& paintInfo, const LayoutPoint&)
364 // Check to see if we are enclosed by a layer that requires complex painting rules. If so, we cannot blit
365 // when scrolling, and we need to use slow repaints. Examples of layers that require this are transparent layers,
366 // layers with reflections, or transformed layers.
367 // FIXME: This needs to be dynamic. We should be able to go back to blitting if we ever stop being inside
368 // a transform, transparency layer, etc.
370 for (elt = document().ownerElement(); view() && elt && elt->renderer(); elt = elt->document().ownerElement()) {
371 RenderLayer* layer = elt->renderer()->enclosingLayer();
372 if (layer->cannotBlitToWindow()) {
373 frameView()->setCannotBlitToWindow();
377 if (layer->enclosingCompositingLayerForRepaint()) {
378 frameView()->setCannotBlitToWindow();
383 if (document().ownerElement() || !view())
386 if (paintInfo.skipRootBackground())
389 bool shouldPaintBackground = true;
390 Node* documentElement = document().documentElement();
391 if (RenderBox* rootBox = documentElement ? toRenderBox(documentElement->renderer()) : 0)
392 shouldPaintBackground = !rootFillsViewportBackground(rootBox) || !rendererObscuresBackground(rootBox);
394 // If painting will entirely fill the view, no need to fill the background.
395 if (!shouldPaintBackground)
398 // This code typically only executes if the root element's visibility has been set to hidden,
399 // if there is a transform on the <html>, or if there is a page scale factor less than 1.
400 // Only fill with the base background color (typically white) if we're the root document,
401 // since iframes/frames with no background in the child document should show the parent's background.
402 if (frameView()->isTransparent()) // FIXME: This needs to be dynamic. We should be able to go back to blitting if we ever stop being transparent.
403 frameView()->setCannotBlitToWindow(); // The parent must show behind the child.
405 Color baseColor = frameView()->baseBackgroundColor();
406 if (baseColor.alpha()) {
407 CompositeOperator previousOperator = paintInfo.context->compositeOperation();
408 paintInfo.context->setCompositeOperation(CompositeCopy);
409 paintInfo.context->fillRect(paintInfo.rect, baseColor);
410 paintInfo.context->setCompositeOperation(previousOperator);
412 paintInfo.context->clearRect(paintInfo.rect);
417 void RenderView::repaintViewRectangle(const LayoutRect& ur) const
419 ASSERT(!ur.isEmpty());
421 if (document().printing() || !m_frameView)
424 // We always just invalidate the root view, since we could be an iframe that is clipped out
425 // or even invisible.
426 Element* elt = document().ownerElement();
428 m_frameView->repaintContentRectangle(pixelSnappedIntRect(ur));
429 else if (RenderBox* obj = elt->renderBox()) {
430 LayoutRect vr = viewRect();
431 LayoutRect r = intersection(ur, vr);
433 // Subtract out the contentsX and contentsY offsets to get our coords within the viewing
435 r.moveBy(-vr.location());
437 // FIXME: Hardcoded offsets here are not good.
438 r.moveBy(obj->contentBoxRect().location());
439 obj->repaintRectangle(r);
443 void RenderView::repaintViewAndCompositedLayers()
447 // The only way we know how to hit these ASSERTS below this point is via the Chromium OS login screen.
448 DisableCompositingQueryAsserts disabler;
450 if (compositor()->inCompositingMode())
451 compositor()->repaintCompositedLayers();
454 void RenderView::computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect& rect, bool fixed) const
456 // If a container was specified, and was not 0 or the RenderView,
457 // then we should have found it by now.
458 ASSERT_ARG(repaintContainer, !repaintContainer || repaintContainer == this);
460 if (document().printing())
463 if (style()->isFlippedBlocksWritingMode()) {
464 // We have to flip by hand since the view's logical height has not been determined. We
465 // can use the viewport width and height.
466 if (style()->isHorizontalWritingMode())
467 rect.setY(viewHeight() - rect.maxY());
469 rect.setX(viewWidth() - rect.maxX());
472 if (fixed && m_frameView) {
473 rect.move(m_frameView->scrollOffsetForFixedPosition());
474 // If we have a pending scroll, invalidate the previous scroll position.
475 if (!m_frameView->pendingScrollDelta().isZero()) {
476 rect.move(-m_frameView->pendingScrollDelta());
480 // Apply our transform if we have one (because of full page zooming).
481 if (!repaintContainer && layer() && layer()->transform())
482 rect = layer()->transform()->mapRect(rect);
485 void RenderView::absoluteRects(Vector<IntRect>& rects, const LayoutPoint& accumulatedOffset) const
487 rects.append(pixelSnappedIntRect(accumulatedOffset, layer()->size()));
490 void RenderView::absoluteQuads(Vector<FloatQuad>& quads, bool* wasFixed) const
494 quads.append(FloatRect(FloatPoint(), layer()->size()));
497 static RenderObject* rendererAfterPosition(RenderObject* object, unsigned offset)
502 RenderObject* child = object->childAt(offset);
503 return child ? child : object->nextInPreOrderAfterChildren();
506 IntRect RenderView::selectionBounds(bool clipToVisibleContent) const
508 typedef HashMap<RenderObject*, OwnPtr<RenderSelectionInfo> > SelectionMap;
509 SelectionMap selectedObjects;
511 RenderObject* os = m_selectionStart;
512 RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
513 while (os && os != stop) {
514 if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
515 // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
516 selectedObjects.set(os, adoptPtr(new RenderSelectionInfo(os, clipToVisibleContent)));
517 RenderBlock* cb = os->containingBlock();
518 while (cb && !cb->isRenderView()) {
519 OwnPtr<RenderSelectionInfo>& blockInfo = selectedObjects.add(cb, nullptr).storedValue->value;
522 blockInfo = adoptPtr(new RenderSelectionInfo(cb, clipToVisibleContent));
523 cb = cb->containingBlock();
527 os = os->nextInPreOrder();
530 // Now create a single bounding box rect that encloses the whole selection.
532 SelectionMap::iterator end = selectedObjects.end();
533 for (SelectionMap::iterator i = selectedObjects.begin(); i != end; ++i) {
534 RenderSelectionInfo* info = i->value.get();
535 // RenderSelectionInfo::rect() is in the coordinates of the repaintContainer, so map to page coordinates.
536 LayoutRect currRect = info->rect();
537 if (const RenderLayerModelObject* repaintContainer = info->repaintContainer()) {
538 FloatQuad absQuad = repaintContainer->localToAbsoluteQuad(FloatRect(currRect));
539 currRect = absQuad.enclosingBoundingBox();
541 selRect.unite(currRect);
543 return pixelSnappedIntRect(selRect);
546 void RenderView::repaintSelection() const
548 HashSet<RenderBlock*> processedBlocks;
550 RenderObject* end = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
551 for (RenderObject* o = m_selectionStart; o && o != end; o = o->nextInPreOrder()) {
552 if (!o->canBeSelectionLeaf() && o != m_selectionStart && o != m_selectionEnd)
554 if (o->selectionState() == SelectionNone)
557 RenderSelectionInfo(o, true).repaint();
559 // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
560 for (RenderBlock* block = o->containingBlock(); block && !block->isRenderView(); block = block->containingBlock()) {
561 if (!processedBlocks.add(block).isNewEntry)
563 RenderSelectionInfo(block, true).repaint();
568 // When exploring the RenderTree looking for the nodes involved in the Selection, sometimes it's
569 // required to change the traversing direction because the "start" position is below the "end" one.
570 static inline RenderObject* getNextOrPrevRenderObjectBasedOnDirection(const RenderObject* o, const RenderObject* stop, bool& continueExploring, bool& exploringBackwards)
573 if (exploringBackwards) {
574 next = o->previousInPreOrder();
575 continueExploring = next && !(next)->isRenderView();
577 next = o->nextInPreOrder();
578 continueExploring = next && next != stop;
579 exploringBackwards = !next && (next != stop);
580 if (exploringBackwards) {
581 next = stop->previousInPreOrder();
582 continueExploring = next && !next->isRenderView();
589 void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode)
591 // This code makes no assumptions as to if the rendering tree is up to date or not
592 // and will not try to update it. Currently clearSelection calls this
593 // (intentionally) without updating the rendering tree as it doesn't care.
594 // Other callers may want to force recalc style before calling this.
596 // Make sure both our start and end objects are defined.
597 // Check www.msnbc.com and try clicking around to find the case where this happened.
598 if ((start && !end) || (end && !start))
601 // Just return if the selection hasn't changed.
602 if (m_selectionStart == start && m_selectionStartPos == startPos &&
603 m_selectionEnd == end && m_selectionEndPos == endPos)
606 // Record the old selected objects. These will be used later
607 // when we compare against the new selected objects.
608 int oldStartPos = m_selectionStartPos;
609 int oldEndPos = m_selectionEndPos;
611 // Objects each have a single selection rect to examine.
612 typedef HashMap<RenderObject*, OwnPtr<RenderSelectionInfo> > SelectedObjectMap;
613 SelectedObjectMap oldSelectedObjects;
614 SelectedObjectMap newSelectedObjects;
616 // Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks.
617 // In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise
618 // the union of those rects might remain the same even when changes have occurred.
619 typedef HashMap<RenderBlock*, OwnPtr<RenderBlockSelectionInfo> > SelectedBlockMap;
620 SelectedBlockMap oldSelectedBlocks;
621 SelectedBlockMap newSelectedBlocks;
623 RenderObject* os = m_selectionStart;
624 RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos);
625 bool exploringBackwards = false;
626 bool continueExploring = os && (os != stop);
627 while (continueExploring) {
628 if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) {
629 // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
630 oldSelectedObjects.set(os, adoptPtr(new RenderSelectionInfo(os, true)));
631 if (blockRepaintMode == RepaintNewXOROld) {
632 RenderBlock* cb = os->containingBlock();
633 while (cb && !cb->isRenderView()) {
634 OwnPtr<RenderBlockSelectionInfo>& blockInfo = oldSelectedBlocks.add(cb, nullptr).storedValue->value;
637 blockInfo = adoptPtr(new RenderBlockSelectionInfo(cb));
638 cb = cb->containingBlock();
643 os = getNextOrPrevRenderObjectBasedOnDirection(os, stop, continueExploring, exploringBackwards);
646 // Now clear the selection.
647 SelectedObjectMap::iterator oldObjectsEnd = oldSelectedObjects.end();
648 for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i)
649 i->key->setSelectionStateIfNeeded(SelectionNone);
651 // set selection start and end
652 m_selectionStart = start;
653 m_selectionStartPos = startPos;
654 m_selectionEnd = end;
655 m_selectionEndPos = endPos;
657 // Update the selection status of all objects between m_selectionStart and m_selectionEnd
658 if (start && start == end)
659 start->setSelectionStateIfNeeded(SelectionBoth);
662 start->setSelectionStateIfNeeded(SelectionStart);
664 end->setSelectionStateIfNeeded(SelectionEnd);
667 RenderObject* o = start;
668 stop = rendererAfterPosition(end, endPos);
670 while (o && o != stop) {
671 if (o != start && o != end && o->canBeSelectionLeaf())
672 o->setSelectionStateIfNeeded(SelectionInside);
673 o = o->nextInPreOrder();
676 if (blockRepaintMode != RepaintNothing)
677 layer()->clearBlockSelectionGapsBounds();
679 // Now that the selection state has been updated for the new objects, walk them again and
680 // put them in the new objects list.
682 exploringBackwards = false;
683 continueExploring = o && (o != stop);
684 while (continueExploring) {
685 if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) {
686 newSelectedObjects.set(o, adoptPtr(new RenderSelectionInfo(o, true)));
687 RenderBlock* cb = o->containingBlock();
688 while (cb && !cb->isRenderView()) {
689 OwnPtr<RenderBlockSelectionInfo>& blockInfo = newSelectedBlocks.add(cb, nullptr).storedValue->value;
692 blockInfo = adoptPtr(new RenderBlockSelectionInfo(cb));
693 cb = cb->containingBlock();
697 o = getNextOrPrevRenderObjectBasedOnDirection(o, stop, continueExploring, exploringBackwards);
700 if (!m_frameView || blockRepaintMode == RepaintNothing)
703 // Have any of the old selected objects changed compared to the new selection?
704 for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i) {
705 RenderObject* obj = i->key;
706 RenderSelectionInfo* newInfo = newSelectedObjects.get(obj);
707 RenderSelectionInfo* oldInfo = i->value.get();
708 if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state() ||
709 (m_selectionStart == obj && oldStartPos != m_selectionStartPos) ||
710 (m_selectionEnd == obj && oldEndPos != m_selectionEndPos)) {
714 newSelectedObjects.remove(obj);
719 // Any new objects that remain were not found in the old objects dict, and so they need to be updated.
720 SelectedObjectMap::iterator newObjectsEnd = newSelectedObjects.end();
721 for (SelectedObjectMap::iterator i = newSelectedObjects.begin(); i != newObjectsEnd; ++i)
724 // Have any of the old blocks changed?
725 SelectedBlockMap::iterator oldBlocksEnd = oldSelectedBlocks.end();
726 for (SelectedBlockMap::iterator i = oldSelectedBlocks.begin(); i != oldBlocksEnd; ++i) {
727 RenderBlock* block = i->key;
728 RenderBlockSelectionInfo* newInfo = newSelectedBlocks.get(block);
729 RenderBlockSelectionInfo* oldInfo = i->value.get();
730 if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) {
734 newSelectedBlocks.remove(block);
739 // Any new blocks that remain were not found in the old blocks dict, and so they need to be updated.
740 SelectedBlockMap::iterator newBlocksEnd = newSelectedBlocks.end();
741 for (SelectedBlockMap::iterator i = newSelectedBlocks.begin(); i != newBlocksEnd; ++i)
745 void RenderView::getSelection(RenderObject*& startRenderer, int& startOffset, RenderObject*& endRenderer, int& endOffset) const
747 startRenderer = m_selectionStart;
748 startOffset = m_selectionStartPos;
749 endRenderer = m_selectionEnd;
750 endOffset = m_selectionEndPos;
753 void RenderView::clearSelection()
755 layer()->repaintBlockSelectionGaps();
756 setSelection(0, -1, 0, -1, RepaintNewMinusOld);
759 void RenderView::selectionStartEnd(int& startPos, int& endPos) const
761 startPos = m_selectionStartPos;
762 endPos = m_selectionEndPos;
765 bool RenderView::shouldUsePrintingLayout() const
767 if (!document().printing() || !m_frameView)
769 return m_frameView->frame().shouldUsePrintingLayout();
772 LayoutRect RenderView::viewRect() const
774 if (shouldUsePrintingLayout())
775 return LayoutRect(LayoutPoint(), size());
777 return m_frameView->visibleContentRect();
781 IntRect RenderView::unscaledDocumentRect() const
783 LayoutRect overflowRect(layoutOverflowRect());
784 flipForWritingMode(overflowRect);
785 return pixelSnappedIntRect(overflowRect);
788 bool RenderView::rootBackgroundIsEntirelyFixed() const
790 RenderObject* rootObject = document().documentElement() ? document().documentElement()->renderer() : 0;
794 RenderObject* rootRenderer = rootObject->rendererForRootBackground();
795 return rootRenderer->hasEntirelyFixedBackground();
798 LayoutRect RenderView::backgroundRect(RenderBox* backgroundRenderer) const
801 return unscaledDocumentRect();
803 ColumnInfo* columnInfo = this->columnInfo();
804 LayoutRect backgroundRect(0, 0, columnInfo->desiredColumnWidth(), columnInfo->columnHeight() * columnInfo->columnCount());
805 if (!isHorizontalWritingMode())
806 backgroundRect = backgroundRect.transposedRect();
807 backgroundRenderer->flipForWritingMode(backgroundRect);
809 return backgroundRect;
812 IntRect RenderView::documentRect() const
814 FloatRect overflowRect(unscaledDocumentRect());
816 overflowRect = layer()->currentTransform().mapRect(overflowRect);
817 return IntRect(overflowRect);
820 int RenderView::viewHeight(IncludeScrollbarsInRect scrollbarInclusion) const
823 if (!shouldUsePrintingLayout() && m_frameView)
824 height = m_frameView->layoutSize(scrollbarInclusion).height();
829 int RenderView::viewWidth(IncludeScrollbarsInRect scrollbarInclusion) const
832 if (!shouldUsePrintingLayout() && m_frameView)
833 width = m_frameView->layoutSize(scrollbarInclusion).width();
838 int RenderView::viewLogicalHeight() const
840 return style()->isHorizontalWritingMode() ? viewHeight(ExcludeScrollbars) : viewWidth(ExcludeScrollbars);
843 float RenderView::zoomFactor() const
845 return m_frameView->frame().pageZoomFactor();
848 void RenderView::pushLayoutState(RenderObject& root)
850 ASSERT(m_layoutStateDisableCount == 0);
851 ASSERT(m_layoutState == 0);
853 pushLayoutStateForCurrentFlowThread(root);
854 m_layoutState = new LayoutState(root);
857 bool RenderView::shouldDisableLayoutStateForSubtree(RenderObject& renderer) const
859 RenderObject* o = &renderer;
861 if (o->shouldDisableLayoutState())
868 void RenderView::updateHitTestResult(HitTestResult& result, const LayoutPoint& point)
870 if (result.innerNode())
873 Node* node = document().documentElement();
875 result.setInnerNode(node);
876 if (!result.innerNonSharedNode())
877 result.setInnerNonSharedNode(node);
879 LayoutPoint adjustedPoint = point;
880 offsetForContents(adjustedPoint);
882 result.setLocalPoint(adjustedPoint);
886 bool RenderView::usesCompositing() const
888 return m_compositor && m_compositor->staleInCompositingMode();
891 RenderLayerCompositor* RenderView::compositor()
894 m_compositor = adoptPtr(new RenderLayerCompositor(*this));
896 return m_compositor.get();
899 void RenderView::setIsInWindow(bool isInWindow)
902 m_compositor->setIsInWindow(isInWindow);
905 FlowThreadController* RenderView::flowThreadController()
907 if (!m_flowThreadController)
908 m_flowThreadController = FlowThreadController::create();
910 return m_flowThreadController.get();
913 void RenderView::pushLayoutStateForCurrentFlowThread(const RenderObject& object)
915 if (!m_flowThreadController)
918 RenderFlowThread* currentFlowThread = m_flowThreadController->currentRenderFlowThread();
919 if (!currentFlowThread)
922 currentFlowThread->pushFlowThreadLayoutState(object);
925 void RenderView::popLayoutStateForCurrentFlowThread()
927 if (!m_flowThreadController)
930 RenderFlowThread* currentFlowThread = m_flowThreadController->currentRenderFlowThread();
931 if (!currentFlowThread)
934 currentFlowThread->popFlowThreadLayoutState();
937 IntervalArena* RenderView::intervalArena()
939 if (!m_intervalArena)
940 m_intervalArena = IntervalArena::create();
941 return m_intervalArena.get();
944 bool RenderView::backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const
946 // FIXME: Remove this main frame check. Same concept applies to subframes too.
947 if (!frame()->isMainFrame())
950 return m_frameView->hasOpaqueBackground();
953 double RenderView::layoutViewportWidth() const
955 float scale = m_frameView ? m_frameView->frame().pageZoomFactor() : 1;
956 return viewWidth(IncludeScrollbars) / scale;
959 double RenderView::layoutViewportHeight() const
961 float scale = m_frameView ? m_frameView->frame().pageZoomFactor() : 1;
962 return viewHeight(IncludeScrollbars) / scale;
965 } // namespace WebCore