Chromium Code Reviews| 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 "core/input/TouchActionUtil.h" | 5 #include "core/input/TouchActionUtil.h" |
| 6 | 6 |
| 7 #include "core/dom/Node.h" | 7 #include "core/dom/Node.h" |
| 8 #include "core/html/HTMLFrameOwnerElement.h" | 8 #include "core/html/HTMLFrameOwnerElement.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" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 namespace TouchActionUtil { | 13 namespace TouchActionUtil { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // touch-action applies to all elements with both width AND height properties. | |
| 18 // According to the CSS Box Model Spec | |
| 19 // (http://dev.w3.org/csswg/css-box/#the-width-and-height-properties) | |
| 20 // width applies to all elements but non-replaced inline elements, table rows, | |
| 21 // and row groups and height applies to all elements but non-replaced inline | |
| 22 // elements, table columns, and column groups. | |
| 23 bool SupportsTouchAction(const LayoutObject& object) { | |
| 24 if (object.IsInline() && !object.IsAtomicInlineLevel()) | |
| 25 return false; | |
| 26 if (object.IsTableRow() || object.IsLayoutTableCol()) | |
| 27 return false; | |
| 28 | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 const Node* ParentNodeAcrossFrames(const Node* cur_node) { | 17 const Node* ParentNodeAcrossFrames(const Node* cur_node) { |
| 33 Node* parent_node = FlatTreeTraversal::Parent(*cur_node); | 18 Node* parent_node = FlatTreeTraversal::Parent(*cur_node); |
| 34 if (parent_node) | 19 if (parent_node) |
| 35 return parent_node; | 20 return parent_node; |
| 36 | 21 |
| 37 if (cur_node->IsDocumentNode()) { | 22 if (cur_node->IsDocumentNode()) { |
| 38 const Document* doc = ToDocument(cur_node); | 23 const Document* doc = ToDocument(cur_node); |
| 39 return doc->LocalOwner(); | 24 return doc->LocalOwner(); |
| 40 } | 25 } |
| 41 | 26 |
| 42 return nullptr; | 27 return nullptr; |
| 43 } | 28 } |
| 44 | 29 |
| 45 } // namespace | 30 } // namespace |
| 46 | 31 |
| 47 TouchAction ComputeEffectiveTouchAction(const Node& node) { | 32 TouchAction ComputeEffectiveTouchAction(const Node& node) { |
| 48 // Start by permitting all actions, then walk the elements supporting | |
| 49 // touch-action from the target node up to root document, exclude any | |
| 50 // prohibited actions at or below the element that supports them. | |
| 51 // I.e. pan-related actions are considered up to the nearest scroller, | |
| 52 // and zoom related actions are considered up to the root. | |
| 53 TouchAction effective_touch_action = TouchAction::kTouchActionAuto; | 33 TouchAction effective_touch_action = TouchAction::kTouchActionAuto; |
| 54 TouchAction handled_touch_actions = TouchAction::kTouchActionNone; | |
| 55 for (const Node* cur_node = &node; cur_node; | 34 for (const Node* cur_node = &node; cur_node; |
| 56 cur_node = ParentNodeAcrossFrames(cur_node)) { | 35 cur_node = ParentNodeAcrossFrames(cur_node)) { |
| 57 if (LayoutObject* layout_object = cur_node->GetLayoutObject()) { | 36 if (cur_node->GetLayoutObject()) { |
|
flackr
2017/06/07 18:21:47
I wonder if we can use Node::GetComputedStyle? Wha
sunxd
2017/06/08 19:08:12
There are cases where the function is called with
flackr
2017/06/08 19:35:21
Acknowledged.
| |
| 58 if (SupportsTouchAction(*layout_object)) { | 37 effective_touch_action = |
| 59 TouchAction action = layout_object->Style()->GetTouchAction(); | 38 cur_node->GetLayoutObject()->Style()->GetEffectiveTouchAction(); |
| 60 action |= handled_touch_actions; | 39 break; |
| 61 effective_touch_action &= action; | |
| 62 if (effective_touch_action == TouchAction::kTouchActionNone) | |
| 63 break; | |
| 64 } | |
| 65 | |
| 66 // If we've reached an ancestor that supports panning, stop allowing | |
| 67 // panning to be disabled. | |
| 68 if ((layout_object->IsBox() && | |
| 69 ToLayoutBox(layout_object)->ScrollsOverflow()) || | |
| 70 layout_object->IsLayoutView()) | |
| 71 handled_touch_actions |= TouchAction::kTouchActionPan; | |
| 72 } | 40 } |
| 73 } | 41 } |
| 74 return effective_touch_action; | 42 return effective_touch_action; |
| 75 } | 43 } |
| 76 | 44 |
| 77 } // namespace TouchActionUtil | 45 } // namespace TouchActionUtil |
| 78 } // namespace blink | 46 } // namespace blink |
| OLD | NEW |