From: Agnelo Vaz Date: Wed, 14 Dec 2016 10:30:11 +0000 (+0000) Subject: Ensure toggle button emits clicked signal when changing state X-Git-Tag: dali_1.2.19~4^2~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=d87bedc9a0cff8c8002164ebf1375da6b9230662 Ensure toggle button emits clicked signal when changing state Change-Id: I6437eab978eb89bcc1f56671ed49b079ec602a6c --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp index 5ae6ee7..7ff4e3a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-PushButton.cpp @@ -47,6 +47,10 @@ namespace { static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg"; +static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 ); +static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 ); +static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 ); + static bool gPushButtonSelectedState = false; bool PushButtonSelected( Button button ) { @@ -70,11 +74,19 @@ static bool PushButtonReleased( Button button ) return true; } +static bool gPushButtonClicked = false; + +static bool PushButtonClicked( Button button ) +{ + gPushButtonClicked = true; + return gPushButtonClicked; +} + Dali::Integration::Point GetPointDownInside() { Dali::Integration::Point point; point.SetState( PointState::DOWN ); - point.SetScreenPosition( Vector2( 240, 400 ) ); + point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON ); return point; } @@ -82,7 +94,7 @@ Dali::Integration::Point GetPointUpInside() { Dali::Integration::Point point; point.SetState( PointState::UP ); - point.SetScreenPosition( Vector2( 240, 400 ) ); + point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON ); return point; } @@ -90,7 +102,7 @@ Dali::Integration::Point GetPointLeave() { Dali::Integration::Point point; point.SetState( PointState::LEAVE ); - point.SetScreenPosition( Vector2( 240, 400 ) ); + point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON ); return point; } @@ -98,7 +110,7 @@ Dali::Integration::Point GetPointEnter() { Dali::Integration::Point point; point.SetState( PointState::MOTION ); - point.SetScreenPosition( Vector2( 240, 400 ) ); + point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON ); return point; } @@ -118,6 +130,22 @@ Dali::Integration::Point GetPointUpOutside() return point; } +// Set up the position of the button for the default test events +void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages ) +{ + button.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + button.SetParentOrigin( ParentOrigin::TOP_LEFT ); + button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS ); + if ( useDefaultImages ) + { + const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ); + TestPlatformAbstraction& platform = application.GetPlatform(); + platform.SetClosestImageSize( TEST_IMAGE_SIZE ); + button.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE ); + button.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE ); + } +} + } //namespace int UtcDaliPushButtonConstructorP(void) @@ -424,8 +452,8 @@ int UtcDaliPushButtonPressed(void) PushButton pushButton = PushButton::New(); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); - pushButton.SetPosition( 240, 400 ); - pushButton.SetSize( 100, 100 ); + pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS ); + pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ); Stage::GetCurrent().Add( pushButton ); @@ -457,8 +485,8 @@ int UtcDaliPushButtonReleased(void) PushButton pushButton = PushButton::New(); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); - pushButton.SetPosition( 240, 400 ); - pushButton.SetSize( 100, 100 ); + pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS ); + pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ); Stage::GetCurrent().Add( pushButton ); @@ -540,8 +568,8 @@ int UtcDaliPushButtonSelected(void) PushButton pushButton = PushButton::New(); pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT ); pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT ); - pushButton.SetPosition( 240, 400 ); - pushButton.SetSize( 100, 100 ); + pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS ); + pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ); Stage::GetCurrent().Add( pushButton ); @@ -1011,7 +1039,7 @@ int UtcDaliPushButtonSetUnSelectedVisual01P(void) ToolkitTestApplication application; PushButton pushButton = PushButton::New(); - pushButton.SetSize(100.0f, 100.0f); + pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ); Stage::GetCurrent().Add( pushButton ); @@ -1241,3 +1269,37 @@ int UtcDaliPushButtonSetDisabledSelectedImageP(void) END_TEST; } + +int UtcDaliPushButtonToggleSignalP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted"); + + PushButton button = PushButton::New(); + button.SetProperty( Button::Property::TOGGLABLE, true); + + SetupButtonForTestTouchEvents( application, button, true ); + + Stage::GetCurrent().Add( button ); + + application.SendNotification(); + application.Render(); + + // connect to its signal + button.ClickedSignal().Connect( &PushButtonClicked ); + gPushButtonClicked = false; + + tet_infoline(" Touch down and up within button"); + Dali::Integration::TouchEvent event; + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointDownInside() ); + application.ProcessEvent( event ); + + event = Dali::Integration::TouchEvent(); + event.AddPoint( GetPointUpInside() ); + application.ProcessEvent( event ); + + DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION ); + + END_TEST; +} diff --git a/dali-toolkit/internal/controls/buttons/button-impl.cpp b/dali-toolkit/internal/controls/buttons/button-impl.cpp index 3bcdde3..0c7005b 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/button-impl.cpp @@ -547,13 +547,13 @@ void Button::ButtonDown() void Button::ButtonUp() { + bool emitSignalsForPressAndReleaseAction = false; + if( DEPRESSED == mButtonPressedState ) { - bool validButtonAction = false; - if( mTogglableButton ) // Button up will change state { - validButtonAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour + emitSignalsForPressAndReleaseAction = OnToggleReleased(); // Derived toggle buttons can override this to provide custom behaviour } else { @@ -562,16 +562,20 @@ void Button::ButtonUp() { mAutoRepeatingTimer.Reset(); } - validButtonAction = true; + emitSignalsForPressAndReleaseAction = true; } + } + else if ( TOGGLE_DEPRESSED == mButtonPressedState ) + { + emitSignalsForPressAndReleaseAction = true; // toggle released after being pressed, a click + } - if ( validButtonAction ) - { - // The clicked and released signals should be emitted regardless of toggle mode. - Toolkit::Button handle( GetOwner() ); - mReleasedSignal.Emit( handle ); - mClickedSignal.Emit( handle ); - } + if ( emitSignalsForPressAndReleaseAction ) + { + // The clicked and released signals should be emitted regardless of toggle mode. + Toolkit::Button handle( GetOwner() ); + mReleasedSignal.Emit( handle ); + mClickedSignal.Emit( handle ); } } @@ -1030,6 +1034,8 @@ void Button::OnRelayout( const Vector2& size, RelayoutContainer& container ) } } + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout selected (%s) \n", IsSelected()?"yes":"no" ); + DALI_LOG_INFO( gLogButtonFilter, Debug::General, "OnRelayout << \n"); }