ui: Rename functions from Safari to Edge

This commit is contained in:
Hajime Hoshi 2017-11-10 00:35:46 +09:00
parent 0c0cd7e9d6
commit 37ca48dc38
4 changed files with 29 additions and 30 deletions

View File

@ -32,8 +32,8 @@ import (
) )
var ( var (
nameToCodes map[string][]string nameToCodes map[string][]string
keyCodeToNameSafari map[int]string keyCodeToNameEdge map[int]string
) )
func init() { func init() {
@ -84,7 +84,7 @@ func init() {
} }
func init() { func init() {
keyCodeToNameSafari = map[int]string{ keyCodeToNameEdge = map[int]string{
0xbc: "Comma", 0xbc: "Comma",
0xbe: "Period", 0xbe: "Period",
0x12: "Alt", 0x12: "Alt",
@ -118,15 +118,15 @@ func init() {
} }
// ASCII: 0 - 9 // ASCII: 0 - 9
for c := '0'; c <= '9'; c++ { for c := '0'; c <= '9'; c++ {
keyCodeToNameSafari[int(c)] = string(c) keyCodeToNameEdge[int(c)] = string(c)
} }
// ASCII: A - Z // ASCII: A - Z
for c := 'A'; c <= 'Z'; c++ { for c := 'A'; c <= 'Z'; c++ {
keyCodeToNameSafari[int(c)] = string(c) keyCodeToNameEdge[int(c)] = string(c)
} }
// Function keys // Function keys
for i := 1; i <= 12; i++ { for i := 1; i <= 12; i++ {
keyCodeToNameSafari[0x70+i-1] = "F" + strconv.Itoa(i) keyCodeToNameEdge[0x70+i-1] = "F" + strconv.Itoa(i)
} }
} }
@ -205,8 +205,8 @@ var keyToCodes = map[Key][]string{
{{end}} {{end}}
} }
var keyCodeToKeySafari = map[int]Key{ var keyCodeToKeyEdge = map[int]Key{
{{range $code, $name := .KeyCodeToNameSafari}}{{$code}}: Key{{$name}}, {{range $code, $name := .KeyCodeToNameEdge}}{{$code}}: Key{{$name}},
{{end}} {{end}}
} }
` `
@ -353,7 +353,7 @@ func main() {
"Notice": notice, "Notice": notice,
"BuildTag": buildTag, "BuildTag": buildTag,
"NameToCodes": nameToCodes, "NameToCodes": nameToCodes,
"KeyCodeToNameSafari": keyCodeToNameSafari, "KeyCodeToNameEdge": keyCodeToNameEdge,
"Codes": codes, "Codes": codes,
"KeyNames": names, "KeyNames": names,
"LastKeyName": names[len(names)-1], "LastKeyName": names[len(names)-1],

View File

@ -29,7 +29,7 @@ func (m mockRWLock) RUnlock() {}
type Input struct { type Input struct {
keyPressed map[string]bool keyPressed map[string]bool
keyPressedSafari map[int]bool keyPressedEdge map[int]bool
mouseButtonPressed map[int]bool mouseButtonPressed map[int]bool
cursorX int cursorX int
cursorY int cursorY int
@ -51,12 +51,12 @@ func (i *Input) IsKeyPressed(key Key) bool {
} }
} }
} }
if i.keyPressedSafari != nil { if i.keyPressedEdge != nil {
for c, k := range keyCodeToKeySafari { for c, k := range keyCodeToKeyEdge {
if k != key { if k != key {
continue continue
} }
if i.keyPressedSafari[c] { if i.keyPressedEdge[c] {
return true return true
} }
} }
@ -99,18 +99,18 @@ func (i *Input) keyUp(code string) {
i.keyPressed[code] = false i.keyPressed[code] = false
} }
func (i *Input) keyDownSafari(code int) { func (i *Input) keyDownEdge(code int) {
if i.keyPressedSafari == nil { if i.keyPressedEdge == nil {
i.keyPressedSafari = map[int]bool{} i.keyPressedEdge = map[int]bool{}
} }
i.keyPressedSafari[code] = true i.keyPressedEdge[code] = true
} }
func (i *Input) keyUpSafari(code int) { func (i *Input) keyUpEdge(code int) {
if i.keyPressedSafari == nil { if i.keyPressedEdge == nil {
i.keyPressedSafari = map[int]bool{} i.keyPressedEdge = map[int]bool{}
} }
i.keyPressedSafari[code] = false i.keyPressedEdge[code] = false
} }
func (i *Input) mouseDown(code int) { func (i *Input) mouseDown(code int) {

View File

@ -255,7 +255,7 @@ var keyToCodes = map[Key][]string{
}, },
} }
var keyCodeToKeySafari = map[int]Key{ var keyCodeToKeyEdge = map[int]Key{
8: KeyBackspace, 8: KeyBackspace,
9: KeyTab, 9: KeyTab,
13: KeyEnter, 13: KeyEnter,

View File

@ -246,13 +246,12 @@ func initialize() error {
canvas.Call("addEventListener", "keydown", func(e *js.Object) { canvas.Call("addEventListener", "keydown", func(e *js.Object) {
c := e.Get("code") c := e.Get("code")
if c == js.Undefined { if c == js.Undefined {
// TODO: Now this is used for Edge, not Safari. Rename functions.
code := e.Get("keyCode").Int() code := e.Get("keyCode").Int()
if keyCodeToKeySafari[code] == KeyUp || if keyCodeToKeyEdge[code] == KeyUp ||
keyCodeToKeySafari[code] == KeyDown || keyCodeToKeyEdge[code] == KeyDown ||
keyCodeToKeySafari[code] == KeyLeft || keyCodeToKeyEdge[code] == KeyLeft ||
keyCodeToKeySafari[code] == KeyRight { keyCodeToKeyEdge[code] == KeyRight {
currentInput.keyDownSafari(code) currentInput.keyDownEdge(code)
} }
return return
} }
@ -274,9 +273,9 @@ func initialize() error {
canvas.Call("addEventListener", "keyup", func(e *js.Object) { canvas.Call("addEventListener", "keyup", func(e *js.Object) {
e.Call("preventDefault") e.Call("preventDefault")
if e.Get("code") == js.Undefined { if e.Get("code") == js.Undefined {
// Assume that UA is Safari. // Assume that UA is Edge.
code := e.Get("keyCode").Int() code := e.Get("keyCode").Int()
currentInput.keyUpSafari(code) currentInput.keyUpEdge(code)
} }
code := e.Get("code").String() code := e.Get("code").String()
currentInput.keyUp(code) currentInput.keyUp(code)