2020-10-28 17:30:54 +01:00
|
|
|
// Copyright 2020 The Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2012 The Chromium Authors. All rights reserved. Use of this source code is
|
|
|
|
// governed by a BSD-style license that can be found in the LICENSE file.
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
#include "libcef/browser/native/cursor_util.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
#include "ui/base/cursor/mojom/cursor_type.mojom.h"
|
2021-12-16 23:35:54 +01:00
|
|
|
#include "ui/base/win/win_cursor.h"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "ui/resources/grit/ui_unscaled_resources.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
namespace cursor_util {
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
namespace {
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// From content/common/cursors/webcursor_win.cc.
|
2020-03-30 22:13:42 +02:00
|
|
|
LPCWSTR ToCursorID(ui::mojom::CursorType type) {
|
2015-11-17 19:20:13 +01:00
|
|
|
switch (type) {
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kPointer:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_ARROW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCross:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_CROSS;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kHand:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_HAND;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kIBeam:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_IBEAM;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWait:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_WAIT;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kHelp:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_HELP;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZEWE;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENS;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENESW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENWSE;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENS;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENWSE;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENESW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZEWE;
|
2021-04-21 00:52:34 +02:00
|
|
|
case ui::mojom::CursorType::kNorthSouthNoResize:
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthSouthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENS;
|
2021-04-21 00:52:34 +02:00
|
|
|
case ui::mojom::CursorType::kEastWestNoResize:
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZEWE;
|
2021-04-21 00:52:34 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastSouthWestNoResize:
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastSouthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENESW;
|
2021-04-21 00:52:34 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestSouthEastNoResize:
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestSouthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZENWSE;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kColumnResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_COLRESIZE);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kRowResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_ROWRESIZE);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_MIDDLE);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_EAST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_NORTH);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_NORTH_EAST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_NORTH_WEST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_SOUTH);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_SOUTH_EAST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_SOUTH_WEST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_WEST);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMove:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_SIZEALL;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kVerticalText:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_VERTICALTEXT);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCell:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_CELL);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kAlias:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_ALIAS);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kProgress:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_APPSTARTING;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNoDrop:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_NO;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCopy:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_COPYCUR);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNotAllowed:
|
2015-11-17 19:20:13 +01:00
|
|
|
return IDC_NO;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kZoomIn:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_ZOOMIN);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kZoomOut:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_ZOOMOUT);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kGrab:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_HAND_GRAB);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kGrabbing:
|
2015-11-17 19:20:13 +01:00
|
|
|
return MAKEINTRESOURCE(IDC_HAND_GRABBING);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNull:
|
2019-09-04 17:13:32 +02:00
|
|
|
return IDC_NO;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanningVertical:
|
2019-09-04 17:13:32 +02:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_MIDDLE_VERTICAL);
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanningHorizontal:
|
2019-09-04 17:13:32 +02:00
|
|
|
return MAKEINTRESOURCE(IDC_PAN_MIDDLE_HORIZONTAL);
|
|
|
|
// TODO(cef): Find better cursors for these things
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndNone:
|
2019-09-04 17:13:32 +02:00
|
|
|
return IDC_ARROW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndMove:
|
2019-09-04 17:13:32 +02:00
|
|
|
return IDC_ARROW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndCopy:
|
2019-09-04 17:13:32 +02:00
|
|
|
return IDC_ARROW;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndLink:
|
2019-09-04 17:13:32 +02:00
|
|
|
return IDC_ARROW;
|
2020-06-09 19:48:00 +02:00
|
|
|
case ui::mojom::CursorType::kContextMenu:
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCustom:
|
2020-06-09 19:48:00 +02:00
|
|
|
case ui::mojom::CursorType::kNone:
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return IDC_ARROW;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
|
|
|
NOTREACHED();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSystemCursorID(LPCWSTR cursor_id) {
|
|
|
|
return cursor_id >= IDC_ARROW; // See WinUser.h
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_handle_t GetPlatformCursor(ui::mojom::CursorType type) {
|
2020-06-09 19:48:00 +02:00
|
|
|
// Using a dark 1x1 bit bmp kNone cursor may still cause DWM to do composition
|
|
|
|
// work unnecessarily. Better to totally remove it from the screen.
|
|
|
|
// crbug.com/1069698
|
|
|
|
if (type == ui::mojom::CursorType::kNone) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
HMODULE module_handle = NULL;
|
|
|
|
const wchar_t* cursor_id = ToCursorID(type);
|
|
|
|
if (!IsSystemCursorID(cursor_id)) {
|
2020-06-28 23:05:36 +02:00
|
|
|
module_handle =
|
|
|
|
::GetModuleHandle(CefAppManager::Get()->GetResourceDllName());
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!module_handle)
|
|
|
|
module_handle = ::GetModuleHandle(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return LoadCursor(module_handle, cursor_id);
|
|
|
|
}
|
2020-10-08 21:54:42 +02:00
|
|
|
|
2021-06-04 03:34:56 +02:00
|
|
|
cef_cursor_handle_t ToCursorHandle(scoped_refptr<ui::PlatformCursor> cursor) {
|
|
|
|
return ui::WinCursor::FromPlatformCursor(cursor)->hcursor();
|
2020-10-08 21:54:42 +02:00
|
|
|
}
|
2020-10-28 17:30:54 +01:00
|
|
|
|
|
|
|
} // namespace cursor_util
|