File: annotator_controller.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 (123 lines) | stat: -rw-r--r-- 4,785 bytes parent folder | download | duplicates (6)
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
// 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 ASH_ANNOTATOR_ANNOTATOR_CONTROLLER_H_
#define ASH_ANNOTATOR_ANNOTATOR_CONTROLLER_H_

#include <memory>
#include <optional>

#include "ash/annotator/annotator_metrics.h"
#include "ash/ash_export.h"
#include "ash/public/cpp/annotator/annotator_controller_base.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "third_party/skia/include/core/SkColor.h"

namespace aura {
class Window;
}  // namespace aura

namespace gfx {
class Rect;
}  // namespace gfx

namespace ash {

struct AnnotatorTool;
class AnnotatorClient;
class AnnotationsOverlayView;
class AnnotationsOverlayController;
class AnnotationSourceWatcher;

// The controller in charge of annotator UI.
class ASH_EXPORT AnnotatorController : public AnnotatorControllerBase {
 public:
  AnnotatorController();
  AnnotatorController(const AnnotatorController&) = delete;
  AnnotatorController& operator=(const AnnotatorController&) = delete;
  ~AnnotatorController() override;

  bool is_annotator_enabled() const { return annotator_enabled_; }
  AnnotationSourceWatcher* annotation_source_watcher() {
    return annotation_source_watcher_.get();
  }

  // Sets the annotator tool.
  virtual void SetAnnotatorTool(const AnnotatorTool& tool);
  // Resets annotator tools and clears the canvas.
  void ResetTools();
  // Shows annotation tray for `new_root`.
  void RegisterView(aura::Window* new_root);
  // Hides annotation tray for `current_root` if it was previously registered
  // with the controller.
  void UnregisterView(aura::Window* current_root);
  // Updates `current_root_` to be the given `new_root`. Updates annotation
  // tray's enabled state.
  void UpdateRootView(aura::Window* new_root);
  // Invoked when marker button is pressed.
  void EnableAnnotatorTool();
  // Resets the canvas and disables the annotator functionality.
  void DisableAnnotator();
  // Creates `annotations_overlay_controller_` for the `window`. This is
  // necessary, as it adds a view for annotating on top of the `window` and
  // loads the Ink library in the view. After the call, annotating is still
  // disabled, until the EnableAnnotatorTool() method is called.
  // TODO(b/342104047): Once the markup pod is implemented, make this method
  // private, called from EnableAnnotatorTool(). Add handling for multiple
  // displays.
  void CreateAnnotationOverlayForWindow(
      aura::Window* window,
      std::optional<gfx::Rect> partial_region_bounds);

  // AnnotatorControllerBase:
  void SetToolClient(AnnotatorClient* client) override;
  bool GetAnnotatorAvailability() const override;
  void OnCanvasInitialized(bool success) override;
  void ToggleAnnotationTray() override;
  void OnUndoRedoAvailabilityChanged(bool undo_available,
                                     bool redo_available) override;

  // Returns a new instance of the concrete view that will be used as the
  // content view of the annotations overlay widget.
  std::unique_ptr<AnnotationsOverlayView> CreateAnnotationsOverlayView() const;

  // Updates the accessible name of the |annotation_tray_| in the accessibility
  // cache.
  void UpdateAnnotationTrayAccessibleName(bool is_annotator_enabled);

  void set_canvas_initialized_callback_for_test(base::OnceClosure callback) {
    on_canvas_initialized_callback_for_test_ = std::move(callback);
  }

 private:
  friend class CaptureModeTestApi;

  // Updates the tray based on annotator availability.
  void UpdateTrayEnabledState();
  // Toggles annotation overlay widget on or off. When on, the annotations
  // overlay widget's window will be shown and can consume all the events
  // targeting the underlying window. Otherwise, it's hidden and cannot accept
  // any events.
  void ToggleAnnotatorCanvas();
  raw_ptr<AnnotatorClient> client_ = nullptr;
  // True if the canvas is initialized successfully, false if it failed to
  // initialize. An absent value indicates that the initialization has not
  // completed.
  std::optional<bool> canvas_initialized_state_;
  bool annotator_enabled_ = false;
  // The current root window for showing annotations.
  raw_ptr<aura::Window> current_root_ = nullptr;
  // If set, will be called when the canvas is initialized.
  base::OnceClosure on_canvas_initialized_callback_for_test_;
  // Controls and owns the overlay widget, which is used to host annotations.
  std::unique_ptr<AnnotationsOverlayController> annotations_overlay_controller_;
  std::unique_ptr<AnnotationSourceWatcher> annotation_source_watcher_;
};

}  // namespace ash

#endif  // ASH_ANNOTATOR_ANNOTATOR_CONTROLLER_H_