2009-02-06 Simon Fraser <simon.fraser@apple.com>
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Feb 2009 22:17:44 +0000 (22:17 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Feb 2009 22:17:44 +0000 (22:17 +0000)
        Reviewed by Eric Seidel

        Factor code that checks whether the object is rooted in
        repaint() and repaintRectangle() into a common isRooted()
        method.

        * rendering/RenderObject.cpp:
        (WebCore::RenderObject::repaint):
        (WebCore::RenderObject::repaintRectangle):
        (WebCore::RenderObject::isRooted):
        * rendering/RenderObject.h:

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

WebCore/ChangeLog
WebCore/rendering/RenderObject.cpp
WebCore/rendering/RenderObject.h

index a16a84f..90b86e8 100644 (file)
@@ -2,6 +2,20 @@
 
         Reviewed by Eric Seidel
 
+        Factor code that checks whether the object is rooted in
+        repaint() and repaintRectangle() into a common isRooted()
+        method.
+        
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::repaint):
+        (WebCore::RenderObject::repaintRectangle):
+        (WebCore::RenderObject::isRooted):
+        * rendering/RenderObject.h:
+
+2009-02-06  Simon Fraser  <simon.fraser@apple.com>
+
+        Reviewed by Eric Seidel
+
         Expose an isRootLayer() method on RenderLayer that works whether the
         layer is rooted or not, and use that in a few places in the
         accelerated compositing code.
index e3cd93c..9bc4bef 100644 (file)
@@ -1666,14 +1666,11 @@ void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer,
 
 void RenderObject::repaint(bool immediate)
 {
-    // Can't use view(), since we might be unrooted.
-    RenderObject* o = this;
-    while (o->parent())
-        o = o->parent();
-    if (!o->isRenderView())
+    // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
+    RenderView* view;
+    if (!isRooted(&view))
         return;
 
-    RenderView* view = toRenderView(o);
     if (view->printing())
         return; // Don't repaint if we're printing.
 
@@ -1683,14 +1680,11 @@ void RenderObject::repaint(bool immediate)
 
 void RenderObject::repaintRectangle(const IntRect& r, bool immediate)
 {
-    // Can't use view(), since we might be unrooted.
-    RenderObject* o = this;
-    while (o->parent())
-        o = o->parent();
-    if (!o->isRenderView())
+    // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
+    RenderView* view;
+    if (!isRooted(&view))
         return;
 
-    RenderView* view = toRenderView(o);
     if (view->printing())
         return; // Don't repaint if we're printing.
 
@@ -2211,6 +2205,21 @@ RenderView* RenderObject::view() const
     return toRenderView(document()->renderer());
 }
 
+bool RenderObject::isRooted(RenderView** view)
+{
+    RenderObject* o = this;
+    while (o->parent())
+        o = o->parent();
+
+    if (!o->isRenderView())
+        return false;
+
+    if (view)
+        *view = toRenderView(o);
+
+    return true;
+}
+
 bool RenderObject::hasOutlineAnnotation() const
 {
     return element() && element()->isLink() && document()->printing();
index e3d3390..947c9ea 100644 (file)
@@ -357,6 +357,9 @@ public:
 
     RenderView* view() const;
 
+    // Returns true if this renderer is rooted, and optionally returns the hosting view (the root of the hierarchy).
+    bool isRooted(RenderView** = 0);
+
     // don't even think about making this method virtual!
     Node* element() const { return m_isAnonymous ? 0 : m_node; }
     Document* document() const { return m_node->document(); }