Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: third_party/WebKit/Source/core/input/TouchActionUtil.cpp

Issue 2916563003: Compute effective touch action in StyleAdjuster. (Closed)
Patch Set: add test case Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/dom/NodeComputedStyle.h"
8 #include "core/html/HTMLFrameOwnerElement.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
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) {
33 Node* parent_node = FlatTreeTraversal::Parent(*cur_node);
34 if (parent_node)
35 return parent_node;
36
37 if (cur_node->IsDocumentNode()) {
38 const Document* doc = ToDocument(cur_node);
39 return doc->LocalOwner();
40 }
41
42 return nullptr;
43 }
44
45 } // namespace
46
47 TouchAction ComputeEffectiveTouchAction(const Node& node) { 16 TouchAction ComputeEffectiveTouchAction(const Node& node) {
48 // Start by permitting all actions, then walk the elements supporting 17 return node.GetComputedStyle()
flackr 2017/06/29 14:34:06 Do some nodes have a null ComputedStyle? Maybe we
sunxd 2017/06/29 15:21:19 Done.
49 // touch-action from the target node up to root document, exclude any 18 ? node.GetComputedStyle()->GetEffectiveTouchAction()
50 // prohibited actions at or below the element that supports them. 19 : TouchAction::kTouchActionAuto;
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;
54 TouchAction handled_touch_actions = TouchAction::kTouchActionNone;
55 for (const Node* cur_node = &node; cur_node;
56 cur_node = ParentNodeAcrossFrames(cur_node)) {
57 if (LayoutObject* layout_object = cur_node->GetLayoutObject()) {
58 if (SupportsTouchAction(*layout_object)) {
59 TouchAction action = layout_object->Style()->GetTouchAction();
60 action |= handled_touch_actions;
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 }
73 }
74 return effective_touch_action;
75 } 20 }
76 21
77 } // namespace TouchActionUtil 22 } // namespace TouchActionUtil
78 } // namespace blink 23 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698