| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 3 * | 4 * |
| 4 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 6 * are met: | 7 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 12 * | 13 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (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. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 * | |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef DOMTimer_h | 27 #ifndef SelectionController_h |
| 28 #define DOMTimer_h | 28 #define SelectionController_h |
| 29 | 29 |
| 30 #include "bindings/core/v8/ScheduledAction.h" | |
| 31 #include "core/CoreExport.h" | 30 #include "core/CoreExport.h" |
| 32 #include "core/frame/SuspendableTimer.h" | 31 #include "core/editing/TextGranularity.h" |
| 33 #include "platform/UserGestureIndicator.h" | 32 #include "core/page/EventWithHitTestResults.h" |
| 34 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 35 #include "wtf/OwnPtr.h" | |
| 36 #include "wtf/PassOwnPtr.h" | |
| 37 #include "wtf/RefPtr.h" | |
| 38 | 34 |
| 39 namespace blink { | 35 namespace blink { |
| 40 | 36 |
| 41 class ExecutionContext; | 37 class FrameSelection; |
| 38 class HitTestResult; |
| 39 class LocalFrame; |
| 40 class VisibleSelection; |
| 42 | 41 |
| 43 class CORE_EXPORT DOMTimer final : public RefCountedWillBeGarbageCollectedFinali
zed<DOMTimer>, public SuspendableTimer { | 42 class SelectionController final : public NoBaseWillBeGarbageCollected<SelectionC
ontroller> { |
| 44 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(DOMTimer); | 43 WTF_MAKE_NONCOPYABLE(SelectionController); |
| 45 public: | 44 public: |
| 46 // Creates a new timer owned by the ExecutionContext, starts it and returns
its ID. | 45 static PassOwnPtrWillBeRawPtr<SelectionController> create(LocalFrame&); |
| 47 static int install(ExecutionContext*, PassOwnPtrWillBeRawPtr<ScheduledAction
>, int timeout, bool singleShot); | 46 DECLARE_TRACE(); |
| 48 static void removeByID(ExecutionContext*, int timeoutID); | |
| 49 | 47 |
| 50 virtual ~DOMTimer(); | 48 bool updateSelectionForMouseDownDispatchingSelectStart(Node*, const VisibleS
election&, TextGranularity); |
| 49 void handleMousePressEvent(const MouseEventWithHitTestResults&); |
| 50 bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&); |
| 51 bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&); |
| 52 bool handleMousePressEventTripleClick(const MouseEventWithHitTestResults&); |
| 53 void handleMouseDraggedEvent(const MouseEventWithHitTestResults&, const IntP
oint&, const LayoutPoint&, Node*, const IntPoint&); |
| 54 bool handleMouseReleaseEvent(const MouseEventWithHitTestResults&, const Layo
utPoint&); |
| 55 bool handlePasteGlobalSelection(const PlatformMouseEvent&); |
| 56 bool handleGestureLongPress(const PlatformGestureEvent&, const HitTestResult
&); |
| 51 | 57 |
| 52 // ActiveDOMObject | 58 void updateSelectionForMouseDrag(Node*, const LayoutPoint&, const IntPoint&)
; |
| 53 virtual void stop() override; | 59 void updateSelectionForMouseDrag(const HitTestResult&, Node*, const LayoutPo
int&, const IntPoint&); |
| 60 void sendContextMenuEvent(const MouseEventWithHitTestResults&, const LayoutP
oint&); |
| 61 void passMousePressEventToSubframe(const MouseEventWithHitTestResults&); |
| 54 | 62 |
| 55 // The following are essentially constants. All intervals are in seconds. | 63 void initializeSelectionState(); |
| 56 static double hiddenPageAlignmentInterval(); | 64 void setMouseDownMayStartSelect(bool); |
| 57 static double visiblePageAlignmentInterval(); | 65 bool mouseDownMayStartSelect() const; |
| 58 | 66 bool mouseDownWasSingleClickInSelection() const; |
| 59 // Eager finalization is needed to promptly stop this Timer object. | |
| 60 // Otherwise timer events might fire at an object that's slated for destruct
ion | |
| 61 // (when lazily swept), but some of its members (m_action) may already have | |
| 62 // been finalized & must not be accessed. | |
| 63 EAGERLY_FINALIZE(); | |
| 64 DECLARE_VIRTUAL_TRACE(); | |
| 65 | |
| 66 void disposeTimer(); | |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 friend class DOMTimerCoordinator; // For create(). | 69 explicit SelectionController(LocalFrame&); |
| 70 | 70 |
| 71 static PassRefPtrWillBeRawPtr<DOMTimer> create(ExecutionContext* context, Pa
ssOwnPtrWillBeRawPtr<ScheduledAction> action, int timeout, bool singleShot, int
timeoutID) | 71 enum AppendTrailingWhitespace { ShouldAppendTrailingWhitespace, DontAppendTr
ailingWhitespace }; |
| 72 { | 72 void selectClosestWordFromHitTestResult(const HitTestResult&, AppendTrailing
Whitespace); |
| 73 return adoptRefWillBeNoop(new DOMTimer(context, action, timeout, singleS
hot, timeoutID)); | 73 void selectClosestMisspellingFromHitTestResult(const HitTestResult&, AppendT
railingWhitespace); |
| 74 } | 74 void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults&); |
| 75 void selectClosestMisspellingFromMouseEvent(const MouseEventWithHitTestResul
ts&); |
| 76 void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResult
s&); |
| 75 | 77 |
| 76 DOMTimer(ExecutionContext*, PassOwnPtrWillBeRawPtr<ScheduledAction>, int int
erval, bool singleShot, int timeoutID); | |
| 77 virtual void fired() override; | |
| 78 | 78 |
| 79 // Retuns timer fire time rounded to the next multiple of timer alignment in
terval. | 79 RawPtrWillBeMember<LocalFrame> const m_frame; |
| 80 virtual double alignedFireTime(double) const override; | 80 bool m_mouseDownMayStartSelect; |
| 81 | 81 bool m_mouseDownWasSingleClickInSelection; |
| 82 int m_timeoutID; | 82 enum SelectionInitiationState { HaveNotStartedSelection, PlacedCaret, Extend
edSelection }; |
| 83 int m_nestingLevel; | 83 SelectionInitiationState m_selectionInitiationState; |
| 84 OwnPtrWillBeMember<ScheduledAction> m_action; | |
| 85 RefPtr<UserGestureToken> m_userGestureToken; | |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 } // namespace blink | 86 } // namespace blink |
| 89 | 87 #endif // SelectionController_h |
| 90 #endif // DOMTimer_h | |
| OLD | NEW |