[Libreoffice-commits] online.git: 2 commits - loleaflet/dist loleaflet/src loolwsd/LOOLKit.cpp
Pranav Kant
pranavk at collabora.co.uk
Mon Oct 10 07:50:41 UTC 2016
loleaflet/dist/toolbar/toolbar.js | 2 -
loleaflet/src/core/LOUtil.js | 20 +-----------
loleaflet/src/layer/tile/TileLayer.js | 14 ++++----
loleaflet/src/map/Map.js | 15 +++++++--
loolwsd/LOOLKit.cpp | 53 ++++++++++++++++++++++++++++++++--
5 files changed, 72 insertions(+), 32 deletions(-)
New commits:
commit 0ad39593d02e139e5f0bba0b8262d7c12563663a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Oct 6 20:07:53 2016 +0530
loleaflet: Use view colors directly from core
Change-Id: I2fdffd6dd0823a77ff52e40150a81db4b261ec81
diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js
index fc35a45..9003281 100644
--- a/loleaflet/dist/toolbar/toolbar.js
+++ b/loleaflet/dist/toolbar/toolbar.js
@@ -1346,7 +1346,7 @@ map.on('addview', function(e) {
}, 3000);
var username = e.username;
- var color = L.LOUtil.getViewIdHexColor(e.viewId);
+ var color = L.LOUtil.rgbToHex(e.color);
if (e.viewId === map._docLayer._viewId) {
username = _('You');
color = '#000';
diff --git a/loleaflet/src/core/LOUtil.js b/loleaflet/src/core/LOUtil.js
index 24c516b..4ebb9d1 100644
--- a/loleaflet/src/core/LOUtil.js
+++ b/loleaflet/src/core/LOUtil.js
@@ -3,20 +3,6 @@
*/
L.LOUtil = {
- // Based on core.git's colordata.hxx: COL_AUTHOR1_DARK...COL_AUTHOR9_DARK
- // consisting of arrays of RGB values
- // Maybe move the color logic to separate file when it becomes complex
- darkColors: [
- [198, 146, 0],
- [87, 157, 28],
- [105, 43, 157],
- [197, 0, 11],
- [0, 128, 128],
- [140, 132, 0],
- [53, 85, 107],
- [209, 118, 0]
- ],
-
startSpinner: function (spinnerCanvas, spinnerSpeed) {
var spinnerInterval;
spinnerCanvas.width = 50;
@@ -42,9 +28,7 @@ L.LOUtil = {
return spinnerInterval;
},
- getViewIdHexColor: function(viewId) {
- var color = this.darkColors[(viewId + 1) % this.darkColors.length];
- var hex = color[2] | (color[1] << 8) | (color[0] << 16);
- return '#' + ('000000' + hex.toString(16)).slice(-6);
+ rgbToHex: function(color) {
+ return '#' + ('000000' + color.toString(16)).slice(-6);
}
};
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index a5aad09..452a93c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -682,7 +682,7 @@ L.TileLayer = L.GridLayer.extend({
if (!this._isEmptyRectangle(this._cellViewCursors[viewId].bounds) && this._selectedPart === viewPart) {
if (!cellViewCursorMarker) {
- var borderColor = L.LOUtil.getViewIdHexColor(viewId);
+ var borderColor = L.LOUtil.rgbToHex(this._map.getViewColor(viewId));
cellViewCursorMarker = L.rectangle(this._cellViewCursors[viewId].bounds, {fill: false, color: borderColor, weight: 2});
this._cellViewCursors[viewId].marker = cellViewCursorMarker;
cellViewCursorMarker.bindPopup(this._map.getViewName(viewId), {autoClose: false, autoPan: false, borderColor: borderColor});
@@ -714,8 +714,8 @@ L.TileLayer = L.GridLayer.extend({
this._onUpdateViewCursor(viewId);
},
- _addView: function(viewId, username) {
- this._map.addView(viewId, username);
+ _addView: function(viewId, username, color) {
+ this._map.addView(viewId, username, color);
//TODO: We can initialize color and other properties here.
if (typeof this._viewCursors[viewId] !== 'undefined') {
@@ -755,7 +755,7 @@ L.TileLayer = L.GridLayer.extend({
var viewIds = [];
for (var viewInfoIdx in viewInfo) {
if (!(parseInt(viewInfo[viewInfoIdx].id) in this._map._viewInfo)) {
- this._addView(viewInfo[viewInfoIdx].id, viewInfo[viewInfoIdx].username);
+ this._addView(viewInfo[viewInfoIdx].id, viewInfo[viewInfoIdx].username, viewInfo[viewInfoIdx].color);
}
viewIds.push(viewInfo[viewInfoIdx].id);
}
@@ -1235,7 +1235,7 @@ L.TileLayer = L.GridLayer.extend({
(this._docType === 'text' || this._selectedPart === viewPart)) {
if (!viewCursorMarker) {
var viewCursorOptions = {
- color: L.LOUtil.getViewIdHexColor(viewId),
+ color: L.LOUtil.rgbToHex(this._map.getViewColor(viewId)),
blink: false,
header: true, // we want a 'hat' to our view cursors (which will contain view user names)
headerTimeout: 3000, // hide after some interval
@@ -1272,7 +1272,7 @@ L.TileLayer = L.GridLayer.extend({
viewSelection = new L.Polygon(viewPolygons, {
pointerEvents: 'none',
- fillColor: L.LOUtil.getViewIdHexColor(viewId),
+ fillColor: L.LOUtil.rgbToHex(this._map.getViewColor(viewId)),
fillOpacity: 0.25,
weight: 2,
opacity: 0.25
@@ -1293,7 +1293,7 @@ L.TileLayer = L.GridLayer.extend({
if (!this._isEmptyRectangle(viewBounds) &&
(this._docType === 'text' || this._selectedPart === viewPart)) {
if (!viewMarker) {
- var color = L.LOUtil.getViewIdHexColor(viewId);
+ var color = L.LOUtil.rgbToHex(this._map.getViewColor(viewId));
viewMarker = L.rectangle(viewBounds, {
pointerEvents: 'auto',
fill: false,
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 7d2dfac..38619f6 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -120,14 +120,17 @@ L.Map = L.Evented.extend({
// View info (user names and view ids)
this._viewInfo = {};
+
+ // View color map
+ this._viewColors = {};
},
// public methods that modify map state
- addView: function(viewid, username) {
- this._viewInfo[viewid] = username;
- this.fire('addview', {viewId: viewid, username: username});
+ addView: function(viewid, username, color) {
+ this._viewInfo[viewid] = {'username': username, 'color': color};
+ this.fire('addview', {viewId: viewid, username: username, color: color});
},
removeView: function(viewid) {
@@ -137,7 +140,11 @@ L.Map = L.Evented.extend({
},
getViewName: function(viewid) {
- return this._viewInfo[viewid];
+ return this._viewInfo[viewid].username;
+ },
+
+ getViewColor: function(viewid) {
+ return this._viewInfo[viewid].color;
},
// replaced by animation-powered implementation in Map.PanAnimation.js
commit 587c0e5222def90659ec5959352c56eed0df27b5
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Oct 6 20:08:24 2016 +0530
loolwsd: Forward 'color' property in 'viewinfo' message to client
Change-Id: Id7d28a46cacd662aeb371805509e5a81b90b9c90
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 852be7a..089b695 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -874,7 +874,7 @@ private:
}
return viewInfo;
- };
+ }
std::mutex& getMutex() override
{
@@ -891,6 +891,7 @@ private:
{
// Store the list of viewid, username mapping in a map
std::map<int, std::string> viewInfoMap = getViewInfo();
+ std::map<std::string, int> viewColorsMap = getViewColors();
std::unique_lock<std::mutex> lock(_mutex);
// Double check if list of viewids from core and our list matches,
@@ -901,7 +902,7 @@ private:
{
Object::Ptr viewInfoObj = new Object();
viewInfoObj->set("id", viewId);
-
+ int color = 0;
if (viewInfoMap.find(viewId) == viewInfoMap.end())
{
Log::error("No username found for viewId [" + std::to_string(viewId) + "].");
@@ -910,7 +911,12 @@ private:
else
{
viewInfoObj->set("username", viewInfoMap[viewId]);
+ if (viewColorsMap.find(viewInfoMap[viewId]) != viewColorsMap.end())
+ {
+ color = viewColorsMap[viewInfoMap[viewId]];
+ }
}
+ viewInfoObj->set("color", color);
viewInfoArray->set(arrayIndex++, viewInfoObj);
}
@@ -931,6 +937,49 @@ private:
private:
+ // Get the color value for all author names from the core
+ std::map<std::string, int> getViewColors()
+ {
+ std::string colorValues;
+ std::map<std::string, int> viewColors;
+
+ {
+ auto lock(_loKitDocument->getLock());
+
+ char* pValues = _loKitDocument->getCommandValues(".uno:TrackedChangeAuthors");
+ colorValues = std::string(pValues == nullptr ? "" : pValues);
+ std::free(pValues);
+ }
+
+ try
+ {
+ if (!colorValues.empty())
+ {
+ Poco::JSON::Parser parser;
+ auto root = parser.parse(colorValues).extract<Poco::JSON::Object::Ptr>();
+ if (root->get("authors").type() == typeid(Poco::JSON::Array::Ptr))
+ {
+ auto authorsArray = root->get("authors").extract<Poco::JSON::Array::Ptr>();
+ for (auto& authorVar: *authorsArray)
+ {
+ auto authorObj = authorVar.extract<Poco::JSON::Object::Ptr>();
+ auto authorName = authorObj->get("name").convert<std::string>();
+ auto colorValue = authorObj->get("color").convert<int>();
+ viewColors[authorName] = colorValue;
+ }
+ }
+ }
+ }
+ catch(const Exception& exc)
+ {
+ Log::error() << "Poco Exception: " << exc.displayText()
+ << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "")
+ << Log::end;
+ }
+
+ return viewColors;
+ }
+
std::shared_ptr<lok::Document> load(const std::string& sessionId,
const std::string& uri,
const std::string& userName,
More information about the Libreoffice-commits
mailing list