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) { ...@@ -34,10 +34,11 @@ WebCursor& WebCursor::operator=(const WebCursor& other) {
bool WebCursor::SetInfo(const CursorInfo& info) { bool WebCursor::SetInfo(const CursorInfo& info) {
static constexpr int kMaxSize = 1024; static constexpr int kMaxSize = 1024;
if (info.image_scale_factor < 0.01f || info.image_scale_factor > 100.f || if (info.image_scale_factor < 0.01f || info.image_scale_factor > 100.f ||
info.custom_image.width() > kMaxSize || (info.type == ui::CursorType::kCustom &&
(info.custom_image.width() > kMaxSize ||
info.custom_image.height() > kMaxSize || info.custom_image.height() > kMaxSize ||
info.custom_image.width() / info.image_scale_factor > kMaxSize || info.custom_image.width() / info.image_scale_factor > kMaxSize ||
info.custom_image.height() / info.image_scale_factor > kMaxSize) { info.custom_image.height() / info.image_scale_factor > kMaxSize))) {
return false; return false;
} }
......
...@@ -11,23 +11,28 @@ namespace content { ...@@ -11,23 +11,28 @@ namespace content {
CursorInfo::CursorInfo(ui::CursorType cursor) : type(cursor) {} CursorInfo::CursorInfo(ui::CursorType cursor) : type(cursor) {}
CursorInfo::CursorInfo(const blink::WebCursorInfo& info) CursorInfo::CursorInfo(const blink::WebCursorInfo& info)
: type(info.type), : type(info.type), image_scale_factor(info.image_scale_factor) {
custom_image(info.custom_image), if (type == ui::CursorType::kCustom) {
hotspot(info.hot_spot), custom_image = info.custom_image;
image_scale_factor(info.image_scale_factor) {} hotspot = info.hot_spot;
}
}
bool CursorInfo::operator==(const CursorInfo& other) const { bool CursorInfo::operator==(const CursorInfo& other) const {
return type == other.type && hotspot == other.hotspot && return type == other.type && image_scale_factor == other.image_scale_factor &&
image_scale_factor == other.image_scale_factor && (type != ui::CursorType::kCustom ||
gfx::BitmapsAreEqual(custom_image, other.custom_image); (hotspot == other.hotspot &&
gfx::BitmapsAreEqual(custom_image, other.custom_image)));
} }
blink::WebCursorInfo CursorInfo::GetWebCursorInfo() const { blink::WebCursorInfo CursorInfo::GetWebCursorInfo() const {
blink::WebCursorInfo info; blink::WebCursorInfo info;
info.type = type; info.type = type;
info.image_scale_factor = image_scale_factor;
if (type == ui::CursorType::kCustom) {
info.hot_spot = hotspot; info.hot_spot = hotspot;
info.custom_image = custom_image; info.custom_image = custom_image;
info.image_scale_factor = image_scale_factor; }
return info; return info;
} }
......
...@@ -69,6 +69,7 @@ include_rules = [ ...@@ -69,6 +69,7 @@ include_rules = [
"+third_party/ced/src/compact_enc_det/compact_enc_det.h", "+third_party/ced/src/compact_enc_det/compact_enc_det.h",
"+third_party/khronos", "+third_party/khronos",
"+third_party/skia", "+third_party/skia",
"+ui/base/cursor/types/cursor_types.h",
"+ui/base/resource/scale_factor.h", "+ui/base/resource/scale_factor.h",
"+ui/gfx", "+ui/gfx",
"+url", "+url",
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
*/ */
#include "third_party/blink/renderer/platform/cursor.h" #include "third_party/blink/renderer/platform/cursor.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h" #include "third_party/blink/renderer/platform/wtf/assertions.h"
#include "ui/base/cursor/types/cursor_types.h"
namespace blink { namespace blink {
...@@ -76,13 +78,17 @@ Cursor::Cursor(Image* image, ...@@ -76,13 +78,17 @@ Cursor::Cursor(Image* image,
Cursor::Cursor(ui::CursorType type) : type_(type), image_scale_factor_(1) {} 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) { Cursor& Cursor::operator=(const Cursor& other) {
type_ = other.type_; type_ = other.type_;
image_scale_factor_ = other.image_scale_factor_;
if (type_ == ui::CursorType::kCustom) {
image_ = other.image_; image_ = other.image_;
hot_spot_ = other.hot_spot_; hot_spot_ = other.hot_spot_;
image_scale_factor_ = other.image_scale_factor_; }
return *this; return *this;
} }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "third_party/blink/public/platform/web_cursor_info.h" #include "third_party/blink/public/platform/web_cursor_info.h"
#include "third_party/blink/renderer/platform/cursor.h" #include "third_party/blink/renderer/platform/cursor.h"
#include "ui/base/cursor/types/cursor_types.h"
namespace blink { namespace blink {
...@@ -41,9 +42,11 @@ static SkBitmap GetCursorBitmap(const Cursor& cursor) { ...@@ -41,9 +42,11 @@ static SkBitmap GetCursorBitmap(const Cursor& cursor) {
} }
WebCursorInfo::WebCursorInfo(const Cursor& cursor) WebCursorInfo::WebCursorInfo(const Cursor& cursor)
: type(static_cast<ui::CursorType>(cursor.GetType())), : type(cursor.GetType()), image_scale_factor(cursor.ImageScaleFactor()) {
hot_spot(cursor.HotSpot()), if (type == ui::CursorType::kCustom) {
image_scale_factor(cursor.ImageScaleFactor()), hot_spot = cursor.HotSpot();
custom_image(GetCursorBitmap(cursor)) {} custom_image = GetCursorBitmap(cursor);
}
}
} // namespace blink } // namespace blink
...@@ -16,11 +16,12 @@ Cursor::Cursor(CursorType type) : native_type_(type) {} ...@@ -16,11 +16,12 @@ Cursor::Cursor(CursorType type) : native_type_(type) {}
Cursor::Cursor(const Cursor& cursor) Cursor::Cursor(const Cursor& cursor)
: native_type_(cursor.native_type_), : native_type_(cursor.native_type_),
platform_cursor_(cursor.platform_cursor_), platform_cursor_(cursor.platform_cursor_),
device_scale_factor_(cursor.device_scale_factor_), device_scale_factor_(cursor.device_scale_factor_) {
custom_hotspot_(cursor.custom_hotspot_), if (native_type_ == CursorType::kCustom) {
custom_bitmap_(cursor.custom_bitmap_) { custom_hotspot_ = cursor.custom_hotspot_;
if (native_type_ == CursorType::kCustom) custom_bitmap_ = cursor.custom_bitmap_;
RefCustomCursor(); RefCustomCursor();
}
} }
Cursor::~Cursor() { Cursor::~Cursor() {
...@@ -69,9 +70,9 @@ bool Cursor::operator==(const Cursor& cursor) const { ...@@ -69,9 +70,9 @@ bool Cursor::operator==(const Cursor& cursor) const {
return native_type_ == cursor.native_type_ && return native_type_ == cursor.native_type_ &&
platform_cursor_ == cursor.platform_cursor_ && platform_cursor_ == cursor.platform_cursor_ &&
device_scale_factor_ == cursor.device_scale_factor_ && device_scale_factor_ == cursor.device_scale_factor_ &&
custom_hotspot_ == cursor.custom_hotspot_ &&
(native_type_ != CursorType::kCustom || (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) { void Cursor::operator=(const Cursor& cursor) {
...@@ -81,11 +82,12 @@ void Cursor::operator=(const Cursor& cursor) { ...@@ -81,11 +82,12 @@ void Cursor::operator=(const Cursor& cursor) {
UnrefCustomCursor(); UnrefCustomCursor();
native_type_ = cursor.native_type_; native_type_ = cursor.native_type_;
platform_cursor_ = cursor.platform_cursor_; platform_cursor_ = cursor.platform_cursor_;
if (native_type_ == CursorType::kCustom) if (native_type_ == CursorType::kCustom) {
RefCustomCursor(); RefCustomCursor();
device_scale_factor_ = cursor.device_scale_factor_;
custom_hotspot_ = cursor.custom_hotspot_; custom_hotspot_ = cursor.custom_hotspot_;
custom_bitmap_ = cursor.custom_bitmap_; custom_bitmap_ = cursor.custom_bitmap_;
}
device_scale_factor_ = cursor.device_scale_factor_;
} }
} // namespace ui } // 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