/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/integration-api/debug.h>
#include <dali/public-api/adaptor-framework/key.h>
#include <dali/public-api/animation/constraints.h>
-#include <dali/public-api/common/stage.h>
+#include <dali/devel-api/common/stage.h>
#include <dali/public-api/events/key-event.h>
-#include <dali/public-api/events/touch-data.h>
+#include <dali/public-api/events/touch-event.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/devel-api/scripting/scripting.h>
#include <dali/devel-api/actors/actor-devel.h>
#include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
-#include <dali-toolkit/public-api/accessibility-manager/accessibility-manager.h>
+#include <dali-toolkit/devel-api/accessibility-manager/accessibility-manager.h>
#include <dali-toolkit/public-api/visuals/color-visual-properties.h>
#include <dali-toolkit/public-api/visuals/visual-properties.h>
#include <dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h>
Toolkit::Popup popup = Toolkit::Popup::New();
// Setup for Toast Popup type.
- popup.SetSizeModeFactor( DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
+ popup.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_TOAST_WIDTH_OF_STAGE_RATIO );
popup.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
popup.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
popup.SetProperty( Toolkit::Popup::Property::CONTEXTUAL_MODE, Toolkit::Popup::NON_CONTEXTUAL );
self.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
self.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
- self.SetSizeModeFactor( DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
+ self.SetProperty( Actor::Property::SIZE_MODE_FACTOR, DEFAULT_POPUP_PARENT_RELATIVE_SIZE );
self.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::WIDTH );
self.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
mPopupLayout.SetResizePolicy( ResizePolicy::USE_ASSIGNED_SIZE, Dimension::WIDTH );
mPopupLayout.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
- mPopupLayout.SetSize( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f );
+ mPopupLayout.SetProperty( Actor::Property::SIZE, Vector2( Stage::GetCurrent().GetSize().x * DEFAULT_RELATIVE_PARENT_WIDTH, 0.0f ) );
mPopupLayout.SetFitHeight( 0 ); // Set row to fit.
mPopupLayout.SetFitHeight( 1 ); // Set row to fit.
- mPopupLayout.TouchSignal().Connect( this, &Popup::OnDialogTouched );
-
mPopupContainer.Add( mPopupLayout );
// Any content after this point which is added to Self() will be re-parented to mContent.
mAlterAddedChild = true;
SetAsKeyboardFocusGroup( true );
+
+ SetupTouch();
}
Popup::~Popup()
case Toolkit::Popup::ZOOM:
{
// Zoom animations start fully zoomed out.
- mPopupContainer.SetScale( Vector3::ZERO );
+ mPopupContainer.SetProperty( Actor::Property::SCALE, Vector3::ZERO );
break;
}
case Toolkit::Popup::FADE:
{
// Fade animations start transparent.
- mPopupContainer.SetProperty( DevelActor::Property::OPACITY, 0.0f );
+ mPopupContainer.SetProperty( Actor::Property::OPACITY, 0.0f );
break;
}
}
else
{
- mPopupContainer.SetScale( transitionIn ? Vector3::ONE : Vector3::ZERO );
+ mPopupContainer.SetProperty( Actor::Property::SCALE, transitionIn ? Vector3::ONE : Vector3::ZERO );
}
break;
}
}
else
{
- mPopupContainer.SetProperty( DevelActor::Property::OPACITY, transitionIn ? 1.0f : 0.0f );
+ mPopupContainer.SetProperty( Actor::Property::OPACITY, transitionIn ? 1.0f : 0.0f );
}
break;
}
mPopupBackgroundImage.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
mPopupBackgroundImage.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
- // OnDialogTouched only consumes the event. It prevents the touch event to be caught by the backing.
- mPopupBackgroundImage.TouchSignal().Connect( this, &Popup::OnDialogTouched );
-
// Set the popup border to be slightly larger than the layout contents.
UpdateBackgroundPositionAndSize();
{
// Set up padding to give sensible default behaviour
// (an application developer can later override this if they wish).
- mTitle.SetPadding( DEFAULT_TITLE_PADDING );
+ mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING );
mPopupLayout.AddChild( mTitle, Toolkit::TableView::CellPosition( 0, 0 ) );
}
{
mPreviousFocusedActor = keyboardFocusManager.GetCurrentFocusActor();
- if( Self().IsKeyboardFocusable() )
+ if( Self().GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
// Setup the actgor to start focus from.
Actor focusActor;
- if( mContent && mContent.IsKeyboardFocusable() )
+ if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
// If the content is focusable, move the focus to the content.
focusActor = mContent;
}
- else if( mFooter && mFooter.IsKeyboardFocusable() )
+ else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
// If the footer is focusable, move the focus to the footer.
focusActor = mFooter;
ClearKeyInputFocus();
// Restore the keyboard focus when popup is hidden.
- if( mPreviousFocusedActor && mPreviousFocusedActor.IsKeyboardFocusable() )
+ if( mPreviousFocusedActor && mPreviousFocusedActor.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
Dali::Toolkit::KeyboardFocusManager keyboardFocusManager = Dali::Toolkit::KeyboardFocusManager::Get();
if( keyboardFocusManager )
{
if( !mContent && !mFooter )
{
- mTitle.SetPadding( DEFAULT_TITLE_ONLY_PADDING );
+ mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_ONLY_PADDING );
}
else
{
- mTitle.SetPadding( DEFAULT_TITLE_PADDING );
+ mTitle.SetProperty( Actor::Property::PADDING, DEFAULT_TITLE_PADDING );
}
}
mTailImage.SetProperty( Dali::Actor::Property::NAME, "tailImage" );
mTailImage.SetProperty( Actor::Property::PARENT_ORIGIN, parentOrigin );
mTailImage.SetProperty( Actor::Property::ANCHOR_POINT, anchorPoint );
- mTailImage.SetPosition( position );
+ mTailImage.SetProperty( Actor::Property::POSITION, position );
if( mPopupBackgroundImage )
{
// Always the full size of the stage.
backing.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
- backing.SetSize( Stage::GetCurrent().GetSize() );
+ backing.SetProperty( Actor::Property::SIZE, Stage::GetCurrent().GetSize() );
// Catch events.
backing.SetProperty( Actor::Property::SENSITIVE, true );
// Default to being transparent.
backing.SetProperty( Actor::Property::COLOR_ALPHA, 0.0f );
- backing.TouchSignal().Connect( this, &Popup::OnBackingTouched );
backing.WheelEventSignal().Connect( this, &Popup::OnBackingWheelEvent );
return backing;
}
if( mPopupBackgroundImage )
{
mPopupBackgroundImage.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
- mPopupBackgroundImage.SetSizeModeFactor( Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) );
+ mPopupBackgroundImage.SetProperty( Actor::Property::SIZE_MODE_FACTOR, Vector3( mBackgroundBorder.left + mBackgroundBorder.right, mBackgroundBorder.top + mBackgroundBorder.bottom, 0.0f ) );
// Adjust the position of the background so the transparent areas are set appropriately
- mPopupBackgroundImage.SetPosition( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f );
+ mPopupBackgroundImage.SetProperty( Actor::Property::POSITION, Vector2( ( mBackgroundBorder.right - mBackgroundBorder.left ) * 0.5f, ( mBackgroundBorder.bottom - mBackgroundBorder.top ) * 0.5f ));
}
}
void Popup::SetTouchTransparent( bool enabled )
{
- mTouchTransparent = enabled;
+ if( mTouchTransparent != enabled )
+ {
+ mTouchTransparent = enabled;
+ SetupTouch();
+ }
}
const bool Popup::IsTouchTransparent() const
return connected;
}
-bool Popup::OnBackingTouched( Actor actor, const TouchData& touch )
+bool Popup::OnBackingTouched( Actor actor, const TouchEvent& touch )
{
- // Allow events to pass through if touch transparency is enabled.
- if( mTouchTransparent )
+ // Allow events to pass through if the backing isn't the hit-actor
+ if( (touch.GetHitActor(0) == actor) &&
+ (touch.GetPointCount() > 0) &&
+ (touch.GetState( 0 ) == PointState::DOWN))
{
- return false;
- }
-
- if( touch.GetPointCount() > 0 )
- {
- if( touch.GetState( 0 ) == PointState::DOWN )
- {
- // Guard against destruction during signal emission.
- Toolkit::Popup handle( GetOwner() );
+ // Guard against destruction during signal emission.
+ Toolkit::Popup handle( GetOwner() );
- mTouchedOutsideSignal.Emit();
- }
+ mTouchedOutsideSignal.Emit();
}
- // Block anything behind backing becoming touched.
- mLayer.SetTouchConsumed( true );
- return true;
+ return false;
}
bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
return false;
}
- // Consume wheel event in dimmed backing actor.
- mLayer.SetTouchConsumed( true );
return true;
}
-bool Popup::OnDialogTouched( Actor actor, const TouchData& touch )
+bool Popup::OnDialogTouched( Actor actor, const TouchEvent& touch )
{
- // Allow events to pass through if touch transparency is enabled.
- if( mTouchTransparent )
- {
- return false;
- }
-
- // Consume event (stops backing actor receiving touch events)
- mLayer.SetTouchConsumed( true );
- return true;
+ // Only connecting this so the backing does not become the default hit-actor and inadvertently closes the popup
+ return false;
}
-void Popup::OnStageConnection( int depth )
+void Popup::OnSceneConnection( int depth )
{
mLayoutDirty = true;
RelayoutRequest();
- Control::OnStageConnection( depth );
+ Control::OnSceneConnection( depth );
}
void Popup::OnChildAdd( Actor& child )
}
// Set the final position.
- mPopupContainer.SetPosition( newPosition );
+ mPopupContainer.SetProperty( Actor::Property::POSITION, newPosition );
}
void Popup::OnRelayout( const Vector2& size, RelayoutContainer& container )
bool consumed = false;
- if( event.state == KeyEvent::Down )
+ if( event.GetState() == KeyEvent::DOWN )
{
- if (event.keyCode == Dali::DALI_KEY_ESCAPE || event.keyCode == Dali::DALI_KEY_BACK)
+ if (event.GetKeyCode() == Dali::DALI_KEY_ESCAPE || event.GetKeyCode() == Dali::DALI_KEY_BACK)
{
SetDisplayState( Toolkit::Popup::HIDDEN );
consumed = true;
Toolkit::Control control = Toolkit::Control::DownCast( parent );
bool layoutControl = control && GetImplementation( control ).IsKeyboardNavigationSupported();
- if( parent.IsKeyboardFocusable() || layoutControl )
+ if( parent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) || layoutControl )
{
focusableActors.push_back( parent );
( currentFocusedActor && ( ( !mContent || ( currentFocusGroup != mContent ) ) && ( !mFooter || ( currentFocusGroup != mFooter ) ) ) ) )
{
// The current focused actor is not within popup.
- if( mContent && mContent.IsKeyboardFocusable() )
+ if( mContent && mContent.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
// If the content is focusable, move the focus to the content.
nextFocusableActor = mContent;
}
- else if( mFooter && mFooter.IsKeyboardFocusable() )
+ else if( mFooter && mFooter.GetProperty< bool >( Actor::Property::KEYBOARD_FOCUSABLE ) )
{
// If the footer is focusable, move the focus to the footer.
nextFocusableActor = mFooter;
return nextFocusableActor;
}
+void Popup::SetupTouch()
+{
+ if( ! mTouchTransparent )
+ {
+ // Connect all the signals and set us up to consume all touch events
+ mBacking.TouchedSignal().Connect( this, &Popup::OnBackingTouched );
+ mPopupBackgroundImage.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
+ mPopupLayout.TouchedSignal().Connect( this, &Popup::OnDialogTouched );
+ mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
+ }
+ else
+ {
+ // We are touch transparent so disconnect all signals and ensure our layer does not consumed all touch events
+ mBacking.TouchedSignal().Disconnect( this, &Popup::OnBackingTouched );
+ mPopupBackgroundImage.TouchedSignal().Disconnect( this, &Popup::OnDialogTouched );
+ mPopupLayout.TouchedSignal().Disconnect( this, &Popup::OnDialogTouched );
+ mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, false );
+ }
+}
} // namespace Internal