HTMLElement.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/StringBuilder.h>
  7. #include <LibWeb/ARIA/Roles.h>
  8. #include <LibWeb/Bindings/ExceptionOrUtils.h>
  9. #include <LibWeb/DOM/Document.h>
  10. #include <LibWeb/DOM/IDLEventListener.h>
  11. #include <LibWeb/DOM/ShadowRoot.h>
  12. #include <LibWeb/HTML/BrowsingContext.h>
  13. #include <LibWeb/HTML/DOMStringMap.h>
  14. #include <LibWeb/HTML/EventHandler.h>
  15. #include <LibWeb/HTML/Focus.h>
  16. #include <LibWeb/HTML/HTMLAnchorElement.h>
  17. #include <LibWeb/HTML/HTMLAreaElement.h>
  18. #include <LibWeb/HTML/HTMLBaseElement.h>
  19. #include <LibWeb/HTML/HTMLBodyElement.h>
  20. #include <LibWeb/HTML/HTMLElement.h>
  21. #include <LibWeb/HTML/NavigableContainer.h>
  22. #include <LibWeb/HTML/VisibilityState.h>
  23. #include <LibWeb/HTML/Window.h>
  24. #include <LibWeb/Infra/CharacterTypes.h>
  25. #include <LibWeb/Infra/Strings.h>
  26. #include <LibWeb/Layout/Box.h>
  27. #include <LibWeb/Layout/BreakNode.h>
  28. #include <LibWeb/Layout/TextNode.h>
  29. #include <LibWeb/Painting/PaintableBox.h>
  30. #include <LibWeb/UIEvents/EventNames.h>
  31. #include <LibWeb/UIEvents/FocusEvent.h>
  32. #include <LibWeb/UIEvents/MouseEvent.h>
  33. #include <LibWeb/WebIDL/DOMException.h>
  34. #include <LibWeb/WebIDL/ExceptionOr.h>
  35. namespace Web::HTML {
  36. JS_DEFINE_ALLOCATOR(HTMLElement);
  37. HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  38. : Element(document, move(qualified_name))
  39. {
  40. }
  41. HTMLElement::~HTMLElement() = default;
  42. void HTMLElement::initialize(JS::Realm& realm)
  43. {
  44. Base::initialize(realm);
  45. WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLElement);
  46. m_dataset = DOMStringMap::create(*this);
  47. }
  48. void HTMLElement::visit_edges(Cell::Visitor& visitor)
  49. {
  50. Base::visit_edges(visitor);
  51. visitor.visit(m_dataset);
  52. }
  53. // https://html.spec.whatwg.org/multipage/dom.html#dom-dir
  54. StringView HTMLElement::dir() const
  55. {
  56. // FIXME: This should probably be `Reflect` in the IDL.
  57. // The dir IDL attribute on an element must reflect the dir content attribute of that element, limited to only known values.
  58. auto dir = get_attribute_value(HTML::AttributeNames::dir);
  59. #define __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(keyword) \
  60. if (dir.equals_ignoring_ascii_case(#keyword##sv)) \
  61. return #keyword##sv;
  62. ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTES
  63. #undef __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE
  64. return {};
  65. }
  66. void HTMLElement::set_dir(String const& dir)
  67. {
  68. MUST(set_attribute(HTML::AttributeNames::dir, dir));
  69. }
  70. bool HTMLElement::is_editable() const
  71. {
  72. switch (m_content_editable_state) {
  73. case ContentEditableState::True:
  74. return true;
  75. case ContentEditableState::False:
  76. return false;
  77. case ContentEditableState::Inherit:
  78. return parent() && parent()->is_editable();
  79. default:
  80. VERIFY_NOT_REACHED();
  81. }
  82. }
  83. bool HTMLElement::is_focusable() const
  84. {
  85. return m_content_editable_state == ContentEditableState::True;
  86. }
  87. // https://html.spec.whatwg.org/multipage/interaction.html#dom-iscontenteditable
  88. bool HTMLElement::is_content_editable() const
  89. {
  90. // The isContentEditable IDL attribute, on getting, must return true if the element is either an editing host or
  91. // editable, and false otherwise.
  92. return is_editable();
  93. }
  94. StringView HTMLElement::content_editable() const
  95. {
  96. switch (m_content_editable_state) {
  97. case ContentEditableState::True:
  98. return "true"sv;
  99. case ContentEditableState::False:
  100. return "false"sv;
  101. case ContentEditableState::Inherit:
  102. return "inherit"sv;
  103. }
  104. VERIFY_NOT_REACHED();
  105. }
  106. // https://html.spec.whatwg.org/multipage/interaction.html#contenteditable
  107. WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(StringView content_editable)
  108. {
  109. if (content_editable.equals_ignoring_ascii_case("inherit"sv)) {
  110. remove_attribute(HTML::AttributeNames::contenteditable);
  111. return {};
  112. }
  113. if (content_editable.equals_ignoring_ascii_case("true"sv)) {
  114. MUST(set_attribute(HTML::AttributeNames::contenteditable, "true"_string));
  115. return {};
  116. }
  117. if (content_editable.equals_ignoring_ascii_case("false"sv)) {
  118. MUST(set_attribute(HTML::AttributeNames::contenteditable, "false"_string));
  119. return {};
  120. }
  121. return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'"_fly_string);
  122. }
  123. void HTMLElement::set_inner_text(StringView text)
  124. {
  125. remove_all_children();
  126. MUST(append_child(document().create_text_node(MUST(String::from_utf8(text)))));
  127. set_needs_style_update(true);
  128. }
  129. String HTMLElement::inner_text()
  130. {
  131. StringBuilder builder;
  132. // innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree.
  133. document().update_layout();
  134. if (!layout_node())
  135. return text_content().value_or(String {});
  136. Function<void(Layout::Node const&)> recurse = [&](auto& node) {
  137. for (auto* child = node.first_child(); child; child = child->next_sibling()) {
  138. if (is<Layout::TextNode>(child))
  139. builder.append(verify_cast<Layout::TextNode>(*child).text_for_rendering());
  140. if (is<Layout::BreakNode>(child))
  141. builder.append('\n');
  142. recurse(*child);
  143. }
  144. };
  145. recurse(*layout_node());
  146. return MUST(builder.to_string());
  147. }
  148. // https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetparent
  149. JS::GCPtr<DOM::Element> HTMLElement::offset_parent() const
  150. {
  151. const_cast<DOM::Document&>(document()).update_layout();
  152. // 1. If any of the following holds true return null and terminate this algorithm:
  153. // - The element does not have an associated CSS layout box.
  154. // - The element is the root element.
  155. // - The element is the HTML body element.
  156. // - The element’s computed value of the position property is fixed.
  157. if (!layout_node())
  158. return nullptr;
  159. if (is_document_element())
  160. return nullptr;
  161. if (is<HTML::HTMLBodyElement>(*this))
  162. return nullptr;
  163. if (layout_node()->is_fixed_position())
  164. return nullptr;
  165. // 2. Return the nearest ancestor element of the element for which at least one of the following is true
  166. // and terminate this algorithm if such an ancestor is found:
  167. // - The computed value of the position property is not static.
  168. // - It is the HTML body element.
  169. // - The computed value of the position property of the element is static
  170. // and the ancestor is one of the following HTML elements: td, th, or table.
  171. for (auto* ancestor = parent_element(); ancestor; ancestor = ancestor->parent_element()) {
  172. if (!ancestor->layout_node())
  173. continue;
  174. if (ancestor->layout_node()->is_positioned())
  175. return const_cast<Element*>(ancestor);
  176. if (is<HTML::HTMLBodyElement>(*ancestor))
  177. return const_cast<Element*>(ancestor);
  178. if (!ancestor->layout_node()->is_positioned() && ancestor->local_name().is_one_of(HTML::TagNames::td, HTML::TagNames::th, HTML::TagNames::table))
  179. return const_cast<Element*>(ancestor);
  180. }
  181. // 3. Return null.
  182. return nullptr;
  183. }
  184. // https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsettop
  185. int HTMLElement::offset_top() const
  186. {
  187. // 1. If the element is the HTML body element or does not have any associated CSS layout box
  188. // return zero and terminate this algorithm.
  189. if (is<HTML::HTMLBodyElement>(*this))
  190. return 0;
  191. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  192. const_cast<DOM::Document&>(document()).update_layout();
  193. if (!layout_node())
  194. return 0;
  195. // 2. If the offsetParent of the element is null
  196. // return the y-coordinate of the top border edge of the first CSS layout box associated with the element,
  197. // relative to the initial containing block origin,
  198. // ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
  199. auto offset_parent = this->offset_parent();
  200. if (!offset_parent || !offset_parent->layout_node()) {
  201. auto position = paintable()->box_type_agnostic_position();
  202. return position.y().to_int();
  203. }
  204. // 3. Return the result of subtracting the y-coordinate of the top padding edge
  205. // of the first box associated with the offsetParent of the element
  206. // from the y-coordinate of the top border edge of the first box associated with the element,
  207. // relative to the initial containing block origin,
  208. // ignoring any transforms that apply to the element and its ancestors.
  209. auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
  210. auto position = paintable()->box_type_agnostic_position();
  211. return position.y().to_int() - offset_parent_position.y().to_int();
  212. }
  213. // https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetleft
  214. int HTMLElement::offset_left() const
  215. {
  216. // 1. If the element is the HTML body element or does not have any associated CSS layout box return zero and terminate this algorithm.
  217. if (is<HTML::HTMLBodyElement>(*this))
  218. return 0;
  219. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  220. const_cast<DOM::Document&>(document()).update_layout();
  221. if (!layout_node())
  222. return 0;
  223. // 2. If the offsetParent of the element is null
  224. // return the x-coordinate of the left border edge of the first CSS layout box associated with the element,
  225. // relative to the initial containing block origin,
  226. // ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
  227. auto offset_parent = this->offset_parent();
  228. if (!offset_parent || !offset_parent->layout_node()) {
  229. auto position = paintable()->box_type_agnostic_position();
  230. return position.x().to_int();
  231. }
  232. // 3. Return the result of subtracting the x-coordinate of the left padding edge
  233. // of the first CSS layout box associated with the offsetParent of the element
  234. // from the x-coordinate of the left border edge of the first CSS layout box associated with the element,
  235. // relative to the initial containing block origin,
  236. // ignoring any transforms that apply to the element and its ancestors.
  237. auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
  238. auto position = paintable()->box_type_agnostic_position();
  239. return position.x().to_int() - offset_parent_position.x().to_int();
  240. }
  241. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
  242. int HTMLElement::offset_width() const
  243. {
  244. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  245. const_cast<DOM::Document&>(document()).update_layout();
  246. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  247. if (!paintable_box())
  248. return 0;
  249. // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  250. // ignoring any transforms that apply to the element and its ancestors.
  251. // FIXME: Account for inline boxes.
  252. return paintable_box()->border_box_width().to_int();
  253. }
  254. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
  255. int HTMLElement::offset_height() const
  256. {
  257. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  258. const_cast<DOM::Document&>(document()).update_layout();
  259. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  260. if (!paintable_box())
  261. return 0;
  262. // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  263. // ignoring any transforms that apply to the element and its ancestors.
  264. // FIXME: Account for inline boxes.
  265. return paintable_box()->border_box_height().to_int();
  266. }
  267. // https://html.spec.whatwg.org/multipage/links.html#cannot-navigate
  268. bool HTMLElement::cannot_navigate() const
  269. {
  270. // An element element cannot navigate if one of the following is true:
  271. // - element's node document is not fully active
  272. if (!document().is_fully_active())
  273. return true;
  274. // - element is not an a element and is not connected.
  275. return !is<HTML::HTMLAnchorElement>(this) && !is_connected();
  276. }
  277. void HTMLElement::attribute_changed(FlyString const& name, Optional<String> const& value)
  278. {
  279. Element::attribute_changed(name, value);
  280. if (name == HTML::AttributeNames::contenteditable) {
  281. if (!value.has_value()) {
  282. m_content_editable_state = ContentEditableState::Inherit;
  283. } else {
  284. if (value->is_empty() || value->equals_ignoring_ascii_case("true"sv)) {
  285. // "true", an empty string or a missing value map to the "true" state.
  286. m_content_editable_state = ContentEditableState::True;
  287. } else if (value->equals_ignoring_ascii_case("false"sv)) {
  288. // "false" maps to the "false" state.
  289. m_content_editable_state = ContentEditableState::False;
  290. } else {
  291. // Having no such attribute or an invalid value maps to the "inherit" state.
  292. m_content_editable_state = ContentEditableState::Inherit;
  293. }
  294. }
  295. }
  296. // 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return.
  297. // FIXME: Add the namespace part once we support attribute namespaces.
  298. #undef __ENUMERATE
  299. #define __ENUMERATE(attribute_name, event_name) \
  300. if (name == HTML::AttributeNames::attribute_name) { \
  301. element_event_handler_attribute_changed(event_name, value); \
  302. }
  303. ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
  304. #undef __ENUMERATE
  305. }
  306. // https://html.spec.whatwg.org/multipage/interaction.html#dom-focus
  307. void HTMLElement::focus()
  308. {
  309. // 1. If the element is marked as locked for focus, then return.
  310. if (m_locked_for_focus)
  311. return;
  312. // 2. Mark the element as locked for focus.
  313. m_locked_for_focus = true;
  314. // 3. Run the focusing steps for the element.
  315. run_focusing_steps(this);
  316. // FIXME: 4. If the value of the preventScroll dictionary member of options is false,
  317. // then scroll the element into view with scroll behavior "auto",
  318. // block flow direction position set to an implementation-defined value,
  319. // and inline base direction position set to an implementation-defined value.
  320. // 5. Unmark the element as locked for focus.
  321. m_locked_for_focus = false;
  322. }
  323. // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event
  324. bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted)
  325. {
  326. // 1. Let event be the result of creating an event using PointerEvent.
  327. // 2. Initialize event's type attribute to e.
  328. // FIXME: Actually create a PointerEvent!
  329. auto event = UIEvents::MouseEvent::create(realm(), type);
  330. // 3. Initialize event's bubbles and cancelable attributes to true.
  331. event->set_bubbles(true);
  332. event->set_cancelable(true);
  333. // 4. Set event's composed flag.
  334. event->set_composed(true);
  335. // 5. If the not trusted flag is set, initialize event's isTrusted attribute to false.
  336. if (not_trusted) {
  337. event->set_is_trusted(false);
  338. }
  339. // FIXME: 6. Initialize event's ctrlKey, shiftKey, altKey, and metaKey attributes according to the current state
  340. // of the key input device, if any (false for any keys that are not available).
  341. // FIXME: 7. Initialize event's view attribute to target's node document's Window object, if any, and null otherwise.
  342. // FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device.
  343. // 9. Return the result of dispatching event at target.
  344. return target.dispatch_event(event);
  345. }
  346. // https://html.spec.whatwg.org/multipage/interaction.html#dom-click
  347. void HTMLElement::click()
  348. {
  349. // FIXME: 1. If this element is a form control that is disabled, then return.
  350. // 2. If this element's click in progress flag is set, then return.
  351. if (m_click_in_progress)
  352. return;
  353. // 3. Set this element's click in progress flag.
  354. m_click_in_progress = true;
  355. // FIXME: 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
  356. fire_a_synthetic_pointer_event(HTML::EventNames::click, *this, true);
  357. // 5. Unset this element's click in progress flag.
  358. m_click_in_progress = false;
  359. }
  360. // https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
  361. void HTMLElement::blur()
  362. {
  363. // The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called.
  364. run_unfocusing_steps(this);
  365. // User agents may selectively or uniformly ignore calls to this method for usability reasons.
  366. }
  367. Optional<ARIA::Role> HTMLElement::default_role() const
  368. {
  369. // https://www.w3.org/TR/html-aria/#el-article
  370. if (local_name() == TagNames::article)
  371. return ARIA::Role::article;
  372. // https://www.w3.org/TR/html-aria/#el-aside
  373. if (local_name() == TagNames::aside)
  374. return ARIA::Role::complementary;
  375. // https://www.w3.org/TR/html-aria/#el-b
  376. if (local_name() == TagNames::b)
  377. return ARIA::Role::generic;
  378. // https://www.w3.org/TR/html-aria/#el-bdi
  379. if (local_name() == TagNames::bdi)
  380. return ARIA::Role::generic;
  381. // https://www.w3.org/TR/html-aria/#el-bdo
  382. if (local_name() == TagNames::bdo)
  383. return ARIA::Role::generic;
  384. // https://www.w3.org/TR/html-aria/#el-code
  385. if (local_name() == TagNames::code)
  386. return ARIA::Role::code;
  387. // https://www.w3.org/TR/html-aria/#el-dfn
  388. if (local_name() == TagNames::dfn)
  389. return ARIA::Role::term;
  390. // https://www.w3.org/TR/html-aria/#el-em
  391. if (local_name() == TagNames::em)
  392. return ARIA::Role::emphasis;
  393. // https://www.w3.org/TR/html-aria/#el-figure
  394. if (local_name() == TagNames::figure)
  395. return ARIA::Role::figure;
  396. // https://www.w3.org/TR/html-aria/#el-footer
  397. if (local_name() == TagNames::footer) {
  398. // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=contentinfo
  399. // Otherwise, role=generic
  400. return ARIA::Role::generic;
  401. }
  402. // https://www.w3.org/TR/html-aria/#el-header
  403. if (local_name() == TagNames::header) {
  404. // TODO: If not a descendant of an article, aside, main, nav or section element, or an element with role=article, complementary, main, navigation or region then role=banner
  405. // Otherwise, role=generic
  406. return ARIA::Role::generic;
  407. }
  408. // https://www.w3.org/TR/html-aria/#el-hgroup
  409. if (local_name() == TagNames::hgroup)
  410. return ARIA::Role::generic;
  411. // https://www.w3.org/TR/html-aria/#el-i
  412. if (local_name() == TagNames::i)
  413. return ARIA::Role::generic;
  414. // https://www.w3.org/TR/html-aria/#el-main
  415. if (local_name() == TagNames::main)
  416. return ARIA::Role::main;
  417. // https://www.w3.org/TR/html-aria/#el-nav
  418. if (local_name() == TagNames::nav)
  419. return ARIA::Role::navigation;
  420. // https://www.w3.org/TR/html-aria/#el-samp
  421. if (local_name() == TagNames::samp)
  422. return ARIA::Role::generic;
  423. // https://www.w3.org/TR/html-aria/#el-section
  424. if (local_name() == TagNames::section) {
  425. // TODO: role=region if the section element has an accessible name
  426. // Otherwise, no corresponding role
  427. return ARIA::Role::region;
  428. }
  429. // https://www.w3.org/TR/html-aria/#el-small
  430. if (local_name() == TagNames::small)
  431. return ARIA::Role::generic;
  432. // https://www.w3.org/TR/html-aria/#el-strong
  433. if (local_name() == TagNames::strong)
  434. return ARIA::Role::strong;
  435. // https://www.w3.org/TR/html-aria/#el-sub
  436. if (local_name() == TagNames::sub)
  437. return ARIA::Role::subscript;
  438. // https://www.w3.org/TR/html-aria/#el-summary
  439. if (local_name() == TagNames::summary)
  440. return ARIA::Role::button;
  441. // https://www.w3.org/TR/html-aria/#el-sup
  442. if (local_name() == TagNames::sup)
  443. return ARIA::Role::superscript;
  444. // https://www.w3.org/TR/html-aria/#el-u
  445. if (local_name() == TagNames::u)
  446. return ARIA::Role::generic;
  447. return {};
  448. }
  449. // https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
  450. String HTMLElement::get_an_elements_target() const
  451. {
  452. // To get an element's target, given an a, area, or form element element, run these steps:
  453. // 1. If element has a target attribute, then return that attribute's value.
  454. auto maybe_target = attribute(AttributeNames::target);
  455. if (maybe_target.has_value())
  456. return maybe_target.release_value();
  457. // FIXME: 2. If element's node document contains a base element with a
  458. // target attribute, then return the value of the target attribute of the
  459. // first such base element.
  460. // 3. Return the empty string.
  461. return String {};
  462. }
  463. // https://html.spec.whatwg.org/multipage/links.html#get-an-element's-noopener
  464. TokenizedFeature::NoOpener HTMLElement::get_an_elements_noopener(StringView target) const
  465. {
  466. // To get an element's noopener, given an a, area, or form element element and a string target:
  467. auto rel = MUST(get_attribute_value(HTML::AttributeNames::rel).to_lowercase());
  468. auto link_types = rel.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
  469. // 1. If element's link types include the noopener or noreferrer keyword, then return true.
  470. if (link_types.contains_slow("noopener"sv) || link_types.contains_slow("noreferrer"sv))
  471. return TokenizedFeature::NoOpener::Yes;
  472. // 2. If element's link types do not include the opener keyword and
  473. // target is an ASCII case-insensitive match for "_blank", then return true.
  474. if (!link_types.contains_slow("opener"sv) && Infra::is_ascii_case_insensitive_match(target, "_blank"sv))
  475. return TokenizedFeature::NoOpener::Yes;
  476. // 3. Return false.
  477. return TokenizedFeature::NoOpener::No;
  478. }
  479. void HTMLElement::did_receive_focus()
  480. {
  481. if (m_content_editable_state != ContentEditableState::True)
  482. return;
  483. auto* browsing_context = document().browsing_context();
  484. if (!browsing_context)
  485. return;
  486. browsing_context->set_cursor_position(DOM::Position::create(realm(), *this, 0));
  487. }
  488. }