New issue
Advanced search Search tips

Issue 830044 link

Starred by 4 users

Issue metadata

Status: Available
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Mac
Pri: 3
Type: Bug



Sign in to add a comment

A range with collapsed selection in an empty element returns an empty array from getClientRects() and a bounding rectangle with zeroed properties

Reported by ishi...@gmail.com, Apr 6 2018

Issue description

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

Steps to reproduce the problem:
See linked JsFiddle which illustrates the issue:
https://jsfiddle.net/hozkkjqq/27/

1. Place cursor into an empty content editable element with no text.
2. Get window seletion.
3. Get range at index 0.
4. Call range's bounding client rectangle.

What is the expected behavior?
As I read the spec, this return the client rectangles of the containing element since the selection is collapsed and the start and end containers are not text nodes.
https://drafts.csswg.org/cssom-view/#dom-range-getclientrects

In particular:
"For each element selected by the range, whose parent is not selected by the range, include the border areas returned by invoking getClientRects() on the element."

What went wrong?
It returns an DOMRect with all properties set to 0 (x, y, width, height, top, left, right, bottom).

This feels wrong since this range is in the DOM, is rendered and should have an x & y coordinate along with top, left, right, bottom.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 65.0.3325.181  Channel: stable
OS Version: OS X 10.13.4
Flash Version: 

This isn't exactly helpful but I believe this used to return either null or what I believe is the expected behavior. Something changed around Chrome 63.

Seems to be related to this bug as well:
https://bugs.chromium.org/p/chromium/issues/detail?id=637296
 
Labels: -Pri-2 Pri-3
Status: Available (was: Unconfirmed)
For the same reason in crbug.com/637296#5, I think this is a spec bug.

With collapsed range in empty DIV, the range doesn't select any element. So "For each element selected by the range" ends up working on nothing.

Comment 2 by ishi...@gmail.com, Apr 6 2018

Thanks, I'll try moving the conversation there by filing an issue on the spec.

Sign in to add a comment