Revert "[Tizen] Add DALi Autofill implementation"
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / input-method-options.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/devel-api/adaptor-framework/input-method-options.h>
20
21 using namespace Dali::InputMethod;
22 using namespace Dali::InputMethod::Category;
23
24 namespace Dali
25 {
26
27 #define TOKEN_STRING(x) #x
28
29 struct InputMethodOptions::Impl
30 {
31   Impl()
32   {
33     mPanelLayout = PanelLayout::NORMAL;
34     mAutoCapital = AutoCapital::SENTENCE;
35     mButtonAction = ButtonAction::DEFAULT;
36     mVariation = NormalLayout::NORMAL;
37   }
38
39   PanelLayout::Type mPanelLayout;
40   AutoCapital::Type mAutoCapital;
41   ButtonAction::Type mButtonAction;
42   int mVariation:4;
43 };
44
45 InputMethodOptions::InputMethodOptions()
46 {
47   mImpl.reset(new Impl());
48 }
49
50 InputMethodOptions::~InputMethodOptions()
51 {
52   // destructor cannot be inlined and must be in a unit
53   // for unique_ptr to work with forward declaration
54 }
55
56 bool InputMethodOptions::IsPassword() const
57 {
58   return (mImpl->mPanelLayout == Dali::InputMethod::PanelLayout::PASSWORD);
59 }
60
61 void InputMethodOptions::ApplyProperty( const Property::Map& settings )
62 {
63   for ( unsigned int i = 0, count = settings.Count(); i < count; ++i )
64   {
65     Property::Key key = settings.GetKeyAt( i );
66     if( key.type == Property::Key::INDEX )
67     {
68       continue;
69     }
70
71     Property::Value item = settings.GetValue(i);
72
73     if( key == TOKEN_STRING( PANEL_LAYOUT ) )
74     {
75       if( item.GetType() == Property::INTEGER )
76       {
77         int value = item.Get< int >();
78         mImpl->mPanelLayout = static_cast<InputMethod::PanelLayout::Type>(value);
79       }
80     }
81     else if ( key == TOKEN_STRING( BUTTON_ACTION ) )
82     {
83       if ( item.GetType() == Property::INTEGER )
84       {
85         int value = item.Get< int >();
86         mImpl->mButtonAction = static_cast<InputMethod::ButtonAction::Type>(value);
87       }
88     }
89     else if ( key == TOKEN_STRING( AUTO_CAPITALIZE ) )
90     {
91       if ( item.GetType() == Property::INTEGER )
92       {
93         int value = item.Get< int >();
94         mImpl->mAutoCapital = static_cast<InputMethod::AutoCapital::Type>(value);
95       }
96     }
97     else if( key == TOKEN_STRING( VARIATION ) )
98     {
99       if( item.GetType() == Property::INTEGER )
100       {
101         int value = item.Get< int >();
102         mImpl->mVariation = value;
103       }
104     }
105     else
106     {
107     }
108   }
109 }
110
111 void InputMethodOptions::RetrieveProperty( Property::Map& settings )
112 {
113   settings[TOKEN_STRING( PANEL_LAYOUT )] = mImpl->mPanelLayout;
114   settings[TOKEN_STRING( BUTTON_ACTION )] = mImpl->mButtonAction;
115   settings[TOKEN_STRING( AUTO_CAPITALIZE )] = mImpl->mAutoCapital;
116   settings[TOKEN_STRING( VARIATION )] = mImpl->mVariation;
117 }
118
119 bool InputMethodOptions::CompareAndSet( InputMethod::Category::Type type, const InputMethodOptions& options, int& index)
120 {
121   bool updated = false;
122
123   switch (type)
124   {
125     case PANEL_LAYOUT:
126     {
127       if ( options.mImpl->mPanelLayout != mImpl->mPanelLayout )
128       {
129         mImpl->mPanelLayout = options.mImpl->mPanelLayout;
130         index = static_cast<int>(mImpl->mPanelLayout);
131         updated = true;
132       }
133       break;
134     }
135     case BUTTON_ACTION:
136     {
137       if ( options.mImpl->mButtonAction != mImpl->mButtonAction )
138       {
139         mImpl->mButtonAction = options.mImpl->mButtonAction;
140         index = static_cast<int>(mImpl->mButtonAction);
141         updated = true;
142       }
143       break;
144     }
145     case AUTO_CAPITALIZE:
146     {
147       if ( options.mImpl->mAutoCapital != mImpl->mAutoCapital )
148       {
149         mImpl->mAutoCapital = options.mImpl->mAutoCapital;
150         index = static_cast<int>(mImpl->mAutoCapital);
151         updated = true;
152       }
153       break;
154     }
155     case VARIATION:
156     {
157       if ( options.mImpl->mVariation != mImpl->mVariation )
158       {
159         mImpl->mVariation = options.mImpl->mVariation;
160         index = static_cast<int>(mImpl->mVariation);
161         updated = true;
162       }
163       break;
164     }
165   }
166   return updated;
167 }
168
169 } // namespace Dali