File: tooltip_aura.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; 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,806; 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 (117 lines) | stat: -rw-r--r-- 3,610 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
// Copyright 2013 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_VIEWS_COREWM_TOOLTIP_AURA_H_
#define UI_VIEWS_COREWM_TOOLTIP_AURA_H_

#include <memory>

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "ui/views/corewm/tooltip.h"
#include "ui/views/corewm/tooltip_view_aura.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/wm/public/tooltip_observer.h"

namespace gfx {
class RenderText;
class Size;
}  // namespace gfx

namespace ui {
struct AXNodeData;
struct OwnedWindowAnchor;
}  // namespace ui

namespace views {

class Widget;

namespace corewm {
namespace test {
class TooltipAuraTestApi;
}

// Implementation of Tooltip that shows the tooltip using a Widget and Label.
class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver {
 public:
  static const char kWidgetName[];
  // TODO(crbug.com/40254494): get cursor offset from actual cursor size.
  static constexpr int kCursorOffsetX = 10;
  static constexpr int kCursorOffsetY = 15;

  using TooltipViewFactory =
      base::RepeatingCallback<std::unique_ptr<TooltipViewAura>(void)>;

  TooltipAura();

  explicit TooltipAura(const TooltipViewFactory& tooltip_view_factory);

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

  ~TooltipAura() override;

  void AddObserver(wm::TooltipObserver* observer) override;
  void RemoveObserver(wm::TooltipObserver* observer) override;
  void SetMaxWidth(int width) override;

  // Adjusts `anchor_point` to the bottom left of the cursor.
  static void AdjustToCursor(gfx::Rect* anchor_point);

 private:
  class TooltipWidget;

  friend class test::TooltipAuraTestApi;
  const gfx::RenderText* GetRenderTextForTest() const;
  void GetAccessibleNodeDataForTest(ui::AXNodeData* node_data);

  // Adjusts the bounds given by the arguments to fit inside the desktop
  // and returns the adjusted bounds, and also sets anchor information to
  // `anchor`.
  // `anchor_point` is an absolute position, not relative to the window.
  gfx::Rect GetTooltipBounds(const gfx::Size& tooltip_size,
                             const gfx::Point& anchor_point,
                             const TooltipTrigger trigger,
                             ui::OwnedWindowAnchor* anchor);

  // Sets |widget_| to a new instance of TooltipWidget. Additional information
  // that helps to position anchored windows in such backends as Wayland.
  void CreateTooltipWidget(const gfx::Rect& bounds,
                           const ui::OwnedWindowAnchor& anchor);

  // Destroys |widget_|.
  void DestroyWidget();

  // Tooltip:
  int GetMaxWidth(const gfx::Point& location) const override;
  void Update(aura::Window* window,
              const std::u16string& tooltip_text,
              const gfx::Point& position,
              const TooltipTrigger trigger) override;
  void Show() override;
  void Hide() override;
  bool IsVisible() override;

  // A callback to generate a `TooltipViewAura` instance.
  const TooltipViewFactory tooltip_view_factory_;

  // The widget containing the tooltip. May be NULL.
  std::unique_ptr<TooltipWidget> widget_;

  // The window we're showing the tooltip for. Never NULL and valid while
  // showing.
  raw_ptr<aura::Window> tooltip_window_ = nullptr;

  int max_width_;

  // Observes tooltip state change.
  base::ObserverList<wm::TooltipObserver> observers_;
};

}  // namespace corewm
}  // namespace views

#endif  // UI_VIEWS_COREWM_TOOLTIP_AURA_H_