Add new platform gamepad abstractions
https://bugs.webkit.org/show_bug.cgi?id=134325

Reviewed by Dean Jackson.

Source/WebCore:
No new tests (Not yet a tested config)

- GamepadStrategy lets ports customize the 3 basic behaviors needed for a gamepad
  implementation to feed the API in WebCore.
- GamepadStrategyClient gives arbitrary objects in WebCore the ability to register
  for callbacks with the GamepadStrategy.
- PlatformGamepad is a platform-agnostic object that represents the data that
  feeds into the Gamepad object that is exposed to web content.

The code in this patch is dead as-is, but https://bugs.webkit.org/show_bug.cgi?id=134324
will contain an immediate follow-up patch that uses it.

Makes sense to review them separately.

* WebCore.xcodeproj/project.pbxproj:

* platform/GamepadStrategy.h: Added.
(WebCore::GamepadStrategy::~GamepadStrategy):

* platform/GamepadStrategyClient.h: Added.
(WebCore::GamepadStrategyClient::~GamepadStrategyClient):

* platform/PlatformGamepad.h: Added.
(WebCore::PlatformGamepad::~PlatformGamepad):
(WebCore::PlatformGamepad::id):
(WebCore::PlatformGamepad::lastUpdateTime):
(WebCore::PlatformGamepad::connectTime):
(WebCore::PlatformGamepad::PlatformGamepad):

* platform/PlatformStrategies.h:
(WebCore::PlatformStrategies::gamepadStrategy):
(WebCore::PlatformStrategies::PlatformStrategies):

Source/WebKit/mac:
* WebCoreSupport/WebPlatformStrategies.h:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::createGamepadStrategy):
(WebPlatformStrategies::startMonitoringGamepads):
(WebPlatformStrategies::stopMonitoringGamepads):
(WebPlatformStrategies::platformGamepads):

Source/WebKit/win:
* WebCoreSupport/WebPlatformStrategies.cpp:
(WebPlatformStrategies::createGamepadStrategy):
* WebCoreSupport/WebPlatformStrategies.h:

Source/WebKit2:
* NetworkProcess/NetworkProcessPlatformStrategies.cpp:
(WebKit::NetworkProcessPlatformStrategies::createGamepadStrategy):
* NetworkProcess/NetworkProcessPlatformStrategies.h:

Actually return a GamepadStrategy in WK2 with no implementation for now:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::createGamepadStrategy):
(WebKit::WebPlatformStrategies::startMonitoringGamepads):
(WebKit::WebPlatformStrategies::stopMonitoringGamepads):
(WebKit::WebPlatformStrategies::platformGamepads):
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170459 268f45cc-cd09-0410-ab3c-d52691b4dbfc
REGRESSION (r170325): UI process crashes in lastCommittedLayerTreeTransactionID() when the Web Content process crashes
https://bugs.webkit.org/show_bug.cgi?id=134284

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-06-25
Reviewed by Simon Fraser.

The crash was caused by the access to the Drawing Area after the crash.
This lead to discovering another bug: m_lastVisibleContentRectUpdate could have been updated after WebPageProxy::resetState(),
which in turn would prevent valid updates when a new WebProcess is created.

This patch fixes both issues by moving the VisibleContentRectUpdateInfo to be internal to WebPageProxy,
then early return if we get there in an invalid state.

* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentView.mm:
(-[WKContentView didUpdateVisibleRect:unobscuredRect:unobscuredRectInScrollViewCoordinates:scale:minimumScale:inStableState:isChangingObscuredInsetsInteractively:]):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::updateVisibleContentRects):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170460 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WK2] Tweak the logic used to choose the scale at which position:fixed gets pushed out of view
https://bugs.webkit.org/show_bug.cgi?id=134323

Reviewed by Benjamin Poulain.

Previously we used a fixed scale (1.2x) at which we'd start pushing position:fixed elements
out of the viewport. This worked well on iPad, but terribly on iPhone. Instead, choose a scale
relative to how much of the page is visible width-wise, the threshold being 2/3 of the page width.
The width is clamped to get reasonable behavior on wide pages.

* page/FrameView.cpp:
(WebCore::FrameView::rectForViewportConstrainedObjects):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170461 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WK2] Fixed position elements jump around when zooming
https://bugs.webkit.org/show_bug.cgi?id=134328
<rdar://problem/17447048>

Reviewed by Zalan Bujtas.

If a given remote layer tree commit contains changes of layers for viewport-constrained
objects, then the associated scrolling tree also needs to show that the layers changed,
since we need to re-run the "viewport changed" logic in the UI process to get the
layers correctly positioned for the current zoom level.

The bug was that page scale changes resulted in small "pixel alignment" position
changes which touched layers, but we didn't commit any scrolling tree changes. So
the scrolling tree commit would result in visibly stale layer positions, with no scrolling tree
update to adjust them for the current transient zoom.

Fix by making use of the existing "alignment offset" field in the ViewportConstraints
data, and having RemoteScrollingCoordinatorProxy::connectStateNodeLayers() note that
fixed or sticky layers changed if any properties of fixed or sticky scrolling tree
nodes were updated.

Source/WebCore:
* page/scrolling/ScrollingConstraints.h:
(WebCore::StickyPositionViewportConstraints::operator==):
* platform/graphics/GraphicsLayer.h:
(WebCore::GraphicsLayer::pixelAlignmentOffset):
* platform/graphics/ca/GraphicsLayerCA.cpp:
(WebCore::GraphicsLayerCA::updateGeometry):
* platform/graphics/ca/GraphicsLayerCA.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::computeFixedViewportConstraints):
(WebCore::RenderLayerCompositor::computeStickyViewportConstraints):

Source/WebKit2:
* UIProcess/ios/RemoteScrollingCoordinatorProxyIOS.mm:
(WebKit::RemoteScrollingCoordinatorProxy::connectStateNodeLayers):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170462 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS WK2] Page jumps when rubber-banding on azuremagazine.com
https://bugs.webkit.org/show_bug.cgi?id=134238
<rdar://problem/16918228>

Reviewed by Benjamin Poulain.

If the scroll view is in the process of rubber-banding when -setContentSize: is called,
it clamps the scroll offsets between zero and the max value, which visibly interrupts the
rubberband. This can easily happen now that we continually send scroll events to the page
on scrolling, especially when pages like azuremagazine.com do fake sticky by toggling
in-flow elements into position:fixed.

Fix by computing the amount of rubber-band before calling -setContentSize:, and then
restoring the contentOffset with the same amount of rubber-band even when the content size
is different, for top/left rubberbands.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _didCommitLayerTree:WebKit::]):
* UIProcess/ios/WKScrollView.h:
* UIProcess/ios/WKScrollView.mm:
(-[WKScrollView _currentTopLeftRubberbandAmount]):
(-[WKScrollView _restoreContentOffsetWithRubberbandAmount:]):
(-[WKScrollView _setContentSizePreservingContentOffsetDuringRubberband:]):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170463 268f45cc-cd09-0410-ab3c-d52691b4dbfc
WebProgressTracker updates progress too frequently
https://bugs.webkit.org/show_bug.cgi?id=134185

Reviewed by Tim Horton.

The old code throttled the progress update to when either 100ms has passed or the delta is at least 2%
but this was still not enough in pages that loaded in sub-seconds. The new code always throttles it at 200ms.

* loader/ProgressTracker.cpp:
(WebCore::ProgressTracker::ProgressTracker):
(WebCore::ProgressTracker::incrementProgress):
* loader/ProgressTracker.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170464 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Add HID-based gamepad implementation for Mac
https://bugs.webkit.org/show_bug.cgi?id=134324

Reviewed by Dean Jackson.

Source/WebCore:
No new tests (Not yet a tested config)

* Modules/gamepad/Gamepad.cpp:
(WebCore::Gamepad::Gamepad):
(WebCore::Gamepad::updateFromPlatformGamepad): Update the Gamepad’s data from the passed-in PlatformGamepad.
* Modules/gamepad/Gamepad.h:

* Modules/gamepad/GamepadButton.h:
(WebCore::GamepadButton::create): Change to use Ref instead of RefPtr.

GamepadManager is a GamepadStrategyClient that receives notifications from the platform gamepad implementation
and forwards them to NavigatorGamepad objects. In the future it will also handle event dispatch and exposing
gamepads to the API layer when a button is pressed:
* Modules/gamepad/GamepadManager.cpp: Added.
(WebCore::GamepadManager::shared):
(WebCore::GamepadManager::GamepadManager):
(WebCore::GamepadManager::platformGamepadConnected):
(WebCore::GamepadManager::platformGamepadDisconnected):
(WebCore::GamepadManager::registerNavigator):
(WebCore::GamepadManager::unregisterNavigator):
* Modules/gamepad/GamepadManager.h:

The NavigatorGamepad supplement actually manages visibility of Gamepads on a per-DOMWindow basis:
* Modules/gamepad/NavigatorGamepad.cpp:
(WebCore::NavigatorGamepad::NavigatorGamepad):
(WebCore::NavigatorGamepad::~NavigatorGamepad):
(WebCore::NavigatorGamepad::from):
(WebCore::NavigatorGamepad::gamepads):
(WebCore::NavigatorGamepad::gamepadsBecameVisible):
(WebCore::NavigatorGamepad::gamepadConnected):
(WebCore::NavigatorGamepad::gamepadDisconnected):
* Modules/gamepad/NavigatorGamepad.h:
(WebCore::NavigatorGamepad::navigationStart):

HIDGamepad is a PlatformGamepad that wraps an IOHIDDeviceRef and keeps input values updated:
* platform/mac/HIDGamepad.cpp: Added.
(WebCore::HIDGamepad::HIDGamepad):
(WebCore::HIDGamepad::initElements):
(WebCore::HIDGamepad::initElementsFromArray):
(WebCore::HIDGamepad::maybeAddButton):
(WebCore::HIDGamepad::maybeAddAxis):
(WebCore::HIDGamepad::valueChanged):
* platform/mac/HIDGamepad.h: Added.
(WebCore::HIDGamepadElement::HIDGamepadElement):
(WebCore::HIDGamepadElement::~HIDGamepadElement):
(WebCore::HIDGamepadElement::isButton):
(WebCore::HIDGamepadElement::isAxis):
(WebCore::HIDGamepadButton::HIDGamepadButton):
(WebCore::HIDGamepadAxis::HIDGamepadAxis):
(WebCore::HIDGamepad::hidDevice):

HIDGamepadListener wraps an IOHIDManagerRef and continuously listens for changes to Gamepad-type
devices plugged in to the system:
* platform/mac/HIDGamepadListener.cpp: Added.
(WebCore::deviceMatchingDictionary):
(WebCore::deviceAddedCallback):
(WebCore::deviceRemovedCallback):
(WebCore::deviceValuesChangedCallback):
(WebCore::HIDGamepadListener::shared):
(WebCore::HIDGamepadListener::HIDGamepadListener):
(WebCore::HIDGamepadListener::indexForNewlyConnectedDevice):
(WebCore::HIDGamepadListener::deviceAdded):
(WebCore::HIDGamepadListener::deviceRemoved):
(WebCore::HIDGamepadListener::valuesChanged):
(WebCore::HIDGamepadListener::removeGamepadForDevice):
* platform/mac/HIDGamepadListener.h: Copied from Source/WebCore/Modules/gamepad/NavigatorGamepad.cpp.
(WebCore::HIDGamepadListenerClient::~HIDGamepadListenerClient):
(WebCore::HIDGamepadListener::setClient):
(WebCore::HIDGamepadListener::platformGamepads):
(WebCore::HIDGamepadListener::setShouldDispatchCallbacks):

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit:
* WebKit.xcodeproj/project.pbxproj:

Source/WebKit/mac:
Add a class that acts as an intermediary between the GamepadStrategyClient
and the HIDGamepadListener:
* WebCoreSupport/WebHIDGamepadController.h:
* WebCoreSupport/WebHIDGamepadController.mm:
(WebHIDGamepadController::shared):
(WebHIDGamepadController::WebHIDGamepadController):
(WebHIDGamepadController::gamepadConnected):
(WebHIDGamepadController::gamepadDisconnected):
(WebHIDGamepadController::registerGamepadStrategyClient):
(WebHIDGamepadController::unregisterGamepadStrategyClient):

Implement the strategies by using the HIDGamepadListener:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::startMonitoringGamepads):
(WebPlatformStrategies::stopMonitoringGamepads):
(WebPlatformStrategies::platformGamepads):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170465 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[iOS][WK2] Update the long press interactions correctly when an overflow scroll view scrolls
https://bugs.webkit.org/show_bug.cgi?id=134334

Patch by Benjamin Poulain <bpoulain@apple.com> on 2014-06-25
Reviewed by Simon Fraser.

* UIProcess/PageClient.h:
* UIProcess/Scrolling/RemoteScrollingCoordinatorProxy.cpp:
(WebKit::RemoteScrollingCoordinatorProxy::scrollingTreeNodeDidScroll):
* UIProcess/Scrolling/ios/ScrollingTreeOverflowScrollingNodeIOS.h:
* UIProcess/Scrolling/ios/ScrollingTreeOverflowScrollingNodeIOS.mm:
(-[WKOverflowScrollViewDelegate scrollViewWillBeginDragging:]):
(WebKit::ScrollingTreeOverflowScrollingNodeIOS::overflowScrollViewWillStartPanGesture):
(WebKit::ScrollingTreeOverflowScrollingNodeIOS::scrollViewWillStartPanGesture): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::overflowScrollViewWillStartPanGesture):
(WebKit::PageClientImpl::overflowScrollViewDidScroll):
(WebKit::PageClientImpl::scrollViewWillStartPanGesture): Deleted.
* UIProcess/ios/RemoteScrollingCoordinatorProxyIOS.mm:
(WebKit::RemoteScrollingCoordinatorProxy::scrollingTreeNodeWillStartPanGesture):
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::overflowScrollViewWillStartPanGesture):
(WebKit::WebPageProxy::overflowScrollViewDidScroll):
(WebKit::WebPageProxy::scrollViewWillStartPanGesture): Deleted.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170466 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[Mac] Radio buttons and checkboxes vanish when redrawn
https://bugs.webkit.org/show_bug.cgi?id=134335

Reviewed by Dan Bernstein.

I screwed up when landing r170343 by moving some code around
which broke the logic. We need to query the animation
state for controls after we draw (both statically and animated).

* platform/mac/ThemeMac.mm:
(WebCore::paintToggleButton): We need to check the state of animation again, after
we draw.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170467 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Build fix attempt after r170465.

* platform/mac/HIDGamepad.cpp:
(WebCore::HIDGamepad::initElementsFromArray):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@170468 268f45cc-cd09-0410-ab3c-d52691b4dbfc