JIRA issues : N_SE-28942, 29459
authorSyed Khaja Moinuddin <moinuddin.s@samsung.com>
Mon, 25 Mar 2013 02:47:48 +0000 (11:47 +0900)
committerkishorekumar Dachinamoorthy <kishore.d@samsung.com>
Tue, 26 Mar 2013 14:16:03 +0000 (19:46 +0530)
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
Change-Id: I5625386f938438775df1515eb55d102ab9bbb05a
Signed-off-by: Syed Khaja Moinuddin <moinuddin.s@samsung.com>
src/ui/controls/FUiCtrl_SliderPresenter.cpp [changed mode: 0755->0644]
src/ui/inc/FUiCtrl_SliderPresenter.h

old mode 100755 (executable)
new mode 100644 (file)
index 41a3540..5f7c2c0
@@ -39,6 +39,7 @@ using namespace Tizen::Graphics;
 using namespace Tizen::Base;
 using namespace Tizen::Ui::Animations;
 using namespace Tizen::Graphics::_Text;
+using namespace Tizen::Base::Runtime;
 
 namespace Tizen { namespace Ui { namespace Controls
 {
@@ -47,6 +48,7 @@ _SliderPresenter::_SliderPresenter(void)
        : __pSlider(null)
        , __pSliderModel(null)
        , __pSliderOverlay(null)
+       , __pSlideTimer(null)
        , __pResourceBgTopBitmap(null)
        , __pResourceBgMiddleBitmap(null)
        , __pResourceBgBottomBitmap(null)
@@ -83,13 +85,14 @@ _SliderPresenter::_SliderPresenter(void)
        , __handleX(0)
        , __isSliderPressed(false)
        , __isNeedToBeUpdated(true)
-       , __isBubblingBlocked(false)
        , __isResourceLoaded(false)
        , __isCustomHandle(false)
        , __isCustomPressedTextColor(false)
        , __groupStyle(GROUP_STYLE_NONE)
        , __fontSize(0.0f)
        , __barOffset(0.0f)
+       , __isTimerRunning(false)
+       , __currentPosition(0.0f, 0.0f)
 {
 }
 
@@ -101,6 +104,13 @@ _SliderPresenter::~_SliderPresenter(void)
        delete __pSliderOverlay;
        __pSliderOverlay = null;
 
+       if (__pSlideTimer != null)
+       {
+               __pSlideTimer->Cancel();
+               delete __pSlideTimer;
+               __pSlideTimer = null;
+       }
+
        delete __pResourceBgTopBitmap;
        __pResourceBgTopBitmap = null;
 
@@ -681,7 +691,7 @@ CATCH:
 }
 
 int
-_SliderPresenter::CalculateSliderValue(int positionX, int offsetX)
+_SliderPresenter::CalculateSliderValue(float positionX, float offsetX)
 {
        int minValue = __pSliderModel->GetMinValue();
        int maxValue = __pSliderModel->GetMaxValue();
@@ -1436,20 +1446,32 @@ _SliderPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touch
                return false;
        }
 
-       Point point = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition());
+       if (__pSlideTimer == null)
+       {
+               __pSlideTimer = new (std::nothrow) Timer;
+               SysTryReturn(NID_UI_CTRL, __pSlideTimer != null, true, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
+
+               result r = __pSlideTimer->Construct(*this);
+               if (r != E_SUCCESS)
+               {
+                       delete __pSlideTimer;
+                       __pSlideTimer = null;
 
-       __isBubblingBlocked = false;
+                       return true;
+               }
+       }
 
-       if (__pSlider->IsEnabled() == true && __handleRect.Contains(FloatPoint(point.x, point.y)) == true)
+       FloatPoint point = touchinfo.GetCurrentPosition();
+
+       if (__handleRect.Contains(point) == true)
        {
+               __isSliderPressed = true;
+
                int candidateValue = CalculateSliderValue(point.x, point.x - __handleRect.x);
 
                __pSliderModel->SetValue(candidateValue);
                __pSlider->SetAccessibilityElementValue();
 
-               __isSliderPressed = true;
-               __isBubblingBlocked = true;
-
                if (__pSlider->GetStyle() & _SLIDER_STYLE_OVERLAY)
                {
                        __pSliderOverlay->Open(false);
@@ -1458,7 +1480,7 @@ _SliderPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touch
                __pSlider->Invalidate();
        }
 
-       return __isBubblingBlocked;
+       return __isSliderPressed;
 }
 
 bool
@@ -1469,15 +1491,20 @@ _SliderPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touc
                return false;
        }
 
-       Point point = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition());
-       bool isBubblingBlocked = __isBubblingBlocked;
+       if (__pSlideTimer != null)
+       {
+               __isTimerRunning = false;
+               __pSlideTimer->Cancel();
+       }
+
+       FloatPoint point = touchinfo.GetCurrentPosition();
 
        Canvas* pCanvas = __pSlider->GetCanvasN();
        SysTryReturn(NID_UI_CTRL, pCanvas != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get the canvas.");
 
-       if (point.x >= (pCanvas->GetBounds().x + pCanvas->GetBounds().width))
+       if (point.x >= (pCanvas->GetBoundsF().x + pCanvas->GetBoundsF().width))
        {
-               point.x = pCanvas->GetBounds().x + pCanvas->GetBounds().width;
+               point.x = pCanvas->GetBoundsF().x + pCanvas->GetBoundsF().width;
        }
 
        if (__isSliderPressed == true)
@@ -1506,9 +1533,10 @@ _SliderPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touc
 
                        pAdjustmentEvent->Fire(*pEventArg);
                }
