element
as parameter and fires
goog.events.PasteHandler.EventType.PASTE
events when text is
pasted in the element
. Uses heuristics to detect paste events in FF2.
See more details of the heuristic on #handleEvent_
.
goog.Disposable | |
goog.events.EventTarget | goog.Disposable |
goog.events.PasteHandler | goog.events.EventTarget |
element
: Element
The textarea element we are listening on.
|
Checks whether the element.value property was updated, and if so, dispatches
the event that let clients know that the text is available.
Returns: boolean
Whether the polling should stop or not, based on whether
we found a text change or not.
|
code » | ||
![]()
Dispatches the paste event.
Arguments:
|
code » | ||
![]()
No description.
|
code » | ||
Returns the event handler.
Returns: goog.events.EventHandler.<T>
The event handler.
|
code » | ||
![]()
Returns the current state of the paste detection algorithm. Used mostly for
testing.
Returns: goog.events.PasteHandler.State
The current state of the class.
|
code » | ||
![]()
The main event handler which implements a state machine.
To handle FF2, we enumerate and cover all the known ways a user can paste:
1) ctrl+v, shift+insert, cmd+v
2) right click -> paste
3) edit menu -> paste
4) drag and drop
5) middle click
(1) is easy and can be detected by listening for key events and finding out
which keys are pressed. (2), (3), (4) and (5) do not generate a key event,
so we need to listen for more than that. (2-5) all generate 'input' events,
but so does key events. So we need to have some sort of 'how did the input
event was generated' history algorithm.
(2) is an interesting case in Opera on a Mac: since Macs does not have two
buttons, right clicking involves pressing the CTRL key. Even more interesting
is the fact that opera does NOT set the e.ctrlKey bit. Instead, it sets
e.keyCode = 0.
http://www.quirksmode.org/js/keys.html
(1) is also an interesting case in Opera on a Mac: Opera is the only browser
covered by this class that can detect the cmd key (FF2 can't apparently). And
it fires e.keyCode = 17, which is the CTRL key code.
http://www.quirksmode.org/js/keys.html
NOTE(user, pbarry): There is an interesting thing about (5): on Linux, (5)
pastes the last thing that you highlighted, not the last thing that you
ctrl+c'ed. This code will still generate a PASTE event though.
We enumerate all the possible steps a user can take to paste text and we
implemented the transition between the steps in a state machine. The
following is the design of the state machine:
matching paths:
(1) happens on INIT -> FOCUSED -> TYPING -> [e.ctrlKey & e.keyCode = 'v']
(2-3) happens on INIT -> FOCUSED -> [input event happened]
(4) happens on INIT -> [mouseover && text changed]
non matching paths:
user is typing normally
INIT -> FOCUS -> TYPING -> INPUT -> INIT
Arguments:
|
code » | ||
![]() goog.events.PasteHandler.EventType.FOCUSED is typically the second
state the textarea will be, which is followed by the INIT state. On
this state, users can paste in three different ways: edit -> paste,
right click -> paste and drag and drop.
The latter will generate a goog.events.EventType.MOUSEOVER event,
which we match by making sure the textarea text changed. The first two will
generate an 'input', which we match by making sure it was NOT generated by a
key event (which also generates an 'input' event).
Unfortunately, in Firefox, if you type fast, some KEYDOWN events are
swallowed but an INPUT event may still happen. That means we need to
differentiate between two consecutive INPUT events being generated either by
swallowed key events OR by a valid edit -> paste -> edit -> paste action. We
do this by checking a minimum time between the two events. This heuristic
seems to work well, but it is obviously a heuristic :).
Arguments:
|
code » | ||
![]() goog.events.PasteHandler.EventType.INIT is the first initial state
the textarea is found. You can only leave this state by setting focus on the
textarea, which is how users will input text. You can also paste things using
drag and drop, which will not generate a goog.events.EventType.FOCUS
event, but will generate a goog.events.EventType.MOUSEOVER .
For browsers that support the 'paste' event, we match it and stay on the same
state.
Arguments:
|
code » | ||
![]() goog.events.PasteHandler.EventType.TYPING is the third state
this class can be. It exists because each KEYPRESS event will ALSO generate
an INPUT event (because the textarea value changes), and we need to
differentiate between an INPUT event generated by a key event and an INPUT
event generated by edit -> paste actions.
This is the state that we match the ctrl+v pattern.
Arguments:
|
code » |
![]()
Use
#listen instead, when possible. Otherwise, use
goog.events.listen if you are passing Object
(instead of Function) as handler.
Adds an event listener to the event target. The same handler can only be
added once per the type. Even if you add the same handler multiple times
using the same type then it will only be called once when the event is
dispatched.
Arguments:
|
code » | |||||
![]()
Asserts that the event target instance is initialized properly.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
Removes listeners from this object. Classes that extend EventTarget may
need to override this method in order to remove references to DOM Elements
and additional listeners.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » | |||||
Returns the parent of this event target to use for bubbling.
Returns: goog.events.EventTarget
The parent EventTarget or null if
there is no parent.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
Use
#unlisten instead, when possible. Otherwise, use
goog.events.unlisten if you are passing Object
(instead of Function) as handler.
Removes an event listener from the event target. The handler must be the
same object as the one added. If the handler has not been added then
nothing is done.
Arguments:
|
code » | |||||
![]()
Sets the parent of this event target to use for capture/bubble
mechanism.
Arguments:
|
code » | |||||
![]()
Sets the target to be used for
event.target when firing
event. Mainly used for testing. For example, see
goog.testing.events.mixinListenable .
Arguments:
|
code » | |||||
![]()
No description.
|
code » | |||||
![]()
No description.
|
code » |
![]()
Invokes a callback function when this object is disposed. Callbacks are
invoked in the order in which they were added.
Arguments:
|
code » | |||
![]()
Disposes of the object. If the object hasn't already been disposed of, calls
#disposeInternal . Classes that extend goog.Disposable should
override #disposeInternal in order to delete references to COM
objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void
Nothing.
|
code » | |||
![]()
Deletes or nulls out any references to COM objects, DOM nodes, or other
disposable objects. Classes that extend
goog.Disposable should
override this method.
Not reentrant. To avoid calling it twice, it must only be called from the
subclass' disposeInternal method. Everywhere else the public
dispose method must be used.
For example:
mypackage.MyClass = function() { mypackage.MyClass.base(this, 'constructor'); // Constructor logic specific to MyClass. ... }; goog.inherits(mypackage.MyClass, goog.Disposable); mypackage.MyClass.prototype.disposeInternal = function() { // Dispose logic specific to MyClass. ... // Call superclass's disposeInternal at the end of the subclass's, like // in C++, to avoid hard-to-catch issues. mypackage.MyClass.base(this, 'disposeInternal'); }; |
code » | |||
Use
#isDisposed instead.
No description.
Returns: boolean
Whether the object has been disposed of.
|
code » | |||
No description.
Returns: boolean
Whether the object has been disposed of.
|
code » | |||
![]()
Associates a disposable object with this object so that they will be disposed
together.
Arguments:
|
code » |
![]()
No description.
|
Code » | |
ConditionalDelay used to poll for changes in the text element once users
paste text. Browsers fire paste events BEFORE the text is actually present
in the element.value property.
|
Code » | |
![]()
The element that you want to listen for paste events on.
|
Code » | |
Handler for events.
|
Code » | |
![]()
The last time an event occurred on the element. Kept to check whether the
last event was generated by two input events or by multiple fast key events
that got swallowed. See more details on
#handleEvent_ .
|
Code » | |
A logger, used to help us debug the algorithm.
|
Code » | |
![]()
The last known value of the element. Kept to check if things changed. See
more details on
#handleEvent_ .
|
Code » | |
![]()
The previous event that caused us to be on the current state.
|
Code » | |
![]()
The initial state of the paste detection algorithm.
|
Code » |
The object to use for event.target. Useful when mixing in an
EventTarget to another object.
|
Code » | |
![]()
No description.
|
Code » | |
Maps of event type to an array of listeners.
|
Code » | |
Parent event target, used during event bubbling.
TODO(user): Change this to goog.events.Listenable. This
currently breaks people who expect getParentEventTarget to return
goog.events.EventTarget.
|
Code » |
![]()
The mandatory delay we expect between two
input events, used to
differentiated between non key paste events and key events.
|
Code » | |
![]()
The period between each time we check whether the pasted text appears in the
text element or not.
|
Code » | |
![]()
The maximum amount of time we want to poll for changes.
|
Code » | |
![]()
No description.
|
Code » |
![]()
The types of events fired by this class.
Constants:
|
Code » | ||||
![]()
The states that this class can be found, on the paste detection algorithm.
Constants:
|
Code » |