loleaflet/Makefile                            |    2 
 loleaflet/dist/loleaflet.html                 |    2 
 loleaflet/dist/toolbar/toolbar.js             |   25 +++----
 loleaflet/src/control/Control.ColumnHeader.js |   24 ++----
 loleaflet/src/control/Control.ContextMenu.js  |    2 
 loleaflet/src/control/Control.Menubar.js      |   91 ++++++++++++++------------
 loleaflet/src/control/Control.PartsPreview.js |    2 
 loleaflet/src/control/Control.RowHeader.js    |   24 ++----
 loleaflet/src/control/Control.Tabs.js         |   24 +++---
 loleaflet/src/core/Socket.js                  |    2 
 loleaflet/src/layer/tile/TileLayer.js         |   49 ++++++--------
 loleaflet/src/map/Map.js                      |   17 ++--
 loleaflet/src/map/handler/Map.Mouse.js        |    7 --
 13 files changed, 129 insertions(+), 142 deletions(-)

New commits:
commit 1106c0a5acf36f21fd433e9b183eaaf7fc02be91
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Sat Jun 25 16:05:40 2016 +0530

    loleaflet: Simplify enable/disable logic in menubar
    
    There is still one problem though, that if already opened
    document is opened in a different browser window, it doesn't
    receive any command states which shows enable/disable states of
    menubar items incorrectly.
    
    Change-Id: Ib03f1becfb6585fed075bb5f1bf9c587063323a6

diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 2f8d479..8f31e41 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -214,36 +214,41 @@ L.Control.Menubar = L.Control.extend({
                        var aItem = this;
                        var type = $(aItem).data('type');
                        var id = $(aItem).data('id');
-                       if (id === 'fullscreen' && (msie > 0 || trident > 0 || 
edge > 0)) { // Full screen works weirdly on IE 11 and on Edge
-                               $(aItem).addClass('disabled');
-                               var index = 
self.options.allowedViewModeActions.indexOf('fullscreen');
-                               if (index > 0) {
-                                       
self.options.allowedViewModeActions.splice(index, 1);
-                               }
-                       }
-                       if (map._permission !== 'edit') {
-                               var found = false;
-                               for (var i in 
self.options.allowedViewModeActions) {
-                                       if 
(self.options.allowedViewModeActions[i] === id) {
-                                               found = true;
-                                               break;
+                       if (map._permission === 'edit') {
+                               if (type === 'unocommand') { // enable all 
depending on stored commandStates
+                                       var unoCommand = $(aItem).data('uno');
+                                       if 
(self.options.commandStates[unoCommand] === 'disabled') {
+                                               $(aItem).addClass('disabled');
+                                       } else {
+                                               
$(aItem).removeClass('disabled');
+                                       }
+                               } else if (type === 'action') { // enable all 
except fullscreen on windows
+                                       if (id === 'fullscreen' && (msie > 0 || 
trident > 0 || edge > 0)) { // Full screen works weirdly on IE 11 and on Edge
+                                               $(aItem).addClass('disabled');
+                                               var index = 
self.options.allowedViewModeActions.indexOf('fullscreen');
+                                               if (index > 0) {
+                                                       
self.options.allowedViewModeActions.splice(index, 1);
+                                               }
+                                       } else {
+                                               
$(aItem).removeClass('disabled');
                                        }
                                }
-                               if (!found) {
-                                       $(aItem).addClass('disabled');
-                               } else {
-                                       $(aItem).removeClass('disabled');
-                               }
-
-                               return;
-                       }
-
-                       if (type === 'unocommand') {
-                               var unoCommand = $(aItem).data('uno');
-                               if (self.options.commandStates[unoCommand] === 
'disabled') {
+                       } else { // eslint-disable-next-line no-lonely-if
+                               if (type === 'unocommand') { // disable all uno 
commands
                                        $(aItem).addClass('disabled');
-                               } else if 
(self.options.commandStates[unoCommand] === 'enabled') {
-                                       $(aItem).removeClass('disabled');
+                               } else if (type === 'action') { // disable all 
except allowedViewModeActions
+                                       var found = false;
+                                       for (var i in 
self.options.allowedViewModeActions) {
+                                               if 
(self.options.allowedViewModeActions[i] === id) {
+                                                       found = true;
+                                                       break;
+                                               }
+                                       }
+                                       if (!found) {
+                                               $(aItem).addClass('disabled');
+                                       } else {
+                                               
$(aItem).removeClass('disabled');
+                                       }
                                }
                        }
                });
commit f0812c14f01349d0d626eae77a14ed848f5cd2a8
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Fri Jun 24 23:57:27 2016 +0530

    Use new event doclayerinit in menubar init for menubar
    
    This event was introduced in
    c39045b1e4ece3eabbf9a9dbf24d8d4df7651e87
    
    Change-Id: Icacb6584ac9e3ab7aaaef55c2c7f7cf2ea2393a7

diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 6b4fec6..2f8d479 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -153,7 +153,7 @@ L.Control.Menubar = L.Control.extend({
                this._menubarCont = L.DomUtil.create('ul', 'sm sm-simple', 
docContainer.parentElement);
                this._menubarCont.id = 'main-menu';
 
-               map.on('updatepermission', this._onUpdatePermission, this);
+               map.on('doclayerinit', this._onDocLayerInit, this);
                map.on('commandstatechanged', this._onCommandStateChanged, 
this);
        },
 
@@ -165,11 +165,7 @@ L.Control.Menubar = L.Control.extend({
                }
        },
 
-       _onUpdatePermission: function() {
-               if (this._initialized || !this._menubarCont) {
-                       return;
-               }
-
+       _onDocLayerInit: function() {
                // Add document specific menu
                var docType = this._map.getDocType();
                if (docType === 'text') {
@@ -193,11 +189,12 @@ L.Control.Menubar = L.Control.extend({
                        subIndicatorsText: '&#8250;'
                });
                $('#main-menu').attr('tabindex', 0);
-               this._initialized = true;
 
                $('#main-menu').bind('select.smapi', {self: this}, 
this._onItemSelected);
                $('#main-menu').bind('beforeshow.smapi', {self: this}, 
this._beforeShow);
                $('#main-menu').bind('click.smapi', {self: this}, 
this._onClicked);
+
+               this._initialized = true;
        },
 
        _onClicked: function(e, menu) {
commit 8e023584ea33b764279b593fb8a593d617c8fd7c
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Fri Jun 24 23:47:05 2016 +0530

    loleaflet: Ask my host to show revision-history
    
    Change-Id: If1ed5fc03c6504e22c565b0278983bb168bb6fc8

diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 9fda481..6b4fec6 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -8,8 +8,9 @@ L.Control.Menubar = L.Control.extend({
        options: {
                text:  [
                        {name: _('File'), type: 'menu', menu: [{name: 
_('Save'), type: 'unocommand', uno: '.uno:Save'},
-                                                                               
                {name: _('Print'), id: 'print', type: 'action'},
-                                                                               
                {name: _('Download as'), type: 'menu', menu: [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
+                                                                               
                   {name: _('Print'), id: 'print', type: 'action'},
+                                                                               
                   {name: _('See revision history'), id: 'rev-history', type: 
'action'},
+                                                                               
                   {name: _('Download as'), type: 'menu', menu: [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
                                                                                
                                                                                
                   {name: _('ODF text document (.odt)'), id: 'downloadas-odt', 
type: 'action'},
                                                                                
                                                                                
                   {name: _('Microsoft Word 2003 (.doc)'), id: 
'downloadas-doc', type: 'action'},
                                                                                
                                                                                
                   {name: _('Microsoft Word (.docx)'), id: 'downloadas-docx', 
type: 'action'}]}]
@@ -53,8 +54,9 @@ L.Control.Menubar = L.Control.extend({
 
                presentation: [
                        {name: _('File'), type: 'menu', menu: [{name: 
_('Save'), type: 'unocommand', uno: '.uno:Save'},
-                                                                               
                {name: _('Print'), id: 'print', type: 'action'},
-                                                                               
                {name: _('Download as'), type: 'menu', menu:  [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
+                                                                               
                   {name: _('Print'), id: 'print', type: 'action'},
+                                                                               
                   {name: _('See revision history'), id: 'rev-history', type: 
'action'},
+                                                                               
                   {name: _('Download as'), type: 'menu', menu:  [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
                                                                                
                                                                                
                        {name: _('ODF presentation (.odp)'), id: 
'downloadas-odp', type: 'action'},
                                                                                
                                                                                
                        {name: _('Microsoft Powerpoint 2003 (.ppt)'), id: 
'downloadas-ppt', type: 'action'},
                                                                                
                                                                                
                        {name: _('Microsoft Powerpoint (.pptx)'), id: 
'downloadas-pptx', type: 'action'}]}]
@@ -98,8 +100,9 @@ L.Control.Menubar = L.Control.extend({
 
                spreadsheet: [
                        {name: _('File'), type: 'menu', menu: [{name: 
_('Save'), type: 'unocommand', uno: '.uno:Save'},
-                                                                               
                {name: _('Print'), id: 'print', type: 'action'},
-                                                                               
                {name: _('Download as'), type: 'menu', menu: [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
+                                                                               
                   {name: _('Print'), id: 'print', type: 'action'},
+                                                                               
                   {name: _('See revision history'), id: 'rev-history', type: 
'action'},
+                                                                               
                   {name: _('Download as'), type: 'menu', menu: [{name: _('PDF 
Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
                                                                                
                                                                                
                   {name: _('ODF spreadsheet (.ods)'), id: 'downloadas-ods', 
type: 'action'},
                                                                                
                                                                                
                   {name: _('Microsoft Excel 2003 (.xls)'), id: 
'downloadas-xls', type: 'action'},
                                                                                
                                                                                
                   {name: _('Microsoft Excel (.xlsx)'), id: 'downloadas-xlsx', 
type: 'action'}]}]
@@ -305,6 +308,12 @@ L.Control.Menubar = L.Control.extend({
                        map.showLOAboutDialog();
                } else if (id === 'keyboard-shortcuts') {
                        map.showLOKeyboardHelp();
+               } else if (id === 'rev-history') {
+                       // if we are being loaded inside an iframe, ask
+                       // our host to show revision history mode
+                       if (window.top !== window.self) {
+                               window.parent.postMessage('rev-history', '*');
+                       }
                }
        },
 
commit b2acd1cfbcbd00190fddde4fb4f3f6c09aabd948
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Fri Jun 24 23:39:34 2016 +0530

    Remove invalid placeholder
    
    This is no longer valid since context menus are implemented in
    loleaflet already.
    
    Change-Id: Ic2e21a92c5fdd87a2f3c34a3ff16628337184e1d

diff --git a/loleaflet/dist/toolbar/toolbar.js 
b/loleaflet/dist/toolbar/toolbar.js
index 5d6629f..e0a4255 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -1103,10 +1103,6 @@ map.on('mouseup keypress', function() {
        }
 });
 
-map.on('locontextmenu', function () {
-       // TODO: context menu handling...
-});
-
 map.on('statusindicator', function (e) {
        if (e.statusType === 'loleafletloaded') {
                var data = [''];
commit 454999fa57b786c889159c75731e9073b9ba9f9a
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Fri Jun 24 22:03:47 2016 +0530

    loleaflet: Resurrect loleaflet permission model for readonly mode
    
    Remove direct usage of editlock; instead change loleaflet
    permission from view to edit when editlock message is received.
    By default, map would be in 'view' mode and only get to 'edit'
    when server asks it to switch to.
    
    Use a new event 'doclayerinit' for actions that are directly
    dependent on intialization of doclayer.
    
    Change-Id: Iaceb95ad85721ddcd675c75cfeb1504ab2759ad4

diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html
index 21cd01e..02c5963 100644
--- a/loleaflet/dist/loleaflet.html
+++ b/loleaflet/dist/loleaflet.html
@@ -103,7 +103,7 @@
     }
 
     var host = '%HOST%';
-    var permission = getParameterByName('permission') || 'edit';
+    var permission = getParameterByName('permission');
     var timestamp = getParameterByName('timestamp');
     var closebutton = getParameterByName('closebutton');
     if (wopiSrc === '' && filePath === '') {
diff --git a/loleaflet/dist/toolbar/toolbar.js 
b/loleaflet/dist/toolbar/toolbar.js
index 1ae7b40..5d6629f 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -623,7 +623,7 @@ function onFormulaBarBlur() {
        }, 250);
 }
 
-map.on('updatepermission', function () {
+map.on('doclayerinit', function () {
        var toolbar = w2ui['toolbar-up'];
        var docType = map.getDocType();
        if (docType !== 'text') {
@@ -784,7 +784,7 @@ map.on('commandstatechanged', function (e) {
 
                // Change the toolbar button state immediately
                // if we already have the editlock
-               if (map._editlock && (state === 'enabled' || state === 
'disabled')) {
+               if (map._permission === 'edit' && (state === 'enabled' || state 
=== 'disabled')) {
                        // in case some buttons are in toolbar-up-more, find
                        // them and en/dis-able them.
                        if (formatButtons[id]) {
@@ -980,13 +980,13 @@ map.on('hyperlinkclicked', function (e) {
        window.open(e.url, '_blank');
 });
 
-map.on('editlock', function (e) {
+map.on('updatepermission', function (e) {
        var toolbar = w2ui['toolbar-down'];
-       if (e.value) {
+       if (e.perm === 'edit') {
                toolbar.disable('takeedit');
                toolbar.set('takeedit', {hint: _('You are editing (others can 
only view)'), caption: _('EDITING')});
        }
-       else {
+       else if (e.perm === 'view') {
                toolbar.enable('takeedit');
                toolbar.set('takeedit', {hint: _('Take edit lock (others can 
only view)'), caption: _('VIEWING')});
                $('#tb_toolbar-down_item_takeedit')
@@ -1002,12 +1002,16 @@ map.on('editlock', function (e) {
                        takeEditPopupTimeout = null;
                }, 3000);
        }
+       else if (e.perm === 'readonly') {
+               toolbar.disable('takeedit');
+               toolbar.set('takeedit', {hint: _('You are locked in readonly 
mode'), caption: _('READONLY')});
+       }
 
        toolbar = w2ui['toolbar-up'];
        var toolbarUpMore = w2ui['toolbar-up-more'];
        // {En,Dis}able toolbar buttons
        for (var id in formatButtons) {
-               if (e.value && formatButtons[id]) {
+               if (e.perm === 'edit' && formatButtons[id]) {
                        // restore the state from stored object (formatButtons)
                        toolbar.enable(id);
                        // some might be hidden in toolbar-up-more
@@ -1022,7 +1026,7 @@ map.on('editlock', function (e) {
        var formulaBarButtons = ['sum', 'function'];
        var presentationButtons = ['insertpage', 'duplicatepage', 'deletepage'];
        var toolbarDownButtons = ['next', 'prev'];
-       if (e.value) {
+       if (e.perm === 'edit') {
                // Enable list boxes
                $('.styles-select').prop('disabled', false);
                $('.fonts-select').prop('disabled', false);
@@ -1081,11 +1085,10 @@ map.on('editlock', function (e) {
                });
                $('#search-input').prop('disabled', true);
        }
-
 });
 
 map.on('mouseup keypress', function() {
-       if (!map._editlock) {
+       if (map._permission === 'view') {
                $('#tb_toolbar-down_item_takeedit')
                        .w2overlay({
                                html: takeEditPopupMessage,
diff --git a/loleaflet/src/control/Control.ColumnHeader.js 
b/loleaflet/src/control/Control.ColumnHeader.js
index 21edd57..a5cfcdc 100644
--- a/loleaflet/src/control/Control.ColumnHeader.js
+++ b/loleaflet/src/control/Control.ColumnHeader.js
@@ -15,7 +15,6 @@ L.Control.ColumnHeader = L.Control.extend({
                this._map.on('updatescrolloffset', this.setScrollPosition, 
this);
                this._map.on('updateviewport', this.setViewPort, this);
                this._map.on('viewrowcolumnheaders', this.viewRowColumnHeaders, 
this);
-               this._map.on('editlock', this._onEditLock, this);
                var docContainer = this._map.options.documentContainer;
                var cornerHeader = L.DomUtil.create('div', 
'spreadsheet-header-corner', docContainer.parentElement);
                L.DomEvent.addListener(cornerHeader, 'click', 
this._onCornerHeaderClick, this);
@@ -50,18 +49,6 @@ L.Control.ColumnHeader = L.Control.extend({
                });
        },
 
-       _onEditLock: function(e) {
-               // editlock message is received very early (before DOM setup)
-               // in that case, wait for a second before disabling/enabling 
the context menu
-               if ($('.spreadsheet-header-column').length === 0) {
-                       setTimeout(function() {
-                               
$('.spreadsheet-header-column').contextMenu(e.value === 1);
-                       }, 1000);
-               } else {
-                       $('.spreadsheet-header-column').contextMenu(e.value === 
1);
-               }
-       },
-
        insertColumn: function(colAlpha) {
                // First select the corresponding column because
                // .uno:InsertColumn doesn't accept any column number
@@ -173,10 +160,17 @@ L.Control.ColumnHeader = L.Control.extend({
                this._map.sendUnoCommand('.uno:SelectAll');
        },
 
-       _onUpdatePermission: function () {
-               if (this._map.getDocType() === 'spreadsheet' && 
!this._initialized) {
+       _onUpdatePermission: function (e) {
+               if (this._map.getDocType() !== 'spreadsheet') {
+                       return;
+               }
+
+               if (!this._initialized) {
                        this._initialize();
                }
+               setTimeout(function() {
+                       $('.spreadsheet-header-column').contextMenu(e.perm === 
'edit');
+               }, 1000);
        }
 });
 
diff --git a/loleaflet/src/control/Control.ContextMenu.js 
b/loleaflet/src/control/Control.ContextMenu.js
index dd84c70..6a4d9b8 100644
--- a/loleaflet/src/control/Control.ContextMenu.js
+++ b/loleaflet/src/control/Control.ContextMenu.js
@@ -60,7 +60,7 @@ L.Control.ContextMenu = L.Control.extend({
        },
 
        _onContextMenu: function(obj) {
-               if (!map._editlock) {
+               if (map._permission !== 'edit') {
                        return;
                }
 
diff --git a/loleaflet/src/control/Control.Menubar.js 
b/loleaflet/src/control/Control.Menubar.js
index 1ad0558..9fda481 100644
--- a/loleaflet/src/control/Control.Menubar.js
+++ b/loleaflet/src/control/Control.Menubar.js
@@ -221,7 +221,7 @@ L.Control.Menubar = L.Control.extend({
                                        
self.options.allowedViewModeActions.splice(index, 1);
                                }
                        }
-                       if (!map._editlock) {
+                       if (map._permission !== 'edit') {
                                var found = false;
                                for (var i in 
self.options.allowedViewModeActions) {
                                        if 
(self.options.allowedViewModeActions[i] === id) {
diff --git a/loleaflet/src/control/Control.PartsPreview.js 
b/loleaflet/src/control/Control.PartsPreview.js
index 092bf6e..14d41dc 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -78,7 +78,7 @@ L.Control.PartsPreview = L.Control.extend({
        },
 
        _setPart: function (e) {
-               if (!map._editlock) {
+               if (map._permission !== 'edit') {
                        return;
                }
                var part = $('.parts-preview .mCSB_container 
.preview-frame').index(e.target.parentNode);
diff --git a/loleaflet/src/control/Control.RowHeader.js 
b/loleaflet/src/control/Control.RowHeader.js
index 67cea77..11cf0da 100644
--- a/loleaflet/src/control/Control.RowHeader.js
+++ b/loleaflet/src/control/Control.RowHeader.js
@@ -15,7 +15,6 @@ L.Control.RowHeader = L.Control.extend({
                this._map.on('updatescrolloffset', this.setScrollPosition, 
this);
                this._map.on('updateviewport', this.setViewPort, this);
                this._map.on('viewrowcolumnheaders', this.viewRowColumnHeaders, 
this);
-               this._map.on('editlock', this._onEditLock, this);
                var docContainer = this._map.options.documentContainer;
                var headersContainer = L.DomUtil.create('div', 
'spreadsheet-header-rows-container', docContainer.parentElement);
                this._rows = L.DomUtil.create('div', 'spreadsheet-header-rows', 
headersContainer);
@@ -48,18 +47,6 @@ L.Control.RowHeader = L.Control.extend({
                });
        },
 
-       _onEditLock: function(e) {
-               // editlock message is received very early (before DOM setup)
-               // in that case, wait for a second before disabling/enabling 
the context menu
-               if ($('.spreadsheet-header-row').length === 0) {
-                       setTimeout(function() {
-                               
$('.spreadsheet-header-row').contextMenu(e.value === 1);
-                       }, 1000);
-               } else {
-                       $('.spreadsheet-header-row').contextMenu(e.value === 1);
-               }
-       },
-
        insertRow: function(row) {
                // First select the corresponding row because
                // .uno:InsertRows doesn't accept any row number
@@ -153,10 +140,17 @@ L.Control.RowHeader = L.Control.extend({
                this._selectRow(row, modifier);
        },
 
-       _onUpdatePermission: function () {
-               if (this._map.getDocType() === 'spreadsheet' && 
!this._initialized) {
+       _onUpdatePermission: function (e) {
+               if (this._map.getDocType() !== 'spreadsheet') {
+                       return;
+               }
+
+               if (!this._initialized) {
                        this._initialize();
                }
+               setTimeout(function() {
+                       $('.spreadsheet-header-row').contextMenu(e.perm === 
'edit');
+               }, 1000);
        }
 });
 
diff --git a/loleaflet/src/control/Control.Tabs.js 
b/loleaflet/src/control/Control.Tabs.js
index a7895f7..7e4bd46 100644
--- a/loleaflet/src/control/Control.Tabs.js
+++ b/loleaflet/src/control/Control.Tabs.js
@@ -9,10 +9,17 @@ L.Control.Tabs = L.Control.extend({
                this._initalized = false;
        },
 
-       _onUpdatePermission: function() {
-               if (this._map.getDocType() === 'spreadsheet' && 
!this._initialized) {
+       _onUpdatePermission: function(e) {
+               if (this._map.getDocType() !== 'spreadsheet') {
+                       return;
+               }
+
+               if (!this._initialized) {
                        this._initialize();
                }
+               setTimeout(function() {
+                       $('.spreadsheet-context-menu').contextMenu(e.perm === 
'edit');
+               }, 1000);
        },
 
        _initialize: function () {
@@ -67,15 +74,6 @@ L.Control.Tabs = L.Control.extend({
                });
 
                map.on('updateparts', this._updateDisabled, this);
-               map.on('editlock', this._enableTabsContextMenu, this);
-       },
-
-       _enableTabsContextMenu: function(e) {
-               if (!e.value) {
-                       $('.spreadsheet-context-menu').contextMenu(false);
-               } else {
-                       $('.spreadsheet-context-menu').contextMenu(true);
-               }
        },
 
        _updateDisabled: function (e) {
@@ -125,7 +123,7 @@ L.Control.Tabs = L.Control.extend({
                                        
L.DomUtil.addClass(this._spreadsheetTabs[key], 
'spreadsheet-context-menu-selected');
                                }
 
-                               if (map._editlock) {
+                               if (map._permission === 'edit') {
                                        
L.DomUtil.removeClass(this._spreadsheetTabs[key], 'context-menu-disabled');
                                } else {
                                        
L.DomUtil.addClass(this._spreadsheetTabs[key], 'context-menu-disabled');
@@ -135,7 +133,7 @@ L.Control.Tabs = L.Control.extend({
        },
 
        _setPart: function (e) {
-               if (!map._editlock) {
+               if (map._permission !== 'edit') {
                        return;
                }
                var part =  e.target.id.match(/\d+/g)[0];
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 8ca6002..7cb235a 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -262,7 +262,7 @@ L.Socket = L.Class.extend({
 
                        this._map._docLayer = docLayer;
                        this._map.addLayer(docLayer);
-                       this._map._fireInitComplete('docLayer');
+                       this._map.fire('doclayerinit');
                }
 
                // these can arrive very early during the startup
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 81d5553..e14fe25 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -174,11 +174,18 @@ L.TileLayer = L.GridLayer.extend({
                        },
                this);
 
-               map.on('editlock', function(e) {
+               map.on('updatepermission', function(e) {
                        // {En,Dis}able selection handles
                        for (var key in this._selectionHandles) {
-                               
this._selectionHandles[key].setDraggable(e.value);
+                               this._selectionHandles[key].setDraggable(e.perm 
=== 'edit');
                        }
+
+                       // we want graphic selection handles to appear
+                       // when in editmode, and dissappear when in view mode
+                       if (e.perm !== 'edit') {
+                               this._graphicSelection = null;
+                       }
+                       this._onUpdateGraphicSelection();
                }, this);
 
                for (var key in this._selectionHandles) {
@@ -186,14 +193,8 @@ L.TileLayer = L.GridLayer.extend({
                }
                this._textArea = map._textArea;
                this._textArea.focus();
-               if (this.options.permission === 'edit' ||
-                               this.options.permission === 'view' ||
-                               this.options.permission === 'readonly') {
-                       map.setPermission(this.options.permission);
-               }
-               else {
-                       map.setPermission(this.options.defaultPermission);
-               }
+
+               map.setPermission(this.options.permission);
 
                map.fire('statusindicator', {statusType: 'loleafletloaded'});
        },
@@ -697,7 +698,7 @@ L.TileLayer = L.GridLayer.extend({
 
        _onTextSelectionEndMsg: function (textMsg) {
                var strTwips = textMsg.match(/\d+/g);
-               if (strTwips != null && this._map._editlock) {
+               if (strTwips != null && this._map._permission === 'edit') {
                        var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
                        var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
                        var bottomRightTwips = topLeftTwips.add(offset);
@@ -712,7 +713,7 @@ L.TileLayer = L.GridLayer.extend({
 
        _onTextSelectionStartMsg: function (textMsg) {
                var strTwips = textMsg.match(/\d+/g);
-               if (strTwips != null && this._map._editlock) {
+               if (strTwips != null && this._map._permission === 'edit') {
                        var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
                        var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
                        var bottomRightTwips = topLeftTwips.add(offset);
@@ -774,7 +775,7 @@ L.TileLayer = L.GridLayer.extend({
        },
 
        _mapOnError: function (e) {
-               if (e.msg) {
+               if (e.msg && this._map._permission === 'edit') {
                        this._map.setPermission('view');
                }
        },
@@ -961,7 +962,7 @@ L.TileLayer = L.GridLayer.extend({
                                this._map.removeLayer(this._graphicMarker);
                        }
 
-                       if (!this._map._editlock) {
+                       if (this._map._permission !== 'edit') {
                                return;
                        }
 
@@ -1274,17 +1275,15 @@ L.TileLayer = L.GridLayer.extend({
        },
 
        _onEditLock: function (textMsg) {
-               var val = parseInt(textMsg.split(' ')[1]);
-               if (!isNaN(val) && val !== this._map._editlock) {
-                       this._map._editlock = val;
-                       this._map.fire('editlock', {value: val});
-
-                       // we want graphic selection handles to appear ...
-                       // when editlock is taken, and dissappear when it is 
taken away
-                       if (!val) {
-                               this._graphicSelection = null;
-                       }
-                       this._onUpdateGraphicSelection();
+               // if we have explicitly set this as readonly,
+               // then never listen server for editlock
+               if (this._map._permission === 'readonly') {
+                       return;
+               }
+
+               var perm = parseInt(textMsg.split(' ')[1]) === 1 ? 'edit' : 
'view';
+               if (perm !== this._map._permission) {
+                       this._map.setPermission(perm);
                }
        },
 
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index b57d3ae..9d212cf 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -83,7 +83,7 @@ L.Map = L.Evented.extend({
 
                // When all these conditions are met, fire 
statusindicator:initializationcomplete
                this.initConditions = {
-                       'docLayer': false,
+                       'doclayerinit': false,
                        'statusindicatorfinish': false,
                        'StyleApply': false,
                        'CharFontName': false,
@@ -92,10 +92,14 @@ L.Map = L.Evented.extend({
                this.initComplete = false;
 
                this.on('updatepermission', function() {
-                       if (this.initComplete) {
-                               return;
+                       if (!this.initComplete) {
+                               this._fireInitComplete('updatepermission');
+                       }
+               });
+               this.on('doclayerinit', function() {
+                       if (!this.initComplete) {
+                               this._fireInitComplete('doclayerinit');
                        }
-                       this._fireInitComplete('updatepermission');
                });
                this.on('updatetoolbarcommandvalues', function(e) {
                        if (this.initComplete) {
@@ -109,11 +113,6 @@ L.Map = L.Evented.extend({
                        }
                });
 
-               // when editing, we need the LOK session right away
-               if (options.permission === 'edit') {
-                       this.setPermission(options.permission);
-               }
-
                this.showBusy(_('Initializing...'), false);
                this.on('statusindicator', this._onUpdateProgress, this);
        },
diff --git a/loleaflet/src/map/handler/Map.Mouse.js 
b/loleaflet/src/map/handler/Map.Mouse.js
index 9a19cdc..b5861ff 100644
--- a/loleaflet/src/map/handler/Map.Mouse.js
+++ b/loleaflet/src/map/handler/Map.Mouse.js
@@ -146,13 +146,6 @@ L.Map.Mouse = L.Handler.extend({
                                }
                                this._mouseEventsQueue.push(L.bind(function() {
                                        var docLayer = this._map._docLayer;
-                                       // if it's a click or mouseup after 
selecting
-                                       if (this._mouseEventsQueue.length > 1) {
-                                               // it's a click
-                                               if (this._map._permission === 
'view') {
-                                                       
docLayer._map.setPermission('edit');
-                                               }
-                                       }
                                        this._mouseEventsQueue = [];
                                        docLayer._postMouseEvent('buttonup', 
mousePos.x, mousePos.y, 1, buttons, modifier);
                                        docLayer._textArea.focus();
commit 29f2f3ec5435aa054205a9c261791ba056415bbb
Author: Pranav Kant <pran...@collabora.co.uk>
Date:   Fri Jun 24 22:05:17 2016 +0530

    loleaflet: Lint before building
    
    Change-Id: I5e38373959574b3a72fbfe0715a8758de9765438

diff --git a/loleaflet/Makefile b/loleaflet/Makefile
index 16cfec0..7b3dd95 100644
--- a/loleaflet/Makefile
+++ b/loleaflet/Makefile
@@ -10,8 +10,8 @@ DRAW_VERSION=0.2.4
 
 all:
        npm install
-       jake build
        jake lint
+       jake build
        rm -rf dist/plugins/draw-$(DRAW_VERSION) && mkdir -p 
dist/plugins/draw-$(DRAW_VERSION)
        cd plugins/draw-$(DRAW_VERSION) && jake build && cp -ar dist 
../../dist/plugins/draw-$(DRAW_VERSION)
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to