loleaflet/build/deps.js                               |   21 +++-
 loleaflet/debug/document/document_simple_example.html |   16 ++-
 loleaflet/src/control/Control.EditView.js             |   65 --------------
 loleaflet/src/control/Control.Parts.js                |   29 +-----
 loleaflet/src/control/Control.Permission.js           |   49 ++++++++++
 loleaflet/src/control/Control.Search.js               |   51 +----------
 loleaflet/src/control/Control.StatusIndicator.js      |   22 +---
 loleaflet/src/control/Control.Zoom.js                 |   11 --
 loleaflet/src/control/Control.js                      |    8 +
 loleaflet/src/control/Parts.js                        |   28 ++++++
 loleaflet/src/control/Permission.js                   |   23 +++++
 loleaflet/src/control/Search.js                       |   34 +++++++
 loleaflet/src/layer/tile/TileLayer.js                 |   82 ++++--------------
 13 files changed, 205 insertions(+), 234 deletions(-)

New commits:
commit bfdf7b987d20d7487929f86a1414db346353655a
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Fri Jul 10 18:01:19 2015 +0300

    loleaflet: manually add controls in the html file
    
    Conflicts:
        loleaflet/src/control/Control.Buttons.js

diff --git a/loleaflet/debug/document/document_simple_example.html 
b/loleaflet/debug/document/document_simple_example.html
index 772caf3..bb00203 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -67,6 +67,14 @@
             doubleClickZoom: false
             });
 
+    ////// Controls /////
+    map.addControl(L.control.buttons());
+    map.addControl(L.control.search());
+    map.addControl(L.control.permissionSwitch());
+    map.addControl(L.control.zoom());
+    map.addControl(L.control.parts());
+    map.addControl(L.control.statusIndicator());
+
     ////// Document layer ////
     var docLayer = new L.TileLayer('', {
         doc: filePath,
@@ -76,10 +84,6 @@
     });
     map.addLayer(docLayer);
 
-    ////// Zoom Control /////
-    var zoomControl = L.control.zoom();
-    map.addControl(zoomControl);
-
     ////// Scrollbar /////
     (function($){
         $(window).load(function(){
diff --git a/loleaflet/src/control/Control.Parts.js 
b/loleaflet/src/control/Control.Parts.js
index 528fcbe..07f67f1 100644
--- a/loleaflet/src/control/Control.Parts.js
+++ b/loleaflet/src/control/Control.Parts.js
@@ -63,16 +63,6 @@ L.Control.Parts = L.Control.extend({
        }
 });
 
-L.Map.mergeOptions({
-       partsControl: true
-});
-
-L.Map.addInitHook(function () {
-       this.partsControl = new L.Control.Parts();
-       this.addControl(this.partsControl);
-});
-
-
 L.control.parts = function (options) {
        return new L.Control.Parts(options);
 };
diff --git a/loleaflet/src/control/Control.Permission.js 
b/loleaflet/src/control/Control.Permission.js
index dee99e9..240d1bb 100644
--- a/loleaflet/src/control/Control.Permission.js
+++ b/loleaflet/src/control/Control.Permission.js
@@ -44,17 +44,6 @@ L.Control.PermissionSwitch = L.Control.extend({
        }
 });
 
-L.Map.mergeOptions({
-       permissionSwitchControl: true
-});
-
-L.Map.addInitHook(function () {
-       if (this.options.permissionSwitchControl) {
-               this.permissionSwitchControl = new L.Control.PermissionSwitch();
-               this.addControl(this.permissionSwitchControl);
-       }
-});
-
 L.control.permissionSwitch = function (options) {
        return new L.Control.PermissionSwitch(options);
 };
diff --git a/loleaflet/src/control/Control.Search.js 
b/loleaflet/src/control/Control.Search.js
index 0973607..91e3638 100644
--- a/loleaflet/src/control/Control.Search.js
+++ b/loleaflet/src/control/Control.Search.js
@@ -115,15 +115,6 @@ L.Control.Search = L.Control.extend({
        }
 });
 
-L.Map.mergeOptions({
-       searchControl: true
-});
-
-L.Map.addInitHook(function () {
-       this.searchControl = new L.Control.Search();
-       this.addControl(this.searchControl);
-});
-
 L.control.search = function (options) {
        return new L.Control.Search(options);
 };
diff --git a/loleaflet/src/control/Control.StatusIndicator.js 
b/loleaflet/src/control/Control.StatusIndicator.js
index fffc625..4603ff9 100644
--- a/loleaflet/src/control/Control.StatusIndicator.js
+++ b/loleaflet/src/control/Control.StatusIndicator.js
@@ -29,17 +29,6 @@ L.Control.StatusIndicator = L.Control.extend({
        }
 });
 
