Merge from Chromium at DEPS revision r216972

This commit was generated by merge_to_master.py.

Change-Id: Ie5904a921ece9c5959b52c8e0b74db09fa08f144
diff --git a/Source/core/rendering/CompositingReasons.h b/Source/core/rendering/CompositingReasons.h
index 0e35e82..5940c09 100644
--- a/Source/core/rendering/CompositingReasons.h
+++ b/Source/core/rendering/CompositingReasons.h
@@ -54,6 +54,10 @@
 const uint64_t CompositingReasonLayerForBackground                     = UINT64_C(1) << 30;
 const uint64_t CompositingReasonLayerForMask                           = UINT64_C(1) << 31;
 
+// FIXME: the following compositing reasons need to be re-organized to fit with categories
+// used in all the other reasons above.
+const uint64_t CompositingReasonLayerForVideoOverlay                   = UINT64_C(1) << 32;
+
 // Note: if you add more reasons here, you will need to update WebCompositingReasons as well.
 typedef uint64_t CompositingReasons;
 
diff --git a/Source/core/rendering/FilterEffectRenderer.cpp b/Source/core/rendering/FilterEffectRenderer.cpp
index 85d6c07..ea8f36e 100644
--- a/Source/core/rendering/FilterEffectRenderer.cpp
+++ b/Source/core/rendering/FilterEffectRenderer.cpp
@@ -29,8 +29,8 @@
 #include "core/rendering/FilterEffectRenderer.h"
 
 #include "core/dom/Document.h"
-#include "core/loader/cache/CachedDocument.h"
-#include "core/loader/cache/CachedSVGDocumentReference.h"
+#include "core/loader/cache/DocumentResource.h"
+#include "core/loader/cache/DocumentResourceReference.h"
 #include "core/page/Page.h"
 #include "core/platform/FloatConversion.h"
 #include "core/platform/graphics/ColorSpace.h"
diff --git a/Source/core/rendering/FilterEffectRenderer.h b/Source/core/rendering/FilterEffectRenderer.h
index 5352713..2dfe268 100644
--- a/Source/core/rendering/FilterEffectRenderer.h
+++ b/Source/core/rendering/FilterEffectRenderer.h
@@ -42,7 +42,7 @@
 
 namespace WebCore {
 
-class CachedShader;
+class ShaderResource;
 class CustomFilterProgram;
 class Document;
 class GraphicsContext;
diff --git a/Source/core/rendering/FlowThreadController.h b/Source/core/rendering/FlowThreadController.h
index b7deda8..7f56615 100644
--- a/Source/core/rendering/FlowThreadController.h
+++ b/Source/core/rendering/FlowThreadController.h
@@ -55,7 +55,7 @@
     {
         m_isRenderNamedFlowThreadOrderDirty = dirty;
         if (dirty)
-            m_view->setNeedsLayout(true);
+            m_view->setNeedsLayout();
     }
 
     RenderNamedFlowThread* ensureRenderFlowThreadWithName(const AtomicString&);
diff --git a/Source/core/rendering/HitTestLocation.cpp b/Source/core/rendering/HitTestLocation.cpp
index 19642db..96c55ae 100644
--- a/Source/core/rendering/HitTestLocation.cpp
+++ b/Source/core/rendering/HitTestLocation.cpp
@@ -34,7 +34,7 @@
 #include "core/html/HTMLPlugInImageElement.h"
 #include "core/html/HTMLVideoElement.h"
 #include "core/html/parser/HTMLParserIdioms.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/page/Frame.h"
 #include "core/page/FrameTree.h"
 #include "core/platform/Scrollbar.h"
diff --git a/Source/core/rendering/HitTestResult.cpp b/Source/core/rendering/HitTestResult.cpp
index 5fd0969..393d2cb 100644
--- a/Source/core/rendering/HitTestResult.cpp
+++ b/Source/core/rendering/HitTestResult.cpp
@@ -37,7 +37,7 @@
 #include "core/html/HTMLTextAreaElement.h"
 #include "core/html/HTMLVideoElement.h"
 #include "core/html/parser/HTMLParserIdioms.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/page/Frame.h"
 #include "core/page/FrameTree.h"
 #include "core/platform/Scrollbar.h"
diff --git a/Source/core/rendering/InlineTextBox.cpp b/Source/core/rendering/InlineTextBox.cpp
index e2eeae0..2bfe7de 100644
--- a/Source/core/rendering/InlineTextBox.cpp
+++ b/Source/core/rendering/InlineTextBox.cpp
@@ -28,6 +28,7 @@
 #include "core/dom/RenderedDocumentMarker.h"
 #include "core/dom/Text.h"
 #include "core/editing/Editor.h"
+#include "core/editing/InputMethodController.h"
 #include "core/page/Frame.h"
 #include "core/page/Page.h"
 #include "core/page/Settings.h"
@@ -47,6 +48,7 @@
 #include "core/rendering/svg/SVGTextRunRenderingContext.h"
 #include "wtf/Vector.h"
 #include "wtf/text/CString.h"
+#include "wtf/text/StringBuilder.h"
 
 using namespace std;
 
@@ -186,16 +188,6 @@
     return state;
 }
 
-static void adjustCharactersAndLengthForHyphen(BufferForAppendingHyphen& charactersWithHyphen, RenderStyle* style, StringView& string, int& length)
-{
-    const AtomicString& hyphenString = style->hyphenString();
-    charactersWithHyphen.reserveCapacity(length + hyphenString.length());
-    charactersWithHyphen.append(string);
-    charactersWithHyphen.append(hyphenString);
-    string = charactersWithHyphen.toString().createView();
-    length += hyphenString.length();
-}
-
 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos)
 {
     int sPos = max(startPos - m_start, 0);
@@ -212,7 +204,7 @@
     RenderStyle* styleToUse = textObj->style(isFirstLineStyle());
     const Font& font = styleToUse->font();
 
-    BufferForAppendingHyphen charactersWithHyphen;
+    StringBuilder charactersWithHyphen;
     bool respectHyphen = ePos == m_len && hasHyphen();
     TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charactersWithHyphen : 0);
     if (respectHyphen)
@@ -545,8 +537,8 @@
         context->concatCTM(rotation(boxRect, Clockwise));
 
     // Determine whether or not we have composition underlines to draw.
-    bool containsComposition = renderer()->node() && renderer()->frame()->editor()->compositionNode() == renderer()->node();
-    bool useCustomUnderlines = containsComposition && renderer()->frame()->editor()->compositionUsesCustomUnderlines();
+    bool containsComposition = renderer()->node() && renderer()->frame()->inputMethodController().compositionNode() == renderer()->node();
+    bool useCustomUnderlines = containsComposition && renderer()->frame()->inputMethodController().compositionUsesCustomUnderlines();
 
     // Determine the text colors and selection colors.
     Color textFillColor;
@@ -650,10 +642,11 @@
     // and composition underlines.
     if (paintInfo.phase != PaintPhaseSelection && paintInfo.phase != PaintPhaseTextClip && !isPrinting) {
 
-        if (containsComposition && !useCustomUnderlines)
+        if (containsComposition && !useCustomUnderlines) {
             paintCompositionBackground(context, boxOrigin, styleToUse, font,
-                renderer()->frame()->editor()->compositionStart(),
-                renderer()->frame()->editor()->compositionEnd());
+                renderer()->frame()->inputMethodController().compositionStart(),
+                renderer()->frame()->inputMethodController().compositionEnd());
+        }
 
         paintDocumentMarkers(context, boxOrigin, styleToUse, font, true);
 
@@ -686,7 +679,7 @@
         maximumLength = length;
     }
 
-    BufferForAppendingHyphen charactersWithHyphen;
+    StringBuilder charactersWithHyphen;
     TextRun textRun = constructTextRun(styleToUse, font, string, maximumLength, hasHyphen() ? &charactersWithHyphen : 0);
     if (hasHyphen())
         length = textRun.length();
@@ -780,7 +773,7 @@
         paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
 
         if (useCustomUnderlines) {
-            const Vector<CompositionUnderline>& underlines = renderer()->frame()->editor()->customCompositionUnderlines();
+            const Vector<CompositionUnderline>& underlines = renderer()->frame()->inputMethodController().customCompositionUnderlines();
             size_t numUnderlines = underlines.size();
 
             for (size_t index = 0; index < numUnderlines; ++index) {
@@ -865,7 +858,7 @@
     if (string.length() != static_cast<unsigned>(length) || m_start)
         string.narrow(m_start, length);
 
-    BufferForAppendingHyphen charactersWithHyphen;
+    StringBuilder charactersWithHyphen;
     bool respectHyphen = ePos == length && hasHyphen();
     TextRun textRun = constructTextRun(style, font, string, textRenderer()->textLength() - m_start, respectHyphen ? &charactersWithHyphen : 0);
     if (respectHyphen)
@@ -1494,7 +1487,7 @@
     return true;
 }
 
-TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, BufferForAppendingHyphen* charactersWithHyphen) const
+TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, StringBuilder* charactersWithHyphen) const
 {
     ASSERT(style);
 
@@ -1512,21 +1505,23 @@
     return constructTextRun(style, font, string, textRenderer->textLength() - startPos, charactersWithHyphen);
 }
 
-TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, StringView string, int maximumLength, BufferForAppendingHyphen* charactersWithHyphen) const
+TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, StringView string, int maximumLength, StringBuilder* charactersWithHyphen) const
 {
     ASSERT(style);
 
     RenderText* textRenderer = this->textRenderer();
     ASSERT(textRenderer);
 
-    int length = string.length();
-
     if (charactersWithHyphen) {
-        adjustCharactersAndLengthForHyphen(*charactersWithHyphen, style, string, length);
-        maximumLength = length;
+        const AtomicString& hyphenString = style->hyphenString();
+        charactersWithHyphen->reserveCapacity(string.length() + hyphenString.length());
+        charactersWithHyphen->append(string);
+        charactersWithHyphen->append(hyphenString);
+        string = charactersWithHyphen->toString().createView();
+        maximumLength = string.length();
     }
 
-    ASSERT(maximumLength >= length);
+    ASSERT(maximumLength >= static_cast<int>(string.length()));
 
     TextRun run(string, textPos(), expansion(), expansionBehavior(), direction(), dirOverride() || style->rtlOrdering() == VisualOrder, !textRenderer->canUseSimpleFontCodePath());
     run.setTabSize(!style->collapseWhiteSpace(), style->tabSize());
diff --git a/Source/core/rendering/InlineTextBox.h b/Source/core/rendering/InlineTextBox.h
index 8778f97..ed4d663 100644
--- a/Source/core/rendering/InlineTextBox.h
+++ b/Source/core/rendering/InlineTextBox.h
@@ -26,7 +26,7 @@
 #include "core/platform/graphics/TextRun.h"
 #include "core/rendering/InlineBox.h"
 #include "core/rendering/RenderText.h" // so textRenderer() can be inline
-#include "wtf/text/StringBuilder.h"
+#include "wtf/Forward.h"
 
 namespace WebCore {
 
@@ -36,11 +36,6 @@
 const unsigned short cNoTruncation = USHRT_MAX;
 const unsigned short cFullTruncation = USHRT_MAX - 1;
 
-class BufferForAppendingHyphen : public StringBuilder {
-public:
-    BufferForAppendingHyphen() { reserveCapacity(256); }
-};
-
 // Helper functions shared by InlineTextBox / SVGRootInlineBox
 void updateGraphicsContext(GraphicsContext*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);
 Color correctedTextColor(Color textColor, Color backgroundColor);
@@ -107,8 +102,9 @@
     LayoutUnit selectionBottom();
     LayoutUnit selectionHeight();
 
-    TextRun constructTextRun(RenderStyle*, const Font&, BufferForAppendingHyphen* = 0) const;
-    TextRun constructTextRun(RenderStyle*, const Font&, StringView, int maximumLength, BufferForAppendingHyphen* = 0) const;
+    // charactersWithHyphen, if provided, must not be destroyed before the TextRun.
+    TextRun constructTextRun(RenderStyle*, const Font&, StringBuilder* charactersWithHyphen = 0) const;
+    TextRun constructTextRun(RenderStyle*, const Font&, StringView, int maximumLength, StringBuilder* charactersWithHyphen = 0) const;
 
 public:
     virtual FloatRect calculateBoundaries() const { return FloatRect(x(), y(), width(), height()); }
diff --git a/Source/core/rendering/RenderBR.cpp b/Source/core/rendering/RenderBR.cpp
index 27fa7c7..c463047 100644
--- a/Source/core/rendering/RenderBR.cpp
+++ b/Source/core/rendering/RenderBR.cpp
@@ -28,7 +28,7 @@
 
 static PassRefPtr<StringImpl> newlineString()
 {
-    DEFINE_STATIC_LOCAL(const String, string, (ASCIILiteral("\n")));
+    DEFINE_STATIC_LOCAL(const String, string, ("\n"));
     return string.impl();
 }
 
diff --git a/Source/core/rendering/RenderBlock.cpp b/Source/core/rendering/RenderBlock.cpp
index 7bcd381..5c7a9d9 100644
--- a/Source/core/rendering/RenderBlock.cpp
+++ b/Source/core/rendering/RenderBlock.cpp
@@ -1699,7 +1699,7 @@
         }
     }
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderBlock::addOverflowFromChildren()
@@ -1714,8 +1714,7 @@
         if (columnCount(colInfo)) {
             LayoutRect lastRect = columnRectAt(colInfo, columnCount(colInfo) - 1);
             addLayoutOverflow(lastRect);
-            if (!hasOverflowClip())
-                addVisualOverflow(lastRect);
+            addContentsVisualOverflow(lastRect);
         }
     }
 }
@@ -1752,8 +1751,8 @@
     LayoutUnit textIndent = textIndentOffset();
     if (textIndent < 0) {
         LayoutRect clientRect(noOverflowRect());
-        LayoutRect rectToApply = LayoutRect(clientRect.x() + min<LayoutUnit>(0, textIndent), clientRect.y(), clientRect.width() - min<LayoutUnit>(0, textIndent), clientRect.height());
-        addVisualOverflow(rectToApply);
+        LayoutRect rectToApply = LayoutRect(clientRect.x() + textIndent, clientRect.y(), clientRect.width() - textIndent, clientRect.height());
+        addContentsVisualOverflow(rectToApply);
     }
 
     // Add visual overflow from box-shadow and border-image-outset.
@@ -1845,7 +1844,7 @@
     if (childLayer->staticBlockPosition() != logicalTop) {
         childLayer->setStaticBlockPosition(logicalTop);
         if (hasStaticBlockPosition)
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
     }
 }
 
@@ -2449,7 +2448,7 @@
     // FIXME: Technically percentage height objects only need a relayout if their percentage isn't going to be turned into
     // an auto value. Add a method to determine this, so that we can avoid the relayout.
     if (relayoutChildren || (child->hasRelativeLogicalHeight() && !isRenderView()))
-        child->setChildNeedsLayout(true, MarkOnlyThis);
+        child->setChildNeedsLayout(MarkOnlyThis);
 
     // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
     if (relayoutChildren && child->needsPreferredWidthsRecalculation())
@@ -2466,7 +2465,7 @@
                 while (box != this) {
                     if (box->normalChildNeedsLayout())
                         break;
-                    box->setChildNeedsLayout(true, MarkOnlyThis);
+                    box->setChildNeedsLayout(MarkOnlyThis);
                     box = box->containingBlock();
                     ASSERT(box);
                     if (!box)
@@ -2610,7 +2609,7 @@
             // When the child shifts to clear an item, its width can
             // change (because it has more available line width).
             // So go ahead and mark the item as dirty.
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
         }
 
         if (childRenderBlock) {
@@ -2681,8 +2680,9 @@
                     RootInlineBox* box = toRenderBox(o)->inlineBoxWrapper()->root();
                     lineBoxes.add(box);
                 }
-            } else if (o->isText() || (o->isRenderInline() && !walker.atEndOfInline()))
-                o->setNeedsLayout(false);
+            } else if (o->isText() || (o->isRenderInline() && !walker.atEndOfInline())) {
+                o->clearNeedsLayout();
+            }
         }
 
         // FIXME: Glyph overflow will get lost in this case, but not really a big deal.
@@ -2738,7 +2738,7 @@
 
     updateScrollInfoAfterLayout();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
     return true;
 }
 
@@ -2763,12 +2763,12 @@
         LayoutUnit oldLeft = box->logicalLeft();
         box->updateLogicalWidth();
         if (box->logicalLeft() != oldLeft)
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
     } else if (hasStaticBlockPosition) {
         LayoutUnit oldTop = box->logicalTop();
         box->updateLogicalHeight();
         if (box->logicalTop() != oldTop)
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
     }
 }
 
@@ -2800,7 +2800,7 @@
         // objects that are positioned implicitly like this.  Such objects are rare, and so in typical DHTML menu usage (where everything is
         // positioned explicitly) this should not incur a performance penalty.
         if (relayoutChildren || (r->style()->hasStaticBlockPosition(isHorizontalWritingMode()) && r->parent() != this))
-            r->setChildNeedsLayout(true, MarkOnlyThis);
+            r->setChildNeedsLayout(MarkOnlyThis);
 
         // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
         if (relayoutChildren && r->needsPreferredWidthsRecalculation())
@@ -2812,7 +2812,7 @@
         // We don't have to do a full layout.  We just have to update our position. Try that first. If we have shrink-to-fit width
         // and we hit the available width constraint, the layoutIfNeeded() will catch it and do a full layout.
         if (r->needsPositionedMovementLayoutOnly() && r->tryLayoutDoingPositionedMovementOnly())
-            r->setNeedsLayout(false);
+            r->clearNeedsLayout();
 
         // If we are paginated or in a line grid, go ahead and compute a vertical position for our object now.
         // If it's wrong we'll lay out again.
@@ -2845,7 +2845,7 @@
         TrackedRendererListHashSet::iterator end = positionedDescendants->end();
         for (TrackedRendererListHashSet::iterator it = positionedDescendants->begin(); it != end; ++it) {
             r = *it;
-            r->setChildNeedsLayout(true);
+            r->setChildNeedsLayout();
         }
     }
 }
@@ -2857,7 +2857,7 @@
         return;
 
     if (view()->layoutState()->pageLogicalHeightChanged() || (view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(this, logicalTop()) != pageLogicalOffset()) || shouldBreakAtLineToAvoidWidow())
-        setChildNeedsLayout(true, MarkOnlyThis);
+        setChildNeedsLayout(MarkOnlyThis);
 }
 
 void RenderBlock::repaintOverhangingFloats(bool paintAllDescendants)
@@ -2904,7 +2904,13 @@
             return;
     }
 
-    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset);
+    // There are some cases where not all clipped visual overflow is accounted for.
+    // FIXME: reduce the number of such cases.
+    ContentsClipBehavior contentsClipBehavior = ForceContentsClip;
+    if (hasOverflowClip() && !hasControlClip() && !(shouldPaintSelectionGaps() && phase == PaintPhaseForeground) && !hasCaret())
+        contentsClipBehavior = SkipContentsClipIfPossible;
+
+    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset, contentsClipBehavior);
     paintObject(paintInfo, adjustedPaintOffset);
     if (pushedClip)
         popContentsClip(paintInfo, phase, adjustedPaintOffset);
@@ -3097,8 +3103,7 @@
         child->paint(paintInfo, childPoint);
 }
 
-
-void RenderBlock::paintCaret(PaintInfo& paintInfo, const LayoutPoint& paintOffset, CaretType type)
+bool RenderBlock::hasCaret(CaretType type) const
 {
     // Paint the caret if the FrameSelection says so or if caret browsing is enabled
     bool caretBrowsing = frame()->settings() && frame()->settings()->caretBrowsingEnabled();
@@ -3111,13 +3116,18 @@
         caretPainter = frame()->page()->dragCaretController()->caretRenderer();
         isContentEditable = frame()->page()->dragCaretController()->isContentEditable();
     }
+    return caretPainter == this && (isContentEditable || caretBrowsing);
+}
 
-    if (caretPainter == this && (isContentEditable || caretBrowsing)) {
-        if (type == CursorCaret)
-            frame()->selection()->paintCaret(paintInfo.context, paintOffset, paintInfo.rect);
-        else
-            frame()->page()->dragCaretController()->paintDragCaret(frame(), paintInfo.context, paintOffset, paintInfo.rect);
-    }
+void RenderBlock::paintCaret(PaintInfo& paintInfo, const LayoutPoint& paintOffset, CaretType type)
+{
+    if (!hasCaret(type))
+        return;
+
+    if (type == CursorCaret)
+        frame()->selection()->paintCaret(paintInfo.context, paintOffset, paintInfo.rect);
+    else
+        frame()->page()->dragCaretController()->paintDragCaret(frame(), paintInfo.context, paintOffset, paintInfo.rect);
 }
 
 void RenderBlock::paintObject(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
@@ -3836,7 +3846,7 @@
         r = *it;
         if (!o || r->isDescendantOf(o)) {
             if (containingBlockState == NewContainingBlock)
-                r->setChildNeedsLayout(true, MarkOnlyThis);
+                r->setChildNeedsLayout(MarkOnlyThis);
 
             // It is parent blocks job to add positioned child to positioned objects list of its containing block
             // Parent layout needs to be invalidated to ensure this happens.
@@ -3844,7 +3854,7 @@
             while (p && !p->isRenderBlock())
                 p = p->parent();
             if (p)
-                p->setChildNeedsLayout(true);
+                p->setChildNeedsLayout();
 
             deadObjects.append(r);
         }
@@ -3886,7 +3896,7 @@
     // Just go ahead and lay out the float.
     bool isChildRenderBlock = o->isRenderBlock();
     if (isChildRenderBlock && !o->needsLayout() && view()->layoutState()->pageLogicalHeightChanged())
-        o->setChildNeedsLayout(true, MarkOnlyThis);
+        o->setChildNeedsLayout(MarkOnlyThis);
 
     bool needsBlockDirectionLocationSetBeforeLayout = isChildRenderBlock && view()->layoutState()->needsBlockDirectionLocationSetBeforeLayout();
     if (!needsBlockDirectionLocationSetBeforeLayout || isWritingModeRoot()) // We are unsplittable if we're a block flow root.
@@ -4118,7 +4128,7 @@
                 setLogicalTopForChild(childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox));
 
                 if (childBlock)
-                    childBlock->setChildNeedsLayout(true, MarkOnlyThis);
+                    childBlock->setChildNeedsLayout(MarkOnlyThis);
                 childBox->layoutIfNeeded();
             }
         }
@@ -4236,31 +4246,42 @@
     return false;
 }
 
+template<>
+bool RenderBlock::FloatIntervalSearchAdapter<RenderBlock::FloatingObject::FloatLeft>::updateOffsetIfNeeded(const FloatingObject* floatingObject) const
+{
+    if (m_renderer->logicalRightForFloat(floatingObject) > m_offset) {
+        m_offset = m_renderer->logicalRightForFloat(floatingObject);
+        return true;
+    }
+    return false;
+}
+
+template<>
+bool RenderBlock::FloatIntervalSearchAdapter<RenderBlock::FloatingObject::FloatRight>::updateOffsetIfNeeded(const FloatingObject* floatingObject) const
+{
+    if (m_renderer->logicalLeftForFloat(floatingObject) < m_offset) {
+        m_offset = m_renderer->logicalLeftForFloat(floatingObject);
+        return true;
+    }
+    return false;
+}
+
 template <RenderBlock::FloatingObject::Type FloatTypeValue>
 inline void RenderBlock::FloatIntervalSearchAdapter<FloatTypeValue>::collectIfNeeded(const IntervalType& interval) const
 {
-    const FloatingObject* r = interval.data();
-    if (r->type() != FloatTypeValue || !rangesIntersect(interval.low(), interval.high(), m_lowValue, m_highValue))
+    const FloatingObject* floatingObject = interval.data();
+    if (floatingObject->type() != FloatTypeValue || !rangesIntersect(interval.low(), interval.high(), m_lowValue, m_highValue))
         return;
 
     // All the objects returned from the tree should be already placed.
-    ASSERT(r->isPlaced() && rangesIntersect(m_renderer->pixelSnappedLogicalTopForFloat(r), m_renderer->pixelSnappedLogicalBottomForFloat(r), m_lowValue, m_highValue));
+    ASSERT(floatingObject->isPlaced());
+    ASSERT(rangesIntersect(m_renderer->pixelSnappedLogicalTopForFloat(floatingObject), m_renderer->pixelSnappedLogicalBottomForFloat(floatingObject), m_lowValue, m_highValue));
 
-    if (FloatTypeValue == FloatingObject::FloatLeft
-        && m_renderer->logicalRightForFloat(r) > m_offset) {
-        m_offset = m_renderer->logicalRightForFloat(r);
-        if (m_heightRemaining)
-            *m_heightRemaining = m_renderer->logicalBottomForFloat(r) - m_lowValue;
-    }
+    bool floatIsNewExtreme = updateOffsetIfNeeded(floatingObject);
+    if (floatIsNewExtreme && m_heightRemaining)
+        *m_heightRemaining = m_renderer->logicalBottomForFloat(floatingObject) - m_lowValue;
 
-    if (FloatTypeValue == FloatingObject::FloatRight
-        && m_renderer->logicalLeftForFloat(r) < m_offset) {
-        m_offset = m_renderer->logicalLeftForFloat(r);
-        if (m_heightRemaining)
-            *m_heightRemaining = m_renderer->logicalBottomForFloat(r) - m_lowValue;
-    }
-
-    m_last = r;
+    m_last = floatingObject;
 }
 
 LayoutUnit RenderBlock::textIndentOffset() const
@@ -4748,7 +4769,7 @@
     if (!everHadLayout())
         return;
     if (childrenInline()) {
-        setNeedsLayout(true);
+        setNeedsLayout();
         return;
     }
     for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
@@ -4765,7 +4786,7 @@
         return;
 
     MarkingBehavior markParents = inLayout ? MarkOnlyThis : MarkContainingBlockChain;
-    setChildNeedsLayout(true, markParents);
+    setChildNeedsLayout(markParents);
 
     if (floatToRemove)
         removeFloatingObject(floatToRemove);
@@ -4863,7 +4884,7 @@
                 // we need to force a relayout as though we shifted. This happens because of the dynamic addition of overhanging floats
                 // from previous siblings when negative margins exist on a child (see the addOverhangingFloats call at the end of collapseMargins).
                 if (childLogicalWidthAtOldLogicalTopOffset != childLogicalWidthAtNewLogicalTopOffset)
-                    child->setChildNeedsLayout(true, MarkOnlyThis);
+                    child->setChildNeedsLayout(MarkOnlyThis);
                 return newLogicalTop - logicalTop;
             }
 
@@ -7552,7 +7573,7 @@
             // When the child shifts to clear an item, its width can
             // change (because it has more available line width).
             // So go ahead and mark the item as dirty.
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
         }
 
         if (childRenderBlock) {
diff --git a/Source/core/rendering/RenderBlock.h b/Source/core/rendering/RenderBlock.h
index c440d3f..06300e8 100644
--- a/Source/core/rendering/RenderBlock.h
+++ b/Source/core/rendering/RenderBlock.h
@@ -881,6 +881,9 @@
     void paintSelection(PaintInfo&, const LayoutPoint&);
     void paintCaret(PaintInfo&, const LayoutPoint&, CaretType);
 
+    bool hasCaret() const { return hasCaret(CursorCaret) || hasCaret(DragCaret); }
+    bool hasCaret(CaretType) const;
+
     FloatingObject* insertFloatingObject(RenderBox*);
     void removeFloatingObject(RenderBox*);
     void removeFloatingObjectsBelow(FloatingObject*, int logicalOffset);
@@ -1188,6 +1191,8 @@
         const FloatingObject* lastFloat() const { return m_last; }
 
     private:
+        bool updateOffsetIfNeeded(const FloatingObject*) const;
+
         const RenderBlock* m_renderer;
         int m_lowValue;
         int m_highValue;
diff --git a/Source/core/rendering/RenderBlockLineLayout.cpp b/Source/core/rendering/RenderBlockLineLayout.cpp
index 4c399db..f16fcb6 100644
--- a/Source/core/rendering/RenderBlockLineLayout.cpp
+++ b/Source/core/rendering/RenderBlockLineLayout.cpp
@@ -1509,7 +1509,7 @@
     // determineStartPosition can change the fullLayout flag we have to do this here. Failure to call
     // determineStartPosition first will break fast/repaint/line-flow-with-floats-9.html.
     if (layoutState.isFullLayout() && hasInlineChild && !selfNeedsLayout()) {
-        setNeedsLayout(true, MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
+        setNeedsLayout(MarkOnlyThis); // Mark as needing a full layout to force us to repaint.
         RenderView* v = view();
         if (v && !v->doingFullRepaint() && hasLayer()) {
             // Because we waited until we were already inside layout to discover
@@ -2091,7 +2091,7 @@
                 RenderBox* box = toRenderBox(o);
 
                 if (relayoutChildren || box->hasRelativeDimensions())
-                    o->setChildNeedsLayout(true, MarkOnlyThis);
+                    o->setChildNeedsLayout(MarkOnlyThis);
 
                 // If relayoutChildren is set and the child has percentage padding or an embedded content box, we also need to invalidate the childs pref widths.
                 if (relayoutChildren && box->needsPreferredWidthsRecalculation())
@@ -2114,7 +2114,7 @@
                     toRenderInline(o)->updateAlwaysCreateLineBoxes(layoutState.isFullLayout());
                 if (layoutState.isFullLayout() || o->selfNeedsLayout())
                     dirtyLineBoxesForRenderer(o, layoutState.isFullLayout());
-                o->setNeedsLayout(false);
+                o->clearNeedsLayout();
             }
         }
 
@@ -3315,8 +3315,8 @@
         endPadding = 1;
     for (RootInlineBox* curr = firstRootBox(); curr; curr = curr->nextRootBox()) {
         addLayoutOverflow(curr->paddedLayoutOverflowRect(endPadding));
-        if (!hasOverflowClip())
-            addVisualOverflow(curr->visualOverflowRect(curr->lineTop(), curr->lineBottom()));
+        LayoutRect visualOverflow = curr->visualOverflowRect(curr->lineTop(), curr->lineBottom());
+        addContentsVisualOverflow(visualOverflow);
     }
 }
 
@@ -3426,7 +3426,7 @@
             RenderBox* o = f->m_renderer;
             setLogicalTopForChild(o, logicalTopForChild(o) + marginBeforeForChild(o) + paginationStrut);
             if (o->isRenderBlock())
-                toRenderBlock(o)->setChildNeedsLayout(true, MarkOnlyThis);
+                toRenderBlock(o)->setChildNeedsLayout(MarkOnlyThis);
             o->layoutIfNeeded();
             // Save the old logical top before calling removePlacedObject which will set
             // isPlaced to false. Otherwise it will trigger an assert in logicalTopForFloat.
diff --git a/Source/core/rendering/RenderBox.cpp b/Source/core/rendering/RenderBox.cpp
index 30f81ff..bb53fd5 100644
--- a/Source/core/rendering/RenderBox.cpp
+++ b/Source/core/rendering/RenderBox.cpp
@@ -219,7 +219,7 @@
             if (oldStyle->position() == StaticPosition)
                 repaint();
             else if (newStyle->hasOutOfFlowPosition())
-                parent()->setChildNeedsLayout(true);
+                parent()->setChildNeedsLayout();
             if (isFloating() && !isOutOfFlowPositioned() && newStyle->hasOutOfFlowPosition())
                 removeFloatingOrPositionedChildFromBlockLists();
         }
@@ -247,7 +247,7 @@
         // to determine the new static position.
         if (isOutOfFlowPositioned() && newStyle->hasStaticBlockPosition(isHorizontalWritingMode()) && oldStyle->marginBefore() != newStyle->marginBefore()
             && parent() && !parent()->normalChildNeedsLayout())
-            parent()->setChildNeedsLayout(true);
+            parent()->setChildNeedsLayout();
     }
 
     if (RenderBlock::hasPercentHeightContainerMap() && firstChild()
@@ -388,7 +388,7 @@
 
     RenderObject* child = firstChild();
     if (!child) {
-        setNeedsLayout(false);
+        clearNeedsLayout();
         return;
     }
 
@@ -400,7 +400,7 @@
     }
     statePusher.pop();
     invalidateBackgroundObscurationStatus();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 // More IE extensions.  clientWidth and clientHeight represent the interior of an object
@@ -1517,7 +1517,7 @@
     return false;
 }
 
-bool RenderBox::pushContentsClip(PaintInfo& paintInfo, const LayoutPoint& accumulatedOffset)
+bool RenderBox::pushContentsClip(PaintInfo& paintInfo, const LayoutPoint& accumulatedOffset, ContentsClipBehavior contentsClipBehavior)
 {
     if (paintInfo.phase == PaintPhaseBlockBackground || paintInfo.phase == PaintPhaseSelfOutline || paintInfo.phase == PaintPhaseMask)
         return false;
@@ -1528,6 +1528,27 @@
     if (!isControlClip && !isOverflowClip)
         return false;
 
+    LayoutRect clipRect = isControlClip ? controlClipRect(accumulatedOffset) : overflowClipRect(accumulatedOffset, paintInfo.renderRegion);
+    RoundedRect clipRoundedRect(0, 0, 0, 0);
+    bool hasBorderRadius = style()->hasBorderRadius();
+    if (hasBorderRadius)
+        clipRoundedRect = style()->getRoundedInnerBorderFor(LayoutRect(accumulatedOffset, size()));
+
+    if (contentsClipBehavior == SkipContentsClipIfPossible) {
+        LayoutRect contentsVisualOverflow = contentsVisualOverflowRect();
+        if (contentsVisualOverflow.isEmpty())
+            return false;
+
+        LayoutRect conservativeClipRect = clipRect;
+        if (hasBorderRadius)
+            conservativeClipRect.intersect(clipRoundedRect.radiusCenterRect());
+        conservativeClipRect.moveBy(-accumulatedOffset);
+        if (hasLayer())
+            conservativeClipRect.move(scrolledContentOffset());
+        if (conservativeClipRect.contains(contentsVisualOverflow))
+            return false;
+    }
+
     if (paintInfo.phase == PaintPhaseOutline)
         paintInfo.phase = PaintPhaseChildOutlines;
     else if (paintInfo.phase == PaintPhaseChildBlockBackground) {
@@ -1535,11 +1556,10 @@
         paintObject(paintInfo, accumulatedOffset);
         paintInfo.phase = PaintPhaseChildBlockBackgrounds;
     }
-    IntRect clipRect = pixelSnappedIntRect(isControlClip ? controlClipRect(accumulatedOffset) : overflowClipRect(accumulatedOffset, paintInfo.renderRegion));
     paintInfo.context->save();
-    if (style()->hasBorderRadius())
-        paintInfo.context->clipRoundedRect(style()->getRoundedInnerBorderFor(LayoutRect(accumulatedOffset, size())));
-    paintInfo.context->clip(clipRect);
+    if (hasBorderRadius)
+        paintInfo.context->clipRoundedRect(clipRoundedRect);
+    paintInfo.context->clip(pixelSnappedIntRect(clipRect));
     return true;
 }
 
@@ -1858,7 +1878,7 @@
             RootInlineBox* root = box->root();
             root->block()->setStaticInlinePositionForChild(this, root->lineTopWithLeading(), LayoutUnit::fromFloatRound(box->logicalLeft()));
             if (style()->hasStaticInlinePosition(box->isHorizontal()))
-                setChildNeedsLayout(true, MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
+                setChildNeedsLayout(MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
         } else {
             // Our object was a block originally, so we make our normal flow position be
             // just below the line box (as though all the inlines that came before us got
@@ -1866,7 +1886,7 @@
             // in flow).  This value was cached in the y() of the box.
             layer()->setStaticBlockPosition(box->logicalTop());
             if (style()->hasStaticBlockPosition(box->isHorizontal()))
-                setChildNeedsLayout(true, MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
+                setChildNeedsLayout(MarkOnlyThis); // Just go ahead and mark the positioned object as needing layout, so it will update its position properly.
         }
 
         // Nuke the box.
@@ -4210,7 +4230,8 @@
     }
 
     // Add in the final overflow with shadows and outsets combined.
-    addVisualOverflow(LayoutRect(overflowMinX, overflowMinY, overflowMaxX - overflowMinX, overflowMaxY - overflowMinY));
+    LayoutRect visualEffectOverflow(overflowMinX, overflowMinY, overflowMaxX - overflowMinX, overflowMaxY - overflowMinY);
+    addVisualOverflow(visualEffectOverflow);
 }
 
 void RenderBox::addOverflowFromChild(RenderBox* child, const LayoutSize& delta)
@@ -4229,11 +4250,11 @@
     // Add in visual overflow from the child.  Even if the child clips its overflow, it may still
     // have visual overflow of its own set from box shadows or reflections.  It is unnecessary to propagate this
     // overflow if we are clipping our own overflow.
-    if (child->hasSelfPaintingLayer() || hasOverflowClip())
+    if (child->hasSelfPaintingLayer())
         return;
     LayoutRect childVisualOverflowRect = child->visualOverflowRectForPropagation(style());
     childVisualOverflowRect.move(delta);
-    addVisualOverflow(childVisualOverflowRect);
+    addContentsVisualOverflow(childVisualOverflowRect);
 }
 
 void RenderBox::addLayoutOverflow(const LayoutRect& rect)
@@ -4298,12 +4319,24 @@
     m_overflow->addVisualOverflow(rect);
 }
 
+void RenderBox::addContentsVisualOverflow(const LayoutRect& rect)
+{
+    if (!hasOverflowClip()) {
+        addVisualOverflow(rect);
+        return;
+    }
+
+    if (!m_overflow)
+        m_overflow = adoptPtr(new RenderOverflow(clientBoxRect(), borderBoxRect()));
+    m_overflow->addContentsVisualOverflow(rect);
+}
+
 void RenderBox::clearLayoutOverflow()
 {
     if (!m_overflow)
         return;
 
-    if (!hasVisualOverflow()) {
+    if (!hasVisualOverflow() && contentsVisualOverflowRect().isEmpty()) {
         m_overflow.clear();
         return;
     }
diff --git a/Source/core/rendering/RenderBox.h b/Source/core/rendering/RenderBox.h
index 24562dc..4246b71 100644
--- a/Source/core/rendering/RenderBox.h
+++ b/Source/core/rendering/RenderBox.h
@@ -40,6 +40,8 @@
 
 enum ShouldComputePreferred { ComputeActual, ComputePreferred };
 
+enum ContentsClipBehavior { ForceContentsClip, SkipContentsClipIfPossible };
+
 class RenderBox : public RenderBoxModelObject {
 public:
     explicit RenderBox(ContainerNode*);
@@ -186,9 +188,14 @@
 
     LayoutRect overflowRectForPaintRejection() const;
 
+    LayoutRect contentsVisualOverflowRect() const { return m_overflow ? m_overflow->contentsVisualOverflowRect() : LayoutRect(); }
+
     void addLayoutOverflow(const LayoutRect&);
     void addVisualOverflow(const LayoutRect&);
 
+    // Clipped by the contents clip, if one exists.
+    void addContentsVisualOverflow(const LayoutRect&);
+
     void addVisualEffectOverflow();
     void addOverflowFromChild(RenderBox* child) { addOverflowFromChild(child, child->locationOffset()); }
     void addOverflowFromChild(RenderBox* child, const LayoutSize& delta);
@@ -470,7 +477,7 @@
     LayoutRect clipRect(const LayoutPoint& location, RenderRegion*);
     virtual bool hasControlClip() const { return false; }
     virtual LayoutRect controlClipRect(const LayoutPoint&) const { return LayoutRect(); }
-    bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset);
+    bool pushContentsClip(PaintInfo&, const LayoutPoint& accumulatedOffset, ContentsClipBehavior);
     void popContentsClip(PaintInfo&, PaintPhase originalPhase, const LayoutPoint& accumulatedOffset);
 
     virtual void paintObject(PaintInfo&, const LayoutPoint&) { ASSERT_NOT_REACHED(); }
diff --git a/Source/core/rendering/RenderDeprecatedFlexibleBox.cpp b/Source/core/rendering/RenderDeprecatedFlexibleBox.cpp
index 8135893..bdf05c9 100644
--- a/Source/core/rendering/RenderDeprecatedFlexibleBox.cpp
+++ b/Source/core/rendering/RenderDeprecatedFlexibleBox.cpp
@@ -333,7 +333,7 @@
     // Repaint with our new bounds if they are different from our old bounds.
     repainter.repaintAfterLayout();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 // The first walk over our kids is to find out if we have any flexible children.
@@ -346,7 +346,7 @@
             // may have changed, and we need to reallocate space.
             child->clearOverrideSize();
             if (!relayoutChildren)
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
             haveFlex = true;
             unsigned int flexGroup = child->style()->boxFlexGroup();
             if (lowestFlexGroup == 0)
@@ -393,7 +393,7 @@
         for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
             // make sure we relayout children if we need it.
             if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent())))
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
 
             if (child->isOutOfFlowPositioned())
                 continue;
@@ -450,7 +450,7 @@
                 if (childLayer->staticBlockPosition() != yPos) {
                     childLayer->setStaticBlockPosition(yPos);
                     if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
-                        child->setChildNeedsLayout(true, MarkOnlyThis);
+                        child->setChildNeedsLayout(MarkOnlyThis);
                 }
                 continue;
             }
@@ -469,7 +469,7 @@
             LayoutUnit oldChildHeight = child->height();
             child->updateLogicalHeight();
             if (oldChildHeight != child->height())
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
 
             if (!child->needsLayout())
                 child->markForPaginationRelayoutIfNeeded();
