tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PrintedSheetFrame.h (6074B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 /* Rendering object for a printed or print-previewed sheet of paper */
      8 
      9 #ifndef LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_
     10 #define LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_
     11 
     12 #include "mozilla/gfx/Point.h"
     13 #include "nsContainerFrame.h"
     14 #include "nsHTMLParts.h"
     15 
     16 class nsSharedPageData;
     17 
     18 namespace mozilla {
     19 
     20 class PrintedSheetFrame final : public nsContainerFrame {
     21 public:
     22  using IntSize = mozilla::gfx::IntSize;
     23 
     24  NS_DECL_QUERYFRAME
     25  NS_DECL_FRAMEARENA_HELPERS(PrintedSheetFrame)
     26 
     27  friend PrintedSheetFrame* ::NS_NewPrintedSheetFrame(
     28      mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
     29 
     30  void SetSharedPageData(nsSharedPageData* aPD) { mPD = aPD; }
     31 
     32  // XXX: this needs a better name, since it also updates style.
     33  // Invokes MoveOverflowToChildList.
     34  // This is intended for use by callers that need to be able to get our first/
     35  // only nsPageFrame from our child list to examine its computed style just
     36  // **prior** to us being reflowed. (If our first nsPageFrame will come from
     37  // our prev-in-flow, we won't otherwise take ownership of it until we are
     38  // reflowed.)
     39  void ClaimPageFrameFromPrevInFlow();
     40 
     41  // nsIFrame overrides
     42  void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput,
     43              const ReflowInput& aReflowInput,
     44              nsReflowStatus& aStatus) override;
     45 
     46  void BuildDisplayList(nsDisplayListBuilder* aBuilder,
     47                        const nsDisplayListSet& aLists) override;
     48 
     49 #ifdef DEBUG_FRAME_DUMP
     50  nsresult GetFrameName(nsAString& aResult) const override;
     51 #endif
     52 
     53  uint32_t GetNumPages() const { return mNumPages; }
     54 
     55  // These methods provide information about the grid that pages should be
     56  // placed into in the case that there are multiple pages-per-sheet.
     57  uint32_t GetGridNumCols() const { return mGridNumCols; }
     58  nsPoint GetGridOrigin() const { return mGridOrigin; }
     59  nscoord GetGridCellWidth() const { return mGridCellWidth; }
     60  nscoord GetGridCellHeight() const { return mGridCellHeight; }
     61 
     62  nsSize ComputeSheetSize(const nsPresContext* aPresContext);
     63 
     64  /**
     65   * When we're printing one page-per-sheet and `page-orientation` on our
     66   * single nsPageFrame child should cause the page to rotate, then we want to
     67   * essentially rotate the sheet. We implement that by switching the
     68   * dimensions of this sheet (changing its orientation), sizing the
     69   * nsPageFrame to the original dimensions, and then applying the rotation to
     70   * the nsPageFrame child.
     71   *
     72   * This returns the dimensions that this frame would have without any
     73   * dimension swap we may have done to implement `page-orientation`. If
     74   * there is no rotation caused by `page-orientation`, then the value returned
     75   * and mRect.Size() are identical.
     76   */
     77  nsSize GetSizeForChildren() const { return mSizeForChildren; }
     78 
     79  /**
     80   * This method returns the dimensions of the physical page that the target
     81   * [pseudo-]printer should create. This may be different from our own
     82   * dimensions in the case where CSS `page-orientation` causes us to be
     83   * rotated, but we only support that if the PrintTarget backend supports
     84   * different page sizes/orientations. That's only the case for our Save-to-PDF
     85   * backends (possibly other save-to-file outputs in future).
     86   *
     87   * The dimensions returned are expected to be passed to
     88   * nsDeviceContext::BeginPage, which will pass them on to
     89   * PrintTarget::BeginPage to use as the physical dimensions of the page.
     90   */
     91  IntSize GetPrintTargetSizeInPoints(
     92      const int32_t aAppUnitsPerPhysicalInch) const;
     93 
     94 private:
     95  // Private construtor & destructor, to avoid accidental (non-FrameArena)
     96  // instantiation/deletion:
     97  PrintedSheetFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
     98      : nsContainerFrame(aStyle, aPresContext, kClassID) {}
     99  ~PrintedSheetFrame() = default;
    100 
    101  // Helper function to populate some pages-per-sheet metrics in our
    102  // nsSharedPageData.
    103  // XXXjwatt: We should investigate sharing this function for the single
    104  // page-per-sheet case (bug 1835782). The logic for that case
    105  // (nsPageFrame::ComputePageSizeScale) is somewhat different though, since
    106  // that case uses no sheet margins and uses the user/CSS specified margins on
    107  // the page, with any page scaling reverted to keep the margins unchanged.
    108  // We, on the other hand, use the unwriteable margins for the sheet, unscaled,
    109  // and use the user/CSS margins on the pages and allow them to be scaled
    110  // along with any pages-per-sheet scaling. (This behavior makes maximum use
    111  // of the sheet and, by scaling the default on the pages, results in a
    112  // a sensible amount of spacing between pages.)
    113  void ComputePagesPerSheetGridMetrics(const nsSize& aSheetSize);
    114 
    115  // See GetSizeForChildren.
    116  nsSize mSizeForChildren;
    117 
    118  // Note: this will be set before reflow, and it's strongly owned by our
    119  // nsPageSequenceFrame, which outlives us.
    120  nsSharedPageData* mPD = nullptr;
    121 
    122  // The number of visible pages in this sheet.
    123  uint32_t mNumPages = 0;
    124 
    125  // Number of "columns" in our pages-per-sheet layout. For example: if we're
    126  // printing with 6 pages-per-sheet, then this could be either 3 or 2,
    127  // depending on whether we're printing portrait-oriented pages onto a
    128  // landscape-oriented sheet (3 cols) vs. if we're printing landscape-oriented
    129  // pages onto a portrait-oriented sheet (2 cols).
    130  uint32_t mGridNumCols = 1;
    131 
    132  // The offset of the start of the multiple pages-per-sheet grid from the
    133  // top-left of the sheet.
    134  nsPoint mGridOrigin;
    135 
    136  // The size of each cell on the sheet into which pages are to be placed.
    137  // (The default values are arbitrary.)
    138  nscoord mGridCellWidth = 1;
    139  nscoord mGridCellHeight = 1;
    140 };
    141 
    142 }  // namespace mozilla
    143 
    144 #endif /* LAYOUT_GENERIC_PRINTEDSHEETFRAME_H_ */