File: overlay_agent_views.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (129 lines) | stat: -rw-r--r-- 4,581 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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_UI_DEVTOOLS_VIEWS_OVERLAY_AGENT_VIEWS_H_
#define COMPONENTS_UI_DEVTOOLS_VIEWS_OVERLAY_AGENT_VIEWS_H_

#include "base/gtest_prod_util.h"
#include "components/ui_devtools/overlay.h"
#include "components/ui_devtools/overlay_agent.h"
#include "components/ui_devtools/views/dom_agent_views.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/gfx/native_widget_types.h"

namespace gfx {
class RenderText;
}

namespace ui_devtools {

enum HighlightRectsConfiguration {
  NO_DRAW,
  R1_CONTAINS_R2,
  R1_HORIZONTAL_FULL_LEFT_R2,
  R1_TOP_FULL_LEFT_R2,
  R1_BOTTOM_FULL_LEFT_R2,
  R1_TOP_PARTIAL_LEFT_R2,
  R1_BOTTOM_PARTIAL_LEFT_R2,
  R1_INTERSECTS_R2
};

enum RectSide { TOP_SIDE, LEFT_SIDE, RIGHT_SIDE, BOTTOM_SIDE };

class OverlayAgentViews : public OverlayAgent,
                          public ui::EventHandler,
                          public ui::LayerDelegate {
 public:
  OverlayAgentViews(const OverlayAgentViews&) = delete;
  OverlayAgentViews& operator=(const OverlayAgentViews&) = delete;

  ~OverlayAgentViews() override;

  // Creates a platform-specific instance.
  static std::unique_ptr<OverlayAgentViews> Create(DOMAgent* dom_agent);

  int pinned_id() const { return pinned_id_; }
  void SetPinnedNodeId(int pinned_id);

  // Overlay::Backend:
  protocol::Response setInspectMode(
      const protocol::String& in_mode,
      std::unique_ptr<protocol::Overlay::HighlightConfig> in_highlightConfig)
      override;
  protocol::Response highlightNode(
      std::unique_ptr<protocol::Overlay::HighlightConfig> highlight_config,
      std::optional<int> node_id) override;
  protocol::Response hideHighlight() override;

  HighlightRectsConfiguration highlight_rect_config() const {
    return highlight_rect_config_;
  }

  // Return the id of the UI element located at |event|'s root location.
  // The function first searches for the targeted window, then the targeted
  // widget (if one exists), then the targeted view (if one exists). Return 0 if
  // no valid target is found.
  virtual int FindElementIdTargetedByPoint(ui::LocatedEvent* event) const = 0;

 protected:
  OverlayAgentViews(DOMAgent* dom_agent);

 private:
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest,
                           MouseEventsGenerateFEEventsInInspectMode);
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightRects);
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightNonexistentNode);
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWidget);
#if defined(USE_AURA)
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightWindow);
  FRIEND_TEST_ALL_PREFIXES(OverlayAgentTest, HighlightEmptyOrInvisibleWindow);
#endif

  // Start handling events intended for inspectable elements.
  virtual void InstallPreTargetHandler() = 0;
  // Stop handling events intended for inspectable elements.
  virtual void RemovePreTargetHandler() = 0;

  protocol::Response HighlightNode(int node_id, bool show_size = false);
  // Returns true when there is any visible element to highlight.
  bool UpdateHighlight(
      const std::pair<gfx::NativeWindow, gfx::Rect>& window_and_screen_bounds);

  // Shows the distances between the nodes identified by |pinned_id| and
  // |element_id| in the highlight overlay.
  void ShowDistancesInHighlightOverlay(int pinned_id, int element_id);

  // ui:EventHandler:
  void OnMouseEvent(ui::MouseEvent* event) override;
  void OnKeyEvent(ui::KeyEvent* event) override;

  // ui::LayerDelegate:
  void OnPaintLayer(const ui::PaintContext& context) override;
  void OnDeviceScaleFactorChanged(float old_device_scale_factor,
                                  float new_device_scale_factor) override {}

  ui::Layer* layer_for_highlighting() { return layer_for_highlighting_.get(); }

  std::unique_ptr<gfx::RenderText> render_text_;
  bool show_size_on_canvas_ = false;
  HighlightRectsConfiguration highlight_rect_config_;
  bool is_swap_ = false;

  // The layer used to paint highlights, and its offset from the screen origin.
  std::unique_ptr<ui::Layer> layer_for_highlighting_;
  gfx::Vector2d layer_for_highlighting_screen_offset_;

  // Hovered and pinned element bounds in screen coordinates; empty if none.
  gfx::Rect hovered_rect_;
  gfx::Rect pinned_rect_;

  int pinned_id_ = 0;
};

}  // namespace ui_devtools

#endif  // COMPONENTS_UI_DEVTOOLS_VIEWS_OVERLAY_AGENT_VIEWS_H_