Bug 1199161 - Add selectedTextContent to CaretStateChangedEvent. r=kanru, sr=smaug
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 16 Sep 2015 17:58:14 +0800
changeset 295703 0cd2bdcae8ce
parent 295702 0dde53859911
child 295704 7941c5a6c7a6
push id5245
push userraliiev@mozilla.com
push date2015-10-29 11:30 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskanru, smaug
bugs1199161
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
dom/browser-element/BrowserElementCopyPaste.js
dom/browser-element/BrowserElementParent.js
dom/webidl/CaretStateChangedEvent.webidl
layout/base/AccessibleCaretManager.cpp
--- a/dom/browser-element/BrowserElementCopyPaste.js
+++ b/dom/browser-element/BrowserElementCopyPaste.js
@@ -67,17 +67,18 @@ var CopyPasteAssistent = {
         canCopy: this._isCommandEnabled("copy"),
         canPaste: this._isCommandEnabled("paste"),
       },
       zoomFactor: zoomFactor,
       reason: e.reason,
       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.
     let currentWindow = e.target.defaultView;
     while (currentWindow.realFrameElement) {
       let currentRect = currentWindow.realFrameElement.getBoundingClientRect();
       detail.rect.top += currentRect.top;
       detail.rect.bottom += currentRect.top;
--- a/dom/browser-element/BrowserElementParent.js
+++ b/dom/browser-element/BrowserElementParent.js
@@ -454,16 +454,18 @@ BrowserElementParent.prototype = {
   //  - zoomFactor: Current zoom factor in child frame.
   //  - reason: The reason causes the state changed. Include "visibilitychange",
   //            "updateposition", "longpressonemptycontent", "taponcaret", "presscaret",
   //            "releasecaret".
   //  - collapsed: Indicate current selection is collapsed or not.
   //  - 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);
 
     let self = this;
     function sendDoCommandMsg(cmd) {
       let data = { command: cmd };
       self._sendAsyncMsg('copypaste-do-command', data);
--- a/dom/webidl/CaretStateChangedEvent.webidl
+++ b/dom/webidl/CaretStateChangedEvent.webidl
@@ -15,20 +15,22 @@ enum CaretChangedReason {
 
 dictionary CaretStateChangedEventInit : EventInit {
   boolean collapsed = true;
   DOMRectReadOnly? boundingClientRect = null;
   CaretChangedReason reason = "visibilitychange";
   boolean caretVisible = false;
   boolean selectionVisible = false;
   boolean selectionEditable = false;
+  DOMString selectedTextContent = "";
 };
 
 [Constructor(DOMString type, optional CaretStateChangedEventInit eventInit),
  ChromeOnly]
 interface CaretStateChangedEvent : Event {
   readonly attribute boolean collapsed;
   readonly attribute DOMRectReadOnly? boundingClientRect;
   readonly attribute CaretChangedReason reason;
   readonly attribute boolean caretVisible;
   readonly attribute boolean selectionVisible;
   readonly attribute boolean selectionEditable;
+  readonly attribute DOMString selectedTextContent;
 };
--- a/layout/base/AccessibleCaretManager.cpp
+++ b/layout/base/AccessibleCaretManager.cpp
@@ -948,16 +948,17 @@ AccessibleCaretManager::DispatchCaretSta
   init.mSelectionEditable = commonAncestorFrame &&
     commonAncestorFrame->GetContent()->GetEditingHost();
 
   init.mBoundingClientRect = domRect;
   init.mReason = aReason;
   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);
 
   event->SetTrusted(true);
   event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
 
   AC_LOG("%s: reason %d, collapsed %d, caretVisible %d", __FUNCTION__,