@@ -682,7 +682,7 @@
         for (RenderBox* child = iterator.first(); child; child = iterator.next()) {
             // Make sure we relayout children if we need it.
             if (!haveLineClamp && (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))))
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
 
             if (child->isOutOfFlowPositioned()) {
                 child->containingBlock()->insertPositionedObject(child);
@@ -691,7 +691,7 @@
                 if (childLayer->staticBlockPosition() != height()) {
                     childLayer->setStaticBlockPosition(height());
                     if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
-                        child->setChildNeedsLayout(true, MarkOnlyThis);
+                        child->setChildNeedsLayout(MarkOnlyThis);
                 }
                 continue;
             }
@@ -909,7 +909,7 @@
         child->clearOverrideSize();
         if (relayoutChildren || (child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))
             || (child->style()->height().isAuto() && child->isBlockFlow())) {
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
 
             // Dirty all the positioned objects.
             if (child->isRenderBlock()) {
@@ -1007,7 +1007,7 @@
         child->clearOverrideSize();
         if ((child->isReplaced() && (child->style()->width().isPercent() || child->style()->height().isPercent()))
             || (child->style()->height().isAuto() && child->isBlockFlow())) {
-            child->setChildNeedsLayout(true);
+            child->setChildNeedsLayout();
 
             if (child->isRenderBlock()) {
                 toRenderBlock(child)->markPositionedObjectsForLayout();
diff --git a/Source/core/rendering/RenderEmbeddedObject.cpp b/Source/core/rendering/RenderEmbeddedObject.cpp
index de41af3..475acd6 100644
--- a/Source/core/rendering/RenderEmbeddedObject.cpp
+++ b/Source/core/rendering/RenderEmbeddedObject.cpp
@@ -225,7 +225,7 @@
     if (!widget() && frameView())
         frameView()->addWidgetToUpdate(this);
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 
     if (!canHaveChildren())
         return;
@@ -254,7 +254,7 @@
     childBox->style()->setHeight(Length(newSize.height(), Fixed));
     childBox->style()->setWidth(Length(newSize.width(), Fixed));
     childBox->forceLayout();
-    setChildNeedsLayout(false);
+    clearNeedsLayout();
 
     statePusher.pop();
 }
diff --git a/Source/core/rendering/RenderFieldset.cpp b/Source/core/rendering/RenderFieldset.cpp
index 291c686..7587425 100644
--- a/Source/core/rendering/RenderFieldset.cpp
+++ b/Source/core/rendering/RenderFieldset.cpp
@@ -65,7 +65,7 @@
     RenderBox* legend = findLegend();
     if (legend) {
         if (relayoutChildren)
-            legend->setNeedsLayout(true);
+            legend->setNeedsLayout();
         legend->layoutIfNeeded();
 
         LayoutUnit logicalLeft;
diff --git a/Source/core/rendering/RenderFlexibleBox.cpp b/Source/core/rendering/RenderFlexibleBox.cpp
index 40c26e0..54139ab 100644
--- a/Source/core/rendering/RenderFlexibleBox.cpp
+++ b/Source/core/rendering/RenderFlexibleBox.cpp
@@ -228,7 +228,7 @@
         for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
             EAlignItems previousAlignment = resolveAlignment(oldStyle, child->style());
             if (previousAlignment == AlignStretch && previousAlignment != resolveAlignment(style(), child->style()))
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
         }
     }
 }
@@ -294,7 +294,7 @@
 
     repainter.repaintAfterLayout();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderFlexibleBox::appendChildFrameRects(ChildFrameRects& childFrameRects)
@@ -659,7 +659,7 @@
     if (flexBasis.isAuto() || (flexBasis.isFixed() && !flexBasis.value() && hasInfiniteLineLength)) {
         if (hasOrthogonalFlow(child)) {
             if (hasOverrideSize)
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
             child->layoutIfNeeded();
         }
         LayoutUnit mainAxisExtent = hasOrthogonalFlow(child) ? child->logicalHeight() : child->maxPreferredLogicalWidth();
@@ -1027,7 +1027,7 @@
     if (childLayer->staticBlockPosition() != staticBlockPosition) {
         childLayer->setStaticBlockPosition(staticBlockPosition);
         if (child->style()->hasStaticBlockPosition(style()->isHorizontalWritingMode()))
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
     }
 }
 
@@ -1101,7 +1101,7 @@
         setLogicalOverrideSize(child, childPreferredSize);
         // FIXME: Can avoid laying out here in some cases. See https://webkit.org/b/87905.
         if (needToStretchChild(child) || childPreferredSize != mainAxisExtentForChild(child))
-            child->setChildNeedsLayout(true, MarkOnlyThis);
+            child->setChildNeedsLayout(MarkOnlyThis);
         else {
             // To avoid double applying margin changes in updateAutoMarginsInCrossAxis, we reset the margins here.
             resetAutoMarginsAndLogicalTopInCrossAxis(child);
diff --git a/Source/core/rendering/RenderFlowThread.cpp b/Source/core/rendering/RenderFlowThread.cpp
index a6b3ae8..97ef84a 100644
--- a/Source/core/rendering/RenderFlowThread.cpp
+++ b/Source/core/rendering/RenderFlowThread.cpp
@@ -84,7 +84,7 @@
     RenderBlock::styleDidChange(diff, oldStyle);
 
     if (oldStyle && oldStyle->writingMode() != style()->writingMode())
-        m_regionsInvalidated = true;
+        invalidateRegions();
 }
 
 void RenderFlowThread::removeFlowChildInfo(RenderObject* child)
@@ -117,7 +117,7 @@
     m_regionRangeMap.clear();
     m_breakBeforeToRegionMap.clear();
     m_breakAfterToRegionMap.clear();
-    setNeedsLayout(true);
+    setNeedsLayout();
 
     m_regionsInvalidated = true;
 }
@@ -849,7 +849,7 @@
 
         // FIXME: We need to find a way to avoid marking all the regions ancestors for layout
         // as we are already inside layout.
-        region->setNeedsLayout(true);
+        region->setNeedsLayout();
     }
 }
 
diff --git a/Source/core/rendering/RenderFlowThread.h b/Source/core/rendering/RenderFlowThread.h
index 18fb7db..3da1907 100644
--- a/Source/core/rendering/RenderFlowThread.h
+++ b/Source/core/rendering/RenderFlowThread.h
@@ -87,6 +87,7 @@
     // Check if the content is flown into at least a region with region styling rules.
     bool hasRegionsWithStyling() const { return m_hasRegionsWithStyling; }
     void checkRegionsWithStyling();
+    virtual void regionChangedWritingMode(RenderRegion*) { }
 
     void validateRegions();
     void invalidateRegions();
diff --git a/Source/core/rendering/RenderFrameSet.cpp b/Source/core/rendering/RenderFrameSet.cpp
index 5849e14..0126642 100644
--- a/Source/core/rendering/RenderFrameSet.cpp
+++ b/Source/core/rendering/RenderFrameSet.cpp
@@ -480,7 +480,7 @@
             repaintUsingContainer(repaintContainer, pixelSnappedIntRect(newBounds));
     }
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderFrameSet::positionFrames()
@@ -505,7 +505,7 @@
             if (width != child->width() || height != child->height()) {
                 child->setWidth(width);
                 child->setHeight(height);
-                child->setNeedsLayout(true);
+                child->setNeedsLayout();
                 child->layout();
             }
 
@@ -522,7 +522,7 @@
     for (; child; child = child->nextSiblingBox()) {
         child->setWidth(0);
         child->setHeight(0);
-        child->setNeedsLayout(false);
+        child->clearNeedsLayout();
     }
 }
 
@@ -549,7 +549,7 @@
         return;
     axis.m_deltas[axis.m_splitBeingResized - 1] += delta;
     axis.m_deltas[axis.m_splitBeingResized] -= delta;
-    setNeedsLayout(true);
+    setNeedsLayout();
 }
 
 bool RenderFrameSet::userResize(MouseEvent* evt)
diff --git a/Source/core/rendering/RenderGrid.cpp b/Source/core/rendering/RenderGrid.cpp
index 3a9e0a7..9d0d589 100644
--- a/Source/core/rendering/RenderGrid.cpp
+++ b/Source/core/rendering/RenderGrid.cpp
@@ -273,7 +273,7 @@
 
     repainter.repaintAfterLayout();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderGrid::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
@@ -514,7 +514,7 @@
     // doesn't return if the logical height is available so would need to be changed.
     // 2) Relayout if the column track's used breadth changed OR the logical height is unavailable.
     if (!child->needsLayout())
-        child->setNeedsLayout(true, MarkOnlyThis);
+        child->setNeedsLayout(MarkOnlyThis);
 
     child->setOverrideContainingBlockContentLogicalWidth(gridAreaBreadthForChild(child, ForColumns, columnTracks));
     // If |child| has a percentage logical height, we shouldn't let it override its intrinsic height, which is
@@ -855,7 +855,7 @@
         LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChild(child, ForColumns, columnTracks);
         LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChild(child, ForRows, rowTracks);
         if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth || oldOverrideContainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight)
-            child->setNeedsLayout(true, MarkOnlyThis);
+            child->setNeedsLayout(MarkOnlyThis);
 
         child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth);
         child->setOverrideContainingBlockContentLogicalHeight(overrideContainingBlockContentLogicalHeight);
@@ -975,7 +975,6 @@
 
 size_t RenderGrid::resolveGridPositionFromStyle(const GridPosition& position, GridPositionSide side) const
 {
-    // FIXME: Handle other values for grid-{row,column} like ranges or line names.
     switch (position.type()) {
     case ExplicitPosition: {
         ASSERT(position.integerPosition());
@@ -997,8 +996,24 @@
         return adjustGridPositionForSide(endOfTrack - resolvedPosition, side);
     }
     case NamedGridAreaPosition:
-        // FIXME: Support resolving named grid area (crbug.com/258092).
+    {
+        NamedGridAreaMap::const_iterator it = style()->namedGridArea().find(position.namedGridLine());
+        // Unknown grid area should have been computed to 'auto' by now.
+        ASSERT(it != style()->namedGridArea().end());
+        const GridCoordinate& gridAreaCoordinate = it->value;
+        switch (side) {
+        case ColumnStartSide:
+            return gridAreaCoordinate.columns.initialPositionIndex;
+        case ColumnEndSide:
+            return gridAreaCoordinate.columns.finalPositionIndex;
+        case RowStartSide:
+            return gridAreaCoordinate.rows.initialPositionIndex;
+        case RowEndSide:
+            return gridAreaCoordinate.rows.finalPositionIndex;
+        }
+        ASSERT_NOT_REACHED();
         return 0;
+    }
     case AutoPosition:
     case SpanPosition:
         // 'auto' and span depend on the opposite position for resolution (e.g. grid-row: auto / 1 or grid-column: span 3 / "myHeader").
diff --git a/Source/core/rendering/RenderHTMLCanvas.cpp b/Source/core/rendering/RenderHTMLCanvas.cpp
index d75685a..e1c5924 100644
--- a/Source/core/rendering/RenderHTMLCanvas.cpp
+++ b/Source/core/rendering/RenderHTMLCanvas.cpp
@@ -92,7 +92,7 @@
         return;
 
     if (!selfNeedsLayout())
-        setNeedsLayout(true);
+        setNeedsLayout();
 }
 
 } // namespace WebCore
diff --git a/Source/core/rendering/RenderIFrame.cpp b/Source/core/rendering/RenderIFrame.cpp
index a4b649a..d594e8b 100644
--- a/Source/core/rendering/RenderIFrame.cpp
+++ b/Source/core/rendering/RenderIFrame.cpp
@@ -137,7 +137,7 @@
     addVisualEffectOverflow();
     updateLayerTransform();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 }
diff --git a/Source/core/rendering/RenderImage.cpp b/Source/core/rendering/RenderImage.cpp
index d1ac1ea..ce48656 100644
--- a/Source/core/rendering/RenderImage.cpp
+++ b/Source/core/rendering/RenderImage.cpp
@@ -34,7 +34,7 @@
 #include "core/html/HTMLImageElement.h"
 #include "core/html/HTMLInputElement.h"
 #include "core/html/HTMLMapElement.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/page/Frame.h"
 #include "core/page/Page.h"
 #include "core/platform/graphics/Font.h"
@@ -91,7 +91,7 @@
 static const float maxAltTextWidth = 1024;
 static const int maxAltTextHeight = 256;
 
-IntSize RenderImage::imageSizeForError(CachedImage* newImage) const
+IntSize RenderImage::imageSizeForError(ImageResource* newImage) const
 {
     ASSERT_ARG(newImage, newImage);
     ASSERT_ARG(newImage, newImage->imageForRenderer(this));
@@ -112,7 +112,7 @@
 
 // Sets the image height and width to fit the alt text.  Returns true if the
 // image size changed.
-bool RenderImage::setImageSizeForAltText(CachedImage* newImage /* = 0 */)
+bool RenderImage::setImageSizeForAltText(ImageResource* newImage /* = 0 */)
 {
     IntSize imageSize;
     if (newImage && newImage->imageForRenderer(this))
@@ -234,7 +234,7 @@
         if (imageSizeChanged || hasOverrideSize || containingBlockNeedsToRecomputePreferredSize) {
             shouldRepaint = false;
             if (!selfNeedsLayout())
-                setNeedsLayout(true);
+                setNeedsLayout();
         }
     }
 
@@ -585,7 +585,7 @@
     if (!m_imageResource)
         return 0;
 
-    CachedImage* cachedImage = m_imageResource->cachedImage();
+    ImageResource* cachedImage = m_imageResource->cachedImage();
     if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage())
         return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox();
 
diff --git a/Source/core/rendering/RenderImage.h b/Source/core/rendering/RenderImage.h
index 9903965..6c4aeed 100644
--- a/Source/core/rendering/RenderImage.h
+++ b/Source/core/rendering/RenderImage.h
@@ -44,9 +44,9 @@
 
     RenderImageResource* imageResource() { return m_imageResource.get(); }
     const RenderImageResource* imageResource() const { return m_imageResource.get(); }
-    CachedImage* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
+    ImageResource* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
 
-    bool setImageSizeForAltText(CachedImage* newImage = 0);
+    bool setImageSizeForAltText(ImageResource* newImage = 0);
 
     void updateAltText();
 
@@ -98,7 +98,7 @@
 
     virtual bool boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance, InlineFlowBox*) const OVERRIDE FINAL;
 
-    IntSize imageSizeForError(CachedImage*) const;
+    IntSize imageSizeForError(ImageResource*) const;
     void imageDimensionsChanged(bool imageSizeChanged, const IntRect* = 0);
     bool updateIntrinsicSizeIfNeeded(const LayoutSize&, bool imageSizeChanged);
 
diff --git a/Source/core/rendering/RenderImageResource.cpp b/Source/core/rendering/RenderImageResource.cpp
index 9ac02de..4a38fdd 100644
--- a/Source/core/rendering/RenderImageResource.cpp
+++ b/Source/core/rendering/RenderImageResource.cpp
@@ -28,7 +28,7 @@
 #include "config.h"
 #include "core/rendering/RenderImageResource.h"
 
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/platform/graphics/Image.h"
 #include "core/rendering/RenderObject.h"
 
@@ -59,7 +59,7 @@
         m_cachedImage->removeClient(m_renderer);
 }
 
