[BlackBerry] SelectionHandler: bring back m_lastSelection attribute
[WebKit-https.git] / Source / WebKit / blackberry / WebKitSupport / SelectionHandler.h
1 /*
2  * Copyright (C) 2010, 2011, 2012, 2013 Research In Motion Limited. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #ifndef SelectionHandler_h
20 #define SelectionHandler_h
21
22 #include "BlackBerryPlatformIntRectRegion.h"
23 #include "BlackBerryPlatformPrimitives.h"
24 #include "BlackBerryPlatformStopWatch.h"
25 #include "Color.h"
26 #include "TextGranularity.h"
27
28 #include <wtf/Vector.h>
29
30 namespace WTF {
31 class String;
32 }
33
34 namespace WebCore {
35 class FloatQuad;
36 class IntPoint;
37 class IntRect;
38 class Node;
39 class VisiblePosition;
40 class VisibleSelection;
41 }
42
43 namespace BlackBerry {
44 namespace Platform {
45 class String;
46 }
47
48 namespace WebKit {
49
50 class FatFingersResult;
51 class WebPagePrivate;
52
53 class SelectionHandler {
54 public:
55     SelectionHandler(WebPagePrivate*);
56     ~SelectionHandler();
57
58     bool isSelectionActive() { return m_selectionActive; }
59     void setSelectionActive(bool active) { m_selectionActive = active; }
60
61     void cancelSelection();
62     BlackBerry::Platform::String selectedText() const;
63
64     bool selectionContains(const WebCore::IntPoint&);
65
66     void setSelection(const WebCore::IntPoint& start, const WebCore::IntPoint& end);
67     void selectAtPoint(const WebCore::IntPoint&, SelectionExpansionType);
68     void selectObject(const WebCore::IntPoint&, WebCore::TextGranularity);
69     void selectObject(WebCore::TextGranularity);
70     void selectObject(WebCore::Node*);
71
72     void selectionPositionChanged(bool forceUpdateWithoutChange = false);
73
74     void setCaretPosition(const WebCore::IntPoint&);
75
76     bool lastUpdatedEndPointIsValid() const { return m_lastUpdatedEndPointIsValid; }
77
78     void inputHandlerDidFinishProcessingChange();
79
80     void expandSelection(bool isScrollStarted);
81     void setOverlayExpansionHeight(int dy) { m_overlayExpansionHeight = dy; }
82     void setParagraphExpansionScrollMargin(const WebCore::IntSize&);
83
84 private:
85     void notifyCaretPositionChangedIfNeeded(bool userTouchTriggered = true);
86     void caretPositionChanged(bool userTouchTriggered);
87     void regionForTextQuads(WTF::Vector<WebCore::FloatQuad>&, BlackBerry::Platform::IntRectRegion&, bool shouldClipToVisibleContent = true) const;
88     WebCore::IntRect clippingRectForVisibleContent() const;
89     bool updateOrHandleInputSelection(WebCore::VisibleSelection& newSelection, const WebCore::IntPoint& relativeStart
90                                       , const WebCore::IntPoint& relativeEnd);
91     WebCore::Node* DOMContainerNodeForVisiblePosition(const WebCore::VisiblePosition&) const;
92     bool shouldUpdateSelectionOrCaretForPoint(const WebCore::IntPoint&, const WebCore::IntRect&, bool startCaret = true) const;
93     unsigned extendSelectionToFieldBoundary(bool isStartHandle, const WebCore::IntPoint& selectionPoint, WebCore::VisibleSelection& newSelection);
94     WebCore::IntPoint clipPointToVisibleContainer(const WebCore::IntPoint&) const;
95
96     void selectNextParagraph();
97     void drawAnimationOverlay(BlackBerry::Platform::IntRectRegion, bool isExpandingOverlayAtConstantRate, bool isStartOfSelection = false);
98     Platform::IntRectRegion regionForSelectionQuads(WebCore::VisibleSelection);
99     bool findNextAnimationOverlayRegion();
100     bool ensureSelectedTextVisible(const WebCore::IntPoint&, bool scrollIfNeeded);
101     bool expandSelectionToGranularity(WebCore::Frame*, WebCore::VisibleSelection, WebCore::TextGranularity, bool isInputMode);
102
103     bool inputNodeOverridesTouch() const;
104     BlackBerry::Platform::RequestedHandlePosition requestedSelectionHandlePosition(const WebCore::VisibleSelection&) const;
105
106     bool selectNodeIfFatFingersResultIsLink(FatFingersResult);
107
108     WebPagePrivate* m_webPage;
109
110     bool m_selectionActive;
111     bool m_caretActive;
112     bool m_lastUpdatedEndPointIsValid;
113     bool m_didSuppressCaretPositionChangedNotification;
114     BlackBerry::Platform::IntRectRegion m_lastSelectionRegion;
115     WebCore::VisiblePosition m_animationOverlayStartPos;
116     WebCore::VisiblePosition m_animationOverlayEndPos;
117     BlackBerry::Platform::IntRectRegion m_currentAnimationOverlayRegion;
118     BlackBerry::Platform::IntRectRegion m_nextAnimationOverlayRegion;
119     int m_overlayExpansionHeight;
120     WebCore::Color m_animationHighlightColor;
121
122     BlackBerry::Platform::StopWatch m_timer;
123
124     WebCore::IntSize m_scrollMargin;
125     WebCore::VisibleSelection m_lastSelection;
126 };
127
128 }
129 }
130
131 #endif // SelectionHandler_h