Applied focus UI on TableView
authoryouseong.ji <youseong.ji@samsung.com>
Fri, 24 May 2013 01:03:20 +0000 (10:03 +0900)
committeryouseong.ji <youseong.ji@samsung.com>
Fri, 24 May 2013 01:03:20 +0000 (10:03 +0900)
Change-Id: Ib6df199af01f3b7ca4d862933d046c9bc079792b
Signed-off-by: youseong.ji <youseong.ji@samsung.com>
src/ui/controls/FUiCtrl_TableView.cpp
src/ui/controls/FUiCtrl_TableViewItem.cpp
src/ui/controls/FUiCtrl_TableViewPresenter.cpp
src/ui/inc/FUiCtrl_TableView.h
src/ui/inc/FUiCtrl_TableViewItem.h
src/ui/inc/FUiCtrl_TableViewPresenter.h

index 290cc5e..894060d 100644 (file)
@@ -1361,6 +1361,18 @@ _TableView::GetVisualElementValueAnimation(const Tizen::Base::String& keyName) c
 }
 
 bool
+_TableView::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
+{
+       return __pTableViewPresenter->OnKeyPressed(source, keyInfo);
+}
+
+bool
+_TableView::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
+{
+       return __pTableViewPresenter->OnKeyReleased(source, keyInfo);
+}
+
+bool
 _TableView::IsChildControlFocusManage(void) const
 {
        return true;
index dddca92..a1f8e93 100644 (file)
@@ -522,7 +522,7 @@ _TableViewItem::CreateItemDivider(void)
                __pItemDivider = _TableViewItemControl::CreateTableViewItemControlN();
                r = GetLastResult();
                SysTryReturn(NID_UI_CTRL, __pItemDivider != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
+               __pItemDivider->SetFocusable(false);
                AttachSystemChild(*__pItemDivider);
 
                _AccessibilityContainer* pContainer = __pItemDivider->GetAccessibilityContainer();
@@ -533,7 +533,7 @@ _TableViewItem::CreateItemDivider(void)
        {
                __pItemTopDivider = _TableViewItemControl::CreateTableViewItemControlN();
                SysTryReturn(NID_UI_CTRL, __pItemTopDivider != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
+               __pItemTopDivider->SetFocusable(false);
                AttachSystemChild(*__pItemTopDivider);
 
                _AccessibilityContainer* pContainer = __pItemTopDivider->GetAccessibilityContainer();
@@ -553,7 +553,7 @@ _TableViewItem::CreateItemAnnexDivider(void)
                __pItemAnnexLeftDivider = _TableViewItemControl::CreateTableViewItemControlN();
                r = GetLastResult();
                SysTryReturn(NID_UI_CTRL, __pItemAnnexLeftDivider != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
+               __pItemAnnexLeftDivider->SetFocusable(false);
                AttachSystemChild(*__pItemAnnexLeftDivider);
        }
 
@@ -561,7 +561,7 @@ _TableViewItem::CreateItemAnnexDivider(void)
        {
                __pItemAnnexRightDivider = _TableViewItemControl::CreateTableViewItemControlN();
                SysTryReturn(NID_UI_CTRL, __pItemAnnexRightDivider != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
+               __pItemAnnexRightDivider->SetFocusable(false);
                AttachSystemChild(*__pItemAnnexRightDivider);
        }
 
@@ -607,6 +607,7 @@ _TableViewItem::CreateCheckBox(void)
                float itemHeight = ((__customHeight > 0) ? __customHeight : GetBoundsF().height);
                __pItemAnnex->Construct(FloatRectangle(leftMargin, ((itemHeight - annexHeight) / 2), annexWidth, annexHeight), L"");
                __pItemAnnex->SetBackgroundColor(Color(0, 0, 0, 0));
+               GetLabelCore(__pItemAnnex)->SetFocusable(true);
 
                AttachSystemChild(*GetLabelCore(__pItemAnnex));
        }
@@ -637,6 +638,7 @@ _TableViewItem::CreateRadioBox(void)
                float itemHeight = ((__customHeight > 0) ? __customHeight : GetBoundsF().height);
                __pItemAnnex->Construct(FloatRectangle(leftMargin, ((itemHeight - annexHeight) / 2), annexWidth, annexHeight), L"");
                __pItemAnnex->SetBackgroundColor(Color(0, 0, 0, 0));
+               GetLabelCore(__pItemAnnex)->SetFocusable(true);
 
                AttachSystemChild(*GetLabelCore(__pItemAnnex));
        }
@@ -669,6 +671,7 @@ _TableViewItem::CreateOnOffButton(void)
                float itemHeight = ((__customHeight > 0) ? __customHeight : GetBoundsF().height);
                __pItemAnnex->Construct(FloatRectangle((GetBoundsF().width - annexWidth - leftMargin), ((itemHeight - annexHeight) / 2), annexWidth, annexHeight), L"");
                __pItemAnnex->SetBackgroundColor(Color(0, 0, 0, 0));
+               GetLabelCore(__pItemAnnex)->SetFocusable(true);
 
                AttachSystemChild(*GetLabelCore(__pItemAnnex));
        }
@@ -699,6 +702,7 @@ _TableViewItem::CreateDetailButton(void)
                float itemHeight = ((__customHeight > 0) ? __customHeight : GetBoundsF().height);
                __pItemAnnex->Construct(FloatRectangle((GetBoundsF().width - annexWidth - leftMargin), ((itemHeight - annexHeight) / 2), annexWidth, annexHeight), L"");
                __pItemAnnex->SetBackgroundColor(Color(0, 0, 0, 0));
+               GetLabelCore(__pItemAnnex)->SetFocusable(true);
 
                AttachSystemChild(*GetLabelCore(__pItemAnnex));
        }
@@ -3522,6 +3526,7 @@ _TableViewItem::CreateSimpleItemContents(bool textOnly)
                        __pSimpleItemText->SetTextColor(__simpleItemTextColor[TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL]);
                }
                __pSimpleItemText->SetBackgroundColor(Color(0, 0, 0, 0));
