File: webcursor.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 (73 lines) | stat: -rw-r--r-- 2,184 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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_CURSORS_WEBCURSOR_H_
#define CONTENT_COMMON_CURSORS_WEBCURSOR_H_

#include "build/build_config.h"
#include "content/common/content_export.h"
#include "ui/base/cursor/cursor.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"

#if defined(USE_AURA)
#include <optional>
#endif

namespace content {

// NOTE(https://crbug.com/1149906): This class is deprecated and ui::Cursor
// should be used instead.
//
// This class encapsulates a cross-platform description of a cursor.  Platform
// specific methods are provided to translate the cross-platform cursor into a
// platform specific cursor.  It is also possible to serialize / de-serialize a
// WebCursor. This class is highly similar to ui::Cursor.
class CONTENT_EXPORT WebCursor {
 public:
  WebCursor();
  explicit WebCursor(const ui::Cursor& info);
  ~WebCursor();

  const ui::Cursor& cursor() const { return cursor_; }

  // Returns a native cursor representing the current WebCursor instance.
  gfx::NativeCursor GetNativeCursor();

#if defined(USE_AURA)
  // Updates |device_scale_factor_| and |rotation_| based on |window|'s
  // preferred scale (if any) and its display information.
  void UpdateDisplayInfoForWindow(aura::Window* window);

  bool has_custom_cursor_for_test() const { return !!custom_cursor_; }
#endif

 private:
  float GetCursorScaleFactor(SkBitmap* bitmap);

  // The basic cursor info.
  ui::Cursor cursor_;

#if defined(USE_AURA)
  // Only used for custom cursors.
  float device_scale_factor_ = 1.f;
  display::Display::Rotation rotation_ = display::Display::ROTATE_0;
#endif

#if BUILDFLAG(IS_CHROMEOS)
  // This matches ozone drm_util.cc's kDefaultCursorWidth/Height.
  static constexpr int kDefaultMaxSize = 64;
  gfx::Size maximum_cursor_size_ = {kDefaultMaxSize, kDefaultMaxSize};
#endif

#if defined(USE_AURA)
  std::optional<ui::Cursor> custom_cursor_;
#endif
};

}  // namespace content

#endif  // CONTENT_COMMON_CURSORS_WEBCURSOR_H_