clipboard events

2010-12-23 Thread Hallvord R. M. Steen

Hi,
looking at what Opera needs to support I drafted a specish text for  
clipboard events. Something for this WG?


--
Hallvord R. M. Steen, Core Tester, Opera Software
http://www.opera.com http://my.opera.com/hallvors/Title:  Clipboard API and events 





Clipboard API and events
Status of this document
This is a Clipboard API event specification draft edited by Hallvord R. M. Steen, Opera Software. Although I've used W3C stylesheets for convenience this spec is not currently adopted by the W3C.

Events
copy event
When the user initiates a copy operation, the implementation must fire a copy event. Its default action is to place the selected data on the clipboard. If there is no selection, the event has no default action.



	
		Typecopy
		InterfaceClipboardEvent
		CancelableYes
		BubblesYes
		TargetElements
	



cut event
When the user initiates a cut operation, the implementation must fire a cut event. In an editable context, its default action is to place the selected data on the clipboard and remove the selection from the document.


In a non-editable context, or if there is no selection, the cut event has no default action.





	
		Typecut
		InterfaceClipboardEvent
		CancelableYes
		BubblesYes
		TargetElements
	



paste event
When the user initiates a paste operation, the implementation must fire a paste event.





If the cursor is in an editable element, the default action is to insert clipboard data in the most suitable format supported for the given context.

In an editable context, the paste event's target property refers to the element that contains the start of the selection.


In a non-editable document, the event is targeted at a node focused by clicking or by an interactive cursor. If the node that has focus is not a text node, the event is targeted at the BODY element.

 The paste event has no default action in a non-editable context.





	
		Typepaste
		InterfaceClipboardEvent
		CancelableYes
		BubblesYes
		TargetElement
	



Interface ClipboardData
How should we define the relationship to the HTML5 DataTransfer interface? Can DataTransfer inherit from ClipboardData and add the drag-and-drop stuff, or should we just defer to HTML5 for all of this? 
IDL definition

interface ClipboardData {
void clearData( in optional DOMString type );
DOMString getData(in DOMString type);
void setData(in DOMString type, in DOMString data);
DOMStringList types;
}



Attributes
types

The types property returns a DOMStringList of MIME type strings. [RFC2046]. In the paste event, it lists those formats available on the clipboard the implementation supports returning to the script.  In the copy and cut events, the types property returns a list of supported formats for the copy operation - for example, if the implementation supports copying plain text and HTML it would return a DOMStringList with the values 'text/plain' and 'text/html'.

The order of these values is undefined.
This .types spec is slightly different from the HTML5 DnD .types - consistent enough to make sense to authors and implementers?
Methods
getData
Calling getData() from within a paste event handler will return the clipboard data in the specified format. An implementation must support 'text/plain' and should support 'text/html' to retrieve any HTML formatted data on the system clipboard.

If getData() is not called from within a paste event handler, or if the type is not available, the method returns undefined. Note: IE allows this, but it seems to go against user expectations



HTML5 says return empty string if data of that type is not found. WebKit returns undefined though..
If the method is called with too many or too few arguments, it throws a syntax error exception.

Note: for compatibility purposes, the value 'text' (case-insensitive) must be treated as 'text/plain'.


setData
Method exists in WebKit but doesn't seem to do anything
Calling setData() from within an event handler will modify the data which will be placed on the clipboard, for the specified format.


If the type argument is not supported, the setData() call does nothing.
setData() with unsupported type throws in IE

Calling setData() from a paste event handler will modify the data before it is inserted. Not what WebKit does (but its support for setData() is non-existant anyway). IE does this.

The default action of a copy and cut event is to place the selection on the clipboard. Hence, after calling setData() the script must cancel the default action of the event, otherwise the data placed on the clipboard with the setData() call will immediately be overwritten by the default action.






clearData
Calling clearData() empties the system clipboard if no argument is given, and removes the specified type of data from the clipboard if called with the optional type argument.





Clipboard event interface
IDL definition
interface ClipboardEvent : Event {
  readonly attribute ClipboardData clipboardData;
  void initClipboardEvent( in DOMString 

Re: clipboard events

2010-12-23 Thread Dmitry Titov
Sounds reasonable, and close to what IE and WebKit implement...

Seems the clipboardData object may simply implement
dataTransferhttp://dev.w3.org/html5/spec/dnd.html#the-datatransfer-interfaceinterface.
This would give it legacy setData/getData as well as
items http://dev.w3.org/html5/spec/dnd.html#datatransferitems list which
can be used for blob-backed reads/writes.

The list of formats that can be found in dataTransfer, although limited now,
will probably grow in the future to enable better integration between
applications (XML Spreadsheet or image for example). I can imagine a web
app that wants to support copy/paste with popular products like MS Office...
Many of those are not suitable for getData() that returns a string, because
they are long/async in nature and/or binary. They will need to be
transferred as blobs or files.

Dmitry

On Thu, Dec 23, 2010 at 7:35 AM, Hallvord R. M. Steen hallv...@opera.comwrote:

 Hi,
 looking at what Opera needs to support I drafted a specish text for
 clipboard events. Something for this WG?

 --
 Hallvord R. M. Steen, Core Tester, Opera Software
 http://www.opera.com http://my.opera.com/hallvors/


Added 'locale' to Text, Keyboard, and Composition Events [ISSUE-119]

2010-12-23 Thread Doug Schepers

Hi, folks-

In the latest draft of DOM3 Events [1], I have added a 'locale' 
attribute to the KeyboardEvent, CompositionEvent, and TextEvent 
interfaces, as agreed in telcons and at TPAC.


I took the liberty of renaming 'inputLocale' to 'locale', since most 
developers prefer shorter, nonCamelCased names, and it seems equally 
descriptive.


Please let us know if this satisfies your issue.

[1] http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html

Regards-
-Doug Schepers
W3C Team Contact, SVG, WebApps, and Web Events WGs