+               GetLabelCore(__pSimpleItemText)->SetFocusable(true);
 
        }
 
@@ -3535,8 +3540,8 @@ _TableViewItem::CreateSimpleItemContents(bool textOnly)
                        SysTryReturn(NID_UI_CTRL, __pSimpleItemBitmap != null, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
                        __pSimpleItemBitmap->Construct(FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), L"");
-
                        __pSimpleItemBitmap->SetBackgroundColor(Color(0, 0, 0, 0));
+                       GetLabelCore(__pSimpleItemBitmap)->SetFocusable(true);
                }
 
        }
@@ -3613,6 +3618,7 @@ _TableViewItem::SetSectionHeaderFooterContents(const Tizen::Base::String& text,
                __pHeaderFooterItemText->SetBackgroundColor(Color(0, 0, 0, 0));
 
                _Label* pHeaderFooterItemTextCore = GetLabelCore(__pHeaderFooterItemText);
+               pHeaderFooterItemTextCore->SetFocusable(true);
                AttachChild(*pHeaderFooterItemTextCore);
        }
 
@@ -4530,5 +4536,173 @@ _TableViewItem::OnAccessibilityValueDecreased(const _AccessibilityContainer& con
        return false;
 }
 
+bool
+_TableViewItem::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
+{
+        _KeyCode keyCode = keyInfo.GetKeyCode();
+        _Control* pFocusedControl = GetFocused();
+        _Control* pChildControl = null;
+        _TableViewItem* pItem = null;
+
+        switch (keyCode)
+        {
+        case _KEY_LEFT:
+                if (pFocusedControl != null)
+                {
+                        pChildControl = GetPreviousFocusChildControl(*pFocusedControl);
+                }
+                break;
+
+        case _KEY_RIGHT:
+                if (pFocusedControl != null)
+                {
+                        pChildControl = GetNextFocusChildControl(*pFocusedControl);
+                }
+                break;
+
+        default:
+                return false;
+        }
+
+        if (pFocusedControl != null)
+        {
+                if (pChildControl)
+                {
+                        pChildControl->SetFocused(true);
+                        pChildControl->DrawFocus();
+                }
+                else
+                {
+                        _Control* pParentControl = pFocusedControl->GetParent();
+                        pParentControl->SetFocused(true);
+                        pParentControl->DrawFocus();
+                }
+        }
+
+        return true;
+}
+
+bool
+_TableViewItem::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
+{
+        _KeyCode keyCode = keyInfo.GetKeyCode();
+
+       if (keyCode == _KEY_LEFT || keyCode == _KEY_RIGHT)
+       {
+               return true;
+       }
+
+       return false;
+}
+
+_Control*
+_TableViewItem::GetPreviousFocusChildControl(const _Control& source)
+{
+        _Control* pParentControl = null;
+        float sourcePosition = 0.0f;
+
+        _Control* pSource = const_cast<_Control*>(&source);
+        _TableViewItem* pItem = dynamic_cast<_TableViewItem*>(pSource);
+        if (pItem != null)
+        {
+                pParentControl = pSource;
+                sourcePosition = pParentControl->GetBoundsF().width;
+        }
+        else
+        {
+                pParentControl = source.GetParent();
+                sourcePosition = source.GetBoundsF().x;
+        }
+
+        if (pParentControl == null)
+        {
+                return null;
+        }
+
+        int childControlCount = pParentControl->GetChildCount();
+        float position = 0.0f;
+        _Control* destination = null;
+
+        for(int i=0; i<childControlCount; i++)
+        {
+                _Control* pChildControl = pParentControl->GetChild(i);
+                if (pChildControl != null && pChildControl->IsFocusable())
+                {
+                        float childPosition = pChildControl->GetBoundsF().x;
+                        if (childPosition < sourcePosition)
+                        {
+                                if (childPosition > position)
+                                {
+                                        position = childPosition;
+                                        destination = pChildControl;
+                                }
+                                else if (_FloatCompare(position, 0.0f))
+                                {
+                                        position = childPosition;
+                                        destination = pChildControl;
+                                }
+                        }
+                }
+        }
+        return destination;
+}
+
+_Control*
+_TableViewItem::GetNextFocusChildControl(const _Control& source)
+{
+        _Control* pParentControl = null;
+        float sourcePosition = 0.0f;
+
+        _Control* pSource = const_cast<_Control*>(&source);
+        _TableViewItem* pItem = dynamic_cast<_TableViewItem*>(pSource);
+        if (pItem != null)
+        {
+                pParentControl = pSource;
+                sourcePosition = 0.0f;
+        }
+        else
+        {
+                pParentControl = source.GetParent();
+                sourcePosition = source.GetBoundsF().x;
+        }
+
+        if (pParentControl == null)
+        {
+                return null;
+        }
+
+        int childControlCount = pParentControl->GetChildCount();
+        float position = 0.0f;
+        _Control* destination = null;
+
+        for(int i=0; i<childControlCount; i++)
+        {
+                _Control* pChildControl = pParentControl->GetChild(i);
+                if (pChildControl != null && pChildControl->IsFocusable())
+                {
+                        float childPosition = pChildControl->GetBoundsF().x;
+                        if (childPosition > sourcePosition)
+                        {
+                                if (childPosition < position)
+                                {
+                                        position = childPosition;
+                                        destination = pChildControl;
+                                }
+                                else if (_FloatCompare(position, 0.0f))
+                                {
+                                        position = childPosition;
+                                        destination = pChildControl;
+                                }
+                        }
+                }
+        }
+        return destination;
+}
+
+bool
+_TableViewItem::IsChildControlFocusManage(void) const
+{
+       return true;
+}
 }}} // Tizen::Ui::Controls
 
