mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-27 05:05:32 +03:00
Deliver mouse events to the appropriate Window.
This commit is contained in:
parent
f2fa7b615f
commit
5d125e40d9
Notes:
sideshowbarker
2024-07-19 18:50:29 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5d125e40d9b
@ -1,5 +1,6 @@
|
||||
#include "Window.h"
|
||||
#include "WindowManager.h"
|
||||
#include "Event.h"
|
||||
|
||||
Window::Window(Object* parent)
|
||||
: Object(parent)
|
||||
@ -37,3 +38,14 @@ void Window::setRect(const Rect& rect)
|
||||
m_rect = rect;
|
||||
WindowManager::the().notifyRectChanged(*this, oldRect, m_rect);
|
||||
}
|
||||
|
||||
void Window::event(Event& event)
|
||||
{
|
||||
if (event.isMouseEvent()) {
|
||||
auto& me = static_cast<MouseEvent&>(event);
|
||||
printf("Window{%p}: %s %d,%d\n", this, me.name(), me.x(), me.y());
|
||||
return Object::event(event);
|
||||
}
|
||||
|
||||
return Object::event(event);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
class Widget;
|
||||
|
||||
class Window : public Object {
|
||||
class Window final : public Object {
|
||||
public:
|
||||
explicit Window(Object* parent = nullptr);
|
||||
virtual ~Window() override;
|
||||
@ -27,6 +27,8 @@ public:
|
||||
|
||||
void setMainWidget(Widget*);
|
||||
|
||||
virtual void event(Event&) override;
|
||||
|
||||
private:
|
||||
String m_title;
|
||||
Rect m_rect;
|
||||
|
@ -116,6 +116,7 @@ void WindowManager::processMouseEvent(MouseEvent& event)
|
||||
if (window->rect().contains(event.position())) {
|
||||
// FIXME: Re-use the existing event instead of crafting a new one?
|
||||
auto localEvent = make<MouseEvent>(event.type(), event.x() - window->rect().x(), event.y() - window->rect().y(), event.button());
|
||||
window->event(*localEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user