Make WebCore::FocusDirection to enum class
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Oct 2020 09:03:25 +0000 (09:03 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Oct 2020 09:03:25 +0000 (09:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=218162

Patch by Tetsuharu Ohzeki <tetsuharu.ohzeki@gmail.com> on 2020-10-27
Reviewed by Darin Adler.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::adjustFocusedNodeOnNodeRemoval):
(WebCore::Document::focusNavigationStartingNode const):
* dom/Document.h:
* dom/Element.h:
* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::handleFocusEvent):
* page/EventHandler.cpp:
(WebCore::focusDirectionForKey):
(WebCore::handleKeyboardSelectionMovement):
(WebCore::EventHandler::accessibilityPreventsEventPropagation):
(WebCore::EventHandler::defaultKeyboardEventHandler):
(WebCore::EventHandler::defaultTabEventHandler):
* page/FocusController.cpp:
(WebCore::dispatchEventsOnWindowAndFocusedElement):
(WebCore::FocusController::advanceFocus):
(WebCore::FocusController::findFocusableElementAcrossFocusScope):
(WebCore::FocusController::findFocusableElementWithinScope):
(WebCore::FocusController::findFocusableElementOrScopeOwner):
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::FocusController::nextFocusableElementOrScopeOwner):
(WebCore::FocusController::previousFocusableElementOrScopeOwner):
* page/FocusController.h:
* page/FocusDirection.h:
* page/SpatialNavigation.cpp:
(WebCore::isHorizontalMove):
(WebCore::areRectsFullyAligned):
(WebCore::areRectsMoreThanFullScreenApart):
(WebCore::isRectInDirection):
(WebCore::hasOffscreenRect):
(WebCore::scrollInDirection):
(WebCore::canScrollInDirection):
(WebCore::entryAndExitPointsForDirection):
(WebCore::isValidCandidate):
(WebCore::distanceDataForNode):
(WebCore::canBeScrolledIntoView):
(WebCore::virtualRectForDirection):
* page/SpatialNavigation.h:

Source/WebKit:

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::takeFocus):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::takeFocus):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::takeFocus):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::handleKeyEventByRelinquishingFocusToChrome):
(WebKit::WebPage::setInitialFocus):

Source/WebKitLegacy/mac:

* WebCoreSupport/WebChromeClient.mm:
(WebChromeClient::takeFocus):
* WebView/WebHTMLView.mm:
(-[WebHTMLView becomeFirstResponder]):

Source/WebKitLegacy/win:

* WebCoreSupport/WebChromeClient.cpp:
(WebChromeClient::canTakeFocus):
(WebChromeClient::takeFocus):
* WebView.cpp:
(WebView::setInitialFocus):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269027 268f45cc-cd09-0410-ab3c-d52691b4dbfc

24 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/dom/Element.h
Source/WebCore/html/BaseDateAndTimeInputType.cpp
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/FocusController.cpp
Source/WebCore/page/FocusController.h
Source/WebCore/page/FocusDirection.h
Source/WebCore/page/SpatialNavigation.cpp
Source/WebCore/page/SpatialNavigation.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebChromeClient.mm
Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebChromeClient.cpp
Source/WebKitLegacy/win/WebView.cpp

index 0d590fa..dc751ad 100644 (file)
@@ -1,3 +1,49 @@
+2020-10-27  Tetsuharu Ohzeki  <tetsuharu.ohzeki@gmail.com>
+
+        Make WebCore::FocusDirection to enum class
+        https://bugs.webkit.org/show_bug.cgi?id=218162
+
+        Reviewed by Darin Adler.
+
+        * dom/Document.cpp:
+        (WebCore::Document::adjustFocusedNodeOnNodeRemoval):
+        (WebCore::Document::focusNavigationStartingNode const):
+        * dom/Document.h:
+        * dom/Element.h:
+        * html/BaseDateAndTimeInputType.cpp:
+        (WebCore::BaseDateAndTimeInputType::handleFocusEvent):
+        * page/EventHandler.cpp:
+        (WebCore::focusDirectionForKey):
+        (WebCore::handleKeyboardSelectionMovement):
+        (WebCore::EventHandler::accessibilityPreventsEventPropagation):
+        (WebCore::EventHandler::defaultKeyboardEventHandler):
+        (WebCore::EventHandler::defaultTabEventHandler):
+        * page/FocusController.cpp:
+        (WebCore::dispatchEventsOnWindowAndFocusedElement):
+        (WebCore::FocusController::advanceFocus):
+        (WebCore::FocusController::findFocusableElementAcrossFocusScope):
+        (WebCore::FocusController::findFocusableElementWithinScope):
+        (WebCore::FocusController::findFocusableElementOrScopeOwner):
+        (WebCore::FocusController::findElementWithExactTabIndex):
+        (WebCore::FocusController::nextFocusableElementOrScopeOwner):
+        (WebCore::FocusController::previousFocusableElementOrScopeOwner):
+        * page/FocusController.h:
+        * page/FocusDirection.h:
+        * page/SpatialNavigation.cpp:
+        (WebCore::isHorizontalMove):
+        (WebCore::areRectsFullyAligned):
+        (WebCore::areRectsMoreThanFullScreenApart):
+        (WebCore::isRectInDirection):
+        (WebCore::hasOffscreenRect):
+        (WebCore::scrollInDirection):
+        (WebCore::canScrollInDirection):
+        (WebCore::entryAndExitPointsForDirection):
+        (WebCore::isValidCandidate):
+        (WebCore::distanceDataForNode):
+        (WebCore::canBeScrolledIntoView):
+        (WebCore::virtualRectForDirection):
+        * page/SpatialNavigation.h:
+
 2020-10-27  Kimmo Kinnunen  <kkinnunen@apple.com>
 
         REGRESSION (r268386): Flashes of inverted color when zooming the map on windy.com
index 8a651fc..c9e3be1 100644 (file)
@@ -4244,7 +4244,7 @@ void Document::adjustFocusedNodeOnNodeRemoval(Node& node, NodeRemoval nodeRemova
         // FIXME: We should avoid synchronously updating the style inside setFocusedElement.
         // FIXME: Object elements should avoid loading a frame synchronously in a post style recalc callback.
         SubframeLoadingDisabler disabler(is<ContainerNode>(node) ? &downcast<ContainerNode>(node) : nullptr);
-        setFocusedElement(nullptr, FocusDirectionNone, FocusRemovalEventsMode::DoNotDispatch);
+        setFocusedElement(nullptr, FocusDirection::None, FocusRemovalEventsMode::DoNotDispatch);
         // Set the focus navigation starting node to the previous focused element so that
         // we can fallback to the siblings or parent node for the next search.
         // Also we need to call removeFocusNavigationNodeOfSubtree after this function because
@@ -4525,7 +4525,7 @@ Element* Document::focusNavigationStartingNode(FocusDirection direction) const
         Node* nextNode = NodeTraversal::next(*node);
         if (!nextNode)
             nextNode = node;
-        if (direction == FocusDirectionForward)
+        if (direction == FocusDirection::Forward)
             return ElementTraversal::previous(*nextNode);
         if (is<Element>(*nextNode))
             return downcast<Element>(nextNode);
@@ -4534,7 +4534,7 @@ Element* Document::focusNavigationStartingNode(FocusDirection direction) const
 
     if (is<Element>(*node))
         return downcast<Element>(node);
-    if (Element* elementBeforeNextFocusableElement = direction == FocusDirectionForward ? ElementTraversal::previous(*node) : ElementTraversal::next(*node))
+    if (Element* elementBeforeNextFocusableElement = direction == FocusDirection::Forward ? ElementTraversal::previous(*node) : ElementTraversal::next(*node))
         return elementBeforeNextFocusableElement;
     return node->parentOrShadowHostElement();
 }
index d54644b..6993ac3 100644 (file)
@@ -749,7 +749,7 @@ public:
     enum class FocusRemovalEventsMode { Dispatch, DoNotDispatch };
     // Returns whether focus was blocked. A true value does not necessarily mean the element was focused.
     // The element could have already been focused or may not be focusable (e.g. <input disabled>).
-    WEBCORE_EXPORT bool setFocusedElement(Element*, FocusDirection = FocusDirectionNone,
+    WEBCORE_EXPORT bool setFocusedElement(Element*, FocusDirection = FocusDirection::None,
         FocusRemovalEventsMode = FocusRemovalEventsMode::Dispatch);
     Element* focusedElement() const { return m_focusedElement.get(); }
     UserActionElementSet& userActionElements()  { return m_userActionElements; }
index 566523d..1974299 100644 (file)
@@ -400,7 +400,7 @@ public:
     virtual String target() const { return String(); }
 
     static AXTextStateChangeIntent defaultFocusTextStateChangeIntent() { return AXTextStateChangeIntent(AXTextStateChangeTypeSelectionMove, AXTextSelection { AXTextSelectionDirectionDiscontiguous, AXTextSelectionGranularityUnknown, true }); }
-    virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
+    virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirection::None);
     void revealFocusedElement(SelectionRestorationMode);
     virtual RefPtr<Element> focusAppearanceUpdateTarget();
     virtual void updateFocusAppearance(SelectionRestorationMode, SelectionRevealMode = SelectionRevealMode::Reveal);
index 6f9e547..ba5370f 100644 (file)
@@ -435,7 +435,7 @@ void BaseDateAndTimeInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirec
     // If the element contains editable components, the element itself should not
     // be focused. Instead, one of it's children should receive focus.
 
-    if (direction == FocusDirectionBackward) {
+    if (direction == FocusDirection::Backward) {
         // If the element received focus when going backwards, advance the focus one more time
         // so that this element no longer has focus. In this case, one of the children should
         // not be focused as the element is losing focus entirely.
index 8ce4312..29a7df6 100644 (file)
@@ -3494,16 +3494,16 @@ static FocusDirection focusDirectionForKey(const AtomString& keyIdentifier)
     static MainThreadNeverDestroyed<const AtomString> Left("Left", AtomString::ConstructFromLiteral);
     static MainThreadNeverDestroyed<const AtomString> Right("Right", AtomString::ConstructFromLiteral);
 
-    FocusDirection retVal = FocusDirectionNone;
+    FocusDirection retVal = FocusDirection::None;
 
     if (keyIdentifier == Down)
-        retVal = FocusDirectionDown;
+        retVal = FocusDirection::Down;
     else if (keyIdentifier == Up)
-        retVal = FocusDirectionUp;
+        retVal = FocusDirection::Up;
     else if (keyIdentifier == Left)
-        retVal = FocusDirectionLeft;
+        retVal = FocusDirection::Left;
     else if (keyIdentifier == Right)
-        retVal = FocusDirectionRight;
+        retVal = FocusDirection::Right;
 
     return retVal;
 }
@@ -3556,25 +3556,25 @@ static void handleKeyboardSelectionMovement(Frame& frame, KeyboardEvent& event)
     TextGranularity granularity = TextGranularity::CharacterGranularity;
 
     switch (focusDirectionForKey(event.keyIdentifier())) {
-    case FocusDirectionNone:
+    case FocusDirection::None:
         return;
-    case FocusDirectionForward:
-    case FocusDirectionBackward:
+    case FocusDirection::Forward:
+    case FocusDirection::Backward:
         ASSERT_NOT_REACHED();
         return;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         direction = SelectionDirection::Backward;
         granularity = isCommanded ? TextGranularity::DocumentBoundary : TextGranularity::LineGranularity;
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         direction = SelectionDirection::Forward;
         granularity = isCommanded ? TextGranularity::DocumentBoundary : TextGranularity::LineGranularity;
         break;
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         direction = SelectionDirection::Left;
         granularity = (isCommanded) ? TextGranularity::LineBoundary : (isOptioned) ? TextGranularity::WordGranularity : TextGranularity::CharacterGranularity;
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         direction = SelectionDirection::Right;
         granularity = (isCommanded) ? TextGranularity::LineBoundary : (isOptioned) ? TextGranularity::WordGranularity : TextGranularity::CharacterGranularity;
         break;
@@ -3609,7 +3609,7 @@ bool EventHandler::accessibilityPreventsEventPropagation(KeyboardEvent& event)
     if (event.keyIdentifier() == "U+0009")
         return true;
     FocusDirection direction = focusDirectionForKey(event.keyIdentifier());
-    if (direction != FocusDirectionNone)
+    if (direction != FocusDirection::None)
         return true;
 #else
     UNUSED_PARAM(event);
@@ -3631,7 +3631,7 @@ void EventHandler::defaultKeyboardEventHandler(KeyboardEvent& event)
             defaultBackspaceEventHandler(event);
         else {
             FocusDirection direction = focusDirectionForKey(event.keyIdentifier());
-            if (direction != FocusDirectionNone)
+            if (direction != FocusDirection::None)
                 defaultArrowEventHandler(direction, event);
         }
 
@@ -4112,7 +4112,7 @@ void EventHandler::defaultTabEventHandler(KeyboardEvent& event)
     if (!page->tabKeyCyclesThroughElements())
         return;
 
-    if (page->focusController().advanceFocus(event.shiftKey() ? FocusDirectionBackward : FocusDirectionForward, &event))
+    if (page->focusController().advanceFocus(event.shiftKey() ? FocusDirection::Backward : FocusDirection::Forward, &event))
         event.setDefaultHandled();
 }
 
index 62a9ea4..82a64c3 100644 (file)
@@ -308,7 +308,7 @@ static inline void dispatchEventsOnWindowAndFocusedElement(Document* document, b
         document->focusedElement()->dispatchBlurEvent(nullptr);
     document->dispatchWindowEvent(Event::create(focused ? eventNames().focusEvent : eventNames().blurEvent, Event::CanBubble::No, Event::IsCancelable::No));
     if (focused && document->focusedElement())
-        document->focusedElement()->dispatchFocusEvent(nullptr, FocusDirectionNone);
+        document->focusedElement()->dispatchFocusEvent(nullptr, FocusDirection::None);
 }
 
 static inline bool isFocusableElementOrScopeOwner(Element& element, KeyboardEvent* event)
@@ -433,13 +433,13 @@ bool FocusController::setInitialFocus(FocusDirection direction, KeyboardEvent* p
 bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event, bool initialFocus)
 {
     switch (direction) {
-    case FocusDirectionForward:
-    case FocusDirectionBackward:
+    case FocusDirection::Forward:
+    case FocusDirection::Backward:
         return advanceFocusInDocumentOrder(direction, event, initialFocus);
-    case FocusDirectionLeft:
-    case FocusDirectionRight:
-    case FocusDirectionUp:
-    case FocusDirectionDown:
+    case FocusDirection::Left:
+    case FocusDirection::Right:
+    case FocusDirection::Up:
+    case FocusDirection::Down:
         return advanceFocusDirectionally(direction, event);
     default:
         ASSERT_NOT_REACHED();
@@ -541,7 +541,7 @@ Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection di
 {
     ASSERT(!is<Element>(currentNode) || !isNonFocusableScopeOwner(downcast<Element>(*currentNode), event));
 
-    if (currentNode && direction == FocusDirectionForward && is<Element>(currentNode) && isFocusableScopeOwner(downcast<Element>(*currentNode), event)) {
+    if (currentNode && direction == FocusDirection::Forward && is<Element>(currentNode) && isFocusableScopeOwner(downcast<Element>(*currentNode), event)) {
         if (Element* candidateInInnerScope = findFocusableElementWithinScope(direction, FocusNavigationScope::scopeOwnedByScopeOwner(downcast<Element>(*currentNode)), 0, event))
             return candidateInInnerScope;
     }
@@ -552,7 +552,7 @@ Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection di
     // If there's no focusable node to advance to, move up the focus scopes until we find one.
     Element* owner = scope.owner();
     while (owner) {
-        if (direction == FocusDirectionBackward && isFocusableScopeOwner(*owner, event))
+        if (direction == FocusDirection::Backward && isFocusableScopeOwner(*owner, event))
             return findFocusableElementDescendingIntoSubframes(direction, owner, event);
 
         auto outerScope = FocusNavigationScope::scopeOf(*owner);
@@ -566,7 +566,7 @@ Element* FocusController::findFocusableElementAcrossFocusScope(FocusDirection di
 Element* FocusController::findFocusableElementWithinScope(FocusDirection direction, const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
 {
     // Starting node is exclusive.
-    Element* candidate = direction == FocusDirectionForward
+    Element* candidate = direction == FocusDirection::Forward
         ? nextFocusableElementWithinScope(scope, start, event)
         : previousFocusableElementWithinScope(scope, start, event);
     return findFocusableElementDescendingIntoSubframes(direction, candidate, event);
@@ -606,7 +606,7 @@ Element* FocusController::previousFocusableElementWithinScope(const FocusNavigat
 
 Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direction, const FocusNavigationScope& scope, Node* node, KeyboardEvent* event)
 {
-    return (direction == FocusDirectionForward)
+    return (direction == FocusDirection::Forward)
         ? nextFocusableElementOrScopeOwner(scope, node, event)
         : previousFocusableElementOrScopeOwner(scope, node, event);
 }
@@ -614,7 +614,7 @@ Element* FocusController::findFocusableElementOrScopeOwner(FocusDirection direct
 Element* FocusController::findElementWithExactTabIndex(const FocusNavigationScope& scope, Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
 {
     // Search is inclusive of start
-    for (Node* node = start; node; node = direction == FocusDirectionForward ? scope.nextInScope(node) : scope.previousInScope(node)) {
+    for (Node* node = start; node; node = direction == FocusDirection::Forward ? scope.nextInScope(node) : scope.previousInScope(node)) {
         if (!is<Element>(*node))
             continue;
         Element& element = downcast<Element>(*node);
@@ -694,7 +694,7 @@ Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigation
         }
 
         // First try to find a node with the same tabindex as start that comes after start in the scope.
-        if (Element* winner = findElementWithExactTabIndex(scope, scope.nextInScope(start), startTabIndex, event, FocusDirectionForward))
+        if (Element* winner = findElementWithExactTabIndex(scope, scope.nextInScope(start), startTabIndex, event, FocusDirection::Forward))
             return winner;
 
         if (!startTabIndex)
@@ -709,7 +709,7 @@ Element* FocusController::nextFocusableElementOrScopeOwner(const FocusNavigation
 
     // There are no nodes with a tabindex greater than start's tabindex,
     // so find the first node with a tabindex of 0.
-    return findElementWithExactTabIndex(scope, scope.firstNodeInScope(), 0, event, FocusDirectionForward);
+    return findElementWithExactTabIndex(scope, scope.firstNodeInScope(), 0, event, FocusDirection::Forward);
 }
 
 Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNavigationScope& scope, Node* start, KeyboardEvent* event)
@@ -741,7 +741,7 @@ Element* FocusController::previousFocusableElementOrScopeOwner(const FocusNaviga
         }
     }
 
-    if (Element* winner = findElementWithExactTabIndex(scope, startingNode, startingTabIndex, event, FocusDirectionBackward))
+    if (Element* winner = findElementWithExactTabIndex(scope, startingNode, startingTabIndex, event, FocusDirection::Backward))
         return winner;
 
     // There are no nodes before start with the same tabindex as start, so look for a node that:
index 17d34c5..29785d1 100644 (file)
@@ -59,7 +59,7 @@ public:
     WEBCORE_EXPORT bool setInitialFocus(FocusDirection, KeyboardEvent*);
     bool advanceFocus(FocusDirection, KeyboardEvent*, bool initialFocus = false);
 
-    WEBCORE_EXPORT bool setFocusedElement(Element*, Frame&, FocusDirection = FocusDirectionNone);
+    WEBCORE_EXPORT bool setFocusedElement(Element*, Frame&, FocusDirection = FocusDirection::None);
 
     void setActivityState(OptionSet<ActivityState::Flag>);
 
index 816421d..af6bd6e 100644 (file)
 
 namespace WebCore {
 
-enum FocusDirection {
-    FocusDirectionNone = 0,
-    FocusDirectionForward,
-    FocusDirectionBackward,
-    FocusDirectionUp,
-    FocusDirectionDown,
-    FocusDirectionLeft,
-    FocusDirectionRight
+enum class FocusDirection: uint8_t {
+    None = 0,
+    Forward,
+    Backward,
+    Up,
+    Down,
+    Left,
+    Right
 };
 
 } // namespace WebCore
index 4d8b72f..38fb497 100644 (file)
@@ -108,7 +108,7 @@ static RectsAlignment alignmentForRects(FocusDirection direction, const LayoutRe
 
 static inline bool isHorizontalMove(FocusDirection direction)
 {
-    return direction == FocusDirectionLeft || direction == FocusDirectionRight;
+    return direction == FocusDirection::Left || direction == FocusDirection::Right;
 }
 
 static inline LayoutUnit start(FocusDirection direction, const LayoutRect& rect)
@@ -139,19 +139,19 @@ static bool areRectsFullyAligned(FocusDirection direction, const LayoutRect& a,
     LayoutUnit aStart, bStart, aEnd, bEnd;
 
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         aStart = a.x();
         bEnd = b.maxX();
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         aStart = b.x();
         bEnd = a.maxX();
         break;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         aStart = a.y();
         bEnd = b.y();
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         aStart = b.y();
         bEnd = a.y();
         break;
@@ -239,13 +239,13 @@ static bool areRectsMoreThanFullScreenApart(FocusDirection direction, const Layo
     ASSERT(isRectInDirection(direction, curRect, targetRect));
 
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         return curRect.x() - targetRect.maxX() > viewSize.width();
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         return targetRect.x() - curRect.maxX() > viewSize.width();
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         return curRect.y() - targetRect.maxY() > viewSize.height();
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         return targetRect.y() - curRect.maxY() > viewSize.height();
     default:
         ASSERT_NOT_REACHED();
@@ -268,13 +268,13 @@ static inline bool rightOf(const LayoutRect& a, const LayoutRect& b)
 static bool isRectInDirection(FocusDirection direction, const LayoutRect& curRect, const LayoutRect& targetRect)
 {
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         return targetRect.maxX() <= curRect.x();
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         return targetRect.x() >= curRect.maxX();
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         return targetRect.maxY() <= curRect.y();
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         return targetRect.y() >= curRect.maxY();
     default:
         ASSERT_NOT_REACHED();
@@ -302,18 +302,18 @@ bool hasOffscreenRect(Node* node, FocusDirection direction)
     // If the container has overflow:hidden, we cannot scroll, so we do not pass direction
     // and we do not adjust for scrolling.
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         containerViewportRect.setX(containerViewportRect.x() - Scrollbar::pixelsPerLineStep());
         containerViewportRect.setWidth(containerViewportRect.width() + Scrollbar::pixelsPerLineStep());
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         containerViewportRect.setWidth(containerViewportRect.width() + Scrollbar::pixelsPerLineStep());
         break;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         containerViewportRect.setY(containerViewportRect.y() - Scrollbar::pixelsPerLineStep());
         containerViewportRect.setHeight(containerViewportRect.height() + Scrollbar::pixelsPerLineStep());
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         containerViewportRect.setHeight(containerViewportRect.height() + Scrollbar::pixelsPerLineStep());
         break;
     default:
@@ -339,16 +339,16 @@ bool scrollInDirection(Frame* frame, FocusDirection direction)
         LayoutUnit dx;
         LayoutUnit dy;
         switch (direction) {
-        case FocusDirectionLeft:
+        case FocusDirection::Left:
             dx = - Scrollbar::pixelsPerLineStep();
             break;
-        case FocusDirectionRight:
+        case FocusDirection::Right:
             dx = Scrollbar::pixelsPerLineStep();
             break;
-        case FocusDirectionUp:
+        case FocusDirection::Up:
             dy = - Scrollbar::pixelsPerLineStep();
             break;
-        case FocusDirectionDown:
+        case FocusDirection::Down:
             dy = Scrollbar::pixelsPerLineStep();
             break;
         default:
@@ -375,17 +375,17 @@ bool scrollInDirection(Node* container, FocusDirection direction)
         LayoutUnit dx;
         LayoutUnit dy;
         switch (direction) {
-        case FocusDirectionLeft:
+        case FocusDirection::Left:
             dx = - std::min<LayoutUnit>(Scrollbar::pixelsPerLineStep(), container->renderBox()->scrollLeft());
             break;
-        case FocusDirectionRight:
+        case FocusDirection::Right:
             ASSERT(container->renderBox()->scrollWidth() > (container->renderBox()->scrollLeft() + container->renderBox()->clientWidth()));
             dx = std::min<LayoutUnit>(Scrollbar::pixelsPerLineStep(), container->renderBox()->scrollWidth() - (container->renderBox()->scrollLeft() + container->renderBox()->clientWidth()));
             break;
-        case FocusDirectionUp:
+        case FocusDirection::Up:
             dy = - std::min<LayoutUnit>(Scrollbar::pixelsPerLineStep(), container->renderBox()->scrollTop());
             break;
-        case FocusDirectionDown:
+        case FocusDirection::Down:
             ASSERT(container->renderBox()->scrollHeight() - (container->renderBox()->scrollTop() + container->renderBox()->clientHeight()));
             dy = std::min<LayoutUnit>(Scrollbar::pixelsPerLineStep(), container->renderBox()->scrollHeight() - (container->renderBox()->scrollTop() + container->renderBox()->clientHeight()));
             break;
@@ -453,13 +453,13 @@ bool canScrollInDirection(const Node* container, FocusDirection direction)
         return false;
 
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         return (container->renderer()->style().overflowX() != Overflow::Hidden && container->renderBox()->scrollLeft() > 0);
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         return (container->renderer()->style().overflowY() != Overflow::Hidden && container->renderBox()->scrollTop() > 0);
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         return (container->renderer()->style().overflowX() != Overflow::Hidden && container->renderBox()->scrollLeft() + container->renderBox()->clientWidth() < container->renderBox()->scrollWidth());
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         return (container->renderer()->style().overflowY() != Overflow::Hidden && container->renderBox()->scrollTop() + container->renderBox()->clientHeight() < container->renderBox()->scrollHeight());
     default:
         ASSERT_NOT_REACHED();
@@ -474,9 +474,9 @@ bool canScrollInDirection(const Frame* frame, FocusDirection direction)
     ScrollbarMode verticalMode;
     ScrollbarMode horizontalMode;
     frame->view()->calculateScrollbarModesForLayout(horizontalMode, verticalMode);
-    if ((direction == FocusDirectionLeft || direction == FocusDirectionRight) && ScrollbarAlwaysOff == horizontalMode)
+    if ((direction == FocusDirection::Left || direction == FocusDirection::Right) && ScrollbarAlwaysOff == horizontalMode)
         return false;
-    if ((direction == FocusDirectionUp || direction == FocusDirectionDown) &&  ScrollbarAlwaysOff == verticalMode)
+    if ((direction == FocusDirection::Up || direction == FocusDirection::Down) &&  ScrollbarAlwaysOff == verticalMode)
         return false;
     LayoutSize size = frame->view()->totalContentsSize();
     LayoutPoint scrollPosition = frame->view()->scrollPosition();
@@ -484,13 +484,13 @@ bool canScrollInDirection(const Frame* frame, FocusDirection direction)
 
     // FIXME: wrong in RTL documents.
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         return scrollPosition.x() > 0;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         return scrollPosition.y() > 0;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         return rect.width() + scrollPosition.x() < size.width();
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         return rect.height() + scrollPosition.y() < size.height();
     default:
         ASSERT_NOT_REACHED();
@@ -544,19 +544,19 @@ LayoutRect frameRectInAbsoluteCoordinates(Frame* frame)
 void entryAndExitPointsForDirection(FocusDirection direction, const LayoutRect& startingRect, const LayoutRect& potentialRect, LayoutPoint& exitPoint, LayoutPoint& entryPoint)
 {
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         exitPoint.setX(startingRect.x());
         entryPoint.setX(potentialRect.maxX());
         break;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         exitPoint.setY(startingRect.y());
         entryPoint.setY(potentialRect.maxY());
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         exitPoint.setX(startingRect.maxX());
         entryPoint.setX(potentialRect.x());
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         exitPoint.setY(startingRect.maxY());
         entryPoint.setY(potentialRect.y());
         break;
@@ -565,8 +565,8 @@ void entryAndExitPointsForDirection(FocusDirection direction, const LayoutRect&
     }
 
     switch (direction) {
-    case FocusDirectionLeft:
-    case FocusDirectionRight:
+    case FocusDirection::Left:
+    case FocusDirection::Right:
         if (below(startingRect, potentialRect)) {
             exitPoint.setY(startingRect.y());
             entryPoint.setY(potentialRect.maxY());
@@ -578,8 +578,8 @@ void entryAndExitPointsForDirection(FocusDirection direction, const LayoutRect&
             entryPoint.setY(exitPoint.y());
         }
         break;
-    case FocusDirectionUp:
-    case FocusDirectionDown:
+    case FocusDirection::Up:
+    case FocusDirection::Down:
         if (rightOf(startingRect, potentialRect)) {
             exitPoint.setX(startingRect.x());
             entryPoint.setX(potentialRect.maxX());
@@ -627,13 +627,13 @@ bool isValidCandidate(FocusDirection direction, const FocusCandidate& current, F
     LayoutRect candidateRect = candidate.rect;
 
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         return candidateRect.x() < currentRect.maxX();
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         return candidateRect.y() < currentRect.maxY();
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         return candidateRect.maxX() > currentRect.x();
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         return candidateRect.maxY() > currentRect.y();
     default:
         ASSERT_NOT_REACHED();
@@ -644,7 +644,7 @@ bool isValidCandidate(FocusDirection direction, const FocusCandidate& current, F
 void distanceDataForNode(FocusDirection direction, const FocusCandidate& current, FocusCandidate& candidate)
 {
     if (areElementsOnSameLine(current, candidate)) {
-        if ((direction == FocusDirectionUp && current.rect.y() > candidate.rect.y()) || (direction == FocusDirectionDown && candidate.rect.y() > current.rect.y())) {
+        if ((direction == FocusDirection::Up && current.rect.y() > candidate.rect.y()) || (direction == FocusDirection::Down && candidate.rect.y() > current.rect.y())) {
             candidate.distance = 0;
             candidate.alignment = Full;
             return;
@@ -665,19 +665,19 @@ void distanceDataForNode(FocusDirection direction, const FocusCandidate& current
     entryAndExitPointsForDirection(direction, currentRect, nodeRect, exitPoint, entryPoint);
 
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         sameAxisDistance = exitPoint.x() - entryPoint.x();
         otherAxisDistance = absoluteValue(exitPoint.y() - entryPoint.y());
         break;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         sameAxisDistance = exitPoint.y() - entryPoint.y();
         otherAxisDistance = absoluteValue(exitPoint.x() - entryPoint.x());
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         sameAxisDistance = entryPoint.x() - exitPoint.x();
         otherAxisDistance = absoluteValue(entryPoint.y() - exitPoint.y());
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         sameAxisDistance = entryPoint.y() - exitPoint.y();
         otherAxisDistance = absoluteValue(entryPoint.x() - exitPoint.x());
         break;
@@ -709,8 +709,8 @@ bool canBeScrolledIntoView(FocusDirection direction, const FocusCandidate& candi
             continue;
         LayoutRect parentRect = nodeRectInAbsoluteCoordinates(parentNode);
         if (!candidateRect.intersects(parentRect)) {
-            if (((direction == FocusDirectionLeft || direction == FocusDirectionRight) && parentNode->renderer()->style().overflowX() == Overflow::Hidden)
-                || ((direction == FocusDirectionUp || direction == FocusDirectionDown) && parentNode->renderer()->style().overflowY() == Overflow::Hidden))
+            if (((direction == FocusDirection::Left || direction == FocusDirection::Right) && parentNode->renderer()->style().overflowX() == Overflow::Hidden)
+                || ((direction == FocusDirection::Up || direction == FocusDirection::Down) && parentNode->renderer()->style().overflowY() == Overflow::Hidden))
                 return false;
         }
         if (parentNode == candidate.enclosingScrollableBox)
@@ -727,18 +727,18 @@ LayoutRect virtualRectForDirection(FocusDirection direction, const LayoutRect& s
 {
     LayoutRect virtualStartingRect = startingRect;
     switch (direction) {
-    case FocusDirectionLeft:
+    case FocusDirection::Left:
         virtualStartingRect.setX(virtualStartingRect.maxX() - width);
         virtualStartingRect.setWidth(width);
         break;
-    case FocusDirectionUp:
+    case FocusDirection::Up:
         virtualStartingRect.setY(virtualStartingRect.maxY() - width);
         virtualStartingRect.setHeight(width);
         break;
-    case FocusDirectionRight:
+    case FocusDirection::Right:
         virtualStartingRect.setWidth(width);
         break;
-    case FocusDirectionDown:
+    case FocusDirection::Down:
         virtualStartingRect.setHeight(width);
         break;
     default:
index e376057..9748686 100644 (file)
@@ -127,7 +127,7 @@ struct FocusCandidate {
     bool isOffscreenAfterScrolling;
 };
 
-bool hasOffscreenRect(Node*, FocusDirection direction = FocusDirectionNone);
+bool hasOffscreenRect(Node*, FocusDirection = FocusDirection::None);
 bool scrollInDirection(Frame*, FocusDirection);
 bool scrollInDirection(Node* container, FocusDirection);
 bool canScrollInDirection(const Node* container, FocusDirection);
index bcf946c..b33776f 100644 (file)
@@ -1,3 +1,22 @@
+2020-10-27  Tetsuharu Ohzeki  <tetsuharu.ohzeki@gmail.com>
+
+        Make WebCore::FocusDirection to enum class
+        https://bugs.webkit.org/show_bug.cgi?id=218162
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::takeFocus):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::takeFocus):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::takeFocus):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::handleKeyEventByRelinquishingFocusToChrome):
+        (WebKit::WebPage::setInitialFocus):
+
 2020-10-26  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         [GPU Process]: Introduce RemoteResourceCacheProxy to manage the remote resources in Web Process
index bbb08e3..d06013b 100644 (file)
@@ -1648,7 +1648,7 @@ void WebViewImpl::takeFocus(WebCore::FocusDirection direction)
 {
     NSView *webView = m_view.getAutoreleased();
 
-    if (direction == WebCore::FocusDirectionForward) {
+    if (direction == WebCore::FocusDirection::Forward) {
         // Since we're trying to move focus out of m_webView, and because
         // m_webView may contain subviews within it, we ask it for the next key
         // view of the last view in its key view loop. This makes m_webView
index a69b7db..9a2aa80 100644 (file)
@@ -6852,9 +6852,9 @@ void WebPageProxy::setFocus(bool focused)
         m_uiClient->unfocus(this);
 }
 
-void WebPageProxy::takeFocus(uint32_t direction)
+void WebPageProxy::takeFocus(uint8_t direction)
 {
-    if (m_uiClient->takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirectionForward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward))
+    if (m_uiClient->takeFocus(this, (static_cast<FocusDirection>(direction) == FocusDirection::Forward) ? kWKFocusDirectionForward : kWKFocusDirectionBackward))
         return;
 
     pageClient().takeFocus(static_cast<FocusDirection>(direction));
index 715ece5..d4694f0 100644 (file)
@@ -2122,7 +2122,7 @@ private:
     void ignoreWord(const String& word);
     void requestCheckingOfString(uint64_t requestID, const WebCore::TextCheckingRequestData&, int32_t insertionPoint);
 
-    void takeFocus(uint32_t direction);
+    void takeFocus(uint8_t direction);
     void setToolTip(const String&);
     void setCursor(const WebCore::Cursor&);
     void setCursorHiddenUntilMouseMoves(bool);
index 950e539..ffa7d61 100644 (file)
@@ -43,7 +43,7 @@ messages -> WebPageProxy {
     SetCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
     SetStatusText(String statusText)
     SetFocus(bool focused)
-    TakeFocus(uint32_t direction)
+    TakeFocus(uint8_t direction)
     FocusedFrameChanged(Optional<WebCore::FrameIdentifier> frameID)
     SetRenderTreeSize(uint64_t treeSize)
     SetToolbarsAreVisible(bool toolbarsAreVisible)
index a0986f3..f8f94c4 100644 (file)
@@ -224,7 +224,7 @@ bool WebChromeClient::canTakeFocus(FocusDirection)
 
 void WebChromeClient::takeFocus(FocusDirection direction)
 {
-    m_page.send(Messages::WebPageProxy::TakeFocus(direction));
+    m_page.send(Messages::WebPageProxy::TakeFocus(static_cast<uint8_t>(direction)));
 }
 
 void WebChromeClient::focusedElementChanged(Element* element)
index 10ef79e..15c6ff7 100644 (file)
@@ -2918,7 +2918,7 @@ bool WebPage::handleKeyEventByRelinquishingFocusToChrome(const KeyboardEvent& ev
     // Allow a shift-tab keypress event to relinquish focus even if we don't allow tab to cycle between
     // elements inside the view. We can only do this for shift-tab, not tab itself because
     // tabKeyCyclesThroughElements is used to make tab character insertion work in editable web views.
-    return m_page->focusController().relinquishFocusToChrome(FocusDirectionBackward);
+    return m_page->focusController().relinquishFocusToChrome(FocusDirection::Backward);
 }
 
 void WebPage::validateCommand(const String& commandName, CallbackID callbackID)
@@ -3247,12 +3247,12 @@ void WebPage::setInitialFocus(bool forward, bool isKeyboardEventValid, const Web
     if (isKeyboardEventValid && event.type() == WebEvent::KeyDown) {
         PlatformKeyboardEvent platformEvent(platform(event));
         platformEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown);
-        m_page->focusController().setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, &KeyboardEvent::create(platformEvent, &frame.windowProxy()).get());
+        m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, &KeyboardEvent::create(platformEvent, &frame.windowProxy()).get());
         completionHandler();
         return;
     }
 
-    m_page->focusController().setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, nullptr);
+    m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, nullptr);
     completionHandler();
 }
 
index 12ac491..c6984e5 100644 (file)
@@ -1,3 +1,15 @@
+2020-10-27  Tetsuharu Ohzeki  <tetsuharu.ohzeki@gmail.com>
+
+        Make WebCore::FocusDirection to enum class
+        https://bugs.webkit.org/show_bug.cgi?id=218162
+
+        Reviewed by Darin Adler.
+
+        * WebCoreSupport/WebChromeClient.mm:
+        (WebChromeClient::takeFocus):
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView becomeFirstResponder]):
+
 2020-10-26  Zan Dobersek  <zdobersek@igalia.com>
 
         Remove Accelerated2dCanvasEnabled WebPreferences entry
index 4bc4c7a..e1182bd 100644 (file)
@@ -205,7 +205,7 @@ bool WebChromeClient::canTakeFocus(FocusDirection)
 void WebChromeClient::takeFocus(FocusDirection direction)
 {
 #if !PLATFORM(IOS_FAMILY)
-    if (direction == FocusDirectionForward) {
+    if (direction == FocusDirection::Forward) {
         // Since we're trying to move focus out of m_webView, and because
         // m_webView may contain subviews within it, we ask it for the next key
         // view of the last view in its key view loop. This makes m_webView
index ee6481f..5e6fe8a 100644 (file)
@@ -4615,7 +4615,7 @@ static RefPtr<WebCore::KeyboardEvent> currentKeyboardEvent(WebCore::Frame* coreF
 
     if (auto* document = frame->document())
         document->setFocusedElement(0);
-    page->focusController().setInitialFocus(direction == NSSelectingNext ? WebCore::FocusDirectionForward : WebCore::FocusDirectionBackward,
+    page->focusController().setInitialFocus(direction == NSSelectingNext ? WebCore::FocusDirection::Forward : WebCore::FocusDirection::Backward,
                                              currentKeyboardEvent(frame).get());
     return YES;
 }
index 4f2d0d3..4fec3ec 100644 (file)
@@ -1,3 +1,16 @@
+2020-10-27  Tetsuharu Ohzeki  <tetsuharu.ohzeki@gmail.com>
+
+        Make WebCore::FocusDirection to enum class
+        https://bugs.webkit.org/show_bug.cgi?id=218162
+
+        Reviewed by Darin Adler.
+
+        * WebCoreSupport/WebChromeClient.cpp:
+        (WebChromeClient::canTakeFocus):
+        (WebChromeClient::takeFocus):
+        * WebView.cpp:
+        (WebView::setInitialFocus):
+
 2020-10-22  Darin Adler  <darin@apple.com>
 
         REGRESSION(r266295): DOMSelection's addRange and containsNode behave incorrectly when selection crosses shadow boundaries
index 938bb85..e531093 100644 (file)
@@ -139,7 +139,7 @@ void WebChromeClient::unfocus()
 bool WebChromeClient::canTakeFocus(FocusDirection direction)
 {
     IWebUIDelegate* uiDelegate = 0;
-    BOOL bForward = (direction == FocusDirectionForward) ? TRUE : FALSE;
+    BOOL bForward = (direction == FocusDirection::Forward) ? TRUE : FALSE;
     BOOL result = FALSE;
     if (SUCCEEDED(m_webView->uiDelegate(&uiDelegate))) {
         uiDelegate->canTakeFocus(m_webView, bForward, &result);
@@ -152,7 +152,7 @@ bool WebChromeClient::canTakeFocus(FocusDirection direction)
 void WebChromeClient::takeFocus(FocusDirection direction)
 {
     IWebUIDelegate* uiDelegate = 0;
-    BOOL bForward = (direction == FocusDirectionForward) ? TRUE : FALSE;
+    BOOL bForward = (direction == FocusDirection::Forward) ? TRUE : FALSE;
     if (SUCCEEDED(m_webView->uiDelegate(&uiDelegate))) {
         uiDelegate->takeFocus(m_webView, bForward);
         uiDelegate->Release();
index ca4f724..99db592 100644 (file)
@@ -5975,7 +5975,7 @@ HRESULT WebView::setInitialFocus(BOOL forward)
     if (m_page) {
         Frame& frame = m_page->focusController().focusedOrMainFrame();
         frame.document()->setFocusedElement(0);
-        m_page->focusController().setInitialFocus(forward ? FocusDirectionForward : FocusDirectionBackward, 0);
+        m_page->focusController().setInitialFocus(forward ? FocusDirection::Forward : FocusDirection::Backward, 0);
     }
     return S_OK;
 }