Bug 1199161 - Add selectedTextContent to CaretStateChangedEvent. r=kanru, sr=smaug

The old SelectionStateChangedEvent dispatched by SelectionChanged had
this field, but it has not being ported to CaretStateChangedEvent. We
should include selected text in the event so that Gaia could have a
chance to enhance user experience.

--HG--
extra : rebase_source : 7304b71e251e2ee081192340b8f86f22bf6e03a6
This commit is contained in:
Ting-Yu Lin 2015-09-16 17:58:14 +08:00
parent 05364ae706
commit 63aeeea1b1
4 changed files with 7 additions and 1 deletions

View File

@ -72,7 +72,8 @@ var CopyPasteAssistent = {
collapsed: e.collapsed,
caretVisible: e.caretVisible,
selectionVisible: e.selectionVisible,
selectionEditable: e.selectionEditable
selectionEditable: e.selectionEditable,
selectedTextContent: e.selectedTextContent
};
// Get correct geometry information if we have nested iframe.

View File

@ -459,6 +459,8 @@ BrowserElementParent.prototype = {
// - caretVisible: Indicate the caret visiibility.
// - selectionVisible: Indicate current selection is visible or not.
// - selectionEditable: Indicate current selection is editable or not.
// - selectedTextContent: Contains current selected text content, which is
// equivalent to the string returned by Selection.toString().
_handleCaretStateChanged: function(data) {
let evt = this._createEvent('caretstatechanged', data.json,
/* cancelable = */ false);

View File

@ -20,6 +20,7 @@ dictionary CaretStateChangedEventInit : EventInit {
boolean caretVisible = false;
boolean selectionVisible = false;
boolean selectionEditable = false;
DOMString selectedTextContent = "";
};
[Constructor(DOMString type, optional CaretStateChangedEventInit eventInit),
@ -31,4 +32,5 @@ interface CaretStateChangedEvent : Event {
readonly attribute boolean caretVisible;
readonly attribute boolean selectionVisible;
readonly attribute boolean selectionEditable;
readonly attribute DOMString selectedTextContent;
};

View File

@ -953,6 +953,7 @@ AccessibleCaretManager::DispatchCaretStateChangedEvent(CaretChangedReason aReaso
init.mCollapsed = sel->IsCollapsed();
init.mCaretVisible = mFirstCaret->IsLogicallyVisible() ||
mSecondCaret->IsLogicallyVisible();
sel->Stringify(init.mSelectedTextContent);
nsRefPtr<CaretStateChangedEvent> event =
CaretStateChangedEvent::Constructor(doc, NS_LITERAL_STRING("mozcaretstatechanged"), init);