Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
noVNC
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
noVNC
Commits
61dd52c9
Commit
61dd52c9
authored
Jun 15, 2010
by
Joel Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mouse position routines to util.js.
On path towards removing dependency on mootools in non-UI code.
parent
e2e7c224
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
78 deletions
+71
-78
TODO
docs/TODO
+4
-0
canvas.js
include/canvas.js
+22
-34
util.js
include/util.js
+34
-0
input.html
tests/input.html
+11
-44
No files found.
docs/TODO
View file @
61dd52c9
Medium Term:
- Remove mootools dependency from vnc.js and canvas.js.
- canvas.js deps:
$(), getPosition, getScroll
- Implement Cursor pseudo-encoding (CSS cursor)
http://en.wikipedia.org/wiki/ICO_(file_format)
https://developer.mozilla.org/en/Using_URL_values_for_the_cursor_property
...
...
include/canvas.js
View file @
61dd52c9
...
...
@@ -27,26 +27,14 @@ keyPress : null,
mouseButton
:
null
,
mouseMove
:
null
,
getX
:
function
()
{
var
c
=
$
(
Canvas
.
id
);
return
c
.
getPosition
().
x
-
document
.
getScroll
().
x
;
},
getY
:
function
()
{
var
c
=
$
(
Canvas
.
id
);
return
c
.
getPosition
().
y
-
document
.
getScroll
().
y
;
},
onMouseButton
:
function
(
e
,
down
)
{
var
evt
,
x
,
y
,
bmask
;
var
evt
,
pos
,
bmask
;
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
getX
());
y
=
(
evt
.
clientY
-
Canvas
.
getY
());
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
bmask
=
1
<<
evt
.
button
;
//console.log('mouse ' + evt.which + '/' + evt.button + ' down:' +
x + "," +
y);
//console.log('mouse ' + evt.which + '/' + evt.button + ' down:' +
pos.x + "," + pos.
y);
if
(
Canvas
.
mouseButton
)
{
Canvas
.
mouseButton
(
x
,
y
,
down
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
down
,
bmask
);
}
e
.
stop
();
return
false
;
...
...
@@ -61,21 +49,19 @@ onMouseUp: function (e) {
},
onMouseWheel
:
function
(
e
)
{
var
evt
,
x
,
y
,
bmask
;
var
evt
,
pos
,
bmask
;
evt
=
e
.
event
||
window
.
event
;
//e = e ? e : window.event;
x
=
(
evt
.
clientX
-
Canvas
.
getX
());
y
=
(
evt
.
clientY
-
Canvas
.
getY
());
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
var
wheelData
=
evt
.
detail
?
evt
.
detail
*
-
1
:
evt
.
wheelDelta
/
40
;
if
(
wheelData
>
0
)
{
bmask
=
1
<<
3
;
}
else
{
bmask
=
1
<<
4
;
}
//console.log('mouse scroll by ' + wheelData + ':' +
x + "," +
y);
//console.log('mouse scroll by ' + wheelData + ':' +
pos.x + "," + pos.
y);
if
(
Canvas
.
mouseButton
)
{
Canvas
.
mouseButton
(
x
,
y
,
1
,
bmask
);
Canvas
.
mouseButton
(
x
,
y
,
0
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
1
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
0
,
bmask
);
}
e
.
stop
();
return
false
;
...
...
@@ -83,12 +69,12 @@ onMouseWheel: function (e) {
onMouseMove
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
getX
())
;
y
=
(
evt
.
clientY
-
Canvas
.
getY
(
));
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
x + "," +
y);
if
(
Canvas
.
keyPress
)
{
Canvas
.
mouseMove
(
x
,
y
);
var
evt
,
pos
;
evt
=
e
.
event
||
window
.
event
;
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
pos.x + "," + pos.
y);
if
(
Canvas
.
mouseMove
)
{
Canvas
.
mouseMove
(
pos
.
x
,
pos
.
y
);
}
},
...
...
@@ -111,12 +97,14 @@ onKeyUp : function (e) {
},
onMouseDisable
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
var
evt
,
pos
;
evt
=
e
.
event
||
window
.
event
;
pos
=
getPosition
(
$
(
Canvas
.
id
));
/* Stop propagation if inside canvas area */
if
((
evt
.
clientX
>=
Canvas
.
getX
()
)
&&
(
evt
.
clientY
>=
Canvas
.
getY
()
)
&&
(
evt
.
clientX
<
(
Canvas
.
getX
()
+
Canvas
.
c_wx
))
&&
(
evt
.
clientY
<
(
Canvas
.
getY
()
+
Canvas
.
c_wy
)))
{
if
((
evt
.
clientX
>=
pos
.
x
)
&&
(
evt
.
clientY
>=
pos
.
y
)
&&
(
evt
.
clientX
<
(
pos
.
x
+
Canvas
.
c_wx
))
&&
(
evt
.
clientY
<
(
pos
.
y
+
Canvas
.
c_wy
)))
{
e
.
stop
();
return
false
;
}
...
...
include/util.js
View file @
61dd52c9
...
...
@@ -28,6 +28,40 @@ function dirObj(obj, depth, parent) {
return
msg
;
}
/*
* Cross-browser positioning
*/
// Get DOM element position on page
function
getPosition
(
obj
)
{
var
x
=
0
,
y
=
0
;
if
(
obj
.
offsetParent
)
{
do
{
x
+=
obj
.
offsetLeft
;
y
+=
obj
.
offsetTop
;
}
while
(
obj
=
obj
.
offsetParent
);
}
return
{
'x'
:
x
,
'y'
:
y
};
}
// Get mouse event position in DOM element
function
getEventPosition
(
e
,
obj
)
{
var
evt
,
docX
,
docY
,
pos
;
//if (!e) evt = window.event;
evt
=
e
.
event
||
window
.
event
;
if
(
evt
.
pageX
||
evt
.
pageY
)
{
docX
=
evt
.
pageX
;
docY
=
evt
.
pageY
;
}
else
if
(
evt
.
clientX
||
evt
.
clientY
)
{
docX
=
evt
.
clientX
+
document
.
body
.
scrollLeft
+
document
.
documentElement
.
scrollLeft
;
docY
=
evt
.
clientY
+
document
.
body
.
scrollTop
+
document
.
documentElement
.
scrollTop
;
}
pos
=
getPosition
(
obj
);
return
{
'x'
:
docX
-
pos
.
x
,
'y'
:
docY
-
pos
.
y
};
}
/*
* Make arrays quack
...
...
tests/input.html
View file @
61dd52c9
...
...
@@ -25,7 +25,7 @@
<script>
var
msg_cnt
=
0
;
var
width
=
80
0
,
height
=
600
;
var
width
=
128
0
,
height
=
600
;
var
iterations
;
function
message
(
str
)
{
...
...
@@ -35,60 +35,27 @@
cell
.
scrollTop
=
cell
.
scrollHeight
;
}
function
mouseDown
(
e
)
{
var
msg
,
evt
=
e
.
event
||
window
.
event
;
e
.
stop
();
msg
=
'mouse '
+
evt
.
which
+
'/'
+
evt
.
button
+
' down:'
+
(
evt
.
clientX
-
Canvas
.
c_x
)
+
","
+
(
evt
.
clientY
-
Canvas
.
c_y
);
function
mouseButton
(
x
,
y
,
down
,
bmask
)
{
msg
=
'mouse x,y: '
+
x
+
','
+
y
+
' down: '
+
down
;
msg
+=
' bmask: '
+
bmask
;
console
.
log
(
msg
);
message
(
msg
);
}
function
mouseUp
(
e
)
{
var
msg
,
evt
=
e
.
event
||
window
.
event
;
e
.
stop
();
msg
=
'mouse '
+
evt
.
which
+
'/'
+
evt
.
button
+
' up:'
+
(
evt
.
clientX
-
Canvas
.
c_x
)
+
","
+
(
evt
.
clientY
-
Canvas
.
c_y
);
console
.
log
(
msg
);
message
(
msg
);
}
function
mouseMove
(
e
)
{
var
msg
,
evt
=
e
.
event
||
window
.
event
;
console
.
log
(
'mouse '
+
evt
.
which
+
'/'
+
evt
.
button
+
' up:'
+
(
evt
.
clientX
-
Canvas
.
c_x
)
+
","
+
(
evt
.
clientY
-
Canvas
.
c_y
));
}
function
mouseWheel
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
//e = e ? e : window.event;
var
wheelData
=
evt
.
detail
?
evt
.
detail
*
-
1
:
evt
.
wheelDelta
/
40
;
msg
=
'mouse scroll by '
+
wheelData
+
':'
+
(
evt
.
clientX
-
Canvas
.
c_x
)
+
","
+
(
evt
.
clientY
-
Canvas
.
c_y
);
console
.
log
(
msg
);
message
(
msg
);
}
function
keyDown
(
e
)
{
var
msg
;
e
.
stop
();
msg
=
"keydown: "
+
e
.
key
+
"("
+
e
.
code
+
")"
;
console
.
log
(
msg
);
message
(
msg
);
function
mouseMove
(
x
,
y
)
{
msg
=
'mouse x,y: '
+
x
+
','
+
y
;
//console.log(msg);
}
function
keyUp
(
e
)
{
var
msg
;
e
.
stop
();
msg
=
"keyup: "
+
e
.
key
+
"("
+
e
.
code
+
")"
;
function
keyPress
(
keysym
,
down
)
{
msg
=
"keyPress keysym: "
+
keysym
+
" down: "
+
down
;
console
.
log
(
msg
);
message
(
msg
);
}
window
.
onload
=
function
()
{
Canvas
.
init
(
'canvas'
,
width
,
height
,
keyDown
,
keyUp
,
mouse
Down
,
mouseUp
,
mouseMove
,
mouseWheel
);
Canvas
.
init
(
'canvas'
,
width
,
height
,
true
,
keyPress
,
mouse
Button
,
mouseMove
);
message
(
"Canvas initialized"
);
}
</script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment