<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>227907</bug_id>
          
          <creation_ts>2021-07-13 09:38:57 -0700</creation_ts>
          <short_desc>Check for dialog existence in top layer in showModal/close</short_desc>
          <delta_ts>2021-08-17 09:35:46 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>229149</dependson>
          <blocked>84635</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Tim Nguyen (:ntim)">ntim</reporter>
          <assigned_to name="Tim Nguyen (:ntim)">ntim</assigned_to>
          <cc>cdumez</cc>
    
    <cc>changseok</cc>
    
    <cc>cmarcelo</cc>
    
    <cc>darin</cc>
    
    <cc>esprehn+autocc</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>gyuyoung.kim</cc>
    
    <cc>kangil.han</cc>
    
    <cc>koivisto</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1776648</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2021-07-13 09:38:57 -0700</bug_when>
    <thetext>Current behaviour is wrong, especially for showModal, since it will wrongly shuffle around the order, if the dialog is already in the top layer.

This needs a isInTopLayer method.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1776650</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-07-13 09:39:29 -0700</bug_when>
    <thetext>&lt;rdar://problem/80523132&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784092</commentid>
    <comment_count>2</comment_count>
      <attachid>435479</attachid>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2021-08-13 06:23:44 -0700</bug_when>
    <thetext>Created attachment 435479
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784098</commentid>
    <comment_count>3</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2021-08-13 07:16:42 -0700</bug_when>
    <thetext>Committed r281014 (240504@main): &lt;https://commits.webkit.org/240504@main&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784102</commentid>
    <comment_count>4</comment_count>
      <attachid>435479</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-08-13 07:25:08 -0700</bug_when>
    <thetext>Comment on attachment 435479
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=435479&amp;action=review

&gt; Source/WebCore/html/HTMLDialogElement.cpp:69
&gt; +    if (!isInTopLayer())
&gt; +        document().addToTopLayer(*this);

This is the double hashing solution, looking in topLayerElements once to see if the element is there and then doing the same hashing in topLayerElements again to add the element. If the addToTopLayer performed this check, it could almost certainly do it without hashing twice.

&gt; Source/WebCore/html/HTMLDialogElement.cpp:89
&gt; +    if (isInTopLayer())
&gt; +        document().removeFromTopLayer(*this);

