Title: [283543] trunk/Source/WebCore
Revision
283543
Author
[email protected]
Date
2021-10-05 02:54:35 -0700 (Tue, 05 Oct 2021)

Log Message

Clean up shouldAutofocus in HTMLFormControlElement.cpp
https://bugs.webkit.org/show_bug.cgi?id=231220

Reviewed by Youenn Fablet.

No behaviour change.

Minor cleanups:
- Make shouldAutofocus take `const HTMLFormControlElement&` instead of `HTMLFormControlElement*`
- Clean up repeated calls to element->document()
- Use topOrigin() instead topDocument().securityOrigin() (same thing, but shorter)

* html/HTMLFormControlElement.cpp:
(WebCore::shouldAutofocus):
(WebCore::HTMLFormControlElement::didAttachRenderers):
* html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::hasAutofocused const):
(WebCore::HTMLFormControlElement::hasAutofocused): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (283542 => 283543)


--- trunk/Source/WebCore/ChangeLog	2021-10-05 08:36:43 UTC (rev 283542)
+++ trunk/Source/WebCore/ChangeLog	2021-10-05 09:54:35 UTC (rev 283543)
@@ -1,3 +1,24 @@
+2021-10-05  Tim Nguyen  <[email protected]>
+
+        Clean up shouldAutofocus in HTMLFormControlElement.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=231220
+
+        Reviewed by Youenn Fablet.
+
+        No behaviour change.
+
+        Minor cleanups:
+        - Make shouldAutofocus take `const HTMLFormControlElement&` instead of `HTMLFormControlElement*`
+        - Clean up repeated calls to element->document()
+        - Use topOrigin() instead topDocument().securityOrigin() (same thing, but shorter)
+
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::shouldAutofocus):
+        (WebCore::HTMLFormControlElement::didAttachRenderers):
+        * html/HTMLFormControlElement.h:
+        (WebCore::HTMLFormControlElement::hasAutofocused const):
+        (WebCore::HTMLFormControlElement::hasAutofocused): Deleted.
+
 2021-10-05  Myles C. Maxfield  <[email protected]>
 
         Negative integers in @font-palette-values are invalid

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (283542 => 283543)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-10-05 08:36:43 UTC (rev 283542)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2021-10-05 09:54:35 UTC (rev 283543)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll ([email protected])
  *           (C) 1999 Antti Koivisto ([email protected])
  *           (C) 2001 Dirk Mueller ([email protected])
- * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2021 Apple Inc. All rights reserved.
  *           (C) 2006 Alexey Proskuryakov ([email protected])
  *
  * This library is free software; you can redistribute it and/or
@@ -201,40 +201,40 @@
     invalidateStyleForSubtree();
 }
 
-static bool shouldAutofocus(HTMLFormControlElement* element)
+static bool shouldAutofocus(const HTMLFormControlElement& element)
 {
-    if (!element->renderer())
+    if (!element.renderer())
         return false;
-    if (!element->hasAttributeWithoutSynchronization(autofocusAttr))
+    if (!element.hasAttributeWithoutSynchronization(autofocusAttr))
         return false;
-    if (!element->isConnected() || !element->document().renderView())
+
+    auto& document = element.document();
+    if (!element.isConnected() || !document.renderView())
         return false;
-    if (element->document().isSandboxed(SandboxAutomaticFeatures)) {
+    if (document.isSandboxed(SandboxAutomaticFeatures)) {
         // FIXME: This message should be moved off the console once a solution to https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
-        element->document().addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked autofocusing on a form control because the form's frame is sandboxed and the 'allow-scripts' permission is not set."_s);
+        document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked autofocusing on a form control because the form's frame is sandboxed and the 'allow-scripts' permission is not set."_s);
         return false;
     }
-
-    auto& document = element->document();
-    if (!document.frame()->isMainFrame() && !document.topDocument().securityOrigin().isSameOriginDomain(document.securityOrigin())) {
+    if (!document.frame()->isMainFrame() && !document.topOrigin().isSameOriginDomain(document.securityOrigin())) {
         document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, "Blocked autofocusing on a form control in a cross-origin subframe."_s);
         return false;
     }
 
-    if (element->hasAutofocused())
+    if (element.hasAutofocused())
         return false;
 
     // FIXME: Should this set of hasTagName checks be replaced by a
     // virtual member function?
-    if (is<HTMLInputElement>(*element))
-        return !downcast<HTMLInputElement>(*element).isInputTypeHidden();
-    if (element->hasTagName(selectTag))
+    if (is<HTMLInputElement>(element))
+        return !downcast<HTMLInputElement>(element).isInputTypeHidden();
+    if (element.hasTagName(selectTag))
         return true;
-    if (element->hasTagName(keygenTag))
+    if (element.hasTagName(keygenTag))
         return true;
-    if (element->hasTagName(buttonTag))
+    if (element.hasTagName(buttonTag))
         return true;
-    if (is<HTMLTextAreaElement>(*element))
+    if (is<HTMLTextAreaElement>(element))
         return true;
 
     return false;
@@ -248,7 +248,7 @@
     if (renderer())
         renderer()->updateFromElement();
 
-    if (shouldAutofocus(this)) {
+    if (shouldAutofocus(*this)) {
         setAutofocused();
 
         RefPtr<HTMLFormControlElement> element = this;

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (283542 => 283543)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2021-10-05 08:36:43 UTC (rev 283542)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2021-10-05 09:54:35 UTC (rev 283543)
@@ -116,7 +116,7 @@
     bool isReadOnly() const { return m_isReadOnly; }
     bool isDisabledOrReadOnly() const { return isDisabledFormControl() || m_isReadOnly; }
 
-    bool hasAutofocused() { return m_hasAutofocused; }
+    bool hasAutofocused() const { return m_hasAutofocused; }
     void setAutofocused() { m_hasAutofocused = true; }
 
     WEBCORE_EXPORT String autocomplete() const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to