From 5b997de415df10e2143406b42297c3571831dabc Mon Sep 17 00:00:00 2001 From: Pablo Luna Date: Sat, 20 Nov 2010 23:43:54 +0100 Subject: [PATCH] Adding Chrome, Safari and IE9 support --- core-js/src/main/javascript/UserAgent.js | 8 + core-js/src/main/javascript/Utils.js | 3 + mindplot/src/main/javascript/DragManager.js | 95 +- .../src/main/javascript/MindmapDesigner.js | 5 +- mindplot/src/main/javascript/ScreenManager.js | 46 +- mindplot/src/main/javascript/Workspace.js | 65 +- .../src/main/javascript/peer/svg/TextPeer.js | 44 +- web2d/src/test/javascript/render/events.html | 231 +- web2d/src/test/javascript/render/group.html | 712 +- web2d/src/test/javascript/render/line.html | 194 +- .../src/test/javascript/render/polyLine.html | 332 +- .../src/test/javascript/render/prototype.html | 341 +- web2d/src/test/javascript/render/rect.html | 110 +- web2d/src/test/javascript/render/shapes.html | 586 +- web2d/src/test/javascript/render/text.html | 93 +- .../javascript/render/web2dLibraryLoader.js | 91 +- .../src/test/javascript/render/workspace.html | 387 +- .../com/wisemapping/filter/UserAgent.java | 28 +- wise-webapp/src/main/webapp/css/editor.css | 9 + wise-webapp/src/main/webapp/js/mootools.js | 14306 ++++++++-------- .../src/main/webapp/jsp/mindmapEditor.jsp | 18 +- 21 files changed, 9030 insertions(+), 8674 deletions(-) diff --git a/core-js/src/main/javascript/UserAgent.js b/core-js/src/main/javascript/UserAgent.js index 43bb9d29..c18e83a9 100644 --- a/core-js/src/main/javascript/UserAgent.js +++ b/core-js/src/main/javascript/UserAgent.js @@ -24,6 +24,9 @@ core.UserAgent = { if (!core.Utils.isDefined()) { this._isVMLSupported = navigator.appVersion.match(/MSIE (\d\.\d)/); + if(this._isVMLSupported == null || parseInt(this._isVMLSupported[1])>=9){ + this._isVMLSupported = false; + } } return this._isVMLSupported; }, @@ -75,6 +78,11 @@ core.UserAgent = { subString: "Apple", identity: "Safari" }, + { + string: navigator.vendor, + subString: "Google Inc.", + identity: "Chrome" + }, { prop: window.opera, identity: "Opera" diff --git a/core-js/src/main/javascript/Utils.js b/core-js/src/main/javascript/Utils.js index 9c3fc142..e61fa982 100644 --- a/core-js/src/main/javascript/Utils.js +++ b/core-js/src/main/javascript/Utils.js @@ -101,6 +101,9 @@ core.Utils.getMousePosition = function(event) throw "Could not obtain mouse position"; } } + if(core.Utils.isDefined(event.$extended)){ + event = event.event; + } if (typeof( event.pageX ) == 'number') { //most browsers xcoord = event.pageX; diff --git a/mindplot/src/main/javascript/DragManager.js b/mindplot/src/main/javascript/DragManager.js index 69194c2e..a119b56c 100644 --- a/mindplot/src/main/javascript/DragManager.js +++ b/mindplot/src/main/javascript/DragManager.js @@ -1,29 +1,27 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* $Id: file 64488 2006-03-10 17:32:09Z paulo $ -*/ - +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * $Id: file 64488 2006-03-10 17:32:09Z paulo $ + */ + mindplot.DragManager = function(workspace) { this._workspace = workspace; this._listeners = {}; - this._processMouseMoveEvent = true; var dragManager = this; - this._precitionUpdater = null; }; mindplot.DragManager.prototype.add = function(node) @@ -44,19 +42,14 @@ mindplot.DragManager.prototype.add = function(node) var dragNode = node.createDragNode(); var mousePos = screen.getWorkspaceMousePosition(event); dragNode.setPosition(mousePos.x, mousePos.y); - var periodicalFunction = function() { - dragManager._processMouseMoveEvent = true; - }; - // Start precision timer updater ... - dragManager._precitionUpdater = periodicalFunction.periodical(mindplot.DragManager.DRAG_PRECISION_IN_SEG); // Register mouse move listener ... var mouseMoveListener = dragManager._buildMouseMoveListener(workspace, dragNode, dragManager); - workspace.addEventListener('mousemove', mouseMoveListener); + screen.addEventListener('mousemove', mouseMoveListener); // Register mouse up listeners ... var mouseUpListener = dragManager._buildMouseUpListener(workspace, node, dragNode, dragManager); - workspace.addEventListener('mouseup', mouseUpListener); + screen.addEventListener('mouseup', mouseUpListener); // Execute Listeners .. var startDragListener = dragManager._listeners['startdragging']; @@ -92,28 +85,26 @@ mindplot.DragManager.prototype._buildMouseMoveListener = function(workspace, dra { var screen = workspace.getScreenManager(); var result = function(event) { - if (dragManager._processMouseMoveEvent) + + if (!dragNode._isInTheWorkspace) { - // Disable mouse move rendering ... - dragManager._processMouseMoveEvent = false; - if (!dragNode._isInTheWorkspace) - { - // Add shadow node to the workspace. - workspace.appendChild(dragNode); - dragNode._isInTheWorkspace = true; - } - - var pos = screen.getWorkspaceMousePosition(event); - dragNode.setPosition(pos.x, pos.y); - - // Call mouse move listeners ... - var dragListener = dragManager._listeners['dragging']; - if (dragListener) - { - dragListener(event, dragNode); - } + // Add shadow node to the workspace. + workspace.appendChild(dragNode); + dragNode._isInTheWorkspace = true; } - }; + + var pos = screen.getWorkspaceMousePosition(event); + dragNode.setPosition(pos.x, pos.y); + + // Call mouse move listeners ... + var dragListener = dragManager._listeners['dragging']; + if (dragListener) + { + dragListener(event, dragNode); + } + + event.preventDefault(); + }.bindWithEvent(this); dragManager._mouseMoveListener = result; return result; }; @@ -133,8 +124,8 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, } // Remove all the events. - workspace.removeEventListener('mousemove', dragManager._mouseMoveListener); - workspace.removeEventListener('mouseup', dragManager._mouseUpListener); + screen.removeEventListener('mousemove', dragManager._mouseMoveListener); + screen.removeEventListener('mouseup', dragManager._mouseUpListener); // Help GC dragManager._mouseMoveListener = null; @@ -149,10 +140,6 @@ mindplot.DragManager.prototype._buildMouseUpListener = function(workspace, node, dragNode._isInTheWorkspace = false; } - // Stop presition updater listener ... - $clear(dragManager._precitionUpdater); - dragManager._precitionUpdater = null; - // Change the cursor to the default. window.document.body.style.cursor = 'default'; diff --git a/mindplot/src/main/javascript/MindmapDesigner.js b/mindplot/src/main/javascript/MindmapDesigner.js index e781f953..2f074a88 100644 --- a/mindplot/src/main/javascript/MindmapDesigner.js +++ b/mindplot/src/main/javascript/MindmapDesigner.js @@ -159,17 +159,16 @@ mindplot.MindmapDesigner.prototype._registerEvents = function() if (!this._viewMode) { - // Initialize workspace event listeners. // Create nodes on double click... - workspace.addEventListener('click', function(event) + screenManager.addEventListener('click', function(event) { mindmapDesigner.getEditor().lostFocus(); // @todo: Puaj hack... mindmapDesigner._cleanScreen(); }); - workspace.addEventListener('dblclick', function(event) + screenManager.addEventListener('dblclick', function(event) { mindmapDesigner.getEditor().lostFocus(); // Get mouse position diff --git a/mindplot/src/main/javascript/ScreenManager.js b/mindplot/src/main/javascript/ScreenManager.js index d7abf07b..d3701fb8 100644 --- a/mindplot/src/main/javascript/ScreenManager.js +++ b/mindplot/src/main/javascript/ScreenManager.js @@ -1,22 +1,22 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* $Id: file 64488 2006-03-10 17:32:09Z paulo $ -*/ - +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* $Id: file 64488 2006-03-10 17:32:09Z paulo $ +*/ + mindplot.ScreenManager = function(width, height, divElement) { this._divContainer = divElement; @@ -29,6 +29,14 @@ mindplot.ScreenManager.prototype.setScale = function(scale) this._workspaceScale = scale; }; +mindplot.ScreenManager.prototype.addEventListener=function(event, listener){ + $(this._divContainer).addListener(event, listener); +}; + +mindplot.ScreenManager.prototype.removeEventListener=function(event, listener){ + $(this._divContainer).removeListener(event, listener); +}; + mindplot.ScreenManager.prototype.getWorkspaceElementPosition = function(e) { // Retrive current element position. diff --git a/mindplot/src/main/javascript/Workspace.js b/mindplot/src/main/javascript/Workspace.js index 76207fa1..aa801437 100644 --- a/mindplot/src/main/javascript/Workspace.js +++ b/mindplot/src/main/javascript/Workspace.js @@ -1,22 +1,22 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* $Id: file 64488 2006-03-10 17:32:09Z paulo $ -*/ - +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* $Id: file 64488 2006-03-10 17:32:09Z paulo $ +*/ + mindplot.Workspace = function(profile, screenManager, zoom) { // Create a suitable container ... @@ -182,18 +182,9 @@ mindplot.Workspace.prototype._registerDragEvents = function() var mouseDownPosition = screenManager.getWorkspaceMousePosition(event); var originalCoordOrigin = workspace.getCoordOrigin(); - var periodicalFunction = function() { - mWorkspace._processMouseMoveEvent = true; - }; - // Start precision timer updater ... - mWorkspace._precitionUpdater = periodicalFunction.periodical(mindplot.Workspace.DRAG_PRECISION_IN_SEG); workspace.mouseMoveListener = function(event) { - if (mWorkspace._processMouseMoveEvent) - { - // Disable mouse move rendering ... - mWorkspace._processMouseMoveEvent = false; var currentMousePosition = screenManager.getWorkspaceMousePosition(event); @@ -213,19 +204,16 @@ mindplot.Workspace.prototype._registerDragEvents = function() { window.document.body.style.cursor = "move"; } - } - }; - workspace.addEventListener('mousemove', workspace.mouseMoveListener); + event.preventDefault(); + }.bindWithEvent(this); + screenManager.addEventListener('mousemove', workspace.mouseMoveListener); // Register mouse up listeners ... workspace.mouseUpListener = function(event) { - // Stop presition updater listener ... - $clear(mWorkspace._precitionUpdater); - mWorkspace._precitionUpdater = null; - workspace.removeEventListener('mousemove', workspace.mouseMoveListener); - workspace.removeEventListener('mouseup', workspace.mouseUpListener); + screenManager.removeEventListener('mousemove', workspace.mouseMoveListener); + screenManager.removeEventListener('mouseup', workspace.mouseUpListener); workspace.mouseUpListener = null; workspace.mouseMoveListener = null; window.document.body.style.cursor = 'default'; @@ -235,7 +223,7 @@ mindplot.Workspace.prototype._registerDragEvents = function() screenManager.setOffset(coordOrigin.x, coordOrigin.y); mWorkspace.enableWorkspaceEvents(true); }; - workspace.addEventListener('mouseup', workspace.mouseUpListener); + screenManager.addEventListener('mouseup', workspace.mouseUpListener); } } else { @@ -243,7 +231,6 @@ mindplot.Workspace.prototype._registerDragEvents = function() } }; - workspace.addEventListener('mousedown', mouseDownListener); + screenManager.addEventListener('mousedown', mouseDownListener); }; -mindplot.Workspace.DRAG_PRECISION_IN_SEG = 50; diff --git a/web2d/src/main/javascript/peer/svg/TextPeer.js b/web2d/src/main/javascript/peer/svg/TextPeer.js index 20241b58..7adb0f19 100644 --- a/web2d/src/main/javascript/peer/svg/TextPeer.js +++ b/web2d/src/main/javascript/peer/svg/TextPeer.js @@ -1,22 +1,22 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one or more -* contributor license agreements. See the NOTICE file distributed with -* this work for additional information regarding copyright ownership. -* The ASF licenses this file to You under the Apache License, Version 2.0 -* (the "License"); you may not use this file except in compliance with -* the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -* $Id: file 64488 2006-03-10 17:32:09Z paulo $ -*/ - +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. See the NOTICE file distributed with +* this work for additional information regarding copyright ownership. +* The ASF licenses this file to You under the Apache License, Version 2.0 +* (the "License"); you may not use this file except in compliance with +* the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* $Id: file 64488 2006-03-10 17:32:09Z paulo $ +*/ + web2d.peer.svg.TextPeer = function() { var svgElement = window.document.createElementNS(this.svgNamespace, 'text'); @@ -167,14 +167,16 @@ web2d.peer.svg.TextPeer.prototype.setSize = function (size) web2d.peer.svg.TextPeer.prototype.getWidth = function () { - var width = parseInt(this._native.getComputedTextLength()); + var computedWidth = this._native.getBBox().width; + var width = parseInt(computedWidth); width = width + this._font.getWidthMargin(); return width; }; web2d.peer.svg.TextPeer.prototype.getHeight = function () { - return this._font.getGraphSize(); + var computedHeight = this._native.getBBox().height; + return parseInt(computedHeight); }; web2d.peer.svg.TextPeer.prototype.getHtmlFontSize = function () diff --git a/web2d/src/test/javascript/render/events.html b/web2d/src/test/javascript/render/events.html index f5e62fa3..3aed4cdd 100755 --- a/web2d/src/test/javascript/render/events.html +++ b/web2d/src/test/javascript/render/events.html @@ -2,7 +2,62 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +