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/html/HTMLFrameOwnerElement.h" |
9 #include "core/layout/LayoutBox.h" | 10 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/LayoutObject.h" | 11 #include "core/layout/LayoutObject.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 namespace TouchActionUtil { | 14 namespace TouchActionUtil { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // touch-action applies to all elements with both width AND height properties. | 18 // touch-action applies to all elements with both width AND height properties. |
18 // According to the CSS Box Model Spec (http://dev.w3.org/csswg/css-box/#the-wid
th-and-height-properties) | 19 // According to the CSS Box Model Spec (http://dev.w3.org/csswg/css-box/#the-wid
th-and-height-properties) |
19 // width applies to all elements but non-replaced inline elements, table rows, a
nd row groups and | 20 // width applies to all elements but non-replaced inline elements, table rows, a
nd row groups and |
20 // height applies to all elements but non-replaced inline elements, table column
s, and column groups. | 21 // height applies to all elements but non-replaced inline elements, table column
s, and column groups. |
21 static bool supportsTouchAction(const LayoutObject& object) | 22 bool supportsTouchAction(const LayoutObject& object) |
22 { | 23 { |
23 if (object.isInline() && !object.isReplaced()) | 24 if (object.isInline() && !object.isReplaced()) |
24 return false; | 25 return false; |
25 if (object.isTableRow() || object.isLayoutTableCol()) | 26 if (object.isTableRow() || object.isLayoutTableCol()) |
26 return false; | 27 return false; |
27 | 28 |
28 return true; | 29 return true; |
29 } | 30 } |
30 | 31 |
| 32 const Node* parentNodeAcrossFrames(const Node* curNode) |
| 33 { |
| 34 Node* parentNode = ComposedTreeTraversal::parent(*curNode); |
| 35 if (parentNode) |
| 36 return parentNode; |
| 37 |
| 38 if (curNode->isDocumentNode()) { |
| 39 const Document* doc = toDocument(curNode); |
| 40 return doc->ownerElement(); |
| 41 } |
| 42 |
| 43 return nullptr; |
| 44 } |
| 45 |
31 } // namespace | 46 } // namespace |
32 | 47 |
33 TouchAction computeEffectiveTouchAction(const Node& node) | 48 TouchAction computeEffectiveTouchAction(const Node& node) |
34 { | 49 { |
35 // Start by permitting all actions, then walk the elements supporting | 50 // Start by permitting all actions, then walk the elements supporting |
36 // touch-action from the target node up to the nearest scrollable ancestor | 51 // touch-action from the target node up to root document, exclude any |
37 // and exclude any prohibited actions. | 52 // prohibited actions at or below the element that supports them. |
| 53 // I.e. pan-related actions are considered up to the nearest scroller, |
| 54 // and zoom related actions are considered up to the root. |
38 TouchAction effectiveTouchAction = TouchActionAuto; | 55 TouchAction effectiveTouchAction = TouchActionAuto; |
39 for (const Node* curNode = &node; curNode; curNode = ComposedTreeTraversal::
parent(*curNode)) { | 56 TouchAction handledTouchActions = TouchActionNone; |
| 57 for (const Node* curNode = &node; curNode; curNode = parentNodeAcrossFrames(
curNode)) { |
40 if (LayoutObject* layoutObject = curNode->layoutObject()) { | 58 if (LayoutObject* layoutObject = curNode->layoutObject()) { |
41 if (supportsTouchAction(*layoutObject)) { | 59 if (supportsTouchAction(*layoutObject)) { |
42 TouchAction action = layoutObject->style()->touchAction(); | 60 TouchAction action = layoutObject->style()->touchAction(); |
| 61 action |= handledTouchActions; |
43 effectiveTouchAction &= action; | 62 effectiveTouchAction &= action; |
44 if (effectiveTouchAction == TouchActionNone) | 63 if (effectiveTouchAction == TouchActionNone) |
45 break; | 64 break; |
46 } | 65 } |
47 | 66 |
48 // If we've reached an ancestor that supports a touch action, search
no further. | 67 // If we've reached an ancestor that supports panning, stop allowing
panning to be disabled. |
49 if (layoutObject->isBox() && toLayoutBox(layoutObject)->scrollsOverf
low()) | 68 if ((layoutObject->isBox() && toLayoutBox(layoutObject)->scrollsOver
flow()) |
50 break; | 69 || layoutObject->isLayoutView()) |
| 70 handledTouchActions |= TouchActionPan; |
51 } | 71 } |
52 } | 72 } |
53 return effectiveTouchAction; | 73 return effectiveTouchAction; |
54 } | 74 } |
55 | 75 |
56 } // namespace TouchActionUtil | 76 } // namespace TouchActionUtil |
57 } // namespace blink | 77 } // namespace blink |
OLD | NEW |