From: minho.sun Date: Fri, 9 Jun 2017 05:01:25 +0000 (+0900) Subject: Added config section to stylesheet X-Git-Tag: dali_1.2.47~9^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=e92dc54dd0580f27586bcaf04bf9fa2a6ae798dc;hp=4e4b3eb5e5a03a92f78da6bbcfc61d6824f8e441 Added config section to stylesheet Added config section to stylesheet. User can set configuration for dali-toolkit via this section. Currently, user can use only "alwaysShowFocus" which is for KeyboardFocusManager. ( If true, shows focus indicator even if there is no KeyEvent. ) Change-Id: Iac2a6202c22a6026c63b3f42542c99341e73ad7b Signed-off-by: minho.sun --- diff --git a/automated-tests/src/dali-toolkit-styling/default-theme.json b/automated-tests/src/dali-toolkit-styling/default-theme.json index c9e87f8..6b3ddd1 100644 --- a/automated-tests/src/dali-toolkit-styling/default-theme.json +++ b/automated-tests/src/dali-toolkit-styling/default-theme.json @@ -1,4 +1,8 @@ { + "config": + { + "alwaysShowFocus":false + }, "constants": { "CONFIG_SCRIPT_LOG_LEVEL":"NoLogging" diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp index 60f4a1b..f134be3 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Builder.cpp @@ -1820,3 +1820,33 @@ int UtcDaliBuilderActionsWithParams(void) END_TEST; } + +int UtcDaliBuilderConfigurationP(void) +{ + ToolkitTestApplication application; + + // JSON with a quit event when the actor is touched + std::string json( + "{\n" + " \"config\":\n" + " {\n" + " \"alwaysShowFocus\":true\n" + " }\n" + "}\n" + ); + + Builder builder = Builder::New(); + builder.LoadFromString( json ); + + Property::Map map = builder.GetConfigurations(); + + Dali::Property::Value* pValue = map.Find( "alwaysShowFocus" ); + + DALI_TEST_CHECK( pValue ); + + bool value = pValue->Get(); + + DALI_TEST_CHECK( value ); + + END_TEST; +} diff --git a/build/tizen/dali-toolkit/Makefile.am b/build/tizen/dali-toolkit/Makefile.am index a766f83..c2f73c3 100644 --- a/build/tizen/dali-toolkit/Makefile.am +++ b/build/tizen/dali-toolkit/Makefile.am @@ -118,6 +118,7 @@ develapifocusmanagerdir = $(develapidir)/focus-manager develapiimageloaderdir = $(develapidir)/image-loader develapiscriptingdir = $(develapidir)/scripting develapishadereffectsdir = $(develapidir)/shader-effects +develapistylingdir = $(develapidir)/styling develapitransitioneffectsdir = $(develapidir)/transition-effects develapitoolbardir = $(develapicontrolsdir)/tool-bar develapitooltipdir = $(develapicontrolsdir)/tooltip @@ -149,6 +150,7 @@ develapivisuals_HEADERS = $(devel_api_visuals_header_files) develapiscripting_HEADERS = $(devel_api_scripting_header_files) develapishadowview_HEADERS = $(devel_api_shadow_view_header_files) develapishadereffects_HEADERS = $(devel_api_shader_effects_header_files) +develapistyling_HEADERS = $(devel_api_styling_header_files) develapisuperblurview_HEADERS = $(devel_api_super_blur_view_header_files) develapitoolbar_HEADERS = $(devel_api_tool_bar_header_files) develapitooltip_HEADERS = $(devel_api_tooltip_header_files) diff --git a/dali-toolkit/devel-api/builder/builder.cpp b/dali-toolkit/devel-api/builder/builder.cpp index 4270b1e..64a08a0 100644 --- a/dali-toolkit/devel-api/builder/builder.cpp +++ b/dali-toolkit/devel-api/builder/builder.cpp @@ -64,6 +64,11 @@ void Builder::AddConstant( const std::string& key, const Property::Value& value GetImpl(*this).AddConstant( key, value ); } +const Property::Map& Builder::GetConfigurations() const +{ + return GetImpl(*this).GetConfigurations(); +} + const Property::Map& Builder::GetConstants() const { return GetImpl(*this).GetConstants(); diff --git a/dali-toolkit/devel-api/builder/builder.h b/dali-toolkit/devel-api/builder/builder.h index 530a81a..422a517 100644 --- a/dali-toolkit/devel-api/builder/builder.h +++ b/dali-toolkit/devel-api/builder/builder.h @@ -187,6 +187,14 @@ class DALI_IMPORT_API Builder : public BaseHandle void AddConstant( const std::string& key, const Property::Value& value ); /** + * @brief Gets all currently defined configurations. + * + * @pre The Builder has been initialized. + * @return A reference to the currently defined configurations. + */ + const Property::Map& GetConfigurations() const; + + /** * @brief Gets all currently defined constants. * * e.g. diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index fe8ef2b..3645136 100644 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -30,6 +30,7 @@ devel_api_src_files = \ $(devel_api_src_dir)/image-loader/atlas-upload-observer.cpp \ $(devel_api_src_dir)/image-loader/image-atlas.cpp \ $(devel_api_src_dir)/scripting/script.cpp \ + $(devel_api_src_dir)/styling/style-manager-devel.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-cross-effect.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-effect.cpp \ $(devel_api_src_dir)/transition-effects/cube-transition-fold-effect.cpp \ @@ -131,6 +132,9 @@ devel_api_shader_effects_header_files = \ $(devel_api_src_dir)/shader-effects/motion-blur-effect.h \ $(devel_api_src_dir)/shader-effects/motion-stretch-effect.h +devel_api_styling_header_files= \ + $(devel_api_src_dir)/styling/style-manager-devel.h + devel_api_super_blur_view_header_files = \ $(devel_api_src_dir)/controls/super-blur-view/super-blur-view.h diff --git a/dali-toolkit/devel-api/styling/style-manager-devel.cpp b/dali-toolkit/devel-api/styling/style-manager-devel.cpp new file mode 100644 index 0000000..7ac5a64 --- /dev/null +++ b/dali-toolkit/devel-api/styling/style-manager-devel.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelStyleManager +{ + +const Property::Map GetConfigurations( StyleManager styleManager ) +{ + return GetImpl(styleManager).GetConfigurations(); +} + +} // namespace DevelStyleManager + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/styling/style-manager-devel.h b/dali-toolkit/devel-api/styling/style-manager-devel.h new file mode 100644 index 0000000..faf3c57 --- /dev/null +++ b/dali-toolkit/devel-api/styling/style-manager-devel.h @@ -0,0 +1,49 @@ +#ifndef DALI_TOOLKIT_STYLE_MANAGER_DEVEL_H +#define DALI_TOOLKIT_STYLE_MANAGER_DEVEL_H + +/* + * Copyright (c) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelStyleManager +{ + + +/** + * @brief Gets all currently defined configurations. + * + * @pre The Builder has been initialized. + * @param[in] styleManager The instance of StyleManager + * @return A property map to the currently defined configurations +**/ +DALI_IMPORT_API const Property::Map GetConfigurations( StyleManager styleManager ); + +} // namespace DevelStyleManager + +} // namespace Toolkit + +} // namespace Dali + +#endif // DALI_TOOLKIT_STYLE_MANAGER_DEVEL_H diff --git a/dali-toolkit/internal/builder/builder-impl.cpp b/dali-toolkit/internal/builder/builder-impl.cpp index e4ef639..4a23ed1 100644 --- a/dali-toolkit/internal/builder/builder-impl.cpp +++ b/dali-toolkit/internal/builder/builder-impl.cpp @@ -179,9 +179,10 @@ void Builder::LoadFromString( std::string const& data, Dali::Toolkit::Builder::U } else { + // load configuration map + LoadConfiguration( *parser.GetRoot(), mConfigurationMap ); // load constant map (allows the user to override the constants in the json after loading) LoadConstants( *parser.GetRoot(), mReplacementMap ); - // merge includes if( OptionalChild includes = IsChild(*parser.GetRoot(), KEYNAME_INCLUDES) ) { @@ -228,6 +229,11 @@ void Builder::AddConstant( const std::string& key, const Property::Value& value mReplacementMap[key] = value; } +const Property::Map& Builder::GetConfigurations() const +{ + return mConfigurationMap; +} + const Property::Map& Builder::GetConstants() const { return mReplacementMap; @@ -773,6 +779,25 @@ Builder::~Builder() { } +void Builder::LoadConfiguration( const TreeNode& root, Property::Map& intoMap ) +{ + Replacement replacer(intoMap); + + if( OptionalChild constants = IsChild(root, "config") ) + { + for(TreeNode::ConstIterator iter = (*constants).CBegin(); + iter != (*constants).CEnd(); ++iter) + { + Dali::Property::Value property; + if( (*iter).second.GetName() ) + { + DeterminePropertyFromNode( (*iter).second, property, replacer ); + intoMap[ (*iter).second.GetName() ] = property; + } + } + } +} + void Builder::LoadConstants( const TreeNode& root, Property::Map& intoMap ) { Replacement replacer(intoMap); diff --git a/dali-toolkit/internal/builder/builder-impl.h b/dali-toolkit/internal/builder/builder-impl.h index ea0b635..8a90b03 100644 --- a/dali-toolkit/internal/builder/builder-impl.h +++ b/dali-toolkit/internal/builder/builder-impl.h @@ -95,6 +95,11 @@ public: void AddConstant( const std::string& key, const Property::Value& value ); /** + * @copydoc Toolkit::Builder::GetConfigurations + */ + const Property::Map& GetConfigurations() const; + + /** * @copydoc Toolkit::Builder::GetConstants */ const Property::Map& GetConstants() const; @@ -257,6 +262,8 @@ private: void LoadConstants( const TreeNode& root, Property::Map& intoMap ); + void LoadConfiguration( const TreeNode& root, Property::Map& intoMap ); + Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor ); @@ -384,6 +391,7 @@ private: LinearConstrainerLut mLinearConstrainerLut; SlotDelegate mSlotDelegate; Property::Map mReplacementMap; + Property::Map mConfigurationMap; MappingsLut mCompleteMappings; Dictionary mStyles; // State based styles Toolkit::Builder::BuilderSignalType mQuitSignal; diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index 15e5366..5225c46 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,8 @@ #include #include #include +#include +#include namespace Dali { @@ -116,8 +119,8 @@ KeyboardFocusManager::KeyboardFocusManager() mFocusedActorEnterKeySignal(), mCurrentFocusActor(), mFocusIndicatorActor(), + mIsFocusIndicatorEnabled( -1 ), mFocusGroupLoopEnabled( false ), - mIsFocusIndicatorEnabled( false ), mIsWaitingKeyboardFocusChangeCommit( false ), mFocusHistory(), mSlotDelegate( this ), @@ -132,10 +135,25 @@ KeyboardFocusManager::~KeyboardFocusManager() { } +void KeyboardFocusManager::GetConfigurationFromStyleManger() +{ + Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); + if( styleManager ) + { + Property::Map config = Toolkit::DevelStyleManager::GetConfigurations( styleManager ); + mIsFocusIndicatorEnabled = static_cast(config["alwaysShowFocus"].Get()); + } +} + bool KeyboardFocusManager::SetCurrentFocusActor( Actor actor ) { DALI_ASSERT_DEBUG( !mIsWaitingKeyboardFocusChangeCommit && "Calling this function in the PreFocusChangeSignal callback?" ); + if( mIsFocusIndicatorEnabled == -1 ) + { + GetConfigurationFromStyleManger(); + } + return DoSetCurrentFocusActor( actor ); } @@ -523,7 +541,7 @@ void KeyboardFocusManager::ClearFocus() } mCurrentFocusActor.Reset(); - mIsFocusIndicatorEnabled = false; + mIsFocusIndicatorEnabled = 0; } void KeyboardFocusManager::SetFocusGroupLoop(bool enabled) @@ -623,6 +641,11 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) std::string keyName = event.keyPressedName; + if( mIsFocusIndicatorEnabled == -1 ) + { + GetConfigurationFromStyleManger(); + } + bool isFocusStartableKey = false; if(event.state == KeyEvent::Down) @@ -634,7 +657,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -657,7 +680,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -678,7 +701,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -693,7 +716,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -708,7 +731,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -723,7 +746,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -738,7 +761,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { @@ -754,7 +777,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } isFocusStartableKey = true; @@ -765,7 +788,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } isFocusStartableKey = true; @@ -785,7 +808,7 @@ void KeyboardFocusManager::OnKeyEvent(const KeyEvent& event) if(!mIsFocusIndicatorEnabled && !isAccessibilityEnabled) { // Show focus indicator - mIsFocusIndicatorEnabled = true; + mIsFocusIndicatorEnabled = 1; } else { diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h index 298b3a7..7283b1e 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.h @@ -165,6 +165,11 @@ private: typedef FocusStack::Iterator FocusStackIterator; ///< Define FocusStack::Iterator as FocusStackIterator to navigate FocusStack /** + * Get configuration from StyleManager. + */ + void GetConfigurationFromStyleManger(); + + /** * Get the focus group of current focused actor. * @pre The FocusManager has been initialized. * @return A handle to the parent of the current focused actor which is a focus group, @@ -253,9 +258,9 @@ private: Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the keyboard focusable actors for highlight - bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group + int mIsFocusIndicatorEnabled; ///< Whether indicator should be shown / hidden when getting focus. It could be enabled when keyboard focus feature is enabled and navigation keys or 'Tab' key are pressed. - bool mIsFocusIndicatorEnabled:1; ///< Whether indicator should be shown / hidden. It could be enabled when keyboard focus feature enabled and navigation keys or 'Tab' key pressed. + bool mFocusGroupLoopEnabled:1; ///< Whether the focus movement is looped within the same focus group bool mIsWaitingKeyboardFocusChangeCommit:1; /// A flag to indicate PreFocusChangeSignal emitted but the proposed focus actor is not commited by the application yet. diff --git a/dali-toolkit/internal/styling/style-manager-impl.cpp b/dali-toolkit/internal/styling/style-manager-impl.cpp index ba89d88..df885d9 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.cpp +++ b/dali-toolkit/internal/styling/style-manager-impl.cpp @@ -228,15 +228,22 @@ void StyleManager::SetTheme( const std::string& themeFile ) { bool themeLoaded = false; - mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); - - // Always load the default theme first, then merge in the custom theme if present - themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); - mThemeFile = themeFile; + if( mThemeFile.compare(DEFAULT_THEME) == 0 && mThemeBuilder ) + { + // We have already loaded the default theme into mThemeBuilder + } + else + { + // Reload the default theme + mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); + themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); + } if( themeFile.compare(DEFAULT_THEME) != 0 ) { - themeLoaded = LoadJSON( mThemeBuilder, mThemeFile ); + // The theme is different to the default: Merge it + themeLoaded = LoadJSON( mThemeBuilder, themeFile ); + mThemeFile = themeFile; } if( themeLoaded ) @@ -254,6 +261,32 @@ void StyleManager::SetTheme( const std::string& themeFile ) } } +const Property::Map StyleManager::GetConfigurations() +{ + Property::Map result; + if( mThemeBuilder ) + { + result = mThemeBuilder.GetConfigurations(); + } + else + { + bool themeLoaded = false; + + mThemeBuilder = CreateBuilder( mThemeBuilderConstants ); + + // Load default theme because this is first try to load stylesheet. + themeLoaded = LoadJSON( mThemeBuilder, DEFAULT_THEME ); + mThemeFile = DEFAULT_THEME; + + if( themeLoaded ) + { + result = mThemeBuilder.GetConfigurations(); + } + } + + return result; +} + bool StyleManager::LoadFile( const std::string& filename, std::string& stringOut ) { DALI_ASSERT_DEBUG( 0 != filename.length()); diff --git a/dali-toolkit/internal/styling/style-manager-impl.h b/dali-toolkit/internal/styling/style-manager-impl.h index aa514ea..d6bc4a1 100644 --- a/dali-toolkit/internal/styling/style-manager-impl.h +++ b/dali-toolkit/internal/styling/style-manager-impl.h @@ -94,6 +94,11 @@ public: // Public API bool GetStyleConstant( const std::string& key, Property::Value& valueOut ); /** + * @copydoc Toolkit::StyleManager::GetConfigurations + */ + const Property::Map GetConfigurations(); + + /** * @brief Apply the theme style to a control. * * @param[in] control The control to apply style. diff --git a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json index 8179db5..2569d8b 100644 --- a/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/1920x1080/dali-toolkit-default-theme.json @@ -26,6 +26,10 @@ //****************************************************************************** { + "config": + { + "alwaysShowFocus":false + }, "styles": { "Tooltip": diff --git a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json index 95d2d01..2426b37 100644 --- a/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/480x800/dali-toolkit-default-theme.json @@ -26,6 +26,10 @@ //****************************************************************************** { + "config": + { + "alwaysShowFocus":false + }, "styles": { "Tooltip": diff --git a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json index fdd8182..8877c16 100644 --- a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json @@ -26,6 +26,10 @@ //****************************************************************************** { + "config": + { + "alwaysShowFocus":false + }, "styles": { "TextLabel":