Implement that a text selection handle can be moved over another text selection handle.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / TextSelection.h
1 /*
2  * Copyright (C) 2012 Samsung Electronics
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef TextSelection_h
27 #define TextSelection_h
28
29 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
30
31 #include "PageClientImpl.h"
32 #include "TextSelectionHandle.h"
33 #include "TextSelectionMagnifier.h"
34 #include "WebPageProxy.h"
35 #include <Evas.h>
36 #include <WebCore/IntPoint.h>
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/text/CString.h>
39 #include <wtf/text/WTFString.h>
40
41 class EwkViewImpl;
42
43 namespace WebKit {
44
45 class TextSelectionHandle;
46 class TextSelectionMagnifier;
47 class PageClientImpl;
48
49 class TextSelection {
50 public:
51     static PassOwnPtr<TextSelection> create(EwkViewImpl* viewImpl)
52     {
53         return adoptPtr(new TextSelection(viewImpl));
54     }
55     ~TextSelection();
56
57     enum HandleMovingDirection {
58         HandleMovingDirectionNone = 0,
59         HandleMovingDirectionNormal,
60         HandleMovingDirectionReverse,
61     };
62
63     void update();
64     bool isTextSelectionDowned() { return m_isTextSelectionDowned; }
65     void setIsTextSelectionDowned(bool isTextSelectionDowned) { m_isTextSelectionDowned = isTextSelectionDowned; }
66     bool isTextSelectionMode() { return m_isTextSelectionMode; }
67     void setIsTextSelectionMode(bool isTextSelectionMode);
68     bool isMagnifierVisible();
69     void updateHandlesAndContextMenu(bool isShow, bool isScrolling = false);
70     bool isEnabled();
71     bool isAutomaticClearEnabled();
72     bool textSelectionDown(const WebCore::IntPoint& point);
73     void textSelectionMove(const WebCore::IntPoint& point);
74     void textSelectionUp(const WebCore::IntPoint& point, bool isStaredTextSelectionFromOutside = false);
75
76     // handle callback
77     void handleMouseDown(TextSelectionHandle* handle, const WebCore::IntPoint& position);
78     void handleMouseMove(TextSelectionHandle* handle, const WebCore::IntPoint& position);
79     void handleMouseUp(TextSelectionHandle* handle, const WebCore::IntPoint& position);
80
81     bool isTextSelectionHandleDowned() { return m_leftHandle->isMouseDowned() || m_rightHandle->isMouseDowned(); }
82 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
83     void textSelectionHandleDown(const WebCore::IntPoint& position);
84     void textSelectionHandleMove(const WebCore::IntPoint& position);
85     void textSelectionHandleUp();
86 #endif
87
88     void requestToShow();
89     void initHandlesMouseDownedStatus();
90
91     void changeContextMenuPosition(WebCore::IntPoint& position);
92
93     friend class PageClientImpl; // to allow hideHandlers() call while zooming
94 private:
95     TextSelection(EwkViewImpl*);
96     void clear();
97     void hide();
98     void updateHandlers();
99     void hideHandlers();
100     void reloadMagnifier();
101     void showMagnifier();
102     void hideMagnifier();
103     void updateMagnifier(const WebCore::IntPoint& position);
104     void showContextMenu();
105     void hideContextMenu();
106     void setLeftSelectionToEvasPoint(const WebCore::IntPoint& evasPoint);
107     void setRightSelectionToEvasPoint(const WebCore::IntPoint& evasPoint);
108
109     void startMoveAnimator();
110     void stopMoveAnimator();
111     static void onMouseUp(void* data, Evas*, Evas_Object*, void* eventInfo);
112     static Eina_Bool moveAnimatorCallback(void*);
113
114 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
115     TextSelectionHandle* getSelectedHandle(const WebCore::IntPoint& position);
116 #endif
117
118     static Eina_Bool showTimerCallback(void* data);
119     void showHandlesAndContextMenu();
120
121 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
122     void informTextStyleState();
123 #endif
124
125 private:
126     EwkViewImpl* m_viewImpl;
127     TextSelectionHandle* m_leftHandle;
128     TextSelectionHandle* m_rightHandle;
129     TextSelectionMagnifier* m_magnifier;
130     bool m_isTextSelectionDowned;
131     bool m_isTextSelectionMode;
132     Ecore_Animator* m_moveAnimator;
133     Ecore_Timer* m_showTimer;
134     WebCore::IntRect m_lastLeftHandleRect;
135     WebCore::IntRect m_lastRightHandleRect;
136 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
137     TextSelectionHandle* m_selectedHandle;
138 #endif
139     int m_handleMovingDirection;
140 };
141
142 } // namespace WebKit
143
144 #endif // TIZEN_WEBKIT2_TEXT_SELECTION
145 #endif // TextSelection_h