Commit 1d477aff authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Ignore custom bitmap and hotspot when possible

The different Cursor and CursorInfo objects may hold a custom image and
hotspot when their type is ui::CursorType::kCustom. This CL makes
changes in several places to ignore those values for non-custom cursors.

Bug: 1040499
Change-Id: I504ef36f45bd771c80a2f8b81b828e16eeca0074
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035412Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#737976}
parent 6345547b
......@@ -34,10 +34,11 @@ WebCursor& WebCursor::operator=(const WebCursor& other) {
bool WebCursor::SetInfo(const CursorInfo& info) {
static constexpr int kMaxSize = 1024;
if (info.image_scale_factor < 0.01f || info.image_scale_factor > 100.f ||
info.custom_image.width() > kMaxSize ||
info.custom_image.height() > kMaxSize ||
info.custom_image.width() / info.image_scale_factor > kMaxSize ||
info.custom_image.height() / info.image_scale_factor > kMaxSize) {
(info.type == ui::CursorType::kCustom &&
(info.custom_image.width() > kMaxSize ||
info.custom_image.height() > kMaxSize ||
info.custom_image.width() / info.image_scale_factor > kMaxSize ||
info.custom_image.height() / info.image_scale_factor > kMaxSize))) {
return false;
}
......
......@@ -11,23 +11,28 @@ namespace content {
CursorInfo::CursorInfo(ui::CursorType cursor) : type(cursor) {}
CursorInfo::CursorInfo(const blink::WebCursorInfo& info)
: type(info.type),
custom_image(info.custom_image),
hotspot(info.hot_spot),
image_scale_factor(info.image_scale_factor) {}
: type(info.type), image_scale_factor(info.image_scale_factor) {
if (type == ui::CursorType::kCustom) {
custom_image = info.custom_image;
hotspot = info.hot_spot;
}
}
bool CursorInfo::operator==(const CursorInfo& other) const {
return type == other.type && hotspot == other.hotspot &&
image_scale_factor == other.image_scale_factor &&
gfx::BitmapsAreEqual(custom_image, other.custom_image);
return type == other.type && image_scale_factor == other.image_scale_factor &&
(type != ui::CursorType::kCustom ||
(hotspot == other.hotspot &&
gfx::BitmapsAreEqual(custom_image, other.custom_image)));
}
blink::WebCursorInfo CursorInfo::GetWebCursorInfo() const {
blink::WebCursorInfo info;
info.type = type;
info.hot_spot = hotspot;
info.custom_image = custom_image;
info.image_scale_factor = image_scale_factor;
if (type == ui::CursorType::kCustom) {
info.hot_spot = hotspot;
info.custom_image = custom_image;
}
return info;
}
......
......@@ -69,6 +69,7 @@ include_rules = [
"+third_party/ced/src/compact_enc_det/compact_enc_det.h",
"+third_party/khronos",
"+third_party/skia",
"+ui/base/cursor/types/cursor_types.h",
"+ui/base/resource/scale_factor.h",
"+ui/gfx",
"+url",
......
......@@ -24,7 +24,9 @@
*/
#include "third_party/blink/renderer/platform/cursor.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "ui/base/cursor/types/cursor_types.h"
namespace blink {
......@@ -76,13 +78,17 @@ Cursor::Cursor(Image* image,
Cursor::Cursor(ui::CursorType type) : type_(type), image_scale_factor_(1) {}
Cursor::Cursor(const Cursor& other) = default;
Cursor::Cursor(const Cursor& other) {
*this = other;
}
Cursor& Cursor::operator=(const Cursor& other) {
type_ = other.type_;
image_ = other.image_;
hot_spot_ = other.hot_spot_;
image_scale_factor_ = other.image_scale_factor_;
if (type_ == ui::CursorType::kCustom) {
image_ = other.image_;
hot_spot_ = other.hot_spot_;
}
return *this;
}
......
......@@ -31,6 +31,7 @@
#include "third_party/blink/public/platform/web_cursor_info.h"
#include "third_party/blink/renderer/platform/cursor.h"
#include "ui/base/cursor/types/cursor_types.h"
namespace blink {
......@@ -41,9 +42,11 @@ static SkBitmap GetCursorBitmap(const Cursor& cursor) {
}
WebCursorInfo::WebCursorInfo(const Cursor& cursor)
: type(static_cast<ui::CursorType>(cursor.GetType())),
hot_spot(cursor.HotSpot()),
image_scale_factor(cursor.ImageScaleFactor()),
custom_image(GetCursorBitmap(cursor)) {}
: type(cursor.GetType()), image_scale_factor(cursor.ImageScaleFactor()) {
if (type == ui::CursorType::kCustom) {
hot_spot = cursor.HotSpot();
custom_image = GetCursorBitmap(cursor);
}
}
} // namespace blink
......@@ -16,11 +16,12 @@ Cursor::Cursor(CursorType type) : native_type_(type) {}
Cursor::Cursor(const Cursor& cursor)
: native_type_(cursor.native_type_),
platform_cursor_(cursor.platform_cursor_),
device_scale_factor_(cursor.device_scale_factor_),
custom_hotspot_(cursor.custom_hotspot_),
custom_bitmap_(cursor.custom_bitmap_) {
if (native_type_ == CursorType::kCustom)
device_scale_factor_(cursor.device_scale_factor_) {
if (native_type_ == CursorType::kCustom) {
custom_hotspot_ = cursor.custom_hotspot_;
custom_bitmap_ = cursor.custom_bitmap_;
RefCustomCursor();
}
}
Cursor::~Cursor() {
......@@ -69,9 +70,9 @@ bool Cursor::operator==(const Cursor& cursor) const {
return native_type_ == cursor.native_type_ &&
platform_cursor_ == cursor.platform_cursor_ &&
device_scale_factor_ == cursor.device_scale_factor_ &&
custom_hotspot_ == cursor.custom_hotspot_ &&
(native_type_ != CursorType::kCustom ||
gfx::BitmapsAreEqual(custom_bitmap_, cursor.custom_bitmap_));
(custom_hotspot_ == cursor.custom_hotspot_ &&
gfx::BitmapsAreEqual(custom_bitmap_, cursor.custom_bitmap_)));
}
void Cursor::operator=(const Cursor& cursor) {
......@@ -81,11 +82,12 @@ void Cursor::operator=(const Cursor& cursor) {
UnrefCustomCursor();
native_type_ = cursor.native_type_;
platform_cursor_ = cursor.platform_cursor_;
if (native_type_ == CursorType::kCustom)
if (native_type_ == CursorType::kCustom) {
RefCustomCursor();
custom_hotspot_ = cursor.custom_hotspot_;
custom_bitmap_ = cursor.custom_bitmap_;
}
device_scale_factor_ = cursor.device_scale_factor_;
custom_hotspot_ = cursor.custom_hotspot_;
custom_bitmap_ = cursor.custom_bitmap_;
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment