[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3-0' - 2 commits - common/Message.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp kit/KitHelper.hpp loleaflet/src tools/KitClient.cpp wsd/ClientSession.cpp
Pranav Kant
pranavk at collabora.co.uk
Tue Dec 5 11:09:08 UTC 2017
common/Message.hpp | 3
kit/ChildSession.cpp | 137 +++++++-------
kit/ChildSession.hpp | 6
kit/Kit.cpp | 2
kit/KitHelper.hpp | 7
loleaflet/src/control/Control.LokDialog.js | 273 ++++++++++++++---------------
loleaflet/src/core/Socket.js | 2
loleaflet/src/layer/tile/TileLayer.js | 42 ----
tools/KitClient.cpp | 3
wsd/ClientSession.cpp | 9
10 files changed, 222 insertions(+), 262 deletions(-)
New commits:
commit bca349f5da691925b11031e3bcfba2065187df19
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Tue Dec 5 00:41:02 2017 +0530
lokdialog: Use dialog close LOK API when user clicks 'X'
Change-Id: I3a90eb8b83688eed7db8228763633e31f82e58d1
(cherry picked from commit 53fc694a3c413684179c4cf1026b2c6d3e8959ef)
Reviewed-on: https://gerrit.libreoffice.org/45846
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 7de22985..4a804aac 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -13,6 +13,9 @@
#include <sstream>
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Parser.h>
#include <Poco/Net/WebSocket.h>
@@ -233,7 +236,8 @@ bool ChildSession::_handleInput(const char *buffer, int length)
tokens[0] == "resetselection" ||
tokens[0] == "saveas" ||
tokens[0] == "useractive" ||
- tokens[0] == "userinactive");
+ tokens[0] == "userinactive" ||
+ tokens[0] == "windowcommand");
if (tokens[0] == "clientzoom")
{
@@ -311,6 +315,10 @@ bool ChildSession::_handleInput(const char *buffer, int length)
{
setIsActive(false);
}
+ else if (tokens[0] == "windowcommand")
+ {
+ sendWindowCommand(buffer, length, tokens);
+ }
else
{
assert(false && "Unknown command token.");
@@ -1005,6 +1013,25 @@ bool ChildSession::renderWindow(const char* /*buffer*/, int /*length*/, const st
return true;
}
+
+bool ChildSession::sendWindowCommand(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
+{
+ std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
+ getLOKitDocument()->setView(_viewId);
+
+ unsigned winId = 0;
+ if (tokens.size() > 1)
+ {
+ std::istringstream reader(tokens[1]);
+ reader >> winId;
+ }
+
+ if (tokens.size() > 2 && tokens[2] == "close")
+ getLOKitDocument()->postWindow(winId, LOK_WINDOW_CLOSE);
+
+ return true;
+}
+
bool ChildSession::selectGraphic(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
{
int type, x, y;
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 47c79421..c0ca190d 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -198,6 +198,7 @@ private:
bool saveAs(const char* buffer, int length, const std::vector<std::string>& tokens);
bool setClientPart(const char* buffer, int length, const std::vector<std::string>& tokens);
bool setPage(const char* buffer, int length, const std::vector<std::string>& tokens);
+ bool sendWindowCommand(const char* buffer, int length, const std::vector<std::string>& tokens);
void rememberEventsForInactiveUser(const int type, const std::string& payload);
diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js
index 9a0729a2..1c5fbe9f 100644
--- a/loleaflet/src/control/Control.LokDialog.js
+++ b/loleaflet/src/control/Control.LokDialog.js
@@ -61,13 +61,17 @@ L.Control.LokDialog = L.Control.extend({
return [x, y, width, height].join(',');
},
- _sendWindowCommand: function(id, rectangle) {
+ _sendPaintWindow: function(id, rectangle) {
if (rectangle)
rectangle = rectangle.replace(/ /g, '');
this._map._socket.sendMessage('paintwindow ' + id + (rectangle ? ' rectangle=' + rectangle : ''));
},
+ _sendCloseWindow: function(id) {
+ this._map._socket.sendMessage('windowcommand ' + id + ' close');
+ },
+
_isRectangleValid: function(rect) {
rect = rect.split(',');
if (parseInt(rect[0]) < 0 || parseInt(rect[1]) < 0 || parseInt(rect[2]) < 0 || parseInt(rect[3]) < 0)
@@ -84,7 +88,7 @@ L.Control.LokDialog = L.Control.extend({
this._width = width;
this._height = height;
this._launchDialog(this._toDlgPrefix(e.id));
- this._sendWindowCommand(e.id, this._createRectStr());
+ this._sendPaintWindow(e.id, this._createRectStr());
} else if (e.winType === 'child') {
if (!this._isOpen(e.parentId))
return;
@@ -100,7 +104,7 @@ L.Control.LokDialog = L.Control.extend({
this._dialogs[parentId].childx = left;
this._dialogs[parentId].childy = top;
this._createDialogChild(e.id, parentId, top, left);
- this._sendWindowCommand(e.id, this._createRectStr(0, 0, width, height));
+ this._sendPaintWindow(e.id, this._createRectStr(0, 0, width, height));
}
} else if (e.action === 'invalidate') {
var parent = this._getParentDialog(e.id);
@@ -114,7 +118,7 @@ L.Control.LokDialog = L.Control.extend({
if (!rectangle)
rectangle = '0,0,' + this._width + ',' + this._height;
}
- this._sendWindowCommand(e.id, rectangle);
+ this._sendPaintWindow(e.id, rectangle);
} else if (e.action === 'size_changed') {
this._width = parseInt(e.size.split(',')[0]);
this._height = parseInt(e.size.split(',')[1]);
@@ -125,7 +129,7 @@ L.Control.LokDialog = L.Control.extend({
$('#' + strDlgId).remove();
this._launchDialog(strDlgId);
$('#' + strDlgId).dialog('option', 'title', this._title);
- this._sendWindowCommand(e.id, this._createRectStr());
+ this._sendPaintWindow(e.id, this._createRectStr());
} else if (e.action === 'cursor_invalidate') {
if (this._isOpen(e.id) && !!e.rectangle) {
var rectangle = e.rectangle.split(',');
@@ -151,7 +155,7 @@ L.Control.LokDialog = L.Control.extend({
if (parent)
this._onDialogChildClose(this._toDlgPrefix(parent));
else
- this._onDialogClose(e.id);
+ this._onDialogClose(e.id, false);
}
},
@@ -181,7 +185,7 @@ L.Control.LokDialog = L.Control.extend({
resizable: false,
dialogClass: 'lokdialog_container',
close: function() {
- that._onDialogClose(strDlgId);
+ that._onDialogClose(that._toRawDlgId(strDlgId), true);
}
});
@@ -265,7 +269,9 @@ L.Control.LokDialog = L.Control.extend({
}
},
- _onDialogClose: function(dialogId) {
+ _onDialogClose: function(dialogId, notifyBackend) {
+ if (notifyBackend)
+ this._sendCloseWindow(dialogId);
$('#' + this._toDlgPrefix(dialogId)).remove();
this._map.focus();
delete this._dialogs[dialogId];
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b607ed0f..2bba11cf 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -156,7 +156,8 @@ bool ClientSession::_handleInput(const char *buffer, int length)
tokens[0] != "uno" &&
tokens[0] != "useractive" &&
tokens[0] != "userinactive" &&
- tokens[0] != "paintwindow")
+ tokens[0] != "paintwindow" &&
+ tokens[0] != "windowcommand")
{
sendTextFrame("error: cmd=" + tokens[0] + " kind=unknown");
return false;
commit c9c426e2bcd9a1586c3c4ca1add7049d79e21904
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Mon Dec 4 22:13:50 2017 +0530
lokdialog: Adapt to LOK dialog API changes
Change-Id: I653304e71573eb253e09a72bc87d54b8554ba7ff
(cherry picked from commit 849eb0d500f549c6feb4eae7d5bba1710945678b)
Reviewed-on: https://gerrit.libreoffice.org/45845
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/common/Message.hpp b/common/Message.hpp
index bfd38cb7..cfca3f81 100644
--- a/common/Message.hpp
+++ b/common/Message.hpp
@@ -131,8 +131,7 @@ private:
if (_tokens[0] == "tile:" ||
_tokens[0] == "tilecombine:" ||
_tokens[0] == "renderfont:" ||
- _tokens[0] == "dialogpaint:" ||
- _tokens[0] == "dialogchildpaint:")
+ _tokens[0] == "windowpaint:")
{
return Type::Binary;
}
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index ca4c855e..7de22985 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -202,9 +202,9 @@ bool ChildSession::_handleInput(const char *buffer, int length)
{
return getStatus(buffer, length);
}
- else if (tokens[0] == "dialog" || tokens[0] == "dialogchild")
+ else if (tokens[0] == "paintwindow")
{
- return renderDialog(buffer, length, tokens);
+ return renderWindow(buffer, length, tokens);
}
else if (tokens[0] == "tile" || tokens[0] == "tilecombine")
{
@@ -224,10 +224,9 @@ bool ChildSession::_handleInput(const char *buffer, int length)
tokens[0] == "paste" ||
tokens[0] == "insertfile" ||
tokens[0] == "key" ||
- tokens[0] == "dialogkey" ||
+ tokens[0] == "windowkey" ||
tokens[0] == "mouse" ||
- tokens[0] == "dialogmouse" ||
- tokens[0] == "dialogchildmouse" ||
+ tokens[0] == "windowmouse" ||
tokens[0] == "uno" ||
tokens[0] == "selecttext" ||
tokens[0] == "selectgraphic" ||
@@ -272,21 +271,17 @@ bool ChildSession::_handleInput(const char *buffer, int length)
{
return keyEvent(buffer, length, tokens, LokEventTargetEnum::Document);
}
- else if (tokens[0] == "dialogkey")
+ else if (tokens[0] == "windowkey")
{
- return keyEvent(buffer, length, tokens, LokEventTargetEnum::Dialog);
+ return keyEvent(buffer, length, tokens, LokEventTargetEnum::Window);
}
else if (tokens[0] == "mouse")
{
return mouseEvent(buffer, length, tokens, LokEventTargetEnum::Document);
}
- else if (tokens[0] == "dialogmouse")
+ else if (tokens[0] == "windowmouse")
{
- return mouseEvent(buffer, length, tokens, LokEventTargetEnum::Dialog);
- }
- else if (tokens[0] == "dialogchildmouse")
- {
- return mouseEvent(buffer, length, tokens, LokEventTargetEnum::DialogChild);
+ return mouseEvent(buffer, length, tokens, LokEventTargetEnum::Window);
}
else if (tokens[0] == "uno")
{
@@ -763,19 +758,19 @@ bool ChildSession::keyEvent(const char* /*buffer*/, int /*length*/,
const LokEventTargetEnum target)
{
int type, charcode, keycode;
- unsigned dialogId = 0;
+ unsigned winId = 0;
unsigned counter = 1;
unsigned expectedTokens = 4; // cmdname(key), type, char, key are strictly required
- if (target == LokEventTargetEnum::Dialog || target == LokEventTargetEnum::DialogChild)
+ if (target == LokEventTargetEnum::Window)
{
if (tokens.size() <= counter ||
- !getTokenUInt32(tokens[counter++], "dialogid", dialogId))
+ !getTokenUInt32(tokens[counter++], "id", winId))
{
- LOG_ERR("Dialog key event expects a valid dialogid= attribute");
+ LOG_ERR("Window key event expects a valid id= attribute");
sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax");
return false;
}
- else // dialogid= attribute is found
+ else // id= attribute is found
expectedTokens++;
}
@@ -812,8 +807,8 @@ bool ChildSession::keyEvent(const char* /*buffer*/, int /*length*/,
getLOKitDocument()->setView(_viewId);
getLOKitDocument()->postKeyEvent(type, charcode, keycode);
}
- else if (dialogId != 0)
- getLOKitDocument()->postDialogKeyEvent(dialogId, type, charcode, keycode);
+ else if (winId != 0)
+ getLOKitDocument()->postWindowKeyEvent(winId, type, charcode, keycode);
return true;
}
@@ -829,18 +824,18 @@ bool ChildSession::mouseEvent(const char* /*buffer*/, int /*length*/,
int buttons = 1; // left button
int modifier = 0;
- unsigned dialogId = 0;
+ unsigned winId = 0;
unsigned counter = 1;
unsigned minTokens = 5; // cmdname(mouse), type, x, y, count are strictly required
- if (target == LokEventTargetEnum::Dialog || target == LokEventTargetEnum::DialogChild)
+ if (target == LokEventTargetEnum::Window)
{
if (tokens.size() <= counter ||
- !getTokenUInt32(tokens[counter++], "dialogid", dialogId))
+ !getTokenUInt32(tokens[counter++], "id", winId))
{
- LOG_ERR("Dialog mouse event expects a valid dialogid= attribute");
+ LOG_ERR("Window mouse event expects a valid id= attribute");
success = false;
}
- else // dialogid= attribute is found
+ else // id= attribute is found
minTokens++;
}
@@ -879,11 +874,8 @@ bool ChildSession::mouseEvent(const char* /*buffer*/, int /*length*/,
getLOKitDocument()->setView(_viewId);
getLOKitDocument()->postMouseEvent(type, x, y, count, buttons, modifier);
break;
- case LokEventTargetEnum::Dialog:
- getLOKitDocument()->postDialogMouseEvent(dialogId, type, x, y, count, buttons, modifier);
- break;
- case LokEventTargetEnum::DialogChild:
- getLOKitDocument()->postDialogChildMouseEvent(dialogId, type, x, y, count, buttons, modifier);
+ case LokEventTargetEnum::Window:
+ getLOKitDocument()->postWindowMouseEvent(winId, type, x, y, count, buttons, modifier);
break;
default:
assert(false && "Unsupported mouse target type");
@@ -950,17 +942,16 @@ bool ChildSession::selectText(const char* /*buffer*/, int /*length*/, const std:
return true;
}
-bool ChildSession::renderDialog(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
+bool ChildSession::renderWindow(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens)
{
std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex());
getLOKitDocument()->setView(_viewId);
- const bool isChild = (tokens[0] == "dialogchild");
- unsigned dialogId = 0;
+ unsigned winId = 0;
if (tokens.size() > 1)
{
std::istringstream reader(tokens[1]);
- reader >> dialogId;
+ reader >> winId;
}
int startX = 0, startY = 0;
@@ -975,43 +966,27 @@ bool ChildSession::renderDialog(const char* /*buffer*/, int /*length*/, const st
bufferHeight = std::atoi(rectParts[3].c_str());
}
else
- LOG_WRN("dialog command doesn't specify a rectangle= attribute.");
+ LOG_WRN("windowpaint command doesn't specify a rectangle= attribute.");
size_t pixmapDataSize = 4 * bufferWidth * bufferHeight;
std::vector<unsigned char> pixmap(pixmapDataSize);
int width = bufferWidth, height = bufferHeight;
std::string response;
- if (isChild)
- {
- Timestamp timestamp;
-
- getLOKitDocument()->paintActiveFloatingWindow(dialogId, pixmap.data(), width, height);
- LOG_TRC("paintActiveFloatingWindow for dialogId [" << dialogId << "] returned floating window with size "
- << width << "X" << height << " "
- << "rendered in " << (timestamp.elapsed()/1000.)
- << "ms (" << (width * height) / (timestamp.elapsed()) << " MP/s).");
-
- response = "dialogchildpaint: id=" + tokens[1] + " width=" + std::to_string(width) + " height=" + std::to_string(height) + "\n";
- }
- else
- {
- Timestamp timestamp;
- getLOKitDocument()->paintDialog(dialogId, pixmap.data(), startX, startY, width, height);
-
- const double area = width * height;
- LOG_TRC("paintDialog for " << dialogId << " returned " << width << "X" << height
- << "@(" << startX << "," << startY << ")"
- << "and rendered in " << (timestamp.elapsed()/1000.)
- << "ms (" << area / (timestamp.elapsed()) << " MP/s).");
+ Timestamp timestamp;
+ getLOKitDocument()->paintWindow(winId, pixmap.data(), startX, startY, width, height);
+ const double area = width * height;
+ LOG_TRC("paintWindow for " << winId << " returned " << width << "X" << height
+ << "@(" << startX << "," << startY << ")"
+ << "and rendered in " << (timestamp.elapsed()/1000.)
+ << "ms (" << area / (timestamp.elapsed()) << " MP/s).");
- response = "dialogpaint: id=" + tokens[1] +
- " width=" + std::to_string(width) + " height=" + std::to_string(height);
+ response = "windowpaint: id=" + tokens[1] +
+ " width=" + std::to_string(width) + " height=" + std::to_string(height);
- if (!paintRectangle.empty())
- response += " rectangle=" + paintRectangle;
+ if (!paintRectangle.empty())
+ response += " rectangle=" + paintRectangle;
- response += "\n";
- }
+ response += "\n";
std::vector<char> output;
output.reserve(response.size() + pixmapDataSize);
@@ -1481,11 +1456,8 @@ void ChildSession::loKitCallback(const int type, const std::string& payload)
case LOK_CALLBACK_RULER_UPDATE:
sendTextFrame("rulerupdate: " + payload);
break;
- case LOK_CALLBACK_DIALOG:
- sendTextFrame("dialog: " + payload);
- break;
- case LOK_CALLBACK_DIALOG_CHILD:
- sendTextFrame("dialogchild: " + payload);
+ case LOK_CALLBACK_WINDOW:
+ sendTextFrame("window: " + payload);
break;
default:
LOG_ERR("Unknown callback event (" << type << "): " << payload);
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index ad9486a2..47c79421 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -29,8 +29,7 @@ class ChildSession;
enum class LokEventTargetEnum
{
Document,
- Dialog,
- DialogChild
+ Window
};
/// An abstract interface that defines the
@@ -194,7 +193,7 @@ private:
bool unoCommand(const char* buffer, int length, const std::vector<std::string>& tokens);
bool selectText(const char* buffer, int length, const std::vector<std::string>& tokens);
bool selectGraphic(const char* buffer, int length, const std::vector<std::string>& tokens);
- bool renderDialog(const char* buffer, int length, const std::vector<std::string>& tokens);
+ bool renderWindow(const char* buffer, int length, const std::vector<std::string>& tokens);
bool resetSelection(const char* buffer, int length, const std::vector<std::string>& tokens);
bool saveAs(const char* buffer, int length, const std::vector<std::string>& tokens);
bool setClientPart(const char* buffer, int length, const std::vector<std::string>& tokens);
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 02516ea3..234ffa13 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -2126,7 +2126,7 @@ void lokit_main(const std::string& childRoot,
TerminationFlag = true;
}
else if (tokens[0] == "tile" || tokens[0] == "tilecombine" || tokens[0] == "canceltiles" ||
- tokens[0] == "dialog" || tokens[0] == "dialogchild" ||
+ tokens[0] == "paintwindow" ||
LOOLProtocol::getFirstToken(tokens[0], '-') == "child")
{
if (document)
diff --git a/kit/KitHelper.hpp b/kit/KitHelper.hpp
index dccf2741..f3523a9f 100644
--- a/kit/KitHelper.hpp
+++ b/kit/KitHelper.hpp
@@ -113,11 +113,8 @@ namespace LOKitHelper
return "INVALIDATE_HEADER";
case LOK_CALLBACK_CELL_ADDRESS:
return "CELL_ADDRESS";
- case LOK_CALLBACK_DIALOG:
- return "DIALOG";
- case LOK_CALLBACK_DIALOG_CHILD:
- return "DIALOG_CHILD";
-
+ case LOK_CALLBACK_WINDOW:
+ return "WINDOW";
}
return std::to_string(type);
diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js
index 1de74937..9a0729a2 100644
--- a/loleaflet/src/control/Control.LokDialog.js
+++ b/loleaflet/src/control/Control.LokDialog.js
@@ -8,10 +8,8 @@ L.Control.LokDialog = L.Control.extend({
dialogIdPrefix: 'lokdialog-',
onAdd: function (map) {
- map.on('dialogpaint', this._onDialogPaint, this);
- map.on('dialogchildpaint', this._onDialogChildPaint, this);
- map.on('dialogchild', this._onDialogChildMsg, this);
- map.on('dialog', this._onDialogMsg, this);
+ map.on('window', this._onDialogMsg, this);
+ map.on('windowpaint', this._onDialogPaint, this);
map.on('opendialog', this._openDialog, this);
map.on('docloaded', this._docLoaded, this);
},
@@ -25,16 +23,29 @@ L.Control.LokDialog = L.Control.extend({
}
},
+ _getParentDialog: function(id) {
+ for (var winId in this._dialogs) {
+ if (this._dialogs[winId].childid && this._dialogs[winId].childid === id) {
+ return winId;
+ }
+ }
+ return null;
+ },
+
_isOpen: function(dialogId) {
return this._dialogs[dialogId] &&
this._dialogs[dialogId].open &&
- $('#' + dialogId).length > 0;
+ $('#' + this._toDlgPrefix(dialogId)).length > 0;
},
_toRawDlgId: function(dialogId) {
return dialogId.replace(this.dialogIdPrefix, '');
},
+ _toDlgPrefix: function(id) {
+ return this.dialogIdPrefix + id;
+ },
+
// Create a rectangle string of form "x,y,width,height"
// if params are missing, assumes 0,0,dialog width, dialog height
_createRectStr: function(x, y, width, height) {
@@ -50,17 +61,11 @@ L.Control.LokDialog = L.Control.extend({
return [x, y, width, height].join(',');
},
- _sendDialogCommand: function(dialogId, rectangle, child) {
- dialogId = dialogId.replace(this.dialogIdPrefix, '');
-
- var dialogCmd = 'dialog';
- if (child)
- dialogCmd = 'dialogchild';
-
+ _sendWindowCommand: function(id, rectangle) {
if (rectangle)
rectangle = rectangle.replace(/ /g, '');
- this._map._socket.sendMessage(dialogCmd + ' ' + dialogId + (rectangle ? ' rectangle=' + rectangle : ''));
+ this._map._socket.sendMessage('paintwindow ' + id + (rectangle ? ' rectangle=' + rectangle : ''));
},
_isRectangleValid: function(rect) {
@@ -71,53 +76,82 @@ L.Control.LokDialog = L.Control.extend({
},
_onDialogMsg: function(e) {
- e.dialogId = this.dialogIdPrefix + e.dialogId;
+ var strDlgId = this._toDlgPrefix(e.id);
if (e.action === 'created') {
- this._width = parseInt(e.size.split(',')[0]);
- this._height = parseInt(e.size.split(',')[1]);
- this._launchDialog(e.dialogId);
- this._sendDialogCommand(e.dialogId, this._createRectStr());
+ var width = parseInt(e.size.split(',')[0]);
+ var height = parseInt(e.size.split(',')[1]);
+ if (e.winType === 'dialog') {
+ this._width = width;
+ this._height = height;
+ this._launchDialog(this._toDlgPrefix(e.id));
+ this._sendWindowCommand(e.id, this._createRectStr());
+ } else if (e.winType === 'child') {
+ if (!this._isOpen(e.parentId))
+ return;
+
+ var parentId = parseInt(e.parentId);
+ var left = parseInt(e.position.split(',')[0]);
+ var top = parseInt(e.position.split(',')[1]);
+
+ this._removeDialogChild(parentId);
+ this._dialogs[parentId].childid = e.id;
+ this._dialogs[parentId].childwidth = width;
+ this._dialogs[parentId].childheight = height;
+ this._dialogs[parentId].childx = left;
+ this._dialogs[parentId].childy = top;
+ this._createDialogChild(e.id, parentId, top, left);
+ this._sendWindowCommand(e.id, this._createRectStr(0, 0, width, height));
+ }
} else if (e.action === 'invalidate') {
- if (this._isOpen(e.dialogId)) {
- if (e.rectangle && !this._isRectangleValid(e.rectangle))
+ var parent = this._getParentDialog(e.id);
+ var rectangle = e.rectangle;
+ if (parent) { // this is a floating window
+ rectangle = '0,0,' + this._dialogs[parent].childwidth + ',' + this._dialogs[parent].childheight;
+ } else { // this is the actual dialog
+ if (rectangle && !this._isRectangleValid(rectangle))
return;
- if (!e.rectangle)
- e.rectangle = '0,0,' + this._width + ',' + this._height;
- this._sendDialogCommand(e.dialogId, e.rectangle);
+ if (!rectangle)
+ rectangle = '0,0,' + this._width + ',' + this._height;
}
+ this._sendWindowCommand(e.id, rectangle);
} else if (e.action === 'size_changed') {
this._width = parseInt(e.size.split(',')[0]);
this._height = parseInt(e.size.split(',')[1]);
+ strDlgId = this._toDlgPrefix(e.id);
// FIXME: we don't really have to destroy and launch the dialog again but do it for
// now because the size sent to us previously in 'created' cb is not correct
- $('#' + e.dialogId).remove();
- this._launchDialog(e.dialogId);
- $('#' + e.dialogId).dialog('option', 'title', this._title);
- this._sendDialogCommand(e.dialogId, this._createRectStr());
+ $('#' + strDlgId).remove();
+ this._launchDialog(strDlgId);
+ $('#' + strDlgId).dialog('option', 'title', this._title);
+ this._sendWindowCommand(e.id, this._createRectStr());
} else if (e.action === 'cursor_invalidate') {
- if (this._isOpen(e.dialogId) && !!e.rectangle) {
+ if (this._isOpen(e.id) && !!e.rectangle) {
var rectangle = e.rectangle.split(',');
var x = parseInt(rectangle[0]);
var y = parseInt(rectangle[1]);
var height = parseInt(rectangle[3]);
- $('#' + e.dialogId + '-cursor').css({height: height});
+ $('#' + strDlgId + '-cursor').css({height: height});
// set the position of the lokdialog-cursor
- $(this._dialogs[e.dialogId].cursor).css({left: x, top: y});
+ $(this._dialogs[e.id].cursor).css({left: x, top: y});
}
} else if (e.action === 'title_changed') {
this._title = e.title;
- $('#' + e.dialogId).dialog('option', 'title', e.title);
+ $('#' + strDlgId).dialog('option', 'title', e.title);
} else if (e.action === 'cursor_visible') {
var visible = e.visible === 'true';
if (visible)
- $('#' + e.dialogId + '-cursor').css({display: 'block'});
+ $('#' + strDlgId + '-cursor').css({display: 'block'});
else
- $('#' + e.dialogId + '-cursor').css({display: 'none'});
+ $('#' + strDlgId + '-cursor').css({display: 'none'});
} else if (e.action === 'close') {
- this._onDialogClose(e.dialogId);
+ parent = this._getParentDialog(e.id);
+ if (parent)
+ this._onDialogChildClose(this._toDlgPrefix(parent));
+ else
+ this._onDialogClose(e.id);
}
},
@@ -126,19 +160,20 @@ L.Control.LokDialog = L.Control.extend({
},
_launchDialogCursor: function(dialogId) {
- this._dialogs[dialogId].cursor = L.DomUtil.create('div', 'leaflet-cursor-container', L.DomUtil.get(dialogId));
- var cursor = L.DomUtil.create('div', 'leaflet-cursor lokdialog-cursor', this._dialogs[dialogId].cursor);
+ var id = this._toRawDlgId(dialogId);
+ this._dialogs[id].cursor = L.DomUtil.create('div', 'leaflet-cursor-container', L.DomUtil.get(dialogId));
+ var cursor = L.DomUtil.create('div', 'leaflet-cursor lokdialog-cursor', this._dialogs[id].cursor);
cursor.id = dialogId + '-cursor';
L.DomUtil.addClass(cursor, 'blinking-cursor');
},
- _launchDialog: function(dialogId) {
- var canvas = '<div class="lokdialog" style="padding: 0px; margin: 0px; overflow: hidden;" id="' + dialogId + '">' +
- '<canvas class="lokdialog_canvas" tabindex="0" id="' + dialogId + '-canvas" width="' + this._width + 'px" height="' + this._height + 'px"></canvas>' +
+ _launchDialog: function(strDlgId) {
+ var canvas = '<div class="lokdialog" style="padding: 0px; margin: 0px; overflow: hidden;" id="' + strDlgId + '">' +
+ '<canvas class="lokdialog_canvas" tabindex="0" id="' + strDlgId + '-canvas" width="' + this._width + 'px" height="' + this._height + 'px"></canvas>' +
'</div>';
$(document.body).append(canvas);
var that = this;
- $('#' + dialogId).dialog({
+ $('#' + strDlgId).dialog({
width: this._width,
title: 'LOK Dialog', // TODO: Get the 'real' dialog title from the backend
modal: false,
@@ -146,59 +181,53 @@ L.Control.LokDialog = L.Control.extend({
resizable: false,
dialogClass: 'lokdialog_container',
close: function() {
- that._onDialogClose(dialogId);
+ that._onDialogClose(strDlgId);
}
});
- this._dialogs[dialogId] = { open: true };
+ this._dialogs[this._toRawDlgId(strDlgId)] = { open: true };
// don't make 'TAB' focus on this button; we want to cycle focus in the lok dialog with each TAB
$('.lokdialog_container button.ui-dialog-titlebar-close').attr('tabindex', '-1').blur();
- $('#' + dialogId + '-canvas').on('mousedown', function(e) {
+ $('#' + strDlgId + '-canvas').on('mousedown', function(e) {
var buttons = 0;
buttons |= e.button === map['mouse'].JSButtons.left ? map['mouse'].LOButtons.left : 0;
buttons |= e.button === map['mouse'].JSButtons.middle ? map['mouse'].LOButtons.middle : 0;
buttons |= e.button === map['mouse'].JSButtons.right ? map['mouse'].LOButtons.right : 0;
var modifier = 0;
- that._postDialogMouseEvent('buttondown', dialogId, e.offsetX, e.offsetY, 1, buttons, modifier);
+ that._postWindowMouseEvent('buttondown', strDlgId, e.offsetX, e.offsetY, 1, buttons, modifier);
});
- $('#' + dialogId + '-canvas').on('mouseup', function(e) {
+ $('#' + strDlgId + '-canvas').on('mouseup', function(e) {
var buttons = 0;
buttons |= e.button === map['mouse'].JSButtons.left ? map['mouse'].LOButtons.left : 0;
buttons |= e.button === map['mouse'].JSButtons.middle ? map['mouse'].LOButtons.middle : 0;
buttons |= e.button === map['mouse'].JSButtons.right ? map['mouse'].LOButtons.right : 0;
var modifier = 0;
- that._postDialogMouseEvent('buttonup', dialogId, e.offsetX, e.offsetY, 1, buttons, modifier);
+ that._postWindowMouseEvent('buttonup', strDlgId, e.offsetX, e.offsetY, 1, buttons, modifier);
});
- $('#' + dialogId + '-canvas').on('keyup keypress keydown', function(e) {
- e.dialogId = dialogId;
+ $('#' + strDlgId + '-canvas').on('keyup keypress keydown', function(e) {
+ e.strDlgId = strDlgId;
that._handleDialogKeyEvent(e);
});
- $('#' + dialogId + '-canvas').on('contextmenu', function() {
+ $('#' + strDlgId + '-canvas').on('contextmenu', function() {
return false;
});
- this._launchDialogCursor(dialogId);
+ this._launchDialogCursor(strDlgId);
},
- _postDialogMouseEvent: function(type, dialogid, x, y, count, buttons, modifier) {
- this._map._socket.sendMessage('dialogmouse dialogid=' + this._toRawDlgId(dialogid) + ' type=' + type +
+ _postWindowMouseEvent: function(type, winid, x, y, count, buttons, modifier) {
+ this._map._socket.sendMessage('windowmouse id=' + this._toRawDlgId(winid) + ' type=' + type +
' x=' + x + ' y=' + y + ' count=' + count +
' buttons=' + buttons + ' modifier=' + modifier);
},
- _postDialogKeyboardEvent: function(type, dialogid, charcode, keycode) {
- this._map._socket.sendMessage('dialogkey dialogid=' + this._toRawDlgId(dialogid) + ' type=' + type +
+ _postWindowKeyboardEvent: function(type, winid, charcode, keycode) {
+ this._map._socket.sendMessage('windowkey id=' + this._toRawDlgId(winid) + ' type=' + type +
' char=' + charcode + ' key=' + keycode);
},
- _postDialogChildMouseEvent: function(type, dialogid, x, y, count, buttons, modifier) {
- this._map._socket.sendMessage('dialogchildmouse dialogid=' + this._toRawDlgId(dialogid) + ' type=' + type +
- ' x=' + x + ' y=' + y + ' count=' + count +
- ' buttons=' + buttons + ' modifier=' + modifier);
- },
-
_handleDialogKeyEvent: function(e) {
var docLayer = this._map._docLayer;
this.modifier = 0;
@@ -216,38 +245,39 @@ L.Control.LokDialog = L.Control.extend({
if (this.modifier) {
unoKeyCode |= this.modifier;
if (e.type !== 'keyup') {
- this._postDialogKeyboardEvent('input', e.dialogId, charCode, unoKeyCode);
+ this._postWindowKeyboardEvent('input', e.strDlgId, charCode, unoKeyCode);
return;
}
}
if (e.type === 'keydown' && this._map['keyboard'].handleOnKeyDownKeys[keyCode]) {
- this._postDialogKeyboardEvent('input', e.dialogId, charCode, unoKeyCode);
+ this._postWindowKeyboardEvent('input', e.strDlgId, charCode, unoKeyCode);
}
else if (e.type === 'keypress' && (!this._map['keyboard'].handleOnKeyDownKeys[keyCode] || charCode !== 0)) {
if (charCode === keyCode && charCode !== 13) {
keyCode = 0;
unoKeyCode = this._map['keyboard']._toUNOKeyCode(keyCode);
}
- this._postDialogKeyboardEvent('input', e.dialogId, charCode, unoKeyCode);
+ this._postWindowKeyboardEvent('input', e.strDlgId, charCode, unoKeyCode);
}
else if (e.type === 'keyup') {
- this._postDialogKeyboardEvent('up', e.dialogId, charCode, unoKeyCode);
+ this._postWindowKeyboardEvent('up', e.strDlgId, charCode, unoKeyCode);
}
},
_onDialogClose: function(dialogId) {
- $('#' + dialogId).remove();
+ $('#' + this._toDlgPrefix(dialogId)).remove();
this._map.focus();
delete this._dialogs[dialogId];
},
- _paintDialog: function(dialogId, title, rectangle, imgData) {
+ _paintDialog: function(dialogId, rectangle, imgData) {
if (!this._isOpen(dialogId))
return;
+ var strDlgId = this._toDlgPrefix(dialogId);
var img = new Image();
- var canvas = document.getElementById(dialogId + '-canvas');
+ var canvas = document.getElementById(strDlgId + '-canvas');
var ctx = canvas.getContext('2d');
img.onload = function() {
var x = 0;
@@ -265,34 +295,35 @@ L.Control.LokDialog = L.Control.extend({
// Binary dialog msg recvd from core
_onDialogPaint: function (e) {
- var dialogId = this.dialogIdPrefix + e.id;
- if (!this._isOpen(dialogId))
- return;
-
- this._paintDialog(dialogId, e.title, e.rectangle, e.dialog);
+ var parent = this._getParentDialog(e.id);
+ if (parent) {
+ this._paintDialogChild(parent, e.width, e.height, e.rectangle, e.img);
+ } else {
+ this._paintDialog(e.id, e.rectangle, e.img);
+ }
},
// Dialog Child Methods
- _onDialogChildPaint: function(e) {
- var dialogId = this.dialogIdPrefix + e.id;
+ _paintDialogChild: function(dialogId, width, height, rectangle, imgData) {
+ var strDlgId = this._toDlgPrefix(dialogId);
var img = new Image();
- var canvas = document.getElementById(dialogId + '-floating');
- canvas.width = e.width;
- canvas.height = e.height;
+ var canvas = document.getElementById(strDlgId + '-floating');
+ canvas.width = width;
+ canvas.height = height;
var ctx = canvas.getContext('2d');
img.onload = function() {
ctx.drawImage(img, 0, 0);
};
- img.src = e.dialog;
+ img.src = imgData;
// increase the height of the container,
// so that if the floating window goes out of the parent,
// it doesn't get stripped off
- var height = parseInt(canvas.style.top) + canvas.height;
- var currentHeight = parseInt($('#' + dialogId).css('height'));
+ height = parseInt(canvas.style.top) + canvas.height;
+ var currentHeight = parseInt($('#' + strDlgId).css('height'));
if (height > currentHeight)
- $('#' + dialogId).css('height', height + 'px');
+ $('#' + strDlgId).css('height', height + 'px');
},
_onDialogChildClose: function(dialogId) {
@@ -302,87 +333,43 @@ L.Control.LokDialog = L.Control.extend({
$('#' + dialogId).height(canvasHeight + 'px');
},
- _isDialogChildUnchanged: function(dialogId, left, top) {
- // get pervious dialog child's specs
- var oldLeft = $('#' + dialogId + '-floating').css('left');
- var oldTop = $('#' + dialogId + '-floating').css('top');
- if (!oldLeft || !oldTop) {
- // no left or top position set earlier; this is first dialog child placement
- return false;
- }
-
- oldLeft = parseInt(oldLeft);
- oldTop = parseInt(oldTop);
- if (oldLeft !== left || oldTop !== top) {
- // something changed in new dialog child
- return false;
- }
-
- return true;
- },
-
- _removeDialogChild: function(dialogId) {
- $('#' + dialogId + '-floating').remove();
+ _removeDialogChild: function(id) {
+ $('#' + id + '-floating').remove();
},
- _createDialogChild: function(dialogId, top, left) {
- var floatingCanvas = '<canvas class="lokdialogchild-canvas" id="' + dialogId + '-floating"></canvas>';
- $('#' + dialogId).append(floatingCanvas);
- $('#' + dialogId + '-floating').css({position: 'absolute', left: left, top: top});
+ _createDialogChild: function(childId, dialogId, top, left) {
+ var strDlgId = this._toDlgPrefix(dialogId);
+ var floatingCanvas = '<canvas class="lokdialogchild-canvas" id="' + strDlgId + '-floating"></canvas>';
+ $('#' + strDlgId).append(floatingCanvas);
+ $('#' + strDlgId + '-floating').css({position: 'absolute', left: left, top: top});
var that = this;
// attach events
- $('#' + dialogId + '-floating').on('mousedown', function(e) {
+ $('#' + strDlgId + '-floating').on('mousedown', function(e) {
var buttons = 0;
buttons |= e.button === map['mouse'].JSButtons.left ? map['mouse'].LOButtons.left : 0;
buttons |= e.button === map['mouse'].JSButtons.middle ? map['mouse'].LOButtons.middle : 0;
buttons |= e.button === map['mouse'].JSButtons.right ? map['mouse'].LOButtons.right : 0;
var modifier = 0;
- that._postDialogChildMouseEvent('buttondown', dialogId, e.offsetX, e.offsetY, 1, buttons, modifier);
+ that._postWindowMouseEvent('buttondown', childId, e.offsetX, e.offsetY, 1, buttons, modifier);
});
- $('#' + dialogId + '-floating').on('mouseup', function(e) {
+ $('#' + strDlgId + '-floating').on('mouseup', function(e) {
var buttons = 0;
buttons |= e.button === map['mouse'].JSButtons.left ? map['mouse'].LOButtons.left : 0;
buttons |= e.button === map['mouse'].JSButtons.middle ? map['mouse'].LOButtons.middle : 0;
buttons |= e.button === map['mouse'].JSButtons.right ? map['mouse'].LOButtons.right : 0;
var modifier = 0;
- that._postDialogChildMouseEvent('buttonup', dialogId, e.offsetX, e.offsetY, 1, buttons, modifier);
+ that._postWindowMouseEvent('buttonup', childId, e.offsetX, e.offsetY, 1, buttons, modifier);
});
- $('#' + dialogId + '-floating').on('mousemove', function(e) {
- that._postDialogChildMouseEvent('move', dialogId, e.offsetX, e.offsetY, 1, 0, 0);
+ $('#' + strDlgId + '-floating').on('mousemove', function(e) {
+ that._postWindowMouseEvent('move', childId, e.offsetX, e.offsetY, 1, 0, 0);
});
- $('#' + dialogId + '-floating').on('contextmenu', function() {
+ $('#' + strDlgId + '-floating').on('contextmenu', function() {
return false;
});
- },
-
- _launchDialogChildIfRequired: function(e) {
- var positions = e.position.split(',');
- var left = parseInt(positions[0]);
- var top = parseInt(positions[1]);
-
- if (e.position === '0, 0' || // FIXME: we get incorrect "0, 0" position for floating windows as first message
- this._isDialogChildUnchanged(e.dialogId, left, top)) // no need to create the html element; we can just repaint it
- return;
-
- this._removeDialogChild(e.dialogId);
- this._createDialogChild(e.dialogId, top, left);
- },
-
- _onDialogChildMsg: function(e) {
- e.dialogId = this.dialogIdPrefix + e.dialogId;
- if (e.action === 'invalidate') {
- if (this._isOpen(e.dialogId))
- {
- this._sendDialogCommand(e.dialogId, false /* no json */, true /* dialog child*/);
- this._launchDialogChildIfRequired(e);
- }
- } else if (e.action === 'close') {
- this._onDialogChildClose(e.dialogId);
- }
}
});
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 5adf34b8..8e2ec804 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -608,7 +608,7 @@ L.Socket = L.Class.extend({
}
}
}
- else if (!textMsg.startsWith('tile:') && !textMsg.startsWith('renderfont:') && !textMsg.startsWith('dialogpaint:') && !textMsg.startsWith('dialogchildpaint:')) {
+ else if (!textMsg.startsWith('tile:') && !textMsg.startsWith('renderfont:') && !textMsg.startsWith('windowpaint:')) {
// log the tile msg separately as we need the tile coordinates
L.Log.log(textMsg, L.INCOMING);
if (imgBytes !== undefined) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 3d416b19..421ad445 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -437,18 +437,12 @@ L.TileLayer = L.GridLayer.extend({
else if (textMsg.startsWith('tile:')) {
this._onTileMsg(textMsg, img);
}
- else if (textMsg.startsWith('dialogpaint:')) {
+ else if (textMsg.startsWith('windowpaint:')) {
this._onDialogPaintMsg(textMsg, img);
}
- else if (textMsg.startsWith('dialogchildpaint:')) {
- this._onDialogChildPaintMsg(textMsg, img);
- }
- else if (textMsg.startsWith('dialog:')) {
+ else if (textMsg.startsWith('window:')) {
this._onDialogMsg(textMsg);
}
- else if (textMsg.startsWith('dialogchild:')) {
- this._onDialogChildMsg(textMsg);
- }
else if (textMsg.startsWith('unocommandresult:')) {
this._onUnoCommandResultMsg(textMsg);
}
@@ -1195,41 +1189,21 @@ L.TileLayer = L.GridLayer.extend({
_onDialogPaintMsg: function(textMsg, img) {
var command = this._map._socket.parseServerCmd(textMsg);
- this._map.fire('dialogpaint', {
+ this._map.fire('windowpaint', {
id: command.id,
- dialog: img,
- title: command.title,
- // TODO: add id too
+ img: img,
width: command.width,
height: command.height,
rectangle: command.rectangle
});
},
- _onDialogChildPaintMsg: function(textMsg, img) {
- var command = this._map._socket.parseServerCmd(textMsg);
- var width = command.width;
- var height = command.height;
-
- this._map.fire('dialogchildpaint', {
- id: command.id,
- dialog: img,
- // TODO: add id too
- width: width,
- height: height
- });
- },
-
_onDialogMsg: function(textMsg) {
- textMsg = textMsg.substring('dialog: '.length);
- var dialogMsg = JSON.parse(textMsg);
- this._map.fire('dialog', dialogMsg);
- },
-
- _onDialogChildMsg: function(textMsg) {
- textMsg = textMsg.substring('dialogchild: '.length);
+ textMsg = textMsg.substring('window: '.length);
var dialogMsg = JSON.parse(textMsg);
- this._map.fire('dialogchild', dialogMsg);
+ // e.type refers to signal type
+ dialogMsg.winType = dialogMsg.type;
+ this._map.fire('window', dialogMsg);
},
_onTileMsg: function (textMsg, img) {
diff --git a/tools/KitClient.cpp b/tools/KitClient.cpp
index 98ee4d9f..4357907c 100644
--- a/tools/KitClient.cpp
+++ b/tools/KitClient.cpp
@@ -79,8 +79,7 @@ extern "C"
CASE(INVALIDATE_HEADER);
CASE(CELL_ADDRESS);
CASE(RULER_UPDATE);
- CASE(DIALOG);
- CASE(DIALOG_CHILD);
+ CASE(WINDOW);
#undef CASE
}
std::cout << " payload: " << payload << std::endl;
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 663a55fc..b607ed0f 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -135,10 +135,9 @@ bool ClientSession::_handleInput(const char *buffer, int length)
tokens[0] != "paste" &&
tokens[0] != "insertfile" &&
tokens[0] != "key" &&
- tokens[0] != "dialogkey" &&
+ tokens[0] != "windowkey" &&
tokens[0] != "mouse" &&
- tokens[0] != "dialogmouse" &&
- tokens[0] != "dialogchildmouse" &&
+ tokens[0] != "windowmouse" &&
tokens[0] != "partpagerectangles" &&
tokens[0] != "ping" &&
tokens[0] != "renderfont" &&
@@ -157,8 +156,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
tokens[0] != "uno" &&
tokens[0] != "useractive" &&
tokens[0] != "userinactive" &&
- tokens[0] != "dialog" &&
- tokens[0] != "dialogchild")
+ tokens[0] != "paintwindow")
{
sendTextFrame("error: cmd=" + tokens[0] + " kind=unknown");
return false;
More information about the Libreoffice-commits
mailing list