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
Show 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:
Medium Term:
- Remove mootools dependency from vnc.js and canvas.js.
- canvas.js deps:
$(), getPosition, getScroll
- Implement Cursor pseudo-encoding (CSS cursor)
- Implement Cursor pseudo-encoding (CSS cursor)
http://en.wikipedia.org/wiki/ICO_(file_format)
http://en.wikipedia.org/wiki/ICO_(file_format)
https://developer.mozilla.org/en/Using_URL_values_for_the_cursor_property
https://developer.mozilla.org/en/Using_URL_values_for_the_cursor_property
...
...
include/canvas.js
View file @
61dd52c9
...
@@ -27,26 +27,14 @@ keyPress : null,
...
@@ -27,26 +27,14 @@ keyPress : null,
mouseButton
:
null
,
mouseButton
:
null
,
mouseMove
:
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
)
{
onMouseButton
:
function
(
e
,
down
)
{
var
evt
,
x
,
y
,
bmask
;
var
evt
,
pos
,
bmask
;
evt
=
e
.
event
||
window
.
event
;
evt
=
e
.
event
||
window
.
event
;
x
=
(
evt
.
clientX
-
Canvas
.
getX
());
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
y
=
(
evt
.
clientY
-
Canvas
.
getY
());
bmask
=
1
<<
evt
.
button
;
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
)
{
if
(
Canvas
.
mouseButton
)
{
Canvas
.
mouseButton
(
x
,
y
,
down
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
down
,
bmask
);
}
}
e
.
stop
();
e
.
stop
();
return
false
;
return
false
;
...
@@ -61,21 +49,19 @@ onMouseUp: function (e) {
...
@@ -61,21 +49,19 @@ onMouseUp: function (e) {
},
},
onMouseWheel
:
function
(
e
)
{
onMouseWheel
:
function
(
e
)
{
var
evt
,
x
,
y
,
bmask
;
var
evt
,
pos
,
bmask
;
evt
=
e
.
event
||
window
.
event
;
evt
=
e
.
event
||
window
.
event
;
//e = e ? e : window.event;
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
x
=
(
evt
.
clientX
-
Canvas
.
getX
());
y
=
(
evt
.
clientY
-
Canvas
.
getY
());
var
wheelData
=
evt
.
detail
?
evt
.
detail
*
-
1
:
evt
.
wheelDelta
/
40
;
var
wheelData
=
evt
.
detail
?
evt
.
detail
*
-
1
:
evt
.
wheelDelta
/
40
;
if
(
wheelData
>
0
)
{
if
(
wheelData
>
0
)
{
bmask
=
1
<<
3
;
bmask
=
1
<<
3
;
}
else
{
}
else
{
bmask
=
1
<<
4
;
bmask
=
1
<<
4
;
}
}
//console.log('mouse scroll by ' + wheelData + ':' +
x + "," +
y);
//console.log('mouse scroll by ' + wheelData + ':' +
pos.x + "," + pos.
y);
if
(
Canvas
.
mouseButton
)
{
if
(
Canvas
.
mouseButton
)
{
Canvas
.
mouseButton
(
x
,
y
,
1
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
1
,
bmask
);
Canvas
.
mouseButton
(
x
,
y
,
0
,
bmask
);
Canvas
.
mouseButton
(
pos
.
x
,
pos
.
y
,
0
,
bmask
);
}
}
e
.
stop
();
e
.
stop
();
return
false
;
return
false
;
...
@@ -83,12 +69,12 @@ onMouseWheel: function (e) {
...
@@ -83,12 +69,12 @@ onMouseWheel: function (e) {
onMouseMove
:
function
(
e
)
{
onMouseMove
:
function
(
e
)
{
var
evt
=
e
.
event
||
window
.
event
;
var
evt
,
pos
;
x
=
(
evt
.
clientX
-
Canvas
.
getX
())
;
evt
=
e
.
event
||
window
.
event
;
y
=
(
evt
.
clientY
-
Canvas
.
getY
(
));
pos
=
getEventPosition
(
e
,
$
(
Canvas
.
id
));
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
x + "," +
y);
//console.log('mouse ' + evt.which + '/' + evt.button + ' up:' +
pos.x + "," + pos.
y);
if
(
Canvas
.
keyPress
)
{
if
(
Canvas
.
mouseMove
)
{
Canvas
.
mouseMove
(
x
,
y
);
Canvas
.
mouseMove
(
pos
.
x
,
pos
.
y
);
}
}
},
},
...
@@ -111,12 +97,14 @@ onKeyUp : function (e) {
...
@@ -111,12 +97,14 @@ onKeyUp : function (e) {
},
},
onMouseDisable
:
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 */
/* Stop propagation if inside canvas area */
if
((
evt
.
clientX
>=
Canvas
.
getX
()
)
&&
if
((
evt
.
clientX
>=
pos
.
x
)
&&
(
evt
.
clientY
>=
Canvas
.
getY
()
)
&&
(
evt
.
clientY
>=
pos
.
y
)
&&
(
evt
.
clientX
<
(
Canvas
.
getX
()
+
Canvas
.
c_wx
))
&&
(
evt
.
clientX
<
(
pos
.
x
+
Canvas
.
c_wx
))
&&
(
evt
.
clientY
<
(
Canvas
.
getY
()
+
Canvas
.
c_wy
)))
{
(
evt
.
clientY
<
(
pos
.
y
+
Canvas
.
c_wy
)))
{
e
.
stop
();
e
.
stop
();
return
false
;
return
false
;
}
}
...
...
include/util.js
View file @
61dd52c9
...
@@ -28,6 +28,40 @@ function dirObj(obj, depth, parent) {
...
@@ -28,6 +28,40 @@ function dirObj(obj, depth, parent) {
return
msg
;
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
* Make arrays quack
...
...
tests/input.html
View file @
61dd52c9
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
<script>
<script>
var
msg_cnt
=
0
;
var
msg_cnt
=
0
;
var
width
=
80
0
,
height
=
600
;
var
width
=
128
0
,
height
=
600
;
var
iterations
;
var
iterations
;
function
message
(
str
)
{
function
message
(
str
)
{
...
@@ -35,60 +35,27 @@
...
@@ -35,60 +35,27 @@
cell
.
scrollTop
=
cell
.
scrollHeight
;
cell
.
scrollTop
=
cell
.
scrollHeight
;
}
}
function
mouseDown
(
e
)
{
function
mouseButton
(
x
,
y
,
down
,
bmask
)
{
var
msg
,
evt
=
e
.
event
||
window
.
event
;
msg
=
'mouse x,y: '
+
x
+
','
+
y
+
' down: '
+
down
;
e
.
stop
();
msg
+=
' bmask: '
+
bmask
;
msg
=
'mouse '
+
evt
.
which
+
'/'
+
evt
.
button
+
' down:'
+
(
evt
.
clientX
-
Canvas
.
c_x
)
+
","
+
(
evt
.
clientY
-
Canvas
.
c_y
);
console
.
log
(
msg
);
console
.
log
(
msg
);
message
(
msg
);
message
(
msg
);
}
}
function
mouseUp
(
e
)
{
function
mouseMove
(
x
,
y
)
{
var
msg
,
evt
=
e
.
event
||
window
.
event
;
msg
=
'mouse x,y: '
+
x
+
','
+
y
;
e
.
stop
();
//console.log(msg);
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
keyUp
(
e
)
{
function
keyPress
(
keysym
,
down
)
{
var
msg
;
msg
=
"keyPress keysym: "
+
keysym
+
" down: "
+
down
;
e
.
stop
();
msg
=
"keyup: "
+
e
.
key
+
"("
+
e
.
code
+
")"
;
console
.
log
(
msg
);
console
.
log
(
msg
);
message
(
msg
);
message
(
msg
);
}
}
window
.
onload
=
function
()
{
window
.
onload
=
function
()
{
Canvas
.
init
(
'canvas'
,
width
,
height
,
keyDown
,
keyUp
,
Canvas
.
init
(
'canvas'
,
width
,
height
,
true
,
keyPress
,
mouse
Down
,
mouseUp
,
mouseMove
,
mouseWheel
);
mouse
Button
,
mouseMove
);
message
(
"Canvas initialized"
);
message
(
"Canvas initialized"
);
}
}
</script>
</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