Title: [188526] trunk/Source
Revision
188526
Author
[email protected]
Date
2015-08-17 10:50:09 -0700 (Mon, 17 Aug 2015)

Log Message

Adopt shrink-wrapping for TextIndicators on Mac
https://bugs.webkit.org/show_bug.cgi?id=148064

Reviewed by Beth Dakin.

Instead of indicating the bounding rect when there are multiple text rects,
use shrink-wrapping for TextIndicatorWindow (on Mac), like we do on iOS.

* bindings/objc/DOM.mm:
(-[DOMNode getPreviewSnapshotImage:andRects:]):
Make getPreviewSnapshotImage use the same options that iOS WebKit2 uses.
This fixes a regression from r188420 where iOS WebKit1 TextIndicators lost
all of the relevant (previously hardcoded inside TextIndicator) options.

* page/TextIndicator.cpp:
(WebCore::TextIndicator::createWithRange):
(WebCore::TextIndicator::createWithSelectionInFrame):
(WebCore::initializeIndicator):
Don't keep indicatesCurrentSelection in TextIndicatorData. Instead,
just pass it through to initializeIndicator. Add a flag which stops us
from zeroing out the margin if indicatesCurrentSelection is true.
Move default margins into TextIndicator so they can be applied to the stored rects
just like on iOS, instead of trying to apply them later like we used to on Mac.

* page/TextIndicator.h:
(WebCore::TextIndicator::indicatesCurrentSelection): Deleted.
* page/mac/TextIndicatorWindow.h:
* page/mac/TextIndicatorWindow.mm:
(-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
(WebCore::TextIndicatorWindow::setTextIndicator):
(outsetIndicatorRectIncludingShadow): Deleted.
(textIndicatorsForTextRectsOverlap): Deleted.
Make use of pathsWithShrinkWrappedRects for TextIndicatorWindow, instead
of just smushing all intersecting rects together. Use the computed path
for the shadows and to mask the yellow highlight and snapshot layer.

* platform/graphics/PathUtilities.cpp:
(WebCore::PathUtilities::pathsWithShrinkWrappedRects):
(WebCore::PathUtilities::pathWithShrinkWrappedRects):
* platform/graphics/PathUtilities.h:
Make it possible to retrieve each non-intersecting path individually, instead
of just a single giant Path, so that TextIndicatorWindow can make separate
layers for each one (so they can bounce separately).

* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<TextIndicatorData>::encode): Deleted.
(IPC::ArgumentCoder<TextIndicatorData>::decode): Deleted.
* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::updateFindIndicator):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPositionInformation):
Use the new option, TextIndicatorOptionIncludeMarginIfRangeMatchesSelection,
for iOS and FindController, because we can keep the margins in these cases
because we don't have to animate to/from the blue highlight.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (188525 => 188526)


--- trunk/Source/WebCore/ChangeLog	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/ChangeLog	2015-08-17 17:50:09 UTC (rev 188526)
@@ -1,3 +1,49 @@
+2015-08-17  Timothy Horton  <[email protected]>
+
+        Adopt shrink-wrapping for TextIndicators on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=148064
+
+        Reviewed by Beth Dakin.
+
+        Instead of indicating the bounding rect when there are multiple text rects,
+        use shrink-wrapping for TextIndicatorWindow (on Mac), like we do on iOS.
+
+        * bindings/objc/DOM.mm:
+        (-[DOMNode getPreviewSnapshotImage:andRects:]):
+        Make getPreviewSnapshotImage use the same options that iOS WebKit2 uses.
+        This fixes a regression from r188420 where iOS WebKit1 TextIndicators lost
+        all of the relevant (previously hardcoded inside TextIndicator) options.
+
+        * page/TextIndicator.cpp:
+        (WebCore::TextIndicator::createWithRange):
+        (WebCore::TextIndicator::createWithSelectionInFrame):
+        (WebCore::initializeIndicator):
+        Don't keep indicatesCurrentSelection in TextIndicatorData. Instead,
+        just pass it through to initializeIndicator. Add a flag which stops us
+        from zeroing out the margin if indicatesCurrentSelection is true.
+        Move default margins into TextIndicator so they can be applied to the stored rects
+        just like on iOS, instead of trying to apply them later like we used to on Mac.
+
+        * page/TextIndicator.h:
+        (WebCore::TextIndicator::indicatesCurrentSelection): Deleted.
+        * page/mac/TextIndicatorWindow.h:
+        * page/mac/TextIndicatorWindow.mm:
+        (-[WebTextIndicatorView initWithFrame:textIndicator:margin:offset:]):
+        (WebCore::TextIndicatorWindow::setTextIndicator):
+        (outsetIndicatorRectIncludingShadow): Deleted.
+        (textIndicatorsForTextRectsOverlap): Deleted.
+        Make use of pathsWithShrinkWrappedRects for TextIndicatorWindow, instead
+        of just smushing all intersecting rects together. Use the computed path
+        for the shadows and to mask the yellow highlight and snapshot layer.
+
+        * platform/graphics/PathUtilities.cpp:
+        (WebCore::PathUtilities::pathsWithShrinkWrappedRects):
+        (WebCore::PathUtilities::pathWithShrinkWrappedRects):
+        * platform/graphics/PathUtilities.h:
+        Make it possible to retrieve each non-intersecting path individually, instead
+        of just a single giant Path, so that TextIndicatorWindow can make separate
+        layers for each one (so they can bounce separately).
+
 2015-08-17  Simon Fraser  <[email protected]>
 
         Remove some includes from Node.cpp