-void RenderImageResource::setCachedImage(CachedImage* newImage)
+void RenderImageResource::setImageResource(ImageResource* newImage)
 {
     ASSERT(m_renderer);
 
diff --git a/Source/core/rendering/RenderImageResource.h b/Source/core/rendering/RenderImageResource.h
index b07dc78..d222111 100644
--- a/Source/core/rendering/RenderImageResource.h
+++ b/Source/core/rendering/RenderImageResource.h
@@ -26,7 +26,7 @@
 #ifndef RenderImageResource_h
 #define RenderImageResource_h
 
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/loader/cache/ResourcePtr.h"
 #include "core/platform/graphics/Image.h"
 #include "core/platform/graphics/LayoutSize.h"
@@ -49,8 +49,8 @@
     virtual void initialize(RenderObject*);
     virtual void shutdown();
 
-    void setCachedImage(CachedImage*);
-    CachedImage* cachedImage() const { return m_cachedImage.get(); }
+    void setImageResource(ImageResource*);
+    ImageResource* cachedImage() const { return m_cachedImage.get(); }
     virtual bool hasImage() const { return m_cachedImage; }
 
     void resetAnimation();
@@ -70,7 +70,7 @@
 protected:
     RenderImageResource();
     RenderObject* m_renderer;
-    ResourcePtr<CachedImage> m_cachedImage;
+    ResourcePtr<ImageResource> m_cachedImage;
 
 private:
     static Image* nullImage();
diff --git a/Source/core/rendering/RenderImageResourceStyleImage.cpp b/Source/core/rendering/RenderImageResourceStyleImage.cpp
index 4580e15..ec90235 100644
--- a/Source/core/rendering/RenderImageResourceStyleImage.cpp
+++ b/Source/core/rendering/RenderImageResourceStyleImage.cpp
@@ -28,9 +28,9 @@
 #include "config.h"
 #include "core/rendering/RenderImageResourceStyleImage.h"
 
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/rendering/RenderObject.h"
-#include "core/rendering/style/StyleCachedImage.h"
+#include "core/rendering/style/StyleFetchedImage.h"
 
 namespace WebCore {
 
@@ -48,8 +48,8 @@
 {
     RenderImageResource::initialize(renderer);
 
-    if (m_styleImage->isCachedImage())
-        m_cachedImage = static_cast<StyleCachedImage*>(m_styleImage.get())->cachedImage();
+    if (m_styleImage->isImageResource())
+        m_cachedImage = static_cast<StyleFetchedImage*>(m_styleImage.get())->cachedImage();
 
     m_styleImage->addClient(m_renderer);
 }
diff --git a/Source/core/rendering/RenderInline.cpp b/Source/core/rendering/RenderInline.cpp
index 9aa9940..9464e2a 100644
--- a/Source/core/rendering/RenderInline.cpp
+++ b/Source/core/rendering/RenderInline.cpp
@@ -192,7 +192,7 @@
         bool alwaysCreateLineBoxes = hasSelfPaintingLayer() || hasBoxDecorations() || newStyle->hasPadding() || newStyle->hasMargin() || hasOutline();
         if (oldStyle && alwaysCreateLineBoxes) {
             dirtyLineBoxes(false);
-            setNeedsLayout(true);
+            setNeedsLayout();
         }
         m_alwaysCreateLineBoxes = alwaysCreateLineBoxes;
     }
diff --git a/Source/core/rendering/RenderLayer.cpp b/Source/core/rendering/RenderLayer.cpp
index 33efe07..9f6939f 100644
--- a/Source/core/rendering/RenderLayer.cpp
+++ b/Source/core/rendering/RenderLayer.cpp
@@ -2530,7 +2530,7 @@
 bool RenderLayer::isActive() const
 {
     Page* page = renderer()->frame()->page();
-    return page && page->focusController()->isActive();
+    return page && page->focusController().isActive();
 }
 
 static int cornerStart(const RenderStyle* style, int minX, int maxX, int thickness)
@@ -3056,7 +3056,7 @@
             if (!m_inOverflowRelayout) {
                 // Our proprietary overflow: overlay value doesn't trigger a layout.
                 m_inOverflowRelayout = true;
-                renderer()->setNeedsLayout(true, MarkOnlyThis);
+                renderer()->setNeedsLayout(MarkOnlyThis);
                 if (renderer()->isRenderBlock()) {
                     RenderBlock* block = toRenderBlock(renderer());
                     block->scrollbarsChanged(autoHorizontalScrollBarChanged, autoVerticalScrollBarChanged);
@@ -6310,6 +6310,33 @@
         renderer()->repaint();
 }
 
+void RenderLayer::addLayerHitTestRects(LayerHitTestRects& rects) const
+{
+    if (!size().isEmpty()) {
+        Vector<LayoutRect> rect;
+
+        if (renderBox() && renderBox()->scrollsOverflow()) {
+            // For scrolling layers, rects are taken to be in the space of the contents.
+            // We need to include both the entire contents, and also the bounding box
+            // of the layer in the space of it's parent (eg. for border / scroll bars).
+            rect.append(m_overflowRect);
+            rects.set(this, rect);
+            if (const RenderLayer* parentLayer = parent()) {
+                LayerHitTestRects::iterator iter = rects.find(parentLayer);
+                if (iter == rects.end())
+                    iter = rects.add(parentLayer, Vector<LayoutRect>()).iterator;
+                iter->value.append(boundingBox(parentLayer));
+            }
+        } else {
+            rect.append(localBoundingBox());
+            rects.set(this, rect);
+        }
+    }
+
+    for (RenderLayer* child = firstChild(); child; child = child->nextSibling())
+        child->addLayerHitTestRects(rects);
+}
+
 } // namespace WebCore
 
 #ifndef NDEBUG
diff --git a/Source/core/rendering/RenderLayer.h b/Source/core/rendering/RenderLayer.h
index db8fd09..5a7c14f 100644
--- a/Source/core/rendering/RenderLayer.h
+++ b/Source/core/rendering/RenderLayer.h
@@ -811,6 +811,8 @@
 
     void setForceNeedsCompositedScrolling(ForceNeedsCompositedScrollingMode);
 
+    void addLayerHitTestRects(LayerHitTestRects&) const;
+
 private:
     enum CollectLayersBehavior {
         ForceLayerToStackingContainer,
diff --git a/Source/core/rendering/RenderLayerBacking.cpp b/Source/core/rendering/RenderLayerBacking.cpp
index 938cf70..c8991f2 100644
--- a/Source/core/rendering/RenderLayerBacking.cpp
+++ b/Source/core/rendering/RenderLayerBacking.cpp
@@ -34,7 +34,7 @@
 #include "core/html/HTMLMediaElement.h"
 #include "core/html/canvas/CanvasRenderingContext.h"
 #include "core/inspector/InspectorInstrumentation.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/page/Chrome.h"
 #include "core/page/FrameView.h"
 #include "core/page/Settings.h"
@@ -1344,7 +1344,7 @@
         return false;
 
     RenderImage* imageRenderer = toRenderImage(renderObject);
-    if (CachedImage* cachedImage = imageRenderer->cachedImage()) {
+    if (ImageResource* cachedImage = imageRenderer->cachedImage()) {
         if (!cachedImage->hasImage())
             return false;
 
@@ -1382,7 +1382,7 @@
     ASSERT(renderer()->isImage());
     RenderImage* imageRenderer = toRenderImage(renderer());
 
-    CachedImage* cachedImage = imageRenderer->cachedImage();
+    ImageResource* cachedImage = imageRenderer->cachedImage();
     if (!cachedImage)
         return;
 
diff --git a/Source/core/rendering/RenderLayerCompositor.cpp b/Source/core/rendering/RenderLayerCompositor.cpp
index 7073a4b..c8ea29d 100644
--- a/Source/core/rendering/RenderLayerCompositor.cpp
+++ b/Source/core/rendering/RenderLayerCompositor.cpp
@@ -471,9 +471,6 @@
 
 void RenderLayerCompositor::layerBecameNonComposited(const RenderLayer* renderLayer)
 {
-    // Inform the inspector that the given RenderLayer was destroyed.
-    InspectorInstrumentation::renderLayerDestroyed(page(), renderLayer);
-
     ASSERT(m_compositedLayerCount > 0);
     --m_compositedLayerCount;
 }
@@ -784,6 +781,14 @@
 
     // First accumulate the straightforward compositing reasons.
     CompositingReasons directReasons = directReasonsForCompositing(layer);
+
+    // Video is special. It's the only RenderLayer type that can both have
+    // RenderLayer children and whose children can't use its backing to render
+    // into. These children (the controls) always need to be promoted into their
+    // own layers to draw on top of the accelerated video.
+    if (compositingState.m_compositingAncestor && compositingState.m_compositingAncestor->renderer()->isVideo())
+        directReasons |= CompositingReasonLayerForVideoOverlay;
+
     if (canBeComposited(layer)) {
         reasonsToComposite |= directReasons;
         reasonsToComposite |= (inCompositingMode() && layer->isRootLayer()) ? CompositingReasonRoot : CompositingReasonNone;
@@ -808,13 +813,6 @@
         overlapCompositingReason = overlapMap->overlapsLayers(absBounds) ? CompositingReasonOverlap : CompositingReasonNone;
     }
 
-    // Video is special. It's the only RenderLayer type that can both have
-    // RenderLayer children and whose children can't use its backing to render
-    // into. These children (the controls) always need to be promoted into their
-    // own layers to draw on top of the accelerated video.
-    if (compositingState.m_compositingAncestor && compositingState.m_compositingAncestor->renderer()->isVideo())
-        overlapCompositingReason = CompositingReasonOverlap;
-
     reasonsToComposite |= overlapCompositingReason;
 
     // The children of this layer don't need to composite, unless there is
diff --git a/Source/core/rendering/RenderLayerFilterInfo.cpp b/Source/core/rendering/RenderLayerFilterInfo.cpp
index e10ff88..abad09d 100644
--- a/Source/core/rendering/RenderLayerFilterInfo.cpp
+++ b/Source/core/rendering/RenderLayerFilterInfo.cpp
@@ -31,8 +31,8 @@
 
 #include "core/rendering/RenderLayerFilterInfo.h"
 
-#include "core/loader/cache/CachedDocument.h"
-#include "core/loader/cache/CachedSVGDocumentReference.h"
+#include "core/loader/cache/DocumentResource.h"
+#include "core/loader/cache/DocumentResourceReference.h"
 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h"
 #include "core/platform/graphics/filters/custom/CustomFilterProgram.h"
 #include "core/rendering/FilterEffectRenderer.h"
@@ -119,8 +119,8 @@
         if (filterOperation->getOperationType() != FilterOperation::REFERENCE)
             continue;
         ReferenceFilterOperation* referenceFilterOperation = static_cast<ReferenceFilterOperation*>(filterOperation.get());
-        CachedSVGDocumentReference* documentReference = referenceFilterOperation->cachedSVGDocumentReference();
-        CachedDocument* cachedSVGDocument = documentReference ? documentReference->document() : 0;
+        DocumentResourceReference* documentReference = referenceFilterOperation->documentResourceReference();
+        DocumentResource* cachedSVGDocument = documentReference ? documentReference->document() : 0;
 
         if (cachedSVGDocument) {
             // Reference is external; wait for notifyFinished().
diff --git a/Source/core/rendering/RenderLayerFilterInfo.h b/Source/core/rendering/RenderLayerFilterInfo.h
index f7c3a22..ad29a02 100644
--- a/Source/core/rendering/RenderLayerFilterInfo.h
+++ b/Source/core/rendering/RenderLayerFilterInfo.h
@@ -31,7 +31,7 @@
 #define RenderLayerFilterInfo_h
 
 #include "core/dom/Element.h"
-#include "core/loader/cache/CachedDocument.h"
+#include "core/loader/cache/DocumentResource.h"
 #include "core/platform/graphics/LayoutRect.h"
 #include "core/platform/graphics/filters/FilterOperation.h"
 #include "core/platform/graphics/filters/custom/CustomFilterProgramClient.h"
@@ -48,7 +48,7 @@
 
 typedef HashMap<const RenderLayer*, RenderLayerFilterInfo*> RenderLayerFilterInfoMap;
 
-class RenderLayerFilterInfo : public CustomFilterProgramClient, public CachedDocumentClient {
+class RenderLayerFilterInfo : public CustomFilterProgramClient, public DocumentResourceClient {
 public:
     static RenderLayerFilterInfo* filterInfoForRenderLayer(const RenderLayer*);
     static RenderLayerFilterInfo* createFilterInfoForRenderLayerIfNeeded(RenderLayer*);
@@ -85,7 +85,7 @@
 
     static RenderLayerFilterInfoMap* s_filterMap;
     Vector<RefPtr<Element> > m_internalSVGReferences;
-    Vector<ResourcePtr<CachedDocument> > m_externalSVGReferences;
+    Vector<ResourcePtr<DocumentResource> > m_externalSVGReferences;
 };
 
 } // namespace WebCore
diff --git a/Source/core/rendering/RenderLayerModelObject.cpp b/Source/core/rendering/RenderLayerModelObject.cpp
index c5aecec..e0f8f77 100644
--- a/Source/core/rendering/RenderLayerModelObject.cpp
+++ b/Source/core/rendering/RenderLayerModelObject.cpp
@@ -145,7 +145,7 @@
     if (requiresLayer()) {
         if (!layer() && layerCreationAllowedForSubtree()) {
             if (s_wasFloating && isFloating())
-                setChildNeedsLayout(true);
+                setChildNeedsLayout();
             ensureLayer();
             if (parent() && !needsLayout() && containingBlock()) {
                 layer()->setRepaintStatus(NeedsFullRepaint);
@@ -159,7 +159,7 @@
         setHasReflection(false);
         layer()->removeOnlyThisLayer(); // calls destroyLayer() which clears m_layer
         if (s_wasFloating && isFloating())
-            setChildNeedsLayout(true);
+            setChildNeedsLayout();
         if (s_hadTransform)
             setNeedsLayoutAndPrefWidthsRecalc();
     }
@@ -167,7 +167,7 @@
     if (layer()) {
         layer()->styleChanged(diff, oldStyle);
         if (s_hadLayer && layer()->isSelfPaintingLayer() != s_layerWasSelfPainting)
-            setChildNeedsLayout(true);
+            setChildNeedsLayout();
     }
 
     if (FrameView *frameView = view()->frameView()) {
@@ -184,16 +184,20 @@
 
 void RenderLayerModelObject::addLayerHitTestRects(LayerHitTestRects& rects, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
 {
-    // If we have a new layer then our current layer/offset is irrelevant.
-    LayoutPoint adjustedLayerOffset = layerOffset;
-    LayoutRect adjustedContainerRect = containerRect;
     if (hasLayer()) {
-        currentLayer = layer();
-        adjustedLayerOffset = LayoutPoint();
-        adjustedContainerRect = LayoutRect();
+        if (isRenderView()) {
+            // RenderView is handled with a special fast-path, but it needs to know the current layer.
+            RenderObject::addLayerHitTestRects(rects, layer(), LayoutPoint(), LayoutRect());
+        } else {
+            // Since a RenderObject never lives outside it's container RenderLayer, we can switch
+            // to marking entire layers instead. This may sometimes mark more than necessary (when
+            // a layer is made of disjoint objects) but in practice is a significant performance
+            // savings.
+            layer()->addLayerHitTestRects(rects);
+        }
+    } else {
+        RenderObject::addLayerHitTestRects(rects, currentLayer, layerOffset, containerRect);
     }
-
-    RenderObject::addLayerHitTestRects(rects, currentLayer, adjustedLayerOffset, adjustedContainerRect);
 }
 
 } // namespace WebCore
diff --git a/Source/core/rendering/RenderLazyBlock.cpp b/Source/core/rendering/RenderLazyBlock.cpp
index 649c579..a43ab54 100644
--- a/Source/core/rendering/RenderLazyBlock.cpp
+++ b/Source/core/rendering/RenderLazyBlock.cpp
@@ -164,7 +164,7 @@
         updateBlockChildDirtyBitsBeforeLayout(relayoutChildren, child);
 
         if (relayoutChildren)
-            child->setNeedsLayout(true, MarkOnlyThis);
+            child->setNeedsLayout(MarkOnlyThis);
 
         if (child->style()->logicalHeight().isSpecified()) {
             LogicalExtentComputedValues computedValues;
@@ -245,7 +245,7 @@
     repainter.repaintAfterLayout();
 
     m_isNestedLayout = false;
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 } // namespace WebCore
diff --git a/Source/core/rendering/RenderLazyBlock.h b/Source/core/rendering/RenderLazyBlock.h
index 442aeb6..5f13f90 100644
--- a/Source/core/rendering/RenderLazyBlock.h
+++ b/Source/core/rendering/RenderLazyBlock.h
@@ -45,7 +45,7 @@
 
     void markForNestedLayout()
     {
-        setNeedsLayout(true);
+        setNeedsLayout();
         m_isNestedLayout = true;
     }
 
diff --git a/Source/core/rendering/RenderListBox.cpp b/Source/core/rendering/RenderListBox.cpp
index a2b87f8..4759684 100644
--- a/Source/core/rendering/RenderListBox.cpp
+++ b/Source/core/rendering/RenderListBox.cpp
@@ -727,7 +727,7 @@
 bool RenderListBox::isActive() const
 {
     Page* page = frame()->page();
-    return page && page->focusController()->isActive();
+    return page && page->focusController().isActive();
 }
 
 void RenderListBox::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
diff --git a/Source/core/rendering/RenderListItem.cpp b/Source/core/rendering/RenderListItem.cpp
index 0944508..918224a 100644
--- a/Source/core/rendering/RenderListItem.cpp
+++ b/Source/core/rendering/RenderListItem.cpp
@@ -392,16 +392,16 @@
             bool propagateLayoutOverflow = true;
             do {
                 o = o->parentBox();
-                if (o->hasOverflowClip())
-                    propagateVisualOverflow = false;
                 if (o->isRenderBlock()) {
                     if (propagateVisualOverflow)
-                        toRenderBlock(o)->addVisualOverflow(markerRect);
+                        toRenderBlock(o)->addContentsVisualOverflow(markerRect);
                     if (propagateLayoutOverflow)
                         toRenderBlock(o)->addLayoutOverflow(markerRect);
                 }
-                if (o->hasOverflowClip())
+                if (o->hasOverflowClip()) {
                     propagateLayoutOverflow = false;
+                    propagateVisualOverflow = false;
+                }
                 if (o->hasSelfPaintingLayer())
                     propagateVisualOverflow = false;
                 markerRect.moveBy(-o->location());
diff --git a/Source/core/rendering/RenderListMarker.cpp b/Source/core/rendering/RenderListMarker.cpp
index bc4aaad..d63728e 100644
--- a/Source/core/rendering/RenderListMarker.cpp
+++ b/Source/core/rendering/RenderListMarker.cpp
@@ -26,7 +26,7 @@
 #include "core/rendering/RenderListMarker.h"
 
 #include "core/dom/Document.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/platform/graphics/Font.h"
 #include "core/platform/graphics/GraphicsContextStateSaver.h"
 #include "core/rendering/RenderLayer.h"
@@ -1343,7 +1343,7 @@
     if (endMargin.isFixed())
         setMarginEnd(endMargin.value());
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderListMarker::imageChanged(WrappedImagePtr o, const IntRect*)
diff --git a/Source/core/rendering/RenderMarquee.cpp b/Source/core/rendering/RenderMarquee.cpp
index eed4b72..ecfff0d 100644
--- a/Source/core/rendering/RenderMarquee.cpp
+++ b/Source/core/rendering/RenderMarquee.cpp
@@ -269,7 +269,7 @@
     // Check the loop count to see if we should now stop.
     bool activate = (m_totalLoops <= 0 || m_currentLoop < m_totalLoops);
     if (activate && !m_timer.isActive())
-        setNeedsLayout(true);
+        setNeedsLayout();
     else if (!activate && m_timer.isActive())
         m_timer.stop();
 }
diff --git a/Source/core/rendering/RenderMedia.cpp b/Source/core/rendering/RenderMedia.cpp
index 48246c9..662cbeb 100644
--- a/Source/core/rendering/RenderMedia.cpp
+++ b/Source/core/rendering/RenderMedia.cpp
@@ -88,7 +88,7 @@
     controlsRenderer->style()->setHeight(Length(newSize.height(), Fixed));
     controlsRenderer->style()->setWidth(Length(newSize.width(), Fixed));
     controlsRenderer->forceLayout();
-    setChildNeedsLayout(false);
+    clearNeedsLayout();
 
     statePusher.pop();
 }
diff --git a/Source/core/rendering/RenderMultiColumnBlock.cpp b/Source/core/rendering/RenderMultiColumnBlock.cpp
index 8831a88..5ab8cb6 100644
--- a/Source/core/rendering/RenderMultiColumnBlock.cpp
+++ b/Source/core/rendering/RenderMultiColumnBlock.cpp
@@ -115,7 +115,7 @@
             if (childBox != m_flowThread && childBox->isRenderMultiColumnSet()) {
                 RenderMultiColumnSet* multicolSet = toRenderMultiColumnSet(childBox);
                 if (multicolSet->calculateBalancedHeight(firstPass)) {
-                    multicolSet->setChildNeedsLayout(true, MarkOnlyThis);
+                    multicolSet->setChildNeedsLayout(MarkOnlyThis);
                     needsRelayout = true;
                 }
             }
@@ -124,8 +124,8 @@
         if (needsRelayout) {
             // Layout again. Column balancing resulted in a new height.
             neededRelayout = true;
-            m_flowThread->setChildNeedsLayout(true, MarkOnlyThis);
-            setChildNeedsLayout(true, MarkOnlyThis);
+            m_flowThread->setChildNeedsLayout(MarkOnlyThis);
+            setChildNeedsLayout(MarkOnlyThis);
             if (firstPass)
                 statePusher.pop();
             layoutBlock(false);
@@ -170,7 +170,7 @@
         m_flowThread->invalidateRegions();
 
     if (relayoutChildren)
-        m_flowThread->setChildNeedsLayout(true, MarkOnlyThis);
+        m_flowThread->setChildNeedsLayout(MarkOnlyThis);
 
     setLogicalTopForChild(m_flowThread, borderBefore() + paddingBefore());
     m_flowThread->layoutIfNeeded();
diff --git a/Source/core/rendering/RenderNamedFlowThread.cpp b/Source/core/rendering/RenderNamedFlowThread.cpp
index 97774fb..bc72e9a 100644
--- a/Source/core/rendering/RenderNamedFlowThread.cpp
+++ b/Source/core/rendering/RenderNamedFlowThread.cpp
@@ -29,7 +29,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "bindings/v8/ExceptionStatePlaceholder.h"
 #include "core/dom/NamedFlow.h"
-#include "core/dom/NodeRenderingContext.h"
+#include "core/dom/NodeRenderingTraversal.h"
 #include "core/dom/NodeTraversal.h"
 #include "core/dom/Position.h"
 #include "core/dom/Range.h"
@@ -90,6 +90,18 @@
     m_contentNodes.clear();
 }
 
+void RenderNamedFlowThread::updateWritingMode()
+{
+    if (RenderRegion* firstRegion = m_regionList.first()) {
+        if (style()->writingMode() != firstRegion->style()->writingMode()) {
+            // The first region defines the principal writing mode for the entire flow.
+            RefPtr<RenderStyle> newStyle = RenderStyle::clone(style());
+            newStyle->setWritingMode(firstRegion->style()->writingMode());
+            setStyle(newStyle);
+        }
+    }
+}
+
 RenderObject* RenderNamedFlowThread::nextRendererForNode(Node* node) const
 {
     FlowThreadChildList::const_iterator it = m_flowThreadChildList.begin();
@@ -244,6 +256,9 @@
 
     renderRegion->setIsValid(true);
     addRegionToList(m_regionList, renderRegion);
+
+    if (m_regionList.first() == renderRegion)
+        updateWritingMode();
 }
 
 void RenderNamedFlowThread::addRegionToThread(RenderRegion* renderRegion)
@@ -283,6 +298,7 @@
     }
 
     ASSERT(m_regionList.contains(renderRegion));
+    bool wasFirst = m_regionList.first() == renderRegion;
     m_regionList.remove(renderRegion);
 
     if (canBeDestroyed())
@@ -291,10 +307,18 @@
     // After removing all the regions in the flow the following layout needs to dispatch the regionLayoutUpdate event
     if (m_regionList.isEmpty())
         setDispatchRegionLayoutUpdateEvent(true);
+    else if (wasFirst)
+        updateWritingMode();
 
     invalidateRegions();
 }
 
+void RenderNamedFlowThread::regionChangedWritingMode(RenderRegion* region)
+{
+    if (m_regionList.first() == region)
+        updateWritingMode();
+}
+
 void RenderNamedFlowThread::computeOversetStateForRegions(LayoutUnit oldClientAfterEdge)
 {
     LayoutUnit height = oldClientAfterEdge;
@@ -455,18 +479,15 @@
 
 bool RenderNamedFlowThread::isChildAllowed(RenderObject* child, RenderStyle* style) const
 {
-    ASSERT(child);
-    ASSERT(style);
-
     if (!child->node())
         return true;
 
     ASSERT(child->node()->isElementNode());
-    RenderObject* parentRenderer = NodeRenderingContext(child->node()).parentRenderer();
-    if (!parentRenderer)
+    Node* originalParent = NodeRenderingTraversal::parent(child->node());
+    if (!originalParent || !originalParent->renderer())
         return true;
 
-    return parentRenderer->isChildAllowed(child, style);
+    return originalParent->renderer()->isChildAllowed(child, style);
 }
 
 void RenderNamedFlowThread::dispatchRegionLayoutUpdateEvent()
diff --git a/Source/core/rendering/RenderNamedFlowThread.h b/Source/core/rendering/RenderNamedFlowThread.h
index 1e41f99..c0dec6c 100644
--- a/Source/core/rendering/RenderNamedFlowThread.h
+++ b/Source/core/rendering/RenderNamedFlowThread.h
@@ -68,6 +68,8 @@
     virtual void addRegionToThread(RenderRegion*) OVERRIDE;
     virtual void removeRegionFromThread(RenderRegion*) OVERRIDE;
 
+    virtual void regionChangedWritingMode(RenderRegion*) OVERRIDE;
+
     bool overset() const { return m_overset; }
     void computeOversetStateForRegions(LayoutUnit oldClientAfterEdge);
 
@@ -104,6 +106,7 @@
     void regionLayoutUpdateEventTimerFired(Timer<RenderNamedFlowThread>*);
     void regionOversetChangeEventTimerFired(Timer<RenderNamedFlowThread>*);
     void clearContentNodes();
+    void updateWritingMode();
 
 private:
     // Observer flow threads have invalid regions that depend on the state of this thread
diff --git a/Source/core/rendering/RenderObject.cpp b/Source/core/rendering/RenderObject.cpp
index eb5cacb..58bbf32 100644
--- a/Source/core/rendering/RenderObject.cpp
+++ b/Source/core/rendering/RenderObject.cpp
@@ -223,7 +223,7 @@
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, renderObjectCounter, ("RenderObject"));
 
 RenderObject::RenderObject(Node* node)
-    : CachedImageClient()
+    : ImageResourceClient()
     , m_style(0)
     , m_node(node)
     , m_parent(0)
@@ -2782,7 +2782,7 @@
         ASSERT(!child->needsLayout());
         child = child->nextSibling();
     }
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 // FIXME: Do we need this method at all? If setNeedsLayout early returns in all the right places,
@@ -2791,7 +2791,7 @@
 {
     // This is the only way it's safe to use MarkOnlyThis (i.e. if we're immediately going to call layout).
     // FIXME: Add asserts that we only ever do the MarkOnlyThis behavior from here.
-    setNeedsLayout(true, MarkOnlyThis);
+    setNeedsLayout(MarkOnlyThis);
     layout();
 }
 
@@ -2799,7 +2799,7 @@
 // I don't think it does and we should change all callers to use forceLayout.
 void RenderObject::forceChildLayout()
 {
-    setChildNeedsLayout(true, MarkOnlyThis);
+    setChildNeedsLayout(MarkOnlyThis);
     forceLayout();
 }
 
@@ -2994,7 +2994,7 @@
         curr->collectAnnotatedRegions(regions);
 }
 
-bool RenderObject::willRenderImage(CachedImage*)
+bool RenderObject::willRenderImage(ImageResource*)
 {
     // Without visibility we won't render (and therefore don't care about animation).
     if (style()->visibility() != VISIBLE)
@@ -3072,7 +3072,7 @@
     return parentNode && toElement(parentNode)->isInert();
 }
 
-void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
+void RenderObject::imageChanged(ImageResource* image, const IntRect* rect)
 {
     imageChanged(static_cast<WrappedImagePtr>(image), rect);
 }
diff --git a/Source/core/rendering/RenderObject.h b/Source/core/rendering/RenderObject.h
index c8dd232..4d34112 100644
--- a/Source/core/rendering/RenderObject.h
+++ b/Source/core/rendering/RenderObject.h
@@ -29,7 +29,7 @@
 #include "core/dom/DocumentStyleSheetCollection.h"
 #include "core/dom/Element.h"
 #include "core/dom/Position.h"
-#include "core/loader/cache/CachedImageClient.h"
+#include "core/loader/cache/ImageResourceClient.h"
 #include "core/platform/graphics/FloatQuad.h"
 #include "core/platform/graphics/LayoutRect.h"
 #include "core/platform/graphics/transforms/TransformationMatrix.h"
@@ -135,7 +135,7 @@
 #endif
 
 // Base class for all rendering tree objects.
-class RenderObject : public CachedImageClient {
+class RenderObject : public ImageResourceClient {
     friend class RenderBlock;
     friend class RenderLayer;
     friend class RenderObjectChildList;
@@ -406,7 +406,7 @@
             if (!s_ancestorLineboxDirtySet)
                 s_ancestorLineboxDirtySet = new RenderObjectAncestorLineboxDirtySet;
             s_ancestorLineboxDirtySet->add(this);
-            setNeedsLayout(true);
+            setNeedsLayout();
         } else if (s_ancestorLineboxDirtySet) {
             s_ancestorLineboxDirtySet->remove(this);
             if (s_ancestorLineboxDirtySet->isEmpty()) {
@@ -622,8 +622,9 @@
     Element* offsetParent() const;
 
     void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
-    void setNeedsLayout(bool needsLayout, MarkingBehavior = MarkContainingBlockChain);
-    void setChildNeedsLayout(bool childNeedsLayout, MarkingBehavior = MarkContainingBlockChain);
+    void setNeedsLayout(MarkingBehavior = MarkContainingBlockChain);
+    void clearNeedsLayout();
+    void setChildNeedsLayout(MarkingBehavior = MarkContainingBlockChain);
     void setNeedsPositionedMovementLayout();
     void setNeedsSimplifiedNormalFlowLayout();
     void setPreferredLogicalWidthsDirty(bool, MarkingBehavior = MarkContainingBlockChain);
@@ -631,7 +632,7 @@
 
     void setNeedsLayoutAndPrefWidthsRecalc()
     {
-        setNeedsLayout(true);
+        setNeedsLayout();
         setPreferredLogicalWidthsDirty(true);
     }
 
@@ -945,9 +946,9 @@
     virtual int previousOffsetForBackwardDeletion(int current) const;
     virtual int nextOffset(int current) const;
 
-    virtual void imageChanged(CachedImage*, const IntRect* = 0);
+    virtual void imageChanged(ImageResource*, const IntRect* = 0);
     virtual void imageChanged(WrappedImagePtr, const IntRect* = 0) { }
-    virtual bool willRenderImage(CachedImage*);
+    virtual bool willRenderImage(ImageResource*);
 
     void selectionStartEnd(int& spos, int& epos) const;
 
@@ -1196,6 +1197,7 @@
 
     RenderObjectBitfields m_bitfields;
 
+    // FIXME: These private methods are silly. We should just call m_bitfields.setXXX(b) directly.
     void setNeedsPositionedMovementLayout(bool b) { m_bitfields.setNeedsPositionedMovementLayout(b); }
     void setNormalChildNeedsLayout(bool b) { m_bitfields.setNormalChildNeedsLayout(b); }
     void setPosChildNeedsLayout(bool b) { m_bitfields.setPosChildNeedsLayout(b); }
@@ -1238,45 +1240,40 @@
     return isBeforeContent() || isAfterContent();
 }
 
-inline void RenderObject::setNeedsLayout(bool needsLayout, MarkingBehavior markParents)
+inline void RenderObject::setNeedsLayout(MarkingBehavior markParents)
 {
+    ASSERT(!isSetNeedsLayoutForbidden());
     bool alreadyNeededLayout = m_bitfields.needsLayout();
-    m_bitfields.setNeedsLayout(needsLayout);
-    if (needsLayout) {
-        ASSERT(!isSetNeedsLayoutForbidden());
-        if (!alreadyNeededLayout) {
-            if (markParents == MarkContainingBlockChain)
-                markContainingBlocksForLayout();
-            if (hasLayer())
-                setLayerNeedsFullRepaint();
-        }
-    } else {
-        setEverHadLayout(true);
-        setPosChildNeedsLayout(false);
-        setNeedsSimplifiedNormalFlowLayout(false);
-        setNormalChildNeedsLayout(false);
-        setNeedsPositionedMovementLayout(false);
-        setAncestorLineBoxDirty(false);
-#ifndef NDEBUG
-        checkBlockPositionedObjectsNeedLayout();
-#endif
+    m_bitfields.setNeedsLayout(true);
+    if (!alreadyNeededLayout) {
+        if (markParents == MarkContainingBlockChain)
+            markContainingBlocksForLayout();
+        if (hasLayer())
+            setLayerNeedsFullRepaint();
     }
 }
 
-inline void RenderObject::setChildNeedsLayout(bool childNeedsLayout, MarkingBehavior markParents)
+inline void RenderObject::clearNeedsLayout()
 {
+    m_bitfields.setNeedsLayout(false);
+    setEverHadLayout(true);
+    setPosChildNeedsLayout(false);
+    setNeedsSimplifiedNormalFlowLayout(false);
+    setNormalChildNeedsLayout(false);
+    setNeedsPositionedMovementLayout(false);
+    setAncestorLineBoxDirty(false);
+#ifndef NDEBUG
+    checkBlockPositionedObjectsNeedLayout();
+#endif
+}
+
+inline void RenderObject::setChildNeedsLayout(MarkingBehavior markParents)
+{
+    ASSERT(!isSetNeedsLayoutForbidden());
     bool alreadyNeededLayout = normalChildNeedsLayout();
-    setNormalChildNeedsLayout(childNeedsLayout);
-    if (childNeedsLayout) {
-        ASSERT(!isSetNeedsLayoutForbidden());
-        if (!alreadyNeededLayout && markParents == MarkContainingBlockChain)
-            markContainingBlocksForLayout();
-    } else {
-        setPosChildNeedsLayout(false);
-        setNeedsSimplifiedNormalFlowLayout(false);
-        setNormalChildNeedsLayout(false);
-        setNeedsPositionedMovementLayout(false);
-    }
+    setNormalChildNeedsLayout(true);
+    if (!alreadyNeededLayout && markParents == MarkContainingBlockChain)
+        markContainingBlocksForLayout();
 }
 
 inline void RenderObject::setNeedsPositionedMovementLayout()
diff --git a/Source/core/rendering/RenderObjectChildList.cpp b/Source/core/rendering/RenderObjectChildList.cpp
index e14404e..2f3b471 100644
--- a/Source/core/rendering/RenderObjectChildList.cpp
+++ b/Source/core/rendering/RenderObjectChildList.cpp
@@ -159,7 +159,7 @@
 
     newChild->setNeedsLayoutAndPrefWidthsRecalc();
     if (!owner->normalChildNeedsLayout())
-        owner->setChildNeedsLayout(true); // We may supply the static position for an absolute positioned child.
+        owner->setChildNeedsLayout(); // We may supply the static position for an absolute positioned child.
 
     if (AXObjectCache* cache = owner->document()->axObjectCache())
         cache->childrenChanged(owner);
diff --git a/Source/core/rendering/RenderOverflow.h b/Source/core/rendering/RenderOverflow.h
index d01d3ba..1c5417f 100644
--- a/Source/core/rendering/RenderOverflow.h
+++ b/Source/core/rendering/RenderOverflow.h
@@ -48,6 +48,7 @@
 
     const LayoutRect layoutOverflowRect() const { return m_layoutOverflow; }
     const LayoutRect visualOverflowRect() const { return m_visualOverflow; }
+    LayoutRect contentsVisualOverflowRect() const { return m_contentsVisualOverflow; }
 
     void setMinYLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setY(overflow); }
     void setMaxYLayoutOverflow(LayoutUnit overflow) { m_layoutOverflow.setHeight(overflow - m_layoutOverflow.y()); }
@@ -63,6 +64,7 @@
 
     void addLayoutOverflow(const LayoutRect&);
     void addVisualOverflow(const LayoutRect&);
+    void addContentsVisualOverflow(const LayoutRect& rect) { m_contentsVisualOverflow.unite(rect); }
 
     void setLayoutOverflow(const LayoutRect&);
     void setVisualOverflow(const LayoutRect&);
@@ -73,6 +75,7 @@
 private:
     LayoutRect m_layoutOverflow;
     LayoutRect m_visualOverflow;
+    LayoutRect m_contentsVisualOverflow;
 
     LayoutUnit m_layoutClientAfterEdge;
 };
@@ -81,6 +84,7 @@
 {
     m_layoutOverflow.move(dx, dy);
     m_visualOverflow.move(dx, dy);
+    m_contentsVisualOverflow.move(dx, dy);
 }
 
 inline void RenderOverflow::addLayoutOverflow(const LayoutRect& rect)
diff --git a/Source/core/rendering/RenderOverflowTest.cpp b/Source/core/rendering/RenderOverflowTest.cpp
new file mode 100644
index 0000000..0a5b7c3
--- /dev/null
+++ b/Source/core/rendering/RenderOverflowTest.cpp
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2013 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "core/rendering/RenderOverflow.h"
+
+#include "core/platform/graphics/LayoutRect.h"
+
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+
+namespace WebCore {
+
+// FIXME: Move this somewhere more generic.
+void PrintTo(const LayoutRect& rect, std::ostream* os)
+{
+    *os << "LayoutRect("
+        << rect.x().toFloat() << ", "
+        << rect.y().toFloat() << ", "
+        << rect.width().toFloat() << ", "
+        << rect.height().toFloat() << ")";
+}
+
+} // namespace WebCore
+
+namespace {
+
+LayoutRect initialLayoutOverflow()
+{
+    return LayoutRect(10, 10, 80, 80);
+}
+
+LayoutRect initialVisualOverflow()
+{
+    return LayoutRect(0, 0, 100, 100);
+}
+
+class RenderOverflowTest : public testing::Test {
+protected:
+    RenderOverflowTest() : m_overflow(initialLayoutOverflow(), initialVisualOverflow()) { }
+    RenderOverflow m_overflow;
+};
+
+TEST_F(RenderOverflowTest, InitialOverflowRects)
+{
+    EXPECT_EQ(initialLayoutOverflow(), m_overflow.layoutOverflowRect());
+    EXPECT_EQ(initialVisualOverflow(), m_overflow.visualOverflowRect());
+    EXPECT_TRUE(m_overflow.contentsVisualOverflowRect().isEmpty());
+}
+
+TEST_F(RenderOverflowTest, AddLayoutOverflowOutsideExpandsRect)
+{
+    m_overflow.addLayoutOverflow(LayoutRect(0, 10, 30, 10));
+    EXPECT_EQ(LayoutRect(0, 10, 90, 80), m_overflow.layoutOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddLayoutOverflowInsideDoesNotAffectRect)
+{
+    m_overflow.addLayoutOverflow(LayoutRect(50, 50, 10, 20));
+    EXPECT_EQ(initialLayoutOverflow(), m_overflow.layoutOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddLayoutOverflowEmpty)
+{
+    // This test documents the existing behavior so that we are aware when/if
+    // it changes. It would also be reasonable for addLayoutOverflow to be
+    // a no-op in this situation.
+    m_overflow.addLayoutOverflow(LayoutRect(200, 200, 0, 0));
+    EXPECT_EQ(LayoutRect(10, 10, 190, 190), m_overflow.layoutOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddLayoutOverflowDoesNotAffectVisualOverflow)
+{
+    m_overflow.addLayoutOverflow(LayoutRect(300, 300, 300, 300));
+    EXPECT_EQ(initialVisualOverflow(), m_overflow.visualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddLayoutOverflowDoesNotAffectContentsVisualOverflow)
+{
+    m_overflow.addLayoutOverflow(LayoutRect(300, 300, 300, 300));
+    EXPECT_TRUE(m_overflow.contentsVisualOverflowRect().isEmpty());
+}
+
+TEST_F(RenderOverflowTest, AddVisualOverflowOutsideExpandsRect)
+{
+    m_overflow.addVisualOverflow(LayoutRect(150, -50, 10, 10));
+    EXPECT_EQ(LayoutRect(0, -50, 160, 150), m_overflow.visualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddVisualOverflowInsideDoesNotAffectRect)
+{
+    m_overflow.addVisualOverflow(LayoutRect(0, 10, 90, 90));
+    EXPECT_EQ(initialVisualOverflow(), m_overflow.visualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddVisualOverflowEmpty)
+{
+    // This test documents the existing behavior so that we are aware when/if
+    // it changes. It would also be reasonable for addVisualOverflow to be
+    // a no-op in this situation.
+    m_overflow.addVisualOverflow(LayoutRect(200, 200, 0, 0));
+    EXPECT_EQ(LayoutRect(0, 0, 200, 200), m_overflow.visualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddVisualOverflowDoesNotAffectLayoutOverflow)
+{
+    m_overflow.addVisualOverflow(LayoutRect(300, 300, 300, 300));
+    EXPECT_EQ(initialLayoutOverflow(), m_overflow.layoutOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddVisualOverflowDoesNotAffectContentsVisualOverflow)
+{
+    m_overflow.addVisualOverflow(LayoutRect(300, 300, 300, 300));
+    EXPECT_TRUE(m_overflow.contentsVisualOverflowRect().isEmpty());
+}
+
+TEST_F(RenderOverflowTest, AddContentsVisualOverflowFirstCall)
+{
+    m_overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10));
+    EXPECT_EQ(LayoutRect(0, 0, 10, 10), m_overflow.contentsVisualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddContentsVisualOverflowUnitesRects)
+{
+    m_overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10));
+    m_overflow.addContentsVisualOverflow(LayoutRect(80, 80, 10, 10));
+    EXPECT_EQ(LayoutRect(0, 0, 90, 90), m_overflow.contentsVisualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddContentsVisualOverflowRectWithinRect)
+{
+    m_overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10));
+    m_overflow.addContentsVisualOverflow(LayoutRect(2, 2, 5, 5));
+    EXPECT_EQ(LayoutRect(0, 0, 10, 10), m_overflow.contentsVisualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, AddContentsVisualOverflowEmpty)
+{
+    // This test documents the existing behavior so that we are aware when/if
+    // it changes. It would also be reasonable for addContentsVisualOverflow to
+    // expand in this situation.
+    m_overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10));
+    m_overflow.addContentsVisualOverflow(LayoutRect(20, 20, 0, 0));
+    EXPECT_EQ(LayoutRect(0, 0, 10, 10), m_overflow.contentsVisualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, MoveAffectsLayoutOverflow)
+{
+    m_overflow.move(500, 100);
+    EXPECT_EQ(LayoutRect(510, 110, 80, 80), m_overflow.layoutOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, MoveAffectsVisualOverflow)
+{
+    m_overflow.move(500, 100);
+    EXPECT_EQ(LayoutRect(500, 100, 100, 100), m_overflow.visualOverflowRect());
+}
+
+TEST_F(RenderOverflowTest, MoveAffectsContentsVisualOverflow)
+{
+    m_overflow.addContentsVisualOverflow(LayoutRect(0, 0, 10, 10));
+    m_overflow.move(500, 100);
+    EXPECT_EQ(LayoutRect(500, 100, 10, 10), m_overflow.contentsVisualOverflowRect());
+}
+
+} // namespace
diff --git a/Source/core/rendering/RenderRegion.cpp b/Source/core/rendering/RenderRegion.cpp
index 203d207..1a739f8 100644
--- a/Source/core/rendering/RenderRegion.cpp
+++ b/Source/core/rendering/RenderRegion.cpp
@@ -270,6 +270,9 @@
 
     checkRegionStyle();
     updateRegionHasAutoLogicalHeightFlag();
+
+    if (oldStyle && oldStyle->writingMode() != style()->writingMode())
+        m_flowThread->regionChangedWritingMode(this);
 }
 
 void RenderRegion::layoutBlock(bool relayoutChildren, LayoutUnit)
diff --git a/Source/core/rendering/RenderReplaced.cpp b/Source/core/rendering/RenderReplaced.cpp
index ff3d191..8b229f4 100644
--- a/Source/core/rendering/RenderReplaced.cpp
+++ b/Source/core/rendering/RenderReplaced.cpp
@@ -91,7 +91,7 @@
     invalidateBackgroundObscurationStatus();
 
     repainter.repaintAfterLayout();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderReplaced::intrinsicSizeChanged()
diff --git a/Source/core/rendering/RenderReplica.cpp b/Source/core/rendering/RenderReplica.cpp
index 3c6e78d..3328ad9 100644
--- a/Source/core/rendering/RenderReplica.cpp
+++ b/Source/core/rendering/RenderReplica.cpp
@@ -59,7 +59,7 @@
     StackStats::LayoutCheckPoint layoutCheckPoint;
     setFrameRect(parentBox()->borderBoxRect());
     updateLayerTransform();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderReplica::computePreferredLogicalWidths()
diff --git a/Source/core/rendering/RenderRubyRun.cpp b/Source/core/rendering/RenderRubyRun.cpp
index 80b4cbd..a0d3c10 100644
--- a/Source/core/rendering/RenderRubyRun.cpp
+++ b/Source/core/rendering/RenderRubyRun.cpp
@@ -222,7 +222,7 @@
     if (!rt)
         return 0;
     if (relayoutChildren)
-        rt->setChildNeedsLayout(true, MarkOnlyThis);
+        rt->setChildNeedsLayout(MarkOnlyThis);
     rt->layoutIfNeeded();
     return rt;
 }
diff --git a/Source/core/rendering/RenderScrollbar.cpp b/Source/core/rendering/RenderScrollbar.cpp
index 1f39c36..9612040 100644
--- a/Source/core/rendering/RenderScrollbar.cpp
+++ b/Source/core/rendering/RenderScrollbar.cpp
@@ -189,7 +189,7 @@
     if (newThickness != oldThickness) {
         setFrameRect(IntRect(location(), IntSize(isHorizontal ? width() : newThickness, isHorizontal ? newThickness : height())));
         if (RenderBox* box = owningRenderer())
-            box->setChildNeedsLayout(true);
+            box->setChildNeedsLayout();
     }
 }
 
diff --git a/Source/core/rendering/RenderScrollbarPart.cpp b/Source/core/rendering/RenderScrollbarPart.cpp
index 5d1dac3..45878a8 100644
--- a/Source/core/rendering/RenderScrollbarPart.cpp
+++ b/Source/core/rendering/RenderScrollbarPart.cpp
@@ -62,7 +62,7 @@
     else
         layoutVerticalPart();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderScrollbarPart::layoutHorizontalPart()
diff --git a/Source/core/rendering/RenderScrollbarTheme.h b/Source/core/rendering/RenderScrollbarTheme.h
index d718f5f..8da44cd 100644
--- a/Source/core/rendering/RenderScrollbarTheme.h
+++ b/Source/core/rendering/RenderScrollbarTheme.h
@@ -26,7 +26,7 @@
 #ifndef RenderScrollbarTheme_h
 #define RenderScrollbarTheme_h
 
-#include "core/platform/ScrollbarThemeComposite.h"
+#include "core/platform/ScrollbarTheme.h"
 
 namespace WebCore {
 
@@ -34,48 +34,48 @@
 class Scrollbar;
 class ScrollView;
 
-class RenderScrollbarTheme : public ScrollbarThemeComposite {
+class RenderScrollbarTheme : public ScrollbarTheme {
 public:
-    virtual ~RenderScrollbarTheme() {};
+    virtual ~RenderScrollbarTheme() { }
 
-    virtual int scrollbarThickness(ScrollbarControlSize controlSize) { return ScrollbarTheme::theme()->scrollbarThickness(controlSize); }
+    virtual int scrollbarThickness(ScrollbarControlSize controlSize) OVERRIDE { return ScrollbarTheme::theme()->scrollbarThickness(controlSize); }
 
-    virtual ScrollbarButtonsPlacement buttonsPlacement() const { return ScrollbarTheme::theme()->buttonsPlacement(); }
+    virtual ScrollbarButtonsPlacement buttonsPlacement() const OVERRIDE { return ScrollbarTheme::theme()->buttonsPlacement(); }
 
-    virtual bool supportsControlTints() const { return true; }
+    virtual bool supportsControlTints() const OVERRIDE { return true; }
 
-    virtual void paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect);
+    virtual void paintScrollCorner(ScrollView*, GraphicsContext*, const IntRect& cornerRect) OVERRIDE;
 
-    virtual bool shouldCenterOnThumb(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& event) { return ScrollbarTheme::theme()->shouldCenterOnThumb(scrollbar, event); }
+    virtual bool shouldCenterOnThumb(ScrollbarThemeClient* scrollbar, const PlatformMouseEvent& event) OVERRIDE { return ScrollbarTheme::theme()->shouldCenterOnThumb(scrollbar, event); }
 
-    virtual double initialAutoscrollTimerDelay() { return ScrollbarTheme::theme()->initialAutoscrollTimerDelay(); }
-    virtual double autoscrollTimerDelay() { return ScrollbarTheme::theme()->autoscrollTimerDelay(); }
+    virtual double initialAutoscrollTimerDelay() OVERRIDE { return ScrollbarTheme::theme()->initialAutoscrollTimerDelay(); }
+    virtual double autoscrollTimerDelay() OVERRIDE { return ScrollbarTheme::theme()->autoscrollTimerDelay(); }
 
-    virtual void registerScrollbar(ScrollbarThemeClient* scrollbar) { return ScrollbarTheme::theme()->registerScrollbar(scrollbar); }
-    virtual void unregisterScrollbar(ScrollbarThemeClient* scrollbar) { return ScrollbarTheme::theme()->unregisterScrollbar(scrollbar); }
+    virtual void registerScrollbar(ScrollbarThemeClient* scrollbar) OVERRIDE { return ScrollbarTheme::theme()->registerScrollbar(scrollbar); }
+    virtual void unregisterScrollbar(ScrollbarThemeClient* scrollbar) OVERRIDE { return ScrollbarTheme::theme()->unregisterScrollbar(scrollbar); }
 
-    virtual int minimumThumbLength(ScrollbarThemeClient*);
+    virtual int minimumThumbLength(ScrollbarThemeClient*) OVERRIDE;
 
     void buttonSizesAlongTrackAxis(ScrollbarThemeClient*, int& beforeSize, int& afterSize);
 
     static RenderScrollbarTheme* renderScrollbarTheme();
 
 protected:
-    virtual bool hasButtons(ScrollbarThemeClient*);
-    virtual bool hasThumb(ScrollbarThemeClient*);
+    virtual bool hasButtons(ScrollbarThemeClient*) OVERRIDE;
+    virtual bool hasThumb(ScrollbarThemeClient*) OVERRIDE;
 
-    virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false);
-    virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false);
-    virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false);
+    virtual IntRect backButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) OVERRIDE;
+    virtual IntRect forwardButtonRect(ScrollbarThemeClient*, ScrollbarPart, bool painting = false) OVERRIDE;
+    virtual IntRect trackRect(ScrollbarThemeClient*, bool painting = false) OVERRIDE;
 
-    virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*);
-    virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&);
-    virtual void paintTrackPiece(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart);
-    virtual void paintButton(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart);
-    virtual void paintThumb(GraphicsContext*, ScrollbarThemeClient*, const IntRect&);
+    virtual void paintScrollbarBackground(GraphicsContext*, ScrollbarThemeClient*) OVERRIDE;
+    virtual void paintTrackBackground(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) OVERRIDE;
+    virtual void paintTrackPiece(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) OVERRIDE;
+    virtual void paintButton(GraphicsContext*, ScrollbarThemeClient*, const IntRect&, ScrollbarPart) OVERRIDE;
+    virtual void paintThumb(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) OVERRIDE;
     virtual void paintTickmarks(GraphicsContext*, ScrollbarThemeClient*, const IntRect&) OVERRIDE;
 
-    virtual IntRect constrainTrackRectToTrackPieces(ScrollbarThemeClient*, const IntRect&);
+    virtual IntRect constrainTrackRectToTrackPieces(ScrollbarThemeClient*, const IntRect&) OVERRIDE;
 };
 
 } // namespace WebCore
