Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1. Redistributions of source code must retain the above
      9  *    copyright notice, this list of conditions and the following
     10  *    disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above
     12  *    copyright notice, this list of conditions and the following
     13  *    disclaimer in the documentation and/or other materials
     14  *    provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
     17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
     20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     21  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     25  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     26  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 #include "config.h"
     31 #include "core/rendering/RenderRegion.h"
     32 
     33 #include "core/css/resolver/StyleResolver.h"
     34 #include "core/rendering/FlowThreadController.h"
     35 #include "core/rendering/HitTestLocation.h"
     36 #include "core/rendering/PaintInfo.h"
     37 #include "core/rendering/RenderFlowThread.h"
     38 #include "core/rendering/RenderView.h"
     39 
     40 namespace blink {
     41 
     42 RenderRegion::RenderRegion(Element* element, RenderFlowThread* flowThread)
     43     : RenderBlockFlow(element)
     44     , m_flowThread(flowThread)
     45     , m_isValid(false)
     46 {
     47 }
     48 
     49 LayoutUnit RenderRegion::pageLogicalWidth() const
     50 {
     51     ASSERT(m_flowThread);
     52     return m_flowThread->isHorizontalWritingMode() ? contentWidth() : contentHeight();
     53 }
     54 
     55 LayoutUnit RenderRegion::pageLogicalHeight() const
     56 {
     57     ASSERT(m_flowThread);
     58     return m_flowThread->isHorizontalWritingMode() ? contentHeight() : contentWidth();
     59 }
     60 
     61 LayoutRect RenderRegion::flowThreadPortionOverflowRect() const
     62 {
     63     return overflowRectForFlowThreadPortion(flowThreadPortionRect(), isFirstRegion(), isLastRegion());
     64 }
     65 
     66 LayoutRect RenderRegion::overflowRectForFlowThreadPortion(const LayoutRect& flowThreadPortionRect, bool isFirstPortion, bool isLastPortion) const
     67 {
     68     ASSERT(isValid());
     69 
     70     if (hasOverflowClip())
     71         return flowThreadPortionRect;
     72 
     73     LayoutRect flowThreadOverflow = m_flowThread->visualOverflowRect();
     74 
     75     // Only clip along the flow thread axis.
     76     LayoutRect clipRect;
     77     if (m_flowThread->isHorizontalWritingMode()) {
     78         LayoutUnit minY = isFirstPortion ? flowThreadOverflow.y() : flowThreadPortionRect.y();
     79         LayoutUnit maxY = isLastPortion ? std::max(flowThreadPortionRect.maxY(), flowThreadOverflow.maxY()) : flowThreadPortionRect.maxY();
     80         LayoutUnit minX = std::min(flowThreadPortionRect.x(), flowThreadOverflow.x());
     81         LayoutUnit maxX = std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX());
     82         clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
     83     } else {
     84         LayoutUnit minX = isFirstPortion ? flowThreadOverflow.x() : flowThreadPortionRect.x();
     85         LayoutUnit maxX = isLastPortion ? std::max(flowThreadPortionRect.maxX(), flowThreadOverflow.maxX()) : flowThreadPortionRect.maxX();
     86         LayoutUnit minY = std::min(flowThreadPortionRect.y(), (flowThreadOverflow.y()));
     87         LayoutUnit maxY = std::max(flowThreadPortionRect.y(), (flowThreadOverflow.maxY()));
     88         clipRect = LayoutRect(minX, minY, maxX - minX, maxY - minY);
     89     }
     90 
     91     return clipRect;
     92 }
     93 
     94 bool RenderRegion::isFirstRegion() const
     95 {
     96     ASSERT(isValid());
     97 
     98     return m_flowThread->firstRegion() == this;
     99 }
    100 
    101 bool RenderRegion::isLastRegion() const
    102 {
    103     ASSERT(isValid());
    104 
    105     return m_flowThread->lastRegion() == this;
    106 }
    107 
    108 void RenderRegion::layoutBlock(bool relayoutChildren)
    109 {
    110     RenderBlockFlow::layoutBlock(relayoutChildren);
    111 
    112     // FIXME: We need to find a way to set up overflow properly. Our flow thread hasn't gotten a layout
    113     // yet, so we can't look to it for correct information. It's possible we could wait until after the RenderFlowThread
    114     // gets a layout, and then try to propagate overflow information back to the region, and then mark for a second layout.
    115     // That second layout would then be able to use the information from the RenderFlowThread to set up overflow.
    116     //
    117     // The big problem though is that overflow needs to be region-specific. We can't simply use the RenderFlowThread's global
    118     // overflow values, since then we'd always think any narrow region had huge overflow (all the way to the width of the
    119     // RenderFlowThread itself).
    120 }
    121 
    122 void RenderRegion::paintInvalidationOfFlowThreadContentRectangle(const LayoutRect& paintInvalidationRect, const LayoutRect& flowThreadPortionRect, const LayoutRect& flowThreadPortionOverflowRect, const LayoutPoint& regionLocation) const
    123 {
    124     ASSERT(isValid());
    125 
    126     // We only have to issue a paint invalidation in this region if the region rect intersects the paint invalidation rect.
    127     LayoutRect flippedFlowThreadPortionRect(flowThreadPortionRect);
    128     LayoutRect flippedFlowThreadPortionOverflowRect(flowThreadPortionOverflowRect);
    129     flowThread()->flipForWritingMode(flippedFlowThreadPortionRect); // Put the region rects into physical coordinates.
    130     flowThread()->flipForWritingMode(flippedFlowThreadPortionOverflowRect);
    131 
    132     LayoutRect clippedRect(paintInvalidationRect);
    133     clippedRect.intersect(flippedFlowThreadPortionOverflowRect);
    134     if (clippedRect.isEmpty())
    135         return;
    136 
    137     // Put the region rect into the region's physical coordinate space.
    138     clippedRect.setLocation(regionLocation + (clippedRect.location() - flippedFlowThreadPortionRect.location()));
    139 
    140     // Now switch to the region's writing mode coordinate space and let it issue paint invalidations itself.
    141     flipForWritingMode(clippedRect);
    142 
    143     invalidatePaintRectangle(clippedRect);
    144 }
    145 
    146 void RenderRegion::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
    147 {
    148     if (!isValid()) {
    149         RenderBlockFlow::computeIntrinsicLogicalWidths(minLogicalWidth, maxLogicalWidth);
    150         return;
    151     }
    152 
    153     minLogicalWidth = m_flowThread->minPreferredLogicalWidth();
    154     maxLogicalWidth = m_flowThread->maxPreferredLogicalWidth();
    155 }
    156 
    157 } // namespace blink
    158