Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: third_party/WebKit/Source/web/WebInputEventConversion.cpp

Issue 2290313002: Remove PlatformKeyboardEvent (Closed)
Patch Set: One more fix Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 case WebGestureDeviceTouchscreen: 338 case WebGestureDeviceTouchscreen:
339 m_source = PlatformGestureSourceTouchscreen; 339 m_source = PlatformGestureSourceTouchscreen;
340 break; 340 break;
341 case WebGestureDeviceUninitialized: 341 case WebGestureDeviceUninitialized:
342 NOTREACHED(); 342 NOTREACHED();
343 } 343 }
344 344
345 m_uniqueTouchEventId = e.uniqueTouchEventId; 345 m_uniqueTouchEventId = e.uniqueTouchEventId;
346 } 346 }
347 347
348 // MakePlatformKeyboardEvent --------------------------------------------------
349
350 inline PlatformEvent::EventType toPlatformKeyboardEventType(WebInputEvent::Type type)
351 {
352 switch (type) {
353 case WebInputEvent::KeyUp:
354 return PlatformEvent::KeyUp;
355 case WebInputEvent::KeyDown:
356 return PlatformEvent::KeyDown;
357 case WebInputEvent::RawKeyDown:
358 return PlatformEvent::RawKeyDown;
359 case WebInputEvent::Char:
360 return PlatformEvent::Char;
361 default:
362 NOTREACHED();
363 }
364 return PlatformEvent::KeyDown;
365 }
366
367 PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(const WebKeyboardEven t& e)
368 {
369 m_type = toPlatformKeyboardEventType(e.type);
370 m_text = String(e.text);
371 m_unmodifiedText = String(e.unmodifiedText);
372 m_nativeVirtualKeyCode = e.nativeKeyCode;
373 m_isSystemKey = e.isSystemKey;
374 // TODO: BUG482880 Fix this initialization to lazy initialization.
375 m_code = Platform::current()->domCodeStringFromEnum(e.domCode);
376 m_key = Platform::current()->domKeyStringFromEnum(e.domKey);
377
378 m_modifiers = e.modifiers;
379 m_timestamp = e.timeStampSeconds;
380 m_windowsVirtualKeyCode = e.windowsKeyCode;
381 }
382
383 void PlatformKeyboardEventBuilder::setKeyType(EventType type)
384 {
385 // According to the behavior of Webkit in Windows platform,
386 // we need to convert KeyDown to RawKeydown and Char events
387 // See WebKit/WebKit/Win/WebView.cpp
388 DCHECK(m_type == KeyDown);
389 DCHECK(type == RawKeyDown || type == Char);
390 m_type = type;
391
392 if (type == RawKeyDown) {
393 m_text = String();
394 m_unmodifiedText = String();
395 } else {
396 m_windowsVirtualKeyCode = 0;
397 }
398 }
399
400 // Please refer to bug http://b/issue?id=961192, which talks about Webkit
401 // keyboard event handling changes. It also mentions the list of keys
402 // which don't have associated character events.
403 bool PlatformKeyboardEventBuilder::isCharacterKey() const
404 {
405 switch (windowsVirtualKeyCode()) {
406 case VKEY_BACK:
407 case VKEY_ESCAPE:
408 return false;
409 }
410 return true;
411 }
412
413 inline PlatformEvent::EventType toPlatformTouchEventType(const WebInputEvent::Ty pe type) 348 inline PlatformEvent::EventType toPlatformTouchEventType(const WebInputEvent::Ty pe type)
414 { 349 {
415 switch (type) { 350 switch (type) {
416 case WebInputEvent::TouchStart: 351 case WebInputEvent::TouchStart:
417 return PlatformEvent::TouchStart; 352 return PlatformEvent::TouchStart;
418 case WebInputEvent::TouchMove: 353 case WebInputEvent::TouchMove:
419 return PlatformEvent::TouchMove; 354 return PlatformEvent::TouchMove;
420 case WebInputEvent::TouchEnd: 355 case WebInputEvent::TouchEnd:
421 return PlatformEvent::TouchEnd; 356 return PlatformEvent::TouchEnd;
422 case WebInputEvent::TouchCancel: 357 case WebInputEvent::TouchCancel:
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 hasPreciseScrollingDeltas = event.hasPreciseScrollingDeltas(); 576 hasPreciseScrollingDeltas = event.hasPreciseScrollingDeltas();
642 dispatchType = event.cancelable() ? WebInputEvent::Blocking : WebInputEvent: :EventNonBlocking; 577 dispatchType = event.cancelable() ? WebInputEvent::Blocking : WebInputEvent: :EventNonBlocking;
643 #if OS(MACOSX) 578 #if OS(MACOSX)
644 phase = static_cast<Phase>(event.phase()); 579 phase = static_cast<Phase>(event.phase());
645 momentumPhase = static_cast<Phase>(event.momentumPhase()); 580 momentumPhase = static_cast<Phase>(event.momentumPhase());
646 #endif 581 #endif
647 } 582 }
648 583
649 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) 584 WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event)
650 { 585 {
586 if (const WebKeyboardEvent* webEvent = event.keyEvent()) {
587 *static_cast<WebKeyboardEvent*>(this) = *webEvent;
588
589 // TODO(dtapuska): DOM KeyboardEvents converted back to WebInputEvents
590 // drop the Raw behaviour. Figure out if this is actually really needed.
591 if (type == RawKeyDown)
592 type = KeyDown;
593 return;
594 }
595
651 if (event.type() == EventTypeNames::keydown) 596 if (event.type() == EventTypeNames::keydown)
652 type = KeyDown; 597 type = KeyDown;
653 else if (event.type() == EventTypeNames::keyup) 598 else if (event.type() == EventTypeNames::keyup)
654 type = WebInputEvent::KeyUp; 599 type = WebInputEvent::KeyUp;
655 else if (event.type() == EventTypeNames::keypress) 600 else if (event.type() == EventTypeNames::keypress)
656 type = WebInputEvent::Char; 601 type = WebInputEvent::Char;
657 else 602 else
658 return; // Skip all other keyboard events. 603 return; // Skip all other keyboard events.
659 604
660 modifiers = event.modifiers(); 605 modifiers = event.modifiers();
661
662 timeStampSeconds = event.platformTimeStamp(); 606 timeStampSeconds = event.platformTimeStamp();
663 windowsKeyCode = event.keyCode(); 607 windowsKeyCode = event.keyCode();
664
665 // The platform keyevent does not exist if the event was created using
666 // initKeyboardEvent.
667 if (!event.keyEvent())
668 return;
669 nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode();
670 domCode = Platform::current()->domEnumFromCodeString(event.keyEvent()->code( ));
671 domKey = Platform::current()->domKeyEnumFromString(event.keyEvent()->key());
672 unsigned numberOfCharacters = std::min(event.keyEvent()->text().length(), st atic_cast<unsigned>(textLengthCap));
673 for (unsigned i = 0; i < numberOfCharacters; ++i) {
674 text[i] = event.keyEvent()->text()[i];
675 unmodifiedText[i] = event.keyEvent()->unmodifiedText()[i];
676 }
677 }
678
679 WebInputEvent::Type toWebKeyboardEventType(PlatformEvent::EventType type)
680 {
681 switch (type) {
682 case PlatformEvent::KeyUp:
683 return WebInputEvent::KeyUp;
684 case PlatformEvent::KeyDown:
685 return WebInputEvent::KeyDown;
686 case PlatformEvent::RawKeyDown:
687 return WebInputEvent::RawKeyDown;
688 case PlatformEvent::Char:
689 return WebInputEvent::Char;
690 default:
691 return WebInputEvent::Undefined;
692 }
693 } 608 }
694 609
695 static WebTouchPoint toWebTouchPoint(const Touch* touch, const LayoutItem layout Item, WebTouchPoint::State state) 610 static WebTouchPoint toWebTouchPoint(const Touch* touch, const LayoutItem layout Item, WebTouchPoint::State state)
696 { 611 {
697 WebTouchPoint point; 612 WebTouchPoint point;
698 point.pointerType = WebPointerProperties::PointerType::Touch; 613 point.pointerType = WebPointerProperties::PointerType::Touch;
699 point.id = touch->identifier(); 614 point.id = touch->identifier();
700 point.screenPosition = touch->screenLocation(); 615 point.screenPosition = touch->screenLocation();
701 point.position = convertAbsoluteLocationForLayoutObjectFloat(touch->absolute Location(), layoutItem); 616 point.position = convertAbsoluteLocationForLayoutObjectFloat(touch->absolute Location(), layoutItem);
702 point.radiusX = touch->radiusX(); 617 point.radiusX = touch->radiusX();
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 break; 734 break;
820 case GestureSourceTouchscreen: 735 case GestureSourceTouchscreen:
821 sourceDevice = WebGestureDeviceTouchscreen; 736 sourceDevice = WebGestureDeviceTouchscreen;
822 break; 737 break;
823 case GestureSourceUninitialized: 738 case GestureSourceUninitialized:
824 NOTREACHED(); 739 NOTREACHED();
825 } 740 }
826 } 741 }
827 742
828 } // namespace blink 743 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698