diff options
-rw-r--r-- | Libraries/LibWeb/Forward.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutFrame.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/EventHandler.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/Frame.cpp | 5 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/Frame.h | 1 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/Page.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibWeb/Page/Page.h | 6 |
7 files changed, 35 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h index 3be40219b7..0474900063 100644 --- a/Libraries/LibWeb/Forward.h +++ b/Libraries/LibWeb/Forward.h @@ -130,6 +130,7 @@ class ImageData; } namespace Web { +class EventHandler; class Frame; class LayoutBlock; class LayoutDocument; diff --git a/Libraries/LibWeb/Layout/LayoutFrame.cpp b/Libraries/LibWeb/Layout/LayoutFrame.cpp index 88255d88e2..a7392dd6b4 100644 --- a/Libraries/LibWeb/Layout/LayoutFrame.cpp +++ b/Libraries/LibWeb/Layout/LayoutFrame.cpp @@ -35,6 +35,8 @@ #include <LibWeb/Page/Frame.h> #include <LibWeb/PageView.h> +//#define DEBUG_HIGHLIGHT_FOCUSED_FRAME + namespace Web { LayoutFrame::LayoutFrame(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style) @@ -82,6 +84,12 @@ void LayoutFrame::paint(PaintContext& context, PaintPhase phase) context.set_viewport_rect(old_viewport_rect); context.painter().restore(); + +#ifdef DEBUG_HIGHLIGHT_FOCUSED_FRAME + if (node().hosted_frame()->is_focused_frame()) { + context.painter().draw_rect(absolute_rect().to<int>(), Color::Cyan); + } +#endif } } diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp index 55769c7699..748ff0f31a 100644 --- a/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Libraries/LibWeb/Page/EventHandler.cpp @@ -119,6 +119,8 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt return false; } + m_frame.page().set_focused_frame({}, m_frame); + auto offset = compute_mouse_event_offset(position, *result.layout_node); node->dispatch_event(UIEvents::MouseEvent::create("mousedown", offset.x(), offset.y())); if (!layout_root()) diff --git a/Libraries/LibWeb/Page/Frame.cpp b/Libraries/LibWeb/Page/Frame.cpp index 6db661242c..f6726476ab 100644 --- a/Libraries/LibWeb/Page/Frame.cpp +++ b/Libraries/LibWeb/Page/Frame.cpp @@ -68,6 +68,11 @@ void Frame::setup() }); } +bool Frame::is_focused_frame() const +{ + return this == &page().focused_frame(); +} + void Frame::set_document(DOM::Document* document) { if (m_document == document) diff --git a/Libraries/LibWeb/Page/Frame.h b/Libraries/LibWeb/Page/Frame.h index 4be5139ee1..9f790e2bf2 100644 --- a/Libraries/LibWeb/Page/Frame.h +++ b/Libraries/LibWeb/Page/Frame.h @@ -48,6 +48,7 @@ public: ~Frame(); bool is_main_frame() const { return this == &m_main_frame; } + bool is_focused_frame() const; const DOM::Document* document() const { return m_document; } DOM::Document* document() { return m_document; } diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp index a9a1bfccbe..9718d0345e 100644 --- a/Libraries/LibWeb/Page/Page.cpp +++ b/Libraries/LibWeb/Page/Page.cpp @@ -40,6 +40,18 @@ Page::~Page() { } +Frame& Page::focused_frame() +{ + if (m_focused_frame) + return *m_focused_frame; + return main_frame(); +} + +void Page::set_focused_frame(Badge<EventHandler>, Frame& frame) +{ + m_focused_frame = frame.make_weak_ptr(); +} + void Page::load(const URL& url) { main_frame().loader().load(url, FrameLoader::Type::Navigation); diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 7becdef055..b686b943c4 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -53,6 +53,11 @@ public: Web::Frame& main_frame() { return *m_main_frame; } const Web::Frame& main_frame() const { return *m_main_frame; } + Web::Frame& focused_frame(); + const Web::Frame& focused_frame() const { return const_cast<Page*>(this)->focused_frame(); } + + void set_focused_frame(Badge<EventHandler>, Frame&); + void load(const URL&); bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers); @@ -67,6 +72,7 @@ private: PageClient& m_client; RefPtr<Frame> m_main_frame; + WeakPtr<Frame> m_focused_frame; }; class PageClient { |