2 * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "ShareableBitmap.h"
29 #include "WebFindOptions.h"
30 #include <WebCore/FindOptions.h>
31 #include <WebCore/IntRect.h>
32 #include <WebCore/PageOverlay.h>
33 #include <wtf/Forward.h>
34 #include <wtf/Noncopyable.h>
35 #include <wtf/Vector.h>
37 #if PLATFORM(IOS_FAMILY)
38 #include "FindIndicatorOverlayClientIOS.h"
44 enum class DidWrap : bool;
51 class FindController : private WebCore::PageOverlay::Client {
52 WTF_MAKE_FAST_ALLOCATED;
53 WTF_MAKE_NONCOPYABLE(FindController);
56 explicit FindController(WebPage*);
57 virtual ~FindController();
59 void findString(const String&, FindOptions, unsigned maxMatchCount, Optional<CallbackID>);
60 void findStringMatches(const String&, FindOptions, unsigned maxMatchCount);
61 void getImageForFindMatch(uint32_t matchIndex);
62 void selectFindMatch(uint32_t matchIndex);
63 void indicateFindMatch(uint32_t matchIndex);
65 void countStringMatches(const String&, FindOptions, unsigned maxMatchCount);
66 uint32_t replaceMatches(const Vector<uint32_t>& matchIndices, const String& replacementText, bool selectionOnly);
68 void hideFindIndicator();
69 void resetMatchIndex();
70 void showFindIndicatorInSelection();
72 bool isShowingOverlay() const { return m_isShowingFindIndicator && m_findPageOverlay; }
74 void deviceScaleFactorDidChange();
75 void didInvalidateDocumentMarkerRects();
80 // PageOverlay::Client.
81 void willMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
82 void didMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
83 bool mouseEvent(WebCore::PageOverlay&, const WebCore::PlatformMouseEvent&) override;
84 void drawRect(WebCore::PageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
86 Vector<WebCore::FloatRect> rectsForTextMatchesInRect(WebCore::IntRect clipRect);
87 bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
89 enum class FindUIOriginator : uint8_t { FindString, FindStringMatches };
90 void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount, WebCore::DidWrap, FindUIOriginator);
92 void willFindString();
94 void didFailToFindString();
95 void didHideFindIndicator();
97 unsigned findIndicatorRadius() const;
98 bool shouldHideFindIndicatorOnScroll() const;
99 void didScrollAffectingFindIndicatorPosition();
102 WebCore::PageOverlay* m_findPageOverlay { nullptr };
104 // Whether the UI process is showing the find indicator. Note that this can be true even if
105 // the find indicator isn't showing, but it will never be false when it is showing.
106 bool m_isShowingFindIndicator { false };
107 WebCore::IntRect m_findIndicatorRect;
108 Vector<RefPtr<WebCore::Range>> m_findMatches;
109 // Index value is -1 if not found or if number of matches exceeds provided maximum.
110 int m_foundStringMatchIndex { -1 };
112 #if PLATFORM(IOS_FAMILY)
113 RefPtr<WebCore::PageOverlay> m_findIndicatorOverlay;
114 std::unique_ptr<FindIndicatorOverlayClientIOS> m_findIndicatorOverlayClient;
118 WebCore::FindOptions core(FindOptions);
120 } // namespace WebKit