#pragma once
#include "ShareableBitmap.h"
#include "WebFindOptions.h"
#include <WebCore/FindOptions.h>
#include <WebCore/IntRect.h>
#include <WebCore/PageOverlay.h>
#include <WebCore/SimpleRange.h>
#include <wtf/Forward.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
#if PLATFORM(IOS_FAMILY)
#include "FindIndicatorOverlayClientIOS.h"
#endif
namespace WebCore {
class Frame;
class Range;
enum class DidWrap : bool;
}
namespace WebKit {
class CallbackID;
class WebPage;
class FindController : private WebCore::PageOverlay::Client {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(FindController);
public:
explicit FindController(WebPage*);
virtual ~FindController();
void findString(const String&, OptionSet<FindOptions>, unsigned maxMatchCount, CompletionHandler<void(bool)>&&);
void findStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount);
void getImageForFindMatch(uint32_t matchIndex);
void selectFindMatch(uint32_t matchIndex);
void indicateFindMatch(uint32_t matchIndex);
void hideFindUI();
void countStringMatches(const String&, OptionSet<FindOptions>, unsigned maxMatchCount);
uint32_t replaceMatches(const Vector<uint32_t>& matchIndices, const String& replacementText, bool selectionOnly);
void hideFindIndicator();
void resetMatchIndex();
void showFindIndicatorInSelection();
bool isShowingOverlay() const { return m_isShowingFindIndicator && m_findPageOverlay; }
void deviceScaleFactorDidChange();
void didInvalidateDocumentMarkerRects();
void redraw();
private:
void willMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
void didMoveToPage(WebCore::PageOverlay&, WebCore::Page*) override;
bool mouseEvent(WebCore::PageOverlay&, const WebCore::PlatformMouseEvent&) override;
void drawRect(WebCore::PageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect) override;
Vector<WebCore::FloatRect> rectsForTextMatchesInRect(WebCore::IntRect clipRect);
bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
enum class FindUIOriginator : uint8_t { FindString, FindStringMatches };
void updateFindUIAfterPageScroll(bool found, const String&, OptionSet<FindOptions>, unsigned maxMatchCount, WebCore::DidWrap, FindUIOriginator);
void willFindString();
void didFindString();
void didFailToFindString();
void didHideFindIndicator();
unsigned findIndicatorRadius() const;
bool shouldHideFindIndicatorOnScroll() const;
void didScrollAffectingFindIndicatorPosition();
WebPage* m_webPage;
WebCore::PageOverlay* m_findPageOverlay { nullptr };
bool m_isShowingFindIndicator { false };
WebCore::IntRect m_findIndicatorRect;
Vector<WebCore::SimpleRange> m_findMatches;
int m_foundStringMatchIndex { -1 };
#if PLATFORM(IOS_FAMILY)
RefPtr<WebCore::PageOverlay> m_findIndicatorOverlay;
std::unique_ptr<FindIndicatorOverlayClientIOS> m_findIndicatorOverlayClient;
#endif
};
WebCore::FindOptions core(OptionSet<FindOptions>);
}