Commit c746d540 authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Replace OptionalCursor with Optional<Cursor>

blink::EventHandler::OptionalCursor is a custom class equivalent to
base::Optional<blink::Cursor>. This CL replaces it with the base class.

Bug: 1040499
Change-Id: I85bb3384b999533c63780177807cbd47d3a8995c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093216
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749196}
parent 12cabc47
......@@ -446,10 +446,10 @@ void EventHandler::UpdateCursor() {
layout_view->HitTest(location, result);
if (LocalFrame* frame = result.InnerNodeFrame()) {
EventHandler::OptionalCursor optional_cursor =
base::Optional<Cursor> optional_cursor =
frame->GetEventHandler().SelectCursor(location, result);
if (optional_cursor.IsCursorChange()) {
view->SetCursor(optional_cursor.GetCursor());
if (optional_cursor.has_value()) {
view->SetCursor(optional_cursor.value());
}
}
}
......@@ -493,17 +493,17 @@ bool EventHandler::ShouldShowIBeamForNode(const Node* node,
return HasEditableStyle(*node);
}
EventHandler::OptionalCursor EventHandler::SelectCursor(
base::Optional<Cursor> EventHandler::SelectCursor(
const HitTestLocation& location,
const HitTestResult& result) {
if (scroll_manager_->InResizeMode())
return kNoCursorChange;
return base::nullopt;
Page* page = frame_->GetPage();
if (!page)
return kNoCursorChange;
return base::nullopt;
if (scroll_manager_->MiddleClickAutoscrollInProgress())
return kNoCursorChange;
return base::nullopt;
if (result.GetScrollbar() && !result.GetScrollbar()->IsCustomScrollbar())
return PointerCursor();
......@@ -543,7 +543,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor(
case kSetCursor:
return override_cursor;
case kDoNotSetCursor:
return kNoCursorChange;
return base::nullopt;
}
}
......@@ -677,7 +677,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor(
return PointerCursor();
}
EventHandler::OptionalCursor EventHandler::SelectAutoCursor(
base::Optional<Cursor> EventHandler::SelectAutoCursor(
const HitTestResult& result,
Node* node,
const Cursor& i_beam) {
......@@ -1061,10 +1061,10 @@ WebInputEventResult EventHandler::HandleMouseMoveOrLeaveEvent(
}
LocalFrameView* view = frame_->View();
if ((!is_remote_frame || is_portal) && view) {
EventHandler::OptionalCursor optional_cursor =
base::Optional<Cursor> optional_cursor =
SelectCursor(mev.GetHitTestLocation(), mev.GetHitTestResult());
if (optional_cursor.IsCursorChange()) {
view->SetCursor(optional_cursor.GetCursor());
if (optional_cursor.has_value()) {
view->SetCursor(optional_cursor.value());
}
}
}
......
......@@ -271,27 +271,6 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> {
bool LongTapShouldInvokeContextMenu();
private:
enum NoCursorChangeType { kNoCursorChange };
class OptionalCursor {
STACK_ALLOCATED();
public:
OptionalCursor(NoCursorChangeType) : is_cursor_change_(false) {}
OptionalCursor(const Cursor& cursor)
: is_cursor_change_(true), cursor_(cursor) {}
bool IsCursorChange() const { return is_cursor_change_; }
const Cursor& GetCursor() const {
DCHECK(is_cursor_change_);
return cursor_;
}
private:
bool is_cursor_change_;
Cursor cursor_;
};
WebInputEventResult HandleMouseMoveOrLeaveEvent(
const WebMouseEvent&,
const Vector<WebMouseEvent>& coalesced_events,
......@@ -316,11 +295,11 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> {
bool IsSelectingLink(const HitTestResult&);
bool ShouldShowIBeamForNode(const Node*, const HitTestResult&);
bool ShouldShowResizeForNode(const Node*, const HitTestLocation&);
OptionalCursor SelectCursor(const HitTestLocation& location,
const HitTestResult&);
OptionalCursor SelectAutoCursor(const HitTestResult&,
Node*,
const Cursor& i_beam);
base::Optional<Cursor> SelectCursor(const HitTestLocation& location,
const HitTestResult&);
base::Optional<Cursor> SelectAutoCursor(const HitTestResult&,
Node*,
const Cursor& i_beam);
void HoverTimerFired(TimerBase*);
void CursorUpdateTimerFired(TimerBase*);
......
......@@ -6,6 +6,7 @@
#include <memory>
#include "base/optional.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
......@@ -626,7 +627,7 @@ TEST_F(EventHandlerTest, AnchorTextCannotStartSelection) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
ui::mojom::CursorType::kHand); // A hand signals ability to navigate.
}
......@@ -649,7 +650,7 @@ TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
ui::mojom::CursorType::kIBeam); // An I-beam signals editability.
}
......@@ -668,7 +669,7 @@ TEST_F(EventHandlerTest, CursorForVerticalResizableTextArea) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
// A north-south resize signals vertical resizability.
ui::mojom::CursorType::kNorthSouthResize);
......@@ -688,7 +689,7 @@ TEST_F(EventHandlerTest, CursorForHorizontalResizableTextArea) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
// An east-west resize signals horizontal resizability.
ui::mojom::CursorType::kEastWestResize);
......@@ -708,7 +709,7 @@ TEST_F(EventHandlerTest, CursorForResizableTextArea) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
// An south-east resize signals both horizontal and
// vertical resizability.
......@@ -730,7 +731,7 @@ TEST_F(EventHandlerTest, CursorForRtlResizableTextArea) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
// An south-west resize signals both horizontal and
// vertical resizability when direction is RTL.
......@@ -754,7 +755,7 @@ TEST_F(EventHandlerTest, CursorForInlineVerticalWritingMode) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
ui::mojom::CursorType::kSouthEastResize);
}
......@@ -776,7 +777,7 @@ TEST_F(EventHandlerTest, CursorForBlockVerticalWritingMode) {
.GetFrame()
->GetEventHandler()
.SelectCursor(location, result)
.GetCursor()
.value()
.GetType(),
ui::mojom::CursorType::kSouthEastResize);
}
......
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