Skip to content

Add Selection API #601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4528,6 +4528,10 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf<Element>;
/**
* Returns an object representing the current selection of the document that is loaded into the object displaying a webpage.
*/
getSelection(): Selection | null;
/**
* Gets a value indicating whether the object currently has focus.
*/
Expand Down Expand Up @@ -4583,9 +4587,6 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par
* @param content The text and HTML tags to write.
*/
writeln(...text: string[]): void;
/**
* Returns an object representing the current selection of the document that is loaded into the object displaying a webpage.
*/
addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -5408,6 +5409,8 @@ interface GlobalEventHandlersEventMap {
"seeked": Event;
"seeking": Event;
"select": Event;
"selectionchange": Event;
"selectstart": Event;
"stalled": Event;
"submit": Event;
"suspend": Event;
Expand Down Expand Up @@ -5655,6 +5658,8 @@ interface GlobalEventHandlers {
* @param ev The event.
*/
onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null;
onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
/**
* Occurs when the download has stopped.
* @param ev The event.
Expand Down Expand Up @@ -14461,32 +14466,27 @@ declare var SecurityPolicyViolationEvent: {

/** A Selection object represents the range of text selected by the user or the current position of the caret. To obtain a Selection object for examination or modification, call Window.getSelection(). */
interface Selection {
readonly anchorNode: Node;
readonly anchorNode: Node | null;
readonly anchorOffset: number;
readonly baseNode: Node;
readonly baseOffset: number;
readonly extentNode: Node;
readonly extentOffset: number;
readonly focusNode: Node;
readonly focusNode: Node | null;
readonly focusOffset: number;
readonly isCollapsed: boolean;
readonly rangeCount: number;
readonly type: string;
addRange(range: Range): void;
collapse(parentNode: Node, offset: number): void;
collapse(node: Node | null, offset?: number): void;
collapseToEnd(): void;
collapseToStart(): void;
containsNode(node: Node, partlyContained: boolean): boolean;
containsNode(node: Node, allowPartialContainment?: boolean): boolean;
deleteFromDocument(): void;
empty(): void;
extend(newNode: Node, offset: number): void;
extend(node: Node, offset?: number): void;
getRangeAt(index: number): Range;
removeAllRanges(): void;
removeRange(range: Range): void;
selectAllChildren(parentNode: Node): void;
setBaseAndExtent(baseNode: Node, baseOffset: number, extentNode: Node, extentOffset: number): void;
setPosition(parentNode: Node, offset: number): void;
toString(): string;
selectAllChildren(node: Node): void;
setBaseAndExtent(anchorNode: Node, anchorOffset: number, focusNode: Node, focusOffset: number): void;
setPosition(node: Node | null, offset?: number): void;
}

declare var Selection: {
Expand Down Expand Up @@ -16979,7 +16979,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
focus(): void;
getComputedStyle(elt: Element, pseudoElt?: string | null): CSSStyleDeclaration;
getMatchedCSSRules(elt: Element, pseudoElt?: string | null): CSSRuleList;
getSelection(): Selection;
getSelection(): Selection | null;
matchMedia(query: string): MediaQueryList;
moveBy(x: number, y: number): void;
moveTo(x: number, y: number): void;
Expand Down Expand Up @@ -17855,7 +17855,7 @@ declare function departFocus(navigationReason: NavigationReason, origin: FocusNa
declare function focus(): void;
declare function getComputedStyle(elt: Element, pseudoElt?: string | null): CSSStyleDeclaration;
declare function getMatchedCSSRules(elt: Element, pseudoElt?: string | null): CSSRuleList;
declare function getSelection(): Selection;
declare function getSelection(): Selection | null;
declare function matchMedia(query: string): MediaQueryList;
declare function moveBy(x: number, y: number): void;
declare function moveTo(x: number, y: number): void;
Expand Down Expand Up @@ -18117,6 +18117,8 @@ declare var onseeking: ((this: Window, ev: Event) => any) | null;
* @param ev The event.
*/
declare var onselect: ((this: Window, ev: Event) => any) | null;
declare var onselectionchange: ((this: Window, ev: Event) => any) | null;
declare var onselectstart: ((this: Window, ev: Event) => any) | null;
/**
* Occurs when the download has stopped.
* @param ev The event.
Expand Down
38 changes: 38 additions & 0 deletions inputfiles/idl/Selection.widl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
interface Selection {
readonly attribute Node? anchorNode;
readonly attribute unsigned long anchorOffset;
readonly attribute Node? focusNode;
readonly attribute unsigned long focusOffset;
readonly attribute boolean isCollapsed;
readonly attribute unsigned long rangeCount;
readonly attribute DOMString type;
Range getRangeAt(unsigned long index);
void addRange(Range range);
void removeRange(Range range);
void removeAllRanges();
void empty();
void collapse(Node? node, optional unsigned long offset = 0);
void setPosition(Node? node, optional unsigned long offset = 0);
void collapseToStart();
void collapseToEnd();
void extend(Node node, optional unsigned long offset = 0);
void setBaseAndExtent(Node anchorNode, unsigned long anchorOffset, Node focusNode, unsigned long focusOffset);
void selectAllChildren(Node node);
[CEReactions]
void deleteFromDocument();
boolean containsNode(Node node, optional boolean allowPartialContainment = false);
stringifier DOMString ();
};

partial interface Document {
Selection? getSelection();
};

partial interface Window {
Selection? getSelection();
};

partial interface GlobalEventHandlers {
attribute EventHandler onselectstart;
attribute EventHandler onselectionchange;
};
4 changes: 4 additions & 0 deletions inputfiles/idlSources.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@
"url": "https://www.w3.org/TR/screen-orientation/",
"title": "Screen Orientation"
},
{
"url": "https://www.w3.org/TR/selection-api/",
"title": "Selection"
},
{
"url": "https://w3c.github.io/ServiceWorker/",
"title": "Service Workers"
Expand Down