• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Embedded Framework Authors. Portions copyright
2 // 2012 The Chromium Authors. All rights reserved. Use of this source code is
3 // governed by a BSD-style license that can be found in the LICENSE file.
4 
5 #include "libcef/browser/native/cursor_util.h"
6 
7 #include "libcef/browser/browser_host_base.h"
8 
9 #include "content/common/cursors/webcursor.h"
10 #include "ui/base/cursor/cursor_factory.h"
11 #include "ui/base/cursor/mojom/cursor_type.mojom.h"
12 
13 namespace cursor_util {
14 
OnCursorChange(CefBrowserHostBase * browser,const ui::Cursor & ui_cursor)15 bool OnCursorChange(CefBrowserHostBase* browser, const ui::Cursor& ui_cursor) {
16   auto client = browser->GetClient();
17   if (!client)
18     return false;
19   auto handler = client->GetDisplayHandler();
20   if (!handler)
21     return false;
22 
23   const cef_cursor_type_t cursor_type =
24       static_cast<cef_cursor_type_t>(ui_cursor.type());
25   CefCursorInfo custom_cursor_info;
26   if (ui_cursor.type() == ui::mojom::CursorType::kCustom) {
27     custom_cursor_info.hotspot.x = ui_cursor.custom_hotspot().x();
28     custom_cursor_info.hotspot.y = ui_cursor.custom_hotspot().y();
29     custom_cursor_info.image_scale_factor = ui_cursor.image_scale_factor();
30     custom_cursor_info.buffer = ui_cursor.custom_bitmap().getPixels();
31     custom_cursor_info.size.width = ui_cursor.custom_bitmap().width();
32     custom_cursor_info.size.height = ui_cursor.custom_bitmap().height();
33   }
34 
35   bool handled = false;
36 
37 #if defined(USE_AURA)
38   CefCursorHandle platform_cursor;
39   scoped_refptr<ui::PlatformCursor> image_cursor;
40 
41   if (ui_cursor.type() == ui::mojom::CursorType::kCustom) {
42     image_cursor = ui::CursorFactory::GetInstance()->CreateImageCursor(
43         ui::mojom::CursorType::kCustom, ui_cursor.custom_bitmap(),
44         ui_cursor.custom_hotspot());
45     platform_cursor = cursor_util::ToCursorHandle(image_cursor);
46   } else {
47     platform_cursor = cursor_util::GetPlatformCursor(ui_cursor.type());
48   }
49 
50   handled = handler->OnCursorChange(browser, platform_cursor, cursor_type,
51                                     custom_cursor_info);
52 #elif BUILDFLAG(IS_MAC)
53   // |web_cursor| owns the resulting |native_cursor|.
54   content::WebCursor web_cursor(ui_cursor);
55   CefCursorHandle native_cursor = web_cursor.GetNativeCursor();
56   handled = handler->OnCursorChange(browser, native_cursor, cursor_type,
57                                     custom_cursor_info);
58 #else
59   NOTIMPLEMENTED();
60 #endif
61 
62   return handled;
63 }
64 
65 }  // namespace cursor_util
66