2009-01-30 Sam Weinig <sam@webkit.org>
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jan 2009 21:57:37 +0000 (21:57 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 30 Jan 2009 21:57:37 +0000 (21:57 +0000)
        Reviewed by Dan Bernstein.

        Add toRenderView methods for casting RenderObjects to RenderViews.  The methods will assert if the object
        is not a RenderView.

        * dom/Document.cpp:
        (WebCore::Document::renderView):
        * editing/SelectionController.cpp:
        (WebCore::SelectionController::nodeWillBeRemoved):
        (WebCore::SelectionController::recomputeCaretRect):
        (WebCore::SelectionController::invalidateCaretRect):
        (WebCore::SelectionController::focusedOrActiveStateChanged):
        * editing/mac/SelectionControllerMac.mm:
        (WebCore::SelectionController::notifyAccessibilityForSelectionChange):
        * rendering/RenderBox.cpp:
        (WebCore::RenderBox::styleDidChange):
        (WebCore::RenderBox::repaintLayerRectsForImage):
        (WebCore::RenderBox::availableHeightUsing):
        * rendering/RenderView.h:
        (WebCore::toRenderView):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@40417 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/dom/Document.cpp
WebCore/editing/SelectionController.cpp
WebCore/editing/mac/SelectionControllerMac.mm
WebCore/rendering/RenderBox.cpp
WebCore/rendering/RenderView.h

index dc6a65e896556561b59a69242e26e94401769f3d..76afcaefeed1c0232cb2f979f0e9601251ef2065 100644 (file)
@@ -1,3 +1,26 @@
+2009-01-30  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Dan Bernstein.
+
+        Add toRenderView methods for casting RenderObjects to RenderViews.  The methods will assert if the object
+        is not a RenderView.
+
+        * dom/Document.cpp:
+        (WebCore::Document::renderView):
+        * editing/SelectionController.cpp:
+        (WebCore::SelectionController::nodeWillBeRemoved):
+        (WebCore::SelectionController::recomputeCaretRect):
+        (WebCore::SelectionController::invalidateCaretRect):
+        (WebCore::SelectionController::focusedOrActiveStateChanged):
+        * editing/mac/SelectionControllerMac.mm:
+        (WebCore::SelectionController::notifyAccessibilityForSelectionChange):
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::styleDidChange):
+        (WebCore::RenderBox::repaintLayerRectsForImage):
+        (WebCore::RenderBox::availableHeightUsing):
+        * rendering/RenderView.h:
+        (WebCore::toRenderView):
+
 2009-01-30  Simon Fraser  <simon.fraser@apple.com>
 
         Reviewed by Dave Hyatt
index 111d91ebc310782f5b14ca748ea9b7794690eab5..baec2da0db07181db547858d29a5c03ad449a619 100644 (file)
@@ -1357,7 +1357,7 @@ void Document::removeAllDisconnectedNodeEventListeners()
 
 RenderView* Document::renderView() const
 {
-    return static_cast<RenderView*>(renderer());
+    return toRenderView(renderer());
 }
 
 void Document::clearAXObjectCache()
index 67f675e60bcb8c47545f8bee86a55d0dc372d8a4..9bdcea69b9bd7cfc54893cabed0ac3923af3e06e 100644 (file)
@@ -215,7 +215,7 @@ void SelectionController::nodeWillBeRemoved(Node *node)
     if (clearRenderTreeSelection) {
         RefPtr<Document> document = m_sel.start().node()->document();
         document->updateRendering();
-        if (RenderView* view = static_cast<RenderView*>(document->renderer()))
+        if (RenderView* view = toRenderView(document->renderer()))
             view->clearSelection();
     }
 
@@ -853,7 +853,7 @@ bool SelectionController::recomputeCaretRect()
     if (oldAbsRepaintRect == m_absCaretBounds)
         return false;
     
