Title: [103677] trunk/Source
Revision
103677
Author
m...@apple.com
Date
2011-12-25 21:20:02 -0800 (Sun, 25 Dec 2011)

Log Message

../WebCore: WebCore changes for: Find indicators overlap when a match spans multiple text boxes
https://bugs.webkit.org/show_bug.cgi?id=75220

Reviewed by Darin Adler.

* WebCore.exp.in: Exported new unionRect(const Vector<FloatRect>&) and existing
FloatRect::intersects().
* platform/graphics/FloatRect.cpp:
(WebCore::unionRect): Added.
* platform/graphics/FloatRect.h:

../WebKit2: Find indicators overlap when a match spans multiple text boxes
https://bugs.webkit.org/show_bug.cgi?id=75220

Reviewed by Darin Adler.

* UIProcess/FindIndicator.cpp:
(WebKit::findIndicatorsForTextRectsOverlap): Added this helper function that checks for
pairwise intersections between all indicator rects.
(WebKit::FindIndicator::FindIndicator): Changed to use a single rect (the union of all text
rects) if any two indicator rects would otherwise overlap. This is similar to what Safari
does, and it eliminates overlapping rects for adjacent text boxes. In rare cases (such as when
a match spans two lines and adjacent text boxes on one of those lines) it results in a find
indicator that is too large and obscures some non-match text.
* UIProcess/FindIndicator.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103676 => 103677)


--- trunk/Source/WebCore/ChangeLog	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebCore/ChangeLog	2011-12-26 05:20:02 UTC (rev 103677)
@@ -1,3 +1,16 @@
+2011-12-25  Dan Bernstein  <m...@apple.com>
+
+        WebCore changes for: Find indicators overlap when a match spans multiple text boxes
+        https://bugs.webkit.org/show_bug.cgi?id=75220
+
+        Reviewed by Darin Adler.
+
+        * WebCore.exp.in: Exported new unionRect(const Vector<FloatRect>&) and existing
+        FloatRect::intersects().
+        * platform/graphics/FloatRect.cpp:
+        (WebCore::unionRect): Added.
+        * platform/graphics/FloatRect.h:
+
 2011-12-25  Darin Adler  <da...@apple.com>
 
         Use OwnPtr for CSSFontFace::m_sources

Modified: trunk/Source/WebCore/WebCore.exp.in (103676 => 103677)


--- trunk/Source/WebCore/WebCore.exp.in	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebCore/WebCore.exp.in	2011-12-26 05:20:02 UTC (rev 103677)
@@ -1115,6 +1115,7 @@
 __ZN7WebCore9pageCacheEv
 __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorE
 __ZN7WebCore9toElementEN3JSC7JSValueE
+__ZN7WebCore9unionRectERKN3WTF6VectorINS_9FloatRectELm0EEE
 __ZNK3JSC8Bindings10RootObject12globalObjectEv
 __ZNK3WTF6String14createCFStringEv
 __ZNK7WebCore10Credential11hasPasswordEv
@@ -1423,6 +1424,7 @@
 __ZNK7WebCore8Position8upstreamENS_27EditingBoundaryCrossingRuleE
 __ZNK7WebCore9DOMWindow27pendingUnloadEventListenersEv
 __ZNK7WebCore9FloatQuad11boundingBoxEv
+__ZNK7WebCore9FloatRect10intersectsERKS0_
 __ZNK7WebCore9FloatRectcv7_NSRectEv
 __ZNK7WebCore9FrameTree12traverseNextEPKNS_5FrameE
 __ZNK7WebCore9FrameTree14isDescendantOfEPKNS_5FrameE

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.cpp (103676 => 103677)


--- trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.cpp	2011-12-26 05:20:02 UTC (rev 103677)
@@ -137,6 +137,17 @@
     m_size.setHeight(height() * sy);
 }
 
+FloatRect unionRect(const Vector<FloatRect>& rects)
+{
+    FloatRect result;
+
+    size_t count = rects.size();
+    for (size_t i = 0; i < count; ++i)
+        result.unite(rects[i]);
+
+    return result;
+}
+
 void FloatRect::fitToPoints(const FloatPoint& p0, const FloatPoint& p1)
 {
     float left = min(p0.x(), p1.x());

Modified: trunk/Source/WebCore/platform/graphics/FloatRect.h (103676 => 103677)


--- trunk/Source/WebCore/platform/graphics/FloatRect.h	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebCore/platform/graphics/FloatRect.h	2011-12-26 05:20:02 UTC (rev 103677)
@@ -28,6 +28,7 @@
 #define FloatRect_h
 
 #include "FloatPoint.h"
+#include <wtf/Vector.h>
 
 #if USE(CG) || USE(SKIA_ON_MAC_CHROMIUM)
 typedef struct CGRect CGRect;
@@ -239,6 +240,8 @@
     return c;
 }
 
