File: touch_selection_magnifier_aura.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 (85 lines) | stat: -rw-r--r-- 3,097 bytes parent folder | download | duplicates (10)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_TOUCH_SELECTION_TOUCH_SELECTION_MAGNIFIER_AURA_H_
#define UI_TOUCH_SELECTION_TOUCH_SELECTION_MAGNIFIER_AURA_H_

#include <memory>

#include "base/scoped_observation.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_observer.h"
#include "ui/touch_selection/ui_touch_selection_export.h"

namespace gfx {
class Rect;
class Point;
}  // namespace gfx

namespace ui {
class Layer;

// A magnifier which shows the text caret or selection endpoint during a touch
// selection session.
class UI_TOUCH_SELECTION_EXPORT TouchSelectionMagnifierAura
    : public NativeThemeObserver {
 public:
  TouchSelectionMagnifierAura();

  TouchSelectionMagnifierAura(const TouchSelectionMagnifierAura&) = delete;
  TouchSelectionMagnifierAura& operator=(const TouchSelectionMagnifierAura&) =
      delete;

  ~TouchSelectionMagnifierAura() override;

  // Shows the magnifier at the focus bound. Roughly, this is a line segment
  // representing a caret position or selection endpoint and is generally
  // vertical or horizontal (depending on text orientation). E.g. for a caret in
  // horizontal text, `focus_start` is the top of the caret and `focus_end` is
  // the bottom of the caret. These are specified in coordinates of the
  // `parent` layer which the magnifier should be attached to.
  void ShowFocusBound(Layer* parent,
                      const gfx::Point& focus_start,
                      const gfx::Point& focus_end);

  // NativeThemeObserver:
  void OnNativeThemeUpdated(NativeTheme* observed_theme) override;

  // Returns the bounds of the zoomed contents in coordinates of the magnifier's
  // parent layer. This is the bounding box of the source pixels that will be
  // scaled and offset to fill the magnifier layer.
  gfx::Rect GetZoomedContentsBoundsForTesting() const;

  // Returns the bounds of the magnifier (i.e. where the zoomed content is drawn
  // to), ignoring border and style padding.
  gfx::Rect GetMagnifierBoundsForTesting() const;

  const Layer* GetMagnifierParentForTesting() const;

 private:
  class BorderRenderer;

  void CreateMagnifierLayer();

  // The magnifier layer is the parent of the zoom layer and border layer. The
  // layer bounds should be updated when selection updates occur.
  std::unique_ptr<Layer> magnifier_layer_;

  // Draws the zoomed contents, i.e. the background with a zoom and offset
  // filter applied.
  std::unique_ptr<Layer> zoom_layer_;

  // Draws the magnifier border and shadows. `border_layer_` must be ordered
  // after `border_renderer_` so that it is destroyed before `border_renderer_`.
  // Otherwise `border_layer_` will have a pointer to a deleted delegate.
  std::unique_ptr<BorderRenderer> border_renderer_;
  std::unique_ptr<Layer> border_layer_;

  base::ScopedObservation<NativeTheme, NativeThemeObserver> theme_observation_{
      this};
};

}  // namespace ui

#endif  // UI_TOUCH_SELECTION_TOUCH_SELECTION_MAGNIFIER_AURA_H_