I don’t see why this change is needed. This would have no effect even if top layer rendering is implemented.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784183</commentid>
    <comment_count>5</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2021-08-13 12:04:54 -0700</bug_when>
    <thetext>(In reply to Darin Adler from comment #4)
&gt; Comment on attachment 435479 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=435479&amp;action=review
&gt; 
&gt; &gt; Source/WebCore/html/HTMLDialogElement.cpp:69
&gt; &gt; +    if (!isInTopLayer())
&gt; &gt; +        document().addToTopLayer(*this);
&gt; 
&gt; This is the double hashing solution, looking in topLayerElements once to see
&gt; if the element is there and then doing the same hashing in topLayerElements
&gt; again to add the element. If the addToTopLayer performed this check, it
&gt; could almost certainly do it without hashing twice.

addToTopLayer adds to the top layer if not in it, and moves to the last position if it is in it. This is what the top layer spec says: &quot;to add an element to the top layer, remove it first then add it again&quot;.

Moving this check in addToTopLayer would change that behaviour (which made the test fail). It&apos;s also worth noting that the new fullscreen API should re-use this top layer concept.

&gt; &gt; Source/WebCore/html/HTMLDialogElement.cpp:89
&gt; &gt; +    if (isInTopLayer())
&gt; &gt; +        document().removeFromTopLayer(*this);
&gt; 
&gt; I don’t see why this change is needed. This would have no effect even if top
&gt; layer rendering is implemented.

I guess it doesn&apos;t matter much right now, this is just following spec words:

https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-close
If subject is in its Document&apos;s top layer, then remove it.

It might matter a bit more if we add more things in the `removeFromTopLayer` function (e.g. fullscreen API related, rendering related, etc.).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784279</commentid>
    <comment_count>6</comment_count>
      <attachid>435479</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-08-13 16:51:35 -0700</bug_when>
    <thetext>Comment on attachment 435479
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=435479&amp;action=review

I understand your responses, but I’m still a little disappointed that we end up doing double hashing.

&gt;&gt;&gt; Source/WebCore/html/HTMLDialogElement.cpp:69
&gt;&gt;&gt; +        document().addToTopLayer(*this);
&gt;&gt; 
&gt;&gt; This is the double hashing solution, looking in topLayerElements once to see if the element is there and then doing the same hashing in topLayerElements again to add the element. If the addToTopLayer performed this check, it could almost certainly do it without hashing twice.
&gt; 
&gt; addToTopLayer adds to the top layer if not in it, and moves to the last position if it is in it. This is what the top layer spec says: &quot;to add an element to the top layer, remove it first then add it again&quot;.
&gt; 
&gt; Moving this check in addToTopLayer would change that behaviour (which made the test fail). It&apos;s also worth noting that the new fullscreen API should re-use this top layer concept.

Understood.

We could still refactor to avoid double hashing, it’s just a bit more complex. We’d need to write a &quot;addToTopLayer if not already present&quot; function, and factor things so that it’s only a single hash table lookup. One way to do that is an argument that changes the behavior of addToTopLayer.

&gt;&gt;&gt; Source/WebCore/html/HTMLDialogElement.cpp:89
&gt;&gt;&gt; +        document().removeFromTopLayer(*this);
&gt;&gt; 
&gt;&gt; I don’t see why this change is needed. This would have no effect even if top layer rendering is implemented.
&gt; 
&gt; I guess it doesn&apos;t matter much right now, this is just following spec words:
&gt; 
&gt; https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-dialog-close
&gt; If subject is in its Document&apos;s top layer, then remove it.
&gt; 
&gt; It might matter a bit more if we add more things in the `removeFromTopLayer` function (e.g. fullscreen API related, rendering related, etc.).

Sure, but if we add such things, we’d just need to make sure that removeFromTopLayer does nothing if it’s not a top layer. That’s going to be really convenient since hash table removal functions already tell you if the thing was removed or not.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784549</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Nguyen (:ntim)">ntim</who>
    <bug_when>2021-08-16 09:33:51 -0700</bug_when>
    <thetext>(In reply to Darin Adler from comment #6)
&gt; Comment on attachment 435479 [details]
&gt; Patch
&gt; 
&gt; View in context:
&gt; https://bugs.webkit.org/attachment.cgi?id=435479&amp;action=review
&gt; 
&gt; I understand your responses, but I’m still a little disappointed that we end
&gt; up doing double hashing.
&gt; 
&gt; &gt;&gt;&gt; Source/WebCore/html/HTMLDialogElement.cpp:69
&gt; &gt;&gt;&gt; +        document().addToTopLayer(*this);
&gt; &gt;&gt; 
&gt; &gt;&gt; This is the double hashing solution, looking in topLayerElements once to see if the element is there and then doing the same hashing in topLayerElements again to add the element. If the addToTopLayer performed this check, it could almost certainly do it without hashing twice.
&gt; &gt; 
&gt; &gt; addToTopLayer adds to the top layer if not in it, and moves to the last position if it is in it. This is what the top layer spec says: &quot;to add an element to the top layer, remove it first then add it again&quot;.
&gt; &gt; 
&gt; &gt; Moving this check in addToTopLayer would change that behaviour (which made the test fail). It&apos;s also worth noting that the new fullscreen API should re-use this top layer concept.
&gt; 
&gt; Understood.
&gt; 
&gt; We could still refactor to avoid double hashing, it’s just a bit more
&gt; complex. We’d need to write a &quot;addToTopLayer if not already present&quot;
&gt; function, and factor things so that it’s only a single hash table lookup.
&gt; One way to do that is an argument that changes the behavior of addToTopLayer.

That sounds reasonable. I filed bug 229149 as followup. I&apos;m unlikely going to take it before I finish the &lt;dialog&gt; work, but feel free to take it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1784853</commentid>
    <comment_count>8</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2021-08-17 09:35:46 -0700</bug_when>
    <thetext>(In reply to Tim Nguyen (:ntim) from comment #7)
&gt; That sounds reasonable. I filed bug 229149 as followup. I&apos;m unlikely going
&gt; to take it before I finish the &lt;dialog&gt; work, but feel free to take it.

Honestly not sure how important it is, but I might do it.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>435479</attachid>
            <date>2021-08-13 06:23:44 -0700</date>
            <delta_ts>2021-08-13 06:58:40 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-227907-20210813152343.patch</filename>
            <type>text/plain</type>
            <size>3074</size>
            <attacher name="Tim Nguyen (:ntim)">ntim</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjgwOTIzCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggMjUwMTU5NjEzNzExMDU0
M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MDcpCi0gICAgZG9j
dW1lbnQoKS5hZGRUb1RvcExheWVyKCp0aGlzKTsKKyAgICBpZiAoIWlzSW5Ub3BMYXllcigpKQor
ICAgICAgICBkb2N1bWVudCgpLmFkZFRvVG9wTGF5ZXIoKnRoaXMpOwogCiAgICAgLy8gRklYTUU6
IEFkZCBzdGVwcyA4ICYgOSBmcm9tIHNwZWMuICh3ZWJraXQub3JnL2IvMjI3NTM3KQogCkBAIC04
NSw4ICs4NSw4IEBAIHZvaWQgSFRNTERpYWxvZ0VsZW1lbnQ6OmNsb3NlKGNvbnN0IFN0cmluZyYg
cmVzdWx0KQogICAgIGlmICghcmVzdWx0LmlzTnVsbCgpKQogICAgICAgICBtX3JldHVyblZhbHVl
ID0gcmVzdWx0OwogCi0gICAgLy8gRklYTUU6IE9ubHkgcmVtb3ZlIGRpYWxvZyBmcm9tIHRvcCBs
YXllciBpZiBpdCdzIGluc2lkZSBpdC4gKHdlYmtpdC5vcmcvYi8yMjc5MDcpCi0gICAgZG9jdW1l
bnQoKS5yZW1vdmVGcm9tVG9wTGF5ZXIoKnRoaXMpOworICAgIGlmIChpc0luVG9wTGF5ZXIoKSkK
KyAgICAgICAgZG9jdW1lbnQoKS5yZW1vdmVGcm9tVG9wTGF5ZXIoKnRoaXMpOwogCiAgICAgLy8g
RklYTUU6IEFkZCBzdGVwIDYgZnJvbSBzcGVjLiAod2Via2l0Lm9yZy9iLzIyNzUzNykKIAo=
</data>
<flag name="review"
          id="458315"
          type_id="1"
          status="+"
          setter="koivisto"
    />
    <flag name="commit-queue"
          id="458316"
          type_id="3"
          status="+"
          setter="ntim"
    />
          </attachment>
      

    </bug>

</bugzilla>