../WebCore: WebCore changes for: Find indicators overlap when a match spans multiple...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Dec 2011 05:20:02 +0000 (05:20 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Dec 2011 05:20:02 +0000 (05:20 +0000)
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:

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/graphics/FloatRect.cpp
Source/WebCore/platform/graphics/FloatRect.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/FindIndicator.cpp
Source/WebKit2/UIProcess/FindIndicator.h

index 4b0705bd9498d31d9faa1a2e8a462767b4c4a8bd..52a8b22139fd5de29e7522134537674bab581e4e 100644 (file)
@@ -1,3 +1,16 @@
+2011-12-25  Dan Bernstein  <mitz@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  <darin@apple.com>
 
         Use OwnPtr for CSSFontFace::m_sources
index de3e77f275d8f416906a938c403d94ebcbdc14f2..76608e6ed2568890390fafde3d964542410dc640 100644 (file)
@@ -1115,6 +1115,7 @@ __ZN7WebCore9makeRangeERKNS_15VisiblePositionES2_
 __ZN7WebCore9pageCacheEv
 __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorE
 __ZN7WebCore9toElementEN3JSC7JSValueE
+__ZN7WebCore9unionRectERKN3WTF6VectorINS_9FloatRectELm0EEE
 __ZNK3JSC8Bindings10RootObject12globalObjectEv
 __ZNK3WTF6String14createCFStringEv
 __ZNK7WebCore10Credential11hasPasswordEv
@@ -1423,6 +1424,7 @@ __ZNK7WebCore8Position26trailingWhitespacePositionENS_9EAffinityEb
 __ZNK7WebCore8Position8upstreamENS_27EditingBoundaryCrossingRuleE
 __ZNK7WebCore9DOMWindow27pendingUnloadEventListenersEv
 __ZNK7WebCore9FloatQuad11boundingBoxEv
+__ZNK7WebCore9FloatRect10intersectsERKS0_
 __ZNK7WebCore9FloatRectcv7_NSRectEv
 __ZNK7WebCore9FrameTree12traverseNextEPKNS_5FrameE
 __ZNK7WebCore9FrameTree14isDescendantOfEPKNS_5FrameE
index 6d4a220657805095a5dbdb2eeed5eedb66f38938..fa9045c0b9ab680292155836ccf2144272143bc9 100644 (file)
@@ -137,6 +137,17 @@ void FloatRect::scale(float sx, float sy)
     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());
index 7de346fabe2efa73d91aff98e21d48627c463f86..ae6c23a7df00eb53db6ccefd16839f8b8727b6ff 100644 (file)
@@ -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 @@ inline FloatRect unionRect(const FloatRect& a, const FloatRect& b)
     return c;
 }
 
+FloatRect unionRect(const Vector<FloatRect>&);
+
 inline FloatRect& operator+=(FloatRect& a, const FloatRect& b)
 {
     a.move(b.x(), b.y());
index 49cb50afad4fcb64463ff4daf23440fb4850b115..27894f52062cfe3abc2a4242c56d2c88bce91d4e 100644 (file)
@@ -1,3 +1,20 @@
+2011-12-25  Dan Bernstein  <mitz@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  <sam@webkit.org>
 
         Start extracting platform specific bits out of PlatformEvents
index aee168b4b49e5920816c75402b382c0bfd622cb0..e3dfe6f4dd7e2fddbdcf0bde44606611c24129cf 100644 (file)
@@ -87,12 +87,42 @@ PassRefPtr<FindIndicator> FindIndicator::create(const FloatRect& selectionRectIn
     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()
index 04afd9bbd7a1a2d9a89d86070341c28d580afaa0..a34973b8423622f39e43c41940e57d8aa47c7875 100644 (file)
@@ -46,8 +46,6 @@ public:
     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);