15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * disclaimer. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * disclaimer in the documentation and/or other materials 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * provided with the distribution. 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SUCH DAMAGE. 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h" 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderRegion.h" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 3381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "core/css/resolver/StyleResolver.h" 3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/FlowThreadController.h" 3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/rendering/HitTestLocation.h" 3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/PaintInfo.h" 3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/rendering/RenderFlowThread.h" 3853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/rendering/RenderView.h" 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 40c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 42926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)RenderRegion::RenderRegion(Element* element, RenderFlowThread* flowThread) 438abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) : RenderBlockFlow(element) 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) , m_flowThread(flowThread) 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) , m_isValid(false) 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)LayoutUnit RenderRegion::pageLogicalWidth() const 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 5153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(m_flowThread); 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return m_flowThread->isHorizontalWritingMode() ? contentWidth() : contentHeight(); 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)LayoutUnit RenderRegion::pageLogicalHeight() const 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 5753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(m_flowThread); 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return m_flowThread->isHorizontalWritingMode() ? contentHeight() : contentWidth(); 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)LayoutRect RenderRegion::flowThreadPortionOverflowRect() const 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return overflowRectForFlowThreadPortion(flowThreadPortionRect(), isFirstRegion(), isLastRegion()); 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)LayoutRect RenderRegion::overflowRectForFlowThreadPortion(const LayoutRect& flowThreadPortionRect, bool isFirstPortion, bool isLastPortion) const 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 6853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(isValid()); 6953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 7009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) if (hasOverflowClip()) 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return flowThreadPortionRect; 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) LayoutRect flowThreadOverflow = m_flowThread->visualOverflowRect(); 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Only clip along the flow thread axis. 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) LayoutRect clipRect; 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (m_flowThread->isHorizontalWritingMode()) { 7807a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch LayoutUnit minY = isFirstPortion ? flowThreadOverflow.y() : flowThreadPortionRect.y(); 79197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit maxY = isLastPortion ? std::max(flowThreadPortionRect.maxY(), flowThreadOverflow.maxY()) : flowThreadPortionRect.maxY(); 80197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit minX = std::min(flowThreadPortionRect.x(), flowThreadOverflow.x()); 81197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit maxX = std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()); 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY); 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else { 8407a852d8c1953036774d8f3b65d18dcfea3bb4a2Ben Murdoch LayoutUnit minX = isFirstPortion ? flowThreadOverflow.x() : flowThreadPortionRect.x(); 85197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit maxX = isLastPortion ? std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()) : flowThreadPortionRect.maxX(); 86197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit minY = std::min(flowThreadPortionRect.y(), (flowThreadOverflow.y())); 87197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch LayoutUnit maxY = std::max(flowThreadPortionRect.y(), (flowThreadOverflow.maxY())); 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY); 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return clipRect; 925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderRegion::isFirstRegion() const 955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 9653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(isValid()); 9753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return m_flowThread->firstRegion() == this; 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)bool RenderRegion::isLastRegion() const 1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 10353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(isValid()); 10453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return m_flowThread->lastRegion() == this; 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 10809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)void RenderRegion::layoutBlock(bool relayoutChildren) 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 1108abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) RenderBlockFlow::layoutBlock(relayoutChildren); 111926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: We need to find a way to set up overflow properly. Our flow thread hasn't gotten a layout 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // yet, so we can't look to it for correct information. It's possible we could wait until after the RenderFlowThread 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // gets a layout, and then try to propagate overflow information back to the region, and then mark for a second layout. 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // That second layout would then be able to use the information from the RenderFlowThread to set up overflow. 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // 1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // The big problem though is that overflow needs to be region-specific. We can't simply use the RenderFlowThread's global 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // overflow values, since then we'd always think any narrow region had huge overflow (all the way to the width of the 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // RenderFlowThread itself). 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tuccivoid RenderRegion::paintInvalidationOfFlowThreadContentRectangle(const LayoutRect& paintInvalidationRect, const LayoutRect& flowThreadPortionRect, const LayoutRect& flowThreadPortionOverflowRect, const LayoutPoint& regionLocation) const 1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 12453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) ASSERT(isValid()); 12553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 1269e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) // We only have to issue a paint invalidation in this region if the region rect intersects the paint invalidation rect. 1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect); 1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) LayoutRect flippedFlowThreadPortionOverflowRect(flowThreadPortionOverflowRect); 1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) flowThread()->flipForWritingMode(flippedFlowThreadPortionRect); // Put the region rects into physical coordinates. 1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) flowThread()->flipForWritingMode(flippedFlowThreadPortionOverflowRect); 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1329e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) LayoutRect clippedRect(paintInvalidationRect); 1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) clippedRect.intersect(flippedFlowThreadPortionOverflowRect); 1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (clippedRect.isEmpty()) 1355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return; 1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Put the region rect into the region's physical coordinate space. 1385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) clippedRect.setLocation(regionLocation + (clippedRect.location() - flippedFlowThreadPortionRect.location())); 1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1409e12abdf8c3a23d52091ea54ebb6a04d327f9300Torne (Richard Coles) // Now switch to the region's writing mode coordinate space and let it issue paint invalidations itself. 1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) flipForWritingMode(clippedRect); 14202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 1435d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) invalidatePaintRectangle(clippedRect); 1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 14653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)void RenderRegion::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const 1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 14853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) if (!isValid()) { 14909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) RenderBlockFlow::computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth); 150926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return; 151926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } 1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 15353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) minLogicalWidth = m_flowThread->minPreferredLogicalWidth(); 15453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) maxLogicalWidth = m_flowThread->maxPreferredLogicalWidth(); 1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 157c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 158