Changeset 277069 in webkit


Ignore:
Timestamp:
May 5, 2021 11:43:14 PM (3 years ago)
Author:
Megan Gardner
Message:

AppHighlight scrolls should be smooth
https://bugs.webkit.org/show_bug.cgi?id=225395

Reviewed by Simon Fraser.

Leverage smooth scrolling experimental feature to allow AppHighlight scrolls
to be smooth.

  • Modules/highlight/AppHighlightStorage.cpp:

(WebCore::AppHighlightStorage::attemptToRestoreHighlightAndScroll):

  • editing/Editor.cpp:

(WebCore::TemporarySelectionChange::setSelection):

  • editing/Editor.h:
  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::setSelection):
(WebCore::FrameSelection::updateAndRevealSelection):
(WebCore::FrameSelection::revealSelection):

  • editing/FrameSelection.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::scrollTo const):

  • page/ScrollBehavior.cpp:

(WebCore::useSmoothScrolling):

  • platform/ScrollTypes.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277068 r277069  
     12021-05-05  Megan Gardner  <megan_gardner@apple.com>
     2
     3        AppHighlight scrolls should be smooth
     4        https://bugs.webkit.org/show_bug.cgi?id=225395
     5
     6        Reviewed by Simon Fraser.
     7
     8        Leverage smooth scrolling experimental feature to allow AppHighlight scrolls
     9        to be smooth.
     10
     11        * Modules/highlight/AppHighlightStorage.cpp:
     12        (WebCore::AppHighlightStorage::attemptToRestoreHighlightAndScroll):
     13        * editing/Editor.cpp:
     14        (WebCore::TemporarySelectionChange::setSelection):
     15        * editing/Editor.h:
     16        * editing/FrameSelection.cpp:
     17        (WebCore::FrameSelection::setSelection):
     18        (WebCore::FrameSelection::updateAndRevealSelection):
     19        (WebCore::FrameSelection::revealSelection):
     20        * editing/FrameSelection.h:
     21        * page/DOMWindow.cpp:
     22        (WebCore::DOMWindow::scrollTo const):
     23        * page/ScrollBehavior.cpp:
     24        (WebCore::useSmoothScrolling):
     25        * platform/ScrollTypes.h:
     26
    1272021-05-05  Mark Lam  <mark.lam@apple.com>
    228
  • trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp

    r276347 r277069  
    261261    strongDocument->appHighlightRegister().addAppHighlight(StaticRange::create(*range));
    262262   
    263     if (scroll == ScrollToHighlight::Yes) {
    264         OptionSet<TemporarySelectionOption> temporarySelectionOptions;
    265         temporarySelectionOptions.add(TemporarySelectionOption::RevealSelection);
    266         TemporarySelectionChange selectionChange(*strongDocument, { range.value() }, temporarySelectionOptions);
    267     }
     263    if (scroll == ScrollToHighlight::Yes)
     264        TemporarySelectionChange selectionChange(*strongDocument, { range.value() }, { TemporarySelectionOption::RevealSelection, TemporarySelectionOption::SmoothScroll, TemporarySelectionOption::OverrideSmoothScrollFeatureEnablment });
     265
    268266    return true;
    269267}
  • trunk/Source/WebCore/dom/Element.cpp

    r276698 r277069  
    937937        isHorizontal ? alignY : alignX,
    938938        ShouldAllowCrossOriginScrolling::No,
    939         options.behavior.valueOr(ScrollBehavior::Auto)
     939        options.behavior.valueOr(ScrollBehavior::Auto),
     940        SmoothScrollFeatureEnablement::Default
    940941    };
    941942    renderer()->scrollRectToVisible(absoluteBounds, insideFixed, visibleOptions);
  • trunk/Source/WebCore/editing/Editor.cpp

    r276347 r277069  
    266266    if (m_options & TemporarySelectionOption::RevealSelection)
    267267        options.add(FrameSelection::RevealSelection);
     268    if (m_options & TemporarySelectionOption::SmoothScroll)
     269        options.add(FrameSelection::SmoothScroll);
     270    if (m_options & TemporarySelectionOption::OverrideSmoothScrollFeatureEnablment)
     271        options.add(FrameSelection::OverrideSmoothScrollFeatureEnablement);
    268272    m_document->selection().setSelection(selection, options);
    269273}
  • trunk/Source/WebCore/editing/Editor.h

    r276191 r277069  
    119119    // Force the render tree to update selection state. Only respected on iOS.
    120120    EnableAppearanceUpdates = 1 << 3,
     121   
     122    SmoothScroll = 1 << 4,
     123   
     124    OverrideSmoothScrollFeatureEnablment = 1 << 5,
    121125};
    122126
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r275161 r277069  
    445445        return;
    446446
    447     updateAndRevealSelection(intent);
     447    updateAndRevealSelection(intent, options.contains(SmoothScroll) ? ScrollBehavior::Smooth : ScrollBehavior::Instant, options.contains(OverrideSmoothScrollFeatureEnablement) ? SmoothScrollFeatureEnablement::Override : SmoothScrollFeatureEnablement::Default);
    448448
    449449    if (options & IsUserTriggered) {
     
    472472}
    473473
    474 void FrameSelection::updateAndRevealSelection(const AXTextStateChangeIntent& intent)
     474void FrameSelection::updateAndRevealSelection(const AXTextStateChangeIntent& intent, ScrollBehavior scrollBehavior, SmoothScrollFeatureEnablement overideFeatureEnablement)
    475475{
    476476    if (!m_pendingSelectionUpdate)
     
    489489            alignment = m_alwaysAlignCursorOnScrollWhenRevealingSelection ? ScrollAlignment::alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded;
    490490
    491         revealSelection(m_selectionRevealMode, alignment, RevealExtent);
     491        revealSelection(m_selectionRevealMode, alignment, RevealExtent, scrollBehavior, overideFeatureEnablement);
    492492    }
    493493
     
    23792379}
    23802380
    2381 void FrameSelection::revealSelection(SelectionRevealMode revealMode, const ScrollAlignment& alignment, RevealExtentOption revealExtentOption)
     2381void FrameSelection::revealSelection(SelectionRevealMode revealMode, const ScrollAlignment& alignment, RevealExtentOption revealExtentOption, ScrollBehavior scrollBehavior, SmoothScrollFeatureEnablement overrideFeatureEnablement)
    23822382{
    23832383    if (revealMode == SelectionRevealMode::DoNotReveal)
     
    24022402                auto* scrollableArea = layer->ensureLayerScrollableArea();
    24032403                scrollableArea->setAdjustForIOSCaretWhenScrolling(true);
    2404                 layer->scrollRectToVisible(rect, insideFixed, { revealMode, alignment, alignment, ShouldAllowCrossOriginScrolling::Yes });
     2404                layer->scrollRectToVisible(rect, insideFixed, { revealMode, alignment, alignment, ShouldAllowCrossOriginScrolling::Yes, scrollBehavior, overrideFeatureEnablement});
    24052405                scrollableArea->setAdjustForIOSCaretWhenScrolling(false);
    24062406                updateAppearance();
     
    24132413        // the selection rect could intersect more than just that.
    24142414        // See <rdar://problem/4799899>.
    2415         if (start.deprecatedNode()->renderer()->scrollRectToVisible(rect, insideFixed, { revealMode, alignment, alignment, ShouldAllowCrossOriginScrolling::Yes }))
     2415        if (start.deprecatedNode()->renderer()->scrollRectToVisible(rect, insideFixed, { revealMode, alignment, alignment, ShouldAllowCrossOriginScrolling::Yes, scrollBehavior, overrideFeatureEnablement}))
    24162416            updateAppearance();
    24172417#endif
  • trunk/Source/WebCore/editing/FrameSelection.h

    r274862 r277069  
    3333#include "LayoutRect.h"
    3434#include "ScrollAlignment.h"
     35#include "ScrollBehavior.h"
    3536#include "Timer.h"
    3637#include "VisibleSelection.h"
     
    123124        RevealSelection = 1 << 7,
    124125        RevealSelectionUpToMainFrame = 1 << 8,
     126        SmoothScroll = 1 << 9,
     127        OverrideSmoothScrollFeatureEnablement = 1 << 10
    125128    };
    126129    static constexpr OptionSet<SetSelectionOption> defaultSetSelectionOptions(EUserTriggered = NotUserTriggered);
     
    246249    WEBCORE_EXPORT HTMLFormElement* currentForm() const;
    247250
    248     WEBCORE_EXPORT void revealSelection(SelectionRevealMode = SelectionRevealMode::Reveal, const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent);
     251    WEBCORE_EXPORT void revealSelection(SelectionRevealMode = SelectionRevealMode::Reveal, const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, RevealExtentOption = DoNotRevealExtent, ScrollBehavior = ScrollBehavior::Instant, SmoothScrollFeatureEnablement = SmoothScrollFeatureEnablement::Default);
    249252    WEBCORE_EXPORT void setSelectionFromNone();
    250253
     
    261264
    262265private:
    263     void updateAndRevealSelection(const AXTextStateChangeIntent&);
     266    void updateAndRevealSelection(const AXTextStateChangeIntent&, ScrollBehavior = ScrollBehavior::Instant, SmoothScrollFeatureEnablement = SmoothScrollFeatureEnablement::Override);
    264267    void updateDataDetectorsForSelection();
    265268
  • trunk/Source/WebCore/page/ScrollBehavior.cpp

    r272295 r277069  
    3434namespace WebCore {
    3535
    36 bool useSmoothScrolling(ScrollBehavior behavior, Element* associatedElement)
     36bool useSmoothScrolling(ScrollBehavior behavior, Element* associatedElement, SmoothScrollFeatureEnablement overrideFeatureEnablement)
    3737{
    3838    if (!associatedElement)
     
    4444        associatedElement = associatedElement->document().documentElement();
    4545
    46     if (!associatedElement->renderer() || !associatedElement->document().settings().CSSOMViewSmoothScrollingEnabled())
     46    if (!associatedElement->renderer() || (overrideFeatureEnablement == SmoothScrollFeatureEnablement::Default && !associatedElement->document().settings().CSSOMViewSmoothScrollingEnabled()))
    4747        return false;
    4848
  • trunk/Source/WebCore/page/ScrollBehavior.h

    r255957 r277069  
    3636};
    3737
    38 bool useSmoothScrolling(ScrollBehavior, Element* associatedElement);
     38enum class SmoothScrollFeatureEnablement : bool { Default, Override };
     39
     40bool useSmoothScrolling(ScrollBehavior, Element* associatedElement, SmoothScrollFeatureEnablement = SmoothScrollFeatureEnablement::Default);
    3941
    4042} // namespace WebCore
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r276718 r277069  
    24082408    {
    24092409        auto scrollPositionOptions = ScrollPositionChangeOptions::createProgrammatic();
    2410         if (!renderer().frame().eventHandler().autoscrollInProgress() && element && useSmoothScrolling(options.behavior, element))
     2410        if (!renderer().frame().eventHandler().autoscrollInProgress() && element && useSmoothScrolling(options.behavior, element, options.overrideFeatureEnablement))
    24112411            scrollPositionOptions.animated = AnimatedScroll::Yes;
    24122412        return scrollPositionOptions;
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r276842 r277069  
    142142    ShouldAllowCrossOriginScrolling shouldAllowCrossOriginScrolling { ShouldAllowCrossOriginScrolling::No };
    143143    ScrollBehavior behavior { ScrollBehavior::Auto };
     144    SmoothScrollFeatureEnablement overrideFeatureEnablement { SmoothScrollFeatureEnablement::Default };
    144145};
    145146
Note: See TracChangeset for help on using the changeset viewer.