-L.Map.mergeOptions({
-       statusIndicatorControl: true
-});
-
-L.Map.addInitHook(function () {
-       if (this.options.statusIndicatorControl) {
-               this.statusIndicatorControl = new L.Control.StatusIndicator();
-               this.addControl(this.statusIndicatorControl);
-       }
-});
-
 L.control.statusIndicator = function (options) {
        return new L.Control.StatusIndicator(options);
 };
diff --git a/loleaflet/src/control/Control.Zoom.js 
b/loleaflet/src/control/Control.Zoom.js
index 5917258..2d550a9 100644
--- a/loleaflet/src/control/Control.Zoom.js
+++ b/loleaflet/src/control/Control.Zoom.js
@@ -86,17 +86,6 @@ L.Control.Zoom = L.Control.extend({
        }
 });
 
-L.Map.mergeOptions({
-       zoomControl: false
-});
-
-L.Map.addInitHook(function () {
-       if (this.options.zoomControl) {
-               this.zoomControl = new L.Control.Zoom();
-               this.addControl(this.zoomControl);
-       }
-});
-
 L.control.zoom = function (options) {
        return new L.Control.Zoom(options);
 };
commit 36407f262b3f8dcf96e48b856a8506d20cf2ee4d
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Fri Jul 10 16:51:50 2015 +0300

    loleaflet: updated the status indicator event

diff --git a/loleaflet/src/control/Control.StatusIndicator.js 
b/loleaflet/src/control/Control.StatusIndicator.js
index 78c24fd..fffc625 100644
--- a/loleaflet/src/control/Control.StatusIndicator.js
+++ b/loleaflet/src/control/Control.StatusIndicator.js
@@ -11,20 +11,19 @@ L.Control.StatusIndicator = L.Control.extend({
                var partName = 'leaflet-control-statusindicator';
                this._container = L.DomUtil.create('div', partName + ' 
leaflet-bar');
 
-               map.on('statusindicator:start statusindicator:setvalue 
statusindicator:finish',
-                       this._updateStatus, this);
+               map.on('statusindicator', this._updateStatus, this);
                return this._container;
        },
 
        _updateStatus: function (e) {
-               if (e.type === 'statusindicator:start') {
+               if (e.statusType === 'start') {
                        L.DomUtil.setStyle(this._container, 'display', '');
                        this._container.innerText = '0 %';
                }
-               else if (e.type === 'statusindicator:setvalue') {
-                       this._container.innerText = e.statusIndicator + '% ';
+               else if (e.statusType === 'setvalue') {
+                       this._container.innerText = e.value + '% ';
                }
-               else if (e.type === 'statusindicator:finish') {
+               else if (e.statusType === 'finish') {
                        L.DomUtil.setStyle(this._container, 'display', 'none');
                }
        }
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 9fa386c..f62ecfc 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -391,14 +391,14 @@ L.TileLayer = L.GridLayer.extend({
                        }
                }
                else if (textMsg.startsWith('statusindicatorstart:')) {
-                       this._map.fire('statusindicator:start');
+                       this._map.fire('statusindicator', {statusType : 
'start'});
                }
                else if (textMsg.startsWith('statusindicatorsetvalue:')) {
-                       var statusIndicator = textMsg.match(/\d+/g)[0];
-                       this._map.fire('statusindicator:setvalue', 
{statusIndicator:statusIndicator});
+                       var value = textMsg.match(/\d+/g)[0];
+                       this._map.fire('statusindicator', {statusType : 
'setvalue', value : value});
                }
                else if (textMsg.startsWith('statusindicatorfinish:')) {
-                       this._map.fire('statusindicator:finish');
+                       this._map.fire('statusindicator', {statusType : 
'finish'});
                }
                else if (textMsg.startsWith('tile:')) {
                        command = this._parseServerCmd(textMsg);
commit e10912e481ae292546ea119dc4d4d936f810487e
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Fri Jul 10 16:32:19 2015 +0300

    loleaflet: setPart API for switching parts
    
    Also added the 'updateparts' event which has the members:
    currentPart and parts, indicating the current visible part
    and the number of parts
    
    Conflicts:
        loleaflet/build/deps.js

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 963ce96..65d5452 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -263,6 +263,11 @@ var deps = {
                desc: 'Permission change handler (edit, view, readonly).'
        },
 
+       Parts: {
+               src: ['control/Parts.js'],
+               desc: 'Parts change handler.'
+       },
+
        AnimationPan: {
                src: [
                        'dom/DomEvent.js',
diff --git a/loleaflet/src/control/Control.Parts.js 
b/loleaflet/src/control/Control.Parts.js
index 7d6d2a7..528fcbe 100644
--- a/loleaflet/src/control/Control.Parts.js
+++ b/loleaflet/src/control/Control.Parts.js
@@ -21,28 +21,16 @@ L.Control.Parts = L.Control.extend({
                this._nextPartButton = this._createButton(options.nextPartText, 
options.nextPartTitle,
                        partName + '-next', container, this._nextPart);
 
-               this._parts = options.parts;
-               this._currentPart = options.currentPart;
-               this._updateDisabled();
-               map.on('setpart', this._updateDisabled, this);
-
+               map.on('updateparts', this._updateDisabled, this);
                return container;
        },
 
        _prevPart: function () {
-               this._map.fire('prevpart');
-               if (this._currentPart > 0) {
-                       this._currentPart -= 1;
-               }
-               this._updateDisabled();
+               this._map.setPart('previous');
        },
 
        _nextPart: function () {
-               this._map.fire('nextpart');
-               if (this._currentPart < this._parts - 1) {
-                       this._currentPart += 1;
-               }
-               this._updateDisabled();
+               this._map.setPart('next');
        },
 
        _createButton: function (html, title, className, container, fn) {
@@ -61,16 +49,13 @@ L.Control.Parts = L.Control.extend({
        },
 
        _updateDisabled: function (e) {
-               if (e) {
-                       this._currentPart = e.currentPart;
-               }
                var className = 'leaflet-disabled';
-               if (this._currentPart === 0) {
+               if (e.currentPart === 0) {
                        L.DomUtil.addClass(this._prevPartButton, className);
                } else {
                        L.DomUtil.removeClass(this._prevPartButton, className);
                }
-               if (this._currentPart === this._parts - 1) {
+               if (e.currentPart === e.parts - 1) {
                        L.DomUtil.addClass(this._nextPartButton, className);
                } else {
                        L.DomUtil.removeClass(this._nextPartButton, className);
@@ -79,9 +64,15 @@ L.Control.Parts = L.Control.extend({
 });
 
 L.Map.mergeOptions({
-       partsControl: false
+       partsControl: true
 });
 
+L.Map.addInitHook(function () {
+       this.partsControl = new L.Control.Parts();
+       this.addControl(this.partsControl);
+});
+
+
 L.control.parts = function (options) {
        return new L.Control.Parts(options);
 };
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
new file mode 100644
index 0000000..69d9e83
--- /dev/null
+++ b/loleaflet/src/control/Parts.js
@@ -0,0 +1,28 @@
+/*
+ * Document parts switching handler
+ */
+L.Map.include({
+       setPart: function (part) {
+               var docLayer = this._docLayer
+               if (part === 'previous') {
+                       if (docLayer._currentPart > 0) {
+                               docLayer._currentPart -= 1;
+                       }
+               }
+               else if (part === 'next') {
+                       if (docLayer._currentPart < docLayer._parts - 1) {
+                               docLayer._currentPart += 1;
+                       }
+               }
+               else if (typeof(part) === 'number' && part >= 0 && part < 
docLayer._parts) {
+                       docLayer._currentPart = part;
+               }
+               else {
+                       return;
+               }
+               this.fire('updateparts', {currentPart : docLayer._currentPart, 
parts : docLayer._parts});
+               docLayer._update();
+               docLayer._pruneTiles();
+               docLayer._clearSelections();
+       }
+});
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 7271ff0..9fa386c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -192,7 +192,6 @@ L.TileLayer = L.GridLayer.extend({
                this._map.on('zoomend resize', this._updateScrollOffset, this);
                this._map.on('zoomstart zoomend', this._onZoom, this);
                this._map.on('clearselection', this._clearSelections, this);
-               this._map.on('prevpart nextpart', this._onSwitchPart, this);
                this._map.on('drag', this._updateScrollOffset, this);
                this._map.on('copy', this._onCopy, this);
                this._map.on('mousedown mouseup mouseover mouseout mousemove 
dblclick',
@@ -385,13 +384,9 @@ L.TileLayer = L.GridLayer.extend({
                                this._docHeightTwips = command.height;
                                this._updateMaxBounds(true);
                                this._documentInfo = textMsg;
-                               if (this._parts === undefined && command.parts 
> 1) {
-                                       this._map.addControl(L.control.parts({
-                                               'parts': command.parts,
-                                               'currentPart': 
command.currentPart}));
-                               }
                                this._parts = command.parts;
                                this._currentPart = command.currentPart;
+                               this._map.fire('updateparts', {currentPart : 
this._currentPart, parts: this._parts});
                                this._update();
                        }
                }
@@ -833,22 +828,6 @@ L.TileLayer = L.GridLayer.extend({
                this._mouseEventsQueue = [];
        },
 
-       _onSwitchPart: function (e) {
-               if (e.type === 'prevpart') {
-                       if (this._currentPart > 0) {
-                               this._currentPart -= 1;
-                       }
-               }
-               else if (e.type === 'nextpart') {
-                       if (this._currentPart < this._parts - 1) {
-                               this._currentPart += 1;
-                       }
-               }
-               this._update();
-               this._pruneTiles();
-               this._clearSelections();
-       },
-
        // Convert javascript key codes to UNO key codes.
        _toUNOKeyCode: function (keyCode) {
                return this.keymap[keyCode] || keyCode;
commit e2637de1f59e00afd06893287ca61a75738309b8
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Fri Jul 10 12:20:46 2015 +0300

    loleaflet: exposed the setPermission API: map.setPermission(perm)
    
    Where perm can be: edit, view or readonly
    This also replaces the editMode and readOnly flags

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index da31dae..963ce96 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -221,11 +221,11 @@ var deps = {
                desc: 'Parts control with two buttons (previous / next).'
        },
 
-       ControlEditViewSwitch: {
+       ControlPermissionSwitch: {
                src: ['control/Control.js',
-                     'control/Control.EditView.js'],
+                     'control/Control.Permission.js'],
                heading: 'Controls',
-               desc: 'Switches from viewing to editing mode and backwards'
+               desc: 'Switches edit, view and readOnly modes'
        },
 
        ControlStatusIndicator: {
@@ -258,6 +258,11 @@ var deps = {
                desc: 'Search command handler.'
        },
 
+       Permission: {
+               src: ['control/Permission.js'],
+               desc: 'Permission change handler (edit, view, readonly).'
+       },
+
        AnimationPan: {
                src: [
                        'dom/DomEvent.js',
diff --git a/loleaflet/debug/document/document_simple_example.html 
b/loleaflet/debug/document/document_simple_example.html
index 27edf71..772caf3 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -50,7 +50,7 @@
 
     var filePath = getParameterByName('file_path');
     var host = getParameterByName('host');
-    var editMode = getParameterByName('edit') === 'true';
+    var edit = getParameterByName('edit') === 'true';
     if (filePath === '') {
         alert('Wrong file_path, usage: file_path=/path/to/doc/');
     }
@@ -71,7 +71,7 @@
     var docLayer = new L.TileLayer('', {
         doc: filePath,
         useSocket : true,
-        editMode: editMode,
+        edit: edit,
         readOnly: false
     });
     map.addLayer(docLayer);
diff --git a/loleaflet/src/control/Control.EditView.js 
b/loleaflet/src/control/Control.EditView.js
deleted file mode 100644
index 748d312..0000000
--- a/loleaflet/src/control/Control.EditView.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * L.Control.EditView is used for switching between viewing and editing mode
- */
-
-L.Control.EditViewSwitch = L.Control.extend({
-       options: {
-               position: 'topleft'
-       },
-
-       onAdd: function (map) {
-               var partName = 'leaflet-control-editviewswitch',
-                       container = L.DomUtil.create('label', partName + ' 
leaflet-bar');
-
-               this._checkBox = L.DomUtil.create('input', 'editview-cb', 
container);
-               this._checkBox.type = 'checkbox';
-               L.DomEvent.on(this._checkBox, 'change', this._onChange, this);
-               map.on('updatemode:view updatemode:edit updatemode:readonly', 
this._onUpdateMode, this);
-               container.appendChild(document.createTextNode('Enable 
editing'));
-               return container;
-       },
-
-       _onChange: function () {
-               var className = 'leaflet-editmode';
-               if (this._checkBox.checked) {
-                       this._map.fire('editmode');
-                       L.DomUtil.addClass(this._map._container, className);
-               }
-               else {
-                       this._map.fire('viewmode');
-                       L.DomUtil.removeClass(this._map._container, className);
-               }
-       },
-
-       _onUpdateMode: function (e) {
-               var className = 'leaflet-editmode';
-               if (e.type === 'updatemode:edit') {
-                       this._map.fire('editmode');
-                       L.DomUtil.addClass(this._map._container, className);
-                       this._checkBox.checked = true;
-               }
-               else if (e.type === 'updatemode:view') {
-                       this._map.fire('viewmode');
-                       L.DomUtil.removeClass(this._map._container, className);
-                       this._checkBox.checked = false;
-               }
-               else if (e.type === 'updatemode:readonly') {
-                       this._checkBox.disabled = true;
-               }
-       }
-});
-
-L.Map.mergeOptions({
-       editViewSwitchControl: true
-});
-
-L.Map.addInitHook(function () {
-       if (this.options.editViewSwitchControl) {
-               this.editViewSwitchControl = new L.Control.EditViewSwitch();
-               this.addControl(this.editViewSwitchControl);
-       }
-});
-
-L.control.editViewSwitch = function (options) {
-       return new L.Control.EditViewSwitch(options);
-};
diff --git a/loleaflet/src/control/Control.Permission.js 
b/loleaflet/src/control/Control.Permission.js
new file mode 100644
index 0000000..dee99e9
--- /dev/null
+++ b/loleaflet/src/control/Control.Permission.js
@@ -0,0 +1,60 @@
+/*
+ * L.Control.EditView is used for switching between viewing and editing mode
+ */
+
+L.Control.PermissionSwitch = L.Control.extend({
+       options: {
+               position: 'topleft'
+       },
+
+       onAdd: function (map) {
+               var partName = 'leaflet-control-editviewswitch',
+                       container = L.DomUtil.create('label', partName + ' 
leaflet-bar');
+
+               this._checkBox = L.DomUtil.create('input', 'editview-cb', 
container);
+               this._checkBox.type = 'checkbox';
+               L.DomEvent.on(this._checkBox, 'change', this._onChange, this);
+               map.on('updatepermission', this._onUpdatePermission, this);
+               container.appendChild(document.createTextNode('Enable 
editing'));
+               return container;
+       },
+
+       _onChange: function () {
+               if (this._checkBox.checked) {
+                       this._map.setPermission('edit');
+               }
+               else {
+                       this._map.setPermission('view');
+               }
+       },
+
+       _onUpdatePermission: function (e) {
+               if (e.perm === 'edit') {
+                       this._checkBox.checked = true;
+                       this._checkBox.disabled = false;
+               }
+               else if (e.perm === 'view') {
+                       this._checkBox.checked = false;
+                       this._checkBox.disabled = false;
+               }
+               else if (e.perm === 'readonly') {
+                       this._checkBox.checked = false;
+                       this._checkBox.disabled = true;
+               }
+       }
+});
+
+L.Map.mergeOptions({
+       permissionSwitchControl: true
+});
+
+L.Map.addInitHook(function () {
+       if (this.options.permissionSwitchControl) {
+               this.permissionSwitchControl = new L.Control.PermissionSwitch();
+               this.addControl(this.permissionSwitchControl);
+       }
+});
+
+L.control.permissionSwitch = function (options) {
+       return new L.Control.PermissionSwitch(options);
+};
diff --git a/loleaflet/src/control/Permission.js 
b/loleaflet/src/control/Permission.js
new file mode 100644
index 0000000..6933f64
--- /dev/null
+++ b/loleaflet/src/control/Permission.js
@@ -0,0 +1,23 @@
+/*
+ * Document permission handler
+ */
+L.Map.include({
+       setPermission: function (perm) {
+               this._docLayer._permission = perm;
+               var className = 'leaflet-editmode';
+               if (perm === 'edit') {
+                       this.dragging.disable();
+                       L.DomUtil.addClass(this._container, className);
+               }
+               else if (perm === 'view' || perm === 'readonly') {
+                       this.dragging.enable();
+                       // disable all user interaction, will need to add 
keyboard too
+                       this._docLayer._onUpdateCursor();
+                       this._docLayer._clearSelections();
+                       this._docLayer._onUpdateTextSelection();
+                       L.DomUtil.removeClass(this._container, className);
+               }
+               this.fire('updatepermission', {perm : perm});
+       }
+});
+
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 4516a21..7271ff0 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -138,7 +138,7 @@ L.TileLayer = L.GridLayer.extend({
                }
                this._documentInfo = '';
                // View or edit mode.
-               this._editMode = false;
+               this._permission = 'view';
                // Position and size of the visible cursor.
                this._visibleCursor = new L.LatLngBounds(new L.LatLng(0, 0), 
new L.LatLng(0, 0));
                // Cursor overlay is visible or hidden (for blinking).
@@ -193,19 +193,17 @@ L.TileLayer = L.GridLayer.extend({
                this._map.on('zoomstart zoomend', this._onZoom, this);
                this._map.on('clearselection', this._clearSelections, this);
                this._map.on('prevpart nextpart', this._onSwitchPart, this);
-               this._map.on('viewmode editmode', this._updateEditViewMode, 
this);
                this._map.on('drag', this._updateScrollOffset, this);
                this._map.on('copy', this._onCopy, this);
                this._map.on('mousedown mouseup mouseover mouseout mousemove 
dblclick',
                                this._onMouseEvent, this);
                this._startMarker.on('drag dragend', 
this._onSelectionHandleDrag, this);
                this._endMarker.on('drag dragend', this._onSelectionHandleDrag, 
this);
-               if (this.options.editMode && !this.options.readOnly) {
-                       this._map.fire('updatemode:edit');
+               if (this.options.edit && !this.options.readOnly) {
+                       this._map.setPermission('edit');
                }
                if (this.options.readOnly) {
-                       this._map.fire('updatemode:readonly');
-                       this._readOnlyMode = true;
+                       this._map.setPermission('readonly');
                }
        },
 
@@ -730,7 +728,7 @@ L.TileLayer = L.GridLayer.extend({
                        return;
                }
 
-               if (this._readOnlyMode) {
+               if (this._permission === 'readonly') {
                        return;
                }
 
@@ -746,7 +744,7 @@ L.TileLayer = L.GridLayer.extend({
                }
                else if (e.type === 'mouseup') {
                        this._mouseDown = false;
-                       if (!this._editMode) {
+                       if (this._permission !== 'edit') {
                                if (this._mouseEventsQueue.length === 0) {
                                        // mouse up after panning
                                        return;
@@ -765,9 +763,8 @@ L.TileLayer = L.GridLayer.extend({
                                        // it's a click, fire mousedown
                                        this._mouseEventsQueue[0]();
                                        this._clickTime = Date.now();
-                                       if (!this._editMode) {
-                                               this._editMode = true;
-                                               
this._map.fire('updatemode:edit');
+                                       if (this._permission !== 'edit') {
+                                               this._map.setPermission('edit');
                                        }
                                }
                                this._mouseEventsQueue = [];
@@ -787,7 +784,7 @@ L.TileLayer = L.GridLayer.extend({
                        if (this._holdMouseEvent) {
                                clearTimeout(this._holdMouseEvent);
                                this._holdMouseEvent = null;
-                               if (!this._editMode) {
+                               if (this._permission !== 'edit') {
                                        // The user just panned the document
                                        this._mouseEventsQueue = [];
                                        return;
@@ -799,7 +796,7 @@ L.TileLayer = L.GridLayer.extend({
                                }
                                this._mouseEventsQueue = [];
                        }
-                       if (this._editMode) {
+                       if (this._permission === 'edit') {
                                mousePos = this._latLngToTwips(e.latlng);
                                this._postMouseEvent('move', mousePos.x, 
mousePos.y, 1);
                                if (this._startMarker._icon) {
@@ -821,15 +818,14 @@ L.TileLayer = L.GridLayer.extend({
 
        _executeMouseEvents: function () {
                this._holdMouseEvent = null;
-               if (this._mouseEventsQueue.length === 1 && !this._editMode) {
+               if (this._mouseEventsQueue.length === 1 && this._permission !== 
'edit') {
                        // long mouse down or a mouseup after panning
                        this._mouseEventsQueue = [];
                        return;
                }
-               else if (!this._editMode) {
+               else if (this._permission !== 'edit') {
                        // this time we have a mousedown and mouseup
-                       this._editMode = true;
-                       this._map.fire('updatemode:edit');
+                       this._map.setPermission('edit');
                }
                for (var i = 0; i < this._mouseEventsQueue.length; i++) {
                        this._mouseEventsQueue[i]();
@@ -853,22 +849,6 @@ L.TileLayer = L.GridLayer.extend({
                this._clearSelections();
        },
 
-       _updateEditViewMode: function (e) {
-               if (e.type === 'viewmode') {
-                       this._map.dragging.enable();
-                       // disable all user interaction, will need to add 
keyboard too
-                       this._editMode = false;
-                       this._onUpdateCursor();
-                       this._clearSelections();
-                       this._onUpdateTextSelection();
-               }
-               else if (e.type === 'editmode') {
-                       this._editMode = true;
-                       this._map.dragging.disable();
-                       this._map._container.focus();
-               }
-       },
-
        // Convert javascript key codes to UNO key codes.
        _toUNOKeyCode: function (keyCode) {
                return this.keymap[keyCode] || keyCode;
@@ -876,7 +856,7 @@ L.TileLayer = L.GridLayer.extend({
 
        // Receives a key press or release event.
        _signalKey: function (e) {
-               if (!this._editMode) {
+               if (this._permission !== 'edit') {
                        return;
                }
 
@@ -918,7 +898,8 @@ L.TileLayer = L.GridLayer.extend({
 
        // Update cursor layer (blinking cursor).
        _onUpdateCursor: function () {
-               if (this._editMode && this._isCursorVisible && 
this._isCursorOverlayVisible && !this._isEmptyRectangle(this._visibleCursor)) {
+               if (this._permission === 'edit' && this._isCursorVisible && 
this._isCursorOverlayVisible
+                               && 
!this._isEmptyRectangle(this._visibleCursor)) {
                        if (this._cursorMarker) {
                                this._map.removeLayer(this._cursorMarker);
                        }
commit 6e720f9cf2a2e402b266c6d3205b026e2b64b16c
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Fri Jul 10 11:00:53 2015 +0300

    loleaflet: exposed the 'search' API: map.search()

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index ec73c3e..da31dae 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -253,6 +253,11 @@ var deps = {
                desc: 'Layer Switcher control.'
        },
 
+       Search: {
+               src: ['control/Search.js'],
+               desc: 'Search command handler.'
+       },
+
        AnimationPan: {
                src: [
                        'dom/DomEvent.js',
diff --git a/loleaflet/src/control/Control.Search.js 
b/loleaflet/src/control/Control.Search.js
index 39e7cb7..0973607 100644
--- a/loleaflet/src/control/Control.Search.js
+++ b/loleaflet/src/control/Control.Search.js
@@ -27,16 +27,6 @@ L.Control.Search = L.Control.extend({
                                searchName + '-next', container, 
this._searchNext);
                this._cancelButton = this._createButton(options.cancelText, 
options.cancelTitle,
                                searchName + '-cancel', container, 
this._cancel);
-               this._searchCmd = {
-                       'SearchItem.SearchString': {
-                               'type': 'string',
-                               'value': ''
-                       },
-                       'SearchItem.Backward': {
-                               'type': 'boolean',
-                               'value': false
-                       }
-               };
 
                this._disabled = true;
                this._updateDisabled();
@@ -50,28 +40,10 @@ L.Control.Search = L.Control.extend({
        },
 
        _searchStart: function (e) {
-               this._map.fire('clearselection');
-               var viewTopLeftpx = 
this._map.project(this._map.getBounds().getNorthWest());
-               var docBoundsTopLeft = 
this._map.project(this._map.options.maxBounds.getNorthWest());
-               var topLeft = this._map.unproject(new L.Point(
-                               Math.max(viewTopLeftpx.x, docBoundsTopLeft.x),
-                               Math.max(viewTopLeftpx.y, docBoundsTopLeft.y)));
-               var topLeftTwips = this._map._docLayer._latLngToTwips(topLeft);
-
                if (e.keyCode === 13 && this._searchBar.value !== '') {
+                       this._map.search(this._searchBar.value);
                        this._disabled = false;
                        this._updateDisabled();
-                       this._searchCmd['SearchItem.SearchString'].value = 
this._searchBar.value;
-                       this._searchCmd['SearchItem.Backward'].value = false;
-                       this._searchCmd['SearchItem.SearchStartPointX'] = {};
-                       this._searchCmd['SearchItem.SearchStartPointX'].type = 
'long';
-                       this._searchCmd['SearchItem.SearchStartPointX'].value = 
topLeftTwips.x;
-                       this._searchCmd['SearchItem.SearchStartPointY'] = {};
-                       this._searchCmd['SearchItem.SearchStartPointY'].type = 
'long';
-                       this._searchCmd['SearchItem.SearchStartPointY'].value = 
topLeftTwips.y;
-                       this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
-                       delete this._searchCmd['SearchItem.SearchStartPointX'];
-                       delete this._searchCmd['SearchItem.SearchStartPointY'];
                        this._refocusOnMap();
                }
        },
@@ -87,16 +59,12 @@ L.Control.Search = L.Control.extend({
        },
 
        _searchPrev: function () {
-               this._searchCmd['SearchItem.Backward'].value = true;
-               this._searchCmd['SearchItem.SearchString'].value = 
this._searchBar.value;
-               this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
+               this._map.search(this._searchBar.value, true);
                this._refocusOnMap();
        },
 
        _searchNext: function () {
-               this._searchCmd['SearchItem.Backward'].value = false;
-               this._searchCmd['SearchItem.SearchString'].value = 
this._searchBar.value;
-               this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
+               this._map.search(this._searchBar.value);
                this._refocusOnMap();
        },
 
diff --git a/loleaflet/src/control/Search.js b/loleaflet/src/control/Search.js
new file mode 100644
index 0000000..a60d9da
--- /dev/null
+++ b/loleaflet/src/control/Search.js
@@ -0,0 +1,34 @@
+L.Map.include({
+       search: function (text, backward) {
+               if (backward === undefined) {
+                       backward = false;
+               }
+
+               var searchCmd = {
+                       'SearchItem.SearchString': {
+                               'type': 'string'
+                       },
+                       'SearchItem.Backward': {
+                               'type': 'boolean'
+                       }
+               };
+
+               this.fire('clearselection');
+               var viewTopLeftpx = 
this.project(this.getBounds().getNorthWest());
+               var docBoundsTopLeft = 
this.project(this.options.maxBounds.getNorthWest());
+               var topLeft = this.unproject(new L.Point(
+                               Math.max(viewTopLeftpx.x, docBoundsTopLeft.x),
+                               Math.max(viewTopLeftpx.y, docBoundsTopLeft.y)));
+               var topLeftTwips = this._docLayer._latLngToTwips(topLeft);
+
+               searchCmd['SearchItem.SearchString'].value = text;
+               searchCmd['SearchItem.Backward'].value = backward;
+               searchCmd['SearchItem.SearchStartPointX'] = {};
+               searchCmd['SearchItem.SearchStartPointX'].type = 'long';
+               searchCmd['SearchItem.SearchStartPointX'].value = 
topLeftTwips.x;
+               searchCmd['SearchItem.SearchStartPointY'] = {};
+               searchCmd['SearchItem.SearchStartPointY'].type = 'long';
+               searchCmd['SearchItem.SearchStartPointY'].value = 
topLeftTwips.y;
+               this.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(searchCmd));
+       }
+});
commit c174a15d98d12d6291e443d4de46eea0137f7f93
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Thu Jul 9 09:28:41 2015 +0300

    loleaflet: restore focus to the document after toolbar interaction

diff --git a/loleaflet/src/control/Control.Search.js 
b/loleaflet/src/control/Control.Search.js
index c007067..39e7cb7 100644
--- a/loleaflet/src/control/Control.Search.js
+++ b/loleaflet/src/control/Control.Search.js
@@ -72,6 +72,7 @@ L.Control.Search = L.Control.extend({
                        this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
                        delete this._searchCmd['SearchItem.SearchStartPointX'];
                        delete this._searchCmd['SearchItem.SearchStartPointY'];
+                       this._refocusOnMap();
                }
        },
 
@@ -89,12 +90,14 @@ L.Control.Search = L.Control.extend({
                this._searchCmd['SearchItem.Backward'].value = true;
                this._searchCmd['SearchItem.SearchString'].value = 
this._searchBar.value;
                this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
+               this._refocusOnMap();
        },
 
        _searchNext: function () {
                this._searchCmd['SearchItem.Backward'].value = false;
                this._searchCmd['SearchItem.SearchString'].value = 
this._searchBar.value;
                this._map.socket.send('uno .uno:ExecuteSearch ' + 
JSON.stringify(this._searchCmd));
+               this._refocusOnMap();
        },
 
        _cancel: function () {
@@ -102,6 +105,7 @@ L.Control.Search = L.Control.extend({
                this._map.fire('clearselection');
                this._disabled = true;
                this._updateDisabled();
+               this._refocusOnMap();
        },
 
        _createSearchBar: function(title, className, container, fn) {
diff --git a/loleaflet/src/control/Control.js b/loleaflet/src/control/Control.js
index 2ce6973..2dd433b 100644
--- a/loleaflet/src/control/Control.js
+++ b/loleaflet/src/control/Control.js
@@ -71,9 +71,11 @@ L.Control = L.Class.extend({
                return this;
        },
 
-       _refocusOnMap: function (e) {
-               // if map exists and event is not a keyboard event
-               if (this._map && e && e.screenX > 0 && e.screenY > 0) {
+       _refocusOnMap: function () {
+               if (this._map._docLayer._editMode) {
+                       this._map._docLayer._textArea.focus();
+               }
+               else {
                        this._map.getContainer().focus();
                }
        }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to