Skip to content

Commit

Permalink
UnifiedPDF: Home and End keys don't work
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271165
<rdar://problem/124785475>

Reviewed by Abrar Rahman Protyasha.

* Source/WebCore/platform/KeyboardScrollingAnimator.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::handleKeyboardEvent):
Take care of Home and End key commands that make it to us.

Canonical link: https://commits.webkit.org/276288@main
  • Loading branch information
hortont424 committed Mar 18, 2024
1 parent d4ecd74 commit 07b0249
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Source/WebCore/platform/KeyboardScrollingAnimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "KeyboardScroll.h" // FIXME: This is a layering violation.
#include "RectEdges.h"
#include "ScrollableArea.h"
#include <wtf/CheckedPtr.h>

namespace WebCore {

Expand All @@ -50,13 +51,13 @@ const std::optional<KeyboardScrollingKey> keyboardScrollingKeyForKeyboardEvent(c
const std::optional<ScrollDirection> scrollDirectionForKeyboardEvent(const KeyboardEvent&);
const std::optional<ScrollGranularity> scrollGranularityForKeyboardEvent(const KeyboardEvent&);

class KeyboardScrollingAnimator : public CanMakeWeakPtr<KeyboardScrollingAnimator> {
class KeyboardScrollingAnimator : public CanMakeWeakPtr<KeyboardScrollingAnimator>, public CanMakeCheckedPtr {
WTF_MAKE_NONCOPYABLE(KeyboardScrollingAnimator);
WTF_MAKE_FAST_ALLOCATED;
public:
KeyboardScrollingAnimator(ScrollableArea&);

bool beginKeyboardScrollGesture(ScrollDirection, ScrollGranularity, bool isKeyRepeat);
WEBCORE_EXPORT bool beginKeyboardScrollGesture(ScrollDirection, ScrollGranularity, bool isKeyRepeat);
void handleKeyUpEvent();
WEBCORE_EXPORT void stopScrollingImmediately();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "WebEventModifier.h"
#include "WebEventType.h"
#include "WebHitTestResultData.h"
#include "WebKeyboardEvent.h"
#include "WebMouseEvent.h"
#include "WebPageProxyMessages.h"
#include <CoreGraphics/CoreGraphics.h>
Expand Down Expand Up @@ -80,6 +81,7 @@
#include <WebCore/RenderLayerBacking.h>
#include <WebCore/RenderLayerCompositor.h>
#include <WebCore/ScreenProperties.h>
#include <WebCore/ScrollAnimator.h>
#include <WebCore/ScrollTypes.h>
#include <WebCore/ScrollbarTheme.h>
#include <WebCore/ScrollbarsController.h>
Expand Down Expand Up @@ -2009,8 +2011,21 @@ static bool isContextMenuEvent(const WebMouseEvent& event)
#endif // ENABLE(CONTEXT_MENUS)
}

bool UnifiedPDFPlugin::handleKeyboardEvent(const WebKeyboardEvent&)
bool UnifiedPDFPlugin::handleKeyboardEvent(const WebKeyboardEvent& event)
{
#if PLATFORM(MAC)
auto& commands = event.commands();
if (commands.size() != 1)
return false;
auto commandName = commands[0].commandName;

CheckedPtr keyboardAnimator = scrollAnimator().keyboardScrollingAnimator();
if (commandName == "scrollToBeginningOfDocument:"_s)
return keyboardAnimator->beginKeyboardScrollGesture(ScrollDirection::ScrollUp, ScrollGranularity::Document, false);
if (commandName == "scrollToEndOfDocument:"_s)
return keyboardAnimator->beginKeyboardScrollGesture(ScrollDirection::ScrollDown, ScrollGranularity::Document, false);
#endif

return false;
}

Expand Down

0 comments on commit 07b0249

Please sign in to comment.