Commit c3813844 authored by Fei Ling's avatar Fei Ling Committed by Commit Bot

Change cursor when mouse over on resizable element

In fact we already detect whether the mouse is in the resize
control. The problem is that the cursor is always set to the pointer
cursor in this case. What we should do is to change the cursor depending
on the value of the resize style.

Bug: 942017
Change-Id: I4205c85627afbad8f59bd85784d4f34046621a9b
Fixed: 942017
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944315
Commit-Queue: Fei Ling <feiling@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721146}
parent b6ae771e
...@@ -509,8 +509,25 @@ EventHandler::OptionalCursor EventHandler::SelectCursor( ...@@ -509,8 +509,25 @@ EventHandler::OptionalCursor EventHandler::SelectCursor(
if (!node) if (!node)
return SelectAutoCursor(result, node, IBeamCursor()); return SelectAutoCursor(result, node, IBeamCursor());
if (ShouldShowResizeForNode(node, location)) if (ShouldShowResizeForNode(node, location)) {
return PointerCursor(); const LayoutBox* box =
node->GetLayoutObject()->EnclosingLayer()->GetLayoutBox();
EResize resize = box->StyleRef().Resize(box->ContainingBlock()->StyleRef());
switch (resize) {
case EResize::kVertical:
return NorthSouthResizeCursor();
case EResize::kHorizontal:
return EastWestResizeCursor();
case EResize::kBoth:
if (box->ShouldPlaceBlockDirectionScrollbarOnLogicalLeft()) {
return SouthWestResizeCursor();
} else {
return SouthEastResizeCursor();
}
default:
return PointerCursor();
}
}
LayoutObject* layout_object = node->GetLayoutObject(); LayoutObject* layout_object = node->GetLayoutObject();
const ComputedStyle* style = layout_object ? layout_object->Style() : nullptr; const ComputedStyle* style = layout_object ? layout_object->Style() : nullptr;
......
...@@ -495,6 +495,15 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> { ...@@ -495,6 +495,15 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> {
EditableAnchorTextCanStartSelection); EditableAnchorTextCanStartSelection);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest, FRIEND_TEST_ALL_PREFIXES(EventHandlerTest,
ReadOnlyInputDoesNotInheritUserSelect); ReadOnlyInputDoesNotInheritUserSelect);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest,
CursorForVerticalResizableTextArea);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest,
CursorForHorizontalResizableTextArea);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest, CursorForResizableTextArea);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest, CursorForRtlResizableTextArea);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest,
CursorForInlineVerticalWritingMode);
FRIEND_TEST_ALL_PREFIXES(EventHandlerTest, CursorForBlockVerticalWritingMode);
FRIEND_TEST_ALL_PREFIXES(FallbackCursorEventManagerTest, FRIEND_TEST_ALL_PREFIXES(FallbackCursorEventManagerTest,
MouseMoveCursorLockOnDiv); MouseMoveCursorLockOnDiv);
......
...@@ -652,6 +652,133 @@ TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) { ...@@ -652,6 +652,133 @@ TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) {
ui::CursorType::kIBeam); // An I-beam signals editability. ui::CursorType::kIBeam); // An I-beam signals editability.
} }
TEST_F(EventHandlerTest, CursorForVerticalResizableTextArea) {
SetHtmlInnerHTML("<textarea style='resize:vertical'>vertical</textarea>");
Node* const element = GetDocument().body()->firstChild();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MaxXMaxYCorner();
point.Move(-5, -5);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
// A north-south resize signals vertical resizability.
ui::CursorType::kNorthSouthResize);
}
TEST_F(EventHandlerTest, CursorForHorizontalResizableTextArea) {
SetHtmlInnerHTML("<textarea style='resize:horizontal'>horizontal</textarea>");
Node* const element = GetDocument().body()->firstChild();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MaxXMaxYCorner();
point.Move(-5, -5);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
// An east-west resize signals horizontal resizability.
ui::CursorType::kEastWestResize);
}
TEST_F(EventHandlerTest, CursorForResizableTextArea) {
SetHtmlInnerHTML("<textarea style='resize:both'>both</textarea>");
Node* const element = GetDocument().body()->firstChild();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MaxXMaxYCorner();
point.Move(-5, -5);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
// An south-east resize signals both horizontal and
// vertical resizability.
ui::CursorType::kSouthEastResize);
}
TEST_F(EventHandlerTest, CursorForRtlResizableTextArea) {
SetHtmlInnerHTML(
"<textarea style='resize:both;direction:rtl'>both</textarea>");
Node* const element = GetDocument().body()->firstChild();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MinXMaxYCorner();
point.Move(5, -5);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
// An south-west resize signals both horizontal and
// vertical resizability when direction is RTL.
ui::CursorType::kSouthWestResize);
}
TEST_F(EventHandlerTest, CursorForInlineVerticalWritingMode) {
SetHtmlInnerHTML(
"Test<p style='resize:both;writing-mode:vertical-lr;"
"width:30px;height:30px;overflow:hidden;display:inline'>Test "
"Test</p>Test");
Node* const element = GetDocument().body()->firstChild()->nextSibling();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MinXMinYCorner();
point.Move(25, 25);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
ui::CursorType::kSouthEastResize);
}
TEST_F(EventHandlerTest, CursorForBlockVerticalWritingMode) {
SetHtmlInnerHTML(
"Test<p style='resize:both;writing-mode:vertical-lr;"
"width:30px;height:30px;overflow:hidden;display:block'>Test "
"Test</p>Test");
Node* const element = GetDocument().body()->firstChild()->nextSibling();
blink::IntPoint point =
element->GetLayoutObject()->AbsoluteBoundingBoxRect().MinXMinYCorner();
point.Move(25, 25);
HitTestLocation location(point);
HitTestResult result =
GetDocument().GetFrame()->GetEventHandler().HitTestResultAtLocation(
location);
EXPECT_EQ(GetDocument()
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.GetType(),
ui::CursorType::kSouthEastResize);
}
TEST_F(EventHandlerTest, implicitSend) { TEST_F(EventHandlerTest, implicitSend) {
SetHtmlInnerHTML("<button>abc</button>"); SetHtmlInnerHTML("<button>abc</button>");
GetDocument().GetSettings()->SetSpatialNavigationEnabled(true); GetDocument().GetSettings()->SetSpatialNavigationEnabled(true);
......
This tests that hovering over a TEXTAREA resizer turns the mouse cursor into the default pointer. This tests that hovering over a TEXTAREA resizer turns the mouse cursor into the SouthEastResize cursor.
Inside TEXTAREA: type=IBeam hotSpot=0,0 Inside TEXTAREA: type=IBeam hotSpot=0,0
Over dragger: type=Pointer hotSpot=0,0 Over dragger: type=SouthEastResize hotSpot=0,0
Over BODY: type=Hand hotSpot=0,0 Over BODY: type=Hand hotSpot=0,0
Over dragger: type=Pointer hotSpot=0,0 Over dragger: type=SouthEastResize hotSpot=0,0
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</head> </head>
<body onload="test()"> <body onload="test()">
<textarea style="width: 100px; height: 100px;"></textarea> <textarea style="width: 100px; height: 100px;"></textarea>
<p>This tests that hovering over a TEXTAREA resizer turns the mouse cursor into the default pointer.<br> <p>This tests that hovering over a TEXTAREA resizer turns the mouse cursor into the SouthEastResize cursor.<br>
<div id="console"></div> <div id="console"></div>
</body> </body>
</html> </html>
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