ServicesOverlayController.h [plain text]
#pragma once
#if (ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)) && PLATFORM(MAC)
#include "GraphicsLayerClient.h"
#include "PageOverlay.h"
#include "Range.h"
#include "Timer.h"
#include <wtf/RefCounted.h>
typedef struct __DDHighlight *DDHighlightRef;
namespace WebCore {
class LayoutRect;
class MainFrame;
struct GapRects;
class ServicesOverlayController : private PageOverlay::Client {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit ServicesOverlayController(MainFrame&);
~ServicesOverlayController();
void selectedTelephoneNumberRangesChanged();
void selectionRectsDidChange(const Vector<LayoutRect>&, const Vector<GapRects>&, bool isTextOnly);
private:
class Highlight : public RefCounted<Highlight>, private GraphicsLayerClient {
WTF_MAKE_NONCOPYABLE(Highlight);
public:
static Ref<Highlight> createForSelection(ServicesOverlayController&, RetainPtr<DDHighlightRef>, PassRefPtr<Range>);
static Ref<Highlight> createForTelephoneNumber(ServicesOverlayController&, RetainPtr<DDHighlightRef>, PassRefPtr<Range>);
~Highlight();
void invalidate();
DDHighlightRef ddHighlight() const { return m_ddHighlight.get(); }
Range* range() const { return m_range.get(); }
GraphicsLayer* layer() const { return m_graphicsLayer.get(); }
enum {
TelephoneNumberType = 1 << 0,
SelectionType = 1 << 1,
};
typedef uint8_t Type;
Type type() const { return m_type; }
void fadeIn();
void fadeOut();
void setDDHighlight(DDHighlightRef);
private:
explicit Highlight(ServicesOverlayController&, Type, RetainPtr<DDHighlightRef>, PassRefPtr<Range>);
void notifyFlushRequired(const GraphicsLayer*) override;
void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const FloatRect& inClip) override;
float deviceScaleFactor() const override;
void didFinishFadeOutAnimation();
RetainPtr<DDHighlightRef> m_ddHighlight;
RefPtr<Range> m_range;
std::unique_ptr<GraphicsLayer> m_graphicsLayer;
Type m_type;
ServicesOverlayController* m_controller;
};
void willMoveToPage(PageOverlay&, Page*) override;
void didMoveToPage(PageOverlay&, Page*) override;
void drawRect(PageOverlay&, GraphicsContext&, const IntRect& dirtyRect) override;
bool mouseEvent(PageOverlay&, const PlatformMouseEvent&) override;
void didScrollFrame(PageOverlay&, Frame&) override;
void createOverlayIfNeeded();
void handleClick(const IntPoint&, Highlight&);
void drawHighlight(Highlight&, GraphicsContext&);
void invalidateHighlightsOfType(Highlight::Type);
void buildPotentialHighlightsIfNeeded();
void replaceHighlightsOfTypePreservingEquivalentHighlights(HashSet<RefPtr<Highlight>>&, Highlight::Type);
void removeAllPotentialHighlightsOfType(Highlight::Type);
void buildPhoneNumberHighlights();
void buildSelectionHighlight();
void determineActiveHighlight(bool& mouseIsOverButton);
void clearActiveHighlight();
Highlight* activeHighlight() const { return m_activeHighlight.get(); }
Highlight* findTelephoneNumberHighlightContainingSelectionHighlight(Highlight&);
bool hasRelevantSelectionServices();
bool mouseIsOverHighlight(Highlight&, bool& mouseIsOverButton) const;
std::chrono::milliseconds remainingTimeUntilHighlightShouldBeShown(Highlight*) const;
void determineActiveHighlightTimerFired();
static bool highlightsAreEquivalent(const Highlight* a, const Highlight* b);
Vector<RefPtr<Range>> telephoneNumberRangesForFocusedFrame();
void didCreateHighlight(Highlight*);
void willDestroyHighlight(Highlight*);
void didFinishFadingOutHighlight(Highlight*);
MainFrame& mainFrame() const { return m_mainFrame; }
MainFrame& m_mainFrame;
PageOverlay* m_servicesOverlay { nullptr };
RefPtr<Highlight> m_activeHighlight;
RefPtr<Highlight> m_nextActiveHighlight;
HashSet<RefPtr<Highlight>> m_potentialHighlights;
HashSet<RefPtr<Highlight>> m_animatingHighlights;
HashSet<Highlight*> m_highlights;
Vector<LayoutRect> m_currentSelectionRects;
bool m_isTextOnly { false };
Highlight::Type m_dirtyHighlightTypes { 0 };
std::chrono::steady_clock::time_point m_lastSelectionChangeTime;
std::chrono::steady_clock::time_point m_nextActiveHighlightChangeTime;
std::chrono::steady_clock::time_point m_lastMouseUpTime;
RefPtr<Highlight> m_currentMouseDownOnButtonHighlight;
IntPoint m_mousePosition;
Timer m_determineActiveHighlightTimer;
Timer m_buildHighlightsTimer;
};
}
#endif // (ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)) && PLATFORM(MAC)