mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibHTML: Build some foundation for text selection
Add LayoutPosition and LayoutRange classes. The layout tree root node now has a selection() LayoutRange. It's essentially a start and end LayoutPosition. A LayoutPosition is a LayoutNode, and an optional index into that node. The index is only relevant for text nodes, where it's the character index into the rendered text. HtmlView now updates the selection start/end of the LayoutDocument when clicking and dragging with the left mouse button. We don't paint the selection yet, and there's no way to copy what's selected. It only exists as a LayoutRange.
This commit is contained in:
parent
2755184e11
commit
f3f0b08d43
8 changed files with 119 additions and 2 deletions
56
Libraries/LibHTML/Layout/LayoutPosition.h
Normal file
56
Libraries/LibHTML/Layout/LayoutPosition.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/RefPtr.h>
|
||||
|
||||
class LayoutNode;
|
||||
|
||||
struct LayoutPosition {
|
||||
bool operator>=(const LayoutPosition& other) const
|
||||
{
|
||||
if (layout_node == other.layout_node)
|
||||
return index_in_node >= other.index_in_node;
|
||||
|
||||
// FIXME: Implement.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool operator<=(const LayoutPosition& other) const
|
||||
{
|
||||
if (layout_node == other.layout_node)
|
||||
return index_in_node <= other.index_in_node;
|
||||
|
||||
// FIXME: Implement.
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> layout_node;
|
||||
int index_in_node { 0 };
|
||||
};
|
||||
|
||||
class LayoutRange {
|
||||
public:
|
||||
LayoutRange() {}
|
||||
LayoutRange(const LayoutPosition& start, const LayoutPosition& end)
|
||||
: m_start(start)
|
||||
, m_end(end)
|
||||
{
|
||||
}
|
||||
|
||||
bool is_valid() const { return m_start.layout_node && m_end.layout_node; }
|
||||
|
||||
void set(const LayoutPosition& start, const LayoutPosition& end)
|
||||
{
|
||||
m_start = start;
|
||||
m_end = end;
|
||||
}
|
||||
|
||||
void set_start(const LayoutPosition& start) { m_start = start; }
|
||||
void set_end(const LayoutPosition& end) { m_end = end; }
|
||||
|
||||
const LayoutPosition& start() const { return m_start; }
|
||||
const LayoutPosition& end() const { return m_end; }
|
||||
|
||||
private:
|
||||
LayoutPosition m_start;
|
||||
LayoutPosition m_end;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue