Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_ScrollPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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                FUiCtrl_ScrollPresenter.cpp
20  * @brief               This is the implementation file for the %_ScrollPresenter class.
21  */
22
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include <FGrpColor.h>
26 #include <FGrpRectangle.h>
27 #include <FGrpCanvas.h>
28 #include <FGrp_BitmapImpl.h>
29 #include <FUiAnimVisualElementAnimation.h>
30 #include <FUiAnimVisualElementAnimationProvider.h>
31 #include "FUi_ResourceManager.h"
32 #include "FUi_UiTouchEvent.h"
33 #include "FUi_Math.h"
34 #include "FUiAnim_TransformMatrix3Df.h"
35 #include "FUiAnim_VisualElement.h"
36 #include "FUiCtrl_ScrollPresenter.h"
37 #include "FUiCtrl_UiScrollEvent.h"
38 #include "FUiCtrl_UiScrollEventArg.h"
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Ui::Animations;
45
46 namespace
47 {
48 const float SCROLL_OPACITY_ON = 1.0f;
49 const float SCROLL_OPACITY_DARK_DIM =0.6f;
50 const float SCROLL_OPACITY_LIGHT_DIM = 0.3f;
51 const float SCROLL_OPACITY_OFF = 0.0f;
52 const float SCROLLING_EFFECT_MAX_POSITION = 100.0f;
53 const float SCROLLING_EFFECT_MIN_SCALE_RATE = 0.95f;
54 }
55
56 namespace Tizen { namespace Ui { namespace Controls
57 {
58
59 #ifndef MAX
60 #define MAX(a, b) ((a) > (b) ? (a) : (b))
61 #define MIN(a, b) ((a) < (b) ? (a) : (b))
62 #endif
63
64 _ScrollPresenter::_ScrollPresenter(void)
65         : __pParentCtrl(null)
66         , __pScrollCtrl(null)
67         , __scrollDirection(SCROLL_DIRECTION_VERTICAL)
68         , __enableFadeEffect(false)
69         , __enableJumpToTop(false)
70         , __enableHandler(false)
71         , __enableScrollingEffect(false)
72         , __enableOverScrollingEffect(false)
73         , __isContextMenuScroll(false)
74         , __parentUsingViewport(true)
75         , __viewRange(0.0f)
76         , __scrollRange(0.0f)
77         , __scrollPositionCurr(0.0f)
78         , __fadeIn(false)
79         , __fadeOut(false)
80         , __scrollVisibility(false)
81         , __scrollingEffectVisibility(false)
82         , __parentBouncingRate(0.0f)
83         , __fadeEffectDuration_ms(5000)
84         , __needUpdateThumb(false)
85         , __needUpdateJumpTopTop(false)
86         , __needUpdateHandler(false)
87         , __needUpdateScrollingEffect(false)
88         , __handlerTouched(false)
89         , __handlerTouchedPosition(0.0f)
90         , __jumpToTopPressed(false)
91         , __pScrollEvent(null)
92         , __pCtrlVe(null)
93         , __pThumbVe(null)
94         , __pJumpToTopVe(null)
95         , __pHandlerVe(null)
96         , __pFrontScrollingEffectVe(null)
97         , __pReerScrollingEffectVe(null)
98         , __thumbColor(0x00000000)
99         , __jumpToTopColor(0x00000000)
100         , __jumpToTopColorPressed(0x00000000)
101         , __buttonColor(0x00000000)
102         , __buttonColorPressed(0x00000000)
103         , __pThumbBitmap(null)
104         , __pThumbEffectBitmap(null)
105         , __pJumpToTopBitmap(null)
106         , __pJumpToTopPressBitmap(null)
107         , __pJumpToTopEfBitmap(null)
108         , __pButtonBitmap(null)
109         , __pButtonEfBitmap(null)
110         , __pButtonPressBitmap(null)
111         , __pButtonPressEfBitmap(null)
112         , __pHandlerBitmap(null)
113         , __pFrontScrollingEffectBitmap(null)
114         , __pReerScrollingEffectBitmap(null)
115         , __thumbSizeMin(0.0f, 0.0f)
116         , __thumbMargin(0.0f)
117         , __jumpToTopSize(0.0f, 0.0f)
118         , __jumpToTopMarginRight(0.0f)
119         , __jumpToTopMarginTop(0.0f)
120         , __handlerSizeMin(0.0f, 0.0f)
121         , __handlerMarginLeft(0.0f)
122         , __handlerMarginRight(0.0f)
123         , __handlerMarginTop(0.0f)
124         , __handlerMarginBottom(0.0f)
125         , __scrollingEffectWidthLeft(0.0f)
126         , __scrollingEffectWidthRight(0.0f)
127         , __scrollingEffectHeightTop(0.0f)
128         , __scrollingEffectHeightBottom(0.0f)
129         , __beforeBouncingMatrixHash()
130 {
131 }
132
133 _ScrollPresenter::~_ScrollPresenter(void)
134 {
135         delete __pScrollEvent;
136         __pScrollEvent = null;
137
138         __beforeBouncingMatrixHash.RemoveAll(true);
139
140         if (__pThumbVe != null)
141         {
142                 __pThumbVe->Destroy();
143                 __pThumbVe = null;
144         }
145
146         if (__pJumpToTopVe != null)
147         {
148                 __pJumpToTopVe->Destroy();
149                 __pJumpToTopVe = null;
150         }
151
152         if (__pHandlerVe != null)
153         {
154                 __pHandlerVe->Destroy();
155                 __pHandlerVe = null;
156         }
157
158         if (__pFrontScrollingEffectVe != null)
159         {
160                 __pFrontScrollingEffectVe->RemoveAllAnimations();
161                 __pFrontScrollingEffectVe->Destroy();
162                 __pFrontScrollingEffectVe = null;
163         }
164
165         if (__pReerScrollingEffectVe != null)
166         {
167                 __pReerScrollingEffectVe->RemoveAllAnimations();
168                 __pReerScrollingEffectVe->Destroy();
169                 __pReerScrollingEffectVe = null;
170         }
171
172         if (__pCtrlVe != null)
173         {
174                 __pCtrlVe->RemoveAllAnimations();
175                 __pCtrlVe->SetAnimationProvider(null);
176                 __pCtrlVe->Destroy();
177                 __pCtrlVe = null;
178         }
179
180         ReleaseBitmapResources();
181 }
182
183 _ScrollPresenter*
184 _ScrollPresenter::CreateScrollPresenterN(_Control& parentCtrl,
185                                                                                                         _Scroll& scrollCtrl,
186                                                                                                         _ScrollDirection scrollDirection,
187                                                                                                         bool enableFadeEffect,
188                                                                                                         bool enableJumpToTop,
189                                                                                                         bool enableHandler,
190                                                                                                         bool visibility,
191                                                                                                         float viewRange,
192                                                                                                         float scrollRange,
193                                                                                                         float scrollPosition)
194 {
195         SysTryReturn(NID_UI_CTRL, ((scrollRange >= viewRange) && (scrollRange != 0)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
196         SysTryReturn(NID_UI_CTRL, scrollPosition >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
197
198         _ScrollPresenter* pPresenter = new (std::nothrow) _ScrollPresenter();
199         SysTryReturn(NID_UI_CTRL, pPresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
200
201         result r = pPresenter->Construct(parentCtrl,
202                                                                                 scrollCtrl,
203                                                                                 scrollDirection,
204                                                                                 enableFadeEffect,
205                                                                                 enableJumpToTop,
206                                                                                 enableHandler,
207                                                                                 visibility,
208                                                                                 viewRange,
209                                                                                 scrollRange,
210                                                                                 scrollPosition);
211
212         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
213
214         SetLastResult(E_SUCCESS);
215         return pPresenter;
216
217 CATCH:
218         delete pPresenter;
219
220         return null;
221 }
222
223 result
224 _ScrollPresenter::SetScrollDirection(_ScrollDirection scrollDirection)
225 {
226         if (__scrollDirection == scrollDirection)
227         {
228                 return E_SUCCESS;
229         }
230
231         // load color/shape configuration and bitmap resources
232         result r = LoadResources(scrollDirection, _CONTROL_ORIENTATION_PORTRAIT);
233         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load resources.");
234
235         // reset attributes
236         __scrollDirection = scrollDirection;
237
238         // reset the bounds of scroll control
239         FloatRectangle bounds = GetParentCtrl().GetBoundsF();
240         bounds.SetPosition(0.0f, 0.0f);
241         r = GetControl().SetBounds(bounds);
242         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _Scroll.");
243
244         // relayout scroll children.
245         r = RelayoutScrollChildren(__scrollDirection);
246         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to relayout scroll chilren");
247
248         return E_SUCCESS;
249 }
250
251 _ScrollDirection
252 _ScrollPresenter::GetScrollDirection(void) const
253 {
254         return __scrollDirection;
255 }
256
257 result
258 _ScrollPresenter::SetScrollRange(float viewRange, float scrollRange)
259 {
260         SysTryReturn(NID_UI_CTRL, ((scrollRange >= viewRange) && (scrollRange != 0)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
261
262         if (__viewRange == viewRange && __scrollRange == scrollRange)
263         {
264                 return E_SUCCESS;
265         }
266
267         __viewRange = viewRange;
268         __scrollRange = scrollRange;
269
270         result r = RelayoutScrollChildren(__scrollDirection);
271         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to relayout scroll chilren");
272
273         return E_SUCCESS;
274 }
275
276 void
277 _ScrollPresenter::GetScrollRange(float* pViewRange, float* pScrollRange) const
278 {
279         SysTryReturnVoidResult(NID_UI_CTRL,
280                                         !((pViewRange == null) && (pScrollRange == null)),
281                                         E_INVALID_ARG,"[E_INVALID_ARG] Input parameter is invalid.");
282
283         *pViewRange = __viewRange;
284         *pScrollRange = __scrollRange;
285
286         return;
287 }
288
289 result
290 _ScrollPresenter::SetScrollPosition(float scrollPosition)
291 {
292         result r = E_SUCCESS;
293
294         if (scrollPosition != __scrollPositionCurr)
295         {
296
297                 if (!__enableScrollingEffect)
298                 {
299                         if (scrollPosition < 0.0f)
300                         {
301                                 scrollPosition = 0.0f;
302                         }
303                         else if (scrollPosition > (__scrollRange - __viewRange))
304                         {
305                                 scrollPosition = (__scrollRange - __viewRange);
306                         }
307                 }
308                 __scrollPositionCurr = scrollPosition;
309
310                 if (__enableJumpToTop)
311                 {
312                         if ((_FloatCompare(__scrollPositionCurr, 0.0f) || __scrollPositionCurr < 0.0f) && (__pJumpToTopVe->GetOpacity() > 0.0f))
313                         {
314                                 __pCtrlVe->SetImplicitAnimationEnabled(true);
315                                 __pJumpToTopVe->SetImplicitAnimationEnabled(true);
316
317                                 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
318
319                                 __pJumpToTopVe->SetImplicitAnimationEnabled(false);
320                                 __pCtrlVe->SetImplicitAnimationEnabled(false);
321                         }
322                         else if ((__scrollPositionCurr > 0.0f) && (__pJumpToTopVe->GetOpacity() < 1.0f))
323                         {
324                                 __pCtrlVe->SetImplicitAnimationEnabled(true);
325                                 __pJumpToTopVe->SetImplicitAnimationEnabled(true);
326
327                                 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_ON);
328
329                                 __pJumpToTopVe->SetImplicitAnimationEnabled(false);
330                                 __pCtrlVe->SetImplicitAnimationEnabled(false);
331                         }
332                         // else keep up current visibility.
333
334                 }
335
336                 if (__enableHandler)
337                 {
338                         FloatPoint handlerPosition = CalculateHandlerPosition(__scrollDirection);
339                         FloatRectangle handlerBounds(handlerPosition.x, handlerPosition.y, __pHandlerVe->GetBounds().width, __pHandlerVe->GetBounds().height);
340                         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
341
342                         if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
343                         {
344                                 if (handlerPosition.x < 0.0f)
345                                 {
346                                         handlerBounds.x = 0.0f;
347                                 }
348                                 else if (handlerPosition.x > scrollCtrlBounds.width - handlerBounds.width)
349                                 {
350                                         handlerBounds.x =scrollCtrlBounds.width - handlerBounds.width;
351                                 }
352                         }
353                         else
354                         {
355                                 if (handlerPosition.y < 0.0f)
356                                 {
357                                         handlerBounds.y = 0.0f;
358                                 }
359                                 else if (handlerPosition.y > scrollCtrlBounds.height - handlerBounds.height)
360                                 {
361                                         handlerBounds.y = scrollCtrlBounds.height - handlerBounds.height;
362                                 }
363                         }
364
365                         __pHandlerVe->SetBounds(handlerBounds);
366                 }
367                 else
368                 {
369                         FloatPoint thumbPosition = CalculateThumbPosition(__scrollDirection);
370                         FloatRectangle thumbBounds(thumbPosition.x, thumbPosition.y, __pThumbVe->GetBounds().width, __pThumbVe->GetBounds().height);
371                         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
372
373                         if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
374                         {
375                                 if (thumbPosition.x < 0.0f)
376                                 {
377                                         thumbBounds.x = 0.0f;
378                                 }
379                                 else if (thumbPosition.x > scrollCtrlBounds.width - thumbBounds.width)
380                                 {
381                                         thumbBounds.x = scrollCtrlBounds.width - thumbBounds.width;
382                                 }
383                         }
384                         else
385                         {
386                                 if (thumbPosition.y < 0.0f)
387                                 {
388                                         thumbBounds.y = 0.0f;
389                                 }
390                                 else if (thumbPosition.y > scrollCtrlBounds.height - thumbBounds.height)
391                                 {
392                                         thumbBounds.y = scrollCtrlBounds.height - thumbBounds.height;
393                                 }
394                         }
395
396                         __pThumbVe->SetBounds(thumbBounds);
397                 }
398
399                 r = SetScrollingEffect();
400                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
401         }
402
403         return r;
404 }
405
406 float
407 _ScrollPresenter::GetScrollPosition(void) const
408 {
409         return __scrollPositionCurr;
410 }
411
412 result
413 _ScrollPresenter::SetContextMenuScrollType(bool isContextMenu)
414 {
415         result r = E_SUCCESS;
416         if (__isContextMenuScroll == isContextMenu)
417         {
418                 return E_SUCCESS;
419         }
420
421         if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
422         {
423                 return E_SUCCESS;
424         }
425
426         __isContextMenuScroll = isContextMenu;
427         __enableJumpToTop = false;
428         __enableHandler = false;
429         __enableScrollingEffect = false;
430         __enableOverScrollingEffect = false;
431
432         delete __pThumbBitmap;
433         __pThumbBitmap = null;
434
435         _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
436         if (isContextMenu)
437         {
438                 r = GET_BITMAP_CONFIG_N(SCROLL::CONTEXTTHUMB_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
439                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
440
441                 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
442                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
443
444                 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
445                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
446
447                 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MARGIN, orientation, __thumbMargin);
448                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
449         }
450         else
451         {
452                 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
453                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
454
455                 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
456                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
457
458                 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
459                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
460
461                 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MARGIN, orientation, __thumbMargin);
462                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
463         }
464
465         __pThumbVe->SetBounds(CalculateThumbBounds(__scrollDirection));
466         __needUpdateThumb = true;
467         (GetControl().GetVisualElement())->InvalidateRectangle(null);
468
469         return E_SUCCESS;
470
471 CATCH:
472         delete __pThumbBitmap;
473         __pThumbBitmap = null;
474
475         return r;
476 }
477
478 void
479 _ScrollPresenter::EnableFadeEffect(bool enable)
480 {
481         __enableFadeEffect = enable;
482
483         return;
484 }
485
486 bool
487 _ScrollPresenter::IsEnabledFadeEffect(void) const
488 {
489         return __enableFadeEffect;
490 }
491
492 bool
493 _ScrollPresenter::IsOnFadeEffect(void) const
494 {
495         return (__fadeIn || __fadeOut);
496 }
497
498 void
499 _ScrollPresenter::EnableScrollingEffect(bool enable)
500 {
501         __enableScrollingEffect = enable;
502 }
503
504 bool
505 _ScrollPresenter::IsEnabledScrollingEffect(void) const
506 {
507         return __enableScrollingEffect;
508 }
509
510 void
511 _ScrollPresenter::EnableOverScrollingEffect(bool enable)
512 {
513         __enableOverScrollingEffect = enable;
514 }
515
516 bool
517 _ScrollPresenter::IsEnabledOverScrollingEffect(void) const
518 {
519         return __enableOverScrollingEffect;
520 }
521
522 void
523 _ScrollPresenter::SetParentUsingViewport(bool useViewPort)
524 {
525         __parentUsingViewport = useViewPort;
526 }
527
528 bool
529 _ScrollPresenter::IsParentUsingViewport(void) const
530 {
531         return __parentUsingViewport;
532 }
533
534 result
535 _ScrollPresenter::SetScrollVisibility(bool visibility)
536 {
537         if (GetScrollVisibility() == visibility)
538         {
539                 // keep up current visibility.
540                 return E_SUCCESS;
541         }
542
543         if (__jumpToTopPressed && visibility == false)
544         {
545                 // ignore visibility off
546                 return E_SUCCESS;
547         }
548
549         __pCtrlVe->RemoveAllAnimations();
550         if (visibility)
551         {
552                 if (__enableFadeEffect)
553                 {
554                         __fadeIn = true;
555                         __fadeOut = false;
556
557                         __pCtrlVe->SetImplicitAnimationEnabled(true);
558                 }
559
560                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
561
562                 if (__enableFadeEffect)
563                 {
564                         __pCtrlVe->SetImplicitAnimationEnabled(false);
565                 }
566                 else
567                 {
568                         __fadeIn = false;
569                         __fadeOut = false;
570                 }
571         }
572         else
573         {
574                 if (__enableFadeEffect)
575                 {
576                         __fadeIn = false;
577                         __fadeOut = true;
578
579                         __pCtrlVe->SetImplicitAnimationEnabled(true);
580                 }
581
582                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
583
584                 if (__enableFadeEffect)
585                 {
586                         __pCtrlVe->SetImplicitAnimationEnabled(false);
587                 }
588                 else
589                 {
590                         __fadeIn = false;
591                         __fadeOut = false;
592                 }
593         }
594
595         __scrollVisibility = visibility;
596
597         return E_SUCCESS;
598 }
599
600 bool
601 _ScrollPresenter::GetScrollVisibility(void) const
602 {
603         if (__enableFadeEffect)
604         {
605                 if (__scrollVisibility)
606                 {
607                         return true;
608                 }
609         }
610         else if (__pCtrlVe->GetOpacity() > SCROLL_OPACITY_OFF)
611         {
612                 return true;
613         }
614
615         return false;
616 }
617
618 void
619 _ScrollPresenter::CancelFadeEffect(void)
620 {
621         if (__fadeIn)
622         {
623                 __fadeIn = false;
624                 __scrollVisibility = false;
625                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
626         }
627         else if (__fadeOut)
628         {
629                 __fadeOut = false;
630                 __scrollVisibility = true;
631                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
632         }
633
634         return;
635 }
636
637 result
638 _ScrollPresenter::EnableJumpToTop(bool enable)
639 {
640         result r = E_SUCCESS;
641
642         if (__enableJumpToTop != enable)
643         {
644                 if (enable)
645                 {
646                         if (__enableFadeEffect)
647                         {
648                                 __pCtrlVe->SetImplicitAnimationEnabled(true);
649                         }
650
651                         r = AttachScrollChild(&__pJumpToTopVe, CalculateJumpToTopBounds(__scrollDirection), true);
652                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pJumpToTopVe to _Scroll");
653
654                         if (!(_FloatCompare(__scrollPositionCurr, 0.0f)))
655                         {
656                                 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_ON);
657                         }
658                         else
659                         {
660                                 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
661                         }
662
663                         if (__enableFadeEffect)
664                         {
665                                 __pCtrlVe->SetImplicitAnimationEnabled(false);
666                         }
667                 }
668                 else
669                 {
670                         DetachScrollChild(&__pJumpToTopVe, true);
671                 }
672
673                 __enableJumpToTop = enable;
674         }
675
676         return E_SUCCESS;
677
678 }
679
680 bool
681 _ScrollPresenter::IsEnabledJumpToTop(void) const
682 {
683         return __enableJumpToTop;
684 }
685
686 result
687 _ScrollPresenter::EnableHandler(bool enable)
688 {
689         result r = E_SUCCESS;
690
691         if (__enableHandler != enable)
692         {
693                 if (__enableFadeEffect)
694                 {
695                         __pCtrlVe->SetImplicitAnimationEnabled(true);
696                 }
697
698                 if (enable)
699                 {
700                         r = AttachScrollChild(&__pHandlerVe, CalculateHandlerBounds(__scrollDirection), true);
701                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pHandlerVe to _Scroll");
702
703                         DetachScrollChild(&__pThumbVe, true);
704                 }
705                 else
706                 {
707                         r = AttachScrollChild(&__pThumbVe, CalculateThumbBounds(__scrollDirection), true);
708                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pThumbVe to _Scroll");
709
710                         DetachScrollChild(&__pHandlerVe, true);
711                 }
712                 __enableHandler = enable;
713
714                 if (__enableFadeEffect)
715                 {
716                         __pCtrlVe->SetImplicitAnimationEnabled(false);
717                 }
718         }
719
720         return E_SUCCESS;
721 }
722
723 bool
724 _ScrollPresenter::IsEnabledHandler(void) const
725 {
726         return __enableHandler;
727 }
728
729 result
730 _ScrollPresenter::SetScrollingEffectVisibility(bool visibility)
731 {
732         if (!__enableScrollingEffect)
733         {
734                 visibility = false;
735         }
736
737         if (__scrollingEffectVisibility == visibility)
738         {
739                 // keep up current visibility.
740                 return E_SUCCESS;
741         }
742
743         if (__pFrontScrollingEffectVe == null || __pReerScrollingEffectVe == null)
744         {
745                 return E_SUCCESS;
746         }
747
748         __pFrontScrollingEffectVe->RemoveAllAnimations();
749         __pReerScrollingEffectVe->RemoveAllAnimations();
750
751         if (visibility)
752         {
753                 if (__enableFadeEffect)
754                 {
755                         __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(true);
756                         __pReerScrollingEffectVe->SetImplicitAnimationEnabled(true);
757                 }
758
759                 SetScrollingEffectOpacity(SCROLL_OPACITY_DARK_DIM);
760
761                 if (__enableFadeEffect)
762                 {
763                         __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
764                         __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
765                 }
766         }
767         else
768         {
769                 if (__enableFadeEffect)
770                 {
771                         __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(true);
772                         __pReerScrollingEffectVe->SetImplicitAnimationEnabled(true);
773                 }
774
775                 SetScrollingEffectOpacity(SCROLL_OPACITY_OFF);
776
777                 if (__enableFadeEffect)
778                 {
779                         __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
780                         __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
781                 }
782         }
783
784         __scrollingEffectVisibility = visibility;
785
786         return E_SUCCESS;
787 }
788
789 void
790 _ScrollPresenter::SetScrollingEffectOpacity(float opacity)
791 {
792         __pFrontScrollingEffectVe->SetOpacity(opacity);
793         __pReerScrollingEffectVe->SetOpacity(opacity);
794 }
795
796 void
797 _ScrollPresenter::SetScrollingEffectOpacity(_VisualElement& Ve, bool isActive, float ratio)
798 {
799         float baseOpacity = (isActive) ? SCROLL_OPACITY_ON : SCROLL_OPACITY_LIGHT_DIM;
800         Ve.SetOpacity(SCROLL_OPACITY_DARK_DIM + ((baseOpacity - SCROLL_OPACITY_DARK_DIM) * ratio));
801 }
802
803 bool
804 _ScrollPresenter::IsScrollVisible(void) const
805 {
806         return (__fadeIn || __fadeOut || __scrollVisibility);
807 }
808
809 void
810 _ScrollPresenter::AddScrollEventListener(const Controls::_IScrollEventListener& listener)
811 {
812         if (__pScrollEvent == null)
813         {
814                 __pScrollEvent = new (std::nothrow) _UiScrollEvent();
815                 SysTryReturnVoidResult(NID_UI_CTRL, __pScrollEvent, E_OUT_OF_MEMORY,
816                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
817                 __pScrollEvent->Construct(GetControl());
818         }
819
820         __pScrollEvent->AddListener(listener);
821
822         return;
823 }
824
825 void
826 _ScrollPresenter::RemoveScrollEventListener(const Controls::_IScrollEventListener& listener)
827 {
828         ClearLastResult();
829         SysTryReturnVoidResult(NID_UI_CTRL, __pScrollEvent, E_SYSTEM, "[E_SYSTEM] __pScrollEvent must not be null.");
830
831         __pScrollEvent->RemoveListener(listener);
832
833         return;
834 }
835
836 void
837 _ScrollPresenter::OnParentBoundsChanged(void)
838 {
839         FloatRectangle bounds = GetParentCtrl().GetBoundsF();
840         bounds.SetPosition(0.0f, 0.0f);
841         GetControl().SetBounds(bounds);
842
843         RelayoutScrollChildren(__scrollDirection);
844         return;
845 }
846
847 void
848 _ScrollPresenter::OnDraw(void)
849 {
850         DrawThumb();
851         DrawJumpToTop();
852         DrawHandler();
853         DrawScrollingEffect();
854
855         return;
856 }
857
858 bool
859 _ScrollPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
860 {
861         bool ret = false;
862
863         ret |= OnTouchPressedHandler(source, touchinfo);
864         ret |= OnTouchPressedJumpToTop(source, touchinfo);
865
866         return ret;
867 }
868
869 bool
870 _ScrollPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
871 {
872         bool ret = false;
873
874         ret |= OnTouchReleasedHandler(source, touchinfo);
875         ret |= OnTouchReleasedJumpToTop(source, touchinfo);
876
877         return ret;
878 }
879
880 bool
881 _ScrollPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
882 {
883         bool ret = false;
884
885         ret |= OnTouchMovedHandler(source, touchinfo);
886         ret |= OnTouchMovedJumpToTop(source, touchinfo);
887
888         return ret;
889 }
890
891 void
892 _ScrollPresenter::OnTouchMoveHandled(const _Control& source)
893 {
894         if (__jumpToTopPressed)
895         {
896                 __needUpdateJumpTopTop = true;
897                 __jumpToTopPressed = false;
898                 (GetControl().GetVisualElement())->InvalidateRectangle(null);
899         }
900 }
901
902 HitTestResult
903 _ScrollPresenter::HitTest(const FloatPoint& point)
904 {
905         FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
906
907         if (__enableJumpToTop && IsScrollVisible())
908         {
909                 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
910                 jumpToTopBounds.x += ctrlBounds.x;
911                 jumpToTopBounds.y += ctrlBounds.y;
912                 if (jumpToTopBounds.Contains(point))
913                 {
914                         return HIT_TEST_MATCH;
915                 }
916         }
917
918         if (__enableHandler)
919         {
920                 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
921                 handlerBounds.x += ctrlBounds.x;
922                 handlerBounds.y += ctrlBounds.y;
923                 if (handlerBounds.Contains(point))
924                 {
925                         return HIT_TEST_MATCH;
926                 }
927         }
928
929         return HIT_TEST_NOWHERE;
930 }
931
932 VisualElementAnimation*
933 _ScrollPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
934 {
935         VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
936         SysTryReturn(NID_UI_CTRL, pAnimation, null, GetLastResult(), "[%s] Failed to create a VisualElementAnimation.", GetErrorMessage(GetLastResult()));
937
938         pAnimation->SetVisualElementAnimationStatusEventListener(this);
939         SetLastResult(E_SUCCESS);
940
941         return pAnimation;
942 }
943
944 void
945 _ScrollPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
946 {
947         return;
948 }
949
950 void
951 _ScrollPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
952 {
953         return;
954 }
955
956 void
957 _ScrollPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
958 {
959         if (__pCtrlVe == (static_cast <_VisualElement*>(&target)))
960         {
961                 __fadeIn = false;
962                 __fadeOut = false;
963         }
964
965         return;
966 }
967
968 result
969 _ScrollPresenter::Construct(_Control& parentCtrl,
970                                                                 _Scroll& scrollCtrl,
971                                                                 _ScrollDirection scrollDirection,
972                                                                 bool enableFadeEffect,
973                                                                 bool enableJumpToTop,
974                                                                 bool enableHandler,
975                                                                 bool visibility,
976                                                                 float viewRange,
977                                                                 float scrollRange,
978                                                                 float scrollPosition)
979 {
980         result r = E_SUCCESS;
981
982         // load color/shape configuration and bitmap resources
983         r = LoadResources(scrollDirection, _CONTROL_ORIENTATION_PORTRAIT);
984         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load resources.");
985
986         // set attributes
987         SetParentCtrl(parentCtrl);
988         SetControl(scrollCtrl);
989         __scrollDirection = scrollDirection;
990         __enableFadeEffect = enableFadeEffect;
991         __enableJumpToTop = enableJumpToTop;
992         __enableHandler = enableHandler;
993         __viewRange = viewRange;
994         __scrollRange = scrollRange;
995         __scrollPositionCurr = scrollPosition;
996
997         _VisualElement* pVe = null;
998
999         // initialize the scroll control
1000         FloatRectangle bounds = GetParentCtrl().GetBoundsF();
1001         bounds.SetPosition(0.0f, 0.0f);
1002         GetControl().SetBounds(bounds);
1003         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the bounds of _Scroll.", GetErrorMessage(r));
1004
1005         scrollCtrl.SetBackgroundColor(Color(0, 0, 0, 0));
1006
1007         // initialize visual elements
1008         pVe = scrollCtrl.GetVisualElement();
1009         SysTryCatch(NID_UI_CTRL, pVe, , GetLastResult(), "[%s] Failed to get VisualElement of the _Scroll.", GetErrorMessage(GetLastResult()));
1010
1011         __pCtrlVe = new (std::nothrow) _VisualElement();
1012         SysTryReturnResult(NID_UI_CTRL, __pCtrlVe != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1013
1014         r = __pCtrlVe->Construct();
1015         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct Visual Element.", GetErrorMessage(r));
1016
1017         r = __pCtrlVe->SetSurfaceOpaque(false);
1018         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1019
1020         __pCtrlVe->SetImplicitAnimationEnabled(false);
1021
1022         r = pVe->AttachChild(*__pCtrlVe);
1023         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1024
1025         __pCtrlVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1026         __pCtrlVe->SetAnimationProvider(this);
1027         __pCtrlVe->SetShowState(true);
1028
1029         if (visibility)
1030         {
1031                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
1032         }
1033         else
1034         {
1035                 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
1036         }
1037
1038         // initialize jumpToTopVe
1039         if (enableJumpToTop)
1040         {
1041                 r = AttachScrollChild(&__pJumpToTopVe, CalculateJumpToTopBounds(scrollDirection), true);
1042                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pJumpToTopVe to _Scroll.", GetErrorMessage(r));
1043
1044                 if ((scrollDirection != SCROLL_DIRECTION_VERTICAL) || (_FloatCompare(scrollPosition, 0.0f)))
1045                 {
1046                         __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
1047                 }
1048
1049                 __needUpdateJumpTopTop = true;
1050         }
1051
1052         // initialize thumbVe and handlerVe
1053         if (enableHandler)
1054         {
1055                 r = AttachScrollChild(&__pHandlerVe, CalculateHandlerBounds(scrollDirection), true);
1056                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pHandlerVe to _Scroll.", GetErrorMessage(r));
1057
1058                 DetachScrollChild(&__pThumbVe, true);
1059
1060                 __needUpdateHandler = true;
1061         }
1062         else
1063         {
1064                 r = AttachScrollChild(&__pThumbVe, CalculateThumbBounds(scrollDirection), true);
1065                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pThumbVe to _Scroll.", GetErrorMessage(r));
1066
1067                 DetachScrollChild(&__pHandlerVe, true);
1068
1069                 __needUpdateThumb = true;
1070         }
1071
1072         // initialize scrolling effect front VE
1073         __pFrontScrollingEffectVe = new (std::nothrow) _VisualElement();
1074         SysTryCatch(NID_UI_CTRL, __pFrontScrollingEffectVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1075
1076         r = __pFrontScrollingEffectVe->Construct();
1077         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pFrontScrollingEffectVe.", GetErrorMessage(r));
1078
1079         r = __pFrontScrollingEffectVe->SetSurfaceOpaque(false);
1080         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1081
1082         __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
1083
1084         r = pVe->AttachChild(*__pFrontScrollingEffectVe);
1085         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1086
1087         __pFrontScrollingEffectVe->SetBounds(CalculateScrollingEffectFrontBounds(scrollDirection));
1088         __pFrontScrollingEffectVe->SetShowState(true);
1089         __pFrontScrollingEffectVe->SetOpacity(SCROLL_OPACITY_OFF);
1090
1091         // initialize scrolling effect reer VE
1092         __pReerScrollingEffectVe = new (std::nothrow) _VisualElement();
1093         SysTryCatch(NID_UI_CTRL, __pReerScrollingEffectVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1094
1095         r = __pReerScrollingEffectVe->Construct();
1096         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pReerScrollingEffectVe.", GetErrorMessage(r));
1097
1098         r = __pReerScrollingEffectVe->SetSurfaceOpaque(false);
1099         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1100
1101         __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
1102
1103         r = pVe->AttachChild(*__pReerScrollingEffectVe);
1104         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1105
1106         __pReerScrollingEffectVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1107         __pReerScrollingEffectVe->SetShowState(true);
1108         __pReerScrollingEffectVe->SetOpacity(SCROLL_OPACITY_OFF);
1109
1110         __needUpdateScrollingEffect = true;
1111
1112         __scrollVisibility = visibility;
1113
1114         r = __beforeBouncingMatrixHash.Construct();
1115         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1116
1117         return E_SUCCESS;
1118
1119 CATCH:
1120         // set attributes
1121         __pParentCtrl = null;
1122         __pScrollCtrl = null;
1123         __scrollDirection = SCROLL_DIRECTION_VERTICAL;
1124         __enableFadeEffect = false;
1125         __enableJumpToTop = false;
1126         __enableHandler = false;
1127         __enableScrollingEffect = false;
1128         __enableOverScrollingEffect = false;
1129         __isContextMenuScroll = false;
1130
1131         __viewRange = 0.0f;
1132         __scrollRange = 0.0f;
1133
1134         __scrollPositionCurr = 0.0f;
1135         __needUpdateThumb = false;
1136         __needUpdateJumpTopTop = false;
1137         __needUpdateHandler = false;
1138         __needUpdateScrollingEffect = false;
1139         __jumpToTopPressed = false;
1140
1141         __thumbColor = 0x00000000;
1142         __jumpToTopColor = 0x00000000;
1143         __jumpToTopColorPressed = 0x00000000;
1144         __buttonColor= 0x00000000;
1145         __buttonColorPressed = 0x00000000;
1146
1147         ReleaseBitmapResources();
1148
1149         __thumbSizeMin.SetSize(0.0f, 0.0f);
1150         __thumbMargin = 0.0f;
1151         __jumpToTopSize.SetSize(0.0f, 0.0f);
1152         __jumpToTopMarginRight = 0.0f;
1153         __jumpToTopMarginTop = 0.0f;
1154         __handlerSizeMin.SetSize(0.0f, 0.0f);
1155         __handlerMarginLeft = 0.0f;
1156         __handlerMarginRight = 0.0f;
1157         __handlerMarginTop = 0.0f;
1158         __handlerMarginBottom = 0.0f;
1159         __scrollingEffectWidthLeft = 0.0f;
1160         __scrollingEffectWidthRight = 0.0f;
1161         __scrollingEffectHeightTop = 0.0f;
1162         __scrollingEffectHeightBottom = 0.0f;
1163
1164         if (__pThumbVe != null)
1165         {
1166                 __pThumbVe->Destroy();
1167                 __pThumbVe = null;
1168         }
1169
1170         if (__pJumpToTopVe != null)
1171         {
1172                 __pJumpToTopVe->Destroy();
1173                 __pJumpToTopVe = null;
1174         }
1175
1176         if (__pHandlerVe != null)
1177         {
1178                 __pHandlerVe->Destroy();
1179                 __pHandlerVe = null;
1180         }
1181
1182         if (__pFrontScrollingEffectVe != null)
1183         {
1184                 __pFrontScrollingEffectVe->RemoveAllAnimations();
1185                 __pFrontScrollingEffectVe->Destroy();
1186                 __pFrontScrollingEffectVe = null;
1187         }
1188
1189         if (__pReerScrollingEffectVe != null)
1190         {
1191                 __pReerScrollingEffectVe->RemoveAllAnimations();
1192                 __pReerScrollingEffectVe->Destroy();
1193                 __pReerScrollingEffectVe = null;
1194         }
1195
1196         if (__pCtrlVe != null)
1197         {
1198                 __pCtrlVe->RemoveAllAnimations();
1199                 __pCtrlVe->SetAnimationProvider(null);
1200                 __pCtrlVe->Destroy();
1201                 __pCtrlVe = null;
1202         }
1203
1204         return r;
1205 }
1206
1207 result
1208 _ScrollPresenter::LoadResources(_ScrollDirection scrollDirection, _ControlOrientation orientation)
1209 {
1210         result r = E_SUCCESS;
1211
1212         r = LoadColorConfig();
1213         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1214
1215         r = LoadBitmapResources(scrollDirection);
1216         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1217
1218         r = LoadShapeConfig(scrollDirection, orientation);
1219         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1220
1221         return E_SUCCESS;
1222
1223 CATCH:
1224         __thumbColor = 0x00000000;
1225         __jumpToTopColor = 0x00000000;
1226         __jumpToTopColorPressed = 0x00000000;
1227         __buttonColor= 0x00000000;
1228         __buttonColorPressed = 0x00000000;
1229
1230         ReleaseBitmapResources();
1231
1232         __thumbSizeMin.SetSize(0, 0);
1233         __thumbMargin = 0;
1234         __jumpToTopSize.SetSize(0, 0);
1235         __jumpToTopMarginRight = 0;
1236         __jumpToTopMarginTop = 0;
1237         __handlerSizeMin.SetSize(0, 0);
1238         __handlerMarginLeft = 0;
1239         __handlerMarginRight = 0;
1240         __handlerMarginTop = 0;
1241         __handlerMarginBottom = 0;
1242         __scrollingEffectWidthLeft = 0;
1243         __scrollingEffectWidthRight = 0;
1244         __scrollingEffectHeightTop = 0;
1245         __scrollingEffectHeightBottom = 0;
1246
1247         return r;
1248
1249 }
1250
1251 result
1252 _ScrollPresenter::LoadColorConfig(void)
1253 {
1254         result r = E_SUCCESS;
1255
1256         // load color configuration
1257         r = GET_COLOR_CONFIG(SCROLL::THUMB_BG_NORMAL, __thumbColor);
1258         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1259
1260         r = GET_COLOR_CONFIG(SCROLL::JUMP_TO_TOP_NORMAL, __jumpToTopColor);
1261         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1262
1263         r = GET_COLOR_CONFIG(SCROLL::JUMP_TO_TOP_PRESSED, __jumpToTopColorPressed);
1264         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1265
1266         r = GET_COLOR_CONFIG(SCROLL::BUTTON_BG_NORMAL, __buttonColor);
1267         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1268
1269         r = GET_COLOR_CONFIG(SCROLL::BUTTON_BG_PRESSED, __buttonColorPressed);
1270         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1271
1272         return E_SUCCESS;
1273
1274 CATCH:
1275         __thumbColor = 0x00000000;
1276         __jumpToTopColor = 0x00000000;
1277         __jumpToTopColorPressed = 0x00000000;
1278         __buttonColor= 0x00000000;
1279         __buttonColorPressed = 0x00000000;
1280
1281         return E_SYSTEM;
1282
1283 }
1284
1285 result
1286 _ScrollPresenter::LoadBitmapResources(_ScrollDirection scrollDirection)
1287 {
1288         result r = E_SUCCESS;
1289
1290         // release allocated resources.
1291         ReleaseBitmapResources();
1292
1293         // load bitmap resources
1294         r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonBitmap);
1295         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1296
1297         r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonEfBitmap);
1298         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1299
1300         r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonPressBitmap);
1301         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1302
1303         r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonPressEfBitmap);
1304         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1305
1306         if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1307         {
1308                 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_HORIZONTAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1309                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1310
1311                 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_HORIZONTAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbEffectBitmap);
1312                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1313
1314                 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopBitmap);
1315                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1316
1317                 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopPressBitmap);
1318                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1319
1320                 GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopEfBitmap);
1321                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1322
1323                 r = GET_BITMAP_CONFIG_N(SCROLL::HANDLER_HORIZONTAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
1324                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1325
1326                 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_LEFT_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pFrontScrollingEffectBitmap);
1327                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1328
1329                 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_RIGHT_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pReerScrollingEffectBitmap);
1330                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1331         }
1332         else // if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
1333         {
1334                 if (__isContextMenuScroll)
1335                 {
1336                         r = GET_BITMAP_CONFIG_N(SCROLL::CONTEXTTHUMB_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1337                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1338                 }
1339                 else
1340                 {
1341                         r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1342                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1343                 }
1344
1345                 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbEffectBitmap);
1346                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1347
1348                 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopBitmap);
1349                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1350
1351                 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopPressBitmap);
1352                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1353
1354                 GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopEfBitmap);
1355                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1356
1357                 r = GET_BITMAP_CONFIG_N(SCROLL::HANDLER_VERTICAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
1358                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1359
1360                 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_TOP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pFrontScrollingEffectBitmap);
1361                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1362
1363                 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_BOTTOM_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pReerScrollingEffectBitmap);
1364                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1365         }
1366
1367         return E_SUCCESS;
1368
1369 CATCH:
1370         ReleaseBitmapResources();
1371
1372         return E_SYSTEM;
1373 }
1374
1375 result
1376 _ScrollPresenter::LoadShapeConfig(_ScrollDirection scrollDirection, _ControlOrientation orientation)
1377 {
1378         result r = E_SUCCESS;
1379
1380         // load shape configuration
1381         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1382         {
1383                 if (__isContextMenuScroll)
1384                 {
1385                         r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1386                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1387
1388                         r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1389                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1390
1391                         r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MARGIN, orientation, __thumbMargin);
1392                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1393                 }
1394                 else
1395                 {
1396                         r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1397                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1398
1399                         r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1400                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1401
1402                         r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MARGIN, orientation, __thumbMargin);
1403                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1404                 }
1405         }
1406         else
1407         {
1408                 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1409                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1410
1411                 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1412                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1413
1414                 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MARGIN, orientation, __thumbMargin);
1415                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1416         }
1417
1418         r = GET_SHAPE_CONFIG(SCROLL::JUMP_TO_TOP_RIGHT_MARGIN, orientation, __jumpToTopMarginRight);
1419         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1420
1421         r = GET_SHAPE_CONFIG(SCROLL::JUMP_TO_TOP_TOP_MARGIN, orientation, __jumpToTopMarginTop);
1422         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1423
1424         r = GET_FIXED_VALUE_CONFIG(SCROLL::JUMP_TO_TOP_WIDTH, orientation, __jumpToTopSize.width);
1425         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1426
1427         r = GET_FIXED_VALUE_CONFIG(SCROLL::JUMP_TO_TOP_HEIGHT, orientation, __jumpToTopSize.height);
1428         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1429
1430         r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MARGIN, orientation, __handlerMarginLeft);
1431         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1432
1433         r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MIN_WIDTH, orientation, __handlerSizeMin.width);
1434         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1435
1436         r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MIN_HEIGHT, orientation, __handlerSizeMin.height);
1437         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1438
1439         GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_LEFT_WIDTH, orientation, __scrollingEffectWidthLeft);
1440         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1441
1442         GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_RIGHT_WIDTH, orientation, __scrollingEffectWidthRight);
1443         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1444
1445         GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_TOP_HEIGHT, orientation, __scrollingEffectHeightTop);
1446         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1447
1448         GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_BOTTOM_HEIGHT, orientation, __scrollingEffectHeightBottom);
1449         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1450
1451         __handlerMarginRight = __handlerMarginLeft;
1452         __handlerMarginTop = __handlerMarginLeft;
1453         __handlerMarginBottom = __handlerMarginLeft;
1454
1455         return E_SUCCESS;
1456
1457 CATCH:
1458         __thumbSizeMin.SetSize(0.0f, 0.0f);
1459         __thumbMargin = 0.0f;
1460         __jumpToTopSize.SetSize(0.0f, 0.0f);
1461         __jumpToTopMarginRight = 0.0f;
1462         __jumpToTopMarginTop = 0.0f;
1463         __handlerSizeMin.SetSize(0.0f, 0.0f);
1464         __handlerMarginLeft = 0.0f;
1465         __handlerMarginRight = 0.0f;
1466         __handlerMarginTop = 0.0f;
1467         __handlerMarginBottom = 0.0f;
1468         __scrollingEffectWidthLeft = 0.0f;
1469         __scrollingEffectWidthRight = 0.0f;
1470         __scrollingEffectHeightTop = 0.0f;
1471         __scrollingEffectHeightBottom = 0.0f;
1472
1473         return E_SYSTEM;
1474
1475 }
1476
1477 void
1478 _ScrollPresenter::ReleaseBitmapResources(void)
1479 {
1480         delete __pThumbBitmap;
1481         __pThumbBitmap = null;
1482
1483         delete __pThumbEffectBitmap;
1484         __pThumbEffectBitmap = null;
1485
1486         delete __pJumpToTopBitmap;
1487         __pJumpToTopBitmap = null;
1488
1489         delete __pJumpToTopPressBitmap;
1490         __pJumpToTopPressBitmap = null;
1491
1492         delete __pJumpToTopEfBitmap;
1493         __pJumpToTopEfBitmap = null;
1494
1495         delete __pButtonBitmap;
1496         __pButtonBitmap = null;
1497
1498         delete __pButtonEfBitmap;
1499         __pButtonEfBitmap = null;
1500
1501         delete __pButtonPressBitmap;
1502         __pButtonPressBitmap = null;
1503
1504         delete __pButtonPressEfBitmap;
1505         __pButtonPressEfBitmap = null;
1506
1507         delete __pHandlerBitmap;
1508         __pHandlerBitmap = null;
1509
1510         delete __pFrontScrollingEffectBitmap;
1511         __pFrontScrollingEffectBitmap = null;
1512
1513         delete __pReerScrollingEffectBitmap;
1514         __pReerScrollingEffectBitmap = null;
1515
1516         return;
1517 }
1518
1519 FloatRectangle
1520 _ScrollPresenter::CalculateScrollCtrlBounds(_ScrollDirection scrollDirection)
1521 {
1522         FloatRectangle scrollCtrlBounds;
1523         FloatRectangle parentBounds = GetParentCtrl().GetBoundsF();
1524
1525         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1526         {
1527                 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__thumbSizeMin.width + __thumbMargin));
1528                 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__handlerSizeMin.width + __handlerMarginRight + __handlerMarginLeft));
1529                 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__jumpToTopSize.width + __jumpToTopMarginRight));
1530                 scrollCtrlBounds.width = MIN(scrollCtrlBounds.width, (parentBounds.width));
1531                 scrollCtrlBounds.height = parentBounds.height;
1532         }
1533         else
1534         {
1535                 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__thumbSizeMin.width + __thumbMargin));
1536                 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__handlerSizeMin.width + __handlerMarginRight + __handlerMarginLeft));
1537                 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__jumpToTopSize.width + __jumpToTopMarginRight));
1538                 scrollCtrlBounds.height = MIN(scrollCtrlBounds.height, (parentBounds.height));
1539                 scrollCtrlBounds.width = parentBounds.width;
1540         }
1541
1542         scrollCtrlBounds.x = parentBounds.width - scrollCtrlBounds.width;
1543         scrollCtrlBounds.y = parentBounds.height - scrollCtrlBounds.height;
1544
1545         return scrollCtrlBounds;
1546 }
1547
1548 FloatRectangle
1549 _ScrollPresenter::CalculateThumbBounds(_ScrollDirection scrollDirection)
1550 {
1551         FloatDimension thumbSize = CalculateThumbSize(scrollDirection);
1552         FloatPoint thumbPosition = CalculateThumbPosition(scrollDirection);
1553
1554         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1555         if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1556         {
1557                 if (thumbPosition.x < 0.0f)
1558                 {
1559                         thumbPosition.x = 0.0f;
1560                 }
1561                 else if (thumbPosition.x > scrollCtrlBounds.width - thumbSize.width)
1562                 {
1563                         thumbPosition.x = scrollCtrlBounds.width - thumbSize.width;
1564                 }
1565         }
1566         else
1567         {
1568                 if (thumbPosition.y < 0.0f)
1569                 {
1570                         thumbPosition.y = 0.0f;
1571                 }
1572                 else if (thumbPosition.y > scrollCtrlBounds.height - thumbSize.height)
1573                 {
1574                         thumbPosition.y = scrollCtrlBounds.height - thumbSize.height;
1575                 }
1576         }
1577
1578         return FloatRectangle(thumbPosition.x, thumbPosition.y, thumbSize.width, thumbSize.height);
1579 }
1580
1581 FloatPoint
1582 _ScrollPresenter::CalculateThumbPosition(_ScrollDirection scrollDirection)
1583 {
1584         FloatPoint thumbPosition;
1585         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1586
1587         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1588         {
1589                 thumbPosition.x = scrollCtrlBounds.width - (__thumbSizeMin.width + __thumbMargin);
1590                 if (thumbPosition.x < 0.0f)
1591                 {
1592                         thumbPosition.x = 0.0f;
1593                 }
1594
1595                 if (__scrollRange > 0.0f)
1596                 {
1597                         thumbPosition.y = (scrollCtrlBounds.height * __scrollPositionCurr) / __scrollRange;
1598                         if (__scrollPositionCurr < 0.0f)
1599                         {
1600                                 thumbPosition.y = 0.0f;
1601                         }
1602                 }
1603                 else
1604                 {
1605                         thumbPosition.y = 0.0f;
1606                 }
1607         }
1608         else
1609         {
1610                 thumbPosition.y = scrollCtrlBounds.height - (__thumbSizeMin.height + __thumbMargin);
1611                 if (thumbPosition.y < 0.0f)
1612                 {
1613                         thumbPosition.y = 0.0f;
1614                 }
1615
1616                 if (__scrollRange > 0.0f)
1617                 {
1618                         thumbPosition.x = (scrollCtrlBounds.width * __scrollPositionCurr) / __scrollRange;
1619                         if (__scrollPositionCurr < 0.0f)
1620                         {
1621                                 thumbPosition.x = 0.0f;
1622                         }
1623                 }
1624                 else
1625                 {
1626                         thumbPosition.x = 0.0f;
1627                 }
1628         }
1629
1630         return thumbPosition;
1631 }
1632
1633 FloatDimension
1634 _ScrollPresenter::CalculateThumbSize(_ScrollDirection scrollDirection)
1635 {
1636         FloatDimension thumbSize;
1637         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1638
1639         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1640         {
1641                 thumbSize.width = MIN(__thumbSizeMin.width, scrollCtrlBounds.width);
1642                 if (__scrollRange > 0.0f)
1643                 {
1644                         thumbSize.height = (scrollCtrlBounds.height * __viewRange) / __scrollRange;
1645                         thumbSize.height = MAX(__thumbSizeMin.height, thumbSize.height);
1646                         thumbSize.height = MIN(scrollCtrlBounds.height, thumbSize.height);
1647                 }
1648                 else
1649                 {
1650                         thumbSize.height = 0.0f;
1651                 }
1652         }
1653         else
1654         {
1655                 thumbSize.height = MIN(__thumbSizeMin.height, scrollCtrlBounds.height);
1656                 if (__scrollRange > 0.0f)
1657                 {
1658                         thumbSize.width = (scrollCtrlBounds.width * __viewRange) / __scrollRange;
1659                         thumbSize.width = MAX(__thumbSizeMin.width, thumbSize.width);
1660                         thumbSize.width = MIN(scrollCtrlBounds.width, thumbSize.width);
1661                 }
1662                 else
1663                 {
1664                         thumbSize.width = 0.0f;
1665                 }
1666         }
1667
1668         return thumbSize;
1669 }
1670
1671 FloatRectangle
1672 _ScrollPresenter::CalculateHandlerBounds(_ScrollDirection scrollDirection)
1673 {
1674         FloatDimension handlerSize = CalculateHandlerSize(scrollDirection);
1675         FloatPoint handlerPosition = CalculateHandlerPosition(scrollDirection);
1676
1677         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1678         if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1679         {
1680                 if (handlerPosition.x < 0.0f)
1681                 {
1682                         handlerPosition.x = 0.0f;
1683                 }
1684                 else if (handlerPosition.x > scrollCtrlBounds.width - handlerSize.width)
1685                 {
1686                         handlerPosition.x = scrollCtrlBounds.width - handlerSize.width;
1687                 }
1688         }
1689         else
1690         {
1691                 if (handlerPosition.y < 0.0f)
1692                 {
1693                         handlerPosition.y = 0.0f;
1694                 }
1695                 else if (handlerPosition.y > scrollCtrlBounds.height - handlerSize.height)
1696                 {
1697                         handlerPosition.y = scrollCtrlBounds.height - handlerSize.height;
1698                 }
1699         }
1700
1701         return FloatRectangle(handlerPosition.x, handlerPosition.y, handlerSize.width, handlerSize.height);
1702 }
1703
1704 FloatPoint
1705 _ScrollPresenter::CalculateHandlerPosition(_ScrollDirection scrollDirection)
1706 {
1707         FloatPoint handlerPosition;
1708         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1709
1710         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1711         {
1712                 handlerPosition.x = scrollCtrlBounds.width - (__handlerSizeMin.width + __handlerMarginRight);
1713                 if (handlerPosition.x < 0.0f)
1714                 {
1715                         handlerPosition.x = 0.0f;
1716                 }
1717                 if (__scrollRange > 0.0f)
1718                 {
1719                         handlerPosition.y = (scrollCtrlBounds.height * __scrollPositionCurr) / __scrollRange;
1720                 }
1721                 else
1722                 {
1723                         handlerPosition.y = 0.0f;
1724                 }
1725         }
1726         else
1727         {
1728                 handlerPosition.y = scrollCtrlBounds.height - (__handlerSizeMin.width + __handlerMarginRight);
1729                 if (handlerPosition.y < 0.0f)
1730                 {
1731                         handlerPosition.y = 0.0f;
1732                 }
1733                 if (__scrollRange > 0.0f)
1734                 {
1735                         handlerPosition.x = (scrollCtrlBounds.width * __scrollPositionCurr) / __scrollRange;
1736                 }
1737                 else
1738                 {
1739                         handlerPosition.x = 0.0f;
1740                 }
1741         }
1742
1743         return handlerPosition;
1744 }
1745
1746 FloatDimension
1747 _ScrollPresenter::CalculateHandlerSize(_ScrollDirection scrollDirection)
1748 {
1749         FloatDimension handlerSize;
1750         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1751
1752         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1753         {
1754                 handlerSize.width = MIN(__handlerSizeMin.width, scrollCtrlBounds.width);
1755                 if (__scrollRange > 0.0f)
1756                 {
1757                         handlerSize.height = (scrollCtrlBounds.height * __viewRange) / __scrollRange;
1758                 }
1759                 else
1760                 {
1761                         handlerSize.height = 0.0f;
1762                 }
1763         }
1764         else
1765         {
1766                 handlerSize.height = MIN(__handlerSizeMin.width, scrollCtrlBounds.height);
1767                 if (__scrollRange > 0.0f)
1768                 {
1769                         handlerSize.width = (scrollCtrlBounds.width * __viewRange) / __scrollRange;
1770                 }
1771                 else
1772                 {
1773                         handlerSize.width = 0.0f;
1774                 }
1775         }
1776
1777         return handlerSize;
1778 }
1779
1780 FloatRectangle
1781 _ScrollPresenter::CalculateJumpToTopBounds(_ScrollDirection scrollDirection)
1782 {
1783         FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1784         FloatRectangle jumpToTopBounds(0.0f, 0.0f, 0.0f, 0.0f);
1785
1786         if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1787         {
1788                 jumpToTopBounds.width = MIN(__jumpToTopSize.width, scrollCtrlBounds.width);
1789                 jumpToTopBounds.height = MIN(__jumpToTopSize.height, scrollCtrlBounds.height);
1790                 jumpToTopBounds.x = scrollCtrlBounds.width - (__jumpToTopSize.width + __jumpToTopMarginRight);
1791                 if (jumpToTopBounds.x < 0.0f)
1792                 {
1793                         jumpToTopBounds.x = 0.0f;
1794                 }
1795                 jumpToTopBounds.y = __jumpToTopMarginTop;
1796         }
1797         else
1798         {
1799                 jumpToTopBounds.width = MIN(__jumpToTopSize.width, scrollCtrlBounds.width);
1800                 jumpToTopBounds.height = MIN(__jumpToTopSize.height, scrollCtrlBounds.height);
1801                 jumpToTopBounds.y = scrollCtrlBounds.height - (__jumpToTopSize.height + __jumpToTopMarginRight);
1802                 if (jumpToTopBounds.y < 0.0f)
1803                 {
1804                         jumpToTopBounds.y = 0.0f;
1805                 }
1806                 jumpToTopBounds.x = __jumpToTopMarginTop;
1807         }
1808
1809         return jumpToTopBounds;
1810 }
1811
1812 FloatRectangle
1813 _ScrollPresenter::CalculateScrollingEffectFrontBounds(_ScrollDirection scrollDirection)
1814 {
1815         FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
1816         FloatRectangle scrollEffectFrontBounds(0.0f, 0.0f, 0.0f, 0.0f);
1817
1818         if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1819         {
1820                 scrollEffectFrontBounds.width = __scrollingEffectWidthLeft;
1821                 scrollEffectFrontBounds.height = scrollCtrlBounds.height;
1822         }
1823         else
1824         {
1825                 scrollEffectFrontBounds.width = scrollCtrlBounds.width;
1826                 scrollEffectFrontBounds.height = __scrollingEffectHeightTop;
1827         }
1828         return scrollEffectFrontBounds;
1829 }
1830
1831 FloatRectangle
1832 _ScrollPresenter::CalculateScrollingEffectReerBounds(_ScrollDirection scrollDirection)
1833 {
1834         FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
1835         FloatRectangle scrollEffectReerBounds(0.0f, 0.0f, 0.0f, 0.0f);
1836
1837         if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1838         {
1839                 scrollEffectReerBounds.x = scrollCtrlBounds.width - __scrollingEffectWidthRight;
1840                 scrollEffectReerBounds.width = __scrollingEffectWidthRight;
1841                 scrollEffectReerBounds.height = scrollCtrlBounds.height;
1842         }
1843         else
1844         {
1845                 scrollEffectReerBounds.y = scrollCtrlBounds.height - __scrollingEffectHeightBottom;
1846                 scrollEffectReerBounds.width = scrollCtrlBounds.width;
1847                 scrollEffectReerBounds.height = __scrollingEffectHeightBottom;
1848         }
1849
1850         return scrollEffectReerBounds;
1851 }
1852
1853 result
1854 _ScrollPresenter::AttachScrollChild(_VisualElement** ppScrollVe, const FloatRectangle& bounds, bool visibility)
1855 {
1856         result r = E_SUCCESS;
1857         _VisualElement* pScrollVe = *ppScrollVe;
1858
1859         if (pScrollVe == null)
1860         {
1861                 pScrollVe = new (std::nothrow) _VisualElement();
1862                 SysTryCatch(NID_UI_CTRL, pScrollVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1863
1864                 r = pScrollVe->Construct();
1865                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pScrollVe.", GetErrorMessage(r));
1866
1867                 r = pScrollVe->SetSurfaceOpaque(false);
1868                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1869
1870                 pScrollVe->SetImplicitAnimationEnabled(false);
1871
1872                 r = __pCtrlVe->AttachChild(*pScrollVe);
1873                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the __pCtrlVe.", GetErrorMessage(r));
1874
1875                 *ppScrollVe = pScrollVe;
1876         }
1877
1878         pScrollVe->SetBounds(bounds);
1879         pScrollVe->SetShowState(visibility);
1880
1881         return E_SUCCESS;
1882
1883 CATCH:
1884         if (pScrollVe)
1885         {
1886                 pScrollVe->Destroy();
1887                 pScrollVe = null;
1888                 *ppScrollVe = pScrollVe;
1889         }
1890
1891         return r;
1892 }
1893
1894 void
1895 _ScrollPresenter::DetachScrollChild(_VisualElement** ppScrollVe, bool destroy)
1896 {
1897         _VisualElement* pScrollVe = *ppScrollVe;
1898
1899         if (pScrollVe)
1900         {
1901                 if (destroy)
1902                 {
1903                         pScrollVe->Destroy();
1904                         pScrollVe = null;
1905                         *ppScrollVe = null;
1906                 }
1907                 else
1908                 {
1909                         pScrollVe->SetShowState(false);
1910                 }
1911         }
1912 }
1913
1914 result
1915 _ScrollPresenter::RelayoutScrollChildren(_ScrollDirection scrollDirection)
1916 {
1917         result r = E_SUCCESS;
1918
1919         __pCtrlVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1920         if (__enableJumpToTop)
1921         {
1922                 __pJumpToTopVe->SetBounds(CalculateJumpToTopBounds(scrollDirection));
1923                 __needUpdateJumpTopTop = true;
1924         }
1925
1926         if (__enableHandler)
1927         {
1928                 __pHandlerVe->SetBounds(CalculateHandlerBounds(scrollDirection));
1929                 __needUpdateHandler = true;
1930         }
1931         else
1932         {
1933                 __pThumbVe->SetBounds(CalculateThumbBounds(scrollDirection));
1934                 __needUpdateThumb = true;
1935         }
1936
1937         __pFrontScrollingEffectVe->SetBounds(CalculateScrollingEffectFrontBounds(scrollDirection));
1938         __pReerScrollingEffectVe->SetBounds(CalculateScrollingEffectReerBounds(scrollDirection));
1939         __needUpdateScrollingEffect = true;
1940
1941         r = (GetControl().GetVisualElement())->InvalidateRectangle(null);
1942         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate Control Ve.");
1943
1944         return E_SUCCESS;
1945 }
1946
1947 void
1948 _ScrollPresenter::DrawThumb(void)
1949 {
1950         if (__needUpdateThumb != true)
1951         {
1952                 return;
1953         }
1954
1955         Canvas* pCanvas = null;
1956         Bitmap* pThumbBitmap = null;
1957         result r = E_SUCCESS;
1958
1959         if (__enableHandler != true)
1960         {
1961                 pCanvas = __pThumbVe->GetCanvasN();
1962                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pThumbVe");
1963
1964                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1965                 pCanvas->Clear();
1966
1967                 FloatRectangle thumbBounds = __pThumbVe->GetBounds();
1968                 thumbBounds.SetPosition(0.0f, 0.0f);
1969                 bool isCustomBitmap = false;
1970                 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
1971                 {
1972                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::THUMB_VERTICAL_BG_NORMAL);
1973                 }
1974                 else
1975                 {
1976                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::THUMB_HORIZONTAL_BG_NORMAL);
1977                 }
1978
1979
1980                 if (__isContextMenuScroll == false)
1981                 {
1982                         pThumbBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pThumbBitmap,
1983                                                                                                                                 Color::GetColor(COLOR_ID_MAGENTA),
1984                                                                                                                                 __thumbColor);
1985                         SysTryCatch(NID_UI_CTRL, pThumbBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.",
1986                                                 GetErrorMessage(GetLastResult()));
1987
1988                         if (isCustomBitmap == false)
1989                         {
1990                                 r = DrawBitmap(*pCanvas, thumbBounds, *__pThumbEffectBitmap);
1991                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
1992                         }
1993
1994                         r = DrawBitmap(*pCanvas, thumbBounds, *pThumbBitmap);
1995                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
1996                 }
1997                 else
1998                 {
1999                         r = DrawBitmap(*pCanvas, thumbBounds, *__pThumbBitmap);
2000                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2001                 }
2002         }
2003
2004         __needUpdateThumb = false;
2005         //fall through
2006 CATCH:
2007         delete pCanvas;
2008         delete pThumbBitmap;
2009
2010         return;
2011 }
2012
2013 void
2014 _ScrollPresenter::DrawJumpToTop(void)
2015 {
2016         if (__needUpdateJumpTopTop != true)
2017         {
2018                 return;
2019         }
2020
2021         Canvas* pCanvas = null;
2022         Bitmap* pColorReplacedBitmap = null;
2023         result r = E_SUCCESS;
2024         bool isCustomBitmap = false;
2025         if (__enableJumpToTop)
2026         {
2027                 String bitmapId = L"SCROLL::JUMP_TO_TOP_NORMAL";
2028                 if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
2029                 {
2030                         bitmapId = L"SCROLL::JUMP_TO_LEFT_NORMAL";
2031                 }
2032
2033                 Color jumpToTopColor = __jumpToTopColor;
2034                 Color buttonColor = __buttonColor;
2035                 Bitmap* pJumpToTopBitmap = __pJumpToTopBitmap;
2036                 Bitmap* pButtonBitmap = __pButtonBitmap;
2037                 Bitmap* pButtonEfBitmap = __pButtonEfBitmap;
2038                 String buttonBitmapId = L"SCROLL::BUTTON_BG_NORMAL";
2039
2040                 if (__jumpToTopPressed)
2041                 {
2042                         jumpToTopColor = __jumpToTopColorPressed;
2043                         buttonColor = __buttonColorPressed;
2044                         pJumpToTopBitmap = __pJumpToTopPressBitmap;
2045                         pButtonBitmap = __pButtonPressBitmap;
2046                         pButtonEfBitmap = __pButtonPressEfBitmap;
2047                         buttonBitmapId = L"SCROLL::BUTTON_BG_PRESSED";
2048                 }
2049
2050                 if (__jumpToTopPressed)
2051                 {
2052                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_PRESSED);
2053                 }
2054                 else
2055                 {
2056                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_NORMAL);
2057                 }
2058
2059                 pCanvas = __pJumpToTopVe->GetCanvasN();
2060                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pJumpToTopVe");
2061
2062                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2063                 pCanvas->Clear();
2064
2065                 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2066                 jumpToTopBounds.SetPosition(0.0f, 0.0f);
2067
2068                 //Draw Button
2069                 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_PRESSED);
2070                 if (isCustomBitmap == false)
2071                 {
2072                         r = DrawBitmap(*pCanvas, jumpToTopBounds, *pButtonEfBitmap);
2073                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2074                 }
2075
2076                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBitmap,
2077                                                                                                                                         Color::GetColor(COLOR_ID_MAGENTA),
2078                                                                                                                                         buttonColor);
2079                 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.", GetErrorMessage(GetLastResult()));
2080
2081                 r = DrawBitmap(*pCanvas, jumpToTopBounds, *pColorReplacedBitmap);
2082                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2083                 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2084                 {
2085                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::JUMP_TO_TOP_NORMAL);
2086                 }
2087                 else
2088                 {
2089                         isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::JUMP_TO_LEFT_NORMAL);
2090                 }
2091                 if (isCustomBitmap == false)
2092                 {
2093                         r = DrawBitmap(*pCanvas, jumpToTopBounds, *__pJumpToTopEfBitmap);
2094                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2095                 }
2096
2097                 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pJumpToTopBitmap,
2098                                                                                                                                         Color::GetColor(COLOR_ID_MAGENTA),
2099                                                                                                                                         jumpToTopColor);
2100                 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.", GetErrorMessage(GetLastResult()));
2101
2102                 r = DrawBitmap(*pCanvas, jumpToTopBounds, *pColorReplacedBitmap);
2103                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2104         }
2105
2106         __needUpdateJumpTopTop = false;
2107         //fall through
2108 CATCH:
2109         delete pCanvas;
2110         delete pColorReplacedBitmap;
2111
2112         return;
2113 }
2114
2115 void
2116 _ScrollPresenter::DrawHandler(void)
2117 {
2118         if (__needUpdateHandler != true)
2119         {
2120                 return;
2121         }
2122
2123         Canvas* pCanvas = null;
2124         result r = E_SUCCESS;
2125
2126         if (__enableHandler)
2127         {
2128                 // handler bounds setting
2129                 pCanvas = __pHandlerVe->GetCanvasN();
2130                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pHandlerVe");
2131
2132                 // clear background
2133                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2134                 pCanvas->Clear();
2135
2136                 // draw handler bg bitmap
2137                 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
2138                 handlerBounds.SetPosition(0.0f, 0.0f);
2139
2140                 r = DrawBitmap(*pCanvas, handlerBounds, *__pHandlerBitmap);
2141                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2142         }
2143
2144         __needUpdateHandler = false;
2145         //fall through
2146 CATCH:
2147         delete pCanvas;
2148
2149         return;
2150 }
2151
2152 void
2153 _ScrollPresenter::DrawScrollingEffect(void)
2154 {
2155         if (__needUpdateScrollingEffect != true)
2156         {
2157                 return;
2158         }
2159
2160         Canvas* pCanvas = null;
2161         result r = E_SUCCESS;
2162
2163         if (__pFrontScrollingEffectBitmap != null)
2164         {
2165                 pCanvas = __pFrontScrollingEffectVe->GetCanvasN();
2166                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of __pFrontScrollingEffectVe", GetErrorMessage(GetLastResult()));
2167
2168                 // clear background
2169                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2170                 pCanvas->Clear();
2171
2172                 FloatRectangle effectBounds = __pFrontScrollingEffectVe->GetBounds();
2173                 effectBounds.SetPosition(0.0f, 0.0f);
2174                 r = DrawBitmap(*pCanvas, effectBounds, *__pFrontScrollingEffectBitmap);
2175                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2176
2177                 delete pCanvas;
2178         }
2179
2180         if (__pReerScrollingEffectBitmap != null)
2181         {
2182                 pCanvas = __pReerScrollingEffectVe->GetCanvasN();
2183                 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of __pReerScrollingEffectVe", GetErrorMessage(GetLastResult()));
2184
2185                 // clear background
2186                 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2187                 pCanvas->Clear();
2188
2189                 FloatRectangle effectBounds = __pReerScrollingEffectVe->GetBounds();
2190                 effectBounds.SetPosition(0.0f, 0.0f);
2191                 r = DrawBitmap(*pCanvas, effectBounds, *__pReerScrollingEffectBitmap);
2192                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2193
2194                 delete pCanvas;
2195         }
2196
2197         __needUpdateScrollingEffect = false;
2198
2199         return;
2200
2201 CATCH:
2202         delete pCanvas;
2203 }
2204
2205 result
2206 _ScrollPresenter::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
2207 {
2208         result r = E_SUCCESS;
2209         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
2210         {
2211                 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
2212                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
2213         }
2214         else
2215         {
2216                 FloatPoint pos((bounds.width - bitmap.GetWidthF()) / 2.0f,      (bounds.height - bitmap.GetHeightF()) / 2.0f);
2217                 r = canvas.DrawBitmap(pos, bitmap);
2218                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
2219         }
2220
2221         return E_SUCCESS;
2222 }
2223
2224 bool
2225 _ScrollPresenter::OnTouchPressedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2226 {
2227         if (__enableJumpToTop && IsScrollVisible())
2228         {
2229                 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2230                 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2231                 jumpToTopBounds.x += ctrlBounds.x;
2232                 jumpToTopBounds.y += ctrlBounds.y;
2233                 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2234                 if (jumpToTopBounds.Contains(touchedPosition))
2235                 {
2236                         __needUpdateJumpTopTop = true;
2237                         __jumpToTopPressed = true;
2238                         SetScrollVisibility(true);
2239                         (GetControl().GetVisualElement())->InvalidateRectangle(null);
2240                         return true;
2241                 }
2242         }
2243
2244         return false;
2245 }
2246
2247 bool
2248 _ScrollPresenter::OnTouchReleasedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2249 {
2250         if (__jumpToTopPressed)
2251         {
2252                 __needUpdateJumpTopTop = true;
2253                 __jumpToTopPressed = false;
2254                 (GetControl().GetVisualElement())->InvalidateRectangle(null);
2255
2256                 if (__pScrollEvent)
2257                 {
2258                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pScrollCtrl);
2259                         _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollJumpToTopEventArgN(*__pScrollCtrl);
2260                         SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2261
2262                         __pScrollEvent->Fire(*pEventArg);
2263                         return true;
2264                 }
2265         }
2266         return false;
2267 }
2268
2269 bool
2270 _ScrollPresenter::OnTouchMovedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2271 {
2272         if (__jumpToTopPressed)
2273         {
2274                 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2275                 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2276                 jumpToTopBounds.x += ctrlBounds.x;
2277                 jumpToTopBounds.y += ctrlBounds.y;
2278                 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2279                 if (!(jumpToTopBounds.Contains(touchedPosition)))
2280                 {
2281                         __needUpdateJumpTopTop = true;
2282                         __jumpToTopPressed = false;
2283                         (GetControl().GetVisualElement())->InvalidateRectangle(null);
2284                 }
2285                 return true;
2286         }
2287
2288         return false;
2289 }
2290
2291 bool
2292 _ScrollPresenter::OnTouchPressedHandler(const _Control& source, const _TouchInfo& touchinfo)
2293 {
2294         if (__enableHandler)
2295         {
2296                 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2297                 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
2298                 handlerBounds.x += ctrlBounds.x;
2299                 handlerBounds.y += ctrlBounds.y;
2300                 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2301                 if (handlerBounds.Contains(touchedPosition))
2302                 {
2303                         __handlerTouched = true;
2304                         if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2305                         {
2306                                 __handlerTouchedPosition = touchinfo.GetCurrentPosition().y;
2307                         }
2308                         else
2309                         {
2310                                 __handlerTouchedPosition = touchinfo.GetCurrentPosition().x;
2311                         }
2312                         return true;
2313                 }
2314         }
2315
2316         return false;
2317 }
2318
2319 bool
2320 _ScrollPresenter::OnTouchReleasedHandler(const _Control& source, const _TouchInfo& touchinfo)
2321 {
2322         if (__enableHandler)
2323         {
2324                 __handlerTouched = false;
2325                 __handlerTouchedPosition = 0.0f;
2326
2327                 if (__pScrollEvent)
2328                 {
2329                         _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl);
2330                         SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2331
2332                         __pScrollEvent->Fire(*pEventArg);
2333                 }
2334                 return true;
2335         }
2336
2337         // forwarding OnTouchReleased event to parent control
2338         return false;
2339 }
2340
2341 bool
2342 _ScrollPresenter::OnTouchMovedHandler(const _Control& source, const _TouchInfo& touchinfo)
2343 {
2344         if (__enableHandler && __handlerTouched)
2345         {
2346                 float scrollPosition = GetScrollPosition();
2347                 FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
2348                 float touchPosition = 0.0f;
2349                 float scrollBoundsRange = 0.0f;
2350
2351                 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2352                 {
2353                         touchPosition = touchinfo.GetCurrentPosition().y;
2354                         scrollBoundsRange = scrollCtrlBounds.height;
2355                 }
2356                 else
2357                 {
2358                         touchPosition = touchinfo.GetCurrentPosition().x;
2359                         scrollBoundsRange = scrollCtrlBounds.width;
2360                 }
2361
2362                 float touchDistance = touchPosition - __handlerTouchedPosition;
2363                 float scrollDistance = ( __scrollRange * touchDistance) / scrollBoundsRange;
2364
2365                 scrollPosition += scrollDistance;
2366
2367                 int scrollType = -1;
2368                 if (_FloatCompare(scrollPosition, 0.0f) || scrollPosition < 0.0f)
2369                 {
2370                         scrollType = (__scrollDirection == SCROLL_DIRECTION_VERTICAL) ? SCROLL_END_EVENT_END_TOP : SCROLL_END_EVENT_END_LEFT;
2371                         scrollPosition = 0.0f;
2372                 }
2373                 else if (scrollPosition >= __scrollRange - __viewRange)
2374                 {
2375                         scrollType = (__scrollDirection == SCROLL_DIRECTION_VERTICAL) ? SCROLL_END_EVENT_END_BOTTOM :
2376                                 SCROLL_END_EVENT_END_RIGHT;
2377                         scrollPosition = __scrollRange - __viewRange;
2378                 }
2379
2380                 result r = SetScrollPosition(scrollPosition);
2381                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to set scroll position.", GetErrorMessage(r));
2382
2383                 __handlerTouchedPosition = touchPosition;
2384
2385                 if (__pScrollEvent)
2386                 {
2387                         _UiScrollEventArg* pEventArg = null;
2388                         if (scrollType >= 0)
2389                         {
2390                                 pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl, (ScrollEndEvent)scrollType);
2391                                 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2392                         }
2393                         else
2394                         {
2395                                 pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl, GetScrollPosition());
2396                                 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2397                         }
2398
2399                         __pScrollEvent->Fire(*pEventArg);
2400                 }
2401
2402                 return true;
2403         }
2404
2405         // forwarding OnTouchMoved event to parent control
2406         return false;
2407 }
2408
2409 void
2410 _ScrollPresenter::SetParentCtrl(_Control& parentCtrl)
2411 {
2412         __pParentCtrl = &parentCtrl;
2413 }
2414
2415 _Control&
2416 _ScrollPresenter::GetParentCtrl(void) const
2417 {
2418         return *__pParentCtrl;
2419 }
2420
2421 void
2422 _ScrollPresenter::SetControl(_Scroll& scrollCtrl)
2423 {
2424         __pScrollCtrl = &scrollCtrl;
2425 }
2426
2427 _Scroll&
2428 _ScrollPresenter::GetControl(void) const
2429 {
2430         return *__pScrollCtrl;
2431 }
2432
2433 result
2434 _ScrollPresenter::SetScrollingEffect(void)
2435 {
2436         if ((__enableScrollingEffect || __enableOverScrollingEffect) && __scrollingEffectVisibility)
2437         {
2438                 if (__scrollPositionCurr < 0.0f)
2439                 {
2440                         SetScrollingEffectVisibility(false);
2441                 }
2442                 else if (__scrollPositionCurr > (__scrollRange - __viewRange))
2443                 {
2444                         SetScrollingEffectVisibility(false);
2445                 }
2446                 else
2447                 {
2448                         if (__pFrontScrollingEffectVe->GetOpacity() != SCROLL_OPACITY_DARK_DIM && !__fadeOut)
2449                         {
2450                                 SetScrollingEffectVisibility(true);
2451                         }
2452                 }
2453         }
2454
2455         return E_SUCCESS;
2456 }
2457
2458 result
2459 _ScrollPresenter::SetParentBouncing(float rate)
2460 {
2461         if (rate == __parentBouncingRate)
2462         {
2463                 return E_SUCCESS;
2464         }
2465
2466         __parentBouncingRate = rate;
2467
2468         return E_SUCCESS;
2469 }
2470
2471 }}} // Tizen::Ui::Controls