[PDF Ink Signatures] Refactor PdfInkModuleClient::UpdateInkCursorImage()
Refactor PdfInkModuleClient::UpdateInkCursorImage() by changing the parameter from an SkBitmap to a ui::Cursor. Rename accordingly. This allows PdfInkModule to set the cursor to pre-defined types, rather than only custom cursors. This CL should not cause any visible change in behavior. This change is needed to use existing cursors in https://crrev.com/c/6269750. Bug: 342445982 Change-Id: If349cd5f428d966a9be108f7556569a5ff90e554 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6310886 Commit-Queue: Andy Phan <andyphan@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1426666}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
269a59e58f
commit
cb08ca05cc
@@ -51,6 +51,7 @@
|
|||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
#include "third_party/skia/include/core/SkCanvas.h"
|
#include "third_party/skia/include/core/SkCanvas.h"
|
||||||
#include "third_party/skia/include/core/SkColor.h"
|
#include "third_party/skia/include/core/SkColor.h"
|
||||||
|
#include "ui/base/cursor/cursor.h"
|
||||||
#include "ui/gfx/geometry/point_f.h"
|
#include "ui/gfx/geometry/point_f.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
#include "ui/gfx/geometry/rect_f.h"
|
#include "ui/gfx/geometry/rect_f.h"
|
||||||
@@ -1348,9 +1349,12 @@ void PdfInkModule::MaybeSetCursor() {
|
|||||||
brush_size = kEraserSize;
|
brush_size = kEraserSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
client_->UpdateInkCursorImage(GenerateToolCursor(
|
SkBitmap bitmap = GenerateToolCursor(
|
||||||
color,
|
color,
|
||||||
CursorDiameterFromBrushSizeAndZoom(brush_size, client_->GetZoom())));
|
CursorDiameterFromBrushSizeAndZoom(brush_size, client_->GetZoom()));
|
||||||
|
gfx::Point hotspot(bitmap.width() / 2, bitmap.height() / 2);
|
||||||
|
client_->UpdateInkCursor(
|
||||||
|
ui::Cursor::NewCustom(std::move(bitmap), std::move(hotspot)));
|
||||||
}
|
}
|
||||||
|
|
||||||
PdfInkModule::DrawingStrokeState::DrawingStrokeState() = default;
|
PdfInkModule::DrawingStrokeState::DrawingStrokeState() = default;
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
#include "pdf/pdf_ink_ids.h"
|
#include "pdf/pdf_ink_ids.h"
|
||||||
#include "pdf/ui/thumbnail.h"
|
#include "pdf/ui/thumbnail.h"
|
||||||
#include "third_party/ink/src/ink/geometry/partitioned_mesh.h"
|
#include "third_party/ink/src/ink/geometry/partitioned_mesh.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
#include "ui/gfx/geometry/vector2d.h"
|
#include "ui/gfx/geometry/vector2d.h"
|
||||||
|
|
||||||
@@ -26,6 +25,10 @@ namespace ink {
|
|||||||
class Stroke;
|
class Stroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
class Cursor;
|
||||||
|
}
|
||||||
|
|
||||||
namespace chrome_pdf {
|
namespace chrome_pdf {
|
||||||
|
|
||||||
class PdfInkModuleClient {
|
class PdfInkModuleClient {
|
||||||
@@ -104,8 +107,8 @@ class PdfInkModuleClient {
|
|||||||
// Notifies the client that a stroke has finished drawing or erasing.
|
// Notifies the client that a stroke has finished drawing or erasing.
|
||||||
virtual void StrokeFinished() {}
|
virtual void StrokeFinished() {}
|
||||||
|
|
||||||
// Asks the client to change the cursor to `bitmap`.
|
// Asks the client to change the cursor to `cursor`.
|
||||||
virtual void UpdateInkCursorImage(SkBitmap bitmap) {}
|
virtual void UpdateInkCursor(const ui::Cursor& cursor) {}
|
||||||
|
|
||||||
// Notifies that an existing shape identified by `id` on the page at
|
// Notifies that an existing shape identified by `id` on the page at
|
||||||
// `page_index` should update its active state.
|
// `page_index` should update its active state.
|
||||||
|
@@ -40,6 +40,8 @@
|
|||||||
#include "third_party/ink/src/ink/geometry/affine_transform.h"
|
#include "third_party/ink/src/ink/geometry/affine_transform.h"
|
||||||
#include "third_party/ink/src/ink/strokes/input/type_matchers.h"
|
#include "third_party/ink/src/ink/strokes/input/type_matchers.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
#include "ui/base/cursor/cursor.h"
|
||||||
|
#include "ui/base/cursor/mojom/cursor_type.mojom.h"
|
||||||
#include "ui/gfx/geometry/point_f.h"
|
#include "ui/gfx/geometry/point_f.h"
|
||||||
#include "ui/gfx/geometry/rect.h"
|
#include "ui/gfx/geometry/rect.h"
|
||||||
#include "ui/gfx/geometry/rect_conversions.h"
|
#include "ui/gfx/geometry/rect_conversions.h"
|
||||||
@@ -174,9 +176,10 @@ MATCHER_P(InkStrokeDrawingBrushTypeEq, expected_type, "") {
|
|||||||
return opacity == 0.4f;
|
return opacity == 0.4f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matcher for bitmap against expected dimensions.
|
// Matcher for cursor with a custom bitmap against expected dimensions.
|
||||||
MATCHER_P(BitmapImageSizeEq, dimensions, "") {
|
MATCHER_P(CursorBitmapImageSizeEq, dimensions, "") {
|
||||||
return arg.dimensions() == dimensions;
|
return arg.type() == ui::mojom::CursorType::kCustom &&
|
||||||
|
arg.custom_bitmap().dimensions() == dimensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, std::vector<raw_ref<const ink::Stroke>>> CollectVisibleStrokes(
|
std::map<int, std::vector<raw_ref<const ink::Stroke>>> CollectVisibleStrokes(
|
||||||
@@ -305,7 +308,7 @@ class FakeClient : public PdfInkModuleClient {
|
|||||||
|
|
||||||
void StrokeFinished() override { ++stroke_finished_count_; }
|
void StrokeFinished() override { ++stroke_finished_count_; }
|
||||||
|
|
||||||
MOCK_METHOD(void, UpdateInkCursorImage, (SkBitmap bitmap), (override));
|
MOCK_METHOD(void, UpdateInkCursor, (const ui::Cursor&), (override));
|
||||||
|
|
||||||
MOCK_METHOD(void,
|
MOCK_METHOD(void,
|
||||||
UpdateShapeActive,
|
UpdateShapeActive,
|
||||||
@@ -650,9 +653,9 @@ TEST_F(PdfInkModuleTest, HandleSetAnnotationModeMessage) {
|
|||||||
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenTogglingAnnotationMode) {
|
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenTogglingAnnotationMode) {
|
||||||
EXPECT_FALSE(ink_module().enabled());
|
EXPECT_FALSE(ink_module().enabled());
|
||||||
|
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_)).WillOnce([this]() {
|
||||||
.WillOnce(
|
EXPECT_TRUE(ink_module().enabled());
|
||||||
[this](SkBitmap bitmap) { EXPECT_TRUE(ink_module().enabled()); });
|
});
|
||||||
|
|
||||||
base::Value::Dict message =
|
base::Value::Dict message =
|
||||||
CreateSetAnnotationModeMessageForTesting(/*enable=*/true);
|
CreateSetAnnotationModeMessageForTesting(/*enable=*/true);
|
||||||
@@ -667,18 +670,24 @@ TEST_F(PdfInkModuleTest, MaybeSetCursorWhenTogglingAnnotationMode) {
|
|||||||
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenChangingBrushes) {
|
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenChangingBrushes) {
|
||||||
{
|
{
|
||||||
InSequence seq;
|
InSequence seq;
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(6, bitmap.width());
|
EXPECT_EQ(6, bitmap.width());
|
||||||
EXPECT_EQ(6, bitmap.height());
|
EXPECT_EQ(6, bitmap.height());
|
||||||
});
|
});
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(20, bitmap.width());
|
EXPECT_EQ(20, bitmap.width());
|
||||||
EXPECT_EQ(20, bitmap.height());
|
EXPECT_EQ(20, bitmap.height());
|
||||||
});
|
});
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(6, bitmap.width());
|
EXPECT_EQ(6, bitmap.width());
|
||||||
EXPECT_EQ(6, bitmap.height());
|
EXPECT_EQ(6, bitmap.height());
|
||||||
});
|
});
|
||||||
@@ -700,18 +709,24 @@ TEST_F(PdfInkModuleTest, MaybeSetCursorWhenChangingBrushes) {
|
|||||||
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenChangingZoom) {
|
TEST_F(PdfInkModuleTest, MaybeSetCursorWhenChangingZoom) {
|
||||||
{
|
{
|
||||||
InSequence seq;
|
InSequence seq;
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(6, bitmap.width());
|
EXPECT_EQ(6, bitmap.width());
|
||||||
EXPECT_EQ(6, bitmap.height());
|
EXPECT_EQ(6, bitmap.height());
|
||||||
});
|
});
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(20, bitmap.width());
|
EXPECT_EQ(20, bitmap.width());
|
||||||
EXPECT_EQ(20, bitmap.height());
|
EXPECT_EQ(20, bitmap.height());
|
||||||
});
|
});
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(_))
|
EXPECT_CALL(client(), UpdateInkCursor(_))
|
||||||
.WillOnce([](SkBitmap bitmap) {
|
.WillOnce([](const ui::Cursor& cursor) {
|
||||||
|
ASSERT_EQ(ui::mojom::CursorType::kCustom, cursor.type());
|
||||||
|
const SkBitmap& bitmap = cursor.custom_bitmap();
|
||||||
EXPECT_EQ(10, bitmap.width());
|
EXPECT_EQ(10, bitmap.width());
|
||||||
EXPECT_EQ(10, bitmap.height());
|
EXPECT_EQ(10, bitmap.height());
|
||||||
});
|
});
|
||||||
@@ -1918,7 +1933,8 @@ TEST_F(PdfInkModuleStrokeTest, ChangeBrushSizeDuringDrawing) {
|
|||||||
// until the mouse-up event. The cursor image will be updated only when
|
// until the mouse-up event. The cursor image will be updated only when
|
||||||
// there is not a stroke in progress.
|
// there is not a stroke in progress.
|
||||||
EXPECT_CALL(client(), StrokeAdded(_, _, _)).Times(0);
|
EXPECT_CALL(client(), StrokeAdded(_, _, _)).Times(0);
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(BitmapImageSizeEq(SkISize(6, 6))));
|
EXPECT_CALL(client(),
|
||||||
|
UpdateInkCursor(CursorBitmapImageSizeEq(SkISize(6, 6))));
|
||||||
TestAnnotationBrushMessageParams message_params{/*color_r=*/0,
|
TestAnnotationBrushMessageParams message_params{/*color_r=*/0,
|
||||||
/*color_g=*/0,
|
/*color_g=*/0,
|
||||||
/*color_b=*/0, /*size=*/2.0};
|
/*color_b=*/0, /*size=*/2.0};
|
||||||
@@ -1945,7 +1961,7 @@ TEST_F(PdfInkModuleStrokeTest, ChangeBrushSizeDuringDrawing) {
|
|||||||
EXPECT_CALL(client(), StrokeAdded(kPageIndex, InkStrokeId(0),
|
EXPECT_CALL(client(), StrokeAdded(kPageIndex, InkStrokeId(0),
|
||||||
InkStrokeBrushSizeEq(2.0f)));
|
InkStrokeBrushSizeEq(2.0f)));
|
||||||
EXPECT_CALL(client(),
|
EXPECT_CALL(client(),
|
||||||
UpdateInkCursorImage(BitmapImageSizeEq(SkISize(8, 8))));
|
UpdateInkCursor(CursorBitmapImageSizeEq(SkISize(8, 8))));
|
||||||
}
|
}
|
||||||
blink::WebMouseEvent mouse_move_event =
|
blink::WebMouseEvent mouse_move_event =
|
||||||
CreateMouseMoveWithLeftButtonEventAtPoint(kLeftVerticalStrokePoint2);
|
CreateMouseMoveWithLeftButtonEventAtPoint(kLeftVerticalStrokePoint2);
|
||||||
@@ -2082,7 +2098,8 @@ TEST_F(PdfInkModuleStrokeTest, ChangeDrawingBrushTypeDuringDrawing) {
|
|||||||
// until the mouse-up event. The cursor image will be updated only if a
|
// until the mouse-up event. The cursor image will be updated only if a
|
||||||
// stroke is not in progress.
|
// stroke is not in progress.
|
||||||
EXPECT_CALL(client(), StrokeAdded(_, _, _)).Times(0);
|
EXPECT_CALL(client(), StrokeAdded(_, _, _)).Times(0);
|
||||||
EXPECT_CALL(client(), UpdateInkCursorImage(BitmapImageSizeEq(SkISize(6, 6))));
|
EXPECT_CALL(client(),
|
||||||
|
UpdateInkCursor(CursorBitmapImageSizeEq(SkISize(6, 6))));
|
||||||
TestAnnotationBrushMessageParams pen_message_params{/*color_r=*/0,
|
TestAnnotationBrushMessageParams pen_message_params{/*color_r=*/0,
|
||||||
/*color_g=*/0,
|
/*color_g=*/0,
|
||||||
/*color_b=*/0,
|
/*color_b=*/0,
|
||||||
@@ -2116,7 +2133,7 @@ TEST_F(PdfInkModuleStrokeTest, ChangeDrawingBrushTypeDuringDrawing) {
|
|||||||
StrokeAdded(kPageIndex, InkStrokeId(0),
|
StrokeAdded(kPageIndex, InkStrokeId(0),
|
||||||
InkStrokeDrawingBrushTypeEq(PdfInkBrush::Type::kPen)));
|
InkStrokeDrawingBrushTypeEq(PdfInkBrush::Type::kPen)));
|
||||||
EXPECT_CALL(client(),
|
EXPECT_CALL(client(),
|
||||||
UpdateInkCursorImage(BitmapImageSizeEq(SkISize(10, 10))));
|
UpdateInkCursor(CursorBitmapImageSizeEq(SkISize(10, 10))));
|
||||||
}
|
}
|
||||||
blink::WebMouseEvent mouse_move_event =
|
blink::WebMouseEvent mouse_move_event =
|
||||||
CreateMouseMoveWithLeftButtonEventAtPoint(kLeftVerticalStrokePoint2);
|
CreateMouseMoveWithLeftButtonEventAtPoint(kLeftVerticalStrokePoint2);
|
||||||
|
@@ -365,10 +365,8 @@ class PdfViewWebPlugin::PdfInkModuleClientImpl : public PdfInkModuleClient {
|
|||||||
plugin_->SetPluginCanSave(true);
|
plugin_->SetPluginCanSave(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateInkCursorImage(SkBitmap bitmap) override {
|
void UpdateInkCursor(const ui::Cursor& cursor) override {
|
||||||
gfx::Point hotspot(bitmap.width() / 2, bitmap.height() / 2);
|
plugin_->cursor_ = cursor;
|
||||||
plugin_->cursor_ =
|
|
||||||
ui::Cursor::NewCustom(std::move(bitmap), std::move(hotspot));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateShapeActive(int page_index,
|
void UpdateShapeActive(int page_index,
|
||||||
|
Reference in New Issue
Block a user