[webkit-dev] DOMRange and khtml::Selection direction

Timothy Hatcher timothy at hatcher.name
Sun Aug 14 08:24:21 PDT 2005


Why not use NSSelectionGranularity? The only thing missing from that  
is line granularity.

— Timothy Hatcher


On Aug 14, 2005, at 11:13 AM, Duncan Wilcox wrote:

> So far I have added support for this:
>
> typedef enum {
>     WebTextSelectForward,
>     WebTextSelectBackward
> } WebTextSelectionDirection;
>
> typedef enum {
>     WebTextSelectByCharacter,
>     WebTextSelectByWord,
>     WebTextSelectByLine,
>     WebTextSelectByParagraph
> } WebTextSelectionGranularity;
>
> @interface WebSelection : NSObject
> {
>     DOMRange *range;
>     NSSelectionAffinity affinity;
>     WebTextSelectionDirection direction;
>     WebTextSelectionGranularity granularity;
> }
>
> + (id)webSelectionWithRange:(DOMRange *)selectionRange affinity: 
> (NSSelectionAffinity)selectionAffinity direction: 
> (WebTextSelectionDirection)selectionDirection granularity: 
> (WebTextSelectionGranularity)selectionGranularity;
> - (DOMRange *)range;
> - (void)setRange:(DOMRange *)newRange;
> - (NSSelectionAffinity)affinity;
> - (void)setAffinity:(NSSelectionAffinity)newAffinity;
> - (WebTextSelectionDirection)direction;
> - (void)setDirection:(WebTextSelectionDirection)newDirection;
> - (WebTextSelectionGranularity)granularity;
> - (void)setGranularity:(WebTextSelectionGranularity)newGranularity;
>
> @end
>
> @interface WebView (WebPendingPublic)
> - (void)setSelection:(WebSelection *)selection;
> - (WebSelection *)selection;
> @end
>
> @interface NSObject (WebEditingDelegatePendingPublic)
> - (BOOL)webView:(WebView *)webView shouldChangeSelection: 
> (WebSelection *)current toSelection:(WebSelection *)proposed  
> stillSelecting:(BOOL)flag;
> @end
>
> The original problem of dragging backwards with the mouse is mostly  
> solved, except for when the selection granularity is not character.
>
> What I think is happening is that the khtml::Selection m_base and  
> m_extent contain text range the mouse actually dragged over, while  
> m_start and m_end contain the same selection expanded with the  
> current granularity.
>
> Again, this information is not being carried through neither the  
> DOMRange nor the WebSelection, so when dragging over some text with  
> a delegate like this:
>
> - (BOOL)webView:(WebView *)webView shouldChangeSelection: 
> (WebSelection *)current toSelection:(WebSelection *)proposed  
> stillSelecting:(BOOL)flag
> {
>     [webView setSelection:proposed];
>     return NO;
> }
>
> what happens is that the granularity-expanded selection is re- 
> expanded at every mouse drag event, because the programmatically  
> set selection doesn't have the correct m_base/m_extent, and the  
> selection quickly expands all the way to the end of line (and on to  
> the end of page).
>
> So the issue is extending the WebSelection to add this state  
> information, but I'm unsure about what might be the best way.  
> Clearly adding m_base and m_extent (as DOMNode *node; long offset;  
> pairs), would mean the direction becomes redundant. Another option  
> would be retaining the direction and adding a straightened m_base/ 
> m_extent pair encoded as a DOMRange, that would contain the non- 
> expanded selection.
>
> Ideas?
>
> Thanks,
> Duncan
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at opendarwin.org
> http://www.opendarwin.org/mailman/listinfo/webkit-dev
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/webkit-dev/attachments/20050814/395848ab/attachment.html


More information about the webkit-dev mailing list