FileDocCategorySizeDatePackage
WebViewEventSender.javaAPI DocAndroid 1.5 API5570Wed May 06 22:42:02 BST 2009com.android.dumprendertree

WebViewEventSender

public class WebViewEventSender extends Object implements EventSender

Fields Summary
private android.webkit.WebView
mWebView
private int
mouseX
private int
mouseY
Constructors Summary
WebViewEventSender(android.webkit.WebView webView)

		mWebView = webView;
	
Methods Summary
public voidenableDOMUIEventLogging(int DOMNode)

		// TODO Auto-generated method stub

	
public voidfireKeyboardEventsToElement(int DOMNode)

		// TODO Auto-generated method stub

	
public voidkeyDown(java.lang.String character, java.lang.String[] withModifiers)

        Log.e("EventSender", "KeyDown: " + character + "("
                + character.getBytes()[0] + ") Modifiers: "
                + Arrays.toString(withModifiers));
        KeyEvent modifier = null;
        if (withModifiers != null && withModifiers.length > 0) {
            for (int i = 0; i < withModifiers.length; i++) {
                int keyCode = modifierMapper(withModifiers[i]);
                modifier = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
                mWebView.onKeyDown(modifier.getKeyCode(), modifier);
            }
        }
        int keyCode = keyMapper(character.toLowerCase().toCharArray()[0]);
        KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
        mWebView.onKeyDown(event.getKeyCode(), event);

    
public voidkeyDown(java.lang.String character)

        keyDown(character, null);
	
static intkeyMapper(char c)

		// handle numbers
		if (c >= '0" && c<= '9") {
			int offset = c - '0";
			return KeyEvent.KEYCODE_0 + offset;
		}

		// handle characters
		if (c >= 'a" && c <= 'z") {
			int offset = c - 'a";
			return KeyEvent.KEYCODE_A + offset;
		}

		// handle all others
		switch (c) {
		case '*":
			return KeyEvent.KEYCODE_STAR;
		case '#":
			return KeyEvent.KEYCODE_POUND;
		case ',":
			return KeyEvent.KEYCODE_COMMA;
		case '.":
			return KeyEvent.KEYCODE_PERIOD;
		case '\t":
			return KeyEvent.KEYCODE_TAB;
		case ' ":
			return KeyEvent.KEYCODE_SPACE;
		case '\n":
			return KeyEvent.KEYCODE_ENTER;
		case '\b":
        case 0x7F:
			return KeyEvent.KEYCODE_DEL;
		case '~":
			return KeyEvent.KEYCODE_GRAVE;
		case '-":
			return KeyEvent.KEYCODE_MINUS;
		case '=":
			return KeyEvent.KEYCODE_EQUALS;
		case '(":
			return KeyEvent.KEYCODE_LEFT_BRACKET;
		case ')":
			return KeyEvent.KEYCODE_RIGHT_BRACKET;
		case '\\":
			return KeyEvent.KEYCODE_BACKSLASH;
		case ';":
			return KeyEvent.KEYCODE_SEMICOLON;
		case '\'":
			return KeyEvent.KEYCODE_APOSTROPHE;
		case '/":
			return KeyEvent.KEYCODE_SLASH;
		default:
			break;
		}

		return c;
	
public voidleapForward(int milliseconds)

		// TODO Auto-generated method stub

	
static intmodifierMapper(java.lang.String modifier)

		if (modifier.equals("ctrlKey")) {
			return KeyEvent.KEYCODE_ALT_LEFT;
		} else if (modifier.equals("shiftKey")) {
			return KeyEvent.KEYCODE_SHIFT_LEFT;
		} else if (modifier.equals("altKey")) {
			return KeyEvent.KEYCODE_SYM;
		} else if (modifier.equals("metaKey")) {
			return KeyEvent.KEYCODE_UNKNOWN;
		}
		return KeyEvent.KEYCODE_UNKNOWN;
	
public voidmouseClick()

		mouseDown();
		mouseUp();
	
public voidmouseDown()

          /*  KeyEvent event = new KeyEvent(
                KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER);
            mWebView.onKeyDown(event.getKeyCode(), event); */
	
public voidmouseMoveTo(int X, int Y)

		if (X > mouseX) {
                    KeyEvent event = new KeyEvent(
                        KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT);
                    mWebView.onKeyDown(event.getKeyCode(), event);
                    mWebView.onKeyUp(event.getKeyCode(), event);
		} else if ( X < mouseX ) {
                    KeyEvent event = new KeyEvent(
                        KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT);
                    mWebView.onKeyDown(event.getKeyCode(), event);
                    mWebView.onKeyUp(event.getKeyCode(), event);
		}
		if (Y > mouseY) {
                    KeyEvent event = new KeyEvent(
                        KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN);
                    mWebView.onKeyDown(event.getKeyCode(), event);
                    mWebView.onKeyUp(event.getKeyCode(), event);
		} else if (Y < mouseY ) {
                    KeyEvent event = new KeyEvent(
                        KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP);
                    mWebView.onKeyDown(event.getKeyCode(), event);
                    mWebView.onKeyUp(event.getKeyCode(), event);
		}
		mouseX= X;
		mouseY= Y;
	
	
public voidmouseUp()

        /*    KeyEvent event = new KeyEvent(
                KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER);
            mWebView.onKeyDown(event.getKeyCode(), event);*/

	
public voidresetMouse()

		mouseX = mouseY = 0;