[go: nahoru, domu]

Clarify page rectangles in DocumentLayout

This change splits DocumentLayout::page_rect() into two methods,
page_rect() and page_bounds_rect(), to better mirror the corresponding
APIs in PDFEngine, GetPageRect() (page rectangle before insets) and
GetPageBoundsRect() (page rectangle after insets).

The existing page_rect() method is equivalent to PDFEngine's
GetPageBoundsRect(), which is confusing, so it has been renamed to
page_bounds_rect(). The new page_rect() method is equivalent to
PDFEngine's GetPageRect(). (This will be useful in a future change.)

DocumentLayout is now responsible for adding insets to the page
rectangles returned by draw_utils::GetRectForSingleView(), etc.,
eliminating the need to pass the insets to these functions.

Bug: 885110
Change-Id: I4ef345333abbb5b75892c32ffff8dee24e20ef05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1762601
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: K Moon <kmoon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689735}
diff --git a/pdf/document_layout.h b/pdf/document_layout.h
index 2e95c59..5b395d6 100644
--- a/pdf/document_layout.h
+++ b/pdf/document_layout.h
@@ -74,12 +74,19 @@
   // TODO(kmoon): Get rid of this method.
   void set_size(const pp::Size& size) { size_ = size; }
 
-  size_t page_count() const { return page_rects_.size(); }
+  size_t page_count() const { return page_layouts_.size(); }
 
   // Gets the layout rectangle for a page. Only valid after computing a layout.
   const pp::Rect& page_rect(size_t page_index) const {
     DCHECK_LT(page_index, page_count());
-    return page_rects_[page_index];
+    return page_layouts_[page_index].outer_rect;
+  }
+
+  // Gets the layout rectangle for a page's bounds (which excludes additional
+  // regions like page shadows). Only valid after computing a layout.
+  const pp::Rect& page_bounds_rect(size_t page_index) const {
+    DCHECK_LT(page_index, page_count());
+    return page_layouts_[page_index].inner_rect;
   }
 
   // Computes layout that represent |page_sizes| formatted for single view.
@@ -98,13 +105,21 @@
   void EnlargeHeight(int height);
 
  private:
+  // Layout of a single page.
+  struct PageLayout {
+    // Bounding rectangle for the page with decorations.
+    pp::Rect outer_rect;
+
+    // Bounding rectangle for the page without decorations.
+    pp::Rect inner_rect;
+  };
+
   Options options_;
 
   // Layout's total size.
   pp::Size size_;
 
-  // Page layout rectangles.
-  std::vector<pp::Rect> page_rects_;
+  std::vector<PageLayout> page_layouts_;
 };
 
 }  // namespace chrome_pdf