+               return true;
        }
 
-       return isBubblingBlocked;
+       return false;
 }
 
 bool
@@ -1519,32 +1547,40 @@ _SliderPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchin
                return false;
        }
 
-       Point point = _CoordinateSystemUtils::ConvertToInteger(touchinfo.GetCurrentPosition());
-       bool isBubblingBlocked = __isBubblingBlocked;
+       if (__isSliderPressed == false)
+       {
+               return false;
+       }
+
+       FloatPoint point = touchinfo.GetCurrentPosition();
 
        Canvas* pCanvas = __pSlider->GetCanvasN();
-       SysTryReturn(NID_UI_CTRL, pCanvas != null, false, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get the canvas.");
+       SysTryReturn(NID_UI_CTRL, pCanvas != null, true, E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to get the canvas.");
 
-       if (point.x >= (pCanvas->GetBounds().x + pCanvas->GetBounds().width))
+       if (point.x >= (pCanvas->GetBoundsF().x + pCanvas->GetBoundsF().width))
        {
-               point.x = pCanvas->GetBounds().x + pCanvas->GetBounds().width;
+               point.x = pCanvas->GetBoundsF().x + pCanvas->GetBoundsF().width;
        }
 
+       __currentPosition.x = point.x;
+       __currentPosition.y = point.y;
 
-       if (__isSliderPressed == false)
+       if ( __isTimerRunning == false )
        {
-               return false;
+               __isTimerRunning = true;
+               __pSlideTimer->Start(__timerValue);
        }
 
-       if (__pSlider->IsEnabled() == false)
-       {
-               __isSliderPressed = false;
-               return false;
-       }
+       return true;
+}
 
-       float handleHalfWidth = __handleRect.width / 2.0f;
-       int oldValue = __pSliderModel->GetValue();
-       int candidateValue = CalculateSliderValue(point.x, handleHalfWidth);
+void
+_SliderPresenter::OnTimerExpired(Timer& timer)
+{
+       __isTimerRunning = false;
+
+       float handleHalfWidth = __handleRect.width / 2;
+       int candidateValue = CalculateSliderValue(__currentPosition.x, handleHalfWidth);
 
        __pSliderModel->SetValue(candidateValue);
        __pSlider->SetAccessibilityElementValue();
@@ -1552,21 +1588,21 @@ _SliderPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchin
        __pSlider->Draw();
        __pSlider->Show();
 
-       if (oldValue != candidateValue)
+       // Slider Event Fire
+       _SliderEvent* pSliderEvent = dynamic_cast <_SliderEvent*>(__pSlider->GetSliderEvent());
+       if (pSliderEvent != null)
        {
-               // Slider Event Fire
-               _SliderEvent* pSliderEvent = dynamic_cast <_SliderEvent*>(__pSlider->GetSliderEvent());
-               if (pSliderEvent != null)
-               {
-                       Tizen::Base::Runtime::IEventArg* pEventArg = _SliderEvent::CreateSliderEventArgN(candidateValue);
-                       result r = GetLastResult();
-                       SysTryReturn(NID_UI_CTRL, pEventArg != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
+               Tizen::Base::Runtime::IEventArg* pEventArg = _SliderEvent::CreateSliderEventArgN(candidateValue);
 
-                       pSliderEvent->Fire(*pEventArg);
+               if( pEventArg == null)
+               {
+                       return;
                }
+
+               pSliderEvent->Fire(*pEventArg);
        }
 
-       return isBubblingBlocked;
+       return;
 }
 
 bool
index 6318b91..6cc815b 100644 (file)
@@ -38,6 +38,7 @@ class _SliderOverlay;
 
 class _SliderPresenter
        : public Tizen::Base::Object
+       , public Tizen::Base::Runtime::ITimerEventListener
 {
 public:
        virtual ~_SliderPresenter(void);
@@ -69,8 +70,10 @@ public:
        result SetThumbBitmap(SliderThumbStatus status, const Tizen::Graphics::Bitmap& bitmap);
        void SetThumbTextColor(SliderThumbStatus status, const Tizen::Graphics::Color& color);
 
+       virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
+
 private:
-       int CalculateSliderValue(int positionX, int offsetX);
+       int CalculateSliderValue(float positionX, float offsetX);
        result Resize(void);
        result LoadBitmap(void);
        result DrawSlider(void);
@@ -100,6 +103,8 @@ private:
        Tizen::Graphics::FloatRectangle __barRect;
        Tizen::Graphics::FloatRectangle __handleRect;
 
+       Tizen::Base::Runtime::Timer* __pSlideTimer;
+
        Tizen::Graphics::Bitmap* __pResourceBgTopBitmap;
        Tizen::Graphics::Bitmap* __pResourceBgMiddleBitmap;
        Tizen::Graphics::Bitmap* __pResourceBgBottomBitmap;
@@ -152,13 +157,17 @@ private:
        bool __isSliderPressed;
 
        bool __isNeedToBeUpdated;
-       bool __isBubblingBlocked;
        bool __isResourceLoaded;
        bool __isCustomHandle;
        bool __isCustomPressedTextColor;
        GroupStyle __groupStyle;
        float __fontSize;
        float __barOffset;
+
+       bool __isTimerRunning;
+
+       Tizen::Graphics::FloatPoint __currentPosition;
+       static const int __timerValue = 5;
 };     // _SliderPresenter
 
 }}} // Tizen::Ui::Controls