Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Format component of webdriver_sever
  • Loading branch information
chansuke committed Sep 4, 2018
1 parent 73459d5 commit 511dfe8
Show file tree
Hide file tree
Showing 2 changed files with 466 additions and 225 deletions.
8 changes: 4 additions & 4 deletions components/webdriver_server/keys.rs
Expand Up @@ -4,7 +4,6 @@

use msg::constellation_msg::{Key, KeyState, KeyModifiers};


/// Takes a character and returns an Option containing a tuple of the
/// corresponding keycode and whether shift is required. This is
/// currently pretty much ascii-only and the webdriver spec isn't
Expand Down Expand Up @@ -164,22 +163,23 @@ fn key_from_char(key_string: &char) -> Option<(Key, bool)> {
'\u{E03C}' => Some((Key::F12, false)),
'\u{E03D}' => None,
'\u{E040}' => None,
_ => None
_ => None,
}
}

pub fn keycodes_to_keys(key_codes: &str) -> Result<Vec<(Key, KeyModifiers, KeyState)>, String> {
let mut rv = vec![];

for char_code in key_codes.chars() {
let (key, with_shift) = key_from_char(&char_code).ok_or(format!("Unsupported character code {}", char_code))?;
let (key, with_shift) =
key_from_char(&char_code).ok_or(format!("Unsupported character code {}", char_code))?;
let modifiers = if with_shift {
KeyModifiers::SHIFT
} else {
KeyModifiers::empty()
};
rv.push((key, modifiers, KeyState::Pressed));
rv.push((key, modifiers, KeyState::Released));
};
}
Ok(rv)
}

0 comments on commit 511dfe8

Please sign in to comment.