diff --git a/Source/core/rendering/RenderSearchField.cpp b/Source/core/rendering/RenderSearchField.cpp
index 11ee314..4e4244c 100644
--- a/Source/core/rendering/RenderSearchField.cpp
+++ b/Source/core/rendering/RenderSearchField.cpp
@@ -25,6 +25,7 @@
 #include "core/rendering/RenderSearchField.h"
 
 #include "core/html/HTMLInputElement.h"
+#include "core/html/shadow/ShadowElementNames.h"
 
 using namespace std;
 
@@ -44,25 +45,25 @@
 {
 }
 
-inline HTMLElement* RenderSearchField::searchDecorationElement() const
+inline Element* RenderSearchField::searchDecorationElement() const
 {
-    return inputElement()->searchDecorationElement();
+    return inputElement()->uaShadowElementById(ShadowElementNames::searchDecoration());
 }
 
-inline HTMLElement* RenderSearchField::cancelButtonElement() const
+inline Element* RenderSearchField::cancelButtonElement() const
 {
-    return inputElement()->cancelButtonElement();
+    return inputElement()->uaShadowElementById(ShadowElementNames::clearButton());
 }
 
 LayoutUnit RenderSearchField::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const
 {
-    HTMLElement* searchDecoration = searchDecorationElement();
+    Element* searchDecoration = searchDecorationElement();
     if (RenderBox* decorationRenderer = searchDecoration ? searchDecoration->renderBox() : 0) {
         decorationRenderer->updateLogicalHeight();
         nonContentHeight = max(nonContentHeight, decorationRenderer->borderAndPaddingLogicalHeight() + decorationRenderer->marginLogicalHeight());
         lineHeight = max(lineHeight, decorationRenderer->logicalHeight());
     }
-    HTMLElement* cancelButton = cancelButtonElement();
+    Element* cancelButton = cancelButtonElement();
     if (RenderBox* cancelRenderer = cancelButton ? cancelButton->renderBox() : 0) {
         cancelRenderer->updateLogicalHeight();
         nonContentHeight = max(nonContentHeight, cancelRenderer->borderAndPaddingLogicalHeight() + cancelRenderer->marginLogicalHeight());
diff --git a/Source/core/rendering/RenderSearchField.h b/Source/core/rendering/RenderSearchField.h
index c793ab1..d8617ae 100644
--- a/Source/core/rendering/RenderSearchField.h
+++ b/Source/core/rendering/RenderSearchField.h
@@ -45,8 +45,8 @@
     virtual void updateFromElement() OVERRIDE;
     EVisibility visibilityForCancelButton() const;
 
-    HTMLElement* searchDecorationElement() const;
-    HTMLElement* cancelButtonElement() const;
+    Element* searchDecorationElement() const;
+    Element* cancelButtonElement() const;
 };
 
 inline RenderSearchField* toRenderSearchField(RenderObject* object)
diff --git a/Source/core/rendering/RenderTable.cpp b/Source/core/rendering/RenderTable.cpp
index f086f2a..12ea553 100644
--- a/Source/core/rendering/RenderTable.cpp
+++ b/Source/core/rendering/RenderTable.cpp
@@ -424,7 +424,7 @@
 
     if (logicalWidth() != oldLogicalWidth) {
         for (unsigned i = 0; i < m_captions.size(); i++)
-            m_captions[i]->setNeedsLayout(true, MarkOnlyThis);
+            m_captions[i]->setNeedsLayout(MarkOnlyThis);
     }
     // FIXME: The optimisation below doesn't work since the internal table
     // layout could have changed.  we need to add a flag to the table
@@ -444,7 +444,7 @@
         if (child->isTableSection()) {
             RenderTableSection* section = toRenderTableSection(child);
             if (m_columnLogicalWidthChanged)
-                section->setChildNeedsLayout(true, MarkOnlyThis);
+                section->setChildNeedsLayout(MarkOnlyThis);
             section->layoutIfNeeded();
             totalSectionLogicalHeight += section->calcRowLogicalHeight();
             if (collapsing)
@@ -566,7 +566,7 @@
     }
 
     m_columnLogicalWidthChanged = false;
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 // Collect all the unique border values that we want to paint in a sorted list.
@@ -637,7 +637,7 @@
             return;
     }
 
