OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/input/TouchActionUtil.h" | 6 #include "core/input/TouchActionUtil.h" |
7 | 7 |
8 #include "core/dom/Node.h" | 8 #include "core/dom/Node.h" |
9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/LayoutObject.h" | 10 #include "core/layout/LayoutObject.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 static bool supportsTouchAction(const LayoutObject& object) | 21 static bool supportsTouchAction(const LayoutObject& object) |
22 { | 22 { |
23 if (object.isInline() && !object.isReplaced()) | 23 if (object.isInline() && !object.isReplaced()) |
24 return false; | 24 return false; |
25 if (object.isTableRow() || object.isLayoutTableCol()) | 25 if (object.isTableRow() || object.isLayoutTableCol()) |
26 return false; | 26 return false; |
27 | 27 |
28 return true; | 28 return true; |
29 } | 29 } |
30 | 30 |
31 static TouchAction intersectTouchAction(TouchAction action1, TouchAction action2
) | |
32 { | |
33 if (action1 == TouchActionNone || action2 == TouchActionNone) | |
34 return TouchActionNone; | |
35 if (action1 == TouchActionAuto) | |
36 return action2; | |
37 if (action2 == TouchActionAuto) | |
38 return action1; | |
39 if (!(action1 & action2)) | |
40 return TouchActionNone; | |
41 return action1 & action2; | |
42 } | |
43 | |
44 } // namespace | 31 } // namespace |
45 | 32 |
46 TouchAction computeEffectiveTouchAction(const Node& node) | 33 TouchAction computeEffectiveTouchAction(const Node& node) |
47 { | 34 { |
48 // Start by permitting all actions, then walk the elements supporting | 35 // Start by permitting all actions, then walk the elements supporting |
49 // touch-action from the target node up to the nearest scrollable ancestor | 36 // touch-action from the target node up to the nearest scrollable ancestor |
50 // and exclude any prohibited actions. | 37 // and exclude any prohibited actions. |
51 TouchAction effectiveTouchAction = TouchActionAuto; | 38 TouchAction effectiveTouchAction = TouchActionAuto; |
52 for (const Node* curNode = &node; curNode; curNode = ComposedTreeTraversal::
parent(*curNode)) { | 39 for (const Node* curNode = &node; curNode; curNode = ComposedTreeTraversal::
parent(*curNode)) { |
53 if (LayoutObject* layoutObject = curNode->layoutObject()) { | 40 if (LayoutObject* layoutObject = curNode->layoutObject()) { |
54 if (supportsTouchAction(*layoutObject)) { | 41 if (supportsTouchAction(*layoutObject)) { |
55 TouchAction action = layoutObject->style()->touchAction(); | 42 TouchAction action = layoutObject->style()->touchAction(); |
56 effectiveTouchAction = intersectTouchAction(action, effectiveTou
chAction); | 43 effectiveTouchAction &= action; |
57 if (effectiveTouchAction == TouchActionNone) | 44 if (effectiveTouchAction == TouchActionNone) |
58 break; | 45 break; |
59 } | 46 } |
60 | 47 |
61 // If we've reached an ancestor that supports a touch action, search
no further. | 48 // If we've reached an ancestor that supports a touch action, search
no further. |
62 if (layoutObject->isBox() && toLayoutBox(layoutObject)->scrollsOverf
low()) | 49 if (layoutObject->isBox() && toLayoutBox(layoutObject)->scrollsOverf
low()) |
63 break; | 50 break; |
64 } | 51 } |
65 } | 52 } |
66 return effectiveTouchAction; | 53 return effectiveTouchAction; |
67 } | 54 } |
68 | 55 |
69 } // namespace TouchActionUtil | 56 } // namespace TouchActionUtil |
70 } // namespace blink | 57 } // namespace blink |
OLD | NEW |