Serenity Operating System
at master 91 lines 2.5 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <LibGfx/Rect.h> 10#include <LibWeb/Forward.h> 11#include <LibWeb/PixelUnits.h> 12 13namespace Web::Layout { 14 15class LineBoxFragment { 16 friend class LineBox; 17 18public: 19 enum class Type { 20 Normal, 21 Leading, 22 Trailing, 23 }; 24 25 LineBoxFragment(Node const& layout_node, int start, int length, CSSPixelPoint offset, CSSPixelSize size, CSSPixels border_box_top, CSSPixels border_box_bottom, Type type) 26 : m_layout_node(layout_node) 27 , m_start(start) 28 , m_length(length) 29 , m_offset(offset) 30 , m_size(size) 31 , m_border_box_top(border_box_top) 32 , m_border_box_bottom(border_box_bottom) 33 , m_type(type) 34 { 35 } 36 37 Node const& layout_node() const { return m_layout_node; } 38 int start() const { return m_start; } 39 int length() const { return m_length; } 40 CSSPixelRect const absolute_rect() const; 41 Type type() const { return m_type; } 42 43 CSSPixelPoint offset() const 44 { 45 return m_offset; 46 } 47 void set_offset(CSSPixelPoint offset) { m_offset = offset; } 48 49 // The baseline of a fragment is the number of pixels from the top to the text baseline. 50 void set_baseline(CSSPixels y) { m_baseline = y; } 51 CSSPixels baseline() const { return m_baseline; } 52 53 CSSPixelSize size() const 54 { 55 return m_size; 56 } 57 void set_width(CSSPixels width) { m_size.set_width(width); } 58 void set_height(CSSPixels height) { m_size.set_height(height); } 59 CSSPixels width() const { return m_size.width(); } 60 CSSPixels height() const { return m_size.height(); } 61 62 CSSPixels border_box_height() const 63 { 64 return m_border_box_top + height() + m_border_box_bottom; 65 } 66 CSSPixels border_box_top() const { return m_border_box_top; } 67 CSSPixels border_box_bottom() const { return m_border_box_bottom; } 68 69 CSSPixels absolute_x() const { return absolute_rect().x(); } 70 71 bool ends_in_whitespace() const; 72 bool is_justifiable_whitespace() const; 73 StringView text() const; 74 75 int text_index_at(CSSPixels x) const; 76 77 CSSPixelRect selection_rect(Gfx::Font const&) const; 78 79private: 80 Node const& m_layout_node; 81 int m_start { 0 }; 82 int m_length { 0 }; 83 CSSPixelPoint m_offset; 84 CSSPixelSize m_size; 85 CSSPixels m_border_box_top { 0 }; 86 CSSPixels m_border_box_bottom { 0 }; 87 CSSPixels m_baseline { 0 }; 88 Type m_type { Type::Normal }; 89}; 90 91}