index bd06029..b0c2c15 100644 (file)
@@ -5213,6 +5213,247 @@ _TableViewPresenter::OnOcurredOverflowItems(const int currentCashSize, const int
 }
 
 bool
+_TableViewPresenter::OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo)
+{
+        _KeyCode keyCode = keyInfo.GetKeyCode();
+        _Control* pFocusedControl = __pTableView->GetFocused();
+        _TableView* pTableView = null;
+        _TableViewItem* pItem = null;
+        TableViewItemTag itemPos = {-1, -1};
+
+        switch (keyCode)
+        {
+        case _KEY_UP:
+                if (pFocusedControl != null)
+                {
+                        pTableView = dynamic_cast<_TableView*>(pFocusedControl);
+                        if (pTableView != null)
+                        {
+                                GetLastItem(itemPos);
+                                if (IsGroupExpanded(itemPos.groupIndex) == false)
+                                {
+                                        itemPos.itemIndex = -1;
+                                }
+
+                                ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
+                                pItem = FindItem(itemPos);
+                                if (pItem != null)
+                                {
+                                        pItem->SetFocused(true);
+                                        pItem->DrawFocus();
+                                }
+                        }
+                        else
+                        {
+                                pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
+                                if (pItem != null)
+                                {
+                                        pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
+                                        if (GetPreviousItemPosition(itemPos, itemPos))
+                                        {
+                                                _Control* pChildControl = null;
+                                                int childControlCount = pItem->GetChildCount();
+                                                for (int i=0; i<childControlCount; i++)
+                                                {
+                                                        pChildControl = pItem->GetChild(i);
+                                                        if (pChildControl != null)
+                                                        {
+                                                                pChildControl->OnFocusLost(*pChildControl);
+                                                        }
+                                                }
+
+                                                if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
+                                                {
+                                                        TableViewItemTag firstItemPos = {-1, -1};
+                                                        GetFirstItem(firstItemPos);
+                                                        if (itemPos.groupIndex == firstItemPos.groupIndex && itemPos.itemIndex == firstItemPos.itemIndex)
+                                                        {
+                                                                if (__pTableView != null)
+                                                                {
+                                                                        __pTableView->SetFocused(true);
+                                                                        __pTableView->DrawFocus();
+                                                                }
+                                                                break;
+                                                        }
+                                                }
+
+                                                if (IsGroupExpanded(itemPos.groupIndex) == false)
+                                                {
+                                                        itemPos.itemIndex = -1;
+                                                }
+
+                                                pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
+                                                if (pItem->GetBoundsF().y < GetScrollPosition())
+                                                {
+                                                        ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
+                                                }
+                                        }
+                                        else
+                                        {
+                                                if (__pTableView != null)
+                                                {
+                                                        __pTableView->SetFocused(true);
+                                                        __pTableView->DrawFocus();
+                                                }
+                                                break;
+                                        }
+                                }
+                                else
+                                {
+                                        _Control* pParentControl = pFocusedControl->GetParent();
+                                        pParentControl->SetFocused(true);
+                                        pParentControl->DrawFocus();
+                                        break;
+                                }
+
+                                pItem = FindItem(itemPos);
+                                if (pItem != null)
+                                {
+                                        pItem->SetFocused(true);
+                                        pItem->DrawFocus();
+                                }
+                        }
+                }
+                break;
+
+        case _KEY_DOWN:
+                if (pFocusedControl != null)
+                {
+                        pTableView = dynamic_cast<_TableView*>(pFocusedControl);
+                        if (pTableView != null)
+                        {
+                                GetFirstItem(itemPos);
+                                if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
+                                {
+                                        itemPos.itemIndex = 0;
+                                }
+
+                                ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
+                                pItem = FindItem(itemPos);
+                                if (pItem != null)
+                                {
+                                        pItem->SetFocused(true);
+                                        pItem->DrawFocus();
+                                }
+                        }
+                        else
+                        {
+                                pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
+                                if (pItem != null)
+                                {
+                                        pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
+                                        if (GetNextItemPosition(itemPos, itemPos))
+                                        {
+                                                _Control* pChildControl = null;
+                                                int childControlCount = pItem->GetChildCount();
+                                                for (int i=0; i<childControlCount; i++)
+                                                {
+                                                        pChildControl = pItem->GetChild(i);
+                                                        if (pChildControl != null)
+                                                        {
+                                                                pChildControl->OnFocusLost(*pChildControl);
+                                                        }
+                                                }
+
+                                                if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE && itemPos.itemIndex == -1)
+                                                {
+                                                        itemPos.itemIndex = 0;
+                                                }
+
+                                                pItem = static_cast <_TableViewItem*>(__pListModel->LoadItem(itemPos.groupIndex, itemPos.itemIndex));
+                                                if (pItem->GetBoundsF().y + pItem->GetBoundsF().height > GetScrollPosition() + __pTableView->GetBoundsF().height)
+                                                {
+                                                        ScrollToItem(itemPos.groupIndex, itemPos.itemIndex, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_TOP);
+                                                }
+                                        }
+                                        else
+                                        {
+                                                if (__pTableView != null)
+                                                {
+                                                        __pTableView->SetFocused(true);
+                                                        __pTableView->DrawFocus();
+                                                }
+                                                break;
+                                        }
+                                }
+                                else
+                                {
+                                        _Control* pParentControl = pFocusedControl->GetParent();
+                                        pParentControl->SetFocused(true);
+                                        pParentControl->DrawFocus();
+                                        break;
+                                }
+
+                                pItem = FindItem(itemPos);
+                                if (pItem != null)
+                                {
+                                        pItem->SetFocused(true);
+                                        pItem->DrawFocus();
+                                }
+                        }
+                }
+                break;
+
+        case _KEY_ENTER:
+                if (pFocusedControl != null)
+                {
+                        pItem = dynamic_cast<_TableViewItem*>(pFocusedControl);
+                        if (pItem != null)
+                        {
+                                TableViewNotifyType eventType = TABLEVIEW_NOTIFY_TYPE_SELECTED_ITEM;
+                                int annexStyle = pItem->GetItemStyle();
+                                pItem->GetItemIndex(itemPos.groupIndex, itemPos.itemIndex);
+                                if ((annexStyle == TABLE_VIEW_ANNEX_STYLE_MARK)
+                                                || (annexStyle == TABLE_VIEW_ANNEX_STYLE_RADIO)
+                                                || (annexStyle == TABLE_VIEW_ANNEX_STYLE_ONOFF_SLIDING))
+                                {
+                                        if (pItem->IsChecked())
+                                        {
+                                                eventType = TABLEVIEW_NOTIFY_TYPE_ANNEX_UNCHECK;
+                                        }
+                                        else
+                                        {
+                                                eventType = TABLEVIEW_NOTIFY_TYPE_ANNEX_CHECK;
+                                        }
+                                }
+                                else if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_GROUPED && itemPos.itemIndex == -1)
+                                {
+                                        if (IsGroupExpanded(itemPos.groupIndex))
+                                        {
+                                                CollapseGroup(itemPos.groupIndex, false);
+                                        }
+                                        else
+                                        {
+                                                ExpandGroup(itemPos.groupIndex, false);
+                                        }
+                                        eventType = TABLEVIEW_NOTIFY_TYPE_NONE;
+                                }
+                                __pTableView->FireTableViewItemEvent(itemPos.groupIndex, itemPos.itemIndex, eventType, pItem);
+                        }
+                }
+                break;
+
+        default:
+                return false;
+        }
+
+        return true;
+}
+
+bool
+_TableViewPresenter::OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo)
+{
+        _KeyCode keyCode = keyInfo.GetKeyCode();
+
+       if (keyCode == _KEY_UP || keyCode == _KEY_DOWN || keyCode == _KEY_ENTER)
+       {
+               return true;
+       }
+
+       return false;
+}
+
+bool
 _TableViewPresenter::GetAccessibilityElementFocusedState(void)
 {
        _TableViewItem* pItem = null;
index 6d0d913..f15a251 100644 (file)
@@ -232,7 +232,10 @@ public:
        Tizen::Ui::Animations::VisualElementValueAnimation* GetVisualElementValueAnimation(const Tizen::Base::String& keyName) const;
 
        // Focus Ui
-       virtual bool IsChildControlFocusManage(void) const;
+       virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
+       virtual bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo);
+       virtual bool IsChildControlFocusManage(void) const;
+
 protected:
        // Properties
        result SetPropertyItemDividerColor(const Variant& itemDividerColor);
index 9e1c2c5..5a4cc2f 100644 (file)
@@ -290,6 +290,11 @@ public:
        virtual bool OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
        virtual bool OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element);
 
+       // Focus Ui
+       virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
+       virtual bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo);
+       virtual bool IsChildControlFocusManage(void) const;
+
        bool SetItemTapSoundEnabled(bool tapSoundEnabled);
        bool GetItemTapSoundEnabled(void);
 
@@ -357,6 +362,9 @@ private:
 
        _Label* GetLabelCore(Label* label);
 
+       _Control* GetPreviousFocusChildControl(const _Control& source);
+       _Control* GetNextFocusChildControl(const _Control& source);
+
 private:
        void* __pAppInfo;
        int __refCount;
index 205f5f8..8360e0e 100644 (file)
@@ -185,6 +185,10 @@ public:
        // List model delegate
        virtual bool OnOcurredOverflowItems(const int currentCashSize, const int overflowCount);
 
+       // Focus Ui
+       virtual bool OnKeyPressed(const _Control& source, const _KeyInfo& keyInfo);
+       virtual bool OnKeyReleased(const _Control& source, const _KeyInfo& keyInfo);
+
        void Dispose(void);
 
        result RefreshTableView(int groupIndex, int itemIndex, TableViewRefreshType type, bool animation);
@@ -303,7 +307,6 @@ private:
        void RefreshItemBounds(_TableViewItem* pItem, TableViewItemTag& itemPos);
        void ScrollToItem(int groupIndex, int itemIndex, TableViewScrollItemAlignment itemAlignment, float shiftingDistance = 0.0f);
 
-
        _TableViewItem* GetTableViewItemFromControl(const _Control& source);
 
        void UnloadItem(TableViewItemTag& itemTag);