X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fpush-button-impl.cpp;h=cf34f85cc409078894308024b9f326d9e9ca20cf;hb=19b6edb066bc90ab6fd4ce93b9dc49b5224d7815;hp=628fe67a3be0b7ba8f9bc626b1e007dec03f794f;hpb=1db0a8becea3dbdebaa942d934d91824a92434e7;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 628fe67..2dc4385 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 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. @@ -19,72 +19,56 @@ #include "push-button-impl.h" // EXTERNAL INCLUDES -#include -#include +#include +#include +#include #include // INTERNAL INCLUDES -#include "push-button-default-painter-impl.h" +#include +#include +#include +#include -#include +#if defined(DEBUG_ENABLED) +extern Debug::Filter* gLogButtonFilter; +#endif namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - BaseHandle Create() { return Toolkit::PushButton::New(); } -TypeRegistration typeRegistration( typeid(Toolkit::PushButton), typeid(Toolkit::Button), Create ); - -} // unnamed namespace - -namespace -{ +// Properties -const float TEXT_PADDING = 12.0f; +DALI_TYPE_REGISTRATION_BEGIN(Toolkit::PushButton, Toolkit::Button, Create) -/** - * Find the first image actor in the actor hierarchy - */ -ImageActor FindImageActor( Actor root ) -{ - ImageActor imageActor = ImageActor::DownCast( root ); - if( !imageActor && root ) - { - for( unsigned int i = 0, numChildren = root.GetChildCount(); i < numChildren; ++i ) - { - ImageActor childImageActor = FindImageActor( root.GetChildAt( i ) ); - if( childImageActor ) - { - return childImageActor; - } - } - } +DALI_PROPERTY_REGISTRATION(Toolkit, PushButton, "labelPadding", STRING, LABEL_PADDING) +DALI_PROPERTY_REGISTRATION(Toolkit, PushButton, "iconPadding", STRING, ICON_PADDING) - return imageActor; -} +DALI_TYPE_REGISTRATION_END() +} // unnamed namespace +namespace +{ } // unnamed namespace Dali::Toolkit::PushButton PushButton::New() { // Create the implementation, temporarily owned on stack - IntrusivePtr< PushButton > internalPushButton = new PushButton(); + IntrusivePtr internalPushButton = new PushButton(); // Pass ownership to CustomActor - Dali::Toolkit::PushButton pushButton( *internalPushButton ); + Dali::Toolkit::PushButton pushButton(*internalPushButton); // Second-phase init of the implementation // This can only be done after the CustomActor connection has been made... @@ -93,70 +77,146 @@ Dali::Toolkit::PushButton PushButton::New() return pushButton; } -void PushButton::OnButtonInitialize() -{ - // Push button requires the Leave event. - Actor root = Self(); - root.SetLeaveRequired( true ); -} - PushButton::PushButton() -: Button() +: Button(), + mIconAlignment(RIGHT) { - // Creates specific painter.GetBu - ButtonPainterPtr painter = PushButtonDefaultPainterPtr( new PushButtonDefaultPainter() ); - SetPainter( painter ); } PushButton::~PushButton() { - SetPainter( NULL ); } -Vector3 PushButton::GetNaturalSize() +void PushButton::OnInitialize() { - Vector3 size = Control::GetNaturalSize(); + Button::OnInitialize(); - const bool widthIsZero = EqualsZero( size.width ); - const bool heightIsZero = EqualsZero( size.height ); + // Push button requires the Leave event. + Actor self = Self(); + self.SetProperty(Actor::Property::LEAVE_REQUIRED, true); - if( widthIsZero || heightIsZero ) + DevelControl::SetAccessibilityConstructor(self, [](Dali::Actor actor) { + return std::unique_ptr( + new AccessibleImpl(actor, Dali::Accessibility::Role::PUSH_BUTTON)); + }); +} + +void PushButton::SetIconAlignment(const PushButton::IconAlignment iconAlignment) +{ + mIconAlignment = iconAlignment; + Button::Align labelAlignment; + switch(iconAlignment) { - // If background and background not scale9 try get size from that - ImageActor imageActor = FindImageActor( GetButtonImage() ); - if( imageActor && imageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) + case RIGHT: + { + labelAlignment = Button::BEGIN; + break; + } + case TOP: + { + labelAlignment = Button::BOTTOM; + break; + } + case BOTTOM: { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( imageActor ); + labelAlignment = Button::TOP; + break; + } + case LEFT: + default: + labelAlignment = Button::END; + break; + } + + Button::SetLabelAlignment(labelAlignment); +} - if( widthIsZero ) +const PushButton::IconAlignment PushButton::GetIconAlignment() const +{ + return mIconAlignment; +} + +void PushButton::SetProperty(BaseObject* object, Property::Index propertyIndex, const Property::Value& value) +{ + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(Dali::BaseHandle(object)); + + if(pushButton) + { + PushButton& pushButtonImpl(GetImplementation(pushButton)); + + // Properties remain here for Tizen 3.0 legacy requirements. Are now in Button base class + + switch(propertyIndex) + { + case Toolkit::PushButton::Property::LABEL_PADDING: { - size.width = imageSize.width; + Vector4 padding(value.Get()); + pushButtonImpl.Button::SetLabelPadding(Padding(padding.x, padding.y, padding.z, padding.w)); + break; } - - if( heightIsZero ) + case Toolkit::PushButton::Property::ICON_PADDING: { - size.height = imageSize.height; + Vector4 padding(value.Get()); + pushButtonImpl.Button::SetForegroundPadding(Padding(padding.x, padding.y, padding.z, padding.w)); + break; } } + } +} - ImageActor backgroundImageActor = FindImageActor( GetBackgroundImage() ); - if( backgroundImageActor && backgroundImageActor.GetStyle() != ImageActor::STYLE_NINE_PATCH ) - { - Vector3 imageSize = RelayoutHelper::GetNaturalSize( backgroundImageActor ); +Property::Value PushButton::GetProperty(BaseObject* object, Property::Index propertyIndex) +{ + Property::Value value; - if( widthIsZero ) + Toolkit::PushButton pushButton = Toolkit::PushButton::DownCast(Dali::BaseHandle(object)); + + if(pushButton) + { + PushButton& pushButtonImpl(GetImplementation(pushButton)); + + switch(propertyIndex) + { + case Toolkit::PushButton::Property::LABEL_PADDING: { - size.width = std::max( size.width, imageSize.width ); + Padding padding = pushButtonImpl.Button::GetLabelPadding(); + value = Vector4(padding.x, padding.y, padding.top, padding.bottom); + break; } - - if( heightIsZero ) + case Toolkit::PushButton::Property::ICON_PADDING: { - size.height = std::max( size.height, imageSize.height ); + Padding padding = pushButtonImpl.Button::GetForegroundPadding(); + value = Vector4(padding.x, padding.y, padding.top, padding.bottom); + break; } } } - return size; + return value; +} + +Dali::Accessibility::States PushButton::AccessibleImpl::CalculateStates() +{ + auto tmp = Button::AccessibleImpl::CalculateStates(); + auto slf = Toolkit::Button::DownCast(Self()); + tmp[Dali::Accessibility::State::PRESSED] = slf.GetProperty(Toolkit::Button::Property::SELECTED); + return tmp; +} + +void PushButton::OnStateChange(State newState) +{ + // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used + if(Dali::Accessibility::IsUp() && (Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor() == Self()) + && (newState == SELECTED_STATE || newState == UNSELECTED_STATE)) + { + Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged( + Dali::Accessibility::State::PRESSED, newState == SELECTED_STATE ? 1 : 0, 0); + + if(Self().GetProperty(Toolkit::Button::Property::TOGGLABLE)) + { + Dali::Accessibility::Accessible::Get(Self())->EmitStateChanged( + Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0); + } + } } } // namespace Internal