LibWeb: Add "focused frame" concept, one focused Frame per Page
Focus currently only moves when doing a mousedown in a frame.
This commit is contained in:
parent
d1d9545875
commit
6b4a7d1ee3
Notes:
sideshowbarker
2024-07-19 03:39:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6b4a7d1ee34
7 changed files with 35 additions and 0 deletions
Libraries/LibWeb
|
@ -130,6 +130,7 @@ class ImageData;
|
|||
}
|
||||
|
||||
namespace Web {
|
||||
class EventHandler;
|
||||
class Frame;
|
||||
class LayoutBlock;
|
||||
class LayoutDocument;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue