Skip to content

Commit

Permalink
Clean up selection direction handling
Browse files Browse the repository at this point in the history
This fixes the issue noted in
#2437 (comment) where
the spec sometimes assumed it was OK to set the selection direction to
none, even though not all platforms support this. It introduces a new
concept, "set the selection direction", which will convert "none" to
"forward" as appropriate.

This commit also makes a couple editorial tweaks:

* Replaces the italicized selection direction states with simple
  strings, which allows us to avoid a switch statement to translate
  between them.
* Splits out getter and setters in <input> and <textarea>'s value IDL
  attribute definitions, and gives the setters a proper numbered list.
  • Loading branch information
domenic authored and foolip committed Mar 21, 2017
1 parent 97d644c commit af9fa0f
Showing 1 changed file with 82 additions and 66 deletions.
148 changes: 82 additions & 66 deletions source
Expand Up @@ -48643,49 +48643,58 @@ You cannot submit this form when the field is incorrect.</samp></pre>
<dt><dfn data-x="dom-input-value-value">value</dfn>

<dd>
<p>On getting, return the current <span data-x="concept-fe-value">value</span> of the
element.</p>

<p>On setting:</p>

<p>On getting, it must return the current <span data-x="concept-fe-value">value</span> of the
element. On setting, it must set the element's <span data-x="concept-fe-value">value</span> to
the new value, set the element's <span data-x="concept-fe-dirty">dirty value flag</span> to
true, invoke the <span>value sanitization algorithm</span>, if the element's <code
data-x="attr-input-type">type</code> attribute's current state defines one, and then, if the
element has a text entry cursor position, should move the text entry cursor position to the end
of the text control, unselecting any selected text and resetting the selection direction to
<i>none</i>.</p>
<ol>
<li><p>Set the element's <span data-x="concept-fe-value">value</span> to the new
value.</p></li>

<li><p>Set the element's <span data-x="concept-fe-dirty">dirty value flag</span> to
true.</p></li>

<li><p>Invoke the <span>value sanitization algorithm</span>, if the element's <code
data-x="attr-input-type">type</code> attribute's current state defines one.</p></li>

<li><p>If the element has a text entry cursor position, move the text entry cursor position to
the end of the text control, unselecting any selected text and <span data-x="set the selection
direction">resetting the selection direction</span> to "<code data-x="">none</code>".</p></li>
</ol>
</dd>

<dt><dfn data-x="dom-input-value-default">default</dfn>

<dd>
<p>On getting, if the element has a <code data-x="attr-input-value">value</code> content
attribute, return that attribute's value; otherwise, return the empty string.</p>

<p>On getting, if the element has a <code data-x="attr-input-value">value</code> attribute, it
must return that attribute's value; otherwise, it must return the empty string. On setting, it
must set the element's <code data-x="attr-input-value">value</code> attribute to the new
value.</p>

<p>On setting, set the value of the element's <code data-x="attr-input-value">value</code>
content attribute to the new value.</p>
</dd>

<dt><dfn data-x="dom-input-value-default-on">default/on</dfn>

<dd>
<p>On getting, if the element has a <code data-x="attr-input-value">value</code> content
attribute, return that attribute's value; otherwise, return the string "<code
data-x="">on</code>".</p>

<p>On getting, if the element has a <code data-x="attr-input-value">value</code> attribute, it
must return that attribute's value; otherwise, it must return the string "<code
data-x="">on</code>". On setting, it must set the element's <code
data-x="attr-input-value">value</code> attribute to the new value.</p>

<p>On setting, set the value of the element's <code data-x="attr-input-value">value</code>
content attribute to the new value.</p>
</dd>

<dt><dfn data-x="dom-input-value-filename">filename</dfn>

<dd id="fakepath-orly">

<p>On getting, it must return the string "<code data-x="">C:\fakepath\</code>" followed by the
name of the first file in the list of <span data-x="concept-input-type-file-selected">selected
files</span>, if any, or the empty string if the list is empty. On setting, if the new value is
the empty string, it must empty the list of <span
data-x="concept-input-type-file-selected">selected files</span>; otherwise, it must throw an
<p>On getting, return the string "<code data-x="">C:\fakepath\</code>" followed by the name of
the first file in the list of <span data-x="concept-input-type-file-selected">selected
files</span>, if any, or the empty string if the list is empty.</p>

<p>On setting, if the new value is the empty string, empty the list of <span
data-x="concept-input-type-file-selected">selected files</span>; otherwise, throw an
<span>"<code>InvalidStateError</code>"</span> <code>DOMException</code>.</p>

<p class="note">This "fakepath" requirement is a sad accident of history. See <a
Expand Down Expand Up @@ -50617,11 +50626,20 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
act like the element's <code>textContent</code> IDL attribute.</p>

<p>The <dfn><code data-x="dom-textarea-value">value</code></dfn> IDL attribute must, on getting,
return the element's <span data-x="concept-fe-api-value">API value</span>; on setting, it must set
the element's <span data-x="concept-textarea-raw-value">raw value</span> to the new value, set the
element's <span data-x="concept-fe-dirty">dirty value flag</span> to true, and should then move
the text entry cursor position to the end of the text control, unselecting any selected text and
resetting the selection direction to <i>none</i>.</p>
return the element's <span data-x="concept-fe-api-value">API value</span>. On setting, it must
perform the following steps:</p>

<ol>
<li><p>Set this element's <span data-x="concept-textarea-raw-value">raw value</span> to the new
value.</p></li>

<li><p>Set this element's <span data-x="concept-fe-dirty">dirty value flag</span> to
true.</p></li>

<li><p>Move the text entry cursor position to the end of the text control, unselecting any
selected text and <span data-x="set the selection direction">resetting the selection
direction</span> to "<code data-x="">none</code>".</p></li>
</ol>

