add validate to SkView for debugging

git-svn-id: http://skia.googlecode.com/svn/trunk@9596 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 0c6c0de..9c3e50f 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -509,55 +509,58 @@
 
 //////////////////////////////////////////////////////////////////////
 
-void SkView::getLocalBounds(SkRect* bounds) const
-{
-    if (bounds)
+void SkView::getLocalBounds(SkRect* bounds) const {
+    if (bounds) {
         bounds->set(0, 0, fWidth, fHeight);
+    }
 }
 
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
 
-void SkView::detachFromParent_NoLayout()
-{
-    if (fParent == NULL)
+void SkView::detachFromParent_NoLayout() {
+    this->validate();
+    if (fParent == NULL) {
         return;
+    }
 
-    if (fContainsFocus)
+    if (fContainsFocus) {
         (void)this->setFocusView(NULL);
+    }
 
     this->inval(NULL);
 
-    SkView*    next = NULL;
+    SkView* next = NULL;
 
-    if (fNextSibling != this)    // do we have any siblings
-    {
+    if (fNextSibling != this) {   // do we have any siblings
         fNextSibling->fPrevSibling = fPrevSibling;
         fPrevSibling->fNextSibling = fNextSibling;
         next = fNextSibling;
     }
 
-    if (fParent->fFirstChild == this)
+    if (fParent->fFirstChild == this) {
         fParent->fFirstChild = next;
+    }
 
     fParent = fNextSibling = fPrevSibling = NULL;
 
+    this->validate();
     this->unref();
 }
 
-void SkView::detachFromParent()
-{
+void SkView::detachFromParent() {
+    this->validate();
     SkView* parent = fParent;
 
-    if (parent)
-    {
+    if (parent) {
         this->detachFromParent_NoLayout();
         parent->invokeLayout();
     }
+    this->validate();
 }
 
-SkView* SkView::attachChildToBack(SkView* child)
-{
+SkView* SkView::attachChildToBack(SkView* child) {
+    this->validate();
     SkASSERT(child != this);
 
     if (child == NULL || fFirstChild == child)
@@ -566,13 +569,10 @@
     child->ref();
     child->detachFromParent_NoLayout();
 
-    if (fFirstChild == NULL)
-    {
+    if (fFirstChild == NULL) {
         child->fNextSibling = child;
         child->fPrevSibling = child;
-    }
-    else
-    {
+    } else {
         child->fNextSibling = fFirstChild;
         child->fPrevSibling = fFirstChild->fPrevSibling;
         fFirstChild->fPrevSibling->fNextSibling = child;
@@ -583,13 +583,14 @@
     child->fParent = this;
     child->inval(NULL);
 
+    this->validate();
     this->invokeLayout();
 DONE:
     return child;
 }
 
-SkView* SkView::attachChildToFront(SkView* child)
-{
+SkView* SkView::attachChildToFront(SkView* child) {
+    this->validate();
     SkASSERT(child != this);
 
     if (child == NULL || (fFirstChild && fFirstChild->fPrevSibling == child))
@@ -598,14 +599,11 @@
     child->ref();
     child->detachFromParent_NoLayout();
 
-    if (fFirstChild == NULL)
-    {
+    if (fFirstChild == NULL) {
         fFirstChild = child;
         child->fNextSibling = child;
         child->fPrevSibling = child;
-    }
-    else
-    {
+    } else {
         child->fNextSibling = fFirstChild;
         child->fPrevSibling = fFirstChild->fPrevSibling;
         fFirstChild->fPrevSibling->fNextSibling = child;
@@ -615,19 +613,19 @@
     child->fParent = this;
     child->inval(NULL);
 
+    this->validate();
     this->invokeLayout();
 DONE:
     return child;
 }
 
-void SkView::detachAllChildren()
-{
+void SkView::detachAllChildren() {
+    this->validate();
     while (fFirstChild)
         fFirstChild->detachFromParent_NoLayout();
 }
 
-void SkView::localToGlobal(SkMatrix* matrix) const
-{
+void SkView::localToGlobal(SkMatrix* matrix) const {
     if (matrix) {
         matrix->reset();
         const SkView* view = this;
@@ -662,8 +660,7 @@
 /*    Even if the subclass overrides onInflate, they should always be
     sure to call the inherited method, so that we get called.
 */
-void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
+void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node) {
     SkScalar x, y;
 
     x = this->locX();
@@ -693,18 +690,15 @@
     this->setFlags(flags);
 }
 
-void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node)
-{
+void SkView::inflate(const SkDOM& dom, const SkDOM::Node* node) {
     this->onInflate(dom, node);
 }
 
-void SkView::onPostInflate(const SkTDict<SkView*>&)
-{
+void SkView::onPostInflate(const SkTDict<SkView*>&) {
     // override in subclass as needed
 }
 
-void SkView::postInflate(const SkTDict<SkView*>& dict)
-{
+void SkView::postInflate(const SkTDict<SkView*>& dict) {
     this->onPostInflate(dict);
 
     B2FIter    iter(this);
@@ -715,14 +709,13 @@
 
 //////////////////////////////////////////////////////////////////
 
-SkView* SkView::sendEventToParents(const SkEvent& evt)
-{
+SkView* SkView::sendEventToParents(const SkEvent& evt) {
     SkView* parent = fParent;
 
-    while (parent)
-    {
-        if (parent->doEvent(evt))
+    while (parent) {
+        if (parent->doEvent(evt)) {
             return parent;
+        }
         parent = parent->fParent;
     }
     return NULL;
@@ -743,38 +736,33 @@
 //////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////
 
-SkView::F2BIter::F2BIter(const SkView* parent)
-{
+SkView::F2BIter::F2BIter(const SkView* parent) {
     fFirstChild = parent ? parent->fFirstChild : NULL;
     fChild = fFirstChild ? fFirstChild->fPrevSibling : NULL;
 }
 
-SkView*    SkView::F2BIter::next()
-{
+SkView* SkView::F2BIter::next() {
     SkView* curr = fChild;
 
-    if (fChild)
-    {
-        if (fChild == fFirstChild)
+    if (fChild) {
+        if (fChild == fFirstChild) {
             fChild = NULL;
-        else
+        } else {
             fChild = fChild->fPrevSibling;
+        }
     }
     return curr;
 }
 
-SkView::B2FIter::B2FIter(const SkView* parent)
-{
+SkView::B2FIter::B2FIter(const SkView* parent) {
     fFirstChild = parent ? parent->fFirstChild : NULL;
     fChild = fFirstChild;
 }
 
-SkView*    SkView::B2FIter::next()
-{
+SkView* SkView::B2FIter::next() {
     SkView* curr = fChild;
 
-    if (fChild)
-    {
+    if (fChild) {
         SkView* next = fChild->fNextSibling;
         if (next == fFirstChild)
             next = NULL;
@@ -788,6 +776,17 @@
 
 #ifdef SK_DEBUG
 
+void SkView::validate() const {
+    if (fParent) {
+        SkASSERT(fNextSibling);
+        SkASSERT(fPrevSibling);
+    } else {
+        bool nextNull = NULL == fNextSibling;
+        bool prevNull = NULL == fNextSibling;
+        SkASSERT(nextNull && prevNull || !nextNull && !prevNull);
+    }
+}
+
 static inline void show_if_nonzero(const char name[], SkScalar value)
 {
     if (value)