Diff
Modified: branches/safari-600.3-branch/Source/WebCore/ChangeLog (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebCore/ChangeLog 2014-11-06 05:14:01 UTC (rev 175664)
@@ -1,5 +1,21 @@
2014-11-05 Dana Burkart <dburk...@apple.com>
+ Merge r175564. <rdar://problem/18840102>
+
+ 2014-11-04 Tim Horton <timothy_hor...@apple.com>
+
+ Implement yellow highlight over data detected items
+ https://bugs.webkit.org/show_bug.cgi?id=138340
+ <rdar://problem/18840102>
+
+ Reviewed by Anders Carlsson.
+
+ * platform/spi/mac/DataDetectorsSPI.h:
+ Add completionHandler SPI.
+
+
+2014-11-05 Dana Burkart <dburk...@apple.com>
+
Merge r175375. <rdar://problem/18883807>
2014-10-30 Eric Carlson <eric.carl...@apple.com>
Modified: branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebCore/platform/spi/mac/DataDetectorsSPI.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -66,6 +66,7 @@
@property NSRect highlightFrame;
@property (retain) NSArray *allResults;
@property (retain) __attribute__((NSObject)) DDResultRef mainResult;
+@property (copy) void (^completionHandler)(void);
@end
Modified: branches/safari-600.3-branch/Source/WebKit2/CMakeLists.txt (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/CMakeLists.txt 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/CMakeLists.txt 2014-11-06 05:14:01 UTC (rev 175664)
@@ -209,6 +209,7 @@
Shared/ShareableBitmap.cpp
Shared/ShareableResource.cpp
Shared/StatisticsData.cpp
+ Shared/TextIndicator.cpp
Shared/UpdateInfo.cpp
Shared/UserData.cpp
Shared/VisitedLinkTable.cpp
@@ -303,7 +304,6 @@
UIProcess/ResponsivenessTimer.cpp
UIProcess/StatisticsRequest.cpp
UIProcess/TextCheckerCompletion.cpp
- UIProcess/TextIndicator.cpp
UIProcess/VisitedLinkProvider.cpp
UIProcess/WebApplicationCacheManagerProxy.cpp
UIProcess/WebBackForwardList.cpp
Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog 2014-11-06 05:14:01 UTC (rev 175664)
@@ -1,5 +1,91 @@
2014-11-05 Dana Burkart <dburk...@apple.com>
+ Merge r175564. <rdar://problem/18840102>
+
+ 2014-11-04 Tim Horton <timothy_hor...@apple.com>
+
+ Implement yellow highlight over data detected items
+ https://bugs.webkit.org/show_bug.cgi?id=138340
+ <rdar://problem/18840102>
+
+ Reviewed by Anders Carlsson.
+
+ * Shared/TextIndicator.cpp: Renamed from Source/WebKit2/UIProcess/TextIndicator.cpp.
+ * Shared/TextIndicator.h: Renamed from Source/WebKit2/UIProcess/TextIndicator.h.
+ Move TextIndicator to Shared.
+ Move all of the members to a Data struct.
+ Implement encode/decode for TextIndicator::Data, so it can be passed as
+ the argument to SetTextIndicator, and also as a field on ActionMenuHitTestResult.
+ Add 'createWithSelectionInFrame', which builds a TextIndicator
+ from the selection in the given frame.
+
+ * Shared/mac/ActionMenuHitTestResult.h:
+ * Shared/mac/ActionMenuHitTestResult.mm:
+ (WebKit::ActionMenuHitTestResult::encode):
+ (WebKit::ActionMenuHitTestResult::decode):
+ Rename actionBoundingBox to detectedDataBoundingBox.
+ Store/encode/decode detectedDataTextIndicator.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::setTextIndicator):
+ * UIProcess/WebPageProxy.h:
+ * UIProcess/WebPageProxy.messages.in:
+ Create a TextIndicator from the TextIndicator::Data.
+ Add an explicit ClearTextIndicator message instead of sending empty Data.
+
+ * UIProcess/mac/WKActionMenuController.h:
+ * UIProcess/mac/WKActionMenuController.mm:
+ (-[WKActionMenuController prepareForMenu:withEvent:]):
+ If the text indicator is up when preparing for a new menu invocation, hide it.
+
+ (-[WKActionMenuController willOpenMenu:withEvent:]):
+ Show the text indicator when the menu opens, for data detected items.
+
+ (-[WKActionMenuController didCloseMenu:withEvent:]):
+ Hide the text indicator when the menu closes, unless we only had one item.
+ Then, we'll hide it in the DDActionContext completionHandler block.
+
+ (-[WKActionMenuController _showTextIndicator]):
+ (-[WKActionMenuController _hideTextIndicator]):
+ Added. Show and hide the text indicator based on the TextIndicator
+ data included in the action menu hit test result.
+
+ (-[WKActionMenuController _defaultMenuItemsForDataDetectedText]):
+ Hide the text indicator when the data detector popover completes.
+
+ * WebKit2.xcodeproj/project.pbxproj:
+ * WebProcess/WebPage/FindController.cpp:
+ (WebKit::FindController::getImageForFindMatch):
+ Make use of the newly-moved createSelectionSnapshot.
+
+ (WebKit::FindController::updateFindIndicator):
+ Make use of TextIndicator::createWithSelectionInFrame, which allows
+ us to share this code for building a TextIndicator with other callers.
+
+ (WebKit::FindController::hideFindIndicator):
+
+ (WebKit::getFindIndicatorBitmap): Deleted.
+ Move getFindIndicatorBitmap to WebFrame::createSelectionSnapshot.
+
+ * WebProcess/WebPage/WebFrame.cpp:
+ (WebKit::WebFrame::createSelectionSnapshot):
+ Moved from FindController's getFindIndicatorBitmap.
+ Now returns a ShareableBitmap instead of going ahead and making a Handle.
+
+ * WebProcess/WebPage/WebFrame.h:
+ * WebProcess/WebPage/mac/WebPageMac.mm:
+ (WebKit::scanForDataDetectedItems):
+ (WebKit::textIndicatorForRange):
+ Temporarily change the selection to the given range, then use
+ TextIndicator::indicatorWithSelectionInFrame to acquire a TextIndicator,
+ then reset the selection.
+
+ (WebKit::WebPage::performActionMenuHitTestAtLocation):
+ Create a TextIndicator from the data detected range.
+
+
+2014-11-05 Dana Burkart <dburk...@apple.com>
+
Merge r175524. <rdar://problem/18861406>
2014-11-04 Tim Horton <timothy_hor...@apple.com>
Copied: branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp (from rev 175663, branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.cpp) (0 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp (rev 0)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp 2014-11-06 05:14:01 UTC (rev 175664)
@@ -0,0 +1,350 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextIndicator.h"
+
+#include "ArgumentCodersCF.h"
+#include "ArgumentDecoder.h"
+#include "ArgumentEncoder.h"
+#include "ShareableBitmap.h"
+#include "WebCoreArgumentCoders.h"
+#include "WebFrame.h"
+#include "WebPage.h"
+#include <WebCore/Frame.h>
+#include <WebCore/FrameSelection.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GeometryUtilities.h>
+#include <WebCore/Gradient.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/IntRect.h>
+#include <WebCore/Path.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
+
+using namespace WebCore;
+
+#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
+static const float cornerRadius = 3.0;
+
+static const float shadowOffsetX = 0.0;
+static const float shadowOffsetY = 1.0;
+static const float shadowBlurRadius = 3.0;
+
+static const int shadowRed = 0;
+static const int shadowGreen = 0;
+static const int shadowBlue = 0;
+static const int shadowAlpha = 204;
+
+static const float lightBorderThickness = 1.0;
+static const float horizontalPaddingInsideLightBorder = 3.0;
+static const float verticalPaddingInsideLightBorder = 1.0;
+
+static const float horizontalBorderInsideShadow = lightBorderThickness + horizontalPaddingInsideLightBorder;
+static const float verticalBorderInsideShadow = lightBorderThickness + verticalPaddingInsideLightBorder;
+
+static const float leftBorderThickness = horizontalBorderInsideShadow + shadowOffsetX + shadowBlurRadius / 2.0;
+static const float topBorderThickness = verticalBorderInsideShadow - shadowOffsetY + shadowBlurRadius / 2.0;
+static const float rightBorderThickness = horizontalBorderInsideShadow - shadowOffsetX + shadowBlurRadius / 2.0;
+static const float bottomBorderThickness = verticalBorderInsideShadow + shadowOffsetY + shadowBlurRadius / 2.0;
+
+static const float horizontalOutsetToCenterOfLightBorder = horizontalBorderInsideShadow - lightBorderThickness / 2.0;
+static const float verticalOutsetToCenterOfLightBorder = verticalBorderInsideShadow - lightBorderThickness / 2.0;
+
+static const int lightBorderRed = 245;
+static const int lightBorderGreen = 230;
+static const int lightBorderBlue = 0;
+static const int lightBorderAlpha = 255;
+
+static const int gradientDarkRed = 237;
+static const int gradientDarkGreen = 204;
+static const int gradientDarkBlue = 0;
+static const int gradientDarkAlpha = 255;
+
+static const int gradientLightRed = 242;
+static const int gradientLightGreen = 239;
+static const int gradientLightBlue = 0;
+static const int gradientLightAlpha = 255;
+#else
+const float flatStyleHorizontalBorder = 2;
+const float flatStyleVerticalBorder = 1;
+const float flatShadowOffsetX = 0;
+const float flatShadowOffsetY = 5;
+const float flatShadowBlurRadius = 25;
+const float flatRimShadowBlurRadius = 2;
+#endif
+
+namespace WebKit {
+
+static FloatRect inflateRect(const FloatRect& rect, float inflateX, float inflateY)
+{
+ FloatRect inflatedRect = rect;
+ inflatedRect.inflateX(inflateX);
+ inflatedRect.inflateY(inflateY);
+ return inflatedRect;
+}
+
+static FloatRect outsetIndicatorRectIncludingShadow(const FloatRect rect)
+{
+#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
+ FloatRect outsetRect = rect;
+ outsetRect.move(-leftBorderThickness, -topBorderThickness);
+ outsetRect.expand(leftBorderThickness + rightBorderThickness, topBorderThickness + bottomBorderThickness);
+ return outsetRect;
+#else
+ return inflateRect(rect, flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder);
+#endif
+}
+
+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;
+}
+
+PassRefPtr<TextIndicator> TextIndicator::create(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage)
+{
+ TextIndicator::Data data;
+ data.selectionRectInWindowCoordinates = selectionRectInWindowCoordinates;
+ data.textRectsInSelectionRectCoordinates = textRectsInSelectionRectCoordinates;
+ data.contentImageScaleFactor = contentImageScaleFactor;
+ data.contentImage = contentImage;
+
+ return TextIndicator::create(data);
+}
+
+PassRefPtr<TextIndicator> TextIndicator::create(const TextIndicator::Data& data)
+{
+ return adoptRef(new TextIndicator(data));
+}
+
+PassRefPtr<TextIndicator> TextIndicator::createWithSelectionInFrame(WebFrame& frame)
+{
+ Frame& coreFrame = *frame.coreFrame();
+ IntRect selectionRect = enclosingIntRect(coreFrame.selection().selectionBounds());
+ RefPtr<ShareableBitmap> indicatorBitmap = frame.createSelectionSnapshot();
+ if (!indicatorBitmap)
+ return nullptr;
+
+ // We want the selection rect in window coordinates.
+ IntRect selectionRectInWindowCoordinates = coreFrame.view()->contentsToWindow(selectionRect);
+
+ Vector<FloatRect> textRects;
+ coreFrame.selection().getClippedVisibleTextRectangles(textRects);
+
+ // We want the text rects in selection rect coordinates.
+ Vector<FloatRect> textRectsInSelectionRectCoordinates;
+
+ for (const FloatRect& textRect : textRects) {
+ IntRect textRectInSelectionRectCoordinates = coreFrame.view()->contentsToWindow(enclosingIntRect(textRect));
+ textRectInSelectionRectCoordinates.move(-selectionRectInWindowCoordinates.x(), -selectionRectInWindowCoordinates.y());
+ textRectsInSelectionRectCoordinates.append(textRectInSelectionRectCoordinates);
+ }
+
+ return TextIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, frame.page()->deviceScaleFactor(), indicatorBitmap);
+}
+
+TextIndicator::TextIndicator(const TextIndicator::Data& data)
+ : m_data(data)
+{
+ ASSERT(m_data.contentImageScaleFactor != 1 || m_data.contentImage->size() == enclosingIntRect(m_data.selectionRectInWindowCoordinates).size());
+
+ if (textIndicatorsForTextRectsOverlap(m_data.textRectsInSelectionRectCoordinates)) {
+ m_data.textRectsInSelectionRectCoordinates[0] = unionRect(m_data.textRectsInSelectionRectCoordinates);
+ m_data.textRectsInSelectionRectCoordinates.shrink(1);
+ }
+}
+
+TextIndicator::~TextIndicator()
+{
+}
+
+FloatRect TextIndicator::frameRect() const
+{
+ return outsetIndicatorRectIncludingShadow(m_data.selectionRectInWindowCoordinates);
+}
+
+#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
+static inline Color lightBorderColor()
+{
+ return Color(lightBorderRed, lightBorderGreen, lightBorderBlue, lightBorderAlpha);
+}
+
+static inline Color shadowColor()
+{
+ return Color(shadowRed, shadowGreen, shadowBlue, shadowAlpha);
+}
+
+static inline Color gradientLightColor()
+{
+ return Color(gradientLightRed, gradientLightGreen, gradientLightBlue, gradientLightAlpha);
+}
+
+static inline Color gradientDarkColor()
+{
+ return Color(gradientDarkRed, gradientDarkGreen, gradientDarkBlue, gradientDarkAlpha);
+}
+
+static Path pathWithRoundedRect(const FloatRect& pathRect, float radius)
+{
+ Path path;
+ path.addRoundedRect(pathRect, FloatSize(radius, radius));
+
+ return path;
+}
+#else
+static inline Color flatHighlightColor()
+{
+ return Color(255, 255, 0, 255);
+}
+
+static inline Color flatRimShadowColor()
+{
+ return Color(0, 0, 0, 38);
+}
+
+static inline Color flatDropShadowColor()
+{
+ return Color(0, 0, 0, 51);
+}
+#endif
+
+void TextIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirtyRect*/)
+{
+#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
+ for (size_t i = 0; i < m_data.textRectsInSelectionRectCoordinates.size(); ++i) {
+ FloatRect textRect = m_data.textRectsInSelectionRectCoordinates[i];
+ textRect.move(leftBorderThickness, topBorderThickness);
+
+ FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder);
+ FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder);
+
+ {
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+ graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor(), ColorSpaceSRGB);
+ graphicsContext.setFillColor(lightBorderColor(), ColorSpaceDeviceRGB);
+ graphicsContext.fillPath(pathWithRoundedRect(outerPathRect, cornerRadius));
+ }
+
+ {
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+ graphicsContext.clip(pathWithRoundedRect(innerPathRect, cornerRadius));
+ RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY()));
+ gradient->addColorStop(0, gradientLightColor());
+ gradient->addColorStop(1, gradientDarkColor());
+ graphicsContext.setFillGradient(gradient.releaseNonNull());
+ graphicsContext.fillRect(outerPathRect);
+ }
+
+ {
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+ graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness)));
+
+ IntRect contentImageRect = enclosingIntRect(m_data.textRectsInSelectionRectCoordinates[i]);
+ m_data.contentImage->paint(graphicsContext, m_data.contentImageScaleFactor, contentImageRect.location(), contentImageRect);
+ }
+ }
+#else
+ for (auto& textRect : m_data.textRectsInSelectionRectCoordinates) {
+ FloatRect blurRect = textRect;
+ blurRect.move(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder);
+ FloatRect outerPathRect = inflateRect(blurRect, flatStyleHorizontalBorder, flatStyleVerticalBorder);
+
+ {
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+ graphicsContext.setShadow(FloatSize(), flatRimShadowBlurRadius, flatRimShadowColor(), ColorSpaceSRGB);
+ graphicsContext.setFillColor(flatHighlightColor(), ColorSpaceSRGB);
+ graphicsContext.fillRect(outerPathRect);
+ graphicsContext.setShadow(FloatSize(flatShadowOffsetX, flatShadowOffsetY), flatShadowBlurRadius, flatDropShadowColor(), ColorSpaceSRGB);
+ graphicsContext.fillRect(outerPathRect);
+ }
+
+ {
+ GraphicsContextStateSaver stateSaver(graphicsContext);
+ graphicsContext.translate(FloatSize(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder));
+
+ IntRect contentImageRect = enclosingIntRect(textRect);
+ m_data.contentImage->paint(graphicsContext, m_data.contentImageScaleFactor, contentImageRect.location(), contentImageRect);
+ }
+ }
+#endif
+}
+
+void TextIndicator::Data::encode(IPC::ArgumentEncoder& encoder) const
+{
+ encoder << selectionRectInWindowCoordinates;
+ encoder << textRectsInSelectionRectCoordinates;
+ encoder << contentImageScaleFactor;
+
+ ShareableBitmap::Handle contentImageHandle;
+ if (contentImage)
+ contentImage->createHandle(contentImageHandle, SharedMemory::ReadOnly);
+ encoder << contentImageHandle;
+}
+
+bool TextIndicator::Data::decode(IPC::ArgumentDecoder& decoder, TextIndicator::Data& textIndicatorData)
+{
+ if (!decoder.decode(textIndicatorData.selectionRectInWindowCoordinates))
+ return false;
+
+ if (!decoder.decode(textIndicatorData.textRectsInSelectionRectCoordinates))
+ return false;
+
+ if (!decoder.decode(textIndicatorData.contentImageScaleFactor))
+ return false;
+
+ ShareableBitmap::Handle contentImageHandle;
+ if (!decoder.decode(contentImageHandle))
+ return false;
+
+ if (!contentImageHandle.isNull())
+ textIndicatorData.contentImage = ShareableBitmap::create(contentImageHandle, SharedMemory::ReadOnly);
+
+ return true;
+}
+
+} // namespace WebKit
Copied: branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h (from rev 175663, branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.h) (0 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h (rev 0)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TextIndicator_h
+#define TextIndicator_h
+
+#include "ShareableBitmap.h"
+#include <WebCore/FloatRect.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+class GraphicsContext;
+}
+
+namespace IPC {
+class ArgumentDecoder;
+class ArgumentEncoder;
+}
+
+namespace WebKit {
+
+class WebFrame;
+
+class TextIndicator : public RefCounted<TextIndicator> {
+public:
+ struct Data {
+ WebCore::FloatRect selectionRectInWindowCoordinates;
+ Vector<WebCore::FloatRect> textRectsInSelectionRectCoordinates;
+ float contentImageScaleFactor;
+ RefPtr<ShareableBitmap> contentImage;
+
+ void encode(IPC::ArgumentEncoder&) const;
+ static bool decode(IPC::ArgumentDecoder&, Data&);
+ };
+
+ static PassRefPtr<TextIndicator> create(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionCoordinates, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage);
+ static PassRefPtr<TextIndicator> create(const TextIndicator::Data&);
+ static PassRefPtr<TextIndicator> createWithSelectionInFrame(WebFrame&);
+
+ ~TextIndicator();
+
+ WebCore::FloatRect selectionRectInWindowCoordinates() const { return m_data.selectionRectInWindowCoordinates; }
+ WebCore::FloatRect frameRect() const;
+ ShareableBitmap* contentImage() const { return m_data.contentImage.get(); }
+ Data data() const { return m_data; }
+
+ void draw(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
+
+private:
+ TextIndicator(const TextIndicator::Data&);
+
+ Data m_data;
+};
+
+} // namespace WebKit
+
+#endif // TextIndicator_h
Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -27,6 +27,7 @@
#define ActionMenuHitTestResult_h
#include "ShareableBitmap.h"
+#include "TextIndicator.h"
#include "WebHitTestResult.h"
#include <WebCore/FloatRect.h>
#include <wtf/text/WTFString.h>
@@ -51,7 +52,8 @@
RefPtr<ShareableBitmap> image;
RetainPtr<DDActionContext> actionContext;
- WebCore::FloatRect actionBoundingBox;
+ WebCore::FloatRect detectedDataBoundingBox;
+ RefPtr<TextIndicator> detectedDataTextIndicator;
};
} // namespace WebKit
Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/mac/ActionMenuHitTestResult.mm 2014-11-06 05:14:01 UTC (rev 175664)
@@ -29,6 +29,7 @@
#import "ArgumentCodersCF.h"
#import "ArgumentDecoder.h"
#import "ArgumentEncoder.h"
+#import "TextIndicator.h"
#import "WebCoreArgumentCoders.h"
#import <WebCore/DataDetectorsSPI.h>
@@ -58,9 +59,14 @@
[archiver finishEncoding];
IPC::encode(encoder, reinterpret_cast<CFDataRef>(data.get()));
+
+ encoder << detectedDataBoundingBox;
+
+ bool hasTextIndicator = detectedDataTextIndicator;
+ encoder << hasTextIndicator;
+ if (hasTextIndicator)
+ encoder << detectedDataTextIndicator->data();
}
-
- encoder << actionBoundingBox;
}
bool ActionMenuHitTestResult::decode(IPC::ArgumentDecoder& decoder, ActionMenuHitTestResult& actionMenuHitTestResult)
@@ -100,11 +106,23 @@
}
[unarchiver finishDecoding];
+
+ if (!decoder.decode(actionMenuHitTestResult.detectedDataBoundingBox))
+ return false;
+
+ bool hasTextIndicator;
+ if (!decoder.decode(hasTextIndicator))
+ return false;
+
+ if (hasTextIndicator) {
+ TextIndicator::Data indicatorData;
+ if (!decoder.decode(indicatorData))
+ return false;
+
+ actionMenuHitTestResult.detectedDataTextIndicator = TextIndicator::create(indicatorData);
+ }
}
- if (!decoder.decode(actionMenuHitTestResult.actionBoundingBox))
- return false;
-
return true;
}
Deleted: branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.cpp (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.cpp 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.cpp 2014-11-06 05:14:01 UTC (rev 175664)
@@ -1,277 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "TextIndicator.h"
-
-#include "ShareableBitmap.h"
-#include <WebCore/GeometryUtilities.h>
-#include <WebCore/Gradient.h>
-#include <WebCore/GraphicsContext.h>
-#include <WebCore/IntRect.h>
-#include <WebCore/Path.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
-
-using namespace WebCore;
-
-#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
-static const float cornerRadius = 3.0;
-
-static const float shadowOffsetX = 0.0;
-static const float shadowOffsetY = 1.0;
-static const float shadowBlurRadius = 3.0;
-
-static const int shadowRed = 0;
-static const int shadowGreen = 0;
-static const int shadowBlue = 0;
-static const int shadowAlpha = 204;
-
-static const float lightBorderThickness = 1.0;
-static const float horizontalPaddingInsideLightBorder = 3.0;
-static const float verticalPaddingInsideLightBorder = 1.0;
-
-static const float horizontalBorderInsideShadow = lightBorderThickness + horizontalPaddingInsideLightBorder;
-static const float verticalBorderInsideShadow = lightBorderThickness + verticalPaddingInsideLightBorder;
-
-static const float leftBorderThickness = horizontalBorderInsideShadow + shadowOffsetX + shadowBlurRadius / 2.0;
-static const float topBorderThickness = verticalBorderInsideShadow - shadowOffsetY + shadowBlurRadius / 2.0;
-static const float rightBorderThickness = horizontalBorderInsideShadow - shadowOffsetX + shadowBlurRadius / 2.0;
-static const float bottomBorderThickness = verticalBorderInsideShadow + shadowOffsetY + shadowBlurRadius / 2.0;
-
-static const float horizontalOutsetToCenterOfLightBorder = horizontalBorderInsideShadow - lightBorderThickness / 2.0;
-static const float verticalOutsetToCenterOfLightBorder = verticalBorderInsideShadow - lightBorderThickness / 2.0;
-
-static const int lightBorderRed = 245;
-static const int lightBorderGreen = 230;
-static const int lightBorderBlue = 0;
-static const int lightBorderAlpha = 255;
-
-static const int gradientDarkRed = 237;
-static const int gradientDarkGreen = 204;
-static const int gradientDarkBlue = 0;
-static const int gradientDarkAlpha = 255;
-
-static const int gradientLightRed = 242;
-static const int gradientLightGreen = 239;
-static const int gradientLightBlue = 0;
-static const int gradientLightAlpha = 255;
-#else
-const float flatStyleHorizontalBorder = 2;
-const float flatStyleVerticalBorder = 1;
-const float flatShadowOffsetX = 0;
-const float flatShadowOffsetY = 5;
-const float flatShadowBlurRadius = 25;
-const float flatRimShadowBlurRadius = 2;
-#endif
-
-namespace WebKit {
-
-PassRefPtr<TextIndicator> TextIndicator::create(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle)
-{
- RefPtr<ShareableBitmap> contentImage = ShareableBitmap::create(contentImageHandle);
- if (!contentImage)
- return 0;
- ASSERT(contentImageScaleFactor != 1 || contentImage->size() == enclosingIntRect(selectionRectInWindowCoordinates).size());
-
- return adoptRef(new TextIndicator(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImage.release()));
-}
-
-static FloatRect inflateRect(const FloatRect& rect, float inflateX, float inflateY)
-{
- FloatRect inflatedRect = rect;
- inflatedRect.inflateX(inflateX);
- inflatedRect.inflateY(inflateY);
- return inflatedRect;
-}
-
-static FloatRect outsetIndicatorRectIncludingShadow(const FloatRect rect)
-{
-#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
- FloatRect outsetRect = rect;
- outsetRect.move(-leftBorderThickness, -topBorderThickness);
- outsetRect.expand(leftBorderThickness + rightBorderThickness, topBorderThickness + bottomBorderThickness);
- return outsetRect;
-#else
- return inflateRect(rect, flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder);
-#endif
-}
-
-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;
-}
-
-TextIndicator::TextIndicator(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 (textIndicatorsForTextRectsOverlap(m_textRectsInSelectionRectCoordinates)) {
- m_textRectsInSelectionRectCoordinates[0] = unionRect(m_textRectsInSelectionRectCoordinates);
- m_textRectsInSelectionRectCoordinates.shrink(1);
- }
-}
-
-TextIndicator::~TextIndicator()
-{
-}
-
-FloatRect TextIndicator::frameRect() const
-{
- return outsetIndicatorRectIncludingShadow(m_selectionRectInWindowCoordinates);
-}
-
-#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
-static inline Color lightBorderColor()
-{
- return Color(lightBorderRed, lightBorderGreen, lightBorderBlue, lightBorderAlpha);
-}
-
-static inline Color shadowColor()
-{
- return Color(shadowRed, shadowGreen, shadowBlue, shadowAlpha);
-}
-
-static inline Color gradientLightColor()
-{
- return Color(gradientLightRed, gradientLightGreen, gradientLightBlue, gradientLightAlpha);
-}
-
-static inline Color gradientDarkColor()
-{
- return Color(gradientDarkRed, gradientDarkGreen, gradientDarkBlue, gradientDarkAlpha);
-}
-
-static Path pathWithRoundedRect(const FloatRect& pathRect, float radius)
-{
- Path path;
- path.addRoundedRect(pathRect, FloatSize(radius, radius));
-
- return path;
-}
-#else
-static inline Color flatHighlightColor()
-{
- return Color(255, 255, 0, 255);
-}
-
-static inline Color flatRimShadowColor()
-{
- return Color(0, 0, 0, 38);
-}
-
-static inline Color flatDropShadowColor()
-{
- return Color(0, 0, 0, 51);
-}
-#endif
-
-void TextIndicator::draw(GraphicsContext& graphicsContext, const IntRect& /*dirtyRect*/)
-{
-#if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
- for (size_t i = 0; i < m_textRectsInSelectionRectCoordinates.size(); ++i) {
- FloatRect textRect = m_textRectsInSelectionRectCoordinates[i];
- textRect.move(leftBorderThickness, topBorderThickness);
-
- FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder);
- FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder);
-
- {
- GraphicsContextStateSaver stateSaver(graphicsContext);
- graphicsContext.setShadow(FloatSize(shadowOffsetX, shadowOffsetY), shadowBlurRadius, shadowColor(), ColorSpaceSRGB);
- graphicsContext.setFillColor(lightBorderColor(), ColorSpaceDeviceRGB);
- graphicsContext.fillPath(pathWithRoundedRect(outerPathRect, cornerRadius));
- }
-
- {
- GraphicsContextStateSaver stateSaver(graphicsContext);
- graphicsContext.clip(pathWithRoundedRect(innerPathRect, cornerRadius));
- RefPtr<Gradient> gradient = Gradient::create(FloatPoint(innerPathRect.x(), innerPathRect.y()), FloatPoint(innerPathRect.x(), innerPathRect.maxY()));
- gradient->addColorStop(0, gradientLightColor());
- gradient->addColorStop(1, gradientDarkColor());
- graphicsContext.setFillGradient(gradient.releaseNonNull());
- graphicsContext.fillRect(outerPathRect);
- }
-
- {
- GraphicsContextStateSaver stateSaver(graphicsContext);
- graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness)));
-
- IntRect contentImageRect = enclosingIntRect(m_textRectsInSelectionRectCoordinates[i]);
- m_contentImage->paint(graphicsContext, m_contentImageScaleFactor, contentImageRect.location(), contentImageRect);
- }
- }
-#else
- for (auto& textRect : m_textRectsInSelectionRectCoordinates) {
- FloatRect blurRect = textRect;
- blurRect.move(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder);
- FloatRect outerPathRect = inflateRect(blurRect, flatStyleHorizontalBorder, flatStyleVerticalBorder);
-
- {
- GraphicsContextStateSaver stateSaver(graphicsContext);
- graphicsContext.setShadow(FloatSize(), flatRimShadowBlurRadius, flatRimShadowColor(), ColorSpaceSRGB);
- graphicsContext.setFillColor(flatHighlightColor(), ColorSpaceSRGB);
- graphicsContext.fillRect(outerPathRect);
- graphicsContext.setShadow(FloatSize(flatShadowOffsetX, flatShadowOffsetY), flatShadowBlurRadius, flatDropShadowColor(), ColorSpaceSRGB);
- graphicsContext.fillRect(outerPathRect);
- }
-
- {
- GraphicsContextStateSaver stateSaver(graphicsContext);
- graphicsContext.translate(FloatSize(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder));
-
- IntRect contentImageRect = enclosingIntRect(textRect);
- m_contentImage->paint(graphicsContext, m_contentImageScaleFactor, contentImageRect.location(), contentImageRect);
- }
- }
-#endif
-}
-
-} // namespace WebKit
Deleted: branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/TextIndicator.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef TextIndicator_h
-#define TextIndicator_h
-
-#include "ShareableBitmap.h"
-#include <WebCore/FloatRect.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/Vector.h>
-
-namespace WebCore {
-class GraphicsContext;
-}
-
-namespace WebKit {
-
-class TextIndicator : public RefCounted<TextIndicator> {
-public:
- static PassRefPtr<TextIndicator> create(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle);
- ~TextIndicator();
-
- WebCore::FloatRect selectionRectInWindowCoordinates() const { return m_selectionRectInWindowCoordinates; }
- WebCore::FloatRect frameRect() const;
-
- ShareableBitmap* contentImage() const { return m_contentImage.get(); }
-
- void draw(WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
-
-private:
- TextIndicator(const WebCore::FloatRect& selectionRect, const Vector<WebCore::FloatRect>& textRects, float contentImageScaleFactor, PassRefPtr<ShareableBitmap> contentImage);
-
- WebCore::FloatRect m_selectionRectInWindowCoordinates;
- Vector<WebCore::FloatRect> m_textRectsInSelectionRectCoordinates;
- float m_contentImageScaleFactor;
- RefPtr<ShareableBitmap> m_contentImage;
-};
-
-} // namespace WebKit
-
-#endif // TextIndicator_h
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-11-06 05:14:01 UTC (rev 175664)
@@ -3548,12 +3548,16 @@
m_findMatchesClient.didGetImageForMatchResult(this, WebImage::create(ShareableBitmap::create(contentImageHandle)).get(), matchIndex);
}
-void WebPageProxy::setTextIndicator(const FloatRect& selectionRectInWindowCoordinates, const Vector<FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate)
+void WebPageProxy::setTextIndicator(const TextIndicator::Data& indicatorData, bool fadeOut, bool animate)
{
- RefPtr<TextIndicator> textIndicator = TextIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, contentImageScaleFactor, contentImageHandle);
- m_pageClient.setTextIndicator(textIndicator.release(), fadeOut, animate);
+ m_pageClient.setTextIndicator(TextIndicator::create(indicatorData), fadeOut, animate);
}
+void WebPageProxy::clearTextIndicator(bool fadeOut, bool animate)
+{
+ m_pageClient.setTextIndicator(nullptr, fadeOut, animate);
+}
+
void WebPageProxy::didFindString(const String& string, uint32_t matchCount, int32_t matchIndex)
{
m_findClient->didFindString(this, string, matchCount, matchIndex);
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -152,6 +152,7 @@
class RemoteLayerTreeTransaction;
class RemoteScrollingCoordinatorProxy;
class StringPairVector;
+class TextIndicator;
class ViewSnapshot;
class VisitedLinkProvider;
class WebBackForwardList;
@@ -656,7 +657,8 @@
void hideFindUI();
void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
void didCountStringMatches(const String&, uint32_t matchCount);
- void setTextIndicator(const WebCore::FloatRect& selectionRectInWindowCoordinates, const Vector<WebCore::FloatRect>& textRectsInSelectionRectCoordinates, float contentImageScaleFactor, const ShareableBitmap::Handle& contentImageHandle, bool fadeOut, bool animate);
+ void setTextIndicator(const TextIndicator::Data&, bool fadeOut, bool animate);
+ void clearTextIndicator(bool fadeOut, bool animate);
void didFindString(const String&, uint32_t matchCount, int32_t matchIndex);
void didFailToFindString(const String&);
void didFindStringMatches(const String&, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection);
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/WebPageProxy.messages.in 2014-11-06 05:14:01 UTC (rev 175664)
@@ -223,7 +223,8 @@
# Find messages
DidCountStringMatches(String string, uint32_t matchCount)
- SetTextIndicator(WebCore::FloatRect selectionRect, Vector<WebCore::FloatRect> textRects, float contentImageScaleFactor, WebKit::ShareableBitmap::Handle contentImageHandle, bool fadeOut, bool animate)
+ SetTextIndicator(WebKit::TextIndicator::Data indicator, bool fadeOut, bool animate)
+ ClearTextIndicator(bool fadeOut, bool animate)
DidFindString(String string, uint32_t matchCount, int32_t matchIndex)
DidFailToFindString(String string)
DidFindStringMatches(String string, Vector<Vector<WebCore::IntRect>> matches, int32_t firstIndexAfterSelection)
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -56,6 +56,8 @@
RefPtr<API::Object> _userData;
_WKActionMenuType _type;
RetainPtr<NSSharingServicePicker> _sharingServicePicker;
+
+ BOOL _isShowingTextIndicator;
}
- (instancetype)initWithPage:(WebKit::WebPageProxy&)page view:(WKView *)wkView;
Modified: branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm 2014-11-06 05:14:01 UTC (rev 175664)
@@ -28,6 +28,7 @@
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+#import "TextIndicator.h"
#import "WKNSURLExtras.h"
#import "WKViewInternal.h"
#import "WebContext.h"
@@ -71,6 +72,8 @@
@interface WKActionMenuController () <NSSharingServiceDelegate, NSSharingServicePickerDelegate>
- (void)_updateActionMenuItemsForStage:(MenuUpdateStage)stage;
- (BOOL)_canAddImageToPhotos;
+- (void)_showTextIndicator;
+- (void)_hideTextIndicator;
@end
@interface WKView (WKDeprecatedSPI)
@@ -97,6 +100,7 @@
{
_page = nullptr;
_wkView = nullptr;
+ _hitTestResult = ActionMenuHitTestResult();
}
- (void)prepareForMenu:(NSMenu *)menu withEvent:(NSEvent *)event
@@ -108,6 +112,8 @@
_state = ActionMenuState::Pending;
[self _updateActionMenuItemsForStage:MenuUpdateStage::PrepareForMenu];
+
+ [self _hideTextIndicator];
}
- (BOOL)isMenuForTextContent
@@ -120,6 +126,9 @@
if (menu != _wkView.actionMenu)
return;
+ if (_type == kWKActionMenuDataDetectedItem)
+ [self _showTextIndicator];
+
if (![self isMenuForTextContent])
return;
@@ -134,6 +143,9 @@
{
if (menu != _wkView.actionMenu)
return;
+
+ if (_type == kWKActionMenuDataDetectedItem && menu.numberOfItems > 1)
+ [self _hideTextIndicator];
_state = ActionMenuState::None;
_hitTestResult = ActionMenuHitTestResult();
@@ -149,6 +161,28 @@
_userData = userData;
}
+#pragma mark Text Indicator
+
+- (void)_showTextIndicator
+{
+ if (_isShowingTextIndicator)
+ return;
+
+ if (_hitTestResult.detectedDataTextIndicator) {
+ _page->setTextIndicator(_hitTestResult.detectedDataTextIndicator->data(), false, true);
+ _isShowingTextIndicator = YES;
+ }
+}
+
+- (void)_hideTextIndicator
+{
+ if (!_isShowingTextIndicator)
+ return;
+
+ _page->clearTextIndicator(false, true);
+ _isShowingTextIndicator = NO;
+}
+
#pragma mark Link actions
- (NSArray *)_defaultMenuItemsForLink
@@ -321,8 +355,12 @@
if (!actionContext)
return @[ ];
+ actionContext.completionHandler = ^() {
+ [self _hideTextIndicator];
+ };
+
WKSetDDActionContextIsForActionMenu(actionContext);
- actionContext.highlightFrame = [_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.actionBoundingBox toView:nil]];
+ actionContext.highlightFrame = [_wkView.window convertRectToScreen:[_wkView convertRect:_hitTestResult.detectedDataBoundingBox toView:nil]];
return [[getDDActionsManagerClass() sharedManager] menuItemsForResult:[_hitTestResult.actionContext mainResult] actionContext:actionContext];
}
Modified: branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2014-11-06 05:14:01 UTC (rev 175664)
@@ -4472,6 +4472,8 @@
5272B2881406985D0096A5D0 /* StatisticsData.cpp */,
5272B2891406985D0096A5D0 /* StatisticsData.h */,
1A5E4DA312D3BD3D0099A2BB /* TextCheckerState.h */,
+ 1A910070126675C4001842F5 /* TextIndicator.cpp */,
+ 1A91006F126675C3001842F5 /* TextIndicator.h */,
1A64245D12DE29A100CAAE2C /* UpdateInfo.cpp */,
1A64245C12DE29A100CAAE2C /* UpdateInfo.h */,
1AC1336518565B5700F3EC05 /* UserData.cpp */,
@@ -5798,10 +5800,8 @@
BC2652121182608100243E12 /* DrawingAreaProxy.cpp */,
BC2652131182608100243E12 /* DrawingAreaProxy.h */,
1A6422FC12DD08FE00CAAE2C /* DrawingAreaProxy.messages.in */,
- 1A910070126675C4001842F5 /* TextIndicator.cpp */,
1AE00D5E1831792100087DD7 /* FrameLoadState.cpp */,
1AE00D5F1831792100087DD7 /* FrameLoadState.h */,
- 1A91006F126675C3001842F5 /* TextIndicator.h */,
BC17753E118BABF0007D9E9A /* GenericCallback.h */,
BC06F44912DBD1F5002D78DE /* GeolocationPermissionRequestManagerProxy.cpp */,
BC06F44812DBD1F5002D78DE /* GeolocationPermissionRequestManagerProxy.h */,
Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/FindController.cpp (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/FindController.cpp 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/FindController.cpp 2014-11-06 05:14:01 UTC (rev 175664)
@@ -29,6 +29,7 @@
#include "DrawingArea.h"
#include "PluginView.h"
#include "ShareableBitmap.h"
+#include "TextIndicator.h"
#include "WKPage.h"
#include "WebCoreArgumentCoders.h"
#include "WebPage.h"
@@ -36,10 +37,8 @@
#include <WebCore/DocumentMarkerController.h>
#include <WebCore/FloatQuad.h>
#include <WebCore/FocusController.h>
-#include <WebCore/FrameSnapshotting.h>
#include <WebCore/FrameView.h>
#include <WebCore/GraphicsContext.h>
-#include <WebCore/ImageBuffer.h>
#include <WebCore/MainFrame.h>
#include <WebCore/Page.h>
#include <WebCore/PageOverlayController.h>
@@ -259,28 +258,6 @@
m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
}
-static bool getFindIndicatorBitmap(Frame& frame, ShareableBitmap::Handle& handle)
-{
- std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(frame, WebCore::SnapshotOptionsForceBlackText);
- if (!snapshot)
- return false;
-
- RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha);
- if (!findIndicatorTextBackingStore)
- return false;
-
- // FIXME: We should consider using subpixel antialiasing for the snapshot
- // if we're compositing this image onto a solid color (the modern find indicator style).
- auto graphicsContext = findIndicatorTextBackingStore->createGraphicsContext();
- float deviceScaleFactor = frame.page()->deviceScaleFactor();
- graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
- graphicsContext->drawImageBuffer(snapshot.get(), ColorSpaceDeviceRGB, FloatPoint());
-
- if (!findIndicatorTextBackingStore->createHandle(handle))
- return false;
- return true;
-}
-
void FindController::getImageForFindMatch(uint32_t matchIndex)
{
if (matchIndex >= m_findMatches.size())
@@ -292,11 +269,16 @@
VisibleSelection oldSelection = frame->selection().selection();
frame->selection().setSelection(VisibleSelection(m_findMatches[matchIndex].get()));
- ShareableBitmap::Handle handle;
- getFindIndicatorBitmap(*frame, handle);
+ RefPtr<ShareableBitmap> selectionSnapshot = WebFrame::fromCoreFrame(*frame)->createSelectionSnapshot();
frame->selection().setSelection(oldSelection);
+ if (!selectionSnapshot)
+ return;
+
+ ShareableBitmap::Handle handle;
+ selectionSnapshot->createHandle(handle);
+
if (handle.isNull())
return;
@@ -332,29 +314,12 @@
#if !PLATFORM(IOS)
bool FindController::updateFindIndicator(Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate)
{
- IntRect selectionRect = enclosingIntRect(selectedFrame.selection().selectionBounds());
- ShareableBitmap::Handle handle;
- if (!getFindIndicatorBitmap(selectedFrame, handle))
+ RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(*WebFrame::fromCoreFrame(selectedFrame));
+ if (!indicator)
return false;
- // We want the selection rect in window coordinates.
- IntRect selectionRectInWindowCoordinates = selectedFrame.view()->contentsToWindow(selectionRect);
-
- Vector<FloatRect> textRects;
- selectedFrame.selection().getClippedVisibleTextRectangles(textRects);
-
- // We want the text rects in selection rect coordinates.
- Vector<FloatRect> textRectsInSelectionRectCoordinates;
-
- for (size_t i = 0; i < textRects.size(); ++i) {
- IntRect textRectInSelectionRectCoordinates = selectedFrame.view()->contentsToWindow(enclosingIntRect(textRects[i]));
- textRectInSelectionRectCoordinates.move(-selectionRectInWindowCoordinates.x(), -selectionRectInWindowCoordinates.y());
-
- textRectsInSelectionRectCoordinates.append(textRectInSelectionRectCoordinates);
- }
-
- m_webPage->send(Messages::WebPageProxy::SetTextIndicator(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, m_webPage->corePage()->deviceScaleFactor(), handle, !isShowingOverlay, shouldAnimate));
- m_findIndicatorRect = selectionRectInWindowCoordinates;
+ m_findIndicatorRect = enclosingIntRect(indicator->selectionRectInWindowCoordinates());
+ m_webPage->send(Messages::WebPageProxy::SetTextIndicator(indicator->data(), !isShowingOverlay, shouldAnimate));
m_isShowingFindIndicator = true;
return true;
@@ -365,8 +330,7 @@
if (!m_isShowingFindIndicator)
return;
- ShareableBitmap::Handle handle;
- m_webPage->send(Messages::WebPageProxy::SetTextIndicator(FloatRect(), Vector<FloatRect>(), m_webPage->corePage()->deviceScaleFactor(), handle, false, true));
+ m_webPage->send(Messages::WebPageProxy::ClearTextIndicator(false, true));
m_isShowingFindIndicator = false;
m_foundStringMatchIndex = -1;
didHideFindIndicator();
Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp 2014-11-06 05:14:01 UTC (rev 175664)
@@ -50,12 +50,14 @@
#include <WebCore/DocumentLoader.h>
#include <WebCore/EventHandler.h>
#include <WebCore/Frame.h>
+#include <WebCore/FrameSnapshotting.h>
#include <WebCore/FrameView.h>
#include <WebCore/HTMLFormElement.h>
#include <WebCore/HTMLFrameOwnerElement.h>
#include <WebCore/HTMLInputElement.h>
#include <WebCore/HTMLNames.h>
#include <WebCore/HTMLTextAreaElement.h>
+#include <WebCore/ImageBuffer.h>
#include <WebCore/JSCSSStyleDeclaration.h>
#include <WebCore/JSElement.h>
#include <WebCore/JSRange.h>
@@ -781,5 +783,25 @@
return archive->rawDataRepresentation();
}
#endif
+
+PassRefPtr<ShareableBitmap> WebFrame::createSelectionSnapshot()
+{
+ std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(*coreFrame(), WebCore::SnapshotOptionsForceBlackText);
+ if (!snapshot)
+ return nullptr;
+
+ RefPtr<ShareableBitmap> sharedSnapshot = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha);
+ if (!sharedSnapshot)
+ return nullptr;
+
+ // FIXME: We should consider providing a way to use subpixel antialiasing for the snapshot
+ // if we're compositing this image onto a solid color (e.g. the modern find indicator style).
+ auto graphicsContext = sharedSnapshot->createGraphicsContext();
+ float deviceScaleFactor = coreFrame()->page()->deviceScaleFactor();
+ graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
+ graphicsContext->drawImageBuffer(snapshot.get(), ColorSpaceDeviceRGB, FloatPoint());
+
+ return sharedSnapshot.release();
+}
} // namespace WebKit
Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.h (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.h 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/WebFrame.h 2014-11-06 05:14:01 UTC (rev 175664)
@@ -27,6 +27,7 @@
#define WebFrame_h
#include "APIObject.h"
+#include "ShareableBitmap.h"
#include "WKBase.h"
#include "WebFrameLoaderClient.h"
#include <_javascript_Core/JSBase.h>
@@ -149,6 +150,8 @@
RetainPtr<CFDataRef> webArchiveData(FrameFilterFunction, void* context);
#endif
+ PassRefPtr<ShareableBitmap> createSelectionSnapshot();
+
private:
static PassRefPtr<WebFrame> create(std::unique_ptr<WebFrameLoaderClient>);
WebFrame(std::unique_ptr<WebFrameLoaderClient>);
Modified: branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (175663 => 175664)
--- branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-06 05:04:00 UTC (rev 175663)
+++ branches/safari-600.3-branch/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm 2014-11-06 05:14:01 UTC (rev 175664)
@@ -1072,7 +1072,7 @@
return String();
}
-static RetainPtr<DDActionContext> scanForDataDetectedItems(const HitTestResult& hitTestResult, FloatRect& actionBoundingBox)
+static RetainPtr<DDActionContext> scanForDataDetectedItems(const HitTestResult& hitTestResult, FloatRect& detectedDataBoundingBox, RefPtr<Range>& detectedDataRange)
{
Node* node = hitTestResult.innerNonSharedNode();
if (!node)
@@ -1123,11 +1123,33 @@
Vector<FloatQuad> quads;
mainResultRange->textQuads(quads);
if (!quads.isEmpty())
- actionBoundingBox = mainResultRange->ownerDocument().view()->contentsToWindow(quads[0].enclosingBoundingBox());
+ detectedDataBoundingBox = mainResultRange->ownerDocument().view()->contentsToWindow(quads[0].enclosingBoundingBox());
+ detectedDataRange = mainResultRange;
+
return actionContext;
}
+static PassRefPtr<TextIndicator> textIndicatorForRange(Range* range)
+{
+ if (!range)
+ return nullptr;
+
+ Frame* frame = range->startContainer()->document().frame();
+
+ if (!frame)
+ return nullptr;
+
+ VisibleSelection oldSelection = frame->selection().selection();
+ frame->selection().setSelection(range);
+
+ RefPtr<TextIndicator> indicator = TextIndicator::createWithSelectionInFrame(*WebFrame::fromCoreFrame(*frame));
+
+ frame->selection().setSelection(oldSelection);
+
+ return indicator.release();
+}
+
void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInViewCooordinates)
{
layoutIfNeeded();
@@ -1161,9 +1183,13 @@
// FIXME: Avoid scanning if we will just throw away the result (e.g. we're over a link).
if (hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode()) {
- FloatRect actionBoundingBox;
- actionMenuResult.actionContext = scanForDataDetectedItems(hitTestResult, actionBoundingBox);
- actionMenuResult.actionBoundingBox = actionBoundingBox;
+ FloatRect detectedDataBoundingBox;
+ RefPtr<Range> detectedDataRange;
+ actionMenuResult.actionContext = scanForDataDetectedItems(hitTestResult, detectedDataBoundingBox, detectedDataRange);
+ if (actionMenuResult.actionContext) {
+ actionMenuResult.detectedDataBoundingBox = detectedDataBoundingBox;
+ actionMenuResult.detectedDataTextIndicator = textIndicatorForRange(detectedDataRange.get());
+ }
}
RefPtr<API::Object> userData;