mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:37:35 +00:00
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
7 changed files with 35 additions and 0 deletions
|
@ -130,6 +130,7 @@ class ImageData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
class EventHandler;
|
||||||
class Frame;
|
class Frame;
|
||||||
class LayoutBlock;
|
class LayoutBlock;
|
||||||
class LayoutDocument;
|
class LayoutDocument;
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include <LibWeb/Page/Frame.h>
|
#include <LibWeb/Page/Frame.h>
|
||||||
#include <LibWeb/PageView.h>
|
#include <LibWeb/PageView.h>
|
||||||
|
|
||||||
|
//#define DEBUG_HIGHLIGHT_FOCUSED_FRAME
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
LayoutFrame::LayoutFrame(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
|
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.set_viewport_rect(old_viewport_rect);
|
||||||
context.painter().restore();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_frame.page().set_focused_frame({}, m_frame);
|
||||||
|
|
||||||
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
auto offset = compute_mouse_event_offset(position, *result.layout_node);
|
||||||
node->dispatch_event(UIEvents::MouseEvent::create("mousedown", offset.x(), offset.y()));
|
node->dispatch_event(UIEvents::MouseEvent::create("mousedown", offset.x(), offset.y()));
|
||||||
if (!layout_root())
|
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)
|
void Frame::set_document(DOM::Document* document)
|
||||||
{
|
{
|
||||||
if (m_document == document)
|
if (m_document == document)
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
~Frame();
|
~Frame();
|
||||||
|
|
||||||
bool is_main_frame() const { return this == &m_main_frame; }
|
bool is_main_frame() const { return this == &m_main_frame; }
|
||||||
|
bool is_focused_frame() const;
|
||||||
|
|
||||||
const DOM::Document* document() const { return m_document; }
|
const DOM::Document* document() const { return m_document; }
|
||||||
DOM::Document* document() { 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)
|
void Page::load(const URL& url)
|
||||||
{
|
{
|
||||||
main_frame().loader().load(url, FrameLoader::Type::Navigation);
|
main_frame().loader().load(url, FrameLoader::Type::Navigation);
|
||||||
|
|
|
@ -53,6 +53,11 @@ public:
|
||||||
Web::Frame& main_frame() { return *m_main_frame; }
|
Web::Frame& main_frame() { return *m_main_frame; }
|
||||||
const Web::Frame& main_frame() const { 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&);
|
void load(const URL&);
|
||||||
|
|
||||||
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
|
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
|
||||||
|
@ -67,6 +72,7 @@ private:
|
||||||
PageClient& m_client;
|
PageClient& m_client;
|
||||||
|
|
||||||
RefPtr<Frame> m_main_frame;
|
RefPtr<Frame> m_main_frame;
|
||||||
|
WeakPtr<Frame> m_focused_frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PageClient {
|
class PageClient {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue