Tizen 2.2.1
[framework/osp/web.git] / src / controls / FWebCtrl_WebNotificationHandler.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_WebNotificationHandler.cpp
20  * @brief               The file contains the definition of _WebNotificationHandler class.
21  */
22
23 #include "FWebCtrl_WebNotification.h"
24 #include "FWebCtrl_WebNotificationHandler.h"
25 #include <FBaseSysLog.h>
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Graphics;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31
32 namespace Tizen { namespace Web { namespace Controls
33 {
34
35 _WebNotificationHandler::_WebNotificationHandler(void)
36                                         : __pNotification(null)
37                                         , __state(NOTIFCATION_STATE_NORMAL)
38 {
39 }
40
41 _WebNotificationHandler::~_WebNotificationHandler(void)
42 {
43 }
44
45
46 result
47 _WebNotificationHandler::Construct(_WebNotification* pNotification)
48 {
49
50         SysTryReturnResult(NID_WEB_CTRL, pNotification != null, E_INVALID_ARG, "Notification instancce cannot be null.");
51
52         __pNotification = pNotification;
53         __pallete[NOTIFCATION_COLOR_BG_NORMAL]  = NOTIFCATION_NORMAL_BLACKGROUND_COLOR;
54         __pallete[NOTIFCATION_COLOR_FG_NORMAL]  = NOTIFCATION_NORMAL_FOREGROUND_COLOR;
55
56         __bounds = __pNotification->GetBounds();
57         return E_SUCCESS;
58 }
59
60
61 int
62 _WebNotificationHandler::GetState(void) const
63 {
64         return __state;
65 }
66
67
68 void
69 _WebNotificationHandler::SetState(int newState)
70 {
71         __state = newState;
72 }
73
74
75 bool
76 _WebNotificationHandler::OnPreviewTouchMoved(Control &source, const TouchEventInfo &touchEventInfo)
77 {
78         return false;
79 }
80
81
82 bool
83 _WebNotificationHandler::OnPreviewTouchPressed(Control &source, const TouchEventInfo &touchEventInfo)
84 {
85         return false;
86 }
87
88
89 bool
90 _WebNotificationHandler::OnPreviewTouchReleased(Control &source, const TouchEventInfo &touchEventInfo)
91 {
92         return false;
93 }
94
95
96 bool
97 _WebNotificationHandler::OnTouchCanceled(Control &source, const TouchEventInfo &touchEventInfo)
98 {
99         if (GetState() == NOTIFCATION_STATE_PRESSED)
100         {
101                 SetState(NOTIFCATION_STATE_NORMAL);
102                 __pNotification->Invalidate(false);
103         }
104         return true;
105 }
106
107
108 bool
109 _WebNotificationHandler::OnTouchMoved(Control &source, const TouchEventInfo &touchEventInfo)
110 {
111         return false;
112 }
113
114
115 bool
116 _WebNotificationHandler::OnTouchPressed(Control &source, const TouchEventInfo &touchEventInfo)
117 {
118         if (GetState() == NOTIFCATION_STATE_NORMAL)
119         {
120                 SetState(NOTIFCATION_STATE_PRESSED);
121                 __pNotification->Invalidate(false);
122         }
123         return true;
124 }
125
126
127 bool
128 _WebNotificationHandler::OnTouchReleased(Control &source, const TouchEventInfo &touchEventInfo)
129 {
130         if (GetState() == NOTIFCATION_STATE_PRESSED)
131         {
132                 SetState(NOTIFCATION_STATE_NORMAL);
133                 __pNotification->Invalidate(false);
134
135                 __pNotification->OnClicked();
136         }
137         return true;
138 }
139
140
141 result
142 _WebNotificationHandler::DrawNotification(Canvas& canvas)
143 {
144         canvas.SetBackgroundColor(Color(0, 0, 0, 0));
145         canvas.Clear();
146         canvas.FillRoundRectangle(__pallete[NOTIFCATION_COLOR_BG_NORMAL], Rectangle(0, 0 , __bounds.width, __bounds.height), Dimension(5, 5));
147
148         EnrichedText enriched;
149         enriched.Construct(Dimension(__bounds.width, __bounds.height));
150         enriched.SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
151         enriched.SetHorizontalAlignment(TEXT_ALIGNMENT_CENTER);
152
153         TextElement element;
154         element.Construct(__text);
155 //      element.SetTextColor(__pallete[NOTIFCATION_COLOR_FG_NORMAL]);
156
157         enriched.Add(element);
158         canvas.DrawText(Point(0, 0), enriched);
159         enriched.RemoveAll(false);
160
161         return E_SUCCESS;
162 }
163
164
165 String
166 _WebNotificationHandler::GetText(void) const
167 {
168         return __text;
169 }
170
171
172 void
173 _WebNotificationHandler::SetText(const String& text)
174 {
175
176         __text = text;
177 }
178
179 }}}