#pragma once
#include "FrameDestructionObserver.h"
#include "LengthBox.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class Document;
class Element;
class Frame;
class FloatRect;
class FloatSize;
class GraphicsContext;
class IntRect;
class Node;
class PrintContext : public FrameDestructionObserver {
WTF_MAKE_FAST_ALLOCATED;
public:
WEBCORE_EXPORT explicit PrintContext(Frame*);
WEBCORE_EXPORT ~PrintContext();
WEBCORE_EXPORT void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling = false);
WEBCORE_EXPORT void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
size_t pageCount() const { return m_pageRects.size(); }
const IntRect& pageRect(size_t pageNumber) const { return m_pageRects[pageNumber]; }
const Vector<IntRect>& pageRects() const { return m_pageRects; }
WEBCORE_EXPORT FloatBoxExtent computedPageMargin(FloatBoxExtent printMargin);
WEBCORE_EXPORT FloatSize computedPageSize(FloatSize pageSize, FloatBoxExtent printMargin);
WEBCORE_EXPORT float computeAutomaticScaleFactor(const FloatSize& availablePaperSize);
WEBCORE_EXPORT void begin(float width, float height = 0);
WEBCORE_EXPORT void spoolPage(GraphicsContext& ctx, int pageNumber, float width);
WEBCORE_EXPORT void spoolRect(GraphicsContext& ctx, const IntRect&);
WEBCORE_EXPORT void end();
WEBCORE_EXPORT static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); WEBCORE_EXPORT static String pageProperty(Frame*, const char* propertyName, int pageNumber);
WEBCORE_EXPORT static bool isPageBoxVisible(Frame*, int pageNumber);
WEBCORE_EXPORT static String pageSizeAndMarginsInPixels(Frame*, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
WEBCORE_EXPORT static int numberOfPages(Frame&, const FloatSize& pageSizeInPixels);
WEBCORE_EXPORT static void spoolAllPagesWithBoundaries(Frame&, GraphicsContext&, const FloatSize& pageSizeInPixels);
static constexpr float minimumShrinkFactor() { return 1.25; }
static constexpr float maximumShrinkFactor() { return 2; }
protected:
Vector<IntRect> m_pageRects;
private:
void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
bool beginAndComputePageRectsWithPageSize(Frame&, const FloatSize& pageSizeInPixels);
void collectLinkedDestinations(Document&);
void outputLinkedDestinations(GraphicsContext&, Document&, const IntRect& pageRect);
bool m_isPrinting { false };
std::unique_ptr<HashMap<String, Ref<Element>>> m_linkedDestinations;
};
}