-    if (RenderView* view = static_cast<RenderView*>(m_frame->document()->renderer())) {
+    if (RenderView* view = toRenderView(m_frame->document()->renderer())) {
         view->repaintViewRectangle(oldAbsRepaintRect, false);
         view->repaintViewRectangle(m_absCaretBounds, false);
     }
@@ -886,7 +886,7 @@ void SelectionController::invalidateCaretRect()
     m_needsLayout = true;
 
     if (!caretRectChanged) {
-        if (RenderView* view = static_cast<RenderView*>(d->renderer()))
+        if (RenderView* view = toRenderView(d->renderer()))
             view->repaintViewRectangle(caretRepaintRect(), false);
     }
 }
@@ -1166,7 +1166,7 @@ void SelectionController::focusedOrActiveStateChanged()
     // Because RenderObject::selectionBackgroundColor() and
     // RenderObject::selectionForegroundColor() check if the frame is active,
     // we have to update places those colors were painted.
-    if (RenderView* view = static_cast<RenderView*>(m_frame->document()->renderer()))
+    if (RenderView* view = toRenderView(m_frame->document()->renderer()))
         view->repaintViewRectangle(enclosingIntRect(m_frame->selectionBounds()));
 
     // Caret appears in the active frame.
index 4125c3a382fa3443f1a6f82d871ac06684925312..b6c11036334f0e03adec35238614541f75a359f8 100644 (file)
@@ -45,7 +45,7 @@ void SelectionController::notifyAccessibilityForSelectionChange()
     
     // if zoom feature is enabled, insertion point changes should update the zoom
     if (UAZoomEnabled() && m_sel.isCaret() && m_sel.start().node()) {
-        RenderView *renderView = static_cast<RenderView*>(m_sel.start().node()->renderer());
+        RenderView* renderView = toRenderView(m_sel.start().node()->renderer());
         if (renderView) {
             IntRect selectionRect = absoluteCaretBounds();
             IntRect viewRect = renderView->viewRect();
index 0f934cb6fc778df32a432441e4e41ffda4b5d2ad..5948ef895c309a8a5da9d0807ae66a9b62cc6e09 100644 (file)
@@ -171,7 +171,7 @@ void RenderBox::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldSty
     // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
     // during the style change (it's used by clippedOverflowRectForRepaint()).
     if (style()->outlineWidth() > 0 && style()->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
-        static_cast<RenderView*>(document()->renderer())->setMaximalOutlineSize(style()->outlineSize());
+        toRenderView(document()->renderer())->setMaximalOutlineSize(style()->outlineSize());
 
     RenderObject::styleDidChange(diff, oldStyle);
 
@@ -954,7 +954,7 @@ bool RenderBox::repaintLayerRectsForImage(WrappedImagePtr image, const FillLayer
                     int rw;
                     int rh;
 
-                    if (FrameView* frameView = static_cast<RenderView*>(layerRenderer)->frameView()) {
+                    if (FrameView* frameView = toRenderView(layerRenderer)->frameView()) {
                         rw = frameView->contentsWidth();
                         rh = frameView->contentsHeight();
                     } else {
@@ -2059,7 +2059,7 @@ int RenderBox::availableHeightUsing(const Length& h) const
         return calcContentBoxHeight(h.value());
 
     if (isRenderView())
-        return static_cast<const RenderView*>(this)->frameView()->visibleHeight();
+        return toRenderView(this)->frameView()->visibleHeight();
 
     // We need to stop here, since we don't want to increase the height of the table
     // artificially.  We're going to rely on this cell getting expanded to some new
index 44bf2ccdf35f460e3462ecb534cf9498f6425209..d9c2a15dbe74e9b80b4f74a4642d57e75d4ef19a 100644 (file)
@@ -180,6 +180,22 @@ private:
     unsigned m_layoutStateDisableCount;
 };
 
+inline RenderView* toRenderView(RenderObject* o)
+{
+    ASSERT(!o || o->isRenderView());
+    return static_cast<RenderView*>(o);
+}
+
+inline const RenderView* toRenderView(const RenderObject* o)
+{
+    ASSERT(!o || o->isRenderView());
+    return static_cast<const RenderView*>(o);
+}
+
+// This will catch anyone doing an unnecessary cast.
+void toRenderView(const RenderView*);
+
+
 // Stack-based class to assist with LayoutState push/pop
 class LayoutStateMaintainer : Noncopyable {
 public: