add onSendClickToChildren to views, so a view can capture all clicks.
speedup some of the unittests that were too slow
minor cleanup in SkScan_Path, in prep for larger changes



git-svn-id: http://skia.googlecode.com/svn/trunk@426 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/views/SkView.h b/include/views/SkView.h
index 1bdd0b6..f3b729f 100644
--- a/include/views/SkView.h
+++ b/include/views/SkView.h
@@ -314,7 +314,13 @@
 
     /** Override this if you might handle the click
     */
-    virtual Click*  onFindClickHandler(SkScalar x, SkScalar y);
+    virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
+    /** Override this to decide if your children are targets for a click.
+        The default returns true, in which case your children views will be
+        candidates for onFindClickHandler. Returning false wil skip the children
+        and just call your onFindClickHandler.
+     */
+    virtual bool onSendClickToChildren(SkScalar x, SkScalar y);
     /** Override this to track clicks, returning true as long as you want to track
         the pen/mouse.
     */
diff --git a/samplecode/OverView.cpp b/samplecode/OverView.cpp
index e2abec2..2ae2119 100644
--- a/samplecode/OverView.cpp
+++ b/samplecode/OverView.cpp
@@ -29,7 +29,11 @@
         return this->INHERITED::onQuery(evt);
     }
 
-    virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
+    virtual bool onSendClickToChildren(SkScalar x, SkScalar y) {
+        return false;
+    }
+
+    virtual Click* onFindClickHandler(SkScalar x, SkScalar y) {
         int ix = (int)(SkScalarDiv(x * N, W));
         int iy = (int)(SkScalarDiv(y * N, H));
         if (ix >= 0 && iy >= 0) {
@@ -88,4 +92,3 @@
     return canvas;
 }
 
-
diff --git a/samplecode/SamplePathClip.cpp b/samplecode/SamplePathClip.cpp
index ece64ae..a126cbf 100644
--- a/samplecode/SamplePathClip.cpp
+++ b/samplecode/SamplePathClip.cpp
@@ -119,9 +119,13 @@
               SkIntToScalar(250), SkIntToScalar(400));
         canvas->drawOval(oval, p);
     }
-    
+
     virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) {
-        fCenter.set(x, y);
+        return new Click(this);
+    }
+        
+    virtual bool onClick(Click* click) {
+        fCenter.set(click->fCurr.fX, click->fCurr.fY);
         this->inval(NULL);
         return NULL;
     }
diff --git a/src/core/SkScan_Path.cpp b/src/core/SkScan_Path.cpp
index 8246376..6d05225 100644
--- a/src/core/SkScan_Path.cpp
+++ b/src/core/SkScan_Path.cpp
@@ -369,43 +369,6 @@
     return (int)(list - start);
 }
 
