[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.16-1409-g5afdf4d
eric at webkit.org
eric at webkit.org
Thu Dec 3 13:31:12 UTC 2009
The following commit has been merged in the webkit-1.1 branch:
commit df9ddc197fcab1b4339ac0e7c35eaab44972f84d
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Nov 10 19:45:13 2009 +0000
2009-11-10 Yaar Schnitman <yaar at chromium.org>
Reviewed by Dimitri Glazkov.
Up-streaming Chromium API src files: Platform specific files.
https://bugs.webkit.org/show_bug.cgi?id=31276
* src/gtk/WebFontInfo.cpp: Added.
(WebKit::WebFontInfo::familyForChars):
* src/gtk/WebInputEventFactory.cpp: Added.
(WebKit::gdkEventTimeToWebEventTime):
(WebKit::gdkStateToWebEventModifiers):
(WebKit::gdkEventToWindowsKeyCode):
(WebKit::getControlCharacter):
(WebKit::WebInputEventFactory::keyboardEvent):
(WebKit::WebInputEventFactory::mouseEvent):
(WebKit::WebInputEventFactory::mouseWheelEvent):
* src/gtk/WebScreenInfoFactory.cpp: Added.
(WebKit::WebScreenInfoFactory::screenInfo):
* src/linux/WebFontRendering.cpp: Added.
(WebKit::WebFontRendering::setHinting):
(WebKit::WebFontRendering::setAntiAlias):
(WebKit::WebFontRendering::setSubpixelGlyphs):
(WebKit::WebFontRendering::setLCDOrder):
(WebKit::WebFontRendering::setLCDOrientation):
* src/mac/WebInputEventFactory.mm: Added.
(WebKit::isKeyUpEvent):
(WebKit::isKeypadEvent):
(WebKit::windowsKeyCodeForKeyEvent):
(WebKit::textFromEvent):
(WebKit::unmodifiedTextFromEvent):
(WebKit::keyIdentifierForKeyEvent):
(WebKit::modifiersFromEvent):
(WebKit::WebInputEventFactory::keyboardEvent):
(WebKit::WebInputEventFactory::mouseEvent):
(WebKit::WebInputEventFactory::mouseWheelEvent):
* src/mac/WebScreenInfoFactory.mm: Added.
(WebKit::screenForWindow):
(WebKit::toUserSpace):
(WebKit::WebScreenInfoFactory::screenInfo):
* src/win/WebInputEventFactory.cpp: Added.
(WebKit::isKeyPad):
(WebKit::WebInputEventFactory::keyboardEvent):
(WebKit::GetRelativeCursorPos):
(WebKit::WebInputEventFactory::resetLastClickState):
(WebKit::WebInputEventFactory::mouseEvent):
(WebKit::WebInputEventFactory::mouseWheelEvent):
* src/win/WebScreenInfoFactory.cpp: Added.
(WebKit::toWebRect):
(WebKit::WebScreenInfoFactory::screenInfo):
* src/x11/WebScreenInfoFactory.cpp: Added.
(WebKit::WebScreenInfoFactory::screenInfo):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@50750 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index f18ea60..3560f77 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,5 +1,59 @@
2009-11-10 Yaar Schnitman <yaar at chromium.org>
+ Reviewed by Dimitri Glazkov.
+
+ Up-streaming Chromium API src files: Platform specific files.
+
+ https://bugs.webkit.org/show_bug.cgi?id=31276
+
+ * src/gtk/WebFontInfo.cpp: Added.
+ (WebKit::WebFontInfo::familyForChars):
+ * src/gtk/WebInputEventFactory.cpp: Added.
+ (WebKit::gdkEventTimeToWebEventTime):
+ (WebKit::gdkStateToWebEventModifiers):
+ (WebKit::gdkEventToWindowsKeyCode):
+ (WebKit::getControlCharacter):
+ (WebKit::WebInputEventFactory::keyboardEvent):
+ (WebKit::WebInputEventFactory::mouseEvent):
+ (WebKit::WebInputEventFactory::mouseWheelEvent):
+ * src/gtk/WebScreenInfoFactory.cpp: Added.
+ (WebKit::WebScreenInfoFactory::screenInfo):
+ * src/linux/WebFontRendering.cpp: Added.
+ (WebKit::WebFontRendering::setHinting):
+ (WebKit::WebFontRendering::setAntiAlias):
+ (WebKit::WebFontRendering::setSubpixelGlyphs):
+ (WebKit::WebFontRendering::setLCDOrder):
+ (WebKit::WebFontRendering::setLCDOrientation):
+ * src/mac/WebInputEventFactory.mm: Added.
+ (WebKit::isKeyUpEvent):
+ (WebKit::isKeypadEvent):
+ (WebKit::windowsKeyCodeForKeyEvent):
+ (WebKit::textFromEvent):
+ (WebKit::unmodifiedTextFromEvent):
+ (WebKit::keyIdentifierForKeyEvent):
+ (WebKit::modifiersFromEvent):
+ (WebKit::WebInputEventFactory::keyboardEvent):
+ (WebKit::WebInputEventFactory::mouseEvent):
+ (WebKit::WebInputEventFactory::mouseWheelEvent):
+ * src/mac/WebScreenInfoFactory.mm: Added.
+ (WebKit::screenForWindow):
+ (WebKit::toUserSpace):
+ (WebKit::WebScreenInfoFactory::screenInfo):
+ * src/win/WebInputEventFactory.cpp: Added.
+ (WebKit::isKeyPad):
+ (WebKit::WebInputEventFactory::keyboardEvent):
+ (WebKit::GetRelativeCursorPos):
+ (WebKit::WebInputEventFactory::resetLastClickState):
+ (WebKit::WebInputEventFactory::mouseEvent):
+ (WebKit::WebInputEventFactory::mouseWheelEvent):
+ * src/win/WebScreenInfoFactory.cpp: Added.
+ (WebKit::toWebRect):
+ (WebKit::WebScreenInfoFactory::screenInfo):
+ * src/x11/WebScreenInfoFactory.cpp: Added.
+ (WebKit::WebScreenInfoFactory::screenInfo):
+
+2009-11-10 Yaar Schnitman <yaar at chromium.org>
+
Reviewed by Eric Seidel.
Up-streaming Chromium API src files: WrapperResourceRequest and Response
diff --git a/WebKit/chromium/src/gtk/WebFontInfo.cpp b/WebKit/chromium/src/gtk/WebFontInfo.cpp
new file mode 100644
index 0000000..76ed618
--- /dev/null
+++ b/WebKit/chromium/src/gtk/WebFontInfo.cpp
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebFontInfo.h"
+
+#include <fontconfig/fontconfig.h>
+#include <string.h>
+#include <unicode/utf16.h>
+
+namespace WebKit {
+
+WebCString WebFontInfo::familyForChars(const WebUChar* characters, size_t numCharacters)
+{
+ FcCharSet* cset = FcCharSetCreate();
+ for (size_t i = 0; i < numCharacters; ++i) {
+ if (U16_IS_SURROGATE(characters[i])
+ && U16_IS_SURROGATE_LEAD(characters[i])
+ && i != numCharacters - 1
+ && U16_IS_TRAIL(characters[i + 1])) {
+ FcCharSetAddChar(cset, U16_GET_SUPPLEMENTARY(characters[i], characters[i+1]));
+ i++;
+ } else
+ FcCharSetAddChar(cset, characters[i]);
+ }
+ FcPattern* pattern = FcPatternCreate();
+
+ FcValue fcvalue;
+ fcvalue.type = FcTypeCharSet;
+ fcvalue.u.c = cset;
+ FcPatternAdd(pattern, FC_CHARSET, fcvalue, 0);
+
+ fcvalue.type = FcTypeBool;
+ fcvalue.u.b = FcTrue;
+ FcPatternAdd(pattern, FC_SCALABLE, fcvalue, 0);
+
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+
+ FcResult result;
+ FcFontSet* fontSet = FcFontSort(0, pattern, 0, 0, &result);
+ FcPatternDestroy(pattern);
+ FcCharSetDestroy(cset);
+
+ if (!fontSet)
+ return WebCString();
+
+ // Older versions of fontconfig have a bug where they cannot select
+ // only scalable fonts so we have to manually filter the results.
+ for (int i = 0; i < fontSet->nfont; ++i) {
+ FcPattern* current = fontSet->fonts[i];
+ FcBool isScalable;
+
+ if (FcPatternGetBool(current, FC_SCALABLE, 0, &isScalable) != FcResultMatch
+ || !isScalable)
+ continue;
+
+ // fontconfig can also return fonts which are unreadable
+ FcChar8* cFilename;
+ if (FcPatternGetString(current, FC_FILE, 0, &cFilename) != FcResultMatch)
+ continue;
+
+ if (access(reinterpret_cast<char*>(cFilename), R_OK))
+ continue;
+
+ FcChar8* family;
+ WebCString result;
+ if (FcPatternGetString(current, FC_FAMILY, 0, &family) == FcResultMatch) {
+ const char* charFamily = reinterpret_cast<char*>(family);
+ result = WebCString(charFamily, strlen(charFamily));
+ }
+ FcFontSetDestroy(fontSet);
+ return result;
+ }
+
+ FcFontSetDestroy(fontSet);
+ return WebCString();
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/gtk/WebInputEventFactory.cpp b/WebKit/chromium/src/gtk/WebInputEventFactory.cpp
new file mode 100644
index 0000000..890767c
--- /dev/null
+++ b/WebKit/chromium/src/gtk/WebInputEventFactory.cpp
@@ -0,0 +1,473 @@
+/*
+ * Copyright (C) 2006-2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebInputEventFactory.h"
+
+#include "KeyboardCodes.h"
+#include "KeyCodeConversion.h"
+
+#include "WebInputEvent.h"
+
+#include <gdk/gdk.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtkversion.h>
+
+#include <wtf/Assertions.h>
+
+namespace WebKit {
+
+static double gdkEventTimeToWebEventTime(guint32 time)
+{
+ // Convert from time in ms to time in sec.
+ return time / 1000.0;
+}
+
+static int gdkStateToWebEventModifiers(guint state)
+{
+ int modifiers = 0;
+ if (state & GDK_SHIFT_MASK)
+ modifiers |= WebInputEvent::ShiftKey;
+ if (state & GDK_CONTROL_MASK)
+ modifiers |= WebInputEvent::ControlKey;
+ if (state & GDK_MOD1_MASK)
+ modifiers |= WebInputEvent::AltKey;
+#if GTK_CHECK_VERSION(2, 10, 0)
+ if (state & GDK_META_MASK)
+ modifiers |= WebInputEvent::MetaKey;
+#endif
+ if (state & GDK_BUTTON1_MASK)
+ modifiers |= WebInputEvent::LeftButtonDown;
+ if (state & GDK_BUTTON2_MASK)
+ modifiers |= WebInputEvent::MiddleButtonDown;
+ if (state & GDK_BUTTON3_MASK)
+ modifiers |= WebInputEvent::RightButtonDown;
+ return modifiers;
+}
+
+static int gdkEventToWindowsKeyCode(const GdkEventKey* event)
+{
+ static const unsigned int hardwareCodeToGDKKeyval[] = {
+ 0, // 0x00:
+ 0, // 0x01:
+ 0, // 0x02:
+ 0, // 0x03:
+ 0, // 0x04:
+ 0, // 0x05:
+ 0, // 0x06:
+ 0, // 0x07:
+ 0, // 0x08:
+ 0, // 0x09: GDK_Escape
+ GDK_1, // 0x0A: GDK_1
+ GDK_2, // 0x0B: GDK_2
+ GDK_3, // 0x0C: GDK_3
+ GDK_4, // 0x0D: GDK_4
+ GDK_5, // 0x0E: GDK_5
+ GDK_6, // 0x0F: GDK_6
+ GDK_7, // 0x10: GDK_7
+ GDK_8, // 0x11: GDK_8
+ GDK_9, // 0x12: GDK_9
+ GDK_0, // 0x13: GDK_0
+ GDK_minus, // 0x14: GDK_minus
+ GDK_equal, // 0x15: GDK_equal
+ 0, // 0x16: GDK_BackSpace
+ 0, // 0x17: GDK_Tab
+ GDK_q, // 0x18: GDK_q
+ GDK_w, // 0x19: GDK_w
+ GDK_e, // 0x1A: GDK_e
+ GDK_r, // 0x1B: GDK_r
+ GDK_t, // 0x1C: GDK_t
+ GDK_y, // 0x1D: GDK_y
+ GDK_u, // 0x1E: GDK_u
+ GDK_i, // 0x1F: GDK_i
+ GDK_o, // 0x20: GDK_o
+ GDK_p, // 0x21: GDK_p
+ GDK_bracketleft, // 0x22: GDK_bracketleft
+ GDK_bracketright, // 0x23: GDK_bracketright
+ 0, // 0x24: GDK_Return
+ 0, // 0x25: GDK_Control_L
+ GDK_a, // 0x26: GDK_a
+ GDK_s, // 0x27: GDK_s
+ GDK_d, // 0x28: GDK_d
+ GDK_f, // 0x29: GDK_f
+ GDK_g, // 0x2A: GDK_g
+ GDK_h, // 0x2B: GDK_h
+ GDK_j, // 0x2C: GDK_j
+ GDK_k, // 0x2D: GDK_k
+ GDK_l, // 0x2E: GDK_l
+ GDK_semicolon, // 0x2F: GDK_semicolon
+ GDK_apostrophe, // 0x30: GDK_apostrophe
+ GDK_grave, // 0x31: GDK_grave
+ 0, // 0x32: GDK_Shift_L
+ GDK_backslash, // 0x33: GDK_backslash
+ GDK_z, // 0x34: GDK_z
+ GDK_x, // 0x35: GDK_x
+ GDK_c, // 0x36: GDK_c
+ GDK_v, // 0x37: GDK_v
+ GDK_b, // 0x38: GDK_b
+ GDK_n, // 0x39: GDK_n
+ GDK_m, // 0x3A: GDK_m
+ GDK_comma, // 0x3B: GDK_comma
+ GDK_period, // 0x3C: GDK_period
+ GDK_slash, // 0x3D: GDK_slash
+ 0, // 0x3E: GDK_Shift_R
+ };
+
+ // |windowsKeyCode| has to include a valid virtual-key code even when we
+ // use non-US layouts, e.g. even when we type an 'A' key of a US keyboard
+ // on the Hebrew layout, |windowsKeyCode| should be VK_A.
+ // On the other hand, |event->keyval| value depends on the current
+ // GdkKeymap object, i.e. when we type an 'A' key of a US keyboard on
+ // the Hebrew layout, |event->keyval| becomes GDK_hebrew_shin and this
+ // WebCore::windowsKeyCodeForKeyEvent() call returns 0.
+ // To improve compatibilty with Windows, we use |event->hardware_keycode|
+ // for retrieving its Windows key-code for the keys when the
+ // WebCore::windowsKeyCodeForEvent() call returns 0.
+ // We shouldn't use |event->hardware_keycode| for keys that GdkKeymap
+ // objects cannot change because |event->hardware_keycode| doesn't change
+ // even when we change the layout options, e.g. when we swap a control
+ // key and a caps-lock key, GTK doesn't swap their
+ // |event->hardware_keycode| values but swap their |event->keyval| values.
+ int windowsKeyCode = WebCore::windowsKeyCodeForKeyEvent(event->keyval);
+ if (windowsKeyCode)
+ return windowsKeyCode;
+
+ const int tableSize = sizeof(hardwareCodeToGDKKeyval) / sizeof(hardwareCodeToGDKKeyval[0]);
+ if (event->hardware_keycode < tableSize) {
+ int keyval = hardwareCodeToGDKKeyval[event->hardware_keycode];
+ if (keyval)
+ return WebCore::windowsKeyCodeForKeyEvent(keyval);
+ }
+
+ // This key is one that keyboard-layout drivers cannot change.
+ // Use |event->keyval| to retrieve its |windowsKeyCode| value.
+ return WebCore::windowsKeyCodeForKeyEvent(event->keyval);
+}
+
+// Gets the corresponding control character of a specified key code. See:
+// http://en.wikipedia.org/wiki/Control_characters
+// We emulate Windows behavior here.
+static WebUChar getControlCharacter(int windowsKeyCode, bool shift)
+{
+ if (windowsKeyCode >= WebCore::VKEY_A && windowsKeyCode <= WebCore::VKEY_Z) {
+ // ctrl-A ~ ctrl-Z map to \x01 ~ \x1A
+ return windowsKeyCode - WebCore::VKEY_A + 1;
+ }
+ if (shift) {
+ // following graphics chars require shift key to input.
+ switch (windowsKeyCode) {
+ // ctrl-@ maps to \x00 (Null byte)
+ case WebCore::VKEY_2:
+ return 0;
+ // ctrl-^ maps to \x1E (Record separator, Information separator two)
+ case WebCore::VKEY_6:
+ return 0x1E;
+ // ctrl-_ maps to \x1F (Unit separator, Information separator one)
+ case WebCore::VKEY_OEM_MINUS:
+ return 0x1F;
+ // Returns 0 for all other keys to avoid inputting unexpected chars.
+ default:
+ return 0;
+ }
+ } else {
+ switch (windowsKeyCode) {
+ // ctrl-[ maps to \x1B (Escape)
+ case WebCore::VKEY_OEM_4:
+ return 0x1B;
+ // ctrl-\ maps to \x1C (File separator, Information separator four)
+ case WebCore::VKEY_OEM_5:
+ return 0x1C;
+ // ctrl-] maps to \x1D (Group separator, Information separator three)
+ case WebCore::VKEY_OEM_6:
+ return 0x1D;
+ // ctrl-Enter maps to \x0A (Line feed)
+ case WebCore::VKEY_RETURN:
+ return 0x0A;
+ // Returns 0 for all other keys to avoid inputting unexpected chars.
+ default:
+ return 0;
+ }
+ }
+}
+
+// WebKeyboardEvent -----------------------------------------------------------
+
+WebKeyboardEvent WebInputEventFactory::keyboardEvent(const GdkEventKey* event)
+{
+ WebKeyboardEvent result;
+
+ result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
+ result.modifiers = gdkStateToWebEventModifiers(event->state);
+
+ switch (event->type) {
+ case GDK_KEY_RELEASE:
+ result.type = WebInputEvent::KeyUp;
+ break;
+ case GDK_KEY_PRESS:
+ result.type = WebInputEvent::RawKeyDown;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ // According to MSDN:
+ // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx
+ // Key events with Alt modifier and F10 are system key events.
+ // We just emulate this behavior. It's necessary to prevent webkit from
+ // processing keypress event generated by alt-d, etc.
+ // F10 is not special on Linux, so don't treat it as system key.
+ if (result.modifiers & WebInputEvent::AltKey)
+ result.isSystemKey = true;
+
+ // The key code tells us which physical key was pressed (for example, the
+ // A key went down or up). It does not determine whether A should be lower
+ // or upper case. This is what text does, which should be the keyval.
+ result.windowsKeyCode = gdkEventToWindowsKeyCode(event);
+ result.nativeKeyCode = event->hardware_keycode;
+
+ if (result.windowsKeyCode == WebCore::VKEY_RETURN)
+ // We need to treat the enter key as a key press of character \r. This
+ // is apparently just how webkit handles it and what it expects.
+ result.unmodifiedText[0] = '\r';
+ else
+ // FIXME: fix for non BMP chars
+ result.unmodifiedText[0] =
+ static_cast<WebUChar>(gdk_keyval_to_unicode(event->keyval));
+
+ // If ctrl key is pressed down, then control character shall be input.
+ if (result.modifiers & WebInputEvent::ControlKey)
+ result.text[0] = getControlCharacter(
+ result.windowsKeyCode, result.modifiers & WebInputEvent::ShiftKey);
+ else
+ result.text[0] = result.unmodifiedText[0];
+
+ result.setKeyIdentifierFromWindowsKeyCode();
+
+ // FIXME: Do we need to set IsAutoRepeat or IsKeyPad?
+
+ return result;
+}
+
+WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character, int state, double timeStampSeconds)
+{
+ // keyboardEvent(const GdkEventKey*) depends on the GdkEventKey object and
+ // it is hard to use/ it from signal handlers which don't use GdkEventKey
+ // objects (e.g. GtkIMContext signal handlers.) For such handlers, this
+ // function creates a WebInputEvent::Char event without using a
+ // GdkEventKey object.
+ WebKeyboardEvent result;
+ result.type = WebKit::WebInputEvent::Char;
+ result.timeStampSeconds = timeStampSeconds;
+ result.modifiers = gdkStateToWebEventModifiers(state);
+ result.windowsKeyCode = character;
+ result.nativeKeyCode = character;
+ result.text[0] = character;
+ result.unmodifiedText[0] = character;
+
+ // According to MSDN:
+ // http://msdn.microsoft.com/en-us/library/ms646286(VS.85).aspx
+ // Key events with Alt modifier and F10 are system key events.
+ // We just emulate this behavior. It's necessary to prevent webkit from
+ // processing keypress event generated by alt-d, etc.
+ // F10 is not special on Linux, so don't treat it as system key.
+ if (result.modifiers & WebInputEvent::AltKey)
+ result.isSystemKey = true;
+
+ return result;
+}
+
+// WebMouseEvent --------------------------------------------------------------
+
+WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventButton* event)
+{
+ WebMouseEvent result;
+
+ result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
+
+ result.modifiers = gdkStateToWebEventModifiers(event->state);
+ result.x = static_cast<int>(event->x);
+ result.y = static_cast<int>(event->y);
+ result.windowX = result.x;
+ result.windowY = result.y;
+ result.globalX = static_cast<int>(event->x_root);
+ result.globalY = static_cast<int>(event->y_root);
+ result.clickCount = 0;
+
+ switch (event->type) {
+ case GDK_3BUTTON_PRESS:
+ ++result.clickCount;
+ // fallthrough
+ case GDK_2BUTTON_PRESS:
+ ++result.clickCount;
+ // fallthrough
+ case GDK_BUTTON_PRESS:
+ result.type = WebInputEvent::MouseDown;
+ ++result.clickCount;
+ break;
+ case GDK_BUTTON_RELEASE:
+ result.type = WebInputEvent::MouseUp;
+ break;
+
+ default:
+ ASSERT_NOT_REACHED();
+ };
+
+ result.button = WebMouseEvent::ButtonNone;
+ if (event->button == 1)
+ result.button = WebMouseEvent::ButtonLeft;
+ else if (event->button == 2)
+ result.button = WebMouseEvent::ButtonMiddle;
+ else if (event->button == 3)
+ result.button = WebMouseEvent::ButtonRight;
+
+ return result;
+}
+
+WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventMotion* event)
+{
+ WebMouseEvent result;
+
+ result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
+ result.modifiers = gdkStateToWebEventModifiers(event->state);
+ result.x = static_cast<int>(event->x);
+ result.y = static_cast<int>(event->y);
+ result.windowX = result.x;
+ result.windowY = result.y;
+ result.globalX = static_cast<int>(event->x_root);
+ result.globalY = static_cast<int>(event->y_root);
+
+ switch (event->type) {
+ case GDK_MOTION_NOTIFY:
+ result.type = WebInputEvent::MouseMove;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ result.button = WebMouseEvent::ButtonNone;
+ if (event->state & GDK_BUTTON1_MASK)
+ result.button = WebMouseEvent::ButtonLeft;
+ else if (event->state & GDK_BUTTON2_MASK)
+ result.button = WebMouseEvent::ButtonMiddle;
+ else if (event->state & GDK_BUTTON3_MASK)
+ result.button = WebMouseEvent::ButtonRight;
+
+ return result;
+}
+
+WebMouseEvent WebInputEventFactory::mouseEvent(const GdkEventCrossing* event)
+{
+ WebMouseEvent result;
+
+ result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
+ result.modifiers = gdkStateToWebEventModifiers(event->state);
+ result.x = static_cast<int>(event->x);
+ result.y = static_cast<int>(event->y);
+ result.windowX = result.x;
+ result.windowY = result.y;
+ result.globalX = static_cast<int>(event->x_root);
+ result.globalY = static_cast<int>(event->y_root);
+
+ switch (event->type) {
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ // Note that if we sent MouseEnter or MouseLeave to WebKit, it
+ // wouldn't work - they don't result in the proper JavaScript events.
+ // MouseMove does the right thing.
+ result.type = WebInputEvent::MouseMove;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ result.button = WebMouseEvent::ButtonNone;
+ if (event->state & GDK_BUTTON1_MASK)
+ result.button = WebMouseEvent::ButtonLeft;
+ else if (event->state & GDK_BUTTON2_MASK)
+ result.button = WebMouseEvent::ButtonMiddle;
+ else if (event->state & GDK_BUTTON3_MASK)
+ result.button = WebMouseEvent::ButtonRight;
+
+ return result;
+}
+
+// WebMouseWheelEvent ---------------------------------------------------------
+
+WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(const GdkEventScroll* event)
+{
+ WebMouseWheelEvent result;
+
+ result.type = WebInputEvent::MouseWheel;
+ result.button = WebMouseEvent::ButtonNone;
+
+ result.timeStampSeconds = gdkEventTimeToWebEventTime(event->time);
+ result.modifiers = gdkStateToWebEventModifiers(event->state);
+ result.x = static_cast<int>(event->x);
+ result.y = static_cast<int>(event->y);
+ result.windowX = result.x;
+ result.windowY = result.y;
+ result.globalX = static_cast<int>(event->x_root);
+ result.globalY = static_cast<int>(event->y_root);
+
+ // How much should we scroll per mouse wheel event?
+ // - Windows uses 3 lines by default and obeys a system setting.
+ // - Mozilla has a pref that lets you either use the "system" number of lines
+ // to scroll, or lets the user override it.
+ // For the "system" number of lines, it appears they've hardcoded 3.
+ // See case NS_MOUSE_SCROLL in content/events/src/nsEventStateManager.cpp
+ // and InitMouseScrollEvent in widget/src/gtk2/nsCommonWidget.cpp .
+ // - Gtk makes the scroll amount a function of the size of the scroll bar,
+ // which is not available to us here.
+ // Instead, we pick a number that empirically matches Firefox's behavior.
+ static const float scrollbarPixelsPerTick = 160.0f / 3.0f;
+
+ switch (event->direction) {
+ case GDK_SCROLL_UP:
+ result.deltaY = scrollbarPixelsPerTick;
+ result.wheelTicksY = 1;
+ break;
+ case GDK_SCROLL_DOWN:
+ result.deltaY = -scrollbarPixelsPerTick;
+ result.wheelTicksY = -1;
+ break;
+ case GDK_SCROLL_LEFT:
+ result.deltaX = scrollbarPixelsPerTick;
+ result.wheelTicksX = -1; // Match Windows positive/negative orientation
+ break;
+ case GDK_SCROLL_RIGHT:
+ result.deltaX = -scrollbarPixelsPerTick;
+ result.wheelTicksX = 1;
+ break;
+ }
+
+ return result;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/gtk/WebScreenInfoFactory.cpp b/WebKit/chromium/src/gtk/WebScreenInfoFactory.cpp
new file mode 100644
index 0000000..081daa2
--- /dev/null
+++ b/WebKit/chromium/src/gtk/WebScreenInfoFactory.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebScreenInfoFactory.h"
+
+#include "WebScreenInfo.h"
+#include <gtk/gtk.h>
+
+namespace WebKit {
+
+WebScreenInfo WebScreenInfoFactory::screenInfo(GtkWidget* widget)
+{
+ WebScreenInfo results;
+ results.depth = 32;
+ results.depthPerComponent = 8;
+ results.isMonochrome = false;
+
+ if (!widget)
+ return results;
+
+ GdkScreen* screen = gtk_widget_get_screen(widget);
+
+ results.rect = WebRect(
+ 0, 0, gdk_screen_get_width(screen), gdk_screen_get_height(screen));
+
+ // I don't know of a way to query the "maximize" size of the window (e.g.
+ // screen size less sidebars etc) since this is something which only the
+ // window manager knows.
+ results.availableRect = results.rect;
+
+ return results;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/linux/WebFontRendering.cpp b/WebKit/chromium/src/linux/WebFontRendering.cpp
new file mode 100644
index 0000000..b9862f5
--- /dev/null
+++ b/WebKit/chromium/src/linux/WebFontRendering.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebFontRendering.h"
+
+#include "FontPlatformData.h"
+
+using WebCore::FontPlatformData;
+
+namespace WebKit {
+
+// static
+void WebFontRendering::setHinting(SkPaint::Hinting hinting)
+{
+ FontPlatformData::setHinting(hinting);
+}
+
+// static
+void WebFontRendering::setAntiAlias(bool isAntiAlias)
+{
+ FontPlatformData::setAntiAlias(isAntiAlias);
+}
+
+// static
+void WebFontRendering::setSubpixelGlyphs(bool isSubpixelGlyphs)
+{
+ FontPlatformData::setSubpixelGlyphs(isSubpixelGlyphs);
+}
+
+// static
+void WebFontRendering::setLCDOrder(SkFontHost::LCDOrder order)
+{
+ SkFontHost::SetSubpixelOrder(order);
+}
+
+// static
+void WebFontRendering::setLCDOrientation(SkFontHost::LCDOrientation orientation)
+{
+ SkFontHost::SetSubpixelOrientation(orientation);
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/mac/WebInputEventFactory.mm b/WebKit/chromium/src/mac/WebInputEventFactory.mm
new file mode 100644
index 0000000..d618228
--- /dev/null
+++ b/WebKit/chromium/src/mac/WebInputEventFactory.mm
@@ -0,0 +1,1196 @@
+/*
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2009 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebInputEventFactory.h"
+
+#include <ApplicationServices/ApplicationServices.h>
+#import <Cocoa/Cocoa.h>
+
+#include "WebInputEvent.h"
+#include <wtf/ASCIICType.h>
+
+namespace WebKit {
+
+// WebKeyboardEvent -----------------------------------------------------------
+
+// ----------------------------------------------------------------------------
+// Begin Apple code, copied from KeyEventMac.mm
+//
+// We can share some of this code if we factored it out of KeyEventMac, but
+// the main problem is that it relies on the NSString ctor on String for
+// conversions, and since we're building without PLATFORM(MAC), we don't have
+// that. As a result we have to use NSString here exclusively and thus tweak
+// the code so it's not re-usable as-is. One possiblity would be to make the
+// upstream code only use NSString, but I'm not certain how far that change
+// would propagate.
+
+static inline bool isKeyUpEvent(NSEvent* event)
+{
+ if ([event type] != NSFlagsChanged)
+ return [event type] == NSKeyUp;
+ // FIXME: This logic fails if the user presses both Shift keys at once, for example:
+ // we treat releasing one of them as keyDown.
+ switch ([event keyCode]) {
+ case 54: // Right Command
+ case 55: // Left Command
+ return ([event modifierFlags] & NSCommandKeyMask) == 0;
+
+ case 57: // Capslock
+ return ([event modifierFlags] & NSAlphaShiftKeyMask) == 0;
+
+ case 56: // Left Shift
+ case 60: // Right Shift
+ return ([event modifierFlags] & NSShiftKeyMask) == 0;
+
+ case 58: // Left Alt
+ case 61: // Right Alt
+ return ([event modifierFlags] & NSAlternateKeyMask) == 0;
+
+ case 59: // Left Ctrl
+ case 62: // Right Ctrl
+ return ([event modifierFlags] & NSControlKeyMask) == 0;
+
+ case 63: // Function
+ return ([event modifierFlags] & NSFunctionKeyMask) == 0;
+ }
+ return false;
+}
+
+static bool isKeypadEvent(NSEvent* event)
+{
+ // Check that this is the type of event that has a keyCode.
+ switch ([event type]) {
+ case NSKeyDown:
+ case NSKeyUp:
+ case NSFlagsChanged:
+ break;
+ default:
+ return false;
+ }
+
+ switch ([event keyCode]) {
+ case 71: // Clear
+ case 81: // =
+ case 75: // /
+ case 67: // *
+ case 78: // -
+ case 69: // +
+ case 76: // Enter
+ case 65: // .
+ case 82: // 0
+ case 83: // 1
+ case 84: // 2
+ case 85: // 3
+ case 86: // 4
+ case 87: // 5
+ case 88: // 6
+ case 89: // 7
+ case 91: // 8
+ case 92: // 9
+ return true;
+ }
+
+ return false;
+}
+
+static int windowsKeyCodeForKeyEvent(NSEvent* event)
+{
+ switch ([event keyCode]) {
+ // VK_TAB (09) TAB key
+ case 48:
+ return 0x09;
+
+ // VK_APPS (5D) Right windows/meta key
+ case 54: // Right Command
+ return 0x5D;
+
+ // VK_LWIN (5B) Left windows/meta key
+ case 55: // Left Command
+ return 0x5B;
+
+ // VK_CAPITAL (14) caps locks key
+ case 57: // Capslock
+ return 0x14;
+
+ // VK_SHIFT (10) either shift key
+ case 56: // Left Shift
+ case 60: // Right Shift
+ return 0x10;
+
+ // VK_MENU (12) either alt key
+ case 58: // Left Alt
+ case 61: // Right Alt
+ return 0x12;
+
+ // VK_CONTROL (11) either ctrl key
+ case 59: // Left Ctrl
+ case 62: // Right Ctrl
+ return 0x11;
+
+// Begin non-Apple addition ---------------------------------------------------
+ case 63: // Function (no Windows key code)
+ return 0;
+// End non-Apple addition -----------------------------------------------------
+
+ // VK_CLEAR (0C) CLEAR key
+ case 71: return 0x0C;
+
+ // VK_NUMPAD0 (60) Numeric keypad 0 key
+ case 82: return 0x60;
+ // VK_NUMPAD1 (61) Numeric keypad 1 key
+ case 83: return 0x61;
+ // VK_NUMPAD2 (62) Numeric keypad 2 key
+ case 84: return 0x62;
+ // VK_NUMPAD3 (63) Numeric keypad 3 key
+ case 85: return 0x63;
+ // VK_NUMPAD4 (64) Numeric keypad 4 key
+ case 86: return 0x64;
+ // VK_NUMPAD5 (65) Numeric keypad 5 key
+ case 87: return 0x65;
+ // VK_NUMPAD6 (66) Numeric keypad 6 key
+ case 88: return 0x66;
+ // VK_NUMPAD7 (67) Numeric keypad 7 key
+ case 89: return 0x67;
+ // VK_NUMPAD8 (68) Numeric keypad 8 key
+ case 91: return 0x68;
+ // VK_NUMPAD9 (69) Numeric keypad 9 key
+ case 92: return 0x69;
+ // VK_MULTIPLY (6A) Multiply key
+ case 67: return 0x6A;
+ // VK_ADD (6B) Add key
+ case 69: return 0x6B;
+
+ // VK_SUBTRACT (6D) Subtract key
+ case 78: return 0x6D;
+ // VK_DECIMAL (6E) Decimal key
+ case 65: return 0x6E;
+ // VK_DIVIDE (6F) Divide key
+ case 75: return 0x6F;
+ }
+
+// Begin non-Apple addition ---------------------------------------------------
+ // |-[NSEvent charactersIgnoringModifiers]| isn't allowed for
+ // NSFlagsChanged, and conceivably we may not have caught everything
+ // which causes an NSFlagsChanged above.
+ if ([event type] == NSFlagsChanged)
+ return 0;
+// End non-Apple addition -----------------------------------------------------
+
+ NSString* s = [event charactersIgnoringModifiers];
+ if ([s length] != 1)
+ return 0;
+
+ switch ([s characterAtIndex:0]) {
+ // VK_LBUTTON (01) Left mouse button
+ // VK_RBUTTON (02) Right mouse button
+ // VK_CANCEL (03) Control-break processing
+ // VK_MBUTTON (04) Middle mouse button (three-button mouse)
+ // VK_XBUTTON1 (05)
+ // VK_XBUTTON2 (06)
+
+ // VK_BACK (08) BACKSPACE key
+ case 8: case 0x7F: return 0x08;
+ // VK_TAB (09) TAB key
+ case 9: return 0x09;
+
+ // VK_CLEAR (0C) CLEAR key
+ // handled by key code above
+
+ // VK_RETURN (0D)
+ case 0xD: case 3: return 0x0D;
+
+ // VK_SHIFT (10) SHIFT key
+ // VK_CONTROL (11) CTRL key
+ // VK_MENU (12) ALT key
+
+ // VK_PAUSE (13) PAUSE key
+ case NSPauseFunctionKey: return 0x13;
+
+ // VK_CAPITAL (14) CAPS LOCK key
+ // VK_KANA (15) Input Method Editor (IME) Kana mode
+ // VK_HANGUEL (15) IME Hanguel mode (maintained for compatibility; use VK_HANGUL)
+ // VK_HANGUL (15) IME Hangul mode
+ // VK_JUNJA (17) IME Junja mode
+ // VK_FINAL (18) IME final mode
+ // VK_HANJA (19) IME Hanja mode
+ // VK_KANJI (19) IME Kanji mode
+
+ // VK_ESCAPE (1B) ESC key
+ case 0x1B: return 0x1B;
+
+ // VK_CONVERT (1C) IME convert
+ // VK_NONCONVERT (1D) IME nonconvert
+ // VK_ACCEPT (1E) IME accept
+ // VK_MODECHANGE (1F) IME mode change request
+
+ // VK_SPACE (20) SPACEBAR
+ case ' ': return 0x20;
+ // VK_PRIOR (21) PAGE UP key
+ case NSPageUpFunctionKey: return 0x21;
+ // VK_NEXT (22) PAGE DOWN key
+ case NSPageDownFunctionKey: return 0x22;
+ // VK_END (23) END key
+ case NSEndFunctionKey: return 0x23;
+ // VK_HOME (24) HOME key
+ case NSHomeFunctionKey: return 0x24;
+ // VK_LEFT (25) LEFT ARROW key
+ case NSLeftArrowFunctionKey: return 0x25;
+ // VK_UP (26) UP ARROW key
+ case NSUpArrowFunctionKey: return 0x26;
+ // VK_RIGHT (27) RIGHT ARROW key
+ case NSRightArrowFunctionKey: return 0x27;
+ // VK_DOWN (28) DOWN ARROW key
+ case NSDownArrowFunctionKey: return 0x28;
+ // VK_SELECT (29) SELECT key
+ case NSSelectFunctionKey: return 0x29;
+ // VK_PRINT (2A) PRINT key
+ case NSPrintFunctionKey: return 0x2A;
+ // VK_EXECUTE (2B) EXECUTE key
+ case NSExecuteFunctionKey: return 0x2B;
+ // VK_SNAPSHOT (2C) PRINT SCREEN key
+ case NSPrintScreenFunctionKey: return 0x2C;
+ // VK_INSERT (2D) INS key
+ case NSInsertFunctionKey: case NSHelpFunctionKey: return 0x2D;
+ // VK_DELETE (2E) DEL key
+ case NSDeleteFunctionKey: return 0x2E;
+
+ // VK_HELP (2F) HELP key
+
+ // (30) 0 key
+ case '0': case ')': return 0x30;
+ // (31) 1 key
+ case '1': case '!': return 0x31;
+ // (32) 2 key
+ case '2': case '@': return 0x32;
+ // (33) 3 key
+ case '3': case '#': return 0x33;
+ // (34) 4 key
+ case '4': case '$': return 0x34;
+ // (35) 5 key
+ case '5': case '%': return 0x35;
+ // (36) 6 key
+ case '6': case '^': return 0x36;
+ // (37) 7 key
+ case '7': case '&': return 0x37;
+ // (38) 8 key
+ case '8': case '*': return 0x38;
+ // (39) 9 key
+ case '9': case '(': return 0x39;
+ // (41) A key
+ case 'a': case 'A': return 0x41;
+ // (42) B key
+ case 'b': case 'B': return 0x42;
+ // (43) C key
+ case 'c': case 'C': return 0x43;
+ // (44) D key
+ case 'd': case 'D': return 0x44;
+ // (45) E key
+ case 'e': case 'E': return 0x45;
+ // (46) F key
+ case 'f': case 'F': return 0x46;
+ // (47) G key
+ case 'g': case 'G': return 0x47;
+ // (48) H key
+ case 'h': case 'H': return 0x48;
+ // (49) I key
+ case 'i': case 'I': return 0x49;
+ // (4A) J key
+ case 'j': case 'J': return 0x4A;
+ // (4B) K key
+ case 'k': case 'K': return 0x4B;
+ // (4C) L key
+ case 'l': case 'L': return 0x4C;
+ // (4D) M key
+ case 'm': case 'M': return 0x4D;
+ // (4E) N key
+ case 'n': case 'N': return 0x4E;
+ // (4F) O key
+ case 'o': case 'O': return 0x4F;
+ // (50) P key
+ case 'p': case 'P': return 0x50;
+ // (51) Q key
+ case 'q': case 'Q': return 0x51;
+ // (52) R key
+ case 'r': case 'R': return 0x52;
+ // (53) S key
+ case 's': case 'S': return 0x53;
+ // (54) T key
+ case 't': case 'T': return 0x54;
+ // (55) U key
+ case 'u': case 'U': return 0x55;
+ // (56) V key
+ case 'v': case 'V': return 0x56;
+ // (57) W key
+ case 'w': case 'W': return 0x57;
+ // (58) X key
+ case 'x': case 'X': return 0x58;
+ // (59) Y key
+ case 'y': case 'Y': return 0x59;
+ // (5A) Z key
+ case 'z': case 'Z': return 0x5A;
+
+ // VK_LWIN (5B) Left Windows key (Microsoft Natural keyboard)
+ // VK_RWIN (5C) Right Windows key (Natural keyboard)
+ // VK_APPS (5D) Applications key (Natural keyboard)
+ // VK_SLEEP (5F) Computer Sleep key
+
+ // VK_NUMPAD0 (60) Numeric keypad 0 key
+ // VK_NUMPAD1 (61) Numeric keypad 1 key
+ // VK_NUMPAD2 (62) Numeric keypad 2 key
+ // VK_NUMPAD3 (63) Numeric keypad 3 key
+ // VK_NUMPAD4 (64) Numeric keypad 4 key
+ // VK_NUMPAD5 (65) Numeric keypad 5 key
+ // VK_NUMPAD6 (66) Numeric keypad 6 key
+ // VK_NUMPAD7 (67) Numeric keypad 7 key
+ // VK_NUMPAD8 (68) Numeric keypad 8 key
+ // VK_NUMPAD9 (69) Numeric keypad 9 key
+ // VK_MULTIPLY (6A) Multiply key
+ // VK_ADD (6B) Add key
+ // handled by key code above
+
+ // VK_SEPARATOR (6C) Separator key
+
+ // VK_SUBTRACT (6D) Subtract key
+ // VK_DECIMAL (6E) Decimal key
+ // VK_DIVIDE (6F) Divide key
+ // handled by key code above
+
+ // VK_F1 (70) F1 key
+ case NSF1FunctionKey: return 0x70;
+ // VK_F2 (71) F2 key
+ case NSF2FunctionKey: return 0x71;
+ // VK_F3 (72) F3 key
+ case NSF3FunctionKey: return 0x72;
+ // VK_F4 (73) F4 key
+ case NSF4FunctionKey: return 0x73;
+ // VK_F5 (74) F5 key
+ case NSF5FunctionKey: return 0x74;
+ // VK_F6 (75) F6 key
+ case NSF6FunctionKey: return 0x75;
+ // VK_F7 (76) F7 key
+ case NSF7FunctionKey: return 0x76;
+ // VK_F8 (77) F8 key
+ case NSF8FunctionKey: return 0x77;
+ // VK_F9 (78) F9 key
+ case NSF9FunctionKey: return 0x78;
+ // VK_F10 (79) F10 key
+ case NSF10FunctionKey: return 0x79;
+ // VK_F11 (7A) F11 key
+ case NSF11FunctionKey: return 0x7A;
+ // VK_F12 (7B) F12 key
+ case NSF12FunctionKey: return 0x7B;
+ // VK_F13 (7C) F13 key
+ case NSF13FunctionKey: return 0x7C;
+ // VK_F14 (7D) F14 key
+ case NSF14FunctionKey: return 0x7D;
+ // VK_F15 (7E) F15 key
+ case NSF15FunctionKey: return 0x7E;
+ // VK_F16 (7F) F16 key
+ case NSF16FunctionKey: return 0x7F;
+ // VK_F17 (80H) F17 key
+ case NSF17FunctionKey: return 0x80;
+ // VK_F18 (81H) F18 key
+ case NSF18FunctionKey: return 0x81;
+ // VK_F19 (82H) F19 key
+ case NSF19FunctionKey: return 0x82;
+ // VK_F20 (83H) F20 key
+ case NSF20FunctionKey: return 0x83;
+ // VK_F21 (84H) F21 key
+ case NSF21FunctionKey: return 0x84;
+ // VK_F22 (85H) F22 key
+ case NSF22FunctionKey: return 0x85;
+ // VK_F23 (86H) F23 key
+ case NSF23FunctionKey: return 0x86;
+ // VK_F24 (87H) F24 key
+ case NSF24FunctionKey: return 0x87;
+
+ // VK_NUMLOCK (90) NUM LOCK key
+
+ // VK_SCROLL (91) SCROLL LOCK key
+ case NSScrollLockFunctionKey: return 0x91;
+
+ // VK_LSHIFT (A0) Left SHIFT key
+ // VK_RSHIFT (A1) Right SHIFT key
+ // VK_LCONTROL (A2) Left CONTROL key
+ // VK_RCONTROL (A3) Right CONTROL key
+ // VK_LMENU (A4) Left MENU key
+ // VK_RMENU (A5) Right MENU key
+ // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
+ // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
+ // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
+ // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
+ // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
+ // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
+ // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
+ // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
+ // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
+ // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
+ // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
+ // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
+ // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
+ // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
+ // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
+ // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
+ // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
+ // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
+
+ // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
+ case ';': case ':': return 0xBA;
+ // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
+ case '=': case '+': return 0xBB;
+ // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
+ case ',': case '<': return 0xBC;
+ // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
+ case '-': case '_': return 0xBD;
+ // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
+ case '.': case '>': return 0xBE;
+ // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
+ case '/': case '?': return 0xBF;
+ // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
+ case '`': case '~': return 0xC0;
+ // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
+ case '[': case '{': return 0xDB;
+ // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
+ case '\\': case '|': return 0xDC;
+ // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
+ case ']': case '}': return 0xDD;
+ // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
+ case '\'': case '"': return 0xDE;
+
+ // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
+ // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
+ // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
+ // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
+ // VK_ATTN (F6) Attn key
+ // VK_CRSEL (F7) CrSel key
+ // VK_EXSEL (F8) ExSel key
+ // VK_EREOF (F9) Erase EOF key
+ // VK_PLAY (FA) Play key
+ // VK_ZOOM (FB) Zoom key
+ // VK_NONAME (FC) Reserved for future use
+ // VK_PA1 (FD) PA1 key
+ // VK_OEM_CLEAR (FE) Clear key
+ }
+
+ return 0;
+}
+
+static inline NSString* textFromEvent(NSEvent* event)
+{
+ if ([event type] == NSFlagsChanged)
+ return @"";
+ return [event characters];
+}
+
+static inline NSString* unmodifiedTextFromEvent(NSEvent* event)
+{
+ if ([event type] == NSFlagsChanged)
+ return @"";
+ return [event charactersIgnoringModifiers];
+}
+
+static NSString* keyIdentifierForKeyEvent(NSEvent* event)
+{
+ if ([event type] == NSFlagsChanged) {
+ switch ([event keyCode]) {
+ case 54: // Right Command
+ case 55: // Left Command
+ return @"Meta";
+
+ case 57: // Capslock
+ return @"CapsLock";
+
+ case 56: // Left Shift
+ case 60: // Right Shift
+ return @"Shift";
+
+ case 58: // Left Alt
+ case 61: // Right Alt
+ return @"Alt";
+
+ case 59: // Left Ctrl
+ case 62: // Right Ctrl
+ return @"Control";
+
+// Begin non-Apple addition/modification --------------------------------------
+ case 63: // Function
+ return @"Function";
+
+ default: // Unknown, but this may be a strange/new keyboard.
+ return @"Unidentified";
+// End non-Apple addition/modification ----------------------------------------
+ }
+ }
+
+ NSString* s = [event charactersIgnoringModifiers];
+ if ([s length] != 1)
+ return @"Unidentified";
+
+ unichar c = [s characterAtIndex:0];
+ switch (c) {
+ // Each identifier listed in the DOM spec is listed here.
+ // Many are simply commented out since they do not appear on standard Macintosh keyboards
+ // or are on a key that doesn't have a corresponding character.
+
+ // "Accept"
+ // "AllCandidates"
+
+ // "Alt"
+ case NSMenuFunctionKey:
+ return @"Alt";
+
+ // "Apps"
+ // "BrowserBack"
+ // "BrowserForward"
+ // "BrowserHome"
+ // "BrowserRefresh"
+ // "BrowserSearch"
+ // "BrowserStop"
+ // "CapsLock"
+
+ // "Clear"
+ case NSClearLineFunctionKey:
+ return @"Clear";
+
+ // "CodeInput"
+ // "Compose"
+ // "Control"
+ // "Crsel"
+ // "Convert"
+ // "Copy"
+ // "Cut"
+
+ // "Down"
+ case NSDownArrowFunctionKey:
+ return @"Down";
+ // "End"
+ case NSEndFunctionKey:
+ return @"End";
+ // "Enter"
+ case 0x3: case 0xA: case 0xD: // Macintosh calls the one on the main keyboard Return, but Windows calls it Enter, so we'll do the same for the DOM
+ return @"Enter";
+
+ // "EraseEof"
+
+ // "Execute"
+ case NSExecuteFunctionKey:
+ return @"Execute";
+
+ // "Exsel"
+
+ // "F1"
+ case NSF1FunctionKey:
+ return @"F1";
+ // "F2"
+ case NSF2FunctionKey:
+ return @"F2";
+ // "F3"
+ case NSF3FunctionKey:
+ return @"F3";
+ // "F4"
+ case NSF4FunctionKey:
+ return @"F4";
+ // "F5"
+ case NSF5FunctionKey:
+ return @"F5";
+ // "F6"
+ case NSF6FunctionKey:
+ return @"F6";
+ // "F7"
+ case NSF7FunctionKey:
+ return @"F7";
+ // "F8"
+ case NSF8FunctionKey:
+ return @"F8";
+ // "F9"
+ case NSF9FunctionKey:
+ return @"F9";
+ // "F10"
+ case NSF10FunctionKey:
+ return @"F10";
+ // "F11"
+ case NSF11FunctionKey:
+ return @"F11";
+ // "F12"
+ case NSF12FunctionKey:
+ return @"F12";
+ // "F13"
+ case NSF13FunctionKey:
+ return @"F13";
+ // "F14"
+ case NSF14FunctionKey:
+ return @"F14";
+ // "F15"
+ case NSF15FunctionKey:
+ return @"F15";
+ // "F16"
+ case NSF16FunctionKey:
+ return @"F16";
+ // "F17"
+ case NSF17FunctionKey:
+ return @"F17";
+ // "F18"
+ case NSF18FunctionKey:
+ return @"F18";
+ // "F19"
+ case NSF19FunctionKey:
+ return @"F19";
+ // "F20"
+ case NSF20FunctionKey:
+ return @"F20";
+ // "F21"
+ case NSF21FunctionKey:
+ return @"F21";
+ // "F22"
+ case NSF22FunctionKey:
+ return @"F22";
+ // "F23"
+ case NSF23FunctionKey:
+ return @"F23";
+ // "F24"
+ case NSF24FunctionKey:
+ return @"F24";
+
+ // "FinalMode"
+
+ // "Find"
+ case NSFindFunctionKey:
+ return @"Find";
+
+ // "FullWidth"
+ // "HalfWidth"
+ // "HangulMode"
+ // "HanjaMode"
+
+ // "Help"
+ case NSHelpFunctionKey:
+ return @"Help";
+
+ // "Hiragana"
+
+ // "Home"
+ case NSHomeFunctionKey:
+ return @"Home";
+ // "Insert"
+ case NSInsertFunctionKey:
+ return @"Insert";
+
+ // "JapaneseHiragana"
+ // "JapaneseKatakana"
+ // "JapaneseRomaji"
+ // "JunjaMode"
+ // "KanaMode"
+ // "KanjiMode"
+ // "Katakana"
+ // "LaunchApplication1"
+ // "LaunchApplication2"
+ // "LaunchMail"
+
+ // "Left"
+ case NSLeftArrowFunctionKey:
+ return @"Left";
+
+ // "Meta"
+ // "MediaNextTrack"
+ // "MediaPlayPause"
+ // "MediaPreviousTrack"
+ // "MediaStop"
+
+ // "ModeChange"
+ case NSModeSwitchFunctionKey:
+ return @"ModeChange";
+
+ // "Nonconvert"
+ // "NumLock"
+
+ // "PageDown"
+ case NSPageDownFunctionKey:
+ return @"PageDown";
+ // "PageUp"
+ case NSPageUpFunctionKey:
+ return @"PageUp";
+
+ // "Paste"
+
+ // "Pause"
+ case NSPauseFunctionKey:
+ return @"Pause";
+
+ // "Play"
+ // "PreviousCandidate"
+
+ // "PrintScreen"
+ case NSPrintScreenFunctionKey:
+ return @"PrintScreen";
+
+ // "Process"
+ // "Props"
+
+ // "Right"
+ case NSRightArrowFunctionKey:
+ return @"Right";
+
+ // "RomanCharacters"
+
+ // "Scroll"
+ case NSScrollLockFunctionKey:
+ return @"Scroll";
+ // "Select"
+ case NSSelectFunctionKey:
+ return @"Select";
+
+ // "SelectMedia"
+ // "Shift"
+
+ // "Stop"
+ case NSStopFunctionKey:
+ return @"Stop";
+ // "Up"
+ case NSUpArrowFunctionKey:
+ return @"Up";
+ // "Undo"
+ case NSUndoFunctionKey:
+ return @"Undo";
+
+ // "VolumeDown"
+ // "VolumeMute"
+ // "VolumeUp"
+ // "Win"
+ // "Zoom"
+
+ // More function keys, not in the key identifier specification.
+ case NSF25FunctionKey:
+ return @"F25";
+ case NSF26FunctionKey:
+ return @"F26";
+ case NSF27FunctionKey:
+ return @"F27";
+ case NSF28FunctionKey:
+ return @"F28";
+ case NSF29FunctionKey:
+ return @"F29";
+ case NSF30FunctionKey:
+ return @"F30";
+ case NSF31FunctionKey:
+ return @"F31";
+ case NSF32FunctionKey:
+ return @"F32";
+ case NSF33FunctionKey:
+ return @"F33";
+ case NSF34FunctionKey:
+ return @"F34";
+ case NSF35FunctionKey:
+ return @"F35";
+
+ // Turn 0x7F into 0x08, because backspace needs to always be 0x08.
+ case 0x7F:
+ return @"U+0008";
+ // Standard says that DEL becomes U+007F.
+ case NSDeleteFunctionKey:
+ return @"U+007F";
+
+ // Always use 0x09 for tab instead of AppKit's backtab character.
+ case NSBackTabCharacter:
+ return @"U+0009";
+
+ case NSBeginFunctionKey:
+ case NSBreakFunctionKey:
+ case NSClearDisplayFunctionKey:
+ case NSDeleteCharFunctionKey:
+ case NSDeleteLineFunctionKey:
+ case NSInsertCharFunctionKey:
+ case NSInsertLineFunctionKey:
+ case NSNextFunctionKey:
+ case NSPrevFunctionKey:
+ case NSPrintFunctionKey:
+ case NSRedoFunctionKey:
+ case NSResetFunctionKey:
+ case NSSysReqFunctionKey:
+ case NSSystemFunctionKey:
+ case NSUserFunctionKey:
+ // FIXME: We should use something other than the vendor-area Unicode values for the above keys.
+ // For now, just fall through to the default.
+ default:
+ return [NSString stringWithFormat:@"U+%04X", WTF::toASCIIUpper(c)];
+ }
+}
+
+// End Apple code.
+// ----------------------------------------------------------------------------
+
+static inline int modifiersFromEvent(NSEvent* event) {
+ int modifiers = 0;
+
+ if ([event modifierFlags] & NSControlKeyMask)
+ modifiers |= WebInputEvent::ControlKey;
+ if ([event modifierFlags] & NSShiftKeyMask)
+ modifiers |= WebInputEvent::ShiftKey;
+ if ([event modifierFlags] & NSAlternateKeyMask)
+ modifiers |= WebInputEvent::AltKey;
+ if ([event modifierFlags] & NSCommandKeyMask)
+ modifiers |= WebInputEvent::MetaKey;
+ // TODO(port): Set mouse button states
+
+ return modifiers;
+}
+
+WebKeyboardEvent WebInputEventFactory::keyboardEvent(NSEvent* event)
+{
+ WebKeyboardEvent result;
+
+ result.type =
+ isKeyUpEvent(event) ? WebInputEvent::KeyUp : WebInputEvent::RawKeyDown;
+
+ result.modifiers = modifiersFromEvent(event);
+
+ if (isKeypadEvent(event))
+ result.modifiers |= WebInputEvent::IsKeyPad;
+
+ if (([event type] != NSFlagsChanged) && [event isARepeat])
+ result.modifiers |= WebInputEvent::IsAutoRepeat;
+
+ result.windowsKeyCode = windowsKeyCodeForKeyEvent(event);
+ result.nativeKeyCode = [event keyCode];
+
+ NSString* textStr = textFromEvent(event);
+ NSString* unmodifiedStr = unmodifiedTextFromEvent(event);
+ NSString* identifierStr = keyIdentifierForKeyEvent(event);
+
+ // Begin Apple code, copied from KeyEventMac.mm
+
+ // Always use 13 for Enter/Return -- we don't want to use AppKit's
+ // different character for Enter.
+ if (result.windowsKeyCode == '\r') {
+ textStr = @"\r";
+ unmodifiedStr = @"\r";
+ }
+
+ // The adjustments below are only needed in backward compatibility mode,
+ // but we cannot tell what mode we are in from here.
+
+ // Turn 0x7F into 8, because backspace needs to always be 8.
+ if ([textStr isEqualToString:@"\x7F"])
+ textStr = @"\x8";
+ if ([unmodifiedStr isEqualToString:@"\x7F"])
+ unmodifiedStr = @"\x8";
+ // Always use 9 for tab -- we don't want to use AppKit's different character
+ // for shift-tab.
+ if (result.windowsKeyCode == 9) {
+ textStr = @"\x9";
+ unmodifiedStr = @"\x9";
+ }
+
+ // End Apple code.
+
+ if ([textStr length] < WebKeyboardEvent::textLengthCap &&
+ [unmodifiedStr length] < WebKeyboardEvent::textLengthCap) {
+ [textStr getCharacters:&result.text[0]];
+ [unmodifiedStr getCharacters:&result.unmodifiedText[0]];
+ } else
+ ASSERT_NOT_REACHED();
+
+ [identifierStr getCString:&result.keyIdentifier[0]
+ maxLength:sizeof(result.keyIdentifier)
+ encoding:NSASCIIStringEncoding];
+
+ result.timeStampSeconds = [event timestamp];
+
+ // Windows and Linux set |isSystemKey| if alt is down. WebKit looks at this
+ // flag to decide if it should handle a key or not. E.g. alt-left/right
+ // shouldn't be used by WebKit to scroll the current page, because we want
+ // to get that key back for it to do history navigation. Hence, the
+ // corresponding situation on OS X is to set this for cmd key presses.
+ if (result.modifiers & WebInputEvent::MetaKey)
+ result.isSystemKey = true;
+
+ return result;
+}
+
+WebKeyboardEvent WebInputEventFactory::keyboardEvent(wchar_t character,
+ int modifiers,
+ double timeStampSeconds)
+{
+ // keyboardEvent(NSEvent*) depends on the NSEvent object and
+ // it is hard to use it from methods of the NSTextInput protocol. For
+ // such methods, this function creates a WebInputEvent::Char event without
+ // using a NSEvent object.
+ WebKeyboardEvent result;
+ result.type = WebKit::WebInputEvent::Char;
+ result.timeStampSeconds = timeStampSeconds;
+ result.modifiers = modifiers;
+ result.windowsKeyCode = character;
+ result.nativeKeyCode = character;
+ result.text[0] = character;
+ result.unmodifiedText[0] = character;
+
+ // Windows and Linux set |isSystemKey| if alt is down. WebKit looks at this
+ // flag to decide if it should handle a key or not. E.g. alt-left/right
+ // shouldn't be used by WebKit to scroll the current page, because we want
+ // to get that key back for it to do history navigation. Hence, the
+ // corresponding situation on OS X is to set this for cmd key presses.
+ if (result.modifiers & WebInputEvent::MetaKey)
+ result.isSystemKey = true;
+
+ return result;
+}
+
+// WebMouseEvent --------------------------------------------------------------
+
+WebMouseEvent WebInputEventFactory::mouseEvent(NSEvent* event, NSView* view)
+{
+ WebMouseEvent result;
+
+ result.clickCount = 0;
+
+ switch ([event type]) {
+ case NSMouseExited:
+ result.type = WebInputEvent::MouseLeave;
+ result.button = WebMouseEvent::ButtonNone;
+ break;
+ case NSLeftMouseDown:
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
+ result.button = WebMouseEvent::ButtonLeft;
+ break;
+ case NSOtherMouseDown:
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
+ result.button = WebMouseEvent::ButtonMiddle;
+ break;
+ case NSRightMouseDown:
+ result.type = WebInputEvent::MouseDown;
+ result.clickCount = [event clickCount];
+ result.button = WebMouseEvent::ButtonRight;
+ break;
+ case NSLeftMouseUp:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonLeft;
+ break;
+ case NSOtherMouseUp:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonMiddle;
+ break;
+ case NSRightMouseUp:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonRight;
+ break;
+ case NSMouseMoved:
+ case NSMouseEntered:
+ result.type = WebInputEvent::MouseMove;
+ break;
+ case NSLeftMouseDragged:
+ result.type = WebInputEvent::MouseMove;
+ result.button = WebMouseEvent::ButtonLeft;
+ break;
+ case NSOtherMouseDragged:
+ result.type = WebInputEvent::MouseMove;
+ result.button = WebMouseEvent::ButtonMiddle;
+ break;
+ case NSRightMouseDragged:
+ result.type = WebInputEvent::MouseMove;
+ result.button = WebMouseEvent::ButtonRight;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ NSPoint location = [NSEvent mouseLocation]; // global coordinates
+ result.globalX = location.x;
+ result.globalY = [[[view window] screen] frame].size.height - location.y;
+
+ NSPoint windowLocal = [event locationInWindow];
+ location = [view convertPoint:windowLocal fromView:nil];
+ result.y = [view frame].size.height - location.y; // flip y
+ result.x = location.x;
+ result.windowX = result.x;
+ result.windowY = result.y;
+
+ result.modifiers = modifiersFromEvent(event);
+
+ result.timeStampSeconds = [event timestamp];
+
+ return result;
+}
+
+// WebMouseWheelEvent ---------------------------------------------------------
+
+WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(NSEvent* event, NSView* view)
+{
+ WebMouseWheelEvent result;
+
+ result.type = WebInputEvent::MouseWheel;
+ result.button = WebMouseEvent::ButtonNone;
+
+ result.modifiers = modifiersFromEvent(event);
+
+ // Set coordinates by translating event coordinates from screen to client.
+ NSPoint location = [NSEvent mouseLocation]; // global coordinates
+ result.globalX = location.x;
+ result.globalY = location.y;
+ NSPoint windowLocal = [event locationInWindow];
+ location = [view convertPoint:windowLocal fromView:nil];
+ result.x = location.x;
+ result.y = [view frame].size.height - location.y; // flip y
+ result.windowX = result.x;
+ result.windowY = result.y;
+
+ // Of Mice and Men
+ // ---------------
+ //
+ // There are three types of scroll data available on a scroll wheel CGEvent.
+ // Apple's documentation ([1]) is rather vague in their differences, and not
+ // terribly helpful in deciding which to use. This is what's really going on.
+ //
+ // First, these events behave very differently depending on whether a standard
+ // wheel mouse is used (one that scrolls in discrete units) or a
+ // trackpad/Mighty Mouse is used (which both provide continuous scrolling).
+ // You must check to see which was used for the event by testing the
+ // kCGScrollWheelEventIsContinuous field.
+ //
+ // Second, these events refer to "axes". Axis 1 is the y-axis, and axis 2 is
+ // the x-axis.
+ //
+ // Third, there is a concept of mouse acceleration. Scrolling the same amount
+ // of physical distance will give you different results logically depending on
+ // whether you scrolled a little at a time or in one continuous motion. Some
+ // fields account for this while others do not.
+ //
+ // Fourth, for trackpads there is a concept of chunkiness. When scrolling
+ // continuously, events can be delivered in chunks. That is to say, lots of
+ // scroll events with delta 0 will be delivered, and every so often an event
+ // with a non-zero delta will be delivered, containing the accumulated deltas
+ // from all the intermediate moves. [2]
+ //
+ // For notchy wheel mice (kCGScrollWheelEventIsContinuous == 0)
+ // ------------------------------------------------------------
+ //
+ // kCGScrollWheelEventDeltaAxis*
+ // This is the rawest of raw events. For each mouse notch you get a value of
+ // +1/-1. This does not take acceleration into account and thus is less
+ // useful for building UIs.
+ //
+ // kCGScrollWheelEventPointDeltaAxis*
+ // This is smarter. In general, for each mouse notch you get a value of
+ // +1/-1, but this _does_ take acceleration into account, so you will get
+ // larger values on longer scrolls. This field would be ideal for building
+ // UIs except for one nasty bug: when the shift key is pressed, this set of
+ // fields fails to move the value into the axis2 field (the other two types
+ // of data do). This wouldn't be so bad except for the fact that while the
+ // number of axes is used in the creation of a CGScrollWheelEvent, there is
+ // no way to get that information out of the event once created.
+ //
+ // kCGScrollWheelEventFixedPtDeltaAxis*
+ // This is a fixed value, and for each mouse notch you get a value of
+ // +0.1/-0.1 (but, like above, scaled appropriately for acceleration). This
+ // value takes acceleration into account, and in fact is identical to the
+ // results you get from -[NSEvent delta*]. (That is, if you linked on Tiger
+ // or greater; see [2] for details.)
+ //
+ // A note about continuous devices
+ // -------------------------------
+ //
+ // There are two devices that provide continuous scrolling events (trackpads
+ // and Mighty Mouses) and they behave rather differently. The Mighty Mouse
+ // behaves a lot like a regular mouse. There is no chunking, and the
+ // FixedPtDelta values are the PointDelta values multiplied by 0.1. With the
+ // trackpad, though, there is chunking. While the FixedPtDelta values are
+ // reasonable (they occur about every fifth event but have values five times
+ // larger than usual) the Delta values are unreasonable. They don't appear to
+ // accumulate properly.
+ //
+ // For continuous devices (kCGScrollWheelEventIsContinuous != 0)
+ // -------------------------------------------------------------
+ //
+ // kCGScrollWheelEventDeltaAxis*
+ // This provides values with no acceleration. With a trackpad, these values
+ // are chunked but each non-zero value does not appear to be cumulative.
+ // This seems to be a bug.
+ //
+ // kCGScrollWheelEventPointDeltaAxis*
+ // This provides values with acceleration. With a trackpad, these values are
+ // not chunked and are highly accurate.
+ //
+ // kCGScrollWheelEventFixedPtDeltaAxis*
+ // This provides values with acceleration. With a trackpad, these values are
+ // chunked but unlike Delta events are properly cumulative.
+ //
+ // Summary
+ // -------
+ //
+ // In general the best approach to take is: determine if the event is
+ // continuous. If it is not, then use the FixedPtDelta events (or just stick
+ // with Cocoa events). They provide both acceleration and proper horizontal
+ // scrolling. If the event is continuous, then doing pixel scrolling with the
+ // PointDelta is the way to go. In general, avoid the Delta events. They're
+ // the oldest (dating back to 10.4, before CGEvents were public) but they lack
+ // acceleration and precision, making them useful only in specific edge cases.
+ //
+ // References
+ // ----------
+ //
+ // [1] <http://developer.apple.com/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html>
+ // [2] <http://developer.apple.com/releasenotes/Cocoa/AppKitOlderNotes.html>
+ // Scroll to the section headed "NSScrollWheel events".
+ //
+ // P.S. The "smooth scrolling" option in the system preferences is utterly
+ // unrelated to any of this.
+
+ CGEventRef cgEvent = [event CGEvent];
+ ASSERT(cgEvent);
+
+ // Wheel ticks are supposed to be raw, unaccelerated values, one per physical
+ // mouse wheel notch. The delta event is perfect for this (being a good
+ // "specific edge case" as mentioned above). Trackpads, unfortunately, do
+ // event chunking, and sending mousewheel events with 0 ticks causes some
+ // websites to malfunction. Therefore, for all continuous input devices we use
+ // the point delta data instead, since we cannot distinguish trackpad data
+ // from data from any other continuous device.
+
+ if (CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventIsContinuous)) {
+ result.wheelTicksY = result.deltaY =
+ CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis1);
+ result.wheelTicksX = result.deltaX =
+ CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventPointDeltaAxis2);
+ } else {
+ result.wheelTicksY =
+ CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis1);
+ result.wheelTicksX =
+ CGEventGetIntegerValueField(cgEvent, kCGScrollWheelEventDeltaAxis2);
+
+ // Convert wheel delta amount to a number of pixels to scroll.
+ static const double scrollbarPixelsPerCocoaTick = 40.0;
+
+ result.deltaX = [event deltaX] * scrollbarPixelsPerCocoaTick;
+ result.deltaY = [event deltaY] * scrollbarPixelsPerCocoaTick;
+ }
+
+ result.timeStampSeconds = [event timestamp];
+
+ return result;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/mac/WebScreenInfoFactory.mm b/WebKit/chromium/src/mac/WebScreenInfoFactory.mm
new file mode 100644
index 0000000..2805f7a
--- /dev/null
+++ b/WebKit/chromium/src/mac/WebScreenInfoFactory.mm
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebScreenInfoFactory.h"
+
+#import <AppKit/AppKit.h>
+
+#include "WebScreenInfo.h"
+
+namespace WebKit {
+
+static NSScreen* screenForWindow(NSWindow* window)
+{
+ NSScreen* screen = [window screen]; // nil if the window is off-screen
+ if (screen)
+ return screen;
+
+ NSArray* screens = [NSScreen screens];
+ if ([screens count] > 0)
+ return [screens objectAtIndex:0]; // screen containing the menubar
+
+ return nil;
+}
+
+static WebRect toUserSpace(const NSRect& rect, NSWindow* destination)
+{
+ CGRect userRect = NSRectToCGRect(rect);
+
+ userRect.origin.y =
+ NSMaxY([screenForWindow(destination) frame]) - (userRect.origin.y + userRect.size.height); // flip
+
+ if (destination) {
+ CGFloat scale = 1 / [destination userSpaceScaleFactor]; // scale down
+ userRect.origin.x *= scale;
+ userRect.origin.y *= scale;
+ userRect.size.width *= scale;
+ userRect.size.height *= scale;
+ }
+
+ return WebRect(userRect.origin.x,
+ userRect.origin.y,
+ userRect.size.width,
+ userRect.size.height);
+}
+
+WebScreenInfo WebScreenInfoFactory::screenInfo(NSView* view)
+{
+ NSString *colorSpace = NSColorSpaceFromDepth([[NSScreen deepestScreen] depth]);
+
+ WebScreenInfo results;
+ results.depth =
+ NSBitsPerPixelFromDepth([[NSScreen deepestScreen] depth]);
+ results.depthPerComponent =
+ NSBitsPerSampleFromDepth([[NSScreen deepestScreen] depth]);
+ results.isMonochrome = colorSpace == NSCalibratedWhiteColorSpace
+ || colorSpace == NSCalibratedBlackColorSpace
+ || colorSpace == NSDeviceWhiteColorSpace
+ || colorSpace == NSDeviceBlackColorSpace;
+ results.rect =
+ toUserSpace([screenForWindow([view window]) frame], [view window]);
+ results.availableRect =
+ toUserSpace([screenForWindow([view window]) visibleFrame], [view window]);
+ return results;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/win/WebInputEventFactory.cpp b/WebKit/chromium/src/win/WebInputEventFactory.cpp
new file mode 100644
index 0000000..a5bd935
--- /dev/null
+++ b/WebKit/chromium/src/win/WebInputEventFactory.cpp
@@ -0,0 +1,437 @@
+/*
+ * Copyright (C) 2006-2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebInputEventFactory.h"
+
+#include "WebInputEvent.h"
+
+#include <wtf/Assertions.h>
+
+namespace WebKit {
+
+static const unsigned long defaultScrollLinesPerWheelDelta = 3;
+static const unsigned long defaultScrollCharsPerWheelDelta = 1;
+
+// WebKeyboardEvent -----------------------------------------------------------
+
+static bool isKeyPad(WPARAM wparam, LPARAM lparam)
+{
+ bool keypad = false;
+ switch (wparam) {
+ case VK_RETURN:
+ keypad = (lparam >> 16) & KF_EXTENDED;
+ break;
+ case VK_INSERT:
+ case VK_DELETE:
+ case VK_HOME:
+ case VK_END:
+ case VK_PRIOR:
+ case VK_NEXT:
+ case VK_UP:
+ case VK_DOWN:
+ case VK_LEFT:
+ case VK_RIGHT:
+ keypad = !((lparam >> 16) & KF_EXTENDED);
+ break;
+ case VK_NUMLOCK:
+ case VK_NUMPAD0:
+ case VK_NUMPAD1:
+ case VK_NUMPAD2:
+ case VK_NUMPAD3:
+ case VK_NUMPAD4:
+ case VK_NUMPAD5:
+ case VK_NUMPAD6:
+ case VK_NUMPAD7:
+ case VK_NUMPAD8:
+ case VK_NUMPAD9:
+ case VK_DIVIDE:
+ case VK_MULTIPLY:
+ case VK_SUBTRACT:
+ case VK_ADD:
+ case VK_DECIMAL:
+ case VK_CLEAR:
+ keypad = true;
+ break;
+ default:
+ keypad = false;
+ }
+ return keypad;
+}
+
+WebKeyboardEvent WebInputEventFactory::keyboardEvent(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam)
+{
+ WebKeyboardEvent result;
+
+ // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that
+ // GetMessageTime() refers to is the same one that we're passed in? Perhaps
+ // one of the construction parameters should be the time passed by the
+ // caller, who would know for sure.
+ result.timeStampSeconds = GetMessageTime() / 1000.0;
+
+ result.windowsKeyCode = result.nativeKeyCode = static_cast<int>(wparam);
+
+ switch (message) {
+ case WM_SYSKEYDOWN:
+ result.isSystemKey = true;
+ case WM_KEYDOWN:
+ result.type = WebInputEvent::RawKeyDown;
+ break;
+ case WM_SYSKEYUP:
+ result.isSystemKey = true;
+ case WM_KEYUP:
+ result.type = WebInputEvent::KeyUp;
+ break;
+ case WM_IME_CHAR:
+ result.type = WebInputEvent::Char;
+ break;
+ case WM_SYSCHAR:
+ result.isSystemKey = true;
+ result.type = WebInputEvent::Char;
+ case WM_CHAR:
+ result.type = WebInputEvent::Char;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ if (result.type == WebInputEvent::Char || result.type == WebInputEvent::RawKeyDown) {
+ result.text[0] = result.windowsKeyCode;
+ result.unmodifiedText[0] = result.windowsKeyCode;
+ }
+ if (result.type != WebInputEvent::Char)
+ result.setKeyIdentifierFromWindowsKeyCode();
+
+ if (GetKeyState(VK_SHIFT) & 0x8000)
+ result.modifiers |= WebInputEvent::ShiftKey;
+ if (GetKeyState(VK_CONTROL) & 0x8000)
+ result.modifiers |= WebInputEvent::ControlKey;
+ if (GetKeyState(VK_MENU) & 0x8000)
+ result.modifiers |= WebInputEvent::AltKey;
+ // NOTE: There doesn't seem to be a way to query the mouse button state in
+ // this case.
+
+ if (LOWORD(lparam) > 1)
+ result.modifiers |= WebInputEvent::IsAutoRepeat;
+ if (isKeyPad(wparam, lparam))
+ result.modifiers |= WebInputEvent::IsKeyPad;
+
+ return result;
+}
+
+// WebMouseEvent --------------------------------------------------------------
+
+static int gLastClickCount;
+static double gLastClickTime;
+
+static LPARAM GetRelativeCursorPos(HWND hwnd)
+{
+ POINT pos = {-1, -1};
+ GetCursorPos(&pos);
+ ScreenToClient(hwnd, &pos);
+ return MAKELPARAM(pos.x, pos.y);
+}
+
+void WebInputEventFactory::resetLastClickState()
+{
+ gLastClickTime = gLastClickCount = 0;
+}
+
+WebMouseEvent WebInputEventFactory::mouseEvent(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam)
+{
+ WebMouseEvent result; //(WebInputEvent::Uninitialized());
+
+ switch (message) {
+ case WM_MOUSEMOVE:
+ result.type = WebInputEvent::MouseMove;
+ if (wparam & MK_LBUTTON)
+ result.button = WebMouseEvent::ButtonLeft;
+ else if (wparam & MK_MBUTTON)
+ result.button = WebMouseEvent::ButtonMiddle;
+ else if (wparam & MK_RBUTTON)
+ result.button = WebMouseEvent::ButtonRight;
+ else
+ result.button = WebMouseEvent::ButtonNone;
+ break;
+ case WM_MOUSELEAVE:
+ result.type = WebInputEvent::MouseLeave;
+ result.button = WebMouseEvent::ButtonNone;
+ // set the current mouse position (relative to the client area of the
+ // current window) since none is specified for this event
+ lparam = GetRelativeCursorPos(hwnd);
+ break;
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ result.type = WebInputEvent::MouseDown;
+ result.button = WebMouseEvent::ButtonLeft;
+ break;
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONDBLCLK:
+ result.type = WebInputEvent::MouseDown;
+ result.button = WebMouseEvent::ButtonMiddle;
+ break;
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONDBLCLK:
+ result.type = WebInputEvent::MouseDown;
+ result.button = WebMouseEvent::ButtonRight;
+ break;
+ case WM_LBUTTONUP:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonLeft;
+ break;
+ case WM_MBUTTONUP:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonMiddle;
+ break;
+ case WM_RBUTTONUP:
+ result.type = WebInputEvent::MouseUp;
+ result.button = WebMouseEvent::ButtonRight;
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that
+ // GetMessageTime() refers to is the same one that we're passed in? Perhaps
+ // one of the construction parameters should be the time passed by the
+ // caller, who would know for sure.
+ result.timeStampSeconds = GetMessageTime() / 1000.0;
+
+ // set position fields:
+
+ result.x = static_cast<short>(LOWORD(lparam));
+ result.y = static_cast<short>(HIWORD(lparam));
+ result.windowX = result.x;
+ result.windowY = result.y;
+
+ POINT globalPoint = { result.x, result.y };
+ ClientToScreen(hwnd, &globalPoint);
+
+ result.globalX = globalPoint.x;
+ result.globalY = globalPoint.y;
+
+ // calculate number of clicks:
+
+ // This differs slightly from the WebKit code in WebKit/win/WebView.cpp
+ // where their original code looks buggy.
+ static int lastClickPositionX;
+ static int lastClickPositionY;
+ static WebMouseEvent::Button lastClickButton = WebMouseEvent::ButtonLeft;
+
+ double currentTime = result.timeStampSeconds;
+ bool cancelPreviousClick =
+ (abs(lastClickPositionX - result.x) > (GetSystemMetrics(SM_CXDOUBLECLK) / 2))
+ || (abs(lastClickPositionY - result.y) > (GetSystemMetrics(SM_CYDOUBLECLK) / 2))
+ || ((currentTime - gLastClickTime) * 1000.0 > GetDoubleClickTime());
+
+ if (result.type == WebInputEvent::MouseDown) {
+ if (!cancelPreviousClick && (result.button == lastClickButton))
+ ++gLastClickCount;
+ else {
+ gLastClickCount = 1;
+ lastClickPositionX = result.x;
+ lastClickPositionY = result.y;
+ }
+ gLastClickTime = currentTime;
+ lastClickButton = result.button;
+ } else if (result.type == WebInputEvent::MouseMove
+ || result.type == WebInputEvent::MouseLeave) {
+ if (cancelPreviousClick) {
+ gLastClickCount = 0;
+ lastClickPositionX = 0;
+ lastClickPositionY = 0;
+ gLastClickTime = 0;
+ }
+ }
+ result.clickCount = gLastClickCount;
+
+ // set modifiers:
+
+ if (wparam & MK_CONTROL)
+ result.modifiers |= WebInputEvent::ControlKey;
+ if (wparam & MK_SHIFT)
+ result.modifiers |= WebInputEvent::ShiftKey;
+ if (GetKeyState(VK_MENU) & 0x8000)
+ result.modifiers |= WebInputEvent::AltKey;
+ if (wparam & MK_LBUTTON)
+ result.modifiers |= WebInputEvent::LeftButtonDown;
+ if (wparam & MK_MBUTTON)
+ result.modifiers |= WebInputEvent::MiddleButtonDown;
+ if (wparam & MK_RBUTTON)
+ result.modifiers |= WebInputEvent::RightButtonDown;
+
+ return result;
+}
+
+// WebMouseWheelEvent ---------------------------------------------------------
+
+WebMouseWheelEvent WebInputEventFactory::mouseWheelEvent(HWND hwnd, UINT message,
+ WPARAM wparam, LPARAM lparam)
+{
+ WebMouseWheelEvent result; //(WebInputEvent::Uninitialized());
+
+ result.type = WebInputEvent::MouseWheel;
+
+ // TODO(pkasting): http://b/1117926 Are we guaranteed that the message that
+ // GetMessageTime() refers to is the same one that we're passed in? Perhaps
+ // one of the construction parameters should be the time passed by the
+ // caller, who would know for sure.
+ result.timeStampSeconds = GetMessageTime() / 1000.0;
+
+ result.button = WebMouseEvent::ButtonNone;
+
+ // Get key state, coordinates, and wheel delta from event.
+ typedef SHORT (WINAPI *GetKeyStateFunction)(int key);
+ GetKeyStateFunction getKeyState;
+ UINT keyState;
+ float wheelDelta;
+ bool horizontalScroll = false;
+ if ((message == WM_VSCROLL) || (message == WM_HSCROLL)) {
+ // Synthesize mousewheel event from a scroll event. This is needed to
+ // simulate middle mouse scrolling in some laptops. Use GetAsyncKeyState
+ // for key state since we are synthesizing the input event.
+ getKeyState = GetAsyncKeyState;
+ keyState = 0;
+ if (getKeyState(VK_SHIFT))
+ keyState |= MK_SHIFT;
+ if (getKeyState(VK_CONTROL))
+ keyState |= MK_CONTROL;
+ // NOTE: There doesn't seem to be a way to query the mouse button state
+ // in this case.
+
+ POINT cursorPosition = {0};
+ GetCursorPos(&cursorPosition);
+ result.globalX = cursorPosition.x;
+ result.globalY = cursorPosition.y;
+
+ switch (LOWORD(wparam)) {
+ case SB_LINEUP: // == SB_LINELEFT
+ wheelDelta = WHEEL_DELTA;
+ break;
+ case SB_LINEDOWN: // == SB_LINERIGHT
+ wheelDelta = -WHEEL_DELTA;
+ break;
+ case SB_PAGEUP:
+ wheelDelta = 1;
+ result.scrollByPage = true;
+ break;
+ case SB_PAGEDOWN:
+ wheelDelta = -1;
+ result.scrollByPage = true;
+ break;
+ default: // We don't supoprt SB_THUMBPOSITION or SB_THUMBTRACK here.
+ wheelDelta = 0;
+ break;
+ }
+
+ if (message == WM_HSCROLL)
+ horizontalScroll = true;
+ } else {
+ // Non-synthesized event; we can just read data off the event.
+ getKeyState = GetKeyState;
+ keyState = GET_KEYSTATE_WPARAM(wparam);
+
+ result.globalX = static_cast<short>(LOWORD(lparam));
+ result.globalY = static_cast<short>(HIWORD(lparam));
+
+ wheelDelta = static_cast<float>(GET_WHEEL_DELTA_WPARAM(wparam));
+ if (message == WM_MOUSEHWHEEL) {
+ horizontalScroll = true;
+ wheelDelta = -wheelDelta; // Windows is <- -/+ ->, WebKit <- +/- ->.
+ }
+ }
+ if (keyState & MK_SHIFT)
+ horizontalScroll = true;
+
+ // Set modifiers based on key state.
+ if (keyState & MK_SHIFT)
+ result.modifiers |= WebInputEvent::ShiftKey;
+ if (keyState & MK_CONTROL)
+ result.modifiers |= WebInputEvent::ControlKey;
+ if (getKeyState(VK_MENU) & 0x8000)
+ result.modifiers |= WebInputEvent::AltKey;
+ if (keyState & MK_LBUTTON)
+ result.modifiers |= WebInputEvent::LeftButtonDown;
+ if (keyState & MK_MBUTTON)
+ result.modifiers |= WebInputEvent::MiddleButtonDown;
+ if (keyState & MK_RBUTTON)
+ result.modifiers |= WebInputEvent::RightButtonDown;
+
+ // Set coordinates by translating event coordinates from screen to client.
+ POINT clientPoint = { result.globalX, result.globalY };
+ MapWindowPoints(0, hwnd, &clientPoint, 1);
+ result.x = clientPoint.x;
+ result.y = clientPoint.y;
+ result.windowX = result.x;
+ result.windowY = result.y;
+
+ // Convert wheel delta amount to a number of pixels to scroll.
+ //
+ // How many pixels should we scroll per line? Gecko uses the height of the
+ // current line, which means scroll distance changes as you go through the
+ // page or go to different pages. IE 7 is ~50 px/line, although the value
+ // seems to vary slightly by page and zoom level. Since IE 7 has a smoothing
+ // algorithm on scrolling, it can get away with slightly larger scroll values
+ // without feeling jerky. Here we use 100 px per three lines (the default
+ // scroll amount is three lines per wheel tick).
+ static const float scrollbarPixelsPerLine = 100.0f / 3.0f;
+ wheelDelta /= WHEEL_DELTA;
+ float scrollDelta = wheelDelta;
+ if (horizontalScroll) {
+ unsigned long scrollChars = defaultScrollCharsPerWheelDelta;
+ SystemParametersInfo(SPI_GETWHEELSCROLLCHARS, 0, &scrollChars, 0);
+ // TODO(pkasting): Should probably have a different multiplier
+ // scrollbarPixelsPerChar here.
+ scrollDelta *= static_cast<float>(scrollChars) * scrollbarPixelsPerLine;
+ } else {
+ unsigned long scrollLines = defaultScrollLinesPerWheelDelta;
+ SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
+ if (scrollLines == WHEEL_PAGESCROLL)
+ result.scrollByPage = true;
+ if (!result.scrollByPage)
+ scrollDelta *= static_cast<float>(scrollLines) * scrollbarPixelsPerLine;
+ }
+
+ // Set scroll amount based on above calculations. WebKit expects positive
+ // deltaY to mean "scroll up" and positive deltaX to mean "scroll left".
+ if (horizontalScroll) {
+ result.deltaX = scrollDelta;
+ result.wheelTicksX = wheelDelta;
+ } else {
+ result.deltaY = scrollDelta;
+ result.wheelTicksY = wheelDelta;
+ }
+
+ return result;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/win/WebScreenInfoFactory.cpp b/WebKit/chromium/src/win/WebScreenInfoFactory.cpp
new file mode 100644
index 0000000..8416acc
--- /dev/null
+++ b/WebKit/chromium/src/win/WebScreenInfoFactory.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebScreenInfoFactory.h"
+
+#include "WebScreenInfo.h"
+
+#include <windows.h>
+
+namespace WebKit {
+
+static WebRect toWebRect(const RECT& input)
+{
+ WebRect output;
+ output.x = input.left;
+ output.y = input.top;
+ output.width = input.right - input.left;
+ output.height = input.bottom - input.top;
+ return output;
+}
+
+WebScreenInfo WebScreenInfoFactory::screenInfo(HWND window)
+{
+ HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
+
+ MONITORINFOEX monitorInfo;
+ monitorInfo.cbSize = sizeof(MONITORINFOEX);
+ GetMonitorInfo(monitor, &monitorInfo);
+
+ DEVMODE devMode;
+ devMode.dmSize = sizeof(devMode);
+ devMode.dmDriverExtra = 0;
+ EnumDisplaySettings(monitorInfo.szDevice, ENUM_CURRENT_SETTINGS, &devMode);
+
+ WebScreenInfo results;
+ results.depth = devMode.dmBitsPerPel;
+ results.depthPerComponent = devMode.dmBitsPerPel / 3; // Assumes RGB
+ results.isMonochrome = devMode.dmColor == DMCOLOR_MONOCHROME;
+ results.rect = toWebRect(monitorInfo.rcMonitor);
+ results.availableRect = toWebRect(monitorInfo.rcWork);
+ return results;
+}
+
+} // namespace WebKit
diff --git a/WebKit/chromium/src/x11/WebScreenInfoFactory.cpp b/WebKit/chromium/src/x11/WebScreenInfoFactory.cpp
new file mode 100644
index 0000000..548880c
--- /dev/null
+++ b/WebKit/chromium/src/x11/WebScreenInfoFactory.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebScreenInfoFactory.h"
+
+#include "WebScreenInfo.h"
+
+#include <X11/Xlib.h>
+
+namespace WebKit {
+
+WebScreenInfo WebScreenInfoFactory::screenInfo(Display* display, int screenNumber)
+{
+ WebScreenInfo results;
+ // FIXME: not all screens with use 8bpp.
+ results.depthPerComponent = 8;
+
+ int displayWidth = XDisplayWidth(display, screenNumber);
+ int displayHeight = XDisplayHeight(display, screenNumber);
+ results.depth = XDisplayPlanes(display, screenNumber);
+ results.isMonochrome = results.depth == 1;
+
+ results.rect = WebRect(0, 0, displayWidth, displayHeight);
+
+ // I don't know of a way to query the "maximize" size of the window (e.g.
+ // screen size less sidebars etc) since this is something which only the
+ // window manager knows.
+ results.availableRect = results.rect;
+
+ return results;
+}
+
+} // namespace WebKit
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list