Tizen 2.1 base
[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(Evas_Object* evas, WebPageProxy* page, PageClientImpl* pageClient)
52     {
53         return adoptPtr(new TextSelection(evas, page, pageClient));
54     }
55     ~TextSelection();
56
57     void update();
58     bool isTextSelectionDowned() { return m_isTextSelectionDowned; }
59     void setIsTextSelectionDowned(bool isTextSelectionDowned) { m_isTextSelectionDowned = isTextSelectionDowned; }
60     bool isTextSelectionMode() { return m_isTextSelectionMode; }
61     void setIsTextSelectionMode(bool isTextSelectionMode);
62     bool isMagnifierVisible();
63     void updateHandlesAndContextMenu(bool isShow, bool isScrolling = false);
64     bool isTextSelectionEnable() { return m_isTextSelectionEnable; }
65     void setIsTextSelectionEnable(bool isTextSelectionEnable) { m_isTextSelectionEnable = isTextSelectionEnable; }
66     bool autoClearTextSelectionMode() { return m_autoClearTextSelectionMode; }
67     void setAutoClearTextSelectionMode(bool autoClearTextSelectionMode) { m_autoClearTextSelectionMode = autoClearTextSelectionMode; }
68     bool textSelectionDown(const WebCore::IntPoint& point, bool isStartedTextSelectionFromOutside = false);
69     void textSelectionMove(const WebCore::IntPoint& point, bool isStaredTextSelectionFromOutside = false);
70     void textSelectionUp(const WebCore::IntPoint& point, bool isStaredTextSelectionFromOutside = false);
71
72
73     // handle callback
74     void handleMouseDown(TextSelectionHandle* handle, const WebCore::IntPoint& position);
75     void handleMouseMove(TextSelectionHandle* handle, const WebCore::IntPoint& position);
76     void handleMouseUp(TextSelectionHandle* handle, const WebCore::IntPoint& position);
77
78     bool isTextSelectionHandleDowned() { return m_leftHandle->isMouseDowned() || m_rightHandle->isMouseDowned(); }
79 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
80     void textSelectionHandleDown(const WebCore::IntPoint& position);
81     void textSelectionHandleMove(const WebCore::IntPoint& position);
82     void textSelectionHandleUp();
83 #endif
84
85     friend class PageClientImpl; // to allow hideHandlers() call while zooming
86 private:
87     TextSelection(Evas_Object*, WebPageProxy*, PageClientImpl*);
88     void clear();
89     void hide();
90     void updateHandlers();
91     void hideHandlers();
92     void reloadMagnifier();
93     void showMagnifier();
94     void hideMagnifier();
95     void updateMagnifier(const WebCore::IntPoint& position);
96     void showContextMenu();
97     void hideContextMenu();
98     void setLeftSelectionToEvasPoint(const WebCore::IntPoint& evasPoint);
99     void setRightSelectionToEvasPoint(const WebCore::IntPoint& evasPoint);
100
101     void startMoveAnimator();
102     void stopMoveAnimator();
103     static void onMouseUp(void* data, Evas*, Evas_Object*, void* eventInfo);
104     static Eina_Bool moveAnimatorCallback(void*);
105
106 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
107     TextSelectionHandle* getSelectedHandle(const WebCore::IntPoint& position);
108 #endif
109
110 private:
111     Evas_Object* m_object;
112     EwkViewImpl* m_viewImpl;
113     TextSelectionHandle* m_leftHandle;
114     TextSelectionHandle* m_rightHandle;
115     TextSelectionMagnifier* m_magnifier;
116     WebPageProxy* m_page;
117     PageClientImpl* m_pageClient;
118     bool m_isTextSelectionDowned;
119     bool m_isTextSelectionMode;
120     bool m_isTextSelectionEnable;
121     bool m_autoClearTextSelectionMode;
122     Ecore_Animator* m_moveAnimator;
123 };
124
125 } // namespace WebKit
126
127 #endif // TIZEN_WEBKIT2_TEXT_SELECTION
128 #endif // TextSelection_h