2015-11-17 19:20:13 +01:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 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.
|
|
|
|
|
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
#include <X11/Xlib.h>
|
2017-05-17 11:29:28 +02:00
|
|
|
#include <X11/cursorfont.h>
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
#include "libcef/browser/native/window_x11.h"
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
|
|
|
#include "ui/base/x/x11_cursor_loader.h"
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "ui/base/x/x11_util.h"
|
|
|
|
#include "ui/gfx/x/x11_types.h"
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Based on ui/base/cursor/cursor_loader_x11.cc.
|
|
|
|
|
2020-03-30 22:13:42 +02:00
|
|
|
int 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 XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCross:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_crosshair;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kHand:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_hand2;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kIBeam:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_xterm;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWait:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_watch;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kHelp:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_question_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_right_side;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_top_side;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_top_right_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_top_left_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_bottom_side;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_bottom_right_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_bottom_left_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_side;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthSouthResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_v_double_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_h_double_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastSouthWestResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestSouthEastResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kColumnResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_h_double_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kRowResize:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_v_double_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_fleur;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_right_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_up_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_top_right_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNorthWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_top_left_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_down_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthEastPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_bottom_right_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kSouthWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_bottom_left_corner;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kWestPanning:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_sb_left_arrow;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMove:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_fleur;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kVerticalText:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCell:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kContextMenu:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kAlias:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kProgress:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNoDrop:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCopy:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNotAllowed:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kZoomIn:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kZoomOut:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kGrab:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kGrabbing:
|
2015-11-17 19:20:13 +01:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanningVertical:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kMiddlePanningHorizontal:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndNone:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndMove:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndCopy:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kDndLink:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kNull:
|
2019-09-04 17:13:32 +02:00
|
|
|
return XC_left_ptr;
|
2020-03-30 22:13:42 +02:00
|
|
|
case ui::mojom::CursorType::kCustom:
|
|
|
|
case ui::mojom::CursorType::kNone:
|
2015-11-17 19:20:13 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
NOTREACHED();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
// The following XCursorCache code was deleted from ui/base/x/x11_util.cc in
|
|
|
|
// https://crbug.com/665574#c2
|
|
|
|
|
|
|
|
// A process wide singleton that manages the usage of X cursors.
|
|
|
|
class XCursorCache {
|
|
|
|
public:
|
|
|
|
XCursorCache() {}
|
2017-05-17 11:29:28 +02:00
|
|
|
~XCursorCache() { Clear(); }
|
2017-01-23 18:36:54 +01:00
|
|
|
|
|
|
|
::Cursor GetCursor(int cursor_shape) {
|
|
|
|
// Lookup cursor by attempting to insert a null value, which avoids
|
|
|
|
// a second pass through the map after a cache miss.
|
2017-05-17 11:29:28 +02:00
|
|
|
std::pair<std::map<int, ::Cursor>::iterator, bool> it =
|
|
|
|
cache_.insert(std::make_pair(cursor_shape, 0));
|
2017-01-23 18:36:54 +01:00
|
|
|
if (it.second) {
|
|
|
|
XDisplay* display = gfx::GetXDisplay();
|
|
|
|
it.first->second = XCreateFontCursor(display, cursor_shape);
|
|
|
|
}
|
|
|
|
return it.first->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
XDisplay* display = gfx::GetXDisplay();
|
2017-05-17 11:29:28 +02:00
|
|
|
for (std::map<int, ::Cursor>::iterator it = cache_.begin();
|
|
|
|
it != cache_.end(); ++it) {
|
2017-01-23 18:36:54 +01:00
|
|
|
XFreeCursor(display, it->second);
|
|
|
|
}
|
|
|
|
cache_.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Maps X11 font cursor shapes to Cursor IDs.
|
|
|
|
std::map<int, ::Cursor> cache_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(XCursorCache);
|
|
|
|
};
|
|
|
|
|
|
|
|
XCursorCache* cursor_cache = nullptr;
|
|
|
|
|
|
|
|
// Returns an X11 Cursor, sharable across the process.
|
|
|
|
// |cursor_shape| is an X font cursor shape, see XCreateFontCursor().
|
|
|
|
::Cursor GetXCursor(int cursor_shape) {
|
|
|
|
if (!cursor_cache)
|
|
|
|
cursor_cache = new XCursorCache;
|
|
|
|
return cursor_cache->GetCursor(cursor_shape);
|
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
// Based on ui/base/x/x11_cursor_factory.cc.
|
|
|
|
scoped_refptr<ui::X11Cursor> CreateInvisibleCursor(
|
|
|
|
ui::XCursorLoader* cursor_loader) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(1, 1);
|
|
|
|
return cursor_loader->CreateCursor(bitmap, gfx::Point(0, 0));
|
|
|
|
}
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
} // namespace
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2020-07-08 19:23:29 +02:00
|
|
|
CefCursorHandle CefRenderWidgetHostViewOSR::GetPlatformCursor(
|
2020-03-30 22:13:42 +02:00
|
|
|
ui::mojom::CursorType type) {
|
2019-04-23 19:00:14 +02:00
|
|
|
#if defined(USE_X11)
|
2020-03-30 22:13:42 +02:00
|
|
|
if (type == ui::mojom::CursorType::kNone) {
|
2015-11-17 19:20:13 +01:00
|
|
|
if (!invisible_cursor_) {
|
2020-08-29 00:39:23 +02:00
|
|
|
cursor_loader_ =
|
|
|
|
std::make_unique<ui::XCursorLoader>(x11::Connection::Get());
|
|
|
|
invisible_cursor_ = CreateInvisibleCursor(cursor_loader_.get());
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2020-08-29 00:39:23 +02:00
|
|
|
return static_cast<::Cursor>(invisible_cursor_->xcursor());
|
2015-11-17 19:20:13 +01:00
|
|
|
} else {
|
2017-01-23 18:36:54 +01:00
|
|
|
return GetXCursor(ToCursorID(type));
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|
2019-04-23 19:00:14 +02:00
|
|
|
#endif // defined(USE_X11)
|
|
|
|
return 0;
|
2015-11-17 19:20:13 +01:00
|
|
|
}
|