-extern "C" {
-    static int edge_compare(const void* a, const void* b)
-    {
-        const SkEdge* edgea = *(const SkEdge**)a;
-        const SkEdge* edgeb = *(const SkEdge**)b;
-
-        int valuea = edgea->fFirstY;
-        int valueb = edgeb->fFirstY;
-
-        if (valuea == valueb)
-        {
-            valuea = edgea->fX;
-            valueb = edgeb->fX;
-        }
-
-        // this overflows if valuea >>> valueb or vice-versa
-        //     return valuea - valueb;
-        // do perform the slower but safe compares
-        return (valuea < valueb) ? -1 : (valuea > valueb);
-    }
-}
-
-static SkEdge* sort_edges(SkEdge* list[], int count, SkEdge** last)
-{
-    qsort(list, count, sizeof(SkEdge*), edge_compare);
-
-    // now make the edges linked in sorted order
-    for (int i = 1; i < count; i++)
-    {
-        list[i - 1]->fNext = list[i];
-        list[i]->fPrev = list[i - 1];
-    }
-
-    *last = list[count - 1];
-    return list[0];
-}
-
 #ifdef SK_DEBUG
 /* 'quick' computation of the max sized needed to allocated for
     our edgelist.
@@ -466,6 +429,41 @@
     return edgeCount;
 }
 
+///////////////////////////////////////////////////////////////////////////////
+
+extern "C" {
+    static int edge_compare(const void* a, const void* b) {
+        const SkEdge* edgea = *(const SkEdge**)a;
+        const SkEdge* edgeb = *(const SkEdge**)b;
+        
+        int valuea = edgea->fFirstY;
+        int valueb = edgeb->fFirstY;
+        
+        if (valuea == valueb) {
+            valuea = edgea->fX;
+            valueb = edgeb->fX;
+        }
+        
+        // this overflows if valuea >>> valueb or vice-versa
+        //     return valuea - valueb;
+        // do perform the slower but safe compares
+        return (valuea < valueb) ? -1 : (valuea > valueb);
+    }
+}
+
+static SkEdge* sort_edges(SkEdge* list[], int count, SkEdge** last) {
+    qsort(list, count, sizeof(SkEdge*), edge_compare);
+    
+    // now make the edges linked in sorted order
+    for (int i = 1; i < count; i++) {
+        list[i - 1]->fNext = list[i];
+        list[i]->fPrev = list[i - 1];
+    }
+    
+    *last = list[count - 1];
+    return list[0];
+}
+
 // clipRect may be null, even though we always have a clip. This indicates that
 // the path is contained in the clip, and so we can ignore it during the blit
 //
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 7797abe..1bbe3da 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -343,18 +343,23 @@
 
 SkView::Click* SkView::findClickHandler(SkScalar x, SkScalar y)
 {
-	if (x < 0 || y < 0 || x >= fWidth || y >= fHeight)
+	if (x < 0 || y < 0 || x >= fWidth || y >= fHeight) {
 		return false;
+    }
 
-	F2BIter	iter(this);
-	SkView*	child;
+    if (this->onSendClickToChildren(x, y)) {
+        F2BIter	iter(this);
+        SkView*	child;
 
-	while ((child = iter.next()) != NULL)
-	{
-		Click* click = child->findClickHandler(x - child->fLoc.fX, y - child->fLoc.fY);
-		if (click)
-			return click;
-	}
+        while ((child = iter.next()) != NULL)
+        {
+            Click* click = child->findClickHandler(x - child->fLoc.fX,
+                                                   y - child->fLoc.fY);
+            if (click) {
+                return click;
+            }
+        }
+    }
 	return this->onFindClickHandler(x, y);
 }
 
@@ -417,38 +422,37 @@
 
 //////////////////////////////////////////////////////////////////////
 
-void SkView::invokeLayout()
-{
+void SkView::invokeLayout() {
 	SkView::Layout* layout = this->getLayout();
 
-	if (layout)
+	if (layout) {
 		layout->layoutChildren(this);
+    }
 }
 
-void SkView::onDraw(SkCanvas* canvas)
-{
+void SkView::onDraw(SkCanvas* canvas) {
 	Artist* artist = this->getArtist();
 
-	if (artist)
+	if (artist) {
 		artist->draw(this, canvas);
+    }
 }
 
-void SkView::onSizeChange()
-{
+void SkView::onSizeChange() {}
+
+bool SkView::onSendClickToChildren(SkScalar x, SkScalar y) {
+    return true;
 }
 
-SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y)
-{
+SkView::Click* SkView::onFindClickHandler(SkScalar x, SkScalar y) {
 	return NULL;
 }
 
-bool SkView::onClick(Click*)
-{
+bool SkView::onClick(Click*) {
 	return false;
 }
 
-bool SkView::handleInval(const SkRect& r)
-{
+bool SkView::handleInval(const SkRect& r) {
 	return false;
 }
 
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index dddd2da..09e3748 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -235,7 +235,7 @@
         REPORTER_ASSERT(reporter, clamp == clamp2);
     }
 
-    for (i = 0; i < 100000; i++) {
+    for (i = 0; i < 10000; i++) {
         SkPoint p;
 
         p.setLength(rand.nextS(), rand.nextS(), SK_Scalar1);
@@ -256,7 +256,7 @@
 #endif
 
 #ifdef SkLONGLONG
-    for (i = 0; i < 100000; i++) {
+    for (i = 0; i < 10000; i++) {
         SkFixed numer = rand.nextS();
         SkFixed denom = rand.nextS();
         SkFixed result = SkFixedDiv(numer, denom);
@@ -321,7 +321,7 @@
 #endif
 
 #ifdef SK_CAN_USE_FLOAT
-    for (i = 0; i < 100000; i++) {
+    for (i = 0; i < 10000; i++) {
         SkFract x = rand.nextU() >> 1;
         double xx = (double)x / SK_Fract1;
         SkFract xr = SkFractSqrt(x);
@@ -351,7 +351,7 @@
     }
 
     int maxDiff = 0;
-    for (i = 0; i < 10000; i++) {
+    for (i = 0; i < 1000; i++) {
         SkFixed rads = rand.nextS() >> 10;
         double frads = SkFixedToFloat(rads);
 
diff --git a/tests/PackBitsTest.cpp b/tests/PackBitsTest.cpp
index 729467e..a22590c 100644
--- a/tests/PackBitsTest.cpp
+++ b/tests/PackBitsTest.cpp
@@ -90,7 +90,7 @@
     }
 
     for (size_t size = 1; size <= 512; size += 1) {
-        for (int n = 200; n; n--) {
+        for (int n = 100; n; n--) {
             uint8_t src[600], src2[600];
             uint8_t dst[600];
             rand_fill(src, size);
@@ -104,7 +104,7 @@
             bool match = memcmp(src, src2, size * sizeof(uint8_t)) == 0;
             REPORTER_ASSERT(reporter, match);
 
-            for (int j = 0; j < 200; j++) {
+            for (int j = 0; j < 100; j++) {
                 size_t skip = gRand.nextU() % size;
                 size_t write = gRand.nextU() % size;
                 if (skip + write > size) {