HTMLElement.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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 <LibJS/Interpreter.h>
  8. #include <LibJS/Parser.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/BrowsingContextContainer.h>
  14. #include <LibWeb/HTML/EventHandler.h>
  15. #include <LibWeb/HTML/HTMLAnchorElement.h>
  16. #include <LibWeb/HTML/HTMLAreaElement.h>
  17. #include <LibWeb/HTML/HTMLBodyElement.h>
  18. #include <LibWeb/HTML/HTMLElement.h>
  19. #include <LibWeb/HTML/VisibilityState.h>
  20. #include <LibWeb/HTML/Window.h>
  21. #include <LibWeb/Layout/Box.h>
  22. #include <LibWeb/Layout/BreakNode.h>
  23. #include <LibWeb/Layout/TextNode.h>
  24. #include <LibWeb/Painting/PaintableBox.h>
  25. #include <LibWeb/UIEvents/EventNames.h>
  26. #include <LibWeb/UIEvents/FocusEvent.h>
  27. #include <LibWeb/UIEvents/MouseEvent.h>
  28. #include <LibWeb/WebIDL/DOMException.h>
  29. #include <LibWeb/WebIDL/ExceptionOr.h>
  30. namespace Web::HTML {
  31. HTMLElement::HTMLElement(DOM::Document& document, DOM::QualifiedName qualified_name)
  32. : Element(document, move(qualified_name))
  33. {
  34. set_prototype(&Bindings::cached_web_prototype(realm(), "HTMLElement"));
  35. }
  36. HTMLElement::~HTMLElement() = default;
  37. void HTMLElement::initialize(JS::Realm& realm)
  38. {
  39. Base::initialize(realm);
  40. m_dataset = DOMStringMap::create(*this);
  41. }
  42. void HTMLElement::visit_edges(Cell::Visitor& visitor)
  43. {
  44. Base::visit_edges(visitor);
  45. visitor.visit(m_dataset.ptr());
  46. }
  47. HTMLElement::ContentEditableState HTMLElement::content_editable_state() const
  48. {
  49. auto contenteditable = attribute(HTML::AttributeNames::contenteditable);
  50. // "true", an empty string or a missing value map to the "true" state.
  51. if ((!contenteditable.is_null() && contenteditable.is_empty()) || contenteditable.equals_ignoring_case("true"sv))
  52. return ContentEditableState::True;
  53. // "false" maps to the "false" state.
  54. if (contenteditable.equals_ignoring_case("false"sv))
  55. return ContentEditableState::False;
  56. // Having no such attribute or an invalid value maps to the "inherit" state.
  57. return ContentEditableState::Inherit;
  58. }
  59. bool HTMLElement::is_editable() const
  60. {
  61. switch (content_editable_state()) {
  62. case ContentEditableState::True:
  63. return true;
  64. case ContentEditableState::False:
  65. return false;
  66. case ContentEditableState::Inherit:
  67. return parent() && parent()->is_editable();
  68. default:
  69. VERIFY_NOT_REACHED();
  70. }
  71. }
  72. String HTMLElement::content_editable() const
  73. {
  74. switch (content_editable_state()) {
  75. case ContentEditableState::True:
  76. return "true";
  77. case ContentEditableState::False:
  78. return "false";
  79. case ContentEditableState::Inherit:
  80. return "inherit";
  81. default:
  82. VERIFY_NOT_REACHED();
  83. }
  84. }
  85. // https://html.spec.whatwg.org/multipage/interaction.html#contenteditable
  86. WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(String const& content_editable)
  87. {
  88. if (content_editable.equals_ignoring_case("inherit"sv)) {
  89. remove_attribute(HTML::AttributeNames::contenteditable);
  90. return {};
  91. }
  92. if (content_editable.equals_ignoring_case("true"sv)) {
  93. set_attribute(HTML::AttributeNames::contenteditable, "true");
  94. return {};
  95. }
  96. if (content_editable.equals_ignoring_case("false"sv)) {
  97. set_attribute(HTML::AttributeNames::contenteditable, "false");
  98. return {};
  99. }
  100. return WebIDL::SyntaxError::create(realm(), "Invalid contentEditable value, must be 'true', 'false', or 'inherit'");
  101. }
  102. void HTMLElement::set_inner_text(StringView text)
  103. {
  104. remove_all_children();
  105. append_child(document().create_text_node(text));
  106. set_needs_style_update(true);
  107. }
  108. String HTMLElement::inner_text()
  109. {
  110. StringBuilder builder;
  111. // innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree.
  112. document().update_layout();
  113. if (!layout_node())
  114. return text_content();
  115. Function<void(Layout::Node const&)> recurse = [&](auto& node) {
  116. for (auto* child = node.first_child(); child; child = child->next_sibling()) {
  117. if (is<Layout::TextNode>(child))
  118. builder.append(verify_cast<Layout::TextNode>(*child).text_for_rendering());
  119. if (is<Layout::BreakNode>(child))
  120. builder.append('\n');
  121. recurse(*child);
  122. }
  123. };
  124. recurse(*layout_node());
  125. return builder.to_string();
  126. }
  127. // // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsettop
  128. int HTMLElement::offset_top() const
  129. {
  130. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  131. const_cast<DOM::Document&>(document()).update_layout();
  132. if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
  133. return 0;
  134. auto position = layout_node()->box_type_agnostic_position();
  135. auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
  136. return position.y() - parent_position.y();
  137. }
  138. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetleft
  139. int HTMLElement::offset_left() const
  140. {
  141. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  142. const_cast<DOM::Document&>(document()).update_layout();
  143. if (is<HTML::HTMLBodyElement>(this) || !layout_node() || !parent_element() || !parent_element()->layout_node())
  144. return 0;
  145. auto position = layout_node()->box_type_agnostic_position();
  146. auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
  147. return position.x() - parent_position.x();
  148. }
  149. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
  150. int HTMLElement::offset_width() const
  151. {
  152. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  153. const_cast<DOM::Document&>(document()).update_layout();
  154. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  155. if (!paint_box())
  156. return 0;
  157. // 2. Return the width of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  158. // ignoring any transforms that apply to the element and its ancestors.
  159. // FIXME: Account for inline boxes.
  160. return paint_box()->border_box_width();
  161. }
  162. // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
  163. int HTMLElement::offset_height() const
  164. {
  165. // NOTE: Ensure that layout is up-to-date before looking at metrics.
  166. const_cast<DOM::Document&>(document()).update_layout();
  167. // 1. If the element does not have any associated CSS layout box return zero and terminate this algorithm.
  168. if (!paint_box())
  169. return 0;
  170. // 2. Return the height of the axis-aligned bounding box of the border boxes of all fragments generated by the element’s principal box,
  171. // ignoring any transforms that apply to the element and its ancestors.
  172. // FIXME: Account for inline boxes.
  173. return paint_box()->border_box_height();
  174. }
  175. // https://html.spec.whatwg.org/multipage/links.html#cannot-navigate
  176. bool HTMLElement::cannot_navigate() const
  177. {
  178. // An element element cannot navigate if one of the following is true:
  179. // - element's node document is not fully active
  180. if (!document().is_fully_active())
  181. return true;
  182. // - element is not an a element and is not connected.
  183. return !is<HTML::HTMLAnchorElement>(this) && !is_connected();
  184. }
  185. void HTMLElement::parse_attribute(FlyString const& name, String const& value)
  186. {
  187. Element::parse_attribute(name, value);
  188. // 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return.
  189. // FIXME: Add the namespace part once we support attribute namespaces.
  190. #undef __ENUMERATE
  191. #define __ENUMERATE(attribute_name, event_name) \
  192. if (name == HTML::AttributeNames::attribute_name) { \
  193. element_event_handler_attribute_changed(event_name, value); \
  194. }
  195. ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
  196. #undef __ENUMERATE
  197. }
  198. // https://html.spec.whatwg.org/multipage/interaction.html#focus-update-steps
  199. static void run_focus_update_steps(Vector<JS::Handle<DOM::Node>> old_chain, Vector<JS::Handle<DOM::Node>> new_chain, DOM::Node* new_focus_target)
  200. {
  201. // 1. If the last entry in old chain and the last entry in new chain are the same,
  202. // pop the last entry from old chain and the last entry from new chain and redo this step.
  203. while (!old_chain.is_empty()
  204. && !new_chain.is_empty()
  205. && &old_chain.last() == &new_chain.last()) {
  206. (void)old_chain.take_last();
  207. (void)new_chain.take_last();
  208. }
  209. // 2. For each entry entry in old chain, in order, run these substeps:
  210. for (auto& entry : old_chain) {
  211. // FIXME: 1. If entry is an input element, and the change event applies to the element,
  212. // and the element does not have a defined activation behavior,
  213. // and the user has changed the element's value or its list of selected files
  214. // while the control was focused without committing that change
  215. // (such that it is different to what it was when the control was first focused),
  216. // then fire an event named change at the element,
  217. // with the bubbles attribute initialized to true.
  218. JS::GCPtr<DOM::EventTarget> blur_event_target;
  219. if (is<DOM::Element>(*entry)) {
  220. // 2. If entry is an element, let blur event target be entry.
  221. blur_event_target = entry.ptr();
  222. } else if (is<DOM::Document>(*entry)) {
  223. // If entry is a Document object, let blur event target be that Document object's relevant global object.
  224. blur_event_target = &static_cast<DOM::Document&>(*entry).window();
  225. }
  226. // 3. If entry is the last entry in old chain, and entry is an Element,
  227. // and the last entry in new chain is also an Element,
  228. // then let related blur target be the last entry in new chain.
  229. // Otherwise, let related blur target be null.
  230. JS::GCPtr<DOM::EventTarget> related_blur_target;
  231. if (!old_chain.is_empty()
  232. && &entry == &old_chain.last()
  233. && is<DOM::Element>(*entry)
  234. && !new_chain.is_empty()
  235. && is<DOM::Element>(*new_chain.last())) {
  236. related_blur_target = new_chain.last().ptr();
  237. }
  238. // 4. If blur event target is not null, fire a focus event named blur at blur event target,
  239. // with related blur target as the related target.
  240. if (blur_event_target) {
  241. // FIXME: Implement the "fire a focus event" spec operation.
  242. auto blur_event = UIEvents::FocusEvent::create(blur_event_target->realm(), HTML::EventNames::blur);
  243. blur_event->set_related_target(related_blur_target);
  244. blur_event_target->dispatch_event(*blur_event);
  245. }
  246. }
  247. // FIXME: 3. Apply any relevant platform-specific conventions for focusing new focus target.
  248. // (For example, some platforms select the contents of a text control when that control is focused.)
  249. (void)new_focus_target;
  250. // 4. For each entry entry in new chain, in reverse order, run these substeps:
  251. for (auto& entry : new_chain.in_reverse()) {
  252. // 1. If entry is a focusable area: designate entry as the focused area of the document.
  253. // FIXME: This isn't entirely right.
  254. if (is<DOM::Element>(*entry))
  255. entry->document().set_focused_element(&static_cast<DOM::Element&>(*entry));
  256. JS::GCPtr<DOM::EventTarget> focus_event_target;
  257. if (is<DOM::Element>(*entry)) {
  258. // 2. If entry is an element, let focus event target be entry.
  259. focus_event_target = entry.ptr();
  260. } else if (is<DOM::Document>(*entry)) {
  261. // If entry is a Document object, let focus event target be that Document object's relevant global object.
  262. focus_event_target = &static_cast<DOM::Document&>(*entry).window();
  263. }
  264. // 3. If entry is the last entry in new chain, and entry is an Element,
  265. // and the last entry in old chain is also an Element,
  266. // then let related focus target be the last entry in old chain.
  267. // Otherwise, let related focus target be null.
  268. JS::GCPtr<DOM::EventTarget> related_focus_target;
  269. if (!new_chain.is_empty()
  270. && &entry == &new_chain.last()
  271. && is<DOM::Element>(*entry)
  272. && !old_chain.is_empty()
  273. && is<DOM::Element>(*old_chain.last())) {
  274. related_focus_target = old_chain.last().ptr();
  275. }
  276. // 4. If focus event target is not null, fire a focus event named focus at focus event target,
  277. // with related focus target as the related target.
  278. if (focus_event_target) {
  279. // FIXME: Implement the "fire a focus event" spec operation.
  280. auto focus_event = UIEvents::FocusEvent::create(focus_event_target->realm(), HTML::EventNames::focus);
  281. focus_event->set_related_target(related_focus_target);
  282. focus_event_target->dispatch_event(*focus_event);
  283. }
  284. }
  285. }
  286. // https://html.spec.whatwg.org/multipage/interaction.html#focus-chain
  287. static Vector<JS::Handle<DOM::Node>> focus_chain(DOM::Node* subject)
  288. {
  289. // FIXME: Move this somewhere more spec-friendly.
  290. if (!subject)
  291. return {};
  292. // 1. Let output be an empty list.
  293. Vector<JS::Handle<DOM::Node>> output;
  294. // 2. Let currentObject be subject.
  295. auto* current_object = subject;
  296. // 3. While true:
  297. while (true) {
  298. // 1. Append currentObject to output.
  299. output.append(JS::make_handle(*current_object));
  300. // FIXME: 2. If currentObject is an area element's shape, then append that area element to output.
  301. // FIXME: Otherwise, if currentObject's DOM anchor is an element that is not currentObject itself, then append currentObject's DOM anchor to output.
  302. // FIXME: Everything below needs work. The conditions are not entirely right.
  303. if (!is<DOM::Document>(*current_object)) {
  304. // 3. If currentObject is a focusable area, then set currentObject to currentObject's DOM anchor's node document.
  305. current_object = &current_object->document();
  306. } else if (is<DOM::Document>(*current_object)
  307. && static_cast<DOM::Document&>(*current_object).browsing_context()
  308. && !static_cast<DOM::Document&>(*current_object).browsing_context()->is_top_level()) {
  309. // Otherwise, if currentObject is a Document whose browsing context is a child browsing context,
  310. // then set currentObject to currentObject's browsing context's container.
  311. current_object = static_cast<DOM::Document&>(*current_object).browsing_context()->container();
  312. } else {
  313. break;
  314. }
  315. }
  316. // 4. Return output.
  317. return output;
  318. }
  319. // https://html.spec.whatwg.org/multipage/interaction.html#focusing-steps
  320. // FIXME: This should accept more types.
  321. static void run_focusing_steps(DOM::Node* new_focus_target, DOM::Node* fallback_target = nullptr, [[maybe_unused]] Optional<String> focus_trigger = {})
  322. {
  323. // FIXME: 1. If new focus target is not a focusable area, then set new focus target
  324. // to the result of getting the focusable area for new focus target,
  325. // given focus trigger if it was passed.
  326. // 2. If new focus target is null, then:
  327. if (!new_focus_target) {
  328. // 1. If no fallback target was specified, then return.
  329. if (!fallback_target)
  330. return;
  331. // 2. Otherwise, set new focus target to the fallback target.
  332. new_focus_target = fallback_target;
  333. }
  334. // 3. If new focus target is a browsing context container with non-null nested browsing context,
  335. // then set new focus target to the nested browsing context's active document.
  336. if (is<BrowsingContextContainer>(*new_focus_target)) {
  337. auto& browsing_context_container = static_cast<BrowsingContextContainer&>(*new_focus_target);
  338. if (auto* nested_browsing_context = browsing_context_container.nested_browsing_context())
  339. new_focus_target = nested_browsing_context->active_document();
  340. }
  341. // FIXME: 4. If new focus target is a focusable area and its DOM anchor is inert, then return.
  342. // 5. If new focus target is the currently focused area of a top-level browsing context, then return.
  343. if (!new_focus_target->document().browsing_context())
  344. return;
  345. auto& top_level_browsing_context = new_focus_target->document().browsing_context()->top_level_browsing_context();
  346. if (new_focus_target == top_level_browsing_context.currently_focused_area().ptr())
  347. return;
  348. // 6. Let old chain be the current focus chain of the top-level browsing context in which
  349. // new focus target finds itself.
  350. auto old_chain = focus_chain(top_level_browsing_context.currently_focused_area());
  351. // 7. Let new chain be the focus chain of new focus target.
  352. auto new_chain = focus_chain(new_focus_target);
  353. // 8. Run the focus update steps with old chain, new chain, and new focus target respectively.
  354. run_focus_update_steps(old_chain, new_chain, new_focus_target);
  355. }
  356. // https://html.spec.whatwg.org/multipage/interaction.html#unfocusing-steps
  357. static void run_unfocusing_steps(DOM::Node* old_focus_target)
  358. {
  359. // NOTE: The unfocusing steps do not always result in the focus changing, even when applied to the currently focused
  360. // area of a top-level browsing context. For example, if the currently focused area of a top-level browsing context
  361. // is a viewport, then it will usually keep its focus regardless until another focusable area is explicitly focused
  362. // with the focusing steps.
  363. auto is_shadow_host = [](DOM::Node* node) {
  364. return is<DOM::Element>(node) && static_cast<DOM::Element*>(node)->shadow_root() != nullptr;
  365. };
  366. // 1. If old focus target is a shadow host whose shadow root's delegates focus is true, and old focus target's
  367. // shadow root is a shadow-including inclusive ancestor of the currently focused area of a top-level browsing
  368. // context's DOM anchor, then set old focus target to that currently focused area of a top-level browsing
  369. // context.
  370. if (is_shadow_host(old_focus_target)) {
  371. auto* shadow_root = static_cast<DOM::Element*>(old_focus_target)->shadow_root();
  372. if (shadow_root->delegates_focus()) {
  373. auto& top_level_browsing_context = old_focus_target->document().browsing_context()->top_level_browsing_context();
  374. if (auto currently_focused_area = top_level_browsing_context.currently_focused_area()) {
  375. if (shadow_root->is_shadow_including_ancestor_of(*currently_focused_area)) {
  376. old_focus_target = currently_focused_area;
  377. }
  378. }
  379. }
  380. }
  381. // FIXME: 2. If old focus target is inert, then return.
  382. // FIXME: 3. If old focus target is an area element and one of its shapes is the currently focused area of a
  383. // top-level browsing context, or, if old focus target is an element with one or more scrollable regions, and one
  384. // of them is the currently focused area of a top-level browsing context, then let old focus target be that
  385. // currently focused area of a top-level browsing context.
  386. // NOTE: HTMLAreaElement is currently missing the shapes property
  387. auto& top_level_browsing_context = old_focus_target->document().browsing_context()->top_level_browsing_context();
  388. // 4. Let old chain be the current focus chain of the top-level browsing context in which old focus target finds itself.
  389. auto old_chain = focus_chain(top_level_browsing_context.currently_focused_area());
  390. // 5. If old focus target is not one of the entries in old chain, then return.
  391. for (auto& node : old_chain) {
  392. if (old_focus_target != node) {
  393. return;
  394. }
  395. }
  396. // 6. If old focus target is not a focusable area, then return.
  397. if (!old_focus_target->is_focusable())
  398. return;
  399. // 7. Let topDocument be old chain's last entry.
  400. auto* top_document = verify_cast<DOM::Document>(old_chain.last().ptr());
  401. // 8. If topDocument's browsing context has system focus, then run the focusing steps for topDocument's viewport.
  402. if (top_document->browsing_context()->system_visibility_state() == VisibilityState::Visible) {
  403. // FIXME: run the focusing steps for topDocument's viewport (??)
  404. } else {
  405. // FIXME: Otherwise, apply any relevant platform-specific conventions for removing system focus from
  406. // topDocument's browsing context, and run the focus update steps with old chain, an empty list, and null
  407. // respectively.
  408. // What? It already doesn't have system focus, what possible platform-specific conventions are there?
  409. run_focus_update_steps(old_chain, {}, nullptr);
  410. }
  411. // FIXME: When the currently focused area of a top-level browsing context is somehow unfocused without another
  412. // element being explicitly focused in its stead, the user agent must immediately run the unfocusing steps for that
  413. // object.
  414. // What? How are we supposed to detect when something is "somehow unfocused without another element being explicitly focused"?
  415. }
  416. // https://html.spec.whatwg.org/multipage/interaction.html#dom-focus
  417. void HTMLElement::focus()
  418. {
  419. // 1. If the element is marked as locked for focus, then return.
  420. if (m_locked_for_focus)
  421. return;
  422. // 2. Mark the element as locked for focus.
  423. m_locked_for_focus = true;
  424. // 3. Run the focusing steps for the element.
  425. run_focusing_steps(this);
  426. // FIXME: 4. If the value of the preventScroll dictionary member of options is false,
  427. // then scroll the element into view with scroll behavior "auto",
  428. // block flow direction position set to an implementation-defined value,
  429. // and inline base direction position set to an implementation-defined value.
  430. // 5. Unmark the element as locked for focus.
  431. m_locked_for_focus = false;
  432. }
  433. // https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event
  434. bool HTMLElement::fire_a_synthetic_pointer_event(FlyString const& type, DOM::Element& target, bool not_trusted)
  435. {
  436. // 1. Let event be the result of creating an event using PointerEvent.
  437. // 2. Initialize event's type attribute to e.
  438. // FIXME: Actually create a PointerEvent!
  439. auto event = UIEvents::MouseEvent::create(realm(), type);
  440. // 3. Initialize event's bubbles and cancelable attributes to true.
  441. event->set_bubbles(true);
  442. event->set_cancelable(true);
  443. // 4. Set event's composed flag.
  444. event->set_composed(true);
  445. // 5. If the not trusted flag is set, initialize event's isTrusted attribute to false.
  446. if (not_trusted) {
  447. event->set_is_trusted(false);
  448. }
  449. // FIXME: 6. Initialize event's ctrlKey, shiftKey, altKey, and metaKey attributes according to the current state
  450. // of the key input device, if any (false for any keys that are not available).
  451. // FIXME: 7. Initialize event's view attribute to target's node document's Window object, if any, and null otherwise.
  452. // FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device.
  453. // 9. Return the result of dispatching event at target.
  454. return target.dispatch_event(*event);
  455. }
  456. // https://html.spec.whatwg.org/multipage/interaction.html#dom-click
  457. void HTMLElement::click()
  458. {
  459. // FIXME: 1. If this element is a form control that is disabled, then return.
  460. // 2. If this element's click in progress flag is set, then return.
  461. if (m_click_in_progress)
  462. return;
  463. // 3. Set this element's click in progress flag.
  464. m_click_in_progress = true;
  465. // FIXME: 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
  466. fire_a_synthetic_pointer_event(HTML::EventNames::click, *this, true);
  467. // 5. Unset this element's click in progress flag.
  468. m_click_in_progress = false;
  469. }
  470. // https://html.spec.whatwg.org/multipage/interaction.html#dom-blur
  471. void HTMLElement::blur()
  472. {
  473. // The blur() method, when invoked, should run the unfocusing steps for the element on which the method was called.
  474. run_unfocusing_steps(this);
  475. // User agents may selectively or uniformly ignore calls to this method for usability reasons.
  476. }
  477. }