File: pdf_ink_module_client.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (165 lines) | stat: -rw-r--r-- 6,385 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_PDF_INK_MODULE_CLIENT_H_
#define PDF_PDF_INK_MODULE_CLIENT_H_

#include <map>

#include "pdf/buildflags.h"
#include "pdf/page_orientation.h"
#include "pdf/pdf_ink_ids.h"
#include "pdf/ui/thumbnail.h"
#include "third_party/ink/src/ink/geometry/partitioned_mesh.h"
#include "ui/base/cursor/cursor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"

static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");

namespace gfx {
class PointF;
}

namespace ink {
class Stroke;
}

namespace ui {
class Cursor;
}

namespace chrome_pdf {

class PdfInkModuleClient {
 public:
  // Key: ID to identify a shape.
  // Value: The Ink shape.
  using PageV2InkPathShapesMap =
      std::map<InkModeledShapeId, ink::PartitionedMesh>;

  // Key: 0-based page index.
  // Value: Map of shapes on the page.
  using DocumentV2InkPathShapesMap = std::map<int, PageV2InkPathShapesMap>;

  virtual ~PdfInkModuleClient() = default;

  // Notifies the client to clear the current text selection.
  virtual void ClearSelection() {}

  // Asks the client to discard the stroke identified by `id` on the page at
  // `page_index`.
  virtual void DiscardStroke(int page_index, InkStrokeId id) {}

  // Extends the current text selection to the nearest page and character to
  // `point`. `point` must be in device coordinates.
  virtual void ExtendSelectionByPoint(const gfx::PointF& point) {}

  // Returns the current cursor.
  virtual ui::Cursor GetCursor() = 0;

  // Gets the current page orientation.
  virtual PageOrientation GetOrientation() const = 0;

  // Gets the current scaled and rotated rectangle area of the page in CSS
  // screen coordinates for the 0-based page index.  Must be non-empty for any
  // non-negative page index returned from `VisiblePageIndexFromPoint()`.
  virtual gfx::Rect GetPageContentsRect(int page_index) = 0;

  // Gets the page size in points for `page_index`.  Must be non-empty for any
  // non-negative page index returned from `VisiblePageIndexFromPoint()`.
  virtual gfx::SizeF GetPageSizeInPoints(int page_index) = 0;

  // Returns all current text selection rects in device coordinates.
  virtual std::vector<gfx::Rect> GetSelectionRects() = 0;

  // Gets the thumbnail size for `page_index`. The size must be non-empty for
  // any valid page index.
  virtual gfx::Size GetThumbnailSize(int page_index) = 0;

  // Gets the offset within the rendering viewport to where the page images
  // will be drawn.  Since the offset is a location within the viewport, it
  // must always contain non-negative values.  Values are in scaled CSS
  // screen coordinates, where the amount of scaling matches that of
  // `GetZoom()`.  The page orientation does not apply to the viewport.
  virtual gfx::Vector2dF GetViewportOriginOffset() = 0;

  // Gets current zoom factor.
  virtual float GetZoom() const = 0;

  // Notifies the client to invalidate the `rect`.  Coordinates are
  // screen-based, based on the same viewport origin that was used to specify
  // the `blink::WebMouseEvent` positions during stroking.
  virtual void Invalidate(const gfx::Rect& rect) {}

  // Returns whether the page at `page_index` is visible or not.
  virtual bool IsPageVisible(int page_index) = 0;

  // Returns whether `point` is within a selectable text area or a link area.
  // `point` must be in device coordinates.
  virtual bool IsSelectableTextOrLinkArea(const gfx::PointF& point) = 0;

  // Asks the client to load Ink data from the PDF.
  virtual DocumentV2InkPathShapesMap LoadV2InkPathsFromPdf() = 0;

  // Notifies the client whether annotation mode is enabled or not.
  virtual void OnAnnotationModeToggled(bool enable) {}

  // Notifies the client that a text area was clicked at `point` `click_count`
  // times during Ink annotation mode. It is the client's responsibility to
  // handle text selection, copying behavior from Blink. Two click counts should
  // select the word at `point`, while three click counts should select the
  // entire line at `point`. `point` must be in device coordinates.
  virtual void OnTextOrLinkAreaClick(const gfx::PointF& point,
                                     int click_count) {}

  // Returns the 0-based page index for the given `point`. `point` must be on a
  // page, otherwise returns -1. `point` must be in device coordinates.
  virtual int PageIndexFromPoint(const gfx::PointF& point) = 0;

  // Asks the client to post `message`.
  virtual void PostMessage(base::Value::Dict message) {}

  // Asks the client to update the page thumbnail for `page_index`. Note that
  // this is the regular page thumbnail, and not the thumbnail with the Ink
  // strokes.
  virtual void RequestThumbnail(int page_index,
                                SendThumbnailCallback callback) {}

  // Notifies that a stroke has been added to the page at `page_index`.
  // Provides an `id` that identifies the `stroke` object.  The `id` can be
  // used later with `UpdateStrokeActive()`.
  virtual void StrokeAdded(int page_index,
                           InkStrokeId id,
                           const ink::Stroke& stroke) {}

  // Notifies the client that stroking has finished. `modified` indicates
  // whether strokes got added or erased.
  virtual void StrokeFinished(bool modified) {}

  // Notifies the client that a stroke has started drawing or erasing.
  virtual void StrokeStarted() {}

  // Asks the client to change the cursor to `cursor`.
  virtual void UpdateInkCursor(const ui::Cursor& cursor) {}

  // Notifies that an existing shape identified by `id` on the page at
  // `page_index` should update its active state.
  virtual void UpdateShapeActive(int page_index,
                                 InkModeledShapeId id,
                                 bool active) {}

  // Notifies that an existing stroke identified by `id` on the page at
  // `page_index` should update its active state.
  virtual void UpdateStrokeActive(int page_index, InkStrokeId id, bool active) {
  }

  // Same as `PageIndexFromPoint()`, but `point` must be on a visible page,
  // otherwise returns -1.
  virtual int VisiblePageIndexFromPoint(const gfx::PointF& point) = 0;
};

}  // namespace chrome_pdf

#endif  // PDF_PDF_INK_MODULE_CLIENT_H_