LCOV - code coverage report
Current view: top level - gfx/layers/apz/util - TouchActionHelper.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 28 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "TouchActionHelper.h"
       7             : 
       8             : #include "mozilla/layers/APZCTreeManager.h"
       9             : #include "nsContainerFrame.h"
      10             : #include "nsIScrollableFrame.h"
      11             : #include "nsLayoutUtils.h"
      12             : 
      13             : namespace mozilla {
      14             : namespace layers {
      15             : 
      16             : void
      17           0 : TouchActionHelper::UpdateAllowedBehavior(uint32_t aTouchActionValue,
      18             :                                          bool aConsiderPanning,
      19             :                                          TouchBehaviorFlags& aOutBehavior)
      20             : {
      21           0 :   if (aTouchActionValue != NS_STYLE_TOUCH_ACTION_AUTO) {
      22             :     // Double-tap-zooming need property value AUTO
      23           0 :     aOutBehavior &= ~AllowedTouchBehavior::DOUBLE_TAP_ZOOM;
      24           0 :     if (aTouchActionValue != NS_STYLE_TOUCH_ACTION_MANIPULATION) {
      25             :       // Pinch-zooming need value AUTO or MANIPULATION
      26           0 :       aOutBehavior &= ~AllowedTouchBehavior::PINCH_ZOOM;
      27             :     }
      28             :   }
      29             : 
      30           0 :   if (aConsiderPanning) {
      31           0 :     if (aTouchActionValue == NS_STYLE_TOUCH_ACTION_NONE) {
      32           0 :       aOutBehavior &= ~AllowedTouchBehavior::VERTICAL_PAN;
      33           0 :       aOutBehavior &= ~AllowedTouchBehavior::HORIZONTAL_PAN;
      34             :     }
      35             : 
      36             :     // Values pan-x and pan-y set at the same time to the same element do not affect panning constraints.
      37             :     // Therefore we need to check whether pan-x is set without pan-y and the same for pan-y.
      38           0 :     if ((aTouchActionValue & NS_STYLE_TOUCH_ACTION_PAN_X) && !(aTouchActionValue & NS_STYLE_TOUCH_ACTION_PAN_Y)) {
      39           0 :       aOutBehavior &= ~AllowedTouchBehavior::VERTICAL_PAN;
      40           0 :     } else if ((aTouchActionValue & NS_STYLE_TOUCH_ACTION_PAN_Y) && !(aTouchActionValue & NS_STYLE_TOUCH_ACTION_PAN_X)) {
      41           0 :       aOutBehavior &= ~AllowedTouchBehavior::HORIZONTAL_PAN;
      42             :     }
      43             :   }
      44           0 : }
      45             : 
      46             : TouchBehaviorFlags
      47           0 : TouchActionHelper::GetAllowedTouchBehavior(nsIWidget* aWidget,
      48             :                                            nsIFrame* aRootFrame,
      49             :                                            const LayoutDeviceIntPoint& aPoint)
      50             : {
      51             :   TouchBehaviorFlags behavior = AllowedTouchBehavior::VERTICAL_PAN | AllowedTouchBehavior::HORIZONTAL_PAN |
      52           0 :                                 AllowedTouchBehavior::PINCH_ZOOM | AllowedTouchBehavior::DOUBLE_TAP_ZOOM;
      53             : 
      54             :   nsPoint relativePoint =
      55           0 :     nsLayoutUtils::GetEventCoordinatesRelativeTo(aWidget, aPoint, aRootFrame);
      56             : 
      57           0 :   nsIFrame *target = nsLayoutUtils::GetFrameForPoint(aRootFrame, relativePoint, nsLayoutUtils::IGNORE_ROOT_SCROLL_FRAME);
      58           0 :   if (!target) {
      59           0 :     return behavior;
      60             :   }
      61           0 :   nsIScrollableFrame *nearestScrollableParent = nsLayoutUtils::GetNearestScrollableFrame(target, 0);
      62           0 :   nsIFrame* nearestScrollableFrame = do_QueryFrame(nearestScrollableParent);
      63             : 
      64             :   // We're walking up the DOM tree until we meet the element with touch behavior and accumulating
      65             :   // touch-action restrictions of all elements in this chain.
      66             :   // The exact quote from the spec, that clarifies more:
      67             :   // To determine the effect of a touch, find the nearest ancestor (starting from the element itself)
      68             :   // that has a default touch behavior. Then examine the touch-action property of each element between
      69             :   // the hit tested element and the element with the default touch behavior (including both the hit
      70             :   // tested element and the element with the default touch behavior). If the touch-action property of
      71             :   // any of those elements disallows the default touch behavior, do nothing. Otherwise allow the element
      72             :   // to start considering the touch for the purposes of executing a default touch behavior.
      73             : 
      74             :   // Currently we support only two touch behaviors: panning and zooming.
      75             :   // For panning we walk up until we meet the first scrollable element (the element that supports panning)
      76             :   // or root element.
      77             :   // For zooming we walk up until the root element since Firefox currently supports only zooming of the
      78             :   // root frame but not the subframes.
      79             : 
      80           0 :   bool considerPanning = true;
      81             : 
      82           0 :   for (nsIFrame *frame = target; frame && frame->GetContent() && behavior; frame = frame->GetParent()) {
      83           0 :     UpdateAllowedBehavior(nsLayoutUtils::GetTouchActionFromFrame(frame), considerPanning, behavior);
      84             : 
      85           0 :     if (frame == nearestScrollableFrame) {
      86             :       // We met the scrollable element, after it we shouldn't consider touch-action
      87             :       // values for the purpose of panning but only for zooming.
      88           0 :       considerPanning = false;
      89             :     }
      90             :   }
      91             : 
      92           0 :   return behavior;
      93             : }
      94             : 
      95             : } // namespace layers
      96             : } // namespace mozilla

Generated by: LCOV version 1.13