HTMLElement.cpp 22 KB

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