layout/generic/nsSimplePageSequenceFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/nsSimplePageSequenceFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsSimplePageSequenceFrame_h___
     1.9 +#define nsSimplePageSequenceFrame_h___
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nsIPageSequenceFrame.h"
    1.13 +#include "nsContainerFrame.h"
    1.14 +#include "nsIPrintSettings.h"
    1.15 +#include "nsIPrintOptions.h"
    1.16 +
    1.17 +class nsIDateTimeFormat;
    1.18 +
    1.19 +namespace mozilla {
    1.20 +namespace dom {
    1.21 +
    1.22 +class HTMLCanvasElement;
    1.23 +
    1.24 +}
    1.25 +}
    1.26 +
    1.27 +//-----------------------------------------------
    1.28 +// This class maintains all the data that 
    1.29 +// is used by all the page frame
    1.30 +// It lives while the nsSimplePageSequenceFrame lives
    1.31 +class nsSharedPageData {
    1.32 +public:
    1.33 +  // This object a shared by all the nsPageFrames
    1.34 +  // parented to a SimplePageSequenceFrame
    1.35 +  nsSharedPageData() : mShrinkToFitRatio(1.0f) {}
    1.36 +
    1.37 +  nsString    mDateTimeStr;
    1.38 +  nsString    mPageNumFormat;
    1.39 +  nsString    mPageNumAndTotalsFormat;
    1.40 +  nsString    mDocTitle;
    1.41 +  nsString    mDocURL;
    1.42 +  nsFont      mHeadFootFont;
    1.43 +
    1.44 +  nsSize      mReflowSize;
    1.45 +  nsMargin    mReflowMargin;
    1.46 +  // Margin for headers and footers; it defaults to 4/100 of an inch on UNIX 
    1.47 +  // and 0 elsewhere; I think it has to do with some inconsistency in page size
    1.48 +  // computations
    1.49 +  nsMargin    mEdgePaperMargin;
    1.50 +
    1.51 +  nsCOMPtr<nsIPrintSettings> mPrintSettings;
    1.52 +  nsCOMPtr<nsIPrintOptions> mPrintOptions;
    1.53 +
    1.54 +  // The scaling ratio we need to apply to make all pages fit horizontally.  It's
    1.55 +  // the minimum "ComputedWidth / OverflowWidth" ratio of all page content frames
    1.56 +  // that overflowed.  It's 1.0 if none overflowed horizontally.
    1.57 +  float mShrinkToFitRatio;
    1.58 +};
    1.59 +
    1.60 +// Simple page sequence frame class. Used when we're in paginated mode
    1.61 +class nsSimplePageSequenceFrame : public nsContainerFrame,
    1.62 +                                  public nsIPageSequenceFrame {
    1.63 +public:
    1.64 +  friend nsIFrame* NS_NewSimplePageSequenceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.65 +
    1.66 +  NS_DECL_QUERYFRAME
    1.67 +  NS_DECL_FRAMEARENA_HELPERS
    1.68 +
    1.69 +  // nsIFrame
    1.70 +  virtual nsresult  Reflow(nsPresContext*      aPresContext,
    1.71 +                           nsHTMLReflowMetrics& aDesiredSize,
    1.72 +                           const nsHTMLReflowState& aMaxSize,
    1.73 +                           nsReflowStatus&      aStatus) MOZ_OVERRIDE;
    1.74 +
    1.75 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.76 +                                const nsRect&           aDirtyRect,
    1.77 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.78 +
    1.79 +  // nsIPageSequenceFrame
    1.80 +  NS_IMETHOD SetPageNo(int32_t aPageNo) { return NS_OK;}
    1.81 +  NS_IMETHOD SetSelectionHeight(nscoord aYOffset, nscoord aHeight) MOZ_OVERRIDE { mYSelOffset = aYOffset; mSelectionHeight = aHeight; return NS_OK; }
    1.82 +  NS_IMETHOD SetTotalNumPages(int32_t aTotal) MOZ_OVERRIDE { mTotalPages = aTotal; return NS_OK; }
    1.83 +  
    1.84 +  // For Shrink To Fit
    1.85 +  NS_IMETHOD GetSTFPercent(float& aSTFPercent) MOZ_OVERRIDE;
    1.86 +
    1.87 +  // Async Printing
    1.88 +  NS_IMETHOD StartPrint(nsPresContext*    aPresContext,
    1.89 +                        nsIPrintSettings* aPrintSettings,
    1.90 +                        const nsAString&  aDocTitle,
    1.91 +                        const nsAString&  aDocURL) MOZ_OVERRIDE;
    1.92 +  NS_IMETHOD PrePrintNextPage(nsITimerCallback* aCallback, bool* aDone) MOZ_OVERRIDE;
    1.93 +  NS_IMETHOD PrintNextPage() MOZ_OVERRIDE;
    1.94 +  NS_IMETHOD ResetPrintCanvasList() MOZ_OVERRIDE;
    1.95 +  NS_IMETHOD GetCurrentPageNum(int32_t* aPageNum) MOZ_OVERRIDE;
    1.96 +  NS_IMETHOD GetNumPages(int32_t* aNumPages) MOZ_OVERRIDE;
    1.97 +  NS_IMETHOD IsDoingPrintRange(bool* aDoing) MOZ_OVERRIDE;
    1.98 +  NS_IMETHOD GetPrintRange(int32_t* aFromPage, int32_t* aToPage) MOZ_OVERRIDE;
    1.99 +  NS_IMETHOD DoPageEnd() MOZ_OVERRIDE;
   1.100 +
   1.101 +  // We must allow Print Preview UI to have a background, no matter what the
   1.102 +  // user's settings
   1.103 +  virtual bool HonorPrintBackgroundSettings() MOZ_OVERRIDE { return false; }
   1.104 +
   1.105 +  virtual bool HasTransformGetter() const MOZ_OVERRIDE { return true; }
   1.106 +
   1.107 +  /**
   1.108 +   * Get the "type" of the frame
   1.109 +   *
   1.110 +   * @see nsGkAtoms::sequenceFrame
   1.111 +   */
   1.112 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
   1.113 +
   1.114 +#ifdef DEBUG_FRAME_DUMP
   1.115 +  virtual nsresult  GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.116 +#endif
   1.117 +
   1.118 +protected:
   1.119 +  nsSimplePageSequenceFrame(nsStyleContext* aContext);
   1.120 +  virtual ~nsSimplePageSequenceFrame();
   1.121 +
   1.122 +  void SetPageNumberFormat(const char* aPropName, const char* aDefPropVal, bool aPageNumOnly);
   1.123 +
   1.124 +  // SharedPageData Helper methods
   1.125 +  void SetDateTimeStr(const nsAString& aDateTimeStr);
   1.126 +  void SetPageNumberFormat(const nsAString& aFormatStr, bool aForPageNumOnly);
   1.127 +
   1.128 +  // Sets the frame desired size to the size of the viewport, or the given
   1.129 +  // nscoords, whichever is larger. Print scaling is applied in this function.
   1.130 +  void SetDesiredSize(nsHTMLReflowMetrics& aDesiredSize,
   1.131 +                      const nsHTMLReflowState& aReflowState,
   1.132 +                      nscoord aWidth, nscoord aHeight);
   1.133 +
   1.134 +  void DetermineWhetherToPrintPage();
   1.135 +  nsIFrame* GetCurrentPageFrame();
   1.136 +
   1.137 +  nsMargin mMargin;
   1.138 +
   1.139 +  // I18N date formatter service which we'll want to cache locally.
   1.140 +  nsCOMPtr<nsIDateTimeFormat> mDateFormatter;
   1.141 +
   1.142 +  nsSize       mSize;
   1.143 +  nsSharedPageData* mPageData; // data shared by all the nsPageFrames
   1.144 +
   1.145 +  // Asynch Printing
   1.146 +  int32_t      mPageNum;
   1.147 +  int32_t      mTotalPages;
   1.148 +  int32_t      mPrintRangeType;
   1.149 +  int32_t      mFromPageNum;
   1.150 +  int32_t      mToPageNum;
   1.151 +  nsTArray<int32_t> mPageRanges;
   1.152 +  nsTArray<nsRefPtr<mozilla::dom::HTMLCanvasElement> > mCurrentCanvasList;
   1.153 +
   1.154 +  // Selection Printing Info
   1.155 +  nscoord      mSelectionHeight;
   1.156 +  nscoord      mYSelOffset;
   1.157 +
   1.158 +  // Asynch Printing
   1.159 +  bool mPrintThisPage;
   1.160 +  bool mDoingPageRange;
   1.161 +
   1.162 +  bool mIsPrintingSelection;
   1.163 +
   1.164 +  bool mCalledBeginPage;
   1.165 +
   1.166 +  bool mCurrentCanvasListSetup;
   1.167 +};
   1.168 +
   1.169 +#endif /* nsSimplePageSequenceFrame_h___ */
   1.170 +

mercurial