add validate to SkView for debugging

git-svn-id: http://skia.googlecode.com/svn/trunk@9596 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2013-06-13 20:20:17 +00:00
parent f09b87dda3
commit a25c94e50a
2 changed files with 64 additions and 60 deletions

View File

@ -373,6 +373,11 @@ protected:
virtual bool onGetFocusView(SkView**) const { return false; }
virtual bool onSetFocusView(SkView*) { return false; }
#ifdef SK_DEBUG
void validate() const;
#else
void validate() const {}
#endif
private:
SkScalar fWidth, fHeight;
SkMatrix fMatrix;

View File

@ -509,55 +509,58 @@ bool SkView::handleInval(const SkRect*) {
//////////////////////////////////////////////////////////////////////
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 @@ SkView* SkView::attachChildToBack(SkView* child)
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 @@ SkView* SkView::attachChildToBack(SkView* child)
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 @@ SkView* SkView::attachChildToFront(SkView* child)
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 @@ SkView* SkView::attachChildToFront(SkView* child)
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 @@ bool SkView::globalToLocal(SkScalar x, SkScalar y, SkPoint* local) const
/* 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 @@ void SkView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
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 @@ void SkView::postInflate(const SkTDict<SkView*>& dict)
//////////////////////////////////////////////////////////////////
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* SkView::sendQueryToParents(SkEvent* evt) {
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
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 @@ SkView* SkView::B2FIter::next()
#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)