X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fpublic-api%2Fcontrols%2Fcontrol-impl.cpp;h=1804809cedfdd1b5c68fc17085d030fdc8d2315f;hp=a41a6f3e9c10522867f6ac568160ad83c674e319;hb=5f339dfbdc685ce6d08415f97931fe0154bffb4e;hpb=0a6c26e72fc8d2ad52837311b7e9069c12eec4be diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp old mode 100644 new mode 100755 index a41a6f3..1804809 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -30,18 +30,19 @@ #include // INTERNAL INCLUDES -#include +#include #include +#include #include #include +#include #include #include -#include #include +#include #include #include #include -#include #include namespace Dali @@ -60,13 +61,75 @@ namespace Debug::Filter* gLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_CONTROL_VISUALS"); #endif -DALI_ENUM_TO_STRING_TABLE_BEGIN( CLIPPING_MODE ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED ) -DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN ) -DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE ) +/** + * @brief Replace the background visual if it's a color visual with the renderIfTransparent property set as required. + * @param[in] controlImpl The control implementation + * @param[in] renderIfTransaparent Whether we should render if the color is transparent + */ +void ChangeBackgroundColorVisual( Control& controlImpl, bool renderIfTransparent ) +{ + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); -} // unnamed namespace + Toolkit::Visual::Base backgroundVisual = controlDataImpl.GetVisual( Toolkit::Control::Property::BACKGROUND ); + if( backgroundVisual ) + { + Property::Map map; + backgroundVisual.CreatePropertyMap( map ); + Property::Value* typeValue = map.Find( Toolkit::Visual::Property::TYPE ); + if( typeValue && typeValue->Get< int >() == Toolkit::Visual::COLOR ) + { + // Only change it if it's a color visual + map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = renderIfTransparent; + controlImpl.SetBackground( map ); + } + } +} + +/** + * @brief Creates a clipping renderer if required. + * (EG. If no renders exist and clipping is enabled). + * @param[in] controlImpl The control implementation. + */ +void CreateClippingRenderer( Control& controlImpl ) +{ + // We want to add a transparent background if we do not have one for clipping. + Actor self( controlImpl.Self() ); + int clippingMode = ClippingMode::DISABLED; + if( self.GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) ) + { + switch( clippingMode ) + { + case ClippingMode::CLIP_CHILDREN: + { + if( self.GetRendererCount() == 0u ) + { + Internal::Control::Impl& controlDataImpl = Internal::Control::Impl::Get( controlImpl ); + if( controlDataImpl.mVisuals.Empty() ) + { + controlImpl.SetBackgroundColor( Color::TRANSPARENT ); + } + else + { + // We have visuals, check if we've set the background and re-create it to + // render even if transparent (only if it's a color visual) + ChangeBackgroundColorVisual( controlImpl, true ); + } + } + break; + } + + case ClippingMode::DISABLED: + case ClippingMode::CLIP_TO_BOUNDING_BOX: + { + // If we have a background visual, check if it's a color visual and remove the render if transparent flag + ChangeBackgroundColorVisual( controlImpl, false ); + break; + } + } + } +} +} // unnamed namespace Toolkit::Control Control::New() @@ -108,9 +171,17 @@ void Control::SetBackgroundColor( const Vector4& color ) { mImpl->mBackgroundColor = color; Property::Map map; - map[ Toolkit::DevelVisual::Property::TYPE ] = Toolkit::Visual::COLOR; + map[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::COLOR; map[ Toolkit::ColorVisual::Property::MIX_COLOR ] = color; + int clippingMode = ClippingMode::DISABLED; + if( ( Self().GetProperty( Actor::Property::CLIPPING_MODE ).Get( clippingMode ) ) && + ( clippingMode == ClippingMode::CLIP_CHILDREN ) ) + { + // If clipping-mode is set to CLIP_CHILDREN, then force visual to add the render even if transparent + map[ Toolkit::DevelColorVisual::Property::RENDER_IF_TRANSPARENT ] = true; + } + SetBackground( map ); } @@ -122,10 +193,10 @@ Vector4 Control::GetBackgroundColor() const void Control::SetBackground( const Property::Map& map ) { Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( map ); + visual.SetName("background"); if( visual ) { - mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual ); - visual.SetDepthIndex( DepthIndex::BACKGROUND ); + mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND ); // Trigger a size negotiation request that may be needed by the new visual to relayout its contents. RelayoutRequest(); @@ -137,8 +208,7 @@ void Control::SetBackgroundImage( Image image ) Toolkit::Visual::Base visual = Toolkit::VisualFactory::Get().CreateVisual( image ); if( visual ) { - mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual ); - visual.SetDepthIndex( DepthIndex::BACKGROUND ); + mImpl->RegisterVisual( Toolkit::Control::Property::BACKGROUND, visual, DepthIndex::BACKGROUND ); } } @@ -355,13 +425,15 @@ bool Control::EmitKeyEventSignal( const KeyEvent& event ) bool consumed = false; + consumed = mImpl->FilterKeyEvent( event ); + // signals are allocated dynamically when someone connects - if ( !mImpl->mKeyEventSignal.Empty() ) + if ( !consumed && !mImpl->mKeyEventSignal.Empty() ) { consumed = mImpl->mKeyEventSignal.Emit( handle, event ); } - if (!consumed) + if ( !consumed ) { // Notification for derived classes consumed = OnKeyEvent(event); @@ -499,35 +571,16 @@ void Control::OnStageConnection( int depth ) } } - if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() ) - { - Property::Value clippingValue = self.GetProperty( Actor::Property::CLIPPING_MODE ); - int clippingMode = ClippingMode::DISABLED; - if( clippingValue.Get( clippingMode ) ) - { - // Add a transparent background if we do not have any renderers or visuals so we clip our children + // The clipping renderer is only created if required. + CreateClippingRenderer( *this ); - if( clippingMode == ClippingMode::CLIP_CHILDREN ) - { - // Create a transparent background visual which will also get staged. - SetBackgroundColor( Color::TRANSPARENT ); - } - } - } + // Request to be laid out when the control is connected to the Stage. + Toolkit::DevelControl::RequestLayout( *this ); } void Control::OnStageDisconnection() { - for(RegisteredVisualContainer::Iterator iter = mImpl->mVisuals.Begin(); iter!= mImpl->mVisuals.End(); iter++) - { - // Check whether the visual is empty - if( (*iter)->visual ) - { - DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::OnStageDisconnection Setting visual(%d) off stage\n", (*iter)->index ); - Actor self( Self() ); - Toolkit::GetImplementation((*iter)->visual).SetOffStage( self ); - } - } + mImpl->OnStageDisconnection(); } void Control::OnKeyInputFocusGained() @@ -554,24 +607,12 @@ void Control::OnChildRemove(Actor& child) void Control::OnPropertySet( Property::Index index, Property::Value propertyValue ) { - Actor self( Self() ); - if( index == Actor::Property::CLIPPING_MODE ) + // If the clipping mode has been set, we may need to create a renderer. + // Only do this if we are already on-stage as the OnStageConnection will handle the off-stage clipping controls. + if( ( index == Actor::Property::CLIPPING_MODE ) && Self().OnStage() ) { - // Only set the background if we're already on the stage and have no renderers or visuals - - if( mImpl->mVisuals.Empty() && ! self.GetRendererCount() && self.OnStage() ) - { - ClippingMode::Type clippingMode = ClippingMode::DISABLED; - if( Scripting::GetEnumerationProperty< ClippingMode::Type >( propertyValue, CLIPPING_MODE_TABLE, CLIPPING_MODE_TABLE_COUNT, clippingMode ) ) - { - // Add a transparent background if we do not have one so we clip children - - if( clippingMode == ClippingMode::CLIP_CHILDREN ) - { - SetBackgroundColor( Color::TRANSPARENT ); - } - } - } + // Note: This method will handle whether creation of the renderer is required. + CreateClippingRenderer( *this ); } } @@ -614,7 +655,47 @@ void Control::OnRelayout( const Vector2& size, RelayoutContainer& container ) { for( unsigned int i = 0, numChildren = Self().GetChildCount(); i < numChildren; ++i ) { - container.Add( Self().GetChildAt( i ), size ); + Actor child = Self().GetChildAt( i ); + Vector2 newChildSize( size ); + + // When setting the padding or margin on the control child should be resized and repositioned for legacy reasons. + if( ( mImpl->mPadding.start != 0 ) || ( mImpl->mPadding.end != 0 ) || ( mImpl->mPadding.top != 0 ) || ( mImpl->mPadding.bottom != 0 ) || + ( mImpl->mMargin.start != 0 ) || ( mImpl->mMargin.end != 0 ) || ( mImpl->mMargin.top != 0 ) || ( mImpl->mMargin.bottom != 0 ) ) + { + // Cannot use childs Position property as it can already have margin applied on it, + // so we end up cumulatively applying them over and over again. + Toolkit::Control childControl = Toolkit::Control::DownCast( child ); + + // If control not a LayoutItem layout then must be the old Relayout algorithm hence account + // for margins and padding. + // Padding is incorrect but may have to keep this functionality for compatibility. + if ( childControl && ! Toolkit::DevelControl::GetLayout( childControl ) ) + { + Extents padding = mImpl->mPadding; + + Dali::CustomActor ownerActor(GetOwner()); + Dali::LayoutDirection::Type layoutDirection = static_cast( ownerActor.GetProperty( Dali::Actor::Property::LAYOUT_DIRECTION ).Get() ); + + if( Dali::LayoutDirection::RIGHT_TO_LEFT == layoutDirection ) + { + std::swap( padding.start, padding.end ); + } + + // Child size should include padding, this is the wrong use of padding but kept for compatibility. + newChildSize.width = size.width - ( padding.start + padding.end ); + newChildSize.height = size.height - ( padding.top + padding.bottom ); + + // Cannot use childs Position property as it can already have padding and margin applied on it, + // so we end up cumulatively applying them over and over again. + Vector2 childOffset( 0.f, 0.f ); + childOffset.x += ( mImpl->mMargin.start + padding.start ); + childOffset.y += ( mImpl->mMargin.top + padding.top ); + + child.SetPosition( childOffset.x, childOffset.y ); + } + } + + container.Add( child, size ); } Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); @@ -630,11 +711,14 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime Vector3 Control::GetNaturalSize() { + DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Control::GetNaturalSize for %s\n", Self().GetName().c_str() ); Toolkit::Visual::Base visual = mImpl->GetVisual( Toolkit::Control::Property::BACKGROUND ); if( visual ) { Vector2 naturalSize; visual.GetNaturalSize( naturalSize ); + naturalSize.width += ( mImpl->mPadding.start + mImpl->mPadding.end ); + naturalSize.height += ( mImpl->mPadding.top + mImpl->mPadding.bottom ); return Vector3( naturalSize ); } return Vector3::ZERO;