Modified: trunk/Source/WebCore/bindings/objc/DOM.mm (188525 => 188526)


--- trunk/Source/WebCore/bindings/objc/DOM.mm	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/bindings/objc/DOM.mm	2015-08-17 17:50:09 UTC (rev 188526)
@@ -596,7 +596,12 @@
     Ref<Range> range = rangeOfContents(*coreNode);
 
     const float margin = 4 / coreNode->document().page()->pageScaleFactor();
-    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, TextIndicatorOptionDefault, TextIndicatorPresentationTransition::None, margin);
+    RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(range, TextIndicatorOptionTightlyFitContent |
+        TextIndicatorOptionRespectTextColor |
+        TextIndicatorOptionPaintBackgrounds |
+        TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges |
+        TextIndicatorOptionIncludeMarginIfRangeMatchesSelection,
+        TextIndicatorPresentationTransition::None, FloatSize(margin, margin));
 
     if (textIndicator) {
         if (Image* image = textIndicator->contentImage())

Modified: trunk/Source/WebCore/page/TextIndicator.cpp (188525 => 188526)


--- trunk/Source/WebCore/page/TextIndicator.cpp	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/page/TextIndicator.cpp	2015-08-17 17:50:09 UTC (rev 188526)
@@ -46,7 +46,7 @@
 
 namespace WebCore {
 
-static bool initializeIndicator(TextIndicatorData&, Frame&, const Range&, unsigned margin);
+static bool initializeIndicator(TextIndicatorData&, Frame&, const Range&, FloatSize margin, bool indicatesCurrentSelection);
 
 TextIndicator::TextIndicator(const TextIndicatorData& data)
     : m_data(data)
@@ -62,7 +62,7 @@
     return adoptRef(*new TextIndicator(data));
 }
 
-RefPtr<TextIndicator> TextIndicator::createWithRange(const Range& range, TextIndicatorOptions options, TextIndicatorPresentationTransition presentationTransition, unsigned margin)
+RefPtr<TextIndicator> TextIndicator::createWithRange(const Range& range, TextIndicatorOptions options, TextIndicatorPresentationTransition presentationTransition, FloatSize margin)
 {
     Frame* frame = range.startContainer()->document().frame();
 
@@ -80,10 +80,11 @@
     TextIndicatorData data;
 
     data.presentationTransition = presentationTransition;
-    data.indicatesCurrentSelection = !areRangesEqual(&range, oldSelection.toNormalizedRange().get());
     data.options = options;
 
-    if (!initializeIndicator(data, *frame, range, margin))
+    bool indicatesCurrentSelection = areRangesEqual(&range, oldSelection.toNormalizedRange().get());
+
+    if (!initializeIndicator(data, *frame, range, margin, indicatesCurrentSelection))
         return nullptr;
 
     RefPtr<TextIndicator> indicator = TextIndicator::create(data);
@@ -98,7 +99,7 @@
     return indicator;
 }
 
-RefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(Frame& frame, TextIndicatorOptions options, TextIndicatorPresentationTransition presentationTransition, unsigned margin)
+RefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(Frame& frame, TextIndicatorOptions options, TextIndicatorPresentationTransition presentationTransition, FloatSize margin)
 {
     RefPtr<Range> range = frame.selection().toNormalizedRange();
     if (!range)
@@ -107,10 +108,9 @@
     TextIndicatorData data;
 
     data.presentationTransition = presentationTransition;
-    data.indicatesCurrentSelection = true;
     data.options = options;
 
-    if (!initializeIndicator(data, frame, *range, margin))
+    if (!initializeIndicator(data, frame, *range, margin, true))
         return nullptr;
 
     return TextIndicator::create(data);
@@ -175,10 +175,16 @@
     return true;
 }
 
-static bool initializeIndicator(TextIndicatorData& data, Frame& frame, const Range& range, unsigned margin)
+static bool initializeIndicator(TextIndicatorData& data, Frame& frame, const Range& range, FloatSize margin, bool indicatesCurrentSelection)
 {
     Vector<FloatRect> textRects;
 
+    // FIXME (138888): Ideally we wouldn't remove the margin in this case, but we need to
+    // ensure that the indicator and indicator-with-highlight overlap precisely, and
+    // we can't add a margin to the indicator-with-highlight.
+    if (indicatesCurrentSelection && !(data.options & TextIndicatorOptionIncludeMarginIfRangeMatchesSelection))
+        margin = FloatSize();
+
     FrameSelection::TextRectangleHeight textRectHeight = (data.options & TextIndicatorOptionTightlyFitContent) ? FrameSelection::TextRectangleHeight::TextHeight : FrameSelection::TextRectangleHeight::SelectionHeight;
 
     if ((data.options & TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges) && hasNonInlineOrReplacedElements(range))
@@ -203,7 +209,8 @@
     Vector<FloatRect> textRectsInRootViewCoordinates;
     for (const FloatRect& textRect : textRects) {
         FloatRect textRectInDocumentCoordinatesIncludingMargin = textRect;
-        textRectInDocumentCoordinatesIncludingMargin.inflate(margin);
+        textRectInDocumentCoordinatesIncludingMargin.inflateX(margin.width());
+        textRectInDocumentCoordinatesIncludingMargin.inflateY(margin.height());
         textBoundingRectInDocumentCoordinates.unite(textRectInDocumentCoordinatesIncludingMargin);
 
         FloatRect textRectInRootViewCoordinates = frame.view()->contentsToRootView(enclosingIntRect(textRectInDocumentCoordinatesIncludingMargin));

Modified: trunk/Source/WebCore/page/TextIndicator.h (188525 => 188526)


--- trunk/Source/WebCore/page/TextIndicator.h	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/page/TextIndicator.h	2015-08-17 17:50:09 UTC (rev 188526)
@@ -32,6 +32,12 @@
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
+#define ENABLE_LEGACY_TEXT_INDICATOR_STYLE 1
+#else
+#define ENABLE_LEGACY_TEXT_INDICATOR_STYLE 0
+#endif
+
 namespace WebCore {
 
 class Frame;
@@ -73,7 +79,11 @@
 
     // If there are any non-inline or replaced elements in the Range, indicate the bounding rect
     // of the range instead of the individual subrects, and don't restrict painting to the given Range
-    TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges = 1 << 5
+    TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges = 1 << 5,
+
+    // By default, TextIndicator removes any margin if the given Range matches the
+    // selection Range. If this option is set, maintain the margin in any case.
+    TextIndicatorOptionIncludeMarginIfRangeMatchesSelection = 1 << 6,
 };
 typedef uint8_t TextIndicatorOptions;
 
@@ -85,15 +95,24 @@
     RefPtr<Image> contentImageWithHighlight;
     RefPtr<Image> contentImage;
     TextIndicatorPresentationTransition presentationTransition;
-    bool indicatesCurrentSelection;
     TextIndicatorOptions options;
 };
 
 class TextIndicator : public RefCounted<TextIndicator> {
 public:
+    // FIXME: These are fairly Mac-specific, and they don't really belong here.
+    // But they're needed at TextIndicator creation time, so they can't go in TextIndicatorWindow.
+    // Maybe they can live in some Theme code somewhere?
+#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
+    constexpr static float defaultHorizontalMargin { 3 };
+#else
+    constexpr static float defaultHorizontalMargin { 2 };
+#endif
+    constexpr static float defaultVerticalMargin { 1 };
+
     WEBCORE_EXPORT static Ref<TextIndicator> create(const TextIndicatorData&);
-    WEBCORE_EXPORT static RefPtr<TextIndicator> createWithSelectionInFrame(Frame&, TextIndicatorOptions, TextIndicatorPresentationTransition, unsigned margin = 0);
-    WEBCORE_EXPORT static RefPtr<TextIndicator> createWithRange(const Range&, TextIndicatorOptions, TextIndicatorPresentationTransition, unsigned margin = 0);
+    WEBCORE_EXPORT static RefPtr<TextIndicator> createWithSelectionInFrame(Frame&, TextIndicatorOptions, TextIndicatorPresentationTransition, FloatSize margin = FloatSize(defaultHorizontalMargin, defaultVerticalMargin));
+    WEBCORE_EXPORT static RefPtr<TextIndicator> createWithRange(const Range&, TextIndicatorOptions, TextIndicatorPresentationTransition, FloatSize margin = FloatSize(defaultHorizontalMargin, defaultVerticalMargin));
 
     WEBCORE_EXPORT ~TextIndicator();
 
@@ -109,8 +128,6 @@
 
     TextIndicatorData data() const { return m_data; }
 
-    bool indicatesCurrentSelection() const { return m_data.indicatesCurrentSelection; }
-
 private:
     TextIndicator(const TextIndicatorData&);
 

Modified: trunk/Source/WebCore/page/mac/TextIndicatorWindow.h (188525 => 188526)


--- trunk/Source/WebCore/page/mac/TextIndicatorWindow.h	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/page/mac/TextIndicatorWindow.h	2015-08-17 17:50:09 UTC (rev 188526)
@@ -32,12 +32,6 @@
 #import <wtf/RetainPtr.h>
 #import <wtf/RunLoop.h>
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
-#define ENABLE_LEGACY_TEXT_INDICATOR_STYLE 1
-#else
-#define ENABLE_LEGACY_TEXT_INDICATOR_STYLE 0
-#endif
-
 OBJC_CLASS NSView;
 OBJC_CLASS WebTextIndicatorView;
 

Modified: trunk/Source/WebCore/page/mac/TextIndicatorWindow.mm (188525 => 188526)


--- trunk/Source/WebCore/page/mac/TextIndicatorWindow.mm	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/page/mac/TextIndicatorWindow.mm	2015-08-17 17:50:09 UTC (rev 188526)
@@ -31,6 +31,7 @@
 #import "CoreGraphicsSPI.h"
 #import "GeometryUtilities.h"
 #import "GraphicsContext.h"
+#import "PathUtilities.h"
 #import "QuartzCoreSPI.h"
 #import "TextIndicator.h"
 #import "WebActionDisablingCALayerDelegate.h"
@@ -43,8 +44,6 @@
 
 #if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
 const CGFloat midBounceScale = 1.5;
-const CGFloat horizontalBorder = 3;
-const CGFloat verticalBorder = 1;
 const CGFloat borderWidth = 1.0;
 const CGFloat cornerRadius = 3;
 const CGFloat dropShadowOffsetX = 0;
@@ -52,8 +51,6 @@
 const CGFloat dropShadowBlurRadius = 1.5;
 #else
 const CGFloat midBounceScale = 1.25;
-const CGFloat horizontalBorder = 2;
-const CGFloat verticalBorder = 1;
 const CGFloat borderWidth = 0;
 const CGFloat cornerRadius = 0;
 const CGFloat dropShadowOffsetX = 0;
@@ -92,38 +89,6 @@
 
 @synthesize fadingOut = _fadingOut;
 
-static FloatRect outsetIndicatorRectIncludingShadow(const FloatRect rect)
-{
-    FloatRect outsetRect = rect;
-    outsetRect.inflateX(dropShadowBlurRadius + horizontalBorder);
-    outsetRect.inflateY(dropShadowBlurRadius + verticalBorder);
-    return outsetRect;
-}
-
-static bool textIndicatorsForTextRectsOverlap(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 = outsetIndicatorRectIncludingShadow(textRects[i]);
-
-        for (size_t j = indicatorRects.size(); j; ) {
-            --j;
-            if (indicatorRect.intersects(indicatorRects[j]))
-                return true;
-        }
-
-        indicatorRects.uncheckedAppend(indicatorRect);
-    }
-
-    return false;
-}
-
 static bool indicatorWantsBounce(const TextIndicator& indicator)
 {
     switch (indicator.presentationTransition()) {
@@ -221,19 +186,22 @@
     RetainPtr<CGColorRef> gradientLightColor = [NSColor colorWithDeviceRed:.949 green:.937 blue:0 alpha:1].CGColor;
 
     Vector<FloatRect> textRectsInBoundingRectCoordinates = _textIndicator->textRectsInBoundingRectCoordinates();
-    if (textIndicatorsForTextRectsOverlap(textRectsInBoundingRectCoordinates)) {
-        textRectsInBoundingRectCoordinates[0] = unionRect(textRectsInBoundingRectCoordinates);
-        textRectsInBoundingRectCoordinates.shrink(1);
-    }
 
-    for (const auto& textRect : textRectsInBoundingRectCoordinates) {
-        FloatRect offsetTextRect = textRect;
+    Vector<Path> paths = PathUtilities::pathsWithShrinkWrappedRects(textRectsInBoundingRectCoordinates, cornerRadius);
+
+    for (const auto& path : paths) {
+        FloatRect pathBoundingRect = path.boundingRect();
+
+        Path translatedPath;
+        AffineTransform transform;
+        transform.translate(-pathBoundingRect.x(), -pathBoundingRect.y());
+        translatedPath.addPath(path, transform);
+
+        FloatRect offsetTextRect = pathBoundingRect;
         offsetTextRect.move(offset.x, offset.y);
 
         FloatRect bounceLayerRect = offsetTextRect;
         bounceLayerRect.move(_margin.width, _margin.height);
-        bounceLayerRect.inflateX(horizontalBorder);
-        bounceLayerRect.inflateY(verticalBorder);
 
         RetainPtr<CALayer> bounceLayer = adoptNS([[CALayer alloc] init]);
         [bounceLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
@@ -242,22 +210,15 @@
         [bounceLayers addObject:bounceLayer.get()];
 
         FloatRect yellowHighlightRect(FloatPoint(), bounceLayerRect.size());
-        // FIXME (138888): Ideally we wouldn't remove the margin in this case, but we need to
-        // ensure that the yellow highlight and contentImageWithHighlight overlap precisely.
-        if (!_textIndicator->indicatesCurrentSelection()) {
-            yellowHighlightRect.inflateX(-horizontalBorder);
-            yellowHighlightRect.inflateY(-verticalBorder);
-        }
 
         RetainPtr<CALayer> dropShadowLayer = adoptNS([[CALayer alloc] init]);
         [dropShadowLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
         [dropShadowLayer setShadowColor:dropShadowColor.get()];
         [dropShadowLayer setShadowRadius:dropShadowBlurRadius];
         [dropShadowLayer setShadowOffset:CGSizeMake(dropShadowOffsetX, dropShadowOffsetY)];
-        [dropShadowLayer setShadowPathIsBounds:YES];
+        [dropShadowLayer setShadowPath:translatedPath.platformPath()];
         [dropShadowLayer setShadowOpacity:1];
         [dropShadowLayer setFrame:yellowHighlightRect];
-        [dropShadowLayer setCornerRadius:cornerRadius];
         [bounceLayer addSublayer:dropShadowLayer.get()];
         [bounceLayer setValue:dropShadowLayer.get() forKey:dropShadowLayerKey];
 
@@ -267,11 +228,10 @@
         [rimShadowLayer setFrame:yellowHighlightRect];
         [rimShadowLayer setShadowColor:rimShadowColor.get()];
         [rimShadowLayer setShadowRadius:rimShadowBlurRadius];
-        [rimShadowLayer setShadowPathIsBounds:YES];
+        [rimShadowLayer setShadowPath:translatedPath.platformPath()];
         [rimShadowLayer setShadowOffset:CGSizeZero];
         [rimShadowLayer setShadowOpacity:1];
         [rimShadowLayer setFrame:yellowHighlightRect];
-        [rimShadowLayer setCornerRadius:cornerRadius];
         [bounceLayer addSublayer:rimShadowLayer.get()];
         [bounceLayer setValue:rimShadowLayer.get() forKey:rimShadowLayerKey];
 #endif
@@ -288,12 +248,15 @@
         [textLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
         [textLayer setContents:(id)contentsImage.get()];
 
-        FloatRect imageRect = textRect;
+        RetainPtr<CAShapeLayer> maskLayer = adoptNS([[CAShapeLayer alloc] init]);
+        [maskLayer setPath:translatedPath.platformPath()];
+        [textLayer setMask:maskLayer.get()];
+
+        FloatRect imageRect = pathBoundingRect;
         [textLayer setContentsRect:CGRectMake(imageRect.x() / contentsImageLogicalSize.width(), imageRect.y() / contentsImageLogicalSize.height(), imageRect.width() / contentsImageLogicalSize.width(), imageRect.height() / contentsImageLogicalSize.height())];
         [textLayer setContentsGravity:kCAGravityCenter];
         [textLayer setContentsScale:_textIndicator->contentImageScaleFactor()];
         [textLayer setFrame:yellowHighlightRect];
-        [textLayer setCornerRadius:cornerRadius];
         [bounceLayer setValue:textLayer.get() forKey:textLayerKey];
         [bounceLayer addSublayer:textLayer.get()];
     }
@@ -500,8 +463,8 @@
 
     m_textIndicator = textIndicator.ptr();
 
-    CGFloat horizontalMargin = dropShadowBlurRadius * 2 + horizontalBorder;
-    CGFloat verticalMargin = dropShadowBlurRadius * 2 + verticalBorder;
+    CGFloat horizontalMargin = dropShadowBlurRadius * 2 + TextIndicator::defaultHorizontalMargin;
+    CGFloat verticalMargin = dropShadowBlurRadius * 2 + TextIndicator::defaultVerticalMargin;
     
     if (indicatorWantsBounce(*m_textIndicator)) {
         horizontalMargin = std::max(horizontalMargin, textBoundingRectInScreenCoordinates.size.width * (midBounceScale - 1) + horizontalMargin);

Modified: trunk/Source/WebCore/platform/graphics/PathUtilities.cpp (188525 => 188526)


--- trunk/Source/WebCore/platform/graphics/PathUtilities.cpp	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/platform/graphics/PathUtilities.cpp	2015-08-17 17:50:09 UTC (rev 188526)
@@ -27,6 +27,7 @@
 #include "config.h"
 #include "PathUtilities.h"
 
+#include "AffineTransform.h"
 #include "FloatPoint.h"
 #include "FloatRect.h"
 #include "GeometryUtilities.h"
@@ -254,16 +255,18 @@
     });
 }
 
-Path PathUtilities::pathWithShrinkWrappedRects(const Vector<FloatRect>& rects, float radius)
+Vector<Path> PathUtilities::pathsWithShrinkWrappedRects(const Vector<FloatRect>& rects, float radius)
 {
-    Path path;
+    Vector<Path> paths;
 
     if (rects.isEmpty())
-        return path;
+        return paths;
 
     if (rects.size() > 20) {
+        Path path;
         path.addRoundedRect(unionRect(rects), FloatSize(radius, radius));
-        return path;
+        paths.append(path);
+        return paths;
     }
 
     Vector<FloatRect> sortedRects = rects;
@@ -292,11 +295,14 @@
     Vector<FloatPointGraph::Polygon> polys = unitePolygons(rectPolygons, graph);
 
     if (polys.isEmpty()) {
+        Path path;
         path.addRoundedRect(unionRect(sortedRects), FloatSize(radius, radius));
-        return path;
+        paths.append(path);
+        return paths;
     }
 
     for (auto& poly : polys) {
+        Path path;
         for (unsigned i = 0; i < poly.size(); i++) {
             FloatPointGraph::Edge& toEdge = poly[i];
             // Connect the first edge to the last.
@@ -327,9 +333,21 @@
         }
 
         path.closeSubpath();
+        paths.append(path);
     }
 
-    return path;
+    return paths;
 }
 
+Path PathUtilities::pathWithShrinkWrappedRects(const Vector<FloatRect>& rects, float radius)
+{
+    Vector<Path> paths = pathsWithShrinkWrappedRects(rects, radius);
+
+    Path unionPath;
+    for (const auto& path : paths)
+        unionPath.addPath(path, AffineTransform());
+
+    return unionPath;
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/PathUtilities.h (188525 => 188526)


--- trunk/Source/WebCore/platform/graphics/PathUtilities.h	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebCore/platform/graphics/PathUtilities.h	2015-08-17 17:50:09 UTC (rev 188526)
@@ -34,6 +34,7 @@
 class PathUtilities {
 public:
     WEBCORE_EXPORT static Path pathWithShrinkWrappedRects(const Vector<FloatRect>& rects, float radius);
+    WEBCORE_EXPORT static Vector<Path> pathsWithShrinkWrappedRects(const Vector<FloatRect>& rects, float radius);
 };
 
 }

Modified: trunk/Source/WebKit2/ChangeLog (188525 => 188526)


--- trunk/Source/WebKit2/ChangeLog	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebKit2/ChangeLog	2015-08-17 17:50:09 UTC (rev 188526)
@@ -1,3 +1,21 @@
+2015-08-17  Timothy Horton  <[email protected]>
+
+        Adopt shrink-wrapping for TextIndicators on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=148064
+
+        Reviewed by Beth Dakin.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<TextIndicatorData>::encode): Deleted.
+        (IPC::ArgumentCoder<TextIndicatorData>::decode): Deleted.
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::FindController::updateFindIndicator):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getPositionInformation):
+        Use the new option, TextIndicatorOptionIncludeMarginIfRangeMatchesSelection,
+        for iOS and FindController, because we can keep the margins in these cases
+        because we don't have to animate to/from the blue highlight.
+
 2015-08-16  Timothy Horton  <[email protected]>
 
         Refactor ViewGestureController swipe snapshot removal to be more platform-independent

Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp (188525 => 188526)


--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-08-17 17:50:09 UTC (rev 188526)
@@ -2139,7 +2139,6 @@
     encoder << textIndicatorData.textBoundingRectInRootViewCoordinates;
     encoder << textIndicatorData.textRectsInBoundingRectCoordinates;
     encoder << textIndicatorData.contentImageScaleFactor;
-    encoder << textIndicatorData.indicatesCurrentSelection;
     encoder.encodeEnum(textIndicatorData.presentationTransition);
     encoder << static_cast<uint64_t>(textIndicatorData.options);
 
@@ -2161,9 +2160,6 @@
     if (!decoder.decode(textIndicatorData.contentImageScaleFactor))
         return false;
 
-    if (!decoder.decode(textIndicatorData.indicatesCurrentSelection))
-        return false;
-
     if (!decoder.decodeEnum(textIndicatorData.presentationTransition))
         return false;
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp (188525 => 188526)


--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp	2015-08-17 17:50:09 UTC (rev 188526)
@@ -320,7 +320,7 @@
 #if !PLATFORM(IOS)
 bool FindController::updateFindIndicator(Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate)
 {
-    RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(selectedFrame, TextIndicatorOptionDefault, shouldAnimate ? TextIndicatorPresentationTransition::Bounce : TextIndicatorPresentationTransition::None);
+    RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(selectedFrame, TextIndicatorOptionIncludeMarginIfRangeMatchesSelection, shouldAnimate ? TextIndicatorPresentationTransition::Bounce : TextIndicatorPresentationTransition::None);
     if (!indicator)
         return false;
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (188525 => 188526)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-08-17 17:41:44 UTC (rev 188525)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2015-08-17 17:50:09 UTC (rev 188526)
@@ -2195,13 +2195,13 @@
                     if (RefPtr<WebImage> snapshot = snapshotNode(*element, SnapshotOptionsShareable, 600 * 1024))
                         info.image = snapshot->bitmap();
 
-
                     RefPtr<Range> linkRange = rangeOfContents(*linkElement);
                     if (linkRange) {
                         float deviceScaleFactor = corePage()->deviceScaleFactor();
                         const float marginInPoints = 4;
 
-                        RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(*linkRange, TextIndicatorOptionTightlyFitContent | TextIndicatorOptionRespectTextColor | TextIndicatorOptionPaintBackgrounds | TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges, TextIndicatorPresentationTransition::None, marginInPoints * deviceScaleFactor);
+                        RefPtr<TextIndicator> textIndicator = TextIndicator::createWithRange(*linkRange, TextIndicatorOptionTightlyFitContent | TextIndicatorOptionRespectTextColor | TextIndicatorOptionPaintBackgrounds | TextIndicatorOptionUseBoundingRectAndPaintAllContentForComplexRanges |
+                            TextIndicatorOptionIncludeMarginIfRangeMatchesSelection, TextIndicatorPresentationTransition::None, FloatSize(marginInPoints * deviceScaleFactor, marginInPoints * deviceScaleFactor));
                         if (textIndicator)
                             info.linkIndicator = textIndicator->data();
                     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to