<p>The <dfn><code data-x="dom-textarea-textLength">textLength</code></dfn> IDL attribute must
return the <span>code-unit length</span> of the element's <span data-x="concept-fe-api-value">API
Expand Down Expand Up @@ -54244,21 +54262,29 @@ MIT Room 32-G524
and <code>textarea</code> elements must be implemented in terms of the DOM API described in this
section, so that, e.g., all the same events fire.</p>

<p>The selections of <code>input</code> and <code>textarea</code> elements have a <dfn>selection
direction</dfn>, which is either "<code data-x="">forward</code>", "<code
data-x="">backward</code>", or "<code data-x="">none</code>". This direction is set when the user
manipulates the selection. The exact meaning of the selection direction depends on the platform.
To <dfn>set the selection direction</dfn> of an element to a given direction, update the element's
<span>selection direction</span> to the given direction, unless the direction is "<code
data-x="">none</code>" and the platform does not support that direction; in that case, update the
element's <span>selection direction</span> to "<code data-x="">forward</code>".</p>

<p>The selections of <code>input</code> and <code>textarea</code> elements have a
<i>direction</i>, which is either <i>forward</i>, <i>backward</i>, or <i>none</i>. This direction
is set when the user manipulates the selection. The exact meaning of the selection direction
depends on the platform.</p>
<div class="note">
<p>On Windows, the direction indicates the position of the caret relative to
the selection: a "<code data-x="">forward</code>" selection has the caret at the end of the
selection and a "<code data-x="">backward</code>" selection has the caret at the start of the
selection. Windows has no "<code data-x="">none</code>" direction.</p>

<p class="note">On Windows, the direction indicates the position of the caret relative to the
selection: a <i>forward</i> selection has the caret at the end of the selection and a
<i>backward</i> selection has the caret at the start of the selection. Windows has no <i>none</i>
direction. On Mac, the direction indicates which end of the selection is affected when the user
adjusts the size of the selection using the arrow keys with the Shift modifier: the forward
direction means the end of the selection is modified, and the backwards direction means the start
of the selection is modified. The none direction is the default on Mac, it indicates that no
particular direction has yet been selected. The user sets the direction implicitly when first
adjusting the selection, based on which directional arrow key was used.</p>
<p>On Mac, the direction indicates which end of the selection is affected when the user adjusts
the size of the selection using the arrow keys with the Shift modifier: the "<code
data-x="">forward</code>" direction means the end of the selection is modified, and the "<code
data-x="">backward</code>" direction means the start of the selection is modified. The "<code
data-x="">none</code>" direction is the default on Mac, it indicates that no particular direction
has yet been selected. The user sets the direction implicitly when first adjusting the selection,
based on which directional arrow key was used.</p>
</div>


<p>The <dfn><code data-x="dom-textarea/input-select">select()</code></dfn> method, when invoked,
Expand Down Expand Up @@ -54352,20 +54378,7 @@ MIT Room 32-G524
data-x="dom-textarea/input-selectionDirection">selectionDirection</code> <span data-x="do not
apply">does not apply</span> to this element, return null.</p></li>

<li>
<p>Return a string determined by switching on the current selection direction:</p>

<dl class="switch">
<dt><i>forward</i></dt>
<dd>"<code data-x="">forward</code>"</dd>

<dt><i>backward</i></dt>
<dd>"<code data-x="">backward</code>"</dd>

<dt><i>none</i></dt>
<dd>"<code data-x="">none</code>"</dd>
</dl>
</li>
<li><p>Return this element's <span>selection direction</span>.</p></li>
</ol>

<p>The <code data-x="dom-textarea/input-selectionDirection">selectionDirection</code> attribute's
Expand Down Expand Up @@ -54414,17 +54427,20 @@ MIT Room 32-G524
at the end of the text control. If <var>end</var> is less than or equal to <var>start</var> then
the start of the selection and the end of the selection must both be placed immediately before
the character with offset <var>end</var>. In UAs where there is no concept of an empty selection,
this must set the cursor to be just before the character with offset <var>end</var>. The
direction of the selection must be set to <i>backward</i> if <var>direction</var> is a
<span>case-sensitive</span> match for the string "<code data-x="">backward</code>",
<i>forward</i> if <var>direction</var> is a <span>case-sensitive</span> match for the string
"<code data-x="">forward</code>" or if the platform does not support selections with the
direction <i>none</i>, and <i>none</i> otherwise (including if the argument is omitted).</p></li>

<li><p>If the previous step caused the selection of the text control to be modified (in either
extent or direction), then <span>queue a task</span>, using the <span>user interaction task
source</span>, to <span data-x="concept-event-fire">fire an event</span> named <code
data-x="event-select">select</code> at the element, with the <code
this must set the cursor to be just before the character with offset <var>end</var>.</p></li>

<li><p>If <var>direction</var> is not a <span>case-sensitive</span> match for either the string
"<code data-x="">backward</code>" or "<code data-x="">forward</code>", or if the
<var>direction</var> argument was omitted, set <var>direction</var> to "<code
data-x="">none</code>".</p></li>

<li><p><span>Set the selection direction</span> of the text control to
<var>direction</var>.</p></li>

<li><p>If the previous steps caused the selection of the text control to be modified (in either
extent or <span data-x="selection direction">direction</span>), then <span>queue a task</span>,
using the <span>user interaction task source</span>, to <span data-x="concept-event-fire">fire an
event</span> named <code data-x="event-select">select</code> at the element, with the <code
data-x="dom-Event-bubbles">bubbles</code> attribute initialized to true.</p></li>

</ol>
Expand Down

0 comments on commit af9fa0f

Please sign in to comment.