@@ -397,88 +397,88 @@ void WebView::Touch(int type, int button, double x, double y, double dx,
397397 }
398398}
399399
400- static LWE::KeyValue KeyNameToKeyValue (const std::string& ecore_key ,
401- bool is_shift_pressed) {
402- if (ecore_key == " Left" ) {
400+ static LWE::KeyValue KeyToKeyValue (const std::string& key ,
401+ bool is_shift_pressed) {
402+ if (key == " Left" ) {
403403 return LWE::KeyValue::ArrowLeftKey;
404- } else if (ecore_key == " Right" ) {
404+ } else if (key == " Right" ) {
405405 return LWE::KeyValue::ArrowRightKey;
406- } else if (ecore_key == " Up" ) {
406+ } else if (key == " Up" ) {
407407 return LWE::KeyValue::ArrowUpKey;
408- } else if (ecore_key == " Down" ) {
408+ } else if (key == " Down" ) {
409409 return LWE::KeyValue::ArrowDownKey;
410- } else if (ecore_key == " space" ) {
410+ } else if (key == " space" ) {
411411 return LWE::KeyValue::SpaceKey;
412- } else if (ecore_key == " Select" ) {
412+ } else if (key == " Select" ) {
413413 return LWE::KeyValue::EnterKey;
414- } else if (ecore_key == " Return" ) {
414+ } else if (key == " Return" ) {
415415 return LWE::KeyValue::EnterKey;
416- } else if (ecore_key == " Tab" ) {
416+ } else if (key == " Tab" ) {
417417 return LWE::KeyValue::TabKey;
418- } else if (ecore_key == " BackSpace" ) {
418+ } else if (key == " BackSpace" ) {
419419 return LWE::KeyValue::BackspaceKey;
420- } else if (ecore_key == " Escape" ) {
420+ } else if (key == " Escape" ) {
421421 return LWE::KeyValue::EscapeKey;
422- } else if (ecore_key == " Delete" ) {
422+ } else if (key == " Delete" ) {
423423 return LWE::KeyValue::DeleteKey;
424- } else if (ecore_key == " at" ) {
424+ } else if (key == " at" ) {
425425 return LWE::KeyValue::AtMarkKey;
426- } else if (ecore_key == " minus" ) {
426+ } else if (key == " minus" ) {
427427 if (is_shift_pressed) {
428428 return LWE::KeyValue::UnderScoreMarkKey;
429429 } else {
430430 return LWE::KeyValue::MinusMarkKey;
431431 }
432- } else if (ecore_key == " equal" ) {
432+ } else if (key == " equal" ) {
433433 if (is_shift_pressed) {
434434 return LWE::KeyValue::PlusMarkKey;
435435 } else {
436436 return LWE::KeyValue::EqualitySignKey;
437437 }
438- } else if (ecore_key == " bracketleft" ) {
438+ } else if (key == " bracketleft" ) {
439439 if (is_shift_pressed) {
440440 return LWE::KeyValue::LeftCurlyBracketMarkKey;
441441 } else {
442442 return LWE::KeyValue::LeftSquareBracketKey;
443443 }
444- } else if (ecore_key == " bracketright" ) {
444+ } else if (key == " bracketright" ) {
445445 if (is_shift_pressed) {
446446 return LWE::KeyValue::RightCurlyBracketMarkKey;
447447 } else {
448448 return LWE::KeyValue::RightSquareBracketKey;
449449 }
450- } else if (ecore_key == " semicolon" ) {
450+ } else if (key == " semicolon" ) {
451451 if (is_shift_pressed) {
452452 return LWE::KeyValue::ColonMarkKey;
453453 } else {
454454 return LWE::KeyValue::SemiColonMarkKey;
455455 }
456- } else if (ecore_key == " apostrophe" ) {
456+ } else if (key == " apostrophe" ) {
457457 if (is_shift_pressed) {
458458 return LWE::KeyValue::DoubleQuoteMarkKey;
459459 } else {
460460 return LWE::KeyValue::SingleQuoteMarkKey;
461461 }
462- } else if (ecore_key == " comma" ) {
462+ } else if (key == " comma" ) {
463463 if (is_shift_pressed) {
464464 return LWE::KeyValue::LessThanMarkKey;
465465 } else {
466466 return LWE::KeyValue::CommaMarkKey;
467467 }
468- } else if (ecore_key == " period" ) {
468+ } else if (key == " period" ) {
469469 if (is_shift_pressed) {
470470 return LWE::KeyValue::GreaterThanSignKey;
471471 } else {
472472 return LWE::KeyValue::PeriodKey;
473473 }
474- } else if (ecore_key == " slash" ) {
474+ } else if (key == " slash" ) {
475475 if (is_shift_pressed) {
476476 return LWE::KeyValue::QuestionMarkKey;
477477 } else {
478478 return LWE::KeyValue::SlashKey;
479479 }
480- } else if (ecore_key .length () == 1 ) {
481- const char ch = ecore_key .at (0 );
480+ } else if (key .length () == 1 ) {
481+ const char ch = key .at (0 );
482482 if (ch >= ' 0' && ch <= ' 9' ) {
483483 if (is_shift_pressed) {
484484 switch (ch) {
@@ -518,125 +518,107 @@ static LWE::KeyValue KeyNameToKeyValue(const std::string& ecore_key,
518518 return LWE::KeyValue (LWE::KeyValue::AKey + ch - ' A' );
519519 }
520520 }
521- } else if (ecore_key == " XF86AudioRaiseVolume" ) {
521+ } else if (key == " XF86AudioRaiseVolume" ) {
522522 return LWE::KeyValue::TVVolumeUpKey;
523- } else if (ecore_key == " XF86AudioLowerVolume" ) {
523+ } else if (key == " XF86AudioLowerVolume" ) {
524524 return LWE::KeyValue::TVVolumeDownKey;
525- } else if (ecore_key == " XF86AudioMute" ) {
525+ } else if (key == " XF86AudioMute" ) {
526526 return LWE::KeyValue::TVMuteKey;
527- } else if (ecore_key == " XF86RaiseChannel" ) {
527+ } else if (key == " XF86RaiseChannel" ) {
528528 return LWE::KeyValue::TVChannelUpKey;
529- } else if (ecore_key == " XF86LowerChannel" ) {
529+ } else if (key == " XF86LowerChannel" ) {
530530 return LWE::KeyValue::TVChannelDownKey;
531- } else if (ecore_key == " XF86AudioRewind" ) {
531+ } else if (key == " XF86AudioRewind" ) {
532532 return LWE::KeyValue::MediaTrackPreviousKey;
533- } else if (ecore_key == " XF86AudioNext" ) {
533+ } else if (key == " XF86AudioNext" ) {
534534 return LWE::KeyValue::MediaTrackNextKey;
535- } else if (ecore_key == " XF86AudioPause" ) {
535+ } else if (key == " XF86AudioPause" ) {
536536 return LWE::KeyValue::MediaPauseKey;
537- } else if (ecore_key == " XF86AudioRecord" ) {
537+ } else if (key == " XF86AudioRecord" ) {
538538 return LWE::KeyValue::MediaRecordKey;
539- } else if (ecore_key == " XF86AudioPlay" ) {
539+ } else if (key == " XF86AudioPlay" ) {
540540 return LWE::KeyValue::MediaPlayKey;
541- } else if (ecore_key == " XF86AudioStop" ) {
541+ } else if (key == " XF86AudioStop" ) {
542542 return LWE::KeyValue::MediaStopKey;
543- } else if (ecore_key == " XF86Info" ) {
543+ } else if (key == " XF86Info" ) {
544544 return LWE::KeyValue::TVInfoKey;
545- } else if (ecore_key == " XF86Back" ) {
545+ } else if (key == " XF86Back" ) {
546546 return LWE::KeyValue::TVReturnKey;
547- } else if (ecore_key == " XF86Red" ) {
547+ } else if (key == " XF86Red" ) {
548548 return LWE::KeyValue::TVRedKey;
549- } else if (ecore_key == " XF86Green" ) {
549+ } else if (key == " XF86Green" ) {
550550 return LWE::KeyValue::TVGreenKey;
551- } else if (ecore_key == " XF86Yellow" ) {
551+ } else if (key == " XF86Yellow" ) {
552552 return LWE::KeyValue::TVYellowKey;
553- } else if (ecore_key == " XF86Blue" ) {
553+ } else if (key == " XF86Blue" ) {
554554 return LWE::KeyValue::TVBlueKey;
555- } else if (ecore_key == " XF86SysMenu" ) {
555+ } else if (key == " XF86SysMenu" ) {
556556 return LWE::KeyValue::TVMenuKey;
557- } else if (ecore_key == " XF86Home" ) {
557+ } else if (key == " XF86Home" ) {
558558 return LWE::KeyValue::TVHomeKey;
559- } else if (ecore_key == " XF86Exit" ) {
559+ } else if (key == " XF86Exit" ) {
560560 return LWE::KeyValue::TVExitKey;
561- } else if (ecore_key == " XF86PreviousChannel" ) {
561+ } else if (key == " XF86PreviousChannel" ) {
562562 return LWE::KeyValue::TVPreviousChannel;
563- } else if (ecore_key == " XF86ChannelList" ) {
563+ } else if (key == " XF86ChannelList" ) {
564564 return LWE::KeyValue::TVChannelList;
565- } else if (ecore_key == " XF86ChannelGuide" ) {
565+ } else if (key == " XF86ChannelGuide" ) {
566566 return LWE::KeyValue::TVChannelGuide;
567- } else if (ecore_key == " XF86SimpleMenu" ) {
567+ } else if (key == " XF86SimpleMenu" ) {
568568 return LWE::KeyValue::TVSimpleMenu;
569- } else if (ecore_key == " XF86EManual" ) {
569+ } else if (key == " XF86EManual" ) {
570570 return LWE::KeyValue::TVEManual;
571- } else if (ecore_key == " XF86ExtraApp" ) {
571+ } else if (key == " XF86ExtraApp" ) {
572572 return LWE::KeyValue::TVExtraApp;
573- } else if (ecore_key == " XF86Search" ) {
573+ } else if (key == " XF86Search" ) {
574574 return LWE::KeyValue::TVSearch;
575- } else if (ecore_key == " XF86PictureSize" ) {
575+ } else if (key == " XF86PictureSize" ) {
576576 return LWE::KeyValue::TVPictureSize;
577- } else if (ecore_key == " XF86Sleep" ) {
577+ } else if (key == " XF86Sleep" ) {
578578 return LWE::KeyValue::TVSleep;
579- } else if (ecore_key == " XF86Caption" ) {
579+ } else if (key == " XF86Caption" ) {
580580 return LWE::KeyValue::TVCaption;
581- } else if (ecore_key == " XF86More" ) {
581+ } else if (key == " XF86More" ) {
582582 return LWE::KeyValue::TVMore;
583- } else if (ecore_key == " XF86BTVoice" ) {
583+ } else if (key == " XF86BTVoice" ) {
584584 return LWE::KeyValue::TVBTVoice;
585- } else if (ecore_key == " XF86Color" ) {
585+ } else if (key == " XF86Color" ) {
586586 return LWE::KeyValue::TVColor;
587- } else if (ecore_key == " XF86PlayBack" ) {
587+ } else if (key == " XF86PlayBack" ) {
588588 return LWE::KeyValue::TVPlayBack;
589589 }
590- LOG_WARN (" Unknown key name: %s" , ecore_key .c_str ());
590+ LOG_WARN (" Unknown key name: %s" , key .c_str ());
591591 return LWE::KeyValue::UnidentifiedKey;
592592}
593593
594- void WebView::DispatchKeyDownEvent (Ecore_Event_Key* key_event) {
594+ void WebView::SendKey (const char * key, const char * string, const char * compose,
595+ uint32_t modifiers, uint32_t scan_code, bool is_down) {
595596 if (!IsFocused ()) {
596597 return ;
597598 }
598599
599- std::string key_name = key_event->keyname ;
600- bool is_shift_pressed = key_event->modifiers & 1 ;
600+ bool is_shift_pressed = modifiers & 1 ;
601601
602602 struct Param {
603603 LWE::WebContainer* webview_instance;
604604 LWE::KeyValue key_value;
605+ bool is_down;
605606 };
606- Param* param = new Param ();
607- param->webview_instance = webview_instance_;
608- param->key_value = KeyNameToKeyValue (key_name, is_shift_pressed);
609-
610- webview_instance_->AddIdleCallback (
611- [](void * data) {
612- Param* param = reinterpret_cast <Param*>(data);
613- param->webview_instance ->DispatchKeyDownEvent (param->key_value );
614- param->webview_instance ->DispatchKeyPressEvent (param->key_value );
615- delete param;
616- },
617- param);
618- }
619607
620- void WebView::DispatchKeyUpEvent (Ecore_Event_Key* key_event) {
621- if (!IsFocused ()) {
622- return ;
623- }
624-
625- std::string key_name = key_event->keyname ;
626- bool is_shift_pressed = key_event->modifiers & 1 ;
627-
628- struct Param {
629- LWE::WebContainer* webview_instance;
630- LWE::KeyValue key_value;
631- };
632608 Param* param = new Param ();
633609 param->webview_instance = webview_instance_;
634- param->key_value = KeyNameToKeyValue (key_name, is_shift_pressed);
610+ param->key_value = KeyToKeyValue (key, is_shift_pressed);
611+ param->is_down = is_down;
635612
636613 webview_instance_->AddIdleCallback (
637614 [](void * data) {
638615 Param* param = reinterpret_cast <Param*>(data);
639- param->webview_instance ->DispatchKeyUpEvent (param->key_value );
616+ if (param->is_down ) {
617+ param->webview_instance ->DispatchKeyDownEvent (param->key_value );
618+ param->webview_instance ->DispatchKeyPressEvent (param->key_value );
619+ } else {
620+ param->webview_instance ->DispatchKeyUpEvent (param->key_value );
621+ }
640622 delete param;
641623 },
642624 param);
0 commit comments