W3C home > Mailing lists > Public > www-style@w3.org > May 2011

Re: [CSSOM] does CaretPosition need a "before/after" hint?

From: Andrew Fedoniouk <andrew.fedoniouk@live.com>
Date: Thu, 12 May 2011 23:17:13 -0700
Message-ID: <BLU165-ds252F241F9671CAB3F09F6F8880@phx.gbl>
To: "Ryosuke Niwa" <rniwa@webkit.org>, "Andrew Fedoniouk" <news@terrainformatica.com>
Cc: "Ojan Vafai" <ojan@chromium.org>, "Robert O'Callahan" <robert@ocallahan.org>, "Julie Parent" <jparent@chromium.org>, "Eric Seidel" <eseidel@chromium.org>, <www-style@w3.org>, "Levi Weintraub" <leviw@chromium.org>, "Xiaomei Ji" <xji@google.com>
  From: Ryosuke Niwa 
  Sent: Thursday, May 12, 2011 9:53 PM
  To: Andrew Fedoniouk
  Cc: Ojan Vafai ; Robert O'Callahan ; Julie Parent ; Eric Seidel ; www-style@w3.org ; Levi Weintraub ; Xiaomei Ji
  Subject: Re: [CSSOM] does CaretPosition need a "before/after" hint?
  On Thu, May 12, 2011 at 9:05 PM, Andrew Fedoniouk <andrew.fedoniouk@live.com> wrote: 
    In general object that represents caret position in HTML should have following interface:
  Where did you get this interface? There are many flaws in this design. To name a few:
    interface CaretPosition
    bool atCharacter() ;
    // true – character input at given position will not change DOM structure.
    // false – the caret is positioned on “head” or “tail” of DOM element.
  The method name and comment say two different things.
Could you be more specific? What exactly is different there?
    bool atTail() ;
    // true – this is the “tail” position – either on the tail of DOM element
    // or on “after” edge of the character.
    // false – this is the head position of the element or character.
    Element currentElement(); // element containing the CP
    TextNode currentTextNode(); // TextNode, valid if atCharacter() == true.
  I don't think currentElement makes much sense. If you're at <hr>|<br>, what is the current element? br because the position is before br? But then what would you do in the case of <div><hr>|</div>?
There are four "physical" caret positions in this markup:

  1.. start of <hr>, position on the left (direction:ltr), currentElement here is <hr> 
  2.. end of <hr>, postion on the right, currentElement here is <hr> 
  3.. start of <br>, currentElement is <br>  (if <br> is DOM element) 
  4.. end of <br>, currentElement is <br>.
It is up to UA and client code to decide how many caret stops will be there but physically there are four positions there, see below.

    bool isLess( CaretPosition other ) // true if this position is less than other.
    bool isLessVisual( CaretPosition other ) // true if this position visually less than other.
  What does it mean to say X is visually less than Y? Does that mean the other appears before this position? Is that in visual order? Or in logical order? What if the text were oriented vertically? What if X was in a absolutely positioned div and Y was in another absolutely positioned div?
isLess - in logical order,  isLessVisual - in visual order.  For caret positions in RTL runs these are different. In LTR - result is usually the same.
    bool isEqualTo( CaretPosition other ) // true if this position and other position
    // will end up in the same rectangle on the canvas.
  Why are we talking about canvas? Also can't we just use == operator for this? Also, a position shouldn't be a rectangle.
Consider this character sequence: "AB" (two characters). If you click [by mouse] between two characters it is possible 
that you will get either 'A/after' or 'B/before' positions. Visually these two positions may end up in the same caret rectangle but 
they are different. For example if the position will be `B/before` then ideally you should show oblique caret and set "current editing registers" to 'italic'.
All  these depends on what quality of WYSIWYG you are going to achieve of course. In my editors I use logics above.
    bool fromXY( coord x, coord y, ... ) // true if the position is set to closest one to x,y.
  This method seems completely arbitrary and impossible to implement. What does it mean to say it's closest? What should I return if multiple caret positions are away from (x,y) with the same distance?
fromXY is in fact a cap of bunch of functions (Note '...' there).  Main purpose of is to find caret position while handling onMouseDown/onTouchEnd.
Any WYSIWYG editor implements this method in one form or another so I do not understand why you think it is “impossible”.
  - Ryosuke

Andrew Fedoniouk

Received on Friday, 13 May 2011 06:17:45 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:38:45 UTC