diff --git a/common/Message.hpp b/common/Message.hpp index bfd38cb7ab..cfca3f81b6 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 ca4c855ef8..7de229859d 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& tokens) +bool ChildSession::renderWindow(const char* /*buffer*/, int /*length*/, const std::vector& tokens) { std::unique_lock 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 pixmap(pixmapDataSize); int width = bufferWidth, height = bufferHeight; std::string response; - if (isChild) - { - Timestamp timestamp; + 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)."); - 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 = "windowpaint: id=" + tokens[1] + + " width=" + std::to_string(width) + " height=" + std::to_string(height); - 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); + if (!paintRectangle.empty()) + response += " rectangle=" + paintRectangle; - 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)."); - - response = "dialogpaint: id=" + tokens[1] + - " width=" + std::to_string(width) + " height=" + std::to_string(height); - - if (!paintRectangle.empty()) - response += " rectangle=" + paintRectangle; - - response += "\n"; - } + response += "\n"; std::vector 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 ad9486a272..47c794214b 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& tokens); bool selectText(const char* buffer, int length, const std::vector& tokens); bool selectGraphic(const char* buffer, int length, const std::vector& tokens); - bool renderDialog(const char* buffer, int length, const std::vector& tokens); + bool renderWindow(const char* buffer, int length, const std::vector& tokens); bool resetSelection(const char* buffer, int length, const std::vector& tokens); bool saveAs(const char* buffer, int length, const std::vector& tokens); bool setClientPart(const char* buffer, int length, const std::vector& tokens); diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 3b373a368f..ac06a8d4de 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -2134,7 +2134,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 dccf27410a..f3523a9f74 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 1187ea4cb8..18e4cd24ce 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()); - } else if (e.action === 'invalidate') { - if (this._isOpen(e.dialogId)) { - if (e.rectangle && !this._isRectangleValid(e.rectangle)) + 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; - if (!e.rectangle) - e.rectangle = '0,0,' + this._width + ',' + this._height; - this._sendDialogCommand(e.dialogId, e.rectangle); + 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') { + 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 (!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 = '
' + - '' + + _launchDialog: function(strDlgId) { + var canvas = '
' + + '' + '
'; $(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) { this.modifier = 0; var shift = e.originalEvent.shiftKey ? this._map['keyboard'].keyModifier.shift : 0; @@ -214,38 +243,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; @@ -263,34 +293,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) { @@ -300,87 +331,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(id) { + $('#' + id + '-floating').remove(); }, - _removeDialogChild: function(dialogId) { - $('#' + dialogId + '-floating').remove(); - }, - - _createDialogChild: function(dialogId, top, left) { - var floatingCanvas = ''; - $('#' + 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 = ''; + $('#' + 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 36c75624d7..fb814ef242 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); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index d704368e9d..fa01615d04 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -449,18 +449,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); } @@ -1207,41 +1201,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); + textMsg = textMsg.substring('window: '.length); var dialogMsg = JSON.parse(textMsg); - this._map.fire('dialog', dialogMsg); - }, - - _onDialogChildMsg: function(textMsg) { - textMsg = textMsg.substring('dialogchild: '.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 98ee4d9fa9..4357907c16 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 663a55fce7..b607ed0faa 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;