// Open Service Platform
// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
//
-// Licensed under the Flora License, Version 1.0 (the License);
+// 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://floralicense.org/license/
+// 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,
+// 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.
#include "FUi_AccessibilityElement.h"
#include "FUi_AccessibilityManager.h"
#include "FUi_CoordinateSystemUtils.h"
+#include "FUiCtrl_SearchBarImpl.h"
+#include "FUiCtrl_EditFieldImpl.h"
+#include "FUiCtrl_ButtonImpl.h"
+#include <FSys_SettingInfoImpl.h>
+
using namespace Tizen::Graphics;
using namespace Tizen::Ui;
using namespace Tizen::Base;
using namespace Tizen::Base::Runtime;
using namespace Tizen::Locales;
+using namespace Tizen::System;
namespace Tizen { namespace Ui { namespace Controls
{
, __isCancelActionInProgress(false)
, __isUserGuideTextColor(false)
, __isKeypadOpening(false)
+ , __isupdateContentBounds(false)
+ , __isKeyPressed(false)
+ , __isFocusCallbackToBeFired(true)
+ , __isButtonTextChangedByApp(false)
, __keypadAction(CORE_KEYPAD_ACTION_SEARCH)
, __pBackgroundBitmap(null)
, __backgroundColor(Color())
, __pTextEvent(null)
, __pSearchBarEvent(null)
, __pLanguageEvent(null)
- , __isupdateContentBounds(false)
+ , __pAccessibilitySearchBarElement(null)
{
for (int i = 0; i < SEARCHBAR_BUTTON_COLOR_MAX; i++)
{
_SearchBar::~_SearchBar(void)
{
+ SettingInfo::RemoveSettingEventListener(*this);
delete __pSearchBarPresenter;
__pSearchBarPresenter = null;
- if (__pEdit)
- {
- __pEdit->HideKeypad();
-
- __pClippedGroupControl->DetachChild(*__pEdit);
-
- delete __pEdit;
- __pEdit = null;
- }
-
- if (__pCancelButton)
- {
- __pClippedGroupControl->DetachChild(*__pCancelButton);
-
- delete __pCancelButton;
- __pCancelButton = null;
- }
-
if (__pClippedGroupControl)
{
DetachChild(*__pClippedGroupControl);
__pSearchBarEvent = null;
}
+ if (__pAccessibilitySearchBarElement)
+ {
+ __pAccessibilitySearchBarElement->Activate(false);
+ __pAccessibilitySearchBarElement = null;
+ }
+
delete __pBackgroundBitmap;
__pBackgroundBitmap = null;
}
}
pSearchBar->AcquireHandle();
+ pSearchBar->SetTouchPressThreshold(_TOUCH_PRESS_THRESHOLD_INSENSITIVE);
return pSearchBar;
}
__pSearchBarPresenter = pPresenter;
+ CreateAccessibilityElement();
+
+ r = _SettingInfoImpl::AddSettingEventListener(*this);
+ SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
return r;
CATCH:
float textHorizontalMargin = 0.0f;
float iconWidth = 0.0f;
float textSize = 0.0f;
- float searchFieldMinWidth = 0.0f;
float searchBarMinHeight = 0.0f;
+ float searchBarMinWidthModeNormal = 0.0f;
FloatRectangle searchBarBounds = GetBoundsF();
_ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
- _AccessibilityContainer* pSearchBarContainer = null;
GET_SHAPE_CONFIG(SEARCHBAR::HORIZONTAL_MARGIN, orientation, horizontalMargin);
GET_SHAPE_CONFIG(SEARCHBAR::VERTICAL_MARGIN, orientation, verticalMargin);
GET_SHAPE_CONFIG(SEARCHBAR::ICON_HORIZONTAL_MARGIN, orientation, iconHorizontalMargin);
GET_SHAPE_CONFIG(SEARCHBAR::ICON_WIDTH, orientation, iconWidth);
GET_SHAPE_CONFIG(SEARCHBAR::TEXT_HORIZONTAL_MARGIN, orientation, textHorizontalMargin);
- GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH, orientation, searchFieldMinWidth);
+ GET_SHAPE_CONFIG(SEARCHBAR::SEARCH_FIELD_MIN_WIDTH_NORMAL_MODE, orientation, searchBarMinWidthModeNormal);
GET_SHAPE_CONFIG(SEARCHBAR::MIN_HEIGHT, orientation, searchBarMinHeight);
float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
editBounds.x = horizontalMargin;
+
+ if (searchBarBounds.height < searchBarMinHeight)
+ {
+ verticalMargin = (searchBarBounds.height - searchFieldMinHeight)/2.0f;
+ if (verticalMargin < 0.0f)
+ {
+ verticalMargin = 0.0f;
+ }
+ }
+
editBounds.y = verticalMargin;
+
editBounds.width = searchBarBounds.width - (editBounds.x * 2.0f);
editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
- editBounds.width = (editBounds.width > searchFieldMinWidth) ? editBounds.width : searchFieldMinWidth;
+ editBounds.width = (editBounds.width > searchBarMinWidthModeNormal) ? editBounds.width : searchBarMinWidthModeNormal;
editBounds.height = (editBounds.height > searchFieldMinHeight) ? editBounds.height : searchFieldMinHeight;
- __pEdit = _Edit::CreateEditN();
- r = GetLastResult();
- SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
+ _SearchBarImpl* pSearchBarImpl = static_cast<_SearchBarImpl*>(GetUserData());
+ __pEdit = &(pSearchBarImpl->GetEditFieldImpl()->GetCore());
- r = __pEdit->Initialize(EDIT_STYLE_NORMAL | EDIT_STYLE_SINGLE_LINE | EDIT_STYLE_CLEAR | EDIT_STYLE_NOSCROLL, INPUT_STYLE_OVERLAY,
- SEARCHBAR_TEXT_LENGTH_MAX);
- SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+ SysTryReturnResult(NID_UI_CTRL, __pEdit != null, E_SYSTEM,
+ "[E_SYSTEM] A system error has occured. Failed to get _Edit instance");
__pEdit->SetKeypadCommandButtonVisible(false);
__pEdit->SetBounds(editBounds);
SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
"[E_SYSTEM] A system error has occurred. Failed to attach edit as child.");
- if (likely(!(_AccessibilityManager::IsActivated())))
- {
- return E_SUCCESS;
- }
-
- pSearchBarContainer = GetAccessibilityContainer();
- if (pSearchBarContainer)
- {
- _AccessibilityContainer* pSearchFieldContainer = __pEdit->GetAccessibilityContainer();
- if (pSearchFieldContainer)
- {
- pSearchBarContainer->AddChildContainer(*pSearchFieldContainer);
- }
- }
-
return E_SUCCESS;
CATCH:
String cancelButtonText;
_ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
- _AccessibilityContainer* pSearchBarContainer = null;
- __pCancelButton = _Button::CreateButtonN();
+ _SearchBarImpl* pSearchBarImpl = static_cast<_SearchBarImpl*>(GetUserData());
+ __pCancelButton = &(pSearchBarImpl->GetButtonImpl()->GetCore());
+
+ SysTryReturnResult(NID_UI_CTRL, __pCancelButton != null, E_SYSTEM,
+ "[E_SYSTEM] A system error has occured. Failed to get _Edit instance");
+
r = GetLastResult();
SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM,
"[E_SYSTEM] A system error has occurred. Failed to attach button as child.");
- if (likely(!(_AccessibilityManager::IsActivated())))
- {
- return E_SUCCESS;
- }
-
- pSearchBarContainer = GetAccessibilityContainer();
- if (pSearchBarContainer)
- {
- _AccessibilityContainer* pButtonContainer = __pCancelButton->GetAccessibilityContainer();
- if (pButtonContainer)
- {
- pSearchBarContainer->AddChildContainer(*pButtonContainer);
- }
- }
-
return E_SUCCESS;
CATCH:
}
FloatRectangle controlBounds = GetBoundsF();
+ controlBounds = CoordinateSystem::AlignToDevice(FloatRectangle(controlBounds));
+
__contentAreaBounds.x = 0.0f;
__contentAreaBounds.y = controlBounds.height;
__contentAreaBounds.width = width - controlBounds.x;
result
_SearchBar::SetModeLocked(bool modeLocked)
{
+ if (modeLocked == true && GetMode() == SEARCH_BAR_MODE_NORMAL)
+ {
+ __pEdit->SetViewModeEnabled(true);
+ }
+
+ if (modeLocked == false && __pEdit->IsViewModeEnabled())
+ {
+ __pEdit->SetViewModeEnabled(false);
+ }
+
return __pSearchBarPresenter->SetModeLocked(modeLocked);
}
SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, E_SYSTEM, E_SYSTEM,
"[E_SYSTEM] A system error has occurred. Failed to set text.");
+ __isButtonTextChangedByApp = true;
+
return r;
}
__isupdateContentBounds = true;
__pSearchBarPresenter->OnBoundsChanged();
}
+
+ if (__pAccessibilitySearchBarElement)
+ {
+ __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
+ }
return;
}
return _UI_TOUCH_EVENT_DELIVERY_YES;
}
- SetMode(SEARCH_BAR_MODE_INPUT);
-
return _UI_TOUCH_EVENT_DELIVERY_YES;
}
__pKeypadEvent->Fire(*pEventArg);
}
+ __isKeypadOpening = false;
+
SetContentsArea();
return;
}
_SearchBar::OnAttachedToMainTree(void)
{
SetContentsArea();
-
return E_SUCCESS;
}
bool
_SearchBar::OnFocusGained(const _Control& source)
{
- SetMode(SEARCH_BAR_MODE_INPUT);
- __pEdit->SetFocused();
- return false;
+ if (__isKeyPressed)
+ {
+ __isKeyPressed = false;
+ _Control::OnDrawFocus();
+
+ return true;
+ }
+
+ if (GetVisibleState() == true)
+ {
+ __pEdit->SetFocused();
+ }
+
+ return true;
}
bool
-_SearchBar::OnFocusLost(const _Control& source)
+_SearchBar::OnFocusLost(const _Control &source)
{
- return false;
+ __pEdit->SetSearchFieldFocus(false);
+ _Control::OnFocusLost(source);
+ return true;
}
bool
return false;
}
+ if (!__pEdit->IsSearchFieldFocused())
+ {
+ return false;
+ }
+
_KeyCode keyCode = keyInfo.GetKeyCode();
- if (keyCode == _KEY_RIGHT)
+ switch (keyCode)
{
- if (__isButtonEnabled)
- {
- __pEdit->SetFocused(false);
- __pCancelButton->SetButtonStatus(_BUTTON_STATUS_HIGHLIGHTED);
- __pCancelButton->SetFocused();
- __pCancelButton->Invalidate(true);
- }
+ case _KEY_RIGHT:
+ SetFocusCallbackParameter(false);
+ if (&source == __pEdit)
+ {
+ if ((!__isButtonEnabled || !__isUsableCancelButton) && __pContentControl && __pContentControl->GetVisibleState() && __pContentControl->GetEnableState())
+ {
+ __pContentControl->SetFocused();
+ __pContentControl->OnDrawFocus();
- return true;
- }
+ return true;
+ }
+ else if (__isButtonEnabled && __isUsableCancelButton)
+ {
+ __pCancelButton->SetFocused();
+ }
- if (keyCode == _KEY_LEFT)
- {
- if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_HIGHLIGHTED)
- {
- __pCancelButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
- __pCancelButton->SetFocused(false);
- __pCancelButton->Invalidate();
+ return true;
+ }
- }
+ if (&source == __pCancelButton && __pContentControl && __pContentControl->GetVisibleState() && __pContentControl->GetEnableState())
+ {
+ __pContentControl->SetFocused();
+ __pContentControl->OnDrawFocus();
- if (__pCancelButton->GetButtonStatus() == _BUTTON_STATUS_DISABLED) //Searchbar Button is disabled, left arrow key is pressed
- {
- __pCancelButton->SetButtonStatus(_BUTTON_STATUS_NORMAL);
- SetButtonEnabled(false);
- }
+ return true;
+ }
- __pEdit->SetFocused();
+ break;
- return true;
+ case _KEY_LEFT:
+ if (&source == __pCancelButton)
+ {
+ __pEdit->SetFocused();
+ return true;
+ }
+
+ if (&source == __pContentControl)
+ {
+ if ((__isButtonEnabled && __isUsableCancelButton))
+ {
+ __pCancelButton->SetFocused();
+ }
+ else
+ {
+ __pEdit->SetFocused();
+ }
+ return true;
+ }
+
+ break;
+
+ case _KEY_ENTER:
+ if (&source == __pCancelButton)
+ {
+ SetMode(SEARCH_BAR_MODE_NORMAL);
+ __isKeyPressed = true;
+ SetFocused();
+ _Control::OnDrawFocus();
+
+ return true;
+ }
+
+ break;
+
+ default:
+ return false;
}
return false;
}
-bool
-_SearchBar::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
+void
+_SearchBar::OnSettingChanged(Tizen::Base::String& key)
{
- return false;
+ if (__isButtonTextChangedByApp || !__isUsableCancelButton)
+ {
+ return;
+ }
+
+ if (key.Equals(L"http://tizen.org/setting/locale.language", false))
+ {
+ String cancelText;
+ GET_STRING_CONFIG(IDS_COM_SK_CANCEL, cancelText);
+ __pCancelButton->SetText(cancelText);
+ __pCancelButton->Invalidate();
+ }
+
+ return;
}
_Control*
}
void
+_SearchBar::CreateAccessibilityElement(void)
+{
+ if (__pAccessibilitySearchBarElement != null)
+ {
+ return;
+ }
+ _AccessibilityContainer* pContainer = null;
+ pContainer = GetAccessibilityContainer();
+
+ if (pContainer)
+ {
+ __pAccessibilitySearchBarElement = new (std::nothrow) _AccessibilityElement(true);
+ SysTryReturnVoidResult(NID_UI_CTRL, __pAccessibilitySearchBarElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Failed to allocate memory.");
+ __pAccessibilitySearchBarElement->SetBounds(FloatRectangle(0.0f, 0.0f, GetBoundsF().width, GetBoundsF().height));
+ __pAccessibilitySearchBarElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
+ __pAccessibilitySearchBarElement->SetName("SearchBar");
+ pContainer->AddElement(*__pAccessibilitySearchBarElement);
+ }
+
+ return;
+}
+
+void
_SearchBar::SetContentDimming(void)
{
if (__pContainer != NULL)
return;
}
+void
+_SearchBar::OnDrawFocus(void)
+{
+ __pEdit->SetSearchFieldFocus(true);
+ return;
+}
+
bool
_SearchBar::IsContentAttachable(const _Control* pContent)
{
cancelButtonBounds.x = searchBarBounds.width - cancelButtonBounds.width - buttonRightMargin;
cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
- if (searchBarBounds.height < searchBarMinHeight)
- {
- cancelButtonBounds.y = buttonVerticalMargin;
- }
+ cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
if (cancelButtonBounds.width < buttonMinWidth)
{
float searchBarMinHeight = 0.0f;
float buttonWidth = 0.0f;
float buttonHeight = 0.0f;
+ float cancelButtonWidth = 0.0f;
FloatRectangle cancelButtonBounds;
+ FloatRectangle editBounds;
FloatRectangle searchBarBounds = GetBoundsF();
_ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
cancelButtonBounds.height = buttonHeight;
- FloatRectangle editBounds;
-
- float cancelButtonWidth = 0;
+ float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
cancelButtonWidth = __pCancelButton->GetTextExtentSizeF() + __pCancelButton->GetRightTouchMarginF() + __pCancelButton->GetLeftTouchMarginF() + __pCancelButton->GetRightMarginF() + __pCancelButton->GetLeftMarginF();
editBounds.x = horizontalMargin;
- editBounds.y = verticalMargin;
+ if (searchBarBounds.height < searchBarMinHeight)
+ {
+ verticalMargin = (searchBarBounds.height - searchFieldMinHeight)/2.0f;
+ if (verticalMargin < 0.0f)
+ {
+ verticalMargin = 0.0f;
+ }
+ }
+
+ editBounds.y = verticalMargin;
editBounds.height = searchBarBounds.height - (editBounds.y * 2.0f);
- float searchFieldMinHeight = searchBarMinHeight - (verticalMargin * 2.0f);
editBounds.height = (editBounds.height > searchFieldMinHeight) ? editBounds.height : searchFieldMinHeight;
editBounds.width = searchBarBounds.width - cancelButtonWidth - horizontalMargin - buttonLeftMargin - buttonRightMargin;
cancelButtonBounds.x = editBounds.width + horizontalMargin + buttonLeftMargin;
cancelButtonBounds.y = (searchBarBounds.height - cancelButtonBounds.height)/2.0f;
- if (searchBarBounds.height < searchBarMinHeight)
- {
- cancelButtonBounds.y = buttonVerticalMargin;
- }
+ cancelButtonBounds.y = cancelButtonBounds.y < 0.0f ? 0.0f:cancelButtonBounds.y;
float remainingWidth = searchBarBounds.width - editBounds.width - horizontalMargin - buttonLeftMargin - buttonRightMargin;
return;
}
+void
+_SearchBar::SetFocusCallbackParameter(bool state)
+{
+ __isFocusCallbackToBeFired = state;
+ return;
+}
+
+bool
+_SearchBar::IsFocusCallbackToBeFired(void) const
+{
+ return __isFocusCallbackToBeFired;
+}
}}} // Tizen::Ui::Controls