[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/protocol.txt

Mihai Varga mihai.mv13 at gmail.com
Wed Jun 24 08:08:38 PDT 2015


 loolwsd/LOOLProtocol.hpp |    3 ++-
 loolwsd/LOOLSession.cpp  |   27 +++++++++++++++++++++++++--
 loolwsd/LOOLSession.hpp  |    1 +
 loolwsd/protocol.txt     |    8 ++++++++
 4 files changed, 36 insertions(+), 3 deletions(-)

New commits:
commit e8007ea405318ca8048c7487e2d4f0ede72597ee
Author: Mihai Varga <mihai.mv13 at gmail.com>
Date:   Wed Jun 24 18:08:15 2015 +0300

    Server getTextSelection implementation

diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp
index 4aad0b3..42e82df 100644
--- a/loolwsd/LOOLProtocol.hpp
+++ b/loolwsd/LOOLProtocol.hpp
@@ -31,8 +31,9 @@ namespace LOOLProtocol
     // "commands".
 
     // Not sure if these enums will be needed
-    enum class Command 
+    enum class Command
     {
+        GETTEXTSELECTION,
         KEY,
         LOAD,
         MOUSE,
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index a485482..67a2bcf 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -240,6 +240,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
         return loadDocument(buffer, length, tokens);
     }
     else if (tokens[0] != "canceltiles" &&
+             tokens[0] != "gettextselection" &&
              tokens[0] != "invalidatetiles" &&
              tokens[0] != "key" &&
              tokens[0] != "mouse" &&
@@ -697,7 +698,8 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
         // All other commands are such that they always require a LibreOfficeKitDocument session,
         // i.e. need to be handled in a child process.
 
-        assert(tokens[0] == "key" ||
+        assert(tokens[0] == "gettextselection" ||
+               tokens[0] == "key" ||
                tokens[0] == "mouse" ||
                tokens[0] == "uno" ||
                tokens[0] == "selecttext" ||
@@ -705,7 +707,11 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
                tokens[0] == "resetselection" ||
                tokens[0] == "saveas");
 
-        if (tokens[0] == "key")
+        if (tokens[0] == "gettextselection")
+        {
+            return getTextSelection(buffer, length, tokens);
+        }
+        else if (tokens[0] == "key")
         {
             return keyEvent(buffer, length, tokens);
         }
@@ -910,6 +916,23 @@ void ChildProcessSession::sendTile(const char *buffer, int length, StringTokeniz
     sendBinaryFrame(output.data(), output.size());
 }
 
+bool ChildProcessSession::getTextSelection(const char *buffer, int length, StringTokenizer& tokens)
+{
+    std::string mimeType;
+
+    if (tokens.count() != 2 ||
+        !getTokenString(tokens[1], "mimetype", mimeType))
+    {
+        sendTextFrame("error: cmd=gettextselection kind=syntax");
+        return false;
+    }
+
+    char *textSelection = _loKitDocument->pClass->getTextSelection(_loKitDocument, mimeType.c_str(), NULL);
+
+    sendTextFrame("textselectioncontent: " + std::string(textSelection));
+    return true;
+}
+
 bool ChildProcessSession::keyEvent(const char *buffer, int length, StringTokenizer& tokens)
 {
     int type, charcode, keycode;
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 4e7e3dd..221de8b 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -166,6 +166,7 @@ public:
 
     virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens);
 
+    bool getTextSelection(const char *buffer, int length, Poco::StringTokenizer& tokens);
     bool keyEvent(const char *buffer, int length, Poco::StringTokenizer& tokens);
     bool mouseEvent(const char *buffer, int length, Poco::StringTokenizer& tokens);
     bool unoCommand(const char *buffer, int length, Poco::StringTokenizer& tokens);
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index 74af6c3..491dc9d 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -17,6 +17,10 @@ canceltiles
     dropped and will not be handled. There is no guarantee of exactly
     which tile: messages might still be sent back to the client.
 
+gettextselection mimetype=<mimeType>
+
+    Request selection's content
+
 invalidatetiles part=<partNumber> tileposx=<xpos> tileposy=<ypos> tilewidth=<tileWidth> tileheight=<tileHeight>
 
     All parameters are numbers. Makes the server remove any cached
@@ -100,6 +104,10 @@ status: type=<typeName> parts=<numberOfParts> current=<currentPartNumber> width=
 
     <typeName> is 'text, 'spreadsheet', 'presentation', 'drawing' or 'other. Others are numbers.
 
+textselectioncontent: <content>
+
+    Current selection's content
+
 tile: part=<partNumber> width=<width> height=<height> tileposx=<xpos> tileposy=<ypos> tilewidth=<tileWidth> tileheight=<tileHeight>
 <binaryPngImage>
 


More information about the Libreoffice-commits mailing list