@@ -65,9 +65,6 @@ size_t PaintableFragment::index_in_node_for_point(CSSPixelPoint position) const
6565
6666CSSPixelRect PaintableFragment::range_rect (Paintable::SelectionState selection_state, size_t start_offset_in_code_units, size_t end_offset_in_code_units) const
6767{
68- if (selection_state == Paintable::SelectionState::None)
69- return {};
70-
7168 if (selection_state == Paintable::SelectionState::Full)
7269 return absolute_rect ();
7370
@@ -77,16 +74,13 @@ CSSPixelRect PaintableFragment::range_rect(Paintable::SelectionState selection_s
7774 auto const & font = glyph_run () ? glyph_run ()->font () : layout_node ().first_available_font ();
7875 auto text = this ->text ();
7976
80- if (selection_state == Paintable::SelectionState::StartAndEnd) {
77+ if (first_is_one_of ( selection_state, Paintable::SelectionState::StartAndEnd, Paintable::SelectionState::None) ) {
8178 // we are in the start/end node (both the same)
8279 if (start_index > end_offset_in_code_units)
8380 return {};
8481 if (end_index < start_offset_in_code_units)
8582 return {};
8683
87- if (start_offset_in_code_units == end_offset_in_code_units)
88- return {};
89-
9084 auto selection_start_in_this_fragment = max (0 , start_offset_in_code_units - m_start_offset);
9185 auto selection_end_in_this_fragment = min (m_length_in_code_units, end_offset_in_code_units - m_start_offset);
9286 auto pixel_distance_to_first_selected_character = CSSPixels::nearest_value_for (font.width (text.substring_view (0 , selection_start_in_this_fragment)));
@@ -180,7 +174,11 @@ Gfx::Orientation PaintableFragment::orientation() const
180174
181175CSSPixelRect PaintableFragment::selection_rect () const
182176{
183- if (auto focused_area = paintable ().document ().focused_area (); is<HTML::FormAssociatedTextControlElement>(focused_area.ptr ())) {
177+ auto const selection_state = paintable ().selection_state ();
178+ if (selection_state == Paintable::SelectionState::None)
179+ return {};
180+
181+ if (auto const * focused_area = as_if<HTML::FormAssociatedTextControlElement>(paintable ().document ().focused_area ().ptr ())) {
184182 HTML::FormAssociatedTextControlElement const * text_control_element = nullptr ;
185183 if (auto const * input_element = as_if<HTML::HTMLInputElement>(*focused_area)) {
186184 text_control_element = input_element;
@@ -191,7 +189,7 @@ CSSPixelRect PaintableFragment::selection_rect() const
191189 }
192190 auto selection_start = text_control_element->selection_start ();
193191 auto selection_end = text_control_element->selection_end ();
194- return range_rect (paintable (). selection_state () , selection_start, selection_end);
192+ return range_rect (selection_state, selection_start, selection_end);
195193 }
196194
197195 auto selection = paintable ().document ().get_selection ();
@@ -201,7 +199,7 @@ CSSPixelRect PaintableFragment::selection_rect() const
201199 if (!range)
202200 return {};
203201
204- return range_rect (paintable (). selection_state () , range->start_offset (), range->end_offset ());
202+ return range_rect (selection_state, range->start_offset (), range->end_offset ());
205203}
206204
207205Utf16View PaintableFragment::text () const
0 commit comments