summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 06:51:01 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-14 06:51:01 +0000
commitc772bf6640208a3251cd6929ba492238ff9a6b23 (patch)
tree9c2eb474616ee13f6b802b52678986d91659fe30 /webkit
parent501677d56876d24ff29ec31a18563b7801a2c28d (diff)
downloadchromium_src-c772bf6640208a3251cd6929ba492238ff9a6b23.zip
chromium_src-c772bf6640208a3251cd6929ba492238ff9a6b23.tar.gz
chromium_src-c772bf6640208a3251cd6929ba492238ff9a6b23.tar.bz2
Move glue/event_conversion.{h,cc} into the WebKit API implementation.
I also renamed the MakeFoo classes to FooBuilder so that it would be more clear at the call sites that you are dealing with a class. I then translated the ToBar functions to also be BarBuilder classes. I just did this for consistency with the FooBuilders. For reference, "Foo" refers to WebCore Platform*Event classes and "Bar" refers to WebInputEvent subclasses :-) R=jorlow BUG=none TEST=none Review URL: http://codereview.chromium.org/164524 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23425 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/api/src/WebInputEventConversion.cpp248
-rw-r--r--webkit/api/src/WebInputEventConversion.h95
-rw-r--r--webkit/glue/event_conversion.cc239
-rw-r--r--webkit/glue/event_conversion.h67
-rw-r--r--webkit/glue/webkit_glue.cc1
-rw-r--r--webkit/glue/webplugin_impl.cc12
-rw-r--r--webkit/glue/webpopupmenu_impl.cc17
-rw-r--r--webkit/glue/webview_impl.cc30
-rw-r--r--webkit/tools/test_shell/keyboard_unittest.cc7
-rw-r--r--webkit/webkit.gyp4
10 files changed, 383 insertions, 337 deletions
diff --git a/webkit/api/src/WebInputEventConversion.cpp b/webkit/api/src/WebInputEventConversion.cpp
new file mode 100644
index 0000000..1a66c6e
--- /dev/null
+++ b/webkit/api/src/WebInputEventConversion.cpp
@@ -0,0 +1,248 @@
+/*
+ * 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 "WebInputEventConversion.h"
+
+#include "WebInputEvent.h"
+
+#include "EventNames.h"
+#include "KeyboardCodes.h"
+#include "KeyboardEvent.h"
+#include "MouseEvent.h"
+#include "PlatformKeyboardEvent.h"
+#include "PlatformMouseEvent.h"
+#include "PlatformWheelEvent.h"
+#include "ScrollView.h"
+#include "Widget.h"
+
+using namespace WebCore;
+
+namespace WebKit {
+
+// MakePlatformMouseEvent -----------------------------------------------------
+
+PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMouseEvent& e)
+{
+ // FIXME: widget is always toplevel, unless it's a popup. We may be able
+ // to get rid of this once we abstract popups into a WebKit API.
+ m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y));
+ m_globalPosition = IntPoint(e.globalX, e.globalY);
+ m_button = static_cast<MouseButton>(e.button);
+ m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
+ m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
+ m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
+ m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
+ m_modifierFlags = e.modifiers;
+ m_timestamp = e.timeStampSeconds;
+ m_clickCount = e.clickCount;
+
+ switch (e.type) {
+ case WebInputEvent::MouseMove:
+ case WebInputEvent::MouseLeave: // synthesize a move event
+ m_eventType = MouseEventMoved;
+ break;
+
+ case WebInputEvent::MouseDown:
+ m_eventType = MouseEventPressed;
+ break;
+
+ case WebInputEvent::MouseUp:
+ m_eventType = MouseEventReleased;
+ break;
+
+ default:
+ ASSERT_NOT_REACHED();
+ }
+}
+
+// PlatformWheelEventBuilder --------------------------------------------------
+
+PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMouseWheelEvent& e)
+{
+ m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y));
+ m_globalPosition = IntPoint(e.globalX, e.globalY);
+ m_deltaX = e.deltaX;
+ m_deltaY = e.deltaY;
+ m_wheelTicksX = e.wheelTicksX;
+ m_wheelTicksY = e.wheelTicksY;
+ m_isAccepted = false;
+ m_granularity = e.scrollByPage ?
+ ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
+ m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
+ m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
+ m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
+ m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
+}
+
+// MakePlatformKeyboardEvent --------------------------------------------------
+
+static inline const PlatformKeyboardEvent::Type toPlatformKeyboardEventType(WebInputEvent::Type type)
+{
+ switch (type) {
+ case WebInputEvent::KeyUp:
+ return PlatformKeyboardEvent::KeyUp;
+ case WebInputEvent::KeyDown:
+ return PlatformKeyboardEvent::KeyDown;
+ case WebInputEvent::RawKeyDown:
+ return PlatformKeyboardEvent::RawKeyDown;
+ case WebInputEvent::Char:
+ return PlatformKeyboardEvent::Char;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+ return PlatformKeyboardEvent::KeyDown;
+}
+
+PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder(const WebKeyboardEvent& e)
+{
+ m_type = toPlatformKeyboardEventType(e.type);
+ m_text = String(e.text);
+ m_unmodifiedText = String(e.unmodifiedText);
+ m_keyIdentifier = String(e.keyIdentifier);
+ m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat) != 0;
+ m_windowsVirtualKeyCode = e.windowsKeyCode;
+ m_nativeVirtualKeyCode = e.nativeKeyCode;
+ m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad) != 0;
+ m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
+ m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
+ m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
+ m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
+ m_isSystemKey = e.isSystemKey;
+}
+
+void PlatformKeyboardEventBuilder::setKeyType(Type type)
+{
+ // According to the behavior of Webkit in Windows platform,
+ // we need to convert KeyDown to RawKeydown and Char events
+ // See WebKit/WebKit/Win/WebView.cpp
+ ASSERT(m_type == KeyDown);
+ ASSERT(type == RawKeyDown || type == Char);
+ m_type = type;
+
+ if (type == RawKeyDown) {
+ m_text = String();
+ m_unmodifiedText = String();
+ } else {
+ m_keyIdentifier = String();
+ m_windowsVirtualKeyCode = 0;
+ }
+}
+
+// Please refer to bug http://b/issue?id=961192, which talks about Webkit
+// keyboard event handling changes. It also mentions the list of keys
+// which don't have associated character events.
+bool PlatformKeyboardEventBuilder::isCharacterKey() const
+{
+ switch (windowsVirtualKeyCode()) {
+ case VKEY_BACK:
+ case VKEY_ESCAPE:
+ return false;
+ }
+ return true;
+}
+
+static int getWebInputModifiers(const UIEventWithKeyState& event)
+{
+ int modifiers = 0;
+ if (event.ctrlKey())
+ modifiers |= WebInputEvent::ControlKey;
+ if (event.shiftKey())
+ modifiers |= WebInputEvent::ShiftKey;
+ if (event.altKey())
+ modifiers |= WebInputEvent::AltKey;
+ if (event.metaKey())
+ modifiers |= WebInputEvent::MetaKey;
+ return modifiers;
+}
+
+WebMouseEventBuilder::WebMouseEventBuilder(const ScrollView* view, const MouseEvent& event)
+{
+ if (event.type() == eventNames().mousemoveEvent)
+ type = WebInputEvent::MouseMove;
+ else if (event.type() == eventNames().mouseoutEvent)
+ type = WebInputEvent::MouseLeave;
+ else if (event.type() == eventNames().mouseoverEvent)
+ type = WebInputEvent::MouseEnter;
+ else if (event.type() == eventNames().mousedownEvent)
+ type = WebInputEvent::MouseDown;
+ else if (event.type() == eventNames().mouseupEvent)
+ type = WebInputEvent::MouseUp;
+ else
+ return; // Skip all other mouse events.
+ timeStampSeconds = event.timeStamp() * 1.0e-3;
+ switch (event.button()) {
+ case LeftButton:
+ button = WebMouseEvent::ButtonLeft;
+ break;
+ case MiddleButton:
+ button = WebMouseEvent::ButtonMiddle;
+ break;
+ case RightButton:
+ button = WebMouseEvent::ButtonRight;
+ break;
+ }
+ modifiers = getWebInputModifiers(event);
+ if (event.buttonDown()) {
+ switch (event.button()) {
+ case LeftButton:
+ modifiers |= WebInputEvent::LeftButtonDown;
+ break;
+ case MiddleButton:
+ modifiers |= WebInputEvent::MiddleButtonDown;
+ break;
+ case RightButton:
+ modifiers |= WebInputEvent::RightButtonDown;
+ break;
+ }
+ }
+ IntPoint p = view->contentsToWindow(IntPoint(event.pageX(), event.pageY()));
+ globalX = event.screenX();
+ globalY = event.screenY();
+ windowX = p.x();
+ windowY = p.y();
+ x = event.offsetX();
+ y = event.offsetY();
+}
+
+WebKeyboardEventBuilder::WebKeyboardEventBuilder(const KeyboardEvent& event) {
+ if (event.type() == eventNames().keydownEvent)
+ type = KeyDown;
+ else if (event.type() == eventNames().keyupEvent)
+ type = WebInputEvent::KeyUp;
+ else
+ return; // Skip all other keyboard events.
+ modifiers = getWebInputModifiers(event);
+ timeStampSeconds = event.timeStamp() * 1.0e-3;
+ windowsKeyCode = event.keyCode();
+ nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode();
+}
+
+} // namespace WebKit
diff --git a/webkit/api/src/WebInputEventConversion.h b/webkit/api/src/WebInputEventConversion.h
new file mode 100644
index 0000000..aaea581
--- /dev/null
+++ b/webkit/api/src/WebInputEventConversion.h
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#ifndef WebInputEventConversion_h
+#define WebInputEventConversion_h
+
+// FIXME: This relative path is a temporary hack to support using this
+// header from webkit/glue.
+#include "../public/WebInputEvent.h"
+
+#include "PlatformKeyboardEvent.h"
+#include "PlatformMouseEvent.h"
+#include "PlatformWheelEvent.h"
+
+namespace WebCore {
+ class KeyboardEvent;
+ class MouseEvent;
+ class ScrollView;
+ class Widget;
+}
+
+namespace WebKit {
+ class WebMouseEvent;
+ class WebMouseWheelEvent;
+ class WebKeyboardEvent;
+
+ // These classes are used to convert from WebInputEvent subclasses to
+ // corresponding WebCore events.
+
+ class PlatformMouseEventBuilder : public WebCore::PlatformMouseEvent {
+ public:
+ PlatformMouseEventBuilder(WebCore::Widget*, const WebMouseEvent&);
+ };
+
+ class PlatformWheelEventBuilder : public WebCore::PlatformWheelEvent {
+ public:
+ PlatformWheelEventBuilder(WebCore::Widget*, const WebMouseWheelEvent&);
+ };
+
+ class PlatformKeyboardEventBuilder : public WebCore::PlatformKeyboardEvent {
+ public:
+ PlatformKeyboardEventBuilder(const WebKeyboardEvent&);
+ void setKeyType(Type);
+ bool isCharacterKey() const;
+ };
+
+ // Converts a WebCore::MouseEvent to a corresponding WebMouseEvent. view is
+ // the ScrollView corresponding to the event. Returns true if successful.
+ // NOTE: This is only implemented for mousemove, mouseover, mouseout,
+ // mousedown and mouseup. If the event mapping fails, the event type will
+ // be set to Undefined.
+ class WebMouseEventBuilder : public WebMouseEvent {
+ public:
+ WebMouseEventBuilder(const WebCore::ScrollView*, const WebCore::MouseEvent&);
+ };
+
+ // Converts a WebCore::KeyboardEvent to a corresponding WebKeyboardEvent.
+ // Returns true if successful. NOTE: This is only implemented for keydown
+ // and keyup. If the event mapping fails, the event type will be set to
+ // Undefined.
+ class WebKeyboardEventBuilder : public WebKeyboardEvent {
+ public:
+ WebKeyboardEventBuilder(const WebCore::KeyboardEvent&);
+ };
+
+} // namespace WebKit
+
+#endif
diff --git a/webkit/glue/event_conversion.cc b/webkit/glue/event_conversion.cc
deleted file mode 100644
index 461063f..0000000
--- a/webkit/glue/event_conversion.cc
+++ /dev/null
@@ -1,239 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "config.h"
-#include "webkit/glue/event_conversion.h"
-
-#include "EventNames.h"
-#include "FrameView.h"
-#include "KeyboardCodes.h"
-#include "KeyboardEvent.h"
-#include "MouseEvent.h"
-#include "StringImpl.h" // This is so that the KJS build works
-#include "PlatformKeyboardEvent.h"
-#include "PlatformMouseEvent.h"
-#include "PlatformWheelEvent.h"
-#include "Widget.h"
-
-#undef LOG
-#include "base/gfx/point.h"
-#include "base/logging.h"
-#include "webkit/api/public/WebInputEvent.h"
-#include "webkit/api/public/WebKit.h"
-#include "webkit/glue/glue_util.h"
-
-using namespace WebCore;
-
-using WebKit::WebInputEvent;
-using WebKit::WebKeyboardEvent;
-using WebKit::WebMouseEvent;
-using WebKit::WebMouseWheelEvent;
-
-// MakePlatformMouseEvent -----------------------------------------------------
-
-MakePlatformMouseEvent::MakePlatformMouseEvent(Widget* widget,
- const WebMouseEvent& e) {
- // TODO(mpcomplete): widget is always toplevel, unless it's a popup. We
- // may be able to get rid of this once we abstract popups into a WebKit API.
- m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y));
- m_globalPosition = IntPoint(e.globalX, e.globalY);
- m_button = static_cast<MouseButton>(e.button);
- m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
- m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
- m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
- m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
- m_modifierFlags = e.modifiers;
- m_timestamp = e.timeStampSeconds;
- m_clickCount = e.clickCount;
-
- switch (e.type) {
- case WebInputEvent::MouseMove:
- case WebInputEvent::MouseLeave: // synthesize a move event
- m_eventType = MouseEventMoved;
- break;
-
- case WebInputEvent::MouseDown:
- m_eventType = MouseEventPressed;
- break;
-
- case WebInputEvent::MouseUp:
- m_eventType = MouseEventReleased;
- break;
-
- default:
- NOTREACHED() << "unexpected mouse event type";
- }
-}
-
-// MakePlatformWheelEvent -----------------------------------------------------
-
-MakePlatformWheelEvent::MakePlatformWheelEvent(Widget* widget,
- const WebMouseWheelEvent& e) {
- m_position = widget->convertFromContainingWindow(IntPoint(e.x, e.y));
- m_globalPosition = IntPoint(e.globalX, e.globalY);
- m_deltaX = e.deltaX;
- m_deltaY = e.deltaY;
- m_wheelTicksX = e.wheelTicksX;
- m_wheelTicksY = e.wheelTicksY;
- m_isAccepted = false;
- m_granularity = e.scrollByPage ?
- ScrollByPageWheelEvent : ScrollByPixelWheelEvent;
- m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
- m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
- m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
- m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
-}
-
-// MakePlatformKeyboardEvent --------------------------------------------------
-
-static inline const PlatformKeyboardEvent::Type ToPlatformKeyboardEventType(
- WebInputEvent::Type type) {
- switch (type) {
- case WebInputEvent::KeyUp:
- return PlatformKeyboardEvent::KeyUp;
- case WebInputEvent::KeyDown:
- return PlatformKeyboardEvent::KeyDown;
- case WebInputEvent::RawKeyDown:
- return PlatformKeyboardEvent::RawKeyDown;
- case WebInputEvent::Char:
- return PlatformKeyboardEvent::Char;
- default:
- ASSERT_NOT_REACHED();
- }
- return PlatformKeyboardEvent::KeyDown;
-}
-
-MakePlatformKeyboardEvent::MakePlatformKeyboardEvent(
- const WebKeyboardEvent& e) {
- m_type = ToPlatformKeyboardEventType(e.type);
- m_text = WebCore::String(e.text);
- m_unmodifiedText = WebCore::String(e.unmodifiedText);
- m_keyIdentifier = WebCore::String(e.keyIdentifier);
- m_autoRepeat = (e.modifiers & WebInputEvent::IsAutoRepeat) != 0;
- m_windowsVirtualKeyCode = e.windowsKeyCode;
- m_nativeVirtualKeyCode = e.nativeKeyCode;
- m_isKeypad = (e.modifiers & WebInputEvent::IsKeyPad) != 0;
- m_shiftKey = (e.modifiers & WebInputEvent::ShiftKey) != 0;
- m_ctrlKey = (e.modifiers & WebInputEvent::ControlKey) != 0;
- m_altKey = (e.modifiers & WebInputEvent::AltKey) != 0;
- m_metaKey = (e.modifiers & WebInputEvent::MetaKey) != 0;
- m_isSystemKey = e.isSystemKey;
-}
-
-void MakePlatformKeyboardEvent::SetKeyType(Type type) {
- // According to the behavior of Webkit in Windows platform,
- // we need to convert KeyDown to RawKeydown and Char events
- // See WebKit/WebKit/Win/WebView.cpp
- ASSERT(m_type == KeyDown);
- ASSERT(type == RawKeyDown || type == Char);
- m_type = type;
-
- if (type == RawKeyDown) {
- m_text = String();
- m_unmodifiedText = String();
- } else {
- m_keyIdentifier = String();
- m_windowsVirtualKeyCode = 0;
- }
-}
-
-// Please refer to bug http://b/issue?id=961192, which talks about Webkit
-// keyboard event handling changes. It also mentions the list of keys
-// which don't have associated character events.
-bool MakePlatformKeyboardEvent::IsCharacterKey() const {
- switch (windowsVirtualKeyCode()) {
- case VKEY_BACK:
- case VKEY_ESCAPE:
- return false;
-
- default:
- break;
- }
- return true;
-}
-
-static int GetWebInputModifiers(const WebCore::UIEventWithKeyState& event) {
- int modifiers = 0;
- if (event.ctrlKey())
- modifiers |= WebInputEvent::ControlKey;
- if (event.shiftKey())
- modifiers |= WebInputEvent::ShiftKey;
- if (event.altKey())
- modifiers |= WebInputEvent::AltKey;
- if (event.metaKey())
- modifiers |= WebInputEvent::MetaKey;
- return modifiers;
-}
-
-
-bool ToWebMouseEvent(const WebCore::FrameView& view,
- const WebCore::MouseEvent& event,
- WebKit::WebMouseEvent* web_event) {
- if (event.type() == WebCore::eventNames().mousemoveEvent) {
- web_event->type = WebInputEvent::MouseMove;
- } else if (event.type() == WebCore::eventNames().mouseoutEvent) {
- web_event->type = WebInputEvent::MouseLeave;
- } else if (event.type() == WebCore::eventNames().mouseoverEvent) {
- web_event->type = WebInputEvent::MouseEnter;
- } else if (event.type() == WebCore::eventNames().mousedownEvent) {
- web_event->type = WebInputEvent::MouseDown;
- } else if (event.type() == WebCore::eventNames().mouseupEvent) {
- web_event->type = WebInputEvent::MouseUp;
- } else {
- // Skip all other mouse events.
- return false;
- }
- web_event->timeStampSeconds = event.timeStamp() * 1.0e-3;
- switch (event.button()) {
- case WebCore::LeftButton:
- web_event->button = WebMouseEvent::ButtonLeft;
- break;
- case WebCore::MiddleButton:
- web_event->button = WebMouseEvent::ButtonMiddle;
- break;
- case WebCore::RightButton:
- web_event->button = WebMouseEvent::ButtonRight;
- break;
- }
- web_event->modifiers = GetWebInputModifiers(event);
- if (event.buttonDown()) {
- switch (event.button()) {
- case WebCore::LeftButton:
- web_event->modifiers |= WebInputEvent::LeftButtonDown;
- break;
- case WebCore::MiddleButton:
- web_event->modifiers |= WebInputEvent::MiddleButtonDown;
- break;
- case WebCore::RightButton:
- web_event->modifiers |= WebInputEvent::RightButtonDown;
- break;
- }
- }
- WebCore::IntPoint p = view.contentsToWindow(WebCore::IntPoint(event.pageX(),
- event.pageY()));
- web_event->globalX = event.screenX();
- web_event->globalY = event.screenY();
- web_event->windowX = p.x();
- web_event->windowY = p.y();
- web_event->x = event.offsetX();
- web_event->y = event.offsetY();
- return true;
-}
-
-bool ToWebKeyboardEvent(const WebCore::KeyboardEvent& event,
- WebKeyboardEvent* web_event) {
- if (event.type() == WebCore::eventNames().keydownEvent) {
- web_event->type = WebInputEvent::KeyDown;
- } else if (event.type() == WebCore::eventNames().keyupEvent) {
- web_event->type = WebInputEvent::KeyUp;
- } else {
- // Skip all other keyboard events.
- return false;
- }
- web_event->modifiers = GetWebInputModifiers(event);
- web_event->timeStampSeconds = event.timeStamp() * 1.0e-3;
- web_event->windowsKeyCode = event.keyCode();
- web_event->nativeKeyCode = event.keyEvent()->nativeVirtualKeyCode();
- return true;
-}
diff --git a/webkit/glue/event_conversion.h b/webkit/glue/event_conversion.h
deleted file mode 100644
index ef82cdb..0000000
--- a/webkit/glue/event_conversion.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WEBKIT_GLUE_EVENT_CONVERSION_H_
-#define WEBKIT_GLUE_EVENT_CONVERSION_H_
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "PlatformKeyboardEvent.h"
-#include "PlatformMouseEvent.h"
-#include "PlatformWheelEvent.h"
-MSVC_POP_WARNING();
-
-namespace WebCore {
-class FrameView;
-class KeyboardEvent;
-class MouseEvent;
-class Widget;
-}
-
-namespace WebKit {
-class WebMouseEvent;
-class WebMouseWheelEvent;
-class WebKeyboardEvent;
-}
-
-// These classes are used to convert from WebInputEvent subclasses to
-// corresponding WebCore events.
-
-class MakePlatformMouseEvent : public WebCore::PlatformMouseEvent {
- public:
- MakePlatformMouseEvent(
- WebCore::Widget* widget, const WebKit::WebMouseEvent& e);
-};
-
-class MakePlatformWheelEvent : public WebCore::PlatformWheelEvent {
- public:
- MakePlatformWheelEvent(
- WebCore::Widget* widget, const WebKit::WebMouseWheelEvent& e);
-};
-
-class MakePlatformKeyboardEvent : public WebCore::PlatformKeyboardEvent {
- public:
- MakePlatformKeyboardEvent(const WebKit::WebKeyboardEvent& e);
- void SetKeyType(Type type);
- bool IsCharacterKey() const;
-};
-
-// Converts a WebCore::MouseEvent to a corresponding WebMouseEvent. view is the
-// FrameView corresponding to the event.
-// Returns true if successful.
-// NOTE: This is only implemented for mousemove, mouseover, mouseout, mousedown
-// and mouseup.
-bool ToWebMouseEvent(const WebCore::FrameView& view,
- const WebCore::MouseEvent& event,
- WebKit::WebMouseEvent* web_event);
-
-// Converts a WebCore::KeyboardEvent to a corresponding WebKeyboardEvent.
-// Returns true if successful.
-// NOTE: This is only implemented for keydown and keyup.
-bool ToWebKeyboardEvent(const WebCore::KeyboardEvent& event,
- WebKit::WebKeyboardEvent* web_event);
-
-#endif // WEBKIT_GLUE_EVENT_CONVERSION_H_
diff --git a/webkit/glue/webkit_glue.cc b/webkit/glue/webkit_glue.cc
index d8b5cf6..1952c27 100644
--- a/webkit/glue/webkit_glue.cc
+++ b/webkit/glue/webkit_glue.cc
@@ -41,7 +41,6 @@
#if defined(OS_WIN)
#include "webkit/api/public/win/WebInputEventFactory.h"
#endif
-#include "webkit/glue/event_conversion.h"
#include "webkit/glue/glue_serialize.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webframe_impl.h"
diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc
index 7bb8b94..1282971 100644
--- a/webkit/glue/webplugin_impl.cc
+++ b/webkit/glue/webplugin_impl.cc
@@ -58,8 +58,8 @@
#include "webkit/api/public/WebURLLoader.h"
#include "webkit/api/public/WebURLLoaderClient.h"
#include "webkit/api/public/WebURLResponse.h"
+#include "webkit/api/src/WebInputEventConversion.h"
#include "webkit/glue/chrome_client_impl.h"
-#include "webkit/glue/event_conversion.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/multipart_response_delegate.h"
#include "webkit/glue/webkit_glue.h"
@@ -76,7 +76,9 @@ using WebKit::WebData;
using WebKit::WebHTTPBody;
using WebKit::WebInputEvent;
using WebKit::WebKeyboardEvent;
+using WebKit::WebKeyboardEventBuilder;
using WebKit::WebMouseEvent;
+using WebKit::WebMouseEventBuilder;
using WebKit::WebString;
using WebKit::WebURLError;
using WebKit::WebURLLoader;
@@ -872,8 +874,8 @@ void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) {
// in the call to HandleEvent. See http://b/issue?id=1362948
WebCore::FrameView* parent_view = static_cast<WebCore::FrameView*>(parent());
- WebMouseEvent web_event;
- if (!ToWebMouseEvent(*parent_view, *event, &web_event))
+ WebMouseEventBuilder web_event(parent_view, *event);
+ if (web_event.type == WebInputEvent::Undefined)
return;
if (event->type() == WebCore::eventNames().mousedownEvent) {
@@ -907,8 +909,8 @@ void WebPluginImpl::handleMouseEvent(WebCore::MouseEvent* event) {
}
void WebPluginImpl::handleKeyboardEvent(WebCore::KeyboardEvent* event) {
- WebKeyboardEvent web_event;
- if (!ToWebKeyboardEvent(*event, &web_event))
+ WebKeyboardEventBuilder web_event(*event);
+ if (web_event.type == WebInputEvent::Undefined)
return;
// TODO(pkasting): http://b/1119691 See above.
WebCursorInfo cursor_info;
diff --git a/webkit/glue/webpopupmenu_impl.cc b/webkit/glue/webpopupmenu_impl.cc
index 74b40ab..326a326 100644
--- a/webkit/glue/webpopupmenu_impl.cc
+++ b/webkit/glue/webpopupmenu_impl.cc
@@ -20,12 +20,15 @@
#include "webkit/api/public/WebInputEvent.h"
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebWidgetClient.h"
-#include "webkit/glue/event_conversion.h"
+#include "webkit/api/src/WebInputEventConversion.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/webpopupmenu_impl.h"
using namespace WebCore;
+using WebKit::PlatformKeyboardEventBuilder;
+using WebKit::PlatformMouseEventBuilder;
+using WebKit::PlatformWheelEventBuilder;
using WebKit::WebCanvas;
using WebKit::WebCompositionCommand;
using WebKit::WebInputEvent;
@@ -81,29 +84,29 @@ void WebPopupMenuImpl::MouseMove(const WebMouseEvent& event) {
if (event.x != last_mouse_position_.x ||
event.y != last_mouse_position_.y) {
last_mouse_position_ = WebPoint(event.x, event.y);
- widget_->handleMouseMoveEvent(MakePlatformMouseEvent(widget_, event));
+ widget_->handleMouseMoveEvent(PlatformMouseEventBuilder(widget_, event));
}
}
void WebPopupMenuImpl::MouseLeave(const WebMouseEvent& event) {
- widget_->handleMouseMoveEvent(MakePlatformMouseEvent(widget_, event));
+ widget_->handleMouseMoveEvent(PlatformMouseEventBuilder(widget_, event));
}
void WebPopupMenuImpl::MouseDown(const WebMouseEvent& event) {
- widget_->handleMouseDownEvent(MakePlatformMouseEvent(widget_, event));
+ widget_->handleMouseDownEvent(PlatformMouseEventBuilder(widget_, event));
}
void WebPopupMenuImpl::MouseUp(const WebMouseEvent& event) {
mouseCaptureLost();
- widget_->handleMouseReleaseEvent(MakePlatformMouseEvent(widget_, event));
+ widget_->handleMouseReleaseEvent(PlatformMouseEventBuilder(widget_, event));
}
void WebPopupMenuImpl::MouseWheel(const WebMouseWheelEvent& event) {
- widget_->handleWheelEvent(MakePlatformWheelEvent(widget_, event));
+ widget_->handleWheelEvent(PlatformWheelEventBuilder(widget_, event));
}
bool WebPopupMenuImpl::KeyEvent(const WebKeyboardEvent& event) {
- return widget_->handleKeyEvent(MakePlatformKeyboardEvent(event));
+ return widget_->handleKeyEvent(PlatformKeyboardEventBuilder(event));
}
// WebWidget -------------------------------------------------------------------
diff --git a/webkit/glue/webview_impl.cc b/webkit/glue/webview_impl.cc
index 6d8f05a..6189d64 100644
--- a/webkit/glue/webview_impl.cc
+++ b/webkit/glue/webview_impl.cc
@@ -67,13 +67,13 @@ MSVC_POP_WARNING();
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebString.h"
#include "webkit/api/public/WebURL.h"
+#include "webkit/api/src/WebInputEventConversion.h"
#include "webkit/api/src/WebSettingsImpl.h"
#include "webkit/glue/chrome_client_impl.h"
#include "webkit/glue/context_menu_client_impl.h"
#include "webkit/glue/dom_operations.h"
#include "webkit/glue/dragclient_impl.h"
#include "webkit/glue/editor_client_impl.h"
-#include "webkit/glue/event_conversion.h"
#include "webkit/glue/glue_serialize.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/image_resource_fetcher.h"
@@ -95,6 +95,9 @@ MSVC_POP_WARNING();
using namespace WebCore;
+using WebKit::PlatformKeyboardEventBuilder;
+using WebKit::PlatformMouseEventBuilder;
+using WebKit::PlatformWheelEventBuilder;
using WebKit::WebCanvas;
using WebKit::WebCompositionCommand;
using WebKit::WebCompositionCommandConfirm;
@@ -432,7 +435,7 @@ void WebViewImpl::MouseMove(const WebMouseEvent& event) {
// our ChromeClientImpl to receive changes to the mouse position and
// tooltip text, and mouseMoved handles all of that.
main_frame()->frame()->eventHandler()->mouseMoved(
- MakePlatformMouseEvent(main_frame()->frameview(), event));
+ PlatformMouseEventBuilder(main_frame()->frameview(), event));
}
void WebViewImpl::MouseLeave(const WebMouseEvent& event) {
@@ -444,7 +447,7 @@ void WebViewImpl::MouseLeave(const WebMouseEvent& event) {
delegate_->UpdateTargetURL(this, GURL());
main_frame()->frame()->eventHandler()->handleMouseMoveEvent(
- MakePlatformMouseEvent(main_frame()->frameview(), event));
+ PlatformMouseEventBuilder(main_frame()->frameview(), event));
}
void WebViewImpl::MouseDown(const WebMouseEvent& event) {
@@ -474,7 +477,7 @@ void WebViewImpl::MouseDown(const WebMouseEvent& event) {
}
main_frame()->frame()->eventHandler()->handleMousePressEvent(
- MakePlatformMouseEvent(main_frame()->frameview(), event));
+ PlatformMouseEventBuilder(main_frame()->frameview(), event));
if (clicked_node.get() && clicked_node == GetFocusedNode()) {
// Focus has not changed, show the autocomplete popup.
@@ -502,7 +505,7 @@ void WebViewImpl::MouseContextMenu(const WebMouseEvent& event) {
page_->contextMenuController()->clearContextMenu();
- MakePlatformMouseEvent pme(main_frame()->frameview(), event);
+ PlatformMouseEventBuilder pme(main_frame()->frameview(), event);
// Find the right target frame. See issue 1186900.
HitTestResult result = HitTestResultForWindowPos(pme.pos());
@@ -556,7 +559,7 @@ void WebViewImpl::MouseUp(const WebMouseEvent& event) {
mouseCaptureLost();
main_frame()->frame()->eventHandler()->handleMouseReleaseEvent(
- MakePlatformMouseEvent(main_frame()->frameview(), event));
+ PlatformMouseEventBuilder(main_frame()->frameview(), event));
#if defined(OS_WIN)
// Dispatch the contextmenu event regardless of if the click was swallowed.
@@ -567,7 +570,7 @@ void WebViewImpl::MouseUp(const WebMouseEvent& event) {
}
void WebViewImpl::MouseWheel(const WebMouseWheelEvent& event) {
- MakePlatformWheelEvent platform_event(main_frame()->frameview(), event);
+ PlatformWheelEventBuilder platform_event(main_frame()->frameview(), event);
main_frame()->frame()->eventHandler()->handleWheelEvent(platform_event);
}
@@ -610,7 +613,7 @@ bool WebViewImpl::KeyEvent(const WebKeyboardEvent& event) {
if (event.windowsKeyCode == base::VKEY_CAPITAL)
handler->capsLockStateMayHaveChanged();
- MakePlatformKeyboardEvent evt(event);
+ PlatformKeyboardEventBuilder evt(event);
if (WebInputEvent::RawKeyDown == event.type) {
if (handler->keyEvent(evt) && !evt.isSystemKey()) {
@@ -666,7 +669,8 @@ bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) {
if (!autocomplete_popup_->isInterestedInEventForKey(event.windowsKeyCode))
return false;
- if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) {
+ if (autocomplete_popup_->handleKeyEvent(
+ PlatformKeyboardEventBuilder(event))) {
// We need to ignore the next Char event after this otherwise pressing
// enter when selecting an item in the menu will go to the page.
if (WebInputEvent::RawKeyDown == event.type)
@@ -699,8 +703,8 @@ bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) {
if (!handler)
return KeyEventDefault(event);
- MakePlatformKeyboardEvent evt(event);
- if (!evt.IsCharacterKey())
+ PlatformKeyboardEventBuilder evt(event);
+ if (!evt.isCharacterKey())
return true;
// Safari 3.1 does not pass off windows system key messages (WM_SYSCHAR) to
@@ -787,7 +791,7 @@ bool WebViewImpl::SendContextMenuEvent(const WebKeyboardEvent& event) {
mouse_event.y = coords.y();
mouse_event.type = WebInputEvent::MouseUp;
- MakePlatformMouseEvent platform_event(view, mouse_event);
+ PlatformMouseEventBuilder platform_event(view, mouse_event);
context_menu_allowed_ = true;
bool handled =
@@ -1340,7 +1344,7 @@ void WebViewImpl::SetInitialFocus(bool reverse) {
keyboard_event.modifiers = WebInputEvent::ShiftKey;
// VK_TAB which is only defined on Windows.
keyboard_event.windowsKeyCode = 0x09;
- MakePlatformKeyboardEvent platform_event(keyboard_event);
+ PlatformKeyboardEventBuilder platform_event(keyboard_event);
RefPtr<KeyboardEvent> webkit_event =
KeyboardEvent::create(platform_event, NULL);
page()->focusController()->setInitialFocus(
diff --git a/webkit/tools/test_shell/keyboard_unittest.cc b/webkit/tools/test_shell/keyboard_unittest.cc
index 10f9e741..3ced54e 100644
--- a/webkit/tools/test_shell/keyboard_unittest.cc
+++ b/webkit/tools/test_shell/keyboard_unittest.cc
@@ -16,13 +16,14 @@ MSVC_POP_WARNING();
#include "base/string_util.h"
#include "webkit/glue/editor_client_impl.h"
-#include "webkit/glue/event_conversion.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/api/public/WebInputEvent.h"
+#include "webkit/api/src/WebInputEventConversion.h"
using WebCore::PlatformKeyboardEvent;
using WebCore::KeyboardEvent;
+using WebKit::PlatformKeyboardEventBuilder;
using WebKit::WebInputEvent;
using WebKit::WebKeyboardEvent;
@@ -40,8 +41,8 @@ class KeyboardTest : public testing::Test {
PlatformKeyboardEvent::Type key_type) {
EditorClientImpl editor_impl(NULL);
- MakePlatformKeyboardEvent evt(keyboard_event);
- evt.SetKeyType(key_type);
+ PlatformKeyboardEventBuilder evt(keyboard_event);
+ evt.setKeyType(key_type);
RefPtr<KeyboardEvent> keyboardEvent = KeyboardEvent::create(evt, NULL);
return editor_impl.interpretKeyEvent(keyboardEvent.get());
}
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index c9028c2..9e48f63 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -1072,6 +1072,8 @@
'api/src/WebImageCG.cpp',
'api/src/WebImageSkia.cpp',
'api/src/WebInputEvent.cpp',
+ 'api/src/WebInputEventConversion.cpp',
+ 'api/src/WebInputEventConversion.h',
'api/src/WebKit.cpp',
'api/src/WebMediaPlayerClientImpl.cpp',
'api/src/WebMediaPlayerClientImpl.h',
@@ -1352,8 +1354,6 @@
'glue/editor_client_impl.h',
'glue/entity_map.cc',
'glue/entity_map.h',
- 'glue/event_conversion.cc',
- 'glue/event_conversion.h',
'glue/feed_preview.cc',
'glue/feed_preview.h',
'glue/form_data.h',