-    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset);
+    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset, ForceContentsClip);
     paintObject(paintInfo, adjustedPaintOffset);
     if (pushedClip)
         popContentsClip(paintInfo, paintPhase, adjustedPaintOffset);
diff --git a/Source/core/rendering/RenderTable.h b/Source/core/rendering/RenderTable.h
index d18b649..bdc1a3d 100644
--- a/Source/core/rendering/RenderTable.h
+++ b/Source/core/rendering/RenderTable.h
@@ -221,7 +221,7 @@
         if (documentBeingDestroyed())
             return;
         m_needsSectionRecalc = true;
-        setNeedsLayout(true);
+        setNeedsLayout();
     }
 
     RenderTableSection* sectionAbove(const RenderTableSection*, SkipEmptySectionsValue = DoNotSkipEmptySections) const;
diff --git a/Source/core/rendering/RenderTableCell.cpp b/Source/core/rendering/RenderTableCell.cpp
index 44316f7..b67203d 100644
--- a/Source/core/rendering/RenderTableCell.cpp
+++ b/Source/core/rendering/RenderTableCell.cpp
@@ -200,7 +200,7 @@
     // FIXME: Changing an intrinsic padding shouldn't trigger a relayout as it only shifts the cell inside the row but
     // doesn't change the logical height.
     if (intrinsicPaddingBefore != oldIntrinsicPaddingBefore || intrinsicPaddingAfter != oldIntrinsicPaddingAfter)
-        setNeedsLayout(true, MarkOnlyThis);
+        setNeedsLayout(MarkOnlyThis);
 }
 
 void RenderTableCell::updateLogicalWidth()
@@ -212,8 +212,8 @@
     if (tableLayoutLogicalWidth == logicalWidth())
         return;
 
-    setNeedsLayout(true, MarkOnlyThis);
-    row()->setChildNeedsLayout(true, MarkOnlyThis);
+    setNeedsLayout(MarkOnlyThis);
+    row()->setChildNeedsLayout(MarkOnlyThis);
 
     if (!table()->selfNeedsLayout() && checkForRepaintDuringLayout())
         repaint();
@@ -237,7 +237,7 @@
     if (isBaselineAligned() && section()->rowBaseline(rowIndex()) && cellBaselinePosition() > section()->rowBaseline(rowIndex())) {
         int newIntrinsicPaddingBefore = max<LayoutUnit>(0, intrinsicPaddingBefore() - max<LayoutUnit>(0, cellBaselinePosition() - oldCellBaseline));
         setIntrinsicPaddingBefore(newIntrinsicPaddingBefore);
-        setNeedsLayout(true, MarkOnlyThis);
+        setNeedsLayout(MarkOnlyThis);
         layoutBlock(cellWidthChanged());
     }
 
diff --git a/Source/core/rendering/RenderTableCol.cpp b/Source/core/rendering/RenderTableCol.cpp
index 533cf48..ce0dd03 100644
--- a/Source/core/rendering/RenderTableCol.cpp
+++ b/Source/core/rendering/RenderTableCol.cpp
@@ -28,7 +28,7 @@
 
 #include "HTMLNames.h"
 #include "core/html/HTMLTableColElement.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/rendering/RenderTable.h"
 #include "core/rendering/RenderTableCell.h"
 
diff --git a/Source/core/rendering/RenderTableRow.cpp b/Source/core/rendering/RenderTableRow.cpp
index f6831b2..3fae922 100644
--- a/Source/core/rendering/RenderTableRow.cpp
+++ b/Source/core/rendering/RenderTableRow.cpp
@@ -27,7 +27,7 @@
 
 #include "HTMLNames.h"
 #include "core/dom/Document.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/rendering/HitTestResult.h"
 #include "core/rendering/PaintInfo.h"
 #include "core/rendering/RenderTableCell.h"
@@ -84,7 +84,7 @@
             for (RenderBox* childBox = firstChildBox(); childBox; childBox = childBox->nextSiblingBox()) {
                 if (!childBox->isTableCell())
                     continue;
-                childBox->setChildNeedsLayout(true, MarkOnlyThis);
+                childBox->setChildNeedsLayout(MarkOnlyThis);
             }
         }
     }
@@ -167,7 +167,7 @@
         if (child->isTableCell()) {
             RenderTableCell* cell = toRenderTableCell(child);
             if (!cell->needsLayout() && paginated && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
-                cell->setChildNeedsLayout(true, MarkOnlyThis);
+                cell->setChildNeedsLayout(MarkOnlyThis);
 
             if (child->needsLayout()) {
                 cell->computeAndSetBlockDirectionMargins(table());
@@ -190,7 +190,7 @@
 
     statePusher.pop();
     // RenderTableSection::layoutRows will set our logical height and width later, so it calls updateLayerTransform().
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 LayoutRect RenderTableRow::clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const
diff --git a/Source/core/rendering/RenderTableSection.cpp b/Source/core/rendering/RenderTableSection.cpp
index 282e7fa..80938cc 100644
--- a/Source/core/rendering/RenderTableSection.cpp
+++ b/Source/core/rendering/RenderTableSection.cpp
@@ -406,15 +406,24 @@
 
         unsigned rowSpan = cell->rowSpan();
 
+        unsigned spanningCellEndIndex = rowIndex + rowSpan;
+        unsigned lastSpanningCellEndIndex = lastRowIndex + lastRowSpan;
+
         // Only heightest spanning cell will distribute it's extra height in row if more then one spanning cells
         // present at same level.
         if (rowIndex == lastRowIndex && rowSpan == lastRowSpan)
             continue;
 
-        int originalBeforePosition = m_rowPos[rowIndex + rowSpan];
+        int originalBeforePosition = m_rowPos[spanningCellEndIndex];
+
+        // When 2 spanning cells are ending at same row index then while extra height distribution of first spanning
+        // cell updates position of the last row so getting the original position of the last row in second spanning
+        // cell need to reduce the height changed by first spanning cell.
+        if (spanningCellEndIndex == lastSpanningCellEndIndex)
+            originalBeforePosition -= extraHeightToPropagate;
 
         if (extraHeightToPropagate) {
-            for (unsigned row = lastRowIndex + lastRowSpan; row <= rowIndex + rowSpan; row++)
+            for (unsigned row = lastSpanningCellEndIndex + 1; row <= spanningCellEndIndex; row++)
                 m_rowPos[row] += extraHeightToPropagate;
         }
 
@@ -436,7 +445,7 @@
         // is distributing it's extra height in rows.
 
         // Calculate total percentage, total auto rows height and total rows height except percent rows.
-        for (unsigned row = rowIndex; row < (rowIndex + rowSpan); row++) {
+        for (unsigned row = rowIndex; row < spanningCellEndIndex; row++) {
             if (m_grid[row].logicalHeight.isPercent()) {
                 totalPercent += m_grid[row].logicalHeight.percent();
                 totalRemainingRowsHeight -= spanningRowsHeight.rowHeight[row - rowIndex];
@@ -454,13 +463,12 @@
         ASSERT(!extraRowSpanningHeight);
 
         // Getting total changed height in the table
-        extraHeightToPropagate = m_rowPos[rowIndex + rowSpan] - originalBeforePosition;
-        m_rowPos[rowIndex + rowSpan] -= extraHeightToPropagate;
+        extraHeightToPropagate = m_rowPos[spanningCellEndIndex] - originalBeforePosition;
     }
 
     if (extraHeightToPropagate) {
         // Apply changed height by rowSpan cells to rows present at the end of the table
-        for (unsigned row = lastRowIndex + lastRowSpan; row <= m_grid.size(); row++)
+        for (unsigned row = lastRowIndex + lastRowSpan + 1; row <= m_grid.size(); row++)
             m_rowPos[row] += extraHeightToPropagate;
     }
 }
@@ -473,13 +481,15 @@
     if (!cell->isBaselineAligned())
         return;
 
-    LayoutUnit baselinePosition = cell->cellBaselinePosition();
-    if (baselinePosition > cell->borderBefore() + cell->paddingBefore()) {
+    // Ignoring the intrinsic padding as it depends on knowing the row's baseline, which won't be accurate
+    // until the end of this function.
+    LayoutUnit baselinePosition = cell->cellBaselinePosition() - cell->intrinsicPaddingBefore();
+    if (baselinePosition > cell->borderBefore() + (cell->paddingBefore() - cell->intrinsicPaddingBefore())) {
         m_grid[row].baseline = max(m_grid[row].baseline, baselinePosition);
 
         int cellStartRowBaselineDescent = 0;
         if (cell->rowSpan() == 1) {
-            baselineDescent = max(baselineDescent, cell->logicalHeightForRowSizing() - (baselinePosition - cell->intrinsicPaddingBefore()));
+            baselineDescent = max(baselineDescent, cell->logicalHeightForRowSizing() - baselinePosition);
             cellStartRowBaselineDescent = baselineDescent;
         }
         m_rowPos[row + 1] = max<int>(m_rowPos[row + 1], m_rowPos[row] + m_grid[row].baseline + cellStartRowBaselineDescent);
@@ -629,7 +639,7 @@
     }
 
     statePusher.pop();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderTableSection::distributeExtraLogicalHeightToPercentRows(int& extraLogicalHeight, int totalPercent)
@@ -789,7 +799,7 @@
                 if (!o->isText() && o->style()->logicalHeight().isPercent() && (flexAllChildren || o->isReplaced() || (o->isBox() && toRenderBox(o)->scrollsOverflow()))) {
                     // Tables with no sections do not flex.
                     if (!o->isTable() || toRenderTable(o)->hasSections()) {
-                        o->setNeedsLayout(true, MarkOnlyThis);
+                        o->setNeedsLayout(MarkOnlyThis);
                         cellChildrenFlex = true;
                     }
                 }
@@ -805,7 +815,7 @@
                     while (box != cell) {
                         if (box->normalChildNeedsLayout())
                             break;
-                        box->setChildNeedsLayout(true, MarkOnlyThis);
+                        box->setChildNeedsLayout(MarkOnlyThis);
                         box = box->containingBlock();
                         ASSERT(box);
                         if (!box)
@@ -837,7 +847,7 @@
             setLogicalPositionForCell(cell, c);
 
             if (!cell->needsLayout() && view()->layoutState()->pageLogicalHeight() && view()->layoutState()->pageLogicalOffset(cell, cell->logicalTop()) != cell->pageLogicalOffset())
-                cell->setChildNeedsLayout(true, MarkOnlyThis);
+                cell->setChildNeedsLayout(MarkOnlyThis);
 
             cell->layoutIfNeeded();
 
@@ -1164,7 +1174,7 @@
     LayoutPoint adjustedPaintOffset = paintOffset + location();
 
     PaintPhase phase = paintInfo.phase;
-    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset);
+    bool pushedClip = pushContentsClip(paintInfo, adjustedPaintOffset, ForceContentsClip);
     paintObject(paintInfo, adjustedPaintOffset);
     if (pushedClip)
         popContentsClip(paintInfo, phase, adjustedPaintOffset);
@@ -1466,7 +1476,7 @@
     }
 
     m_grid.shrinkToFit();
-    setNeedsLayout(true);
+    setNeedsLayout();
 }
 
 // FIXME: This function could be made O(1) in certain cases (like for the non-most-constrainive cells' case).
diff --git a/Source/core/rendering/RenderText.cpp b/Source/core/rendering/RenderText.cpp
index 94a73bf..56135c0 100644
--- a/Source/core/rendering/RenderText.cpp
+++ b/Source/core/rendering/RenderText.cpp
@@ -41,6 +41,7 @@
 #include "core/rendering/RenderView.h"
 #include "core/rendering/break_lines.h"
 #include "wtf/text/StringBuffer.h"
+#include "wtf/text/StringBuilder.h"
 #include "wtf/unicode/CharacterNames.h"
 
 using namespace std;
diff --git a/Source/core/rendering/RenderTextControl.cpp b/Source/core/rendering/RenderTextControl.cpp
index 5ca4fd8..aaac50e 100644
--- a/Source/core/rendering/RenderTextControl.cpp
+++ b/Source/core/rendering/RenderTextControl.cpp
@@ -283,7 +283,7 @@
         // The markParents arguments should be false because this function is
         // called from layout() of the parent and the placeholder layout doesn't
         // affect the parent layout.
-        placeholderRenderer->setChildNeedsLayout(true, MarkOnlyThis);
+        placeholderRenderer->setChildNeedsLayout(MarkOnlyThis);
     }
     return placeholderRenderer;
 }
diff --git a/Source/core/rendering/RenderTextControlSingleLine.cpp b/Source/core/rendering/RenderTextControlSingleLine.cpp
index de649d4..08b9501 100644
--- a/Source/core/rendering/RenderTextControlSingleLine.cpp
+++ b/Source/core/rendering/RenderTextControlSingleLine.cpp
@@ -92,7 +92,7 @@
     ASSERT(start);
     ASSERT(start != end);
     for (RenderObject* renderer = start; renderer != end; renderer = renderer->parent())
-        renderer->setNeedsLayout(true, MarkOnlyThis);
+        renderer->setNeedsLayout(MarkOnlyThis);
 }
 
 void RenderTextControlSingleLine::layout()
