Prechádzať zdrojové kódy

LibWeb: Fire "keyup" events as well :^)

This was easy, now that we have KeyboardEvent.
Andreas Kling 3 rokov pred
rodič
commit
0af0ee4293

+ 5 - 0
Userland/Libraries/LibWeb/OutOfProcessWebView.cpp

@@ -161,6 +161,11 @@ void OutOfProcessWebView::keydown_event(GUI::KeyEvent& event)
     client().async_key_down(event.key(), event.modifiers(), event.code_point());
 }
 
+void OutOfProcessWebView::keyup_event(GUI::KeyEvent& event)
+{
+    client().async_key_up(event.key(), event.modifiers(), event.code_point());
+}
+
 void OutOfProcessWebView::mousedown_event(GUI::MouseEvent& event)
 {
     client().async_mouse_down(to_content_position(event.position()), event.button(), event.buttons(), event.modifiers());

+ 1 - 0
Userland/Libraries/LibWeb/OutOfProcessWebView.h

@@ -96,6 +96,7 @@ private:
     virtual void mousemove_event(GUI::MouseEvent&) override;
     virtual void mousewheel_event(GUI::MouseEvent&) override;
     virtual void keydown_event(GUI::KeyEvent&) override;
+    virtual void keyup_event(GUI::KeyEvent&) override;
     virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
     virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
 

+ 7 - 0
Userland/Libraries/LibWeb/Page/EventHandler.cpp

@@ -460,6 +460,13 @@ bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_poin
     return m_frame.active_document()->window().dispatch_event(move(event));
 }
 
+bool EventHandler::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
+{
+    auto event = UIEvents::KeyboardEvent::create_from_platform_event(UIEvents::EventNames::keyup, key, modifiers, code_point);
+    // FIXME: Figure out the right event target.
+    return m_frame.active_document()->window().dispatch_event(move(event));
+}
+
 void EventHandler::set_mouse_event_tracking_layout_node(Layout::Node* layout_node)
 {
     if (layout_node)

+ 1 - 0
Userland/Libraries/LibWeb/Page/EventHandler.h

@@ -30,6 +30,7 @@ public:
     bool handle_mousewheel(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers, int wheel_delta);
 
     bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
+    bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);
 
     void set_mouse_event_tracking_layout_node(Layout::Node*);
 

+ 5 - 0
Userland/Libraries/LibWeb/Page/Page.cpp

@@ -81,4 +81,9 @@ bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)
     return focused_context().event_handler().handle_keydown(key, modifiers, code_point);
 }
 
+bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
+{
+    return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
+}
+
 }

+ 1 - 0
Userland/Libraries/LibWeb/Page/Page.h

@@ -52,6 +52,7 @@ public:
     bool handle_mousewheel(const Gfx::IntPoint&, unsigned button, unsigned modifiers, int wheel_delta);
 
     bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
+    bool handle_keyup(KeyCode, unsigned modifiers, u32 code_point);
 
     Gfx::Palette palette() const;
     Gfx::IntRect screen_rect() const;

+ 1 - 0
Userland/Libraries/LibWeb/UIEvents/EventNames.h

@@ -16,6 +16,7 @@ namespace Web::UIEvents::EventNames {
 #define ENUMERATE_UI_EVENTS          \
     __ENUMERATE_UI_EVENT(click)      \
     __ENUMERATE_UI_EVENT(keydown)    \
+    __ENUMERATE_UI_EVENT(keyup)      \
     __ENUMERATE_UI_EVENT(mousedown)  \
     __ENUMERATE_UI_EVENT(mouseenter) \
     __ENUMERATE_UI_EVENT(mouseleave) \

+ 5 - 0
Userland/Services/WebContent/ClientConnection.cpp

@@ -169,6 +169,11 @@ void ClientConnection::key_down(i32 key, unsigned int modifiers, u32 code_point)
     page().handle_keydown((KeyCode)key, modifiers, code_point);
 }
 
+void ClientConnection::key_up(i32 key, unsigned int modifiers, u32 code_point)
+{
+    page().handle_keyup((KeyCode)key, modifiers, code_point);
+}
+
 void ClientConnection::debug_request(const String& request, const String& argument)
 {
     if (request == "dump-dom-tree") {

+ 1 - 0
Userland/Services/WebContent/ClientConnection.h

@@ -47,6 +47,7 @@ private:
     virtual void mouse_up(Gfx::IntPoint const&, unsigned, unsigned, unsigned) override;
     virtual void mouse_wheel(Gfx::IntPoint const&, unsigned, unsigned, unsigned, i32) override;
     virtual void key_down(i32, unsigned, u32) override;
+    virtual void key_up(i32, unsigned, u32) override;
     virtual void add_backing_store(i32, Gfx::ShareableBitmap const&) override;
     virtual void remove_backing_store(i32) override;
     virtual void debug_request(String const&, String const&) override;

+ 1 - 0
Userland/Services/WebContent/WebContentServer.ipc

@@ -23,6 +23,7 @@ endpoint WebContentServer
     mouse_wheel(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers, i32 wheel_delta) =|
 
     key_down(i32 key, unsigned modifiers, u32 code_point) =|
+    key_up(i32 key, unsigned modifiers, u32 code_point) =|
 
     debug_request(String request, String argument) =|
     get_source() =|