Tizen 2.1 base
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / ewk_text_style.cpp
1 /*
2    Copyright (C) 2011 Samsung Electronics
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library 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     Library General Public License for more details.
13
14     You should have received a copy of the GNU Library General Public License
15     along with this library; see the file COPYING.LIB.  If not, write to
16     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21 #include "ewk_text_style.h"
22
23 #include <WebCore/IntPoint.h>
24
25 struct _Ewk_Text_Style {
26     Ewk_Text_Style_State underlineState;
27     Ewk_Text_Style_State italicState;
28     Ewk_Text_Style_State boldState;
29
30     struct {
31         Evas_Point startPoint;
32         Evas_Point endPoint;
33     } position;
34 };
35
36 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
37 Ewk_Text_Style* ewkTextStyleCreate(int underlineState, int italicState, int boldState, const WebCore::IntPoint& startPoint, const WebCore::IntPoint& endPoint)
38
39 {
40     Ewk_Text_Style* textStyle = new Ewk_Text_Style;
41
42     textStyle->underlineState = static_cast<Ewk_Text_Style_State>(underlineState);
43     textStyle->italicState = static_cast<Ewk_Text_Style_State>(italicState);
44     textStyle->boldState = static_cast<Ewk_Text_Style_State>(boldState);
45
46     textStyle->position.startPoint.x = startPoint.x();
47     textStyle->position.startPoint.y = startPoint.y();
48     textStyle->position.endPoint.x = endPoint.x();
49     textStyle->position.endPoint.y = endPoint.y();
50
51     return textStyle;
52 }
53
54 void ewkTextStyleDelete(Ewk_Text_Style* textStyle)
55 {
56     EINA_SAFETY_ON_NULL_RETURN(textStyle);
57
58     delete textStyle;
59 }
60 #endif
61
62 Ewk_Text_Style_State ewk_text_style_underline_get(Ewk_Text_Style* textStyle)
63 {
64 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
65     EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
66
67     return textStyle->underlineState;
68 #else
69     return EWK_TEXT_STYLE_STATE_FALSE;
70 #endif
71 }
72
73 Ewk_Text_Style_State ewk_text_style_italic_get(Ewk_Text_Style* textStyle)
74 {
75 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
76     EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
77
78     return textStyle->italicState;
79 #else
80     return EWK_TEXT_STYLE_STATE_FALSE;
81 #endif
82 }
83
84 Ewk_Text_Style_State ewk_text_style_bold_get(Ewk_Text_Style* textStyle)
85 {
86 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
87     EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, EWK_TEXT_STYLE_STATE_FALSE);
88
89     return textStyle->boldState;
90 #else
91     return EWK_TEXT_STYLE_STATE_FALSE;
92 #endif
93 }
94
95 Eina_Bool ewk_text_style_position_get(Ewk_Text_Style* textStyle, Evas_Point* startPoint, Evas_Point* endPoint)
96 {
97 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
98     EINA_SAFETY_ON_NULL_RETURN_VAL(textStyle, false);
99
100     startPoint->x = textStyle->position.startPoint.x;
101     startPoint->y = textStyle->position.startPoint.y;
102
103     endPoint->x = textStyle->position.endPoint.x;
104     endPoint->y = textStyle->position.endPoint.y;
105
106     return true;
107 #else
108     return false;
109 #endif
110 }