[webkit-dev] Programmatically Selecting a DOMRange in a WebView and New WebKit-Related Bug in Apple Mail

Steven Schuldt sws at outspring.com
Wed Jul 5 13:02:54 PDT 2006


All:

I've been unable to programmatically select a DOMRange in a WebView  
(this on Mac OS X 10.4.7).  I'm trying to emulate the behavior one  
can see in an editable WebView such as in Mail.app's compose window  
where the user can click on an image (to begin a drag for example)  
and the WebView immediately selects the image prior to the drag  
action.  The simple case fails:

	DOMRange *range = [myWebView editableDOMRangeForPoint: [[self  
window] convertScreenToBase:[NSEvent mouseLocation]]];	
	[range collapse:NO];
	[ myWebView setSelectedDOMRange:range affinity:[myWebView  
selectionAffinity]];

And worse, there appears to be a bug (or an undocumented API change)  
whereby the WebEditingDelegate method:

- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange: 
(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange  
affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL) 
flag;

WebEditingDelegate method is no longer called.

Also: The latest changes to WebKit's editing capabilities as Apple  
now distributes them with 10.4.7 have broken something fundamental in  
DOMRange selection.  Whatever hack Apple used to use to perform the  
above magic I'm trying to emulate has itself broken now.  To see the  
bug, drag a few small images into Mail.app.  Now try to move them  
around by dragging them to rearrange their order.  Note how Mail.app  
programmatically selects two images instead of just the one you're  
dragging.

Any pointers appreciated.  Thanks!

Steven





More information about the webkit-dev mailing list