Bug 1130891 part 3 - Add param to HTMLCopy to allow copy with ruby annotation. r=smaug
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 10 Mar 2015 17:11:55 +1100
changeset 261534 209982f6fccbb853568786df85dd6a2eca0cb8d1
parent 261533 90727c00a60a64150f448be307f7e800eabea3be
child 261535 94d5173fa1cd9979498b225419d8b8c42a6e9955
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1130891
milestone39.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 1130891 part 3 - Add param to HTMLCopy to allow copy with ruby annotation. r=smaug
dom/base/nsCopySupport.cpp
dom/base/nsCopySupport.h
layout/generic/nsSelection.cpp
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -143,17 +143,18 @@ SelectionCopyHelper(nsISelection *aSel, 
     textPlainBuf.Assign(buf);
   } else {
     // Redo the encoding, but this time use pretty printing.
     flags =
       nsIDocumentEncoder::OutputSelectionOnly |
       nsIDocumentEncoder::OutputAbsoluteLinks |
       nsIDocumentEncoder::SkipInvisibleContent |
       nsIDocumentEncoder::OutputDropInvisibleBreak |
-      (aFlags & nsIDocumentEncoder::OutputNoScriptContent);
+      (aFlags & (nsIDocumentEncoder::OutputNoScriptContent |
+                 nsIDocumentEncoder::OutputRubyAnnotation));
 
     mimeType.AssignLiteral(kTextMime);
     rv = docEncoder->Init(domDoc, mimeType, flags);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = docEncoder->SetSelection(aSel);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -268,21 +269,23 @@ SelectionCopyHelper(nsISelection *aSel, 
       }
     }
   }
   return rv;
 }
 
 nsresult
 nsCopySupport::HTMLCopy(nsISelection* aSel, nsIDocument* aDoc,
-                        int16_t aClipboardID)
+                        int16_t aClipboardID, bool aWithRubyAnnotation)
 {
-  return SelectionCopyHelper(aSel, aDoc, true, aClipboardID,
-                             nsIDocumentEncoder::SkipInvisibleContent,
-                             nullptr);
+  uint32_t flags = nsIDocumentEncoder::SkipInvisibleContent;
+  if (aWithRubyAnnotation) {
+    flags |= nsIDocumentEncoder::OutputRubyAnnotation;
+  }
+  return SelectionCopyHelper(aSel, aDoc, true, aClipboardID, flags, nullptr);
 }
 
 nsresult
 nsCopySupport::GetTransferableForSelection(nsISelection* aSel,
                                            nsIDocument* aDoc,
                                            nsITransferable** aTransferable)
 {
   return SelectionCopyHelper(aSel, aDoc, false, 0,
@@ -686,17 +689,17 @@ nsCopySupport::FireClipboardEvent(int32_
   if (doDefault) {
     // get the data from the selection if any
     bool isCollapsed;
     sel->GetIsCollapsed(&isCollapsed);
     if (isCollapsed) {
       return false;
     }
     // call the copy code
-    rv = HTMLCopy(sel, doc, aClipboardType);
+    rv = HTMLCopy(sel, doc, aClipboardType, false);
     if (NS_FAILED(rv)) {
       return false;
     }
   } else if (clipboardData) {
     // check to see if any data was put on the data transfer.
     clipboardData->GetMozItemCount(&count);
     if (count) {
       nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1"));
--- a/dom/base/nsCopySupport.h
+++ b/dom/base/nsCopySupport.h
@@ -18,17 +18,18 @@ class nsACString;
 class nsAString;
 class nsIPresShell;
 class nsILoadContext;
 
 class nsCopySupport
 {
   // class of static helper functions for copy support
   public:
-    static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc, int16_t aClipboardID);
+    static nsresult HTMLCopy(nsISelection *aSel, nsIDocument *aDoc,
+                             int16_t aClipboardID, bool aWithRubyAnnotation);
     static nsresult DoHooks(nsIDocument *aDoc, nsITransferable *aTrans,
                             bool *aDoPutOnClipboard);
 
     // Get the selection, or entire document, in the format specified by the mime type
     // (text/html or text/plain). If aSel is non-null, use it, otherwise get the entire
     // doc.
     static nsresult GetContents(const nsACString& aMimeType, uint32_t aFlags, nsISelection *aSel, nsIDocument *aDoc, nsAString& outdata);
     
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -6120,10 +6120,11 @@ nsAutoCopyListener::NotifySelectionChang
     /* clear X clipboard? */
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
   NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
   // call the copy code
-  return nsCopySupport::HTMLCopy(aSel, doc, nsIClipboard::kSelectionClipboard);
-}
+  return nsCopySupport::HTMLCopy(aSel, doc,
+                                 nsIClipboard::kSelectionClipboard, false);
+}