Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2010 Apple Inc. 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "RenderIFrame.h"
     28 
     29 #include "FrameView.h"
     30 #include "HTMLNames.h"
     31 #include "HTMLIFrameElement.h"
     32 #include "RenderView.h"
     33 #include "Settings.h"
     34 
     35 namespace WebCore {
     36 
     37 using namespace HTMLNames;
     38 
     39 RenderIFrame::RenderIFrame(Element* element)
     40     : RenderFrameBase(element)
     41 {
     42 }
     43 
     44 void RenderIFrame::computeLogicalHeight()
     45 {
     46     RenderPart::computeLogicalHeight();
     47     if (!flattenFrame())
     48          return;
     49 
     50     HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
     51     bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
     52 
     53     if (isScrollable || !style()->height().isFixed()) {
     54         FrameView* view = static_cast<FrameView*>(widget());
     55         if (!view)
     56             return;
     57         int border = borderTop() + borderBottom();
     58         setHeight(max(height(), view->contentsHeight() + border));
     59     }
     60 }
     61 
     62 void RenderIFrame::computeLogicalWidth()
     63 {
     64     RenderPart::computeLogicalWidth();
     65     if (!flattenFrame())
     66         return;
     67 
     68     HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
     69     bool isScrollable = frame->scrollingMode() != ScrollbarAlwaysOff;
     70 
     71     if (isScrollable || !style()->width().isFixed()) {
     72         FrameView* view = static_cast<FrameView*>(widget());
     73         if (!view)
     74             return;
     75         int border = borderLeft() + borderRight();
     76         setWidth(max(width(), view->contentsWidth() + border));
     77     }
     78 }
     79 
     80 bool RenderIFrame::flattenFrame()
     81 {
     82     if (!node() || !node()->hasTagName(iframeTag))
     83         return false;
     84 
     85     HTMLIFrameElement* element = static_cast<HTMLIFrameElement*>(node());
     86     bool isScrollable = element->scrollingMode() != ScrollbarAlwaysOff;
     87 
     88     if (!isScrollable && style()->width().isFixed()
     89         && style()->height().isFixed())
     90         return false;
     91 
     92     Frame* frame = element->document()->frame();
     93     bool enabled = frame && frame->settings()->frameFlatteningEnabled();
     94 
     95     if (!enabled || !frame->page())
     96         return false;
     97 
     98     FrameView* view = frame->page()->mainFrame()->view();
     99     if (!view)
    100         return false;
    101 
    102     // Do not flatten offscreen inner frames during frame flattening.
    103     return absoluteBoundingBoxRect().intersects(IntRect(IntPoint(0, 0), view->contentsSize()));
    104 }
    105 
    106 void RenderIFrame::layout()
    107 {
    108     ASSERT(needsLayout());
    109 
    110     RenderPart::computeLogicalWidth();
    111     RenderPart::computeLogicalHeight();
    112 
    113     if (flattenFrame()) {
    114         layoutWithFlattening(style()->width().isFixed(), style()->height().isFixed());
    115         return;
    116     }
    117 
    118     RenderPart::layout();
    119 
    120     m_overflow.clear();
    121     addShadowOverflow();
    122     updateLayerTransform();
    123 
    124     setNeedsLayout(false);
    125 }
    126 
    127 }
    128