Skip to content

Commit

Permalink
Bug 978679 - Implement touch events for GTK3. r=karlt
Browse files Browse the repository at this point in the history
  • Loading branch information
makotokato committed Oct 19, 2015
1 parent f8cdc95 commit e044ede
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 38 deletions.
1 change: 1 addition & 0 deletions dom/events/DataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "mozilla/dom/FileList.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/OSFileSystem.h"
#include "mozilla/dom/Promise.h"

namespace mozilla {
namespace dom {
Expand Down
2 changes: 1 addition & 1 deletion dom/events/DataTransfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/Promise.h"

class nsINode;
class nsITransferable;
Expand All @@ -36,6 +35,7 @@ namespace dom {
class DOMStringList;
class Element;
class FileList;
class Promise;
template<typename T> class Optional;

/**
Expand Down
4 changes: 2 additions & 2 deletions dom/events/TouchEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ TouchEvent::PrefEnabled(JSContext* aCx, JSObject* aGlobal)
int32_t flag = 0;
if (NS_SUCCEEDED(Preferences::GetInt("dom.w3c_touch_events.enabled", &flag))) {
if (flag == 2) {
#ifdef XP_WIN
#if defined(XP_WIN) || MOZ_WIDGET_GTK == 3
static bool sDidCheckTouchDeviceSupport = false;
static bool sIsTouchDeviceSupportPresent = false;
// On Windows we auto-detect based on device support.
// On Windows and GTK3 we auto-detect based on device support.
if (!sDidCheckTouchDeviceSupport) {
sDidCheckTouchDeviceSupport = true;
sIsTouchDeviceSupportPresent = WidgetUtils::IsTouchDeviceSupportPresent();
Expand Down
1 change: 1 addition & 0 deletions dom/mobilemessage/android/SmsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "mozilla/Services.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsIObserverService.h"
#include "nsThreadUtils.h"

using namespace mozilla::dom;
using namespace mozilla::dom::mobilemessage;
Expand Down
6 changes: 5 additions & 1 deletion modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4530,11 +4530,15 @@ pref("dom.mozSettings.enabled", false);
pref("dom.mozPermissionSettings.enabled", false);

// W3C touch events
// 0 - disabled, 1 - enabled, 2 - autodetect (win)
// 0 - disabled, 1 - enabled, 2 - autodetect (win/gtk3)
#ifdef XP_WIN
pref("dom.w3c_touch_events.enabled", 2);
#endif

#if MOZ_WIDGET_GTK == 3
pref("dom.w3c_touch_events.enabled", 2);
#endif

// W3C draft pointer events
pref("dom.w3c_pointer_events.enabled", false);

Expand Down
4 changes: 4 additions & 0 deletions widget/WidgetUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "mozilla/WidgetUtils.h"
#ifdef XP_WIN
#include "WinUtils.h"
#elif MOZ_WIDGET_GTK == 3
#include "mozilla/WidgetUtilsGtk.h"
#endif

namespace mozilla {
Expand Down Expand Up @@ -100,6 +102,8 @@ WidgetUtils::IsTouchDeviceSupportPresent()
{
#ifdef XP_WIN
return WinUtils::IsTouchDeviceSupportPresent();
#elif MOZ_WIDGET_GTK == 3
return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
#else
return 0;
#endif
Expand Down
47 changes: 47 additions & 0 deletions widget/gtk/WidgetUtilsGtk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "WidgetUtilsGtk.h"

namespace mozilla {

namespace widget {

int32_t WidgetUtilsGTK::IsTouchDeviceSupportPresent()
{
int32_t result = 0;
GdkDisplay* display = gdk_display_get_default();
if (!display) {
return 0;
}

GdkDeviceManager* manager = gdk_display_get_device_manager(display);
if (!manager) {
return 0;
}

GList* devices =
gdk_device_manager_list_devices(manager, GDK_DEVICE_TYPE_SLAVE);
GList* list = devices;

while (devices) {
GdkDevice* device = static_cast<GdkDevice*>(devices->data);
if (gdk_device_get_source(device) == GDK_SOURCE_TOUCHSCREEN) {
result = 1;
break;
}
devices = devices->next;
}

if (list) {
g_list_free(list);
}

return result;
}

} // namespace widget

} // namespace mozilla
25 changes: 25 additions & 0 deletions widget/gtk/WidgetUtilsGtk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef WidgetUtilsGtk_h__
#define WidgetUtilsGtk_h__

#include <stdint.h>

namespace mozilla {
namespace widget {

class WidgetUtilsGTK
{
public:
/* See WidgetUtils::IsTouchDeviceSupportPresent(). */
static int32_t IsTouchDeviceSupportPresent();
};

} // namespace widget

} // namespace mozilla

#endif // WidgetUtilsGtk_h__
5 changes: 5 additions & 0 deletions widget/gtk/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ EXPORTS += [
'nsIImageToPixbuf.h',
]

EXPORTS.mozilla += [
'WidgetUtilsGtk.h'
]

UNIFIED_SOURCES += [
'IMContextWrapper.cpp',
'mozcontainer.c',
Expand All @@ -32,6 +36,7 @@ UNIFIED_SOURCES += [
'nsWidgetFactory.cpp',
'WakeLockListener.cpp',
'WidgetTraceEvent.cpp',
'WidgetUtilsGtk.cpp',
]

SOURCES += [
Expand Down
1 change: 1 addition & 0 deletions widget/gtk/mozgtk/mozgtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ STUB(gtk_window_unmaximize)
#ifdef GTK3_SYMBOLS
STUB(gdk_device_get_source)
STUB(gdk_device_manager_get_client_pointer)
STUB(gdk_device_manager_list_devices)
STUB(gdk_disable_multidevice)
STUB(gdk_display_get_device_manager)
STUB(gdk_error_trap_pop_ignored)
Expand Down
6 changes: 6 additions & 0 deletions widget/gtk/nsLookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "gtkdrawing.h"
#include "nsStyleConsts.h"
#include "gfxFontConstants.h"
#include "WidgetUtilsGtk.h"

#include <dlfcn.h>

Expand Down Expand Up @@ -634,8 +635,13 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult)
res = NS_ERROR_NOT_IMPLEMENTED;
break;
case eIntID_TouchEnabled:
#if MOZ_WIDGET_GTK == 3
aResult = mozilla::widget::WidgetUtilsGTK::IsTouchDeviceSupportPresent();
break;
#else
aResult = 0;
res = NS_ERROR_NOT_IMPLEMENTED;
#endif
break;
case eIntID_MacGraphiteTheme:
case eIntID_MacLionTheme:
Expand Down
Loading

0 comments on commit e044ede

Please sign in to comment.