1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "config.h"
  27 
  28 #include <wtf/java/JavaEnv.h>
  29 #include "KeyboardEvent.h"
  30 #include "PlatformKeyboardEvent.h"
  31 #include "NotImplemented.h"
  32 
  33 #include <wtf/Assertions.h>
  34 
  35 #include "com_sun_webkit_event_WCKeyEvent.h"
  36 
  37 namespace WebCore {
  38 
  39 static PlatformKeyboardEvent::Type toPlatformKeyboardEventType(jint type)
  40 {
  41     switch (type) {
  42         case com_sun_webkit_event_WCKeyEvent_KEY_PRESSED:
  43             return PlatformKeyboardEvent::RawKeyDown;
  44         case com_sun_webkit_event_WCKeyEvent_KEY_TYPED:
  45             return PlatformKeyboardEvent::Char;
  46         case com_sun_webkit_event_WCKeyEvent_KEY_RELEASED:
  47             return PlatformKeyboardEvent::KeyUp;
  48         default:
  49             ASSERT_NOT_REACHED();
  50             return PlatformKeyboardEvent::RawKeyDown;
  51     }
  52 }
  53 
  54 PlatformKeyboardEvent::PlatformKeyboardEvent(
  55     jint type,
  56     jstring text,
  57     jstring keyIdentifier,
  58     jint windowsVirtualKeyCode,
  59     jboolean shiftKey,
  60     jboolean ctrlKey,
  61     jboolean altKey,
  62     jboolean metaKey,
  63     jdouble timestamp)
  64         : PlatformEvent(
  65             toPlatformKeyboardEventType(type),
  66             shiftKey,
  67             ctrlKey,
  68             altKey,
  69             metaKey,
  70             WallTime::fromRawSeconds(timestamp))
  71         , m_windowsVirtualKeyCode(windowsVirtualKeyCode)
  72         , m_autoRepeat(false)
  73         , m_isKeypad(false)
  74 {
  75     JNIEnv* env = WebCore_GetJavaEnv();
  76 
  77     m_text = text
  78         ? String(env, text)
  79         : String();
  80     m_unmodifiedText = m_text;
  81     m_keyIdentifier = keyIdentifier
  82         ? String(env, keyIdentifier)
  83         : String();
  84 }
  85 
  86 bool PlatformKeyboardEvent::currentCapsLockState()
  87 {
  88     notImplemented();
  89     return false;
  90 }
  91 
  92 void PlatformKeyboardEvent::disambiguateKeyDownEvent(Type, bool)
  93 {
  94     ASSERT_NOT_REACHED();
  95 }
  96 
  97 void PlatformKeyboardEvent::getCurrentModifierState(bool&, bool&, bool&, bool&)
  98 {
  99     //utaTODO: realize it in Java
 100 /*
 101 static const unsigned short HIGH_BIT_MASK_SHORT = 0x8000;
 102 #if OS(WINDOWS) || PLATFORM(JAVA_WIN)
 103     shiftKey = GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT;
 104     ctrlKey = GetKeyState(VK_CONTROL) & HIGH_BIT_MASK_SHORT;
 105     altKey = GetKeyState(VK_MENU) & HIGH_BIT_MASK_SHORT;
 106     metaKey = false;
 107 #elif OS(DARWIN)
 108     UInt32 currentModifiers = GetCurrentKeyModifiers();
 109     shiftKey = currentModifiers & ::shiftKey;
 110     ctrlKey = currentModifiers & ::controlKey;
 111     altKey = currentModifiers & ::optionKey;
 112     metaKey = currentModifiers & ::cmdKey;
 113 #else
 114     notImplemented();
 115 #endif
 116 */
 117     notImplemented();
 118 }
 119 
 120 
 121 } // namespace WebCore