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

Side by Side Diff: Source/core/input/EventHandler.h

Issue 1113323002: [Reland] Refactor the selection code in EventHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 5 years, 6 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
« no previous file with comments | « Source/core/html/HTMLLabelElement.cpp ('k') | Source/core/input/EventHandler.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef EventHandler_h 26 #ifndef EventHandler_h
27 #define EventHandler_h 27 #define EventHandler_h
28 28
29 #include "core/CoreExport.h" 29 #include "core/CoreExport.h"
30 #include "core/editing/TextGranularity.h"
31 #include "core/events/TextEventInputType.h" 30 #include "core/events/TextEventInputType.h"
32 #include "core/layout/HitTestRequest.h" 31 #include "core/layout/HitTestRequest.h"
33 #include "core/page/DragActions.h" 32 #include "core/page/DragActions.h"
34 #include "core/page/EventWithHitTestResults.h" 33 #include "core/page/EventWithHitTestResults.h"
35 #include "core/style/ComputedStyleConstants.h" 34 #include "core/style/ComputedStyleConstants.h"
36 #include "platform/Cursor.h" 35 #include "platform/Cursor.h"
37 #include "platform/PlatformMouseEvent.h" 36 #include "platform/PlatformMouseEvent.h"
38 #include "platform/Timer.h" 37 #include "platform/Timer.h"
39 #include "platform/UserGestureIndicator.h" 38 #include "platform/UserGestureIndicator.h"
40 #include "platform/geometry/LayoutPoint.h" 39 #include "platform/geometry/LayoutPoint.h"
(...skipping 28 matching lines...) Expand all
69 class Node; 68 class Node;
70 class OptionalCursor; 69 class OptionalCursor;
71 class PlatformGestureEvent; 70 class PlatformGestureEvent;
72 class PlatformKeyboardEvent; 71 class PlatformKeyboardEvent;
73 class PlatformTouchEvent; 72 class PlatformTouchEvent;
74 class PlatformWheelEvent; 73 class PlatformWheelEvent;
75 class LayoutObject; 74 class LayoutObject;
76 class ScrollableArea; 75 class ScrollableArea;
77 class Scrollbar; 76 class Scrollbar;
78 class ScrollState; 77 class ScrollState;
78 class SelectionController;
79 class TextEvent; 79 class TextEvent;
80 class VisibleSelection;
81 class WheelEvent; 80 class WheelEvent;
82 class Widget; 81 class Widget;
83 82
84 enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTraili ngWhitespace };
85 enum class DragInitiator; 83 enum class DragInitiator;
86 84
87 class CORE_EXPORT EventHandler : public NoBaseWillBeGarbageCollectedFinalized<Ev entHandler> { 85 class CORE_EXPORT EventHandler : public NoBaseWillBeGarbageCollectedFinalized<Ev entHandler> {
88 WTF_MAKE_NONCOPYABLE(EventHandler); 86 WTF_MAKE_NONCOPYABLE(EventHandler);
89 public: 87 public:
90 explicit EventHandler(LocalFrame*); 88 explicit EventHandler(LocalFrame*);
91 ~EventHandler(); 89 ~EventHandler();
92 DECLARE_TRACE(); 90 DECLARE_TRACE();
93 91
94 void clear(); 92 void clear();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 189
192 bool handleTouchEvent(const PlatformTouchEvent&); 190 bool handleTouchEvent(const PlatformTouchEvent&);
193 191
194 bool useHandCursor(Node*, bool isOverLink); 192 bool useHandCursor(Node*, bool isOverLink);
195 193
196 void notifyElementActivated(); 194 void notifyElementActivated();
197 195
198 PassRefPtr<UserGestureToken> takeLastMouseDownGestureToken() { return m_last MouseDownUserGestureToken.release(); } 196 PassRefPtr<UserGestureToken> takeLastMouseDownGestureToken() { return m_last MouseDownUserGestureToken.release(); }
199 197
200 int clickCount() { return m_clickCount; } 198 int clickCount() { return m_clickCount; }
201 bool mouseDownWasSingleClickInSelection() { return m_mouseDownWasSingleClick InSelection; } 199
200 SelectionController& selectionController() const { return *m_selectionContro ller; }
202 201
203 private: 202 private:
204 static DragState& dragState(); 203 static DragState& dragState();
205 204
206 DataTransfer* createDraggingDataTransfer() const; 205 DataTransfer* createDraggingDataTransfer() const;
207 206
208 bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleS election&, TextGranularity);
209 void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailing Whitespace);
210 void selectClosestMisspellingFromHitTestResult(const HitTestResult&, AppendT railingWhitespace);
211 void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&);
212 void selectClosestMisspellingFromMouseEvent(const MouseEventWithHitTestResul ts&);
213 void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResult s&);
214
215 bool handleMouseMoveOrLeaveEvent(const PlatformMouseEvent&, HitTestResult* h overedNode = nullptr, bool onlyUpdateScrollbars = false, bool forceLeave = false ); 207 bool handleMouseMoveOrLeaveEvent(const PlatformMouseEvent&, HitTestResult* h overedNode = nullptr, bool onlyUpdateScrollbars = false, bool forceLeave = false );
216 bool handleMousePressEvent(const MouseEventWithHitTestResults&); 208 bool handleMousePressEvent(const MouseEventWithHitTestResults&);
217 bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&);
218 bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
219 bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&);
220 bool handleMouseFocus(const MouseEventWithHitTestResults&); 209 bool handleMouseFocus(const MouseEventWithHitTestResults&);
221 bool handleMouseDraggedEvent(const MouseEventWithHitTestResults&); 210 bool handleMouseDraggedEvent(const MouseEventWithHitTestResults&);
222 bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&); 211 bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&);
223 212
224 bool handlePasteGlobalSelection(const PlatformMouseEvent&);
225
226 HitTestRequest::HitTestRequestType getHitTypeForGestureType(PlatformEvent::T ype); 213 HitTestRequest::HitTestRequestType getHitTypeForGestureType(PlatformEvent::T ype);
227 void applyTouchAdjustment(PlatformGestureEvent*, HitTestResult*); 214 void applyTouchAdjustment(PlatformGestureEvent*, HitTestResult*);
228 bool handleGestureTap(const GestureEventWithHitTestResults&); 215 bool handleGestureTap(const GestureEventWithHitTestResults&);
229 bool handleGestureLongPress(const GestureEventWithHitTestResults&); 216 bool handleGestureLongPress(const GestureEventWithHitTestResults&);
230 bool handleGestureLongTap(const GestureEventWithHitTestResults&); 217 bool handleGestureLongTap(const GestureEventWithHitTestResults&);
231 bool handleGestureScrollUpdate(const PlatformGestureEvent&); 218 bool handleGestureScrollUpdate(const PlatformGestureEvent&);
232 bool handleGestureScrollBegin(const PlatformGestureEvent&); 219 bool handleGestureScrollBegin(const PlatformGestureEvent&);
233 void clearGestureScrollState(); 220 void clearGestureScrollState();
234 221
235 bool shouldApplyTouchAdjustment(const PlatformGestureEvent&) const; 222 bool shouldApplyTouchAdjustment(const PlatformGestureEvent&) const;
236 223
237 OptionalCursor selectCursor(const HitTestResult&); 224 OptionalCursor selectCursor(const HitTestResult&);
238 OptionalCursor selectAutoCursor(const HitTestResult&, Node*, const Cursor& i Beam); 225 OptionalCursor selectAutoCursor(const HitTestResult&, Node*, const Cursor& i Beam);
239 226
240 void hoverTimerFired(Timer<EventHandler>*); 227 void hoverTimerFired(Timer<EventHandler>*);
241 void cursorUpdateTimerFired(Timer<EventHandler>*); 228 void cursorUpdateTimerFired(Timer<EventHandler>*);
242 void activeIntervalTimerFired(Timer<EventHandler>*); 229 void activeIntervalTimerFired(Timer<EventHandler>*);
243 230
244 bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
245
246 void fakeMouseMoveEventTimerFired(Timer<EventHandler>*); 231 void fakeMouseMoveEventTimerFired(Timer<EventHandler>*);
247 void cancelFakeMouseMoveEvent(); 232 void cancelFakeMouseMoveEvent();
248 bool isCursorVisible() const; 233 bool isCursorVisible() const;
249 void updateCursor(); 234 void updateCursor();
250 235
251 ScrollableArea* associatedScrollableArea(const DeprecatedPaintLayer*) const; 236 ScrollableArea* associatedScrollableArea(const DeprecatedPaintLayer*) const;
252 237
253 // Scrolls the elements of the DOM tree. Returns true if a node was scrolled . 238 // Scrolls the elements of the DOM tree. Returns true if a node was scrolled .
254 // False if we reached the root and couldn't scroll anything. 239 // False if we reached the root and couldn't scroll anything.
255 // direction - The direction to scroll in. If this is a logical direction, i t will be 240 // direction - The direction to scroll in. If this is a logical direction, i t will be
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 286
302 bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&); 287 bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&);
303 288
304 bool passWheelEventToWidget(const PlatformWheelEvent&, Widget&); 289 bool passWheelEventToWidget(const PlatformWheelEvent&, Widget&);
305 void defaultSpaceEventHandler(KeyboardEvent*); 290 void defaultSpaceEventHandler(KeyboardEvent*);
306 void defaultBackspaceEventHandler(KeyboardEvent*); 291 void defaultBackspaceEventHandler(KeyboardEvent*);
307 void defaultTabEventHandler(KeyboardEvent*); 292 void defaultTabEventHandler(KeyboardEvent*);
308 void defaultEscapeEventHandler(KeyboardEvent*); 293 void defaultEscapeEventHandler(KeyboardEvent*);
309 void defaultArrowEventHandler(WebFocusType, KeyboardEvent*); 294 void defaultArrowEventHandler(WebFocusType, KeyboardEvent*);
310 295
311 void updateSelectionForMouseDrag(const HitTestResult&);
312
313 void updateLastScrollbarUnderMouse(Scrollbar*, bool); 296 void updateLastScrollbarUnderMouse(Scrollbar*, bool);
314 297
315 void setFrameWasScrolledByUser(); 298 void setFrameWasScrolledByUser();
316 299
317 bool capturesDragging() const { return m_capturesDragging; } 300 bool capturesDragging() const { return m_capturesDragging; }
318 301
319 bool handleGestureShowPress(); 302 bool handleGestureShowPress();
320 303
321 bool handleScrollGestureOnResizer(Node*, const PlatformGestureEvent&); 304 bool handleScrollGestureOnResizer(Node*, const PlatformGestureEvent&);
322 305
(...skipping 12 matching lines...) Expand all
335 318
336 // NOTE: If adding a new field to this class please ensure that it is 319 // NOTE: If adding a new field to this class please ensure that it is
337 // cleared in |EventHandler::clear()|. 320 // cleared in |EventHandler::clear()|.
338 321
339 LocalFrame* const m_frame; 322 LocalFrame* const m_frame;
340 323
341 bool m_mousePressed; 324 bool m_mousePressed;
342 bool m_capturesDragging; 325 bool m_capturesDragging;
343 RefPtrWillBeMember<Node> m_mousePressNode; 326 RefPtrWillBeMember<Node> m_mousePressNode;
344 327
345 bool m_mouseDownMayStartSelect;
346 bool m_mouseDownMayStartDrag; 328 bool m_mouseDownMayStartDrag;
347 bool m_mouseDownWasSingleClickInSelection; 329 const OwnPtrWillBeMember<SelectionController> m_selectionController;
348 enum SelectionInitiationState { HaveNotStartedSelection, PlacedCaret, Extend edSelection };
349 SelectionInitiationState m_selectionInitiationState;
350 330
351 LayoutPoint m_dragStartPos; 331 LayoutPoint m_dragStartPos;
352 332
353 Timer<EventHandler> m_hoverTimer; 333 Timer<EventHandler> m_hoverTimer;
354 334
355 // TODO(rbyers): Mouse cursor update is page-wide, not per-frame. Page-wide state 335 // TODO(rbyers): Mouse cursor update is page-wide, not per-frame. Page-wide state
356 // should move out of EventHandler to a new PageEventHandler class. crbug.co m/449649 336 // should move out of EventHandler to a new PageEventHandler class. crbug.co m/449649
357 Timer<EventHandler> m_cursorUpdateTimer; 337 Timer<EventHandler> m_cursorUpdateTimer;
358 338
359 bool m_mouseDownMayStartAutoscroll; 339 bool m_mouseDownMayStartAutoscroll;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // scroll sequence in this frame, or any child frames. Only used 411 // scroll sequence in this frame, or any child frames. Only used
432 // with ScrollCustomization. If some delta has been consumed, a 412 // with ScrollCustomization. If some delta has been consumed, a
433 // scroll which shouldn't propagate can't cause any element to 413 // scroll which shouldn't propagate can't cause any element to
434 // scroll other than the |m_previousGestureScrolledNode|. 414 // scroll other than the |m_previousGestureScrolledNode|.
435 bool m_deltaConsumedForScrollSequence; 415 bool m_deltaConsumedForScrollSequence;
436 }; 416 };
437 417
438 } // namespace blink 418 } // namespace blink
439 419
440 #endif // EventHandler_h 420 #endif // EventHandler_h
OLDNEW
« no previous file with comments | « Source/core/html/HTMLLabelElement.cpp ('k') | Source/core/input/EventHandler.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698