@@ -133,15 +133,15 @@
     LayoutUnit logicalHeightLimit = computeLogicalHeightLimit();
     if (innerTextRenderer && innerTextRenderer->logicalHeight() > logicalHeightLimit) {
         if (desiredLogicalHeight != innerTextRenderer->logicalHeight())
-            setNeedsLayout(true, MarkOnlyThis);
+            setNeedsLayout(MarkOnlyThis);
 
         m_desiredInnerTextLogicalHeight = desiredLogicalHeight;
 
         innerTextRenderer->style()->setLogicalHeight(Length(desiredLogicalHeight, Fixed));
-        innerTextRenderer->setNeedsLayout(true, MarkOnlyThis);
+        innerTextRenderer->setNeedsLayout(MarkOnlyThis);
         if (innerBlockRenderer) {
             innerBlockRenderer->style()->setLogicalHeight(Length(desiredLogicalHeight, Fixed));
-            innerBlockRenderer->setNeedsLayout(true, MarkOnlyThis);
+            innerBlockRenderer->setNeedsLayout(MarkOnlyThis);
         }
     }
     // The container might be taller because of decoration elements.
@@ -150,10 +150,10 @@
         LayoutUnit containerLogicalHeight = containerRenderer->logicalHeight();
         if (containerLogicalHeight > logicalHeightLimit) {
             containerRenderer->style()->setLogicalHeight(Length(logicalHeightLimit, Fixed));
-            setNeedsLayout(true, MarkOnlyThis);
+            setNeedsLayout(MarkOnlyThis);
         } else if (containerRenderer->logicalHeight() < contentLogicalHeight()) {
             containerRenderer->style()->setLogicalHeight(Length(contentLogicalHeight(), Fixed));
-            setNeedsLayout(true, MarkOnlyThis);
+            setNeedsLayout(MarkOnlyThis);
         } else
             containerRenderer->style()->setLogicalHeight(Length(containerLogicalHeight, Fixed));
     }
@@ -252,7 +252,7 @@
     }
     RenderObject* innerTextRenderer = innerTextElement()->renderer();
     if (innerTextRenderer && diff == StyleDifferenceLayout)
-        innerTextRenderer->setNeedsLayout(true, MarkContainingBlockChain);
+        innerTextRenderer->setNeedsLayout(MarkContainingBlockChain);
     if (HTMLElement* placeholder = inputElement()->placeholderElement())
         placeholder->setInlineStyleProperty(CSSPropertyTextOverflow, textShouldBeTruncated() ? CSSValueEllipsis : CSSValueClip);
     setHasOverflowClip(false);
diff --git a/Source/core/rendering/RenderTheme.cpp b/Source/core/rendering/RenderTheme.cpp
index 0150f98..0e4903c 100644
--- a/Source/core/rendering/RenderTheme.cpp
+++ b/Source/core/rendering/RenderTheme.cpp
@@ -802,15 +802,11 @@
     if (!node)
         return false;
 
-    Frame* frame = node->document()->frame();
-    if (!frame)
-        return false;
-
-    Page* page = frame->page();
+    Page* page = node->document()->page();
     if (!page)
         return false;
 
-    return page->focusController()->isActive();
+    return page->focusController().isActive();
 }
 
 bool RenderTheme::isChecked(const RenderObject* o) const
diff --git a/Source/core/rendering/RenderThemeChromiumFontProvider.cpp b/Source/core/rendering/RenderThemeChromiumFontProvider.cpp
index 81623a2..527f855 100644
--- a/Source/core/rendering/RenderThemeChromiumFontProvider.cpp
+++ b/Source/core/rendering/RenderThemeChromiumFontProvider.cpp
@@ -48,7 +48,7 @@
 // sizes (e.g. 15px). So, for now we just use Arial.
 const String& RenderThemeChromiumFontProvider::defaultGUIFont()
 {
-    DEFINE_STATIC_LOCAL(String, fontFace, (ASCIILiteral("Arial")));
+    DEFINE_STATIC_LOCAL(String, fontFace, ("Arial"));
     return fontFace;
 }
 
diff --git a/Source/core/rendering/RenderVideo.cpp b/Source/core/rendering/RenderVideo.cpp
index 580bbf3..62e8ac2 100644
--- a/Source/core/rendering/RenderVideo.cpp
+++ b/Source/core/rendering/RenderVideo.cpp
@@ -81,7 +81,7 @@
 
     setIntrinsicSize(size);
     setPreferredLogicalWidthsDirty(true);
-    setNeedsLayout(true);
+    setNeedsLayout();
 }
 
 LayoutSize RenderVideo::calculateIntrinsicSize()
diff --git a/Source/core/rendering/RenderView.cpp b/Source/core/rendering/RenderView.cpp
index 12b102b..b71d4fe 100644
--- a/Source/core/rendering/RenderView.cpp
+++ b/Source/core/rendering/RenderView.cpp
@@ -119,7 +119,7 @@
 void RenderView::markLazyBlocksForLayout()
 {
     for (RenderLazyBlock* block = m_firstLazyBlock; block; block = block->next())
-        block->setNeedsLayout(true);
+        block->setNeedsLayout();
 }
 
 void RenderView::layoutContent(const LayoutState& state)
@@ -260,7 +260,7 @@
     // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
     bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
     if (relayoutChildren) {
-        setChildNeedsLayout(true, MarkOnlyThis);
+        setChildNeedsLayout(MarkOnlyThis);
         for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
             if ((child->isBox() && toRenderBox(child)->hasRelativeLogicalHeight())
                     || child->style()->logicalHeight().isPercent()
@@ -270,7 +270,7 @@
                     || child->style()->logicalMinHeight().isViewportPercentage()
                     || child->style()->logicalMaxHeight().isViewportPercentage()
                     || child->isSVGRoot())
-                child->setChildNeedsLayout(true, MarkOnlyThis);
+                child->setChildNeedsLayout(MarkOnlyThis);
         }
     }
 
@@ -293,7 +293,7 @@
     checkLayoutState(state);
 #endif
     m_layoutState = 0;
-    setNeedsLayout(false);
+    clearNeedsLayout();
 
     if (isSeamlessAncestorInFlowThread)
         flowThreadController()->setCurrentRenderFlowThread(0);
diff --git a/Source/core/rendering/RenderWidget.cpp b/Source/core/rendering/RenderWidget.cpp
index 8879ab2..7b73394 100644
--- a/Source/core/rendering/RenderWidget.cpp
+++ b/Source/core/rendering/RenderWidget.cpp
@@ -207,7 +207,7 @@
     StackStats::LayoutCheckPoint layoutCheckPoint;
     ASSERT(needsLayout());
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
diff --git a/Source/core/rendering/style/RenderStyle.h b/Source/core/rendering/style/RenderStyle.h
index b4c6a66..7d97ea9 100644
--- a/Source/core/rendering/style/RenderStyle.h
+++ b/Source/core/rendering/style/RenderStyle.h
@@ -1319,6 +1319,8 @@
     void setStrokeOpacity(float f) { accessSVGStyle()->setStrokeOpacity(f); }
     SVGLength strokeWidth() const { return svgStyle()->strokeWidth(); }
     void setStrokeWidth(SVGLength w) { accessSVGStyle()->setStrokeWidth(w); }
+    Vector<SVGLength> strokeDashArray() const { return svgStyle()->strokeDashArray(); }
+    void setStrokeDashArray(Vector<SVGLength> array) { accessSVGStyle()->setStrokeDashArray(array); }
     SVGLength strokeDashOffset() const { return svgStyle()->strokeDashOffset(); }
     void setStrokeDashOffset(SVGLength d) { accessSVGStyle()->setStrokeDashOffset(d); }
     float strokeMiterLimit() const { return svgStyle()->strokeMiterLimit(); }
diff --git a/Source/core/rendering/style/StyleCustomFilterProgram.h b/Source/core/rendering/style/StyleCustomFilterProgram.h
index 1581a2f..1678217 100644
--- a/Source/core/rendering/style/StyleCustomFilterProgram.h
+++ b/Source/core/rendering/style/StyleCustomFilterProgram.h
@@ -30,9 +30,9 @@
 #ifndef StyleCustomFilterProgram_h
 #define StyleCustomFilterProgram_h
 
-#include "core/loader/cache/CachedShader.h"
 #include "core/loader/cache/ResourceClient.h"
 #include "core/loader/cache/ResourcePtr.h"
+#include "core/loader/cache/ShaderResource.h"
 #include "core/platform/graphics/filters/custom/CustomFilterProgram.h"
 #include "core/rendering/style/StyleShader.h"
 #include "weborigin/KURL.h"
