From f60ebed9b7f450666adf939a86eb0e613d8e239a Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Tue, 12 Sep 2017 11:24:43 +0200 Subject: [PATCH 1/2] [cssom-view] Add notIfViewed to ScrollIntoViewOptions; add FocusScrollOptions notIfViewed was originally suggested in http://www.w3.org/mid/CAE3TfZPmNWvz1z7XPqFjtg5S+m_9BOmNNHsOZuSrR2z2AgyNHA@mail.gmail.com Now it is needed for HTMLElement focus(options) to match the behavior of focus() in browsers. Since the defaults for focus() is different from the defaults for scrollIntoView(), a new dictionary FocusScrollOptions is introduced. For now the defaults for block and inline are UA-defined. https://github.com/whatwg/html/pull/2787#issuecomment-328397430 --- cssom-view-1/Overview.bs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/cssom-view-1/Overview.bs b/cssom-view-1/Overview.bs index d3e5a95df6f2..00c32eea4a52 100644 --- a/cssom-view-1/Overview.bs +++ b/cssom-view-1/Overview.bs @@ -1065,9 +1065,15 @@ Note: This {{DOMRect}} object is not live.
 enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
 dictionary ScrollIntoViewOptions : ScrollOptions {
+  boolean notIfViewed = false;
   ScrollLogicalPosition block = "start";
   ScrollLogicalPosition inline = "nearest";
 };
+dictionary FocusScrollOptions : ScrollOptions {
+  boolean notIfViewed = true;
+  ScrollLogicalPosition block;
+  ScrollLogicalPosition inline;
+};
 
 partial interface Element {
   DOMRectList getClientRects();
@@ -1090,6 +1096,13 @@ partial interface Element {
 };
 
+The {{ScrollIntoViewOptions}} dictionary is used by {{Element/scrollIntoView()}} and similar APIs +that primarily scroll something into view. + +The {{FocusScrollOptions}} dictionary is similar to {{ScrollIntoViewOptions}}, but has different +defaults, and is used by {{HTMLElement}}'s {{HTMLElement/focus()}} and similar APIs that primarily +move focus to something, or equivalent, and secondarily scroll it into view. + The getClientRects() method, when invoked, must return the result of the following algorithm: 1. If the element on which it was invoked does not have an associated layout box return an empty {{DOMRectList}} object and stop this algorithm. @@ -1130,14 +1143,16 @@ The scrollIntoView(arg 1. Let behavior be "auto". 1. Let block be "start". 1. Let inline be "nearest". +1. Let notIfViewed be false. 1. If arg is a {{ScrollIntoViewOptions}} dictionary, then: 1. Set behavior to the {{ScrollOptions/behavior}} dictionary member of options. 1. Set block to the {{ScrollIntoViewOptions/block}} dictionary member of options. 1. Set inline to the {{ScrollIntoViewOptions/inline}} dictionary member of options. + 1. Set notIfViewed to the {{ScrollIntoViewOptions/notIfViewed}} dictionary member of options. 1. Otherwise, if arg is false, then set block to "end". 1. If the element does not have any associated layout box, then return. 1. Scroll the element into view - with behavior, block, and inline. + with behavior, block, inline, and notIfViewed. 1. Optionally perform some other action that brings the element to the user's attention. The scroll() method must run these steps: @@ -1290,8 +1305,9 @@ The clientHeight attribute must run these steps To scroll an element into view element, with a scroll behavior behavior, -a block flow direction position block, -and an inline base direction position inline, +a boolean indicating to not scroll if the element is already in view notIfViewed, +optionally a block flow direction position block (undefined if not given), +and optionally an inline base direction position inline (undefined if not given), means to run these steps for each ancestor element or viewport that establishes a scrolling box scrolling box, in order of innermost to outermost scrolling box: @@ -1305,6 +1321,15 @@ a scrolling box scrolling box, in order of innermost to outerm 1. Let scrolling box height be the distance between scrolling box edge A and scrolling box edge B. 1. Let element width be the distance between element edge C and element edge D. 1. Let scrolling box width be the distance between scrolling box edge C and scrolling box edge D. +1. If notIfViewed is true, and element is entirely in view already, then return. + + ISSUE: Define "entirely in view". + +1. If block is undefined, set block to a UA-defined value. +1. If inline is undefined, set inline to a UA-defined value. + + ISSUE: Define defaults for block and inline for {{FocusScrollOptions}}. + 1. Let position be the scroll position scrolling box would have by following these steps: 1. If block is "start", then align element edge A with scrolling box edge A. From 6ff3c4d1bd9aed0741f4920e32a00d9394ca4802 Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Wed, 13 Sep 2017 15:58:31 +0200 Subject: [PATCH 2/2] Change notIfViewed to scroll:"always"/"if-needed" --- cssom-view-1/Overview.bs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cssom-view-1/Overview.bs b/cssom-view-1/Overview.bs index 00c32eea4a52..73a0c6c01621 100644 --- a/cssom-view-1/Overview.bs +++ b/cssom-view-1/Overview.bs @@ -1063,14 +1063,15 @@ Note: This {{DOMRect}} object is not live.

Extensions to the {{Element}} Interface

+enum ScrollIntoViewMode { "always", "if-needed" };
 enum ScrollLogicalPosition { "start", "center", "end", "nearest" };
 dictionary ScrollIntoViewOptions : ScrollOptions {
-  boolean notIfViewed = false;
+  ScrollIntoViewMode scroll = "always";
   ScrollLogicalPosition block = "start";
   ScrollLogicalPosition inline = "nearest";
 };
 dictionary FocusScrollOptions : ScrollOptions {
-  boolean notIfViewed = true;
+  ScrollIntoViewMode scroll = "if-needed";
   ScrollLogicalPosition block;
   ScrollLogicalPosition inline;
 };
@@ -1143,16 +1144,16 @@ The scrollIntoView(arg
 1. Let behavior be "auto".
 1. Let block be "start".
 1. Let inline be "nearest".
-1. Let notIfViewed be false.
+1. Let scrollMode be "always".
 1. If arg is a {{ScrollIntoViewOptions}} dictionary, then:
     1. Set behavior to the {{ScrollOptions/behavior}} dictionary member of options.
     1. Set block to the {{ScrollIntoViewOptions/block}} dictionary member of options.
     1. Set inline to the {{ScrollIntoViewOptions/inline}} dictionary member of options.
-    1. Set notIfViewed to the {{ScrollIntoViewOptions/notIfViewed}} dictionary member of options.
+    1. Set scrollMode to the {{ScrollIntoViewOptions/scroll}} dictionary member of options.
 1. Otherwise, if arg is false, then set block to "end".
 1. If the element does not have any associated layout box, then return.
 1. Scroll the element into view
-    with behavior, block, inline, and notIfViewed.
+    with behavior, block, inline, and scrollMode.
 1. Optionally perform some other action that brings the element to the user's attention.
 
 The scroll() method must run these steps:
@@ -1305,7 +1306,7 @@ The clientHeight attribute must run these steps
 
 To scroll an element into view element,
 with a scroll behavior behavior,
-a boolean indicating to not scroll if the element is already in view notIfViewed,
+a mode indicating whether to scroll if the element is already in view scrollMode,
 optionally a block flow direction position block (undefined if not given),
 and optionally an inline base direction position inline (undefined if not given),
 means to run these steps for each ancestor element or viewport that establishes
@@ -1321,7 +1322,7 @@ a scrolling box scrolling box, in order of innermost to outerm
 1. Let scrolling box height be the distance between scrolling box edge A and scrolling box edge B.
 1. Let element width be the distance between element edge C and element edge D.
 1. Let scrolling box width be the distance between scrolling box edge C and scrolling box edge D.
-1. If notIfViewed is true, and element is entirely in view already, then return.
+1. If scrollMode is "if-needed", and element is entirely in view already, then return.
 
         ISSUE: Define "entirely in view".