1 /* 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Apple Inc. 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef PrintContext_h 22 #define PrintContext_h 23 24 #include "platform/heap/Handle.h" 25 #include "platform/weborigin/KURLHash.h" 26 #include "wtf/Forward.h" 27 #include "wtf/HashMap.h" 28 #include "wtf/Vector.h" 29 #include "wtf/text/WTFString.h" 30 31 namespace blink { 32 33 class Element; 34 class LocalFrame; 35 class FloatRect; 36 class FloatSize; 37 class GraphicsContext; 38 class IntRect; 39 class Node; 40 41 class PrintContext : public NoBaseWillBeGarbageCollectedFinalized<PrintContext> { 42 public: 43 explicit PrintContext(LocalFrame*); 44 virtual ~PrintContext(); 45 frame()46 LocalFrame* frame() const { return m_frame; } 47 48 // Break up a page into rects without relayout. 49 // FIXME: This means that CSS page breaks won't be on page boundary if the size is different than what was passed to begin(). That's probably not always desirable. 50 // FIXME: Header and footer height should be applied before layout, not after. 51 // FIXME: The printRect argument is only used to determine page aspect ratio, it would be better to pass a FloatSize with page dimensions instead. 52 virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight); 53 54 // Deprecated. Page size computation is already in this class, clients shouldn't be copying it. 55 // FIXME: Everyone passes |false| for the second paramer. We should remove the second parameter. 56 virtual void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling); 57 58 // These are only valid after page rects are computed. pageCount()59 size_t pageCount() const { return m_pageRects.size(); } pageRect(size_t pageNumber)60 const IntRect& pageRect(size_t pageNumber) const { return m_pageRects[pageNumber]; } pageRects()61 const Vector<IntRect>& pageRects() const { return m_pageRects; } 62 63 // Enter print mode, updating layout for new page size. 64 // This function can be called multiple times to apply new print options without going back to screen mode. 65 virtual void begin(float width, float height = 0); 66 67 // Return to screen mode. 68 virtual void end(); 69 70 // Used by layout tests. 71 static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); // Returns -1 if page isn't found. 72 static String pageProperty(LocalFrame* frame, const char* propertyName, int pageNumber); 73 static bool isPageBoxVisible(LocalFrame* frame, int pageNumber); 74 static String pageSizeAndMarginsInPixels(LocalFrame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft); 75 static int numberOfPages(LocalFrame*, const FloatSize& pageSizeInPixels); 76 77 virtual void trace(Visitor*); 78 79 protected: 80 void outputLinkAndLinkedDestinations(GraphicsContext&, Node*, const IntRect& pageRect); 81 82 RawPtrWillBeMember<LocalFrame> m_frame; 83 Vector<IntRect> m_pageRects; 84 85 private: 86 void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling); 87 void collectLinkAndLinkedDestinations(Node*); 88 89 // Used to prevent misuses of begin() and end() (e.g., call end without begin). 90 bool m_isPrinting; 91 92 WillBeHeapHashMap<RawPtrWillBeMember<Element>, KURL> m_linkDestinations; 93 WillBeHeapHashMap<String, RawPtrWillBeMember<Element> > m_linkedDestinations; 94 bool m_linkAndLinkedDestinationsValid; 95 }; 96 97 } 98 99 #endif 100