@@ -86,8 +86,8 @@
     {
         // Do not use the Resource:isLoaded method here, because it actually means !isLoading(),
         // so missing and canceled resources will have isLoaded set to true, even if they are not loaded yet.
-        ASSERT(!m_vertexShader || m_vertexShader->isCachedShader());
-        ASSERT(!m_fragmentShader || m_fragmentShader->isCachedShader());
+        ASSERT(!m_vertexShader || m_vertexShader->isShaderResource());
+        ASSERT(!m_fragmentShader || m_fragmentShader->isShaderResource());
         ASSERT(m_cachedVertexShader.get() || m_cachedFragmentShader.get());
         return (!m_cachedVertexShader.get() || m_isVertexShaderLoaded)
             && (!m_cachedFragmentShader.get() || m_isFragmentShaderLoaded);
@@ -96,11 +96,11 @@
     virtual void willHaveClients()
     {
         if (m_vertexShader) {
-            m_cachedVertexShader = m_vertexShader->cachedShader();
+            m_cachedVertexShader = m_vertexShader->resource();
             m_cachedVertexShader->addClient(this);
         }
         if (m_fragmentShader) {
-            m_cachedFragmentShader = m_fragmentShader->cachedShader();
+            m_cachedFragmentShader = m_fragmentShader->resource();
             m_cachedFragmentShader->addClient(this);
         }
     }
@@ -164,8 +164,8 @@
     RefPtr<StyleShader> m_vertexShader;
     RefPtr<StyleShader> m_fragmentShader;
 
-    ResourcePtr<CachedShader> m_cachedVertexShader;
-    ResourcePtr<CachedShader> m_cachedFragmentShader;
+    ResourcePtr<ShaderResource> m_cachedVertexShader;
+    ResourcePtr<ShaderResource> m_cachedFragmentShader;
 
     // The URLs form the key of the StyleCustomFilterProgram in the cache and are used
     // to lookup the StyleCustomFilterProgram when it's removed from the cache.
diff --git a/Source/core/rendering/style/StyleCachedImage.cpp b/Source/core/rendering/style/StyleFetchedImage.cpp
similarity index 61%
rename from Source/core/rendering/style/StyleCachedImage.cpp
rename to Source/core/rendering/style/StyleFetchedImage.cpp
index 76e90e2..e094475 100644
--- a/Source/core/rendering/style/StyleCachedImage.cpp
+++ b/Source/core/rendering/style/StyleFetchedImage.cpp
@@ -22,91 +22,91 @@
  */
 
 #include "config.h"
-#include "core/rendering/style/StyleCachedImage.h"
+#include "core/rendering/style/StyleFetchedImage.h"
 
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/rendering/RenderObject.h"
 
 namespace WebCore {
 
-StyleCachedImage::StyleCachedImage(CachedImage* image)
+StyleFetchedImage::StyleFetchedImage(ImageResource* image)
     : m_image(image)
 {
-    m_isCachedImage = true;
+    m_isImageResource = true;
     m_image->addClient(this);
 }
 
-StyleCachedImage::~StyleCachedImage()
+StyleFetchedImage::~StyleFetchedImage()
 {
     m_image->removeClient(this);
 }
 
-PassRefPtr<CSSValue> StyleCachedImage::cssValue() const
+PassRefPtr<CSSValue> StyleFetchedImage::cssValue() const
 {
     return CSSPrimitiveValue::create(m_image->url().string(), CSSPrimitiveValue::CSS_URI);
 }
 
-bool StyleCachedImage::canRender(const RenderObject* renderer, float multiplier) const
+bool StyleFetchedImage::canRender(const RenderObject* renderer, float multiplier) const
 {
     return m_image->canRender(renderer, multiplier);
 }
 
-bool StyleCachedImage::isLoaded() const
+bool StyleFetchedImage::isLoaded() const
 {
     return m_image->isLoaded();
 }
 
-bool StyleCachedImage::errorOccurred() const
+bool StyleFetchedImage::errorOccurred() const
 {
     return m_image->errorOccurred();
 }
 
-LayoutSize StyleCachedImage::imageSize(const RenderObject* renderer, float multiplier) const
+LayoutSize StyleFetchedImage::imageSize(const RenderObject* renderer, float multiplier) const
 {
     return m_image->imageSizeForRenderer(renderer, multiplier);
 }
 
-bool StyleCachedImage::imageHasRelativeWidth() const
+bool StyleFetchedImage::imageHasRelativeWidth() const
 {
     return m_image->imageHasRelativeWidth();
 }
 
-bool StyleCachedImage::imageHasRelativeHeight() const
+bool StyleFetchedImage::imageHasRelativeHeight() const
 {
     return m_image->imageHasRelativeHeight();
 }
 
-void StyleCachedImage::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+void StyleFetchedImage::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
 {
     m_image->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
 }
 
-bool StyleCachedImage::usesImageContainerSize() const
+bool StyleFetchedImage::usesImageContainerSize() const
 {
     return m_image->usesImageContainerSize();
 }
 
-void StyleCachedImage::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
+void StyleFetchedImage::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
 {
     m_image->setContainerSizeForRenderer(renderer, imageContainerSize, imageContainerZoomFactor);
 }
 
-void StyleCachedImage::addClient(RenderObject* renderer)
+void StyleFetchedImage::addClient(RenderObject* renderer)
 {
     m_image->addClient(renderer);
 }
 
-void StyleCachedImage::removeClient(RenderObject* renderer)
+void StyleFetchedImage::removeClient(RenderObject* renderer)
 {
     m_image->removeClient(renderer);
 }
 
-PassRefPtr<Image> StyleCachedImage::image(RenderObject* renderer, const IntSize&) const
+PassRefPtr<Image> StyleFetchedImage::image(RenderObject* renderer, const IntSize&) const
 {
     return m_image->imageForRenderer(renderer);
 }
 
-bool StyleCachedImage::knownToBeOpaque(const RenderObject* renderer) const
+bool StyleFetchedImage::knownToBeOpaque(const RenderObject* renderer) const
 {
     return m_image->currentFrameKnownToBeOpaque(renderer);
 }
diff --git a/Source/core/rendering/style/StyleCachedImage.h b/Source/core/rendering/style/StyleFetchedImage.h
similarity index 80%
rename from Source/core/rendering/style/StyleCachedImage.h
rename to Source/core/rendering/style/StyleFetchedImage.h
index 806357d..b9effd9 100644
--- a/Source/core/rendering/style/StyleCachedImage.h
+++ b/Source/core/rendering/style/StyleFetchedImage.h
@@ -21,22 +21,22 @@
  *
  */
 
-#ifndef StyleCachedImage_h
-#define StyleCachedImage_h
+#ifndef StyleFetchedImage_h
+#define StyleFetchedImage_h
 
-#include "core/loader/cache/CachedImageClient.h"
+#include "core/loader/cache/ImageResourceClient.h"
 #include "core/loader/cache/ResourcePtr.h"
 #include "core/rendering/style/StyleImage.h"
 
 namespace WebCore {
 
-class CachedImage;
+class ImageResource;
 
-class StyleCachedImage : public StyleImage, private CachedImageClient {
+class StyleFetchedImage : public StyleImage, private ImageResourceClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<StyleCachedImage> create(CachedImage* image) { return adoptRef(new StyleCachedImage(image)); }
-    virtual ~StyleCachedImage();
+    static PassRefPtr<StyleFetchedImage> create(ImageResource* image) { return adoptRef(new StyleFetchedImage(image)); }
+    virtual ~StyleFetchedImage();
 
     virtual WrappedImagePtr data() const { return m_image.get(); }
 
@@ -55,12 +55,12 @@
     virtual void removeClient(RenderObject*);
     virtual PassRefPtr<Image> image(RenderObject*, const IntSize&) const;
     virtual bool knownToBeOpaque(const RenderObject*) const OVERRIDE;
-    virtual CachedImage* cachedImage() const OVERRIDE { return m_image.get(); }
+    virtual ImageResource* cachedImage() const OVERRIDE { return m_image.get(); }
 
 private:
-    explicit StyleCachedImage(CachedImage*);
+    explicit StyleFetchedImage(ImageResource*);
 
-    ResourcePtr<CachedImage> m_image;
+    ResourcePtr<ImageResource> m_image;
 };
 
 }
diff --git a/Source/core/rendering/style/StyleCachedImageSet.cpp b/Source/core/rendering/style/StyleFetchedImageSet.cpp
similarity index 65%
rename from Source/core/rendering/style/StyleCachedImageSet.cpp
rename to Source/core/rendering/style/StyleFetchedImageSet.cpp
index 127f3f1..b9e9d52 100644
--- a/Source/core/rendering/style/StyleCachedImageSet.cpp
+++ b/Source/core/rendering/style/StyleFetchedImageSet.cpp
@@ -24,97 +24,97 @@
  */
 
 #include "config.h"
-#include "core/rendering/style/StyleCachedImageSet.h"
+#include "core/rendering/style/StyleFetchedImageSet.h"
 
 #include "core/css/CSSImageSetValue.h"
-#include "core/loader/cache/CachedImage.h"
+#include "core/loader/cache/ImageResource.h"
 #include "core/rendering/RenderObject.h"
 
 namespace WebCore {
 
-StyleCachedImageSet::StyleCachedImageSet(CachedImage* image, float imageScaleFactor, CSSImageSetValue* value)
+StyleFetchedImageSet::StyleFetchedImageSet(ImageResource* image, float imageScaleFactor, CSSImageSetValue* value)
     : m_bestFitImage(image)
     , m_imageScaleFactor(imageScaleFactor)
     , m_imageSetValue(value)
 {
-    m_isCachedImageSet = true;
+    m_isImageResourceSet = true;
     m_bestFitImage->addClient(this);
 }
 
 
-StyleCachedImageSet::~StyleCachedImageSet()
+StyleFetchedImageSet::~StyleFetchedImageSet()
 {
     m_bestFitImage->removeClient(this);
 }
 
-PassRefPtr<CSSValue> StyleCachedImageSet::cssValue() const
+PassRefPtr<CSSValue> StyleFetchedImageSet::cssValue() const
 {
     return m_imageSetValue;
 }
 
-bool StyleCachedImageSet::canRender(const RenderObject* renderer, float multiplier) const
+bool StyleFetchedImageSet::canRender(const RenderObject* renderer, float multiplier) const
 {
     return m_bestFitImage->canRender(renderer, multiplier);
 }
 
-bool StyleCachedImageSet::isLoaded() const
+bool StyleFetchedImageSet::isLoaded() const
 {
     return m_bestFitImage->isLoaded();
 }
 
-bool StyleCachedImageSet::errorOccurred() const
+bool StyleFetchedImageSet::errorOccurred() const
 {
     return m_bestFitImage->errorOccurred();
 }
 
-LayoutSize StyleCachedImageSet::imageSize(const RenderObject* renderer, float multiplier) const
+LayoutSize StyleFetchedImageSet::imageSize(const RenderObject* renderer, float multiplier) const
 {
     LayoutSize scaledImageSize = m_bestFitImage->imageSizeForRenderer(renderer, multiplier);
     scaledImageSize.scale(1 / m_imageScaleFactor);
     return scaledImageSize;
 }
 
-bool StyleCachedImageSet::imageHasRelativeWidth() const
+bool StyleFetchedImageSet::imageHasRelativeWidth() const
 {
     return m_bestFitImage->imageHasRelativeWidth();
 }
 
-bool StyleCachedImageSet::imageHasRelativeHeight() const
+bool StyleFetchedImageSet::imageHasRelativeHeight() const
 {
     return m_bestFitImage->imageHasRelativeHeight();
 }
 
-void StyleCachedImageSet::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
+void StyleFetchedImageSet::computeIntrinsicDimensions(const RenderObject*, Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
 {
     m_bestFitImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
 }
 
-bool StyleCachedImageSet::usesImageContainerSize() const
+bool StyleFetchedImageSet::usesImageContainerSize() const
 {
     return m_bestFitImage->usesImageContainerSize();
 }
 
-void StyleCachedImageSet::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
+void StyleFetchedImageSet::setContainerSizeForRenderer(const RenderObject* renderer, const IntSize& imageContainerSize, float imageContainerZoomFactor)
 {
     m_bestFitImage->setContainerSizeForRenderer(renderer, imageContainerSize, imageContainerZoomFactor);
 }
 
-void StyleCachedImageSet::addClient(RenderObject* renderer)
+void StyleFetchedImageSet::addClient(RenderObject* renderer)
 {
     m_bestFitImage->addClient(renderer);
 }
 
-void StyleCachedImageSet::removeClient(RenderObject* renderer)
+void StyleFetchedImageSet::removeClient(RenderObject* renderer)
 {
     m_bestFitImage->removeClient(renderer);
 }
 
-PassRefPtr<Image> StyleCachedImageSet::image(RenderObject* renderer, const IntSize&) const
+PassRefPtr<Image> StyleFetchedImageSet::image(RenderObject* renderer, const IntSize&) const
 {
     return m_bestFitImage->imageForRenderer(renderer);
 }
 
-bool StyleCachedImageSet::knownToBeOpaque(const RenderObject* renderer) const
+bool StyleFetchedImageSet::knownToBeOpaque(const RenderObject* renderer) const
 {
     return m_bestFitImage->currentFrameKnownToBeOpaque(renderer);
 }
diff --git a/Source/core/rendering/style/StyleCachedImageSet.h b/Source/core/rendering/style/StyleFetchedImageSet.h
similarity index 81%
rename from Source/core/rendering/style/StyleCachedImageSet.h
rename to Source/core/rendering/style/StyleFetchedImageSet.h
index c90b5e7..3e431e2 100644
--- a/Source/core/rendering/style/StyleCachedImageSet.h
+++ b/Source/core/rendering/style/StyleFetchedImageSet.h
@@ -23,29 +23,29 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef StyleCachedImageSet_h
-#define StyleCachedImageSet_h
+#ifndef StyleFetchedImageSet_h
+#define StyleFetchedImageSet_h
 
-#include "core/loader/cache/CachedImageClient.h"
+#include "core/loader/cache/ImageResourceClient.h"
 #include "core/loader/cache/ResourcePtr.h"
 #include "core/platform/graphics/LayoutSize.h"
 #include "core/rendering/style/StyleImage.h"
 
 namespace WebCore {
 
-class CachedImage;
+class ImageResource;
 class CSSImageSetValue;
 
 // This class keeps one cached image and has access to a set of alternatives.
 
-class StyleCachedImageSet : public StyleImage, private CachedImageClient {
+class StyleFetchedImageSet : public StyleImage, private ImageResourceClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<StyleCachedImageSet> create(CachedImage* image, float imageScaleFactor, CSSImageSetValue* value)
+    static PassRefPtr<StyleFetchedImageSet> create(ImageResource* image, float imageScaleFactor, CSSImageSetValue* value)
     {
-        return adoptRef(new StyleCachedImageSet(image, imageScaleFactor, value));
+        return adoptRef(new StyleFetchedImageSet(image, imageScaleFactor, value));
     }
-    virtual ~StyleCachedImageSet();
+    virtual ~StyleFetchedImageSet();
 
     virtual PassRefPtr<CSSValue> cssValue() const;
 
@@ -70,16 +70,16 @@
     virtual PassRefPtr<Image> image(RenderObject*, const IntSize&) const;
     virtual float imageScaleFactor() const { return m_imageScaleFactor; }
     virtual bool knownToBeOpaque(const RenderObject*) const OVERRIDE;
-    virtual CachedImage* cachedImage() const OVERRIDE { return m_bestFitImage.get(); }
+    virtual ImageResource* cachedImage() const OVERRIDE { return m_bestFitImage.get(); }
 
 private:
-    StyleCachedImageSet(CachedImage*, float imageScaleFactor, CSSImageSetValue*);
+    StyleFetchedImageSet(ImageResource*, float imageScaleFactor, CSSImageSetValue*);
 
-    ResourcePtr<CachedImage> m_bestFitImage;
+    ResourcePtr<ImageResource> m_bestFitImage;
     float m_imageScaleFactor;
     CSSImageSetValue* m_imageSetValue; // Not retained; it owns us.
 };
 
 } // namespace WebCore
 
-#endif // StyleCachedImageSet_h
+#endif // StyleFetchedImageSet_h
diff --git a/Source/core/rendering/style/StyleCachedShader.cpp b/Source/core/rendering/style/StyleFetchedShader.cpp
similarity index 86%
rename from Source/core/rendering/style/StyleCachedShader.cpp
rename to Source/core/rendering/style/StyleFetchedShader.cpp
index f01ddcf..2b6c6c2 100644
--- a/Source/core/rendering/style/StyleCachedShader.cpp
+++ b/Source/core/rendering/style/StyleFetchedShader.cpp
@@ -29,21 +29,21 @@
 
 #include "config.h"
 
-#include "core/rendering/style/StyleCachedShader.h"
+#include "core/rendering/style/StyleFetchedShader.h"
 
 #include "core/css/CSSPrimitiveValue.h"
-#include "core/loader/cache/CachedShader.h"
+#include "core/loader/cache/ShaderResource.h"
 
 namespace WebCore {
 
 
-StyleCachedShader::StyleCachedShader(CachedShader* shader)
+StyleFetchedShader::StyleFetchedShader(ShaderResource* shader)
     : m_shader(shader)
 {
-     m_isCachedShader = true;
+    m_isShaderResource = true;
 }
 
-PassRefPtr<CSSValue> StyleCachedShader::cssValue() const
+PassRefPtr<CSSValue> StyleFetchedShader::cssValue() const
 {
     return CSSPrimitiveValue::create(m_shader->url().string(), CSSPrimitiveValue::CSS_URI);
 }
diff --git a/Source/core/rendering/style/StyleCachedShader.h b/Source/core/rendering/style/StyleFetchedShader.h
similarity index 75%
rename from Source/core/rendering/style/StyleCachedShader.h
rename to Source/core/rendering/style/StyleFetchedShader.h
index 739f349..88e5411 100644
--- a/Source/core/rendering/style/StyleCachedShader.h
+++ b/Source/core/rendering/style/StyleFetchedShader.h
@@ -27,31 +27,31 @@
  * SUCH DAMAGE.
  */
 
-#ifndef StyleCachedShader_h
-#define StyleCachedShader_h
+#ifndef StyleFetchedShader_h
+#define StyleFetchedShader_h
 
 #include "core/loader/cache/ResourcePtr.h"
 #include "core/rendering/style/StyleShader.h"
 
 namespace WebCore {
 
-class CachedShader;
+class ShaderResource;
 
-class StyleCachedShader : public StyleShader {
+class StyleFetchedShader : public StyleShader {
 public:
-    // FIXME: Keep a reference to the actual CachedShader in this class.
-    static PassRefPtr<StyleCachedShader> create(CachedShader* shader) { return adoptRef(new StyleCachedShader(shader)); }
+    // FIXME: Keep a reference to the actual ShaderResource in this class.
+    static PassRefPtr<StyleFetchedShader> create(ShaderResource* shader) { return adoptRef(new StyleFetchedShader(shader)); }
 
     virtual PassRefPtr<CSSValue> cssValue() const;
 
-    virtual CachedShader* cachedShader() const { return m_shader.get(); }
+    virtual ShaderResource* resource() const { return m_shader.get(); }
 
 private:
-    StyleCachedShader(CachedShader*);
+    StyleFetchedShader(ShaderResource*);
 
-    ResourcePtr<CachedShader> m_shader;
+    ResourcePtr<ShaderResource> m_shader;
 };
 
 }
 
-#endif // StyleCachedShader_h
+#endif // StyleFetchedShader_h
diff --git a/Source/core/rendering/style/StyleImage.h b/Source/core/rendering/style/StyleImage.h
index 58f0908..e440c22 100644
--- a/Source/core/rendering/style/StyleImage.h
+++ b/Source/core/rendering/style/StyleImage.h
@@ -34,7 +34,7 @@
 
 namespace WebCore {
 
-class CachedImage;
+class ImageResource;
 class CSSValue;
 class RenderObject;
 
@@ -66,12 +66,12 @@
     virtual WrappedImagePtr data() const = 0;
     virtual float imageScaleFactor() const { return 1; }
     virtual bool knownToBeOpaque(const RenderObject*) const = 0;
-    virtual CachedImage* cachedImage() const { return 0; }
+    virtual ImageResource* cachedImage() const { return 0; }
 
-    ALWAYS_INLINE bool isCachedImage() const { return m_isCachedImage; }
+    ALWAYS_INLINE bool isImageResource() const { return m_isImageResource; }
     ALWAYS_INLINE bool isPendingImage() const { return m_isPendingImage; }
     ALWAYS_INLINE bool isGeneratedImage() const { return m_isGeneratedImage; }
-    ALWAYS_INLINE bool isCachedImageSet() const { return m_isCachedImageSet; }
+    ALWAYS_INLINE bool isImageResourceSet() const { return m_isImageResourceSet; }
 
     static bool imagesEquivalent(const StyleImage* image1, const StyleImage* image2)
     {
@@ -85,16 +85,16 @@
 
 protected:
     StyleImage()
-        : m_isCachedImage(false)
+        : m_isImageResource(false)
         , m_isPendingImage(false)
         , m_isGeneratedImage(false)
-        , m_isCachedImageSet(false)
+        , m_isImageResourceSet(false)
     {
     }
-    bool m_isCachedImage:1;
+    bool m_isImageResource:1;
     bool m_isPendingImage:1;
     bool m_isGeneratedImage:1;
-    bool m_isCachedImageSet:1;
+    bool m_isImageResourceSet:1;
 };
 
 }
diff --git a/Source/core/rendering/style/StylePendingImage.h b/Source/core/rendering/style/StylePendingImage.h
index 9f7bc2a..3633d15 100644
--- a/Source/core/rendering/style/StylePendingImage.h
+++ b/Source/core/rendering/style/StylePendingImage.h
@@ -43,10 +43,10 @@
 public:
     static PassRefPtr<StylePendingImage> create(CSSValue* value) { return adoptRef(new StylePendingImage(value)); }
 
-    virtual WrappedImagePtr data() const { return static_cast<CSSImageValue*>(m_value); }
+    virtual WrappedImagePtr data() const { return m_value; }
 
     virtual PassRefPtr<CSSValue> cssValue() const { return m_value; }
-    CSSImageValue* cssImageValue() const { return m_value->isImageValue() ? static_cast<CSSImageValue*>(m_value) : 0; }
+    CSSImageValue* cssImageValue() const { return m_value->isImageValue() ? toCSSImageValue(m_value) : 0; }
     CSSImageGeneratorValue* cssImageGeneratorValue() const { return m_value->isImageGeneratorValue() ? static_cast<CSSImageGeneratorValue*>(m_value) : 0; }
     CSSCursorImageValue* cssCursorImageValue() const { return m_value->isCursorImageValue() ? static_cast<CSSCursorImageValue*>(m_value) : 0; }
     CSSImageSetValue* cssImageSetValue() const { return m_value->isImageSetValue() ? static_cast<CSSImageSetValue*>(m_value) : 0; }
diff --git a/Source/core/rendering/style/StyleShader.h b/Source/core/rendering/style/StyleShader.h
index de43941..c5927e6 100644
--- a/Source/core/rendering/style/StyleShader.h
+++ b/Source/core/rendering/style/StyleShader.h
@@ -34,27 +34,27 @@
 
 namespace WebCore {
 
-class CachedShader;
+class ShaderResource;
 class CSSValue;
 
 class StyleShader : public RefCounted<StyleShader> {
 public:
     virtual ~StyleShader() { }
 
-    ALWAYS_INLINE bool isCachedShader() const { return m_isCachedShader; }
+    ALWAYS_INLINE bool isShaderResource() const { return m_isShaderResource; }
     ALWAYS_INLINE bool isPendingShader() const { return m_isPendingShader; }
 
     virtual PassRefPtr<CSSValue> cssValue() const = 0;
 
-    virtual CachedShader* cachedShader() const { return 0; }
+    virtual ShaderResource* resource() const { return 0; }
 
 protected:
     StyleShader()
-        : m_isCachedShader(false)
+        : m_isShaderResource(false)
         , m_isPendingShader(false)
     {
     }
-    bool m_isCachedShader : 1;
+    bool m_isShaderResource : 1;
     bool m_isPendingShader : 1;
 };
 
diff --git a/Source/core/rendering/svg/ReferenceFilterBuilder.cpp b/Source/core/rendering/svg/ReferenceFilterBuilder.cpp
index 11ce00e..ab598e3 100644
--- a/Source/core/rendering/svg/ReferenceFilterBuilder.cpp
+++ b/Source/core/rendering/svg/ReferenceFilterBuilder.cpp
@@ -33,8 +33,8 @@
 #include "core/css/CSSPrimitiveValue.h"
 #include "core/css/CSSPrimitiveValueMappings.h"
 #include "core/dom/Element.h"
-#include "core/loader/cache/CachedDocument.h"
-#include "core/loader/cache/CachedSVGDocumentReference.h"
+#include "core/loader/cache/DocumentResource.h"
+#include "core/loader/cache/DocumentResourceReference.h"
 #include "core/platform/graphics/filters/FilterEffect.h"
 #include "core/platform/graphics/filters/SourceAlpha.h"
 #include "core/rendering/svg/RenderSVGResourceFilter.h"
@@ -92,8 +92,8 @@
     Document* document = renderer->document();
     ASSERT(document);
 
-    CachedSVGDocumentReference* cachedSVGDocumentReference = filterOperation->cachedSVGDocumentReference();
-    CachedDocument* cachedSVGDocument = cachedSVGDocumentReference ? cachedSVGDocumentReference->document() : 0;
+    DocumentResourceReference* documentResourceReference = filterOperation->documentResourceReference();
+    DocumentResource* cachedSVGDocument = documentResourceReference ? documentResourceReference->document() : 0;
 
     // If we have an SVG document, this is an external reference. Otherwise
     // we look up the referenced node in the current document.
diff --git a/Source/core/rendering/svg/RenderSVGContainer.cpp b/Source/core/rendering/svg/RenderSVGContainer.cpp
index d64aec4..3e6ea82 100644
--- a/Source/core/rendering/svg/RenderSVGContainer.cpp
+++ b/Source/core/rendering/svg/RenderSVGContainer.cpp
@@ -81,7 +81,7 @@
     }
 
     repainter.repaintAfterLayout();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderSVGContainer::addChild(RenderObject* child, RenderObject* beforeChild)
diff --git a/Source/core/rendering/svg/RenderSVGGradientStop.cpp b/Source/core/rendering/svg/RenderSVGGradientStop.cpp
index f490629..1cada34 100644
--- a/Source/core/rendering/svg/RenderSVGGradientStop.cpp
+++ b/Source/core/rendering/svg/RenderSVGGradientStop.cpp
@@ -63,7 +63,7 @@
 void RenderSVGGradientStop::layout()
 {
     StackStats::LayoutCheckPoint layoutCheckPoint;
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 SVGGradientElement* RenderSVGGradientStop::gradientElement() const
diff --git a/Source/core/rendering/svg/RenderSVGHiddenContainer.cpp b/Source/core/rendering/svg/RenderSVGHiddenContainer.cpp
index 9fc703e..81116fd 100644
--- a/Source/core/rendering/svg/RenderSVGHiddenContainer.cpp
+++ b/Source/core/rendering/svg/RenderSVGHiddenContainer.cpp
@@ -33,7 +33,7 @@
     StackStats::LayoutCheckPoint layoutCheckPoint;
     ASSERT(needsLayout());
     SVGRenderSupport::layoutChildren(this, selfNeedsLayout());
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderSVGHiddenContainer::paint(PaintInfo&, const LayoutPoint&)
diff --git a/Source/core/rendering/svg/RenderSVGImage.cpp b/Source/core/rendering/svg/RenderSVGImage.cpp
index 3717f9d..9456092 100644
--- a/Source/core/rendering/svg/RenderSVGImage.cpp
+++ b/Source/core/rendering/svg/RenderSVGImage.cpp
@@ -68,7 +68,7 @@
     // by setting the image's container size to its intrinsic size.
     // See: http://www.w3.org/TR/SVG/single-page.html, 7.8 The ‘preserveAspectRatio’ attribute.
     if (image->preserveAspectRatioCurrentValue().align() == SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE) {
-        if (CachedImage* cachedImage = m_imageResource->cachedImage()) {
+        if (ImageResource* cachedImage = m_imageResource->cachedImage()) {
             LayoutSize intrinsicSize = cachedImage->imageSizeForRenderer(0, style()->effectiveZoom());
             if (intrinsicSize != m_imageResource->imageSize(style()->effectiveZoom())) {
                 m_imageResource->setContainerSizeForRenderer(roundedIntSize(intrinsicSize));
@@ -117,7 +117,7 @@
         RenderSVGModelObject::setNeedsBoundariesUpdate();
 
     repainter.repaintAfterLayout();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderSVGImage::paint(PaintInfo& paintInfo, const LayoutPoint&)
diff --git a/Source/core/rendering/svg/RenderSVGResource.cpp b/Source/core/rendering/svg/RenderSVGResource.cpp
index 9ecdfdf..6a2d951 100644
--- a/Source/core/rendering/svg/RenderSVGResource.cpp
+++ b/Source/core/rendering/svg/RenderSVGResource.cpp
@@ -191,7 +191,7 @@
     ASSERT(object->node());
 
     if (needsLayout)
-        object->setNeedsLayout(true);
+        object->setNeedsLayout();
 
     removeFromCacheAndInvalidateDependencies(object, needsLayout);
 
diff --git a/Source/core/rendering/svg/RenderSVGResourceContainer.cpp b/Source/core/rendering/svg/RenderSVGResourceContainer.cpp
index 33fb263..9d78c84 100644
--- a/Source/core/rendering/svg/RenderSVGResourceContainer.cpp
+++ b/Source/core/rendering/svg/RenderSVGResourceContainer.cpp
@@ -191,7 +191,7 @@
         if (!renderer)
             continue;
         SVGResourcesCache::clientStyleChanged(renderer, StyleDifferenceLayout, renderer->style());
-        renderer->setNeedsLayout(true);
+        renderer->setNeedsLayout();
     }
 }
 
diff --git a/Source/core/rendering/svg/RenderSVGRoot.cpp b/Source/core/rendering/svg/RenderSVGRoot.cpp
index 7f52741..3e63935 100644
--- a/Source/core/rendering/svg/RenderSVGRoot.cpp
+++ b/Source/core/rendering/svg/RenderSVGRoot.cpp
@@ -251,7 +251,7 @@
 
     repainter.repaintAfterLayout();
 
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 void RenderSVGRoot::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
diff --git a/Source/core/rendering/svg/RenderSVGShape.cpp b/Source/core/rendering/svg/RenderSVGShape.cpp
index 08b862e..522f7ab 100644
--- a/Source/core/rendering/svg/RenderSVGShape.cpp
+++ b/Source/core/rendering/svg/RenderSVGShape.cpp
@@ -168,7 +168,7 @@
         RenderSVGModelObject::setNeedsBoundariesUpdate();
 
     repainter.repaintAfterLayout();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 Path* RenderSVGShape::nonScalingStrokePath(const Path* path, const AffineTransform& strokeTransform) const
diff --git a/Source/core/rendering/svg/RenderSVGText.cpp b/Source/core/rendering/svg/RenderSVGText.cpp
index f3e17a0..bbcbf95 100644
--- a/Source/core/rendering/svg/RenderSVGText.cpp
+++ b/Source/core/rendering/svg/RenderSVGText.cpp
@@ -428,7 +428,7 @@
         RenderSVGBlock::setNeedsBoundariesUpdate();
 
     repainter.repaintAfterLayout();
-    setNeedsLayout(false);
+    clearNeedsLayout();
 }
 
 RootInlineBox* RenderSVGText::createRootInlineBox()
diff --git a/Source/core/rendering/svg/SVGRenderSupport.cpp b/Source/core/rendering/svg/SVGRenderSupport.cpp
index 8d4a272..09fdae4 100644
--- a/Source/core/rendering/svg/SVGRenderSupport.cpp
+++ b/Source/core/rendering/svg/SVGRenderSupport.cpp
@@ -241,7 +241,7 @@
         }
 
         if (needsLayout)
-            child->setNeedsLayout(true, MarkOnlyThis);
+            child->setNeedsLayout(MarkOnlyThis);
 
         if (child->needsLayout()) {
             child->layout();