/*
- * 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>
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()
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();
// 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;
}
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.SetProperty( Layer::Property::CONSUMES_TOUCH, true );
- return true;
+ return false;
}
bool Popup::OnBackingWheelEvent( Actor actor, const WheelEvent& event )
return false;
}
- // Consume wheel event in dimmed backing actor.
- mLayer.SetProperty( Layer::Property::CONSUMES_TOUCH, 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.SetProperty( Layer::Property::CONSUMES_TOUCH, 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 )
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;
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