+FloatRect unionRect(const Vector<FloatRect>&);
+
 inline FloatRect& operator+=(FloatRect& a, const FloatRect& b)
 {
     a.move(b.x(), b.y());

Modified: trunk/Source/WebKit2/ChangeLog (103676 => 103677)


--- trunk/Source/WebKit2/ChangeLog	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-26 05:20:02 UTC (rev 103677)
@@ -1,3 +1,20 @@
+2011-12-25  Dan Bernstein  <m...@apple.com>
+
+        Find indicators overlap when a match spans multiple text boxes
+        https://bugs.webkit.org/show_bug.cgi?id=75220
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/FindIndicator.cpp:
+        (WebKit::findIndicatorsForTextRectsOverlap): Added this helper function that checks for
+        pairwise intersections between all indicator rects.
+        (WebKit::FindIndicator::FindIndicator): Changed to use a single rect (the union of all text
+        rects) if any two indicator rects would otherwise overlap. This is similar to what Safari
+        does, and it eliminates overlapping rects for adjacent text boxes. In rare cases (such as when
+        a match spans two lines and adjacent text boxes on one of those lines) it results in a find
+        indicator that is too large and obscures some non-match text.
+        * UIProcess/FindIndicator.h:
+
 2011-12-21  Sam Weinig  <s...@webkit.org>
 
         Start extracting platform specific bits out of PlatformEvents

Modified: trunk/Source/WebKit2/UIProcess/FindIndicator.cpp (103676 => 103677)


--- trunk/Source/WebKit2/UIProcess/FindIndicator.cpp	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebKit2/UIProcess/FindIndicator.cpp	2011-12-26 05:20:02 UTC (rev 103677)
@@ -87,12 +87,42 @@
     return adoptRef(new FindIndicator(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImage.release()));
 }
 
+static bool findIndicatorsForTextRectsOverlap(const Vector<FloatRect>& textRects)
+{
+    size_t count = textRects.size();
+    if (count <= 1)
+        return false;
+
+    Vector<FloatRect> indicatorRects;
+    indicatorRects.reserveInitialCapacity(count);
+
+    for (size_t i = 0; i < count; ++i) {
+        FloatRect indicatorRect = textRects[i];
+        indicatorRect.move(-leftBorderThickness, -topBorderThickness);
+        indicatorRect.expand(leftBorderThickness + rightBorderThickness, topBorderThickness + bottomBorderThickness);
+
+        for (size_t j = indicatorRects.size(); j; ) {
+            --j;
+            if (indicatorRect.intersects(indicatorRects[j]))
+                return true;
+        }
+
+        indicatorRects.uncheckedAppend(indicatorRect);
+    }
+
+    return false;
+}
+
 FindIndicator::FindIndicator(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage)
     : m_selectionRectInWindowCoordinates(selectionRectInWindowCoordinates)
     , m_textRectsInSelectionRectCoordinates(textRectsInSelectionRectCoordinates)
     , m_contentImageScaleFactor(contentImageScaleFactor)
     , m_contentImage(contentImage)
 {
+    if (findIndicatorsForTextRectsOverlap(m_textRectsInSelectionRectCoordinates)) {
+        m_textRectsInSelectionRectCoordinates[0] = unionRect(m_textRectsInSelectionRectCoordinates);
+        m_textRectsInSelectionRectCoordinates.shrink(1);
+    }
 }
 
 FindIndicator::~FindIndicator()

Modified: trunk/Source/WebKit2/UIProcess/FindIndicator.h (103676 => 103677)


--- trunk/Source/WebKit2/UIProcess/FindIndicator.h	2011-12-26 04:46:34 UTC (rev 103676)
+++ trunk/Source/WebKit2/UIProcess/FindIndicator.h	2011-12-26 05:20:02 UTC (rev 103677)
@@ -46,8 +46,6 @@
     WebCore::FloatRect selectionRectInWindowCoordinates() const { return m_selectionRectInWindowCoordinates; }
     WebCore::FloatRect frameRect() const;
 
-    const Vector<WebCore::FloatRect>& textRects() const { return m_textRectsInSelectionRectCoordinates; }
-
     ShareableBitmap* contentImage() const { return m_contentImage.get(); }
 
     void draw(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to