Ver Fonte

LibWeb: Make Document::{visibility,read}_state return a StringView

Also using the visibility state enum to change strcmp to a simple
enum state check :^)
Shannon Booth há 1 ano atrás
pai
commit
c3e6077cfc

+ 3 - 3
Userland/Libraries/LibWeb/DOM/Document.cpp

@@ -1856,7 +1856,7 @@ void Document::scroll_to_the_beginning_of_the_document()
         browsing_context->scroll_to({ 0, 0 });
         browsing_context->scroll_to({ 0, 0 });
 }
 }
 
 
-DeprecatedString Document::ready_state() const
+StringView Document::ready_state() const
 {
 {
     switch (m_readiness) {
     switch (m_readiness) {
     case HTML::DocumentReadyState::Loading:
     case HTML::DocumentReadyState::Loading:
@@ -2052,11 +2052,11 @@ JS::GCPtr<HTML::Location> Document::location()
 // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
 // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-hidden
 bool Document::hidden() const
 bool Document::hidden() const
 {
 {
-    return visibility_state() == "hidden";
+    return m_visibility_state == HTML::VisibilityState::Hidden;
 }
 }
 
 
 // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
 // https://html.spec.whatwg.org/multipage/interaction.html#dom-document-visibilitystate
-DeprecatedString Document::visibility_state() const
+StringView Document::visibility_state() const
 {
 {
     switch (m_visibility_state) {
     switch (m_visibility_state) {
     case HTML::VisibilityState::Hidden:
     case HTML::VisibilityState::Hidden:

+ 2 - 2
Userland/Libraries/LibWeb/DOM/Document.h

@@ -308,7 +308,7 @@ public:
 
 
     JS::NonnullGCPtr<Document> appropriate_template_contents_owner_document();
     JS::NonnullGCPtr<Document> appropriate_template_contents_owner_document();
 
 
-    DeprecatedString ready_state() const;
+    StringView ready_state() const;
     HTML::DocumentReadyState readiness() const { return m_readiness; }
     HTML::DocumentReadyState readiness() const { return m_readiness; }
     void update_readiness(HTML::DocumentReadyState);
     void update_readiness(HTML::DocumentReadyState);
 
 
@@ -375,7 +375,7 @@ public:
     void set_page_showing(bool value) { m_page_showing = value; }
     void set_page_showing(bool value) { m_page_showing = value; }
 
 
     bool hidden() const;
     bool hidden() const;
-    DeprecatedString visibility_state() const;
+    StringView visibility_state() const;
 
 
     // https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
     // https://html.spec.whatwg.org/multipage/interaction.html#update-the-visibility-state
     void update_the_visibility_state(HTML::VisibilityState);
     void update_the_visibility_state(HTML::VisibilityState);

+ 1 - 1
Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp

@@ -1339,7 +1339,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_ind
     // FIXME: 6. If newDocument has any form controls whose autofill field name is "off", invoke the reset algorithm of each of those elements.
     // FIXME: 6. If newDocument has any form controls whose autofill field name is "off", invoke the reset algorithm of each of those elements.
 
 
     // 7. If newDocument's current document readiness "complete",
     // 7. If newDocument's current document readiness "complete",
-    if (new_document->ready_state() == "complete"sv) {
+    if (new_document->readiness() == HTML::DocumentReadyState::Complete) {
         // then queue a global task on the DOM manipulation task source given newDocument's relevant global object to run the following steps:
         // then queue a global task on the DOM manipulation task source given newDocument's relevant global object to run the following steps:
 
 
         queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document] {
         queue_global_task(Task::Source::DOMManipulation, relevant_global_object(*new_document), [new_document] {