HTMLElement.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. set_prototype(&Bindings::ensure_web_prototype<Bindings::HTMLElementPrototype>(realm, "HTMLElement"_fly_string));
  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. VERIFY_NOT_REACHED();
  182. }
  183. // https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsettop
  184. int HTMLElement::offset_top() const
  185. {
  186. // 1. If the element is the HTML body element or does not have any associated CSS layout box
  187. // return zero and terminate this algorithm.
  188. if (is<HTML::HTMLBodyElement>(*this))
  189. return 0;
  190. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  191. const_cast<DOM::Document&>(document()).update_layout();
  192. if (!layout_node())
  193. return 0;
  194. // 2. If the offsetParent of the element is null
  195. // return the y-coordinate of the top border edge of the first CSS layout box associated with the element,
  196. // relative to the initial containing block origin,
  197. // ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
  198. auto offset_parent = this->offset_parent();
  199. if (!offset_parent || !offset_parent->layout_node()) {
  200. auto position = paintable()->box_type_agnostic_position();
  201. return position.y().to_int();
  202. }
  203. // 3. Return the result of subtracting the y-coordinate of the top padding edge
  204. // of the first box associated with the offsetParent of the element
  205. // from the y-coordinate of the top border edge of the first box associated with the element,
  206. // relative to the initial containing block origin,
  207. // ignoring any transforms that apply to the element and its ancestors.
  208. auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
  209. auto position = paintable()->box_type_agnostic_position();
  210. return position.y().to_int() - offset_parent_position.y().to_int();
  211. }
  212. // https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetleft
  213. int HTMLElement::offset_left() const
  214. {
  215. // 1. If the element is the HTML body element or does not have any associated CSS layout box return zero and terminate this algorithm.
  216. if (is<HTML::HTMLBodyElement>(*this))
  217. return 0;
  218. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  219. const_cast<DOM::Document&>(document()).update_layout();
  220. if (!layout_node())
  221. return 0;
  222. // 2. If the offsetParent of the element is null
  223. // return the x-coordinate of the left border edge of the first CSS layout box associated with the element,
  224. // relative to the initial containing block origin,
  225. // ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
  226. auto offset_parent = this->offset_parent();
  227. if (!offset_parent || !offset_parent->layout_node()) {
  228. auto position = paintable()->box_type_agnostic_position();
  229. return position.x().to_int();
  230. }
  231. // 3. Return the result of subtracting the x-coordinate of the left padding edge
  232. // of the first CSS layout box associated with the offsetParent of the element
  233. // from the x-coordinate of the left border edge of the first CSS layout box associated with the element,
  234. // relative to the initial containing block origin,
  235. // ignoring any transforms that apply to the element and its ancestors.
  236. auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
  237. auto position = paintable()->box_type_agnostic_position();
  238. return position.x().to_int() - offset_parent_position.x().to_int();
  239. }
  240. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
  241. int HTMLElement::offset_width() const
  242. {
  243. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  244. const_cast<DOM::Document&>(document()).update_layout();
  245. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  246. if (!paintable_box())
  247. return 0;
  248. // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  249. // ignoring any transforms that apply to the element and its ancestors.
  250. // FIXME: Account for inline boxes.
  251. return paintable_box()->border_box_width().to_int();
  252. }
  253. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
  254. int HTMLElement::offset_height() const
  255. {
  256. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  257. const_cast<DOM::Document&>(document()).update_layout();
  258. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  259. if (!paintable_box())
  260. return 0;
  261. // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  262. // ignoring any transforms that apply to the element and its ancestors.
  263. // FIXME: Account for inline boxes.
  264. return paintable_box()->border_box_height().to_int();
  265. }
  266. // https://html.spec.whatwg.org/multipage/links.html#cannot-navigate
  267. bool HTMLElement::cannot_navigate() const
  268. {
  269. // An element element cannot navigate if one of the following is true:
  270. // - element's node document is not fully active
  271. if (!document().is_fully_active())
  272. return true;
  273. // - element is not an a element and is not connected.
  274. return !is<HTML::HTMLAnchorElement>(this) && !is_connected();
  275. }
  276. void HTMLElement::attribute_changed(FlyString const& name, Optional<String> const& value)
  277. {
  278. Element::attribute_changed(name, value);
  279. if (name == HTML::AttributeNames::contenteditable) {
  280. if (!value.has_value()) {
  281. m_content_editable_state = ContentEditableState::Inherit;
  282. } else {
  283. if (value->is_empty() || value->equals_ignoring_ascii_case("true"sv)) {
  284. // "true", an empty string or a missing value map to the "true" state.
  285. m_content_editable_state = ContentEditableState::True;
  286. } else if (value->equals_ignoring_ascii_case("false"sv)) {
  287. // "false" maps to the "false" state.
  288. m_content_editable_state = ContentEditableState::False;
  289. } else {
  290. // Having no such attribute or an invalid value maps to the "inherit" state.
  291. m_content_editable_state = ContentEditableState::Inherit;
  292. }
  293. }
  294. }
  295. // 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return.
  296. // FIXME: Add the namespace part once we support attribute namespaces.
  297. #undef __ENUMERATE
  298. #define __ENUMERATE(attribute_name, event_name) \
  299. if (name == HTML::AttributeNames::attribute_name) { \
  300. element_event_handler_attribute_changed(event_name, value); \
  301. }
  302. ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
  303. #undef __ENUMERATE
  304. }
  305. // https://html.spec.whatwg.org/multipage/interaction.html#dom-focus
  306. void HTMLElement::focus()
  307. {
  308. // 1. If the element is marked as locked for focus, then return.
  309. if (m_locked_for_focus)
  310. return;
  311. // 2. Mark the element as locked for focus.
  312. m_locked_for_focus = true;
  313. // 3. Run the focusing steps for the element.
  314. run_focusing_steps(this);
  315. // FIXME: 4. If the value of the preventScroll dictionary member of options is false,
  316. // then scroll the element into view with scroll behavior "auto",
  317. // block flow direction position set to an implementation-defined value,
  318. // and inline base direction position set to an implementation-defined value.
  319. // 5. Unmark the element as locked for focus.
  320. m_locked_for_focus = false;
  321. }
  322. // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event
  323. bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted)
  324. {
  325. // 1. Let event be the result of creating an event using PointerEvent.
  326. // 2. Initialize event's type attribute to e.
  327. // FIXME: Actually create a PointerEvent!
  328. auto event = UIEvents::MouseEvent::create(realm(), type);
  329. // 3. Initialize event's bubbles and cancelable attributes to true.
  330. event->set_bubbles(true);
  331. event->set_cancelable(true);
  332. // 4. Set event's composed flag.
  333. event->set_composed(true);
  334. // 5. If the not trusted flag is set, initialize event's isTrusted attribute to false.
  335. if (not_trusted) {
  336. event->set_is_trusted(false);
  337. }
  338. // FIXME: 6. Initialize event's ctrlKey, shiftKey, altKey, and metaKey attributes according to the current state
  339. // of the key input device, if any (false for any keys that are not available).
  340. // FIXME: 7. Initialize event's view attribute to target's node document's Window object, if any, and null otherwise.
  341. // FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device.
  342. // 9. Return the result of dispatching event at target.
  343. return target.dispatch_event(event);
  344. }
  345. // https://html.spec.whatwg.org/multipage/interaction.html#dom-click
  346. void HTMLElement::click()
  347. {
  348. // FIXME: 1. If this element is a form control that is disabled, then return.
  349. // 2. If this element's click in progress flag is set, then return.
  350. if (m_click_in_progress)
  351. return;
  352. // 3. Set this element's click in progress flag.
  353. m_click_in_progress = true;
  354. // FIXME: 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
  355. fire_a_synthetic_pointer_event(HTML::EventNames::click, *this, true);
  356. // 5. Unset this element's click in progress flag.
  357. m_click_in_progress = false;
  358. }
  359. // https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
  360. void HTMLElement::blur()
  361. {
  362. // The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called.
  363. run_unfocusing_steps(this);
  364. // User agents may selectively or uniformly ignore calls to this method for usability reasons.
  365. }
  366. Optional<ARIA::Role> HTMLElement::default_role() const
  367. {
  368. // https://www.w3.org/TR/html-aria/#el-article
  369. if (local_name() == TagNames::article)
  370. return ARIA::Role::article;
  371. // https://www.w3.org/TR/html-aria/#el-aside
  372. if (local_name() == TagNames::aside)
  373. return ARIA::Role::complementary;
  374. // https://www.w3.org/TR/html-aria/#el-b
  375. if (local_name() == TagNames::b)
  376. return ARIA::Role::generic;
  377. // https://www.w3.org/TR/html-aria/#el-bdi
  378. if (local_name() == TagNames::bdi)
  379. return ARIA::Role::generic;
  380. // https://www.w3.org/TR/html-aria/#el-bdo
  381. if (local_name() == TagNames::bdo)
  382. return ARIA::Role::generic;
  383. // https://www.w3.org/TR/html-aria/#el-code
  384. if (local_name() == TagNames::code)
  385. return ARIA::Role::code;
  386. // https://www.w3.org/TR/html-aria/#el-dfn
  387. if (local_name() == TagNames::dfn)
  388. return ARIA::Role::term;
  389. // https://www.w3.org/TR/html-aria/#el-em
  390. if (local_name() == TagNames::em)
  391. return ARIA::Role::emphasis;
  392. // https://www.w3.org/TR/html-aria/#el-figure
  393. if (local_name() == TagNames::figure)
  394. return ARIA::Role::figure;
  395. // https://www.w3.org/TR/html-aria/#el-footer
  396. if (local_name() == TagNames::footer) {
  397. // 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
  398. // Otherwise, role=generic
  399. return ARIA::Role::generic;
  400. }
  401. // https://www.w3.org/TR/html-aria/#el-header
  402. if (local_name() == TagNames::header) {
  403. // 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
  404. // Otherwise, role=generic
  405. return ARIA::Role::generic;
  406. }
  407. // https://www.w3.org/TR/html-aria/#el-hgroup
  408. if (local_name() == TagNames::hgroup)
  409. return ARIA::Role::generic;
  410. // https://www.w3.org/TR/html-aria/#el-i
  411. if (local_name() == TagNames::i)
  412. return ARIA::Role::generic;
  413. // https://www.w3.org/TR/html-aria/#el-main
  414. if (local_name() == TagNames::main)
  415. return ARIA::Role::main;
  416. // https://www.w3.org/TR/html-aria/#el-nav
  417. if (local_name() == TagNames::nav)
  418. return ARIA::Role::navigation;
  419. // https://www.w3.org/TR/html-aria/#el-samp
  420. if (local_name() == TagNames::samp)
  421. return ARIA::Role::generic;
  422. // https://www.w3.org/TR/html-aria/#el-section
  423. if (local_name() == TagNames::section) {
  424. // TODO: role=region if the section element has an accessible name
  425. // Otherwise, no corresponding role
  426. return ARIA::Role::region;
  427. }
  428. // https://www.w3.org/TR/html-aria/#el-small
  429. if (local_name() == TagNames::small)
  430. return ARIA::Role::generic;
  431. // https://www.w3.org/TR/html-aria/#el-strong
  432. if (local_name() == TagNames::strong)
  433. return ARIA::Role::strong;
  434. // https://www.w3.org/TR/html-aria/#el-sub
  435. if (local_name() == TagNames::sub)
  436. return ARIA::Role::subscript;
  437. // https://www.w3.org/TR/html-aria/#el-summary
  438. if (local_name() == TagNames::summary)
  439. return ARIA::Role::button;
  440. // https://www.w3.org/TR/html-aria/#el-sup
  441. if (local_name() == TagNames::sup)
  442. return ARIA::Role::superscript;
  443. // https://www.w3.org/TR/html-aria/#el-u
  444. if (local_name() == TagNames::u)
  445. return ARIA::Role::generic;
  446. return {};
  447. }
  448. // https://html.spec.whatwg.org/multipage/semantics.html#get-an-element's-target
  449. String HTMLElement::get_an_elements_target() const
  450. {
  451. // To get an element's target, given an a, area, or form element element, run these steps:
  452. // 1. If element has a target attribute, then return that attribute's value.
  453. auto maybe_target = attribute(AttributeNames::target);
  454. if (maybe_target.has_value())
  455. return maybe_target.release_value();
  456. // FIXME: 2. If element's node document contains a base element with a
  457. // target attribute, then return the value of the target attribute of the
  458. // first such base element.
  459. // 3. Return the empty string.
  460. return String {};
  461. }
  462. // https://html.spec.whatwg.org/multipage/links.html#get-an-element's-noopener
  463. TokenizedFeature::NoOpener HTMLElement::get_an_elements_noopener(StringView target) const
  464. {
  465. // To get an element's noopener, given an a, area, or form element element and a string target:
  466. auto rel = MUST(get_attribute_value(HTML::AttributeNames::rel).to_lowercase());
  467. auto link_types = rel.bytes_as_string_view().split_view_if(Infra::is_ascii_whitespace);
  468. // 1. If element's link types include the noopener or noreferrer keyword, then return true.
  469. if (link_types.contains_slow("noopener"sv) || link_types.contains_slow("noreferrer"sv))
  470. return TokenizedFeature::NoOpener::Yes;
  471. // 2. If element's link types do not include the opener keyword and
  472. // target is an ASCII case-insensitive match for "_blank", then return true.
  473. if (!link_types.contains_slow("opener"sv) && Infra::is_ascii_case_insensitive_match(target, "_blank"sv))
  474. return TokenizedFeature::NoOpener::Yes;
  475. // 3. Return false.
  476. return TokenizedFeature::NoOpener::No;
  477. }
  478. void HTMLElement::did_receive_focus()
  479. {
  480. if (m_content_editable_state != ContentEditableState::True)
  481. return;
  482. auto* browsing_context = document().browsing_context();
  483. if (!browsing_context)
  484. return;
  485. browsing_context->set_cursor_position(DOM::Position::create(realm(), *this, 0));
  486. }
  487. }