Algorithms.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2024, Jelle Raaijmakers <jelle@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibWeb/DOM/Node.h>
  9. namespace Web::Editing {
  10. // https://w3c.github.io/editing/docs/execCommand/#record-the-values
  11. struct RecordedNodeValue {
  12. GC::Ref<DOM::Node> node;
  13. FlyString const& command;
  14. Optional<String> specified_command_value;
  15. };
  16. // Below algorithms are specified here:
  17. // https://w3c.github.io/editing/docs/execCommand/#assorted-common-algorithms
  18. GC::Ref<DOM::Range> block_extend_a_range(DOM::Range&);
  19. String canonical_space_sequence(u32 length, bool non_breaking_start, bool non_breaking_end);
  20. void canonicalize_whitespace(GC::Ref<DOM::Node>, u32 offset, bool fix_collapsed_space = true);
  21. void delete_the_selection(Selection::Selection const&);
  22. GC::Ptr<DOM::Node> editing_host_of_node(GC::Ref<DOM::Node>);
  23. void fix_disallowed_ancestors_of_node(GC::Ref<DOM::Node>);
  24. bool follows_a_line_break(GC::Ref<DOM::Node>);
  25. bool is_allowed_child_of_node(Variant<GC::Ref<DOM::Node>, FlyString> child, Variant<GC::Ref<DOM::Node>, FlyString> parent);
  26. bool is_block_boundary_point(GC::Ref<DOM::Node>, u32 offset);
  27. bool is_block_end_point(GC::Ref<DOM::Node>, u32 offset);
  28. bool is_block_node(GC::Ref<DOM::Node>);
  29. bool is_block_start_point(GC::Ref<DOM::Node>, u32 offset);
  30. bool is_collapsed_whitespace_node(GC::Ref<DOM::Node>);
  31. bool is_editing_host(GC::Ref<DOM::Node>);
  32. bool is_element_with_inline_contents(GC::Ref<DOM::Node>);
  33. bool is_extraneous_line_break(GC::Ref<DOM::Node>);
  34. bool is_in_same_editing_host(GC::Ref<DOM::Node>, GC::Ref<DOM::Node>);
  35. bool is_inline_node(GC::Ref<DOM::Node>);
  36. bool is_invisible_node(GC::Ref<DOM::Node>);
  37. bool is_name_of_an_element_with_inline_contents(FlyString const&);
  38. bool is_non_list_single_line_container(GC::Ref<DOM::Node>);
  39. bool is_prohibited_paragraph_child(GC::Ref<DOM::Node>);
  40. bool is_prohibited_paragraph_child_name(FlyString const&);
  41. bool is_single_line_container(GC::Ref<DOM::Node>);
  42. bool is_visible_node(GC::Ref<DOM::Node>);
  43. bool is_whitespace_node(GC::Ref<DOM::Node>);
  44. void move_node_preserving_ranges(GC::Ref<DOM::Node>, GC::Ref<DOM::Node> new_parent, u32 new_index);
  45. void normalize_sublists_in_node(GC::Ref<DOM::Element>);
  46. bool precedes_a_line_break(GC::Ref<DOM::Node>);
  47. Vector<RecordedNodeValue> record_the_values_of_nodes(Vector<GC::Ref<DOM::Node>> const&);
  48. void remove_extraneous_line_breaks_at_the_end_of_node(GC::Ref<DOM::Node>);
  49. void remove_extraneous_line_breaks_before_node(GC::Ref<DOM::Node>);
  50. void remove_extraneous_line_breaks_from_a_node(GC::Ref<DOM::Node>);
  51. void remove_node_preserving_its_descendants(GC::Ref<DOM::Node>);
  52. void restore_the_values_of_nodes(Vector<RecordedNodeValue> const&);
  53. GC::Ref<DOM::Element> set_the_tag_name(GC::Ref<DOM::Element>, FlyString const&);
  54. Optional<String> specified_command_value(GC::Ref<DOM::Element>, FlyString const& command);
  55. void split_the_parent_of_nodes(Vector<GC::Ref<DOM::Node>> const&);
  56. GC::Ptr<DOM::Node> wrap(Vector<GC::Ref<DOM::Node>>, Function<bool(GC::Ref<DOM::Node>)> sibling_criteria, Function<GC::Ptr<DOM::Node>()> new_parent_instructions);
  57. // Utility methods:
  58. bool is_heading(FlyString const&);
  59. }