File: EventHandlingUtil.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (122 lines) | stat: -rw-r--r-- 4,444 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/input/EventHandlingUtil.h"

#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/layout/api/LayoutViewItem.h"
#include "core/paint/PaintLayer.h"
#include "platform/scroll/ScrollableArea.h"

namespace blink {
namespace EventHandlingUtil {

HitTestResult hitTestResultInFrame(LocalFrame* frame,
                                   const LayoutPoint& point,
                                   HitTestRequest::HitTestRequestType hitType) {
  HitTestResult result(HitTestRequest(hitType), point);

  if (!frame || frame->contentLayoutItem().isNull())
    return result;
  if (frame->view()) {
    IntRect rect = frame->view()->visibleContentRect(IncludeScrollbars);
    if (!rect.contains(roundedIntPoint(point)))
      return result;
  }
  frame->contentLayoutItem().hitTest(result);
  return result;
}

WebInputEventResult mergeEventResult(WebInputEventResult resultA,
                                     WebInputEventResult resultB) {
  // The ordering of the enumeration is specific. There are times that
  // multiple events fire and we need to combine them into a single
  // result code. The enumeration is based on the level of consumption that
  // is most significant. The enumeration is ordered with smaller specified
  // numbers first. Examples of merged results are:
  // (HandledApplication, HandledSystem) -> HandledSystem
  // (NotHandled, HandledApplication) -> HandledApplication
  static_assert(static_cast<int>(WebInputEventResult::NotHandled) == 0,
                "WebInputEventResult not ordered");
  static_assert(static_cast<int>(WebInputEventResult::HandledSuppressed) <
                    static_cast<int>(WebInputEventResult::HandledApplication),
                "WebInputEventResult not ordered");
  static_assert(static_cast<int>(WebInputEventResult::HandledApplication) <
                    static_cast<int>(WebInputEventResult::HandledSystem),
                "WebInputEventResult not ordered");
  return static_cast<WebInputEventResult>(
      max(static_cast<int>(resultA), static_cast<int>(resultB)));
}

WebInputEventResult toWebInputEventResult(DispatchEventResult result) {
  switch (result) {
    case DispatchEventResult::NotCanceled:
      return WebInputEventResult::NotHandled;
    case DispatchEventResult::CanceledByEventHandler:
      return WebInputEventResult::HandledApplication;
    case DispatchEventResult::CanceledByDefaultEventHandler:
      return WebInputEventResult::HandledSystem;
    case DispatchEventResult::CanceledBeforeDispatch:
      return WebInputEventResult::HandledSuppressed;
    default:
      NOTREACHED();
      return WebInputEventResult::HandledSystem;
  }
}

PaintLayer* layerForNode(Node* node) {
  if (!node)
    return nullptr;

  LayoutObject* layoutObject = node->layoutObject();
  if (!layoutObject)
    return nullptr;

  PaintLayer* layer = layoutObject->enclosingLayer();
  if (!layer)
    return nullptr;

  return layer;
}

ScrollableArea* associatedScrollableArea(const PaintLayer* layer) {
  if (PaintLayerScrollableArea* scrollableArea = layer->getScrollableArea()) {
    if (scrollableArea->scrollsOverflow())
      return scrollableArea;
  }

  return nullptr;
}

ContainerNode* parentForClickEvent(const Node& node) {
  // IE doesn't dispatch click events for mousedown/mouseup events across form
  // controls.
  if (node.isHTMLElement() && toHTMLElement(node).isInteractiveContent())
    return nullptr;

  return FlatTreeTraversal::parent(node);
}

LayoutPoint contentPointFromRootFrame(LocalFrame* frame,
                                      const IntPoint& pointInRootFrame) {
  FrameView* view = frame->view();
  // FIXME: Is it really OK to use the wrong coordinates here when view is 0?
  // Historically the code would just crash; this is clearly no worse than that.
  return view ? view->rootFrameToContents(pointInRootFrame) : pointInRootFrame;
}

MouseEventWithHitTestResults performMouseEventHitTest(
    LocalFrame* frame,
    const HitTestRequest& request,
    const PlatformMouseEvent& mev) {
  DCHECK(frame);
  DCHECK(frame->document());

  return frame->document()->performMouseEventHitTest(
      request, contentPointFromRootFrame(frame, mev.position()), mev);
}

}  // namespace EventHandlingUtil
}  // namespace blink