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() { ...@@ -446,10 +446,10 @@ void EventHandler::UpdateCursor() {
layout_view->HitTest(location, result); layout_view->HitTest(location, result);
if (LocalFrame* frame = result.InnerNodeFrame()) { if (LocalFrame* frame = result.InnerNodeFrame()) {
EventHandler::OptionalCursor optional_cursor = base::Optional<Cursor> optional_cursor =
frame->GetEventHandler().SelectCursor(location, result); frame->GetEventHandler().SelectCursor(location, result);
if (optional_cursor.IsCursorChange()) { if (optional_cursor.has_value()) {
view->SetCursor(optional_cursor.GetCursor()); view->SetCursor(optional_cursor.value());
} }
} }
} }
...@@ -493,17 +493,17 @@ bool EventHandler::ShouldShowIBeamForNode(const Node* node, ...@@ -493,17 +493,17 @@ bool EventHandler::ShouldShowIBeamForNode(const Node* node,
return HasEditableStyle(*node); return HasEditableStyle(*node);
} }
EventHandler::OptionalCursor EventHandler::SelectCursor( base::Optional<Cursor> EventHandler::SelectCursor(
const HitTestLocation& location, const HitTestLocation& location,
const HitTestResult& result) { const HitTestResult& result) {
if (scroll_manager_->InResizeMode()) if (scroll_manager_->InResizeMode())
return kNoCursorChange; return base::nullopt;
Page* page = frame_->GetPage(); Page* page = frame_->GetPage();
if (!page) if (!page)
return kNoCursorChange; return base::nullopt;
if (scroll_manager_->MiddleClickAutoscrollInProgress()) if (scroll_manager_->MiddleClickAutoscrollInProgress())
return kNoCursorChange; return base::nullopt;
if (result.GetScrollbar() && !result.GetScrollbar()->IsCustomScrollbar()) if (result.GetScrollbar() && !result.GetScrollbar()->IsCustomScrollbar())
return PointerCursor(); return PointerCursor();
...@@ -543,7 +543,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor( ...@@ -543,7 +543,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor(
case kSetCursor: case kSetCursor:
return override_cursor; return override_cursor;
case kDoNotSetCursor: case kDoNotSetCursor:
return kNoCursorChange; return base::nullopt;
} }
} }
...@@ -677,7 +677,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor( ...@@ -677,7 +677,7 @@ EventHandler::OptionalCursor EventHandler::SelectCursor(
return PointerCursor(); return PointerCursor();
} }
EventHandler::OptionalCursor EventHandler::SelectAutoCursor( base::Optional<Cursor> EventHandler::SelectAutoCursor(
const HitTestResult& result, const HitTestResult& result,
Node* node, Node* node,
const Cursor& i_beam) { const Cursor& i_beam) {
...@@ -1061,10 +1061,10 @@ WebInputEventResult EventHandler::HandleMouseMoveOrLeaveEvent( ...@@ -1061,10 +1061,10 @@ WebInputEventResult EventHandler::HandleMouseMoveOrLeaveEvent(
} }
LocalFrameView* view = frame_->View(); LocalFrameView* view = frame_->View();
if ((!is_remote_frame || is_portal) && view) { if ((!is_remote_frame || is_portal) && view) {
EventHandler::OptionalCursor optional_cursor = base::Optional<Cursor> optional_cursor =
SelectCursor(mev.GetHitTestLocation(), mev.GetHitTestResult()); SelectCursor(mev.GetHitTestLocation(), mev.GetHitTestResult());
if (optional_cursor.IsCursorChange()) { if (optional_cursor.has_value()) {
view->SetCursor(optional_cursor.GetCursor()); view->SetCursor(optional_cursor.value());
} }
} }
} }
......
...@@ -271,27 +271,6 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> { ...@@ -271,27 +271,6 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> {
bool LongTapShouldInvokeContextMenu(); bool LongTapShouldInvokeContextMenu();
private: 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( WebInputEventResult HandleMouseMoveOrLeaveEvent(
const WebMouseEvent&, const WebMouseEvent&,
const Vector<WebMouseEvent>& coalesced_events, const Vector<WebMouseEvent>& coalesced_events,
...@@ -316,11 +295,11 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> { ...@@ -316,11 +295,11 @@ class CORE_EXPORT EventHandler final : public GarbageCollected<EventHandler> {
bool IsSelectingLink(const HitTestResult&); bool IsSelectingLink(const HitTestResult&);
bool ShouldShowIBeamForNode(const Node*, const HitTestResult&); bool ShouldShowIBeamForNode(const Node*, const HitTestResult&);
bool ShouldShowResizeForNode(const Node*, const HitTestLocation&); bool ShouldShowResizeForNode(const Node*, const HitTestLocation&);
OptionalCursor SelectCursor(const HitTestLocation& location, base::Optional<Cursor> SelectCursor(const HitTestLocation& location,
const HitTestResult&); const HitTestResult&);
OptionalCursor SelectAutoCursor(const HitTestResult&, base::Optional<Cursor> SelectAutoCursor(const HitTestResult&,
Node*, Node*,
const Cursor& i_beam); const Cursor& i_beam);
void HoverTimerFired(TimerBase*); void HoverTimerFired(TimerBase*);
void CursorUpdateTimerFired(TimerBase*); void CursorUpdateTimerFired(TimerBase*);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include "base/optional.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -626,7 +627,7 @@ TEST_F(EventHandlerTest, AnchorTextCannotStartSelection) { ...@@ -626,7 +627,7 @@ TEST_F(EventHandlerTest, AnchorTextCannotStartSelection) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
ui::mojom::CursorType::kHand); // A hand signals ability to navigate. ui::mojom::CursorType::kHand); // A hand signals ability to navigate.
} }
...@@ -649,7 +650,7 @@ TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) { ...@@ -649,7 +650,7 @@ TEST_F(EventHandlerTest, EditableAnchorTextCanStartSelection) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
ui::mojom::CursorType::kIBeam); // An I-beam signals editability. ui::mojom::CursorType::kIBeam); // An I-beam signals editability.
} }
...@@ -668,7 +669,7 @@ TEST_F(EventHandlerTest, CursorForVerticalResizableTextArea) { ...@@ -668,7 +669,7 @@ TEST_F(EventHandlerTest, CursorForVerticalResizableTextArea) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
// A north-south resize signals vertical resizability. // A north-south resize signals vertical resizability.
ui::mojom::CursorType::kNorthSouthResize); ui::mojom::CursorType::kNorthSouthResize);
...@@ -688,7 +689,7 @@ TEST_F(EventHandlerTest, CursorForHorizontalResizableTextArea) { ...@@ -688,7 +689,7 @@ TEST_F(EventHandlerTest, CursorForHorizontalResizableTextArea) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
// An east-west resize signals horizontal resizability. // An east-west resize signals horizontal resizability.
ui::mojom::CursorType::kEastWestResize); ui::mojom::CursorType::kEastWestResize);
...@@ -708,7 +709,7 @@ TEST_F(EventHandlerTest, CursorForResizableTextArea) { ...@@ -708,7 +709,7 @@ TEST_F(EventHandlerTest, CursorForResizableTextArea) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
// An south-east resize signals both horizontal and // An south-east resize signals both horizontal and
// vertical resizability. // vertical resizability.
...@@ -730,7 +731,7 @@ TEST_F(EventHandlerTest, CursorForRtlResizableTextArea) { ...@@ -730,7 +731,7 @@ TEST_F(EventHandlerTest, CursorForRtlResizableTextArea) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
// An south-west resize signals both horizontal and // An south-west resize signals both horizontal and
// vertical resizability when direction is RTL. // vertical resizability when direction is RTL.
...@@ -754,7 +755,7 @@ TEST_F(EventHandlerTest, CursorForInlineVerticalWritingMode) { ...@@ -754,7 +755,7 @@ TEST_F(EventHandlerTest, CursorForInlineVerticalWritingMode) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
ui::mojom::CursorType::kSouthEastResize); ui::mojom::CursorType::kSouthEastResize);
} }
...@@ -776,7 +777,7 @@ TEST_F(EventHandlerTest, CursorForBlockVerticalWritingMode) { ...@@ -776,7 +777,7 @@ TEST_F(EventHandlerTest, CursorForBlockVerticalWritingMode) {
.GetFrame() .GetFrame()
->GetEventHandler() ->GetEventHandler()
.SelectCursor(location, result) .SelectCursor(location, result)
.GetCursor() .value()
.GetType(), .GetType(),
ui::mojom::CursorType::kSouthEastResize); 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