From edf75a71747ca6f50ba265c167064c2ee69a0b42 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Sat, 26 Oct 2013 18:12:56 -0500 Subject: [PATCH] setCommitOnReturn moved to from llbutton to lluictrl, cleanup some focus/key handling, avoid needless reshape calls. --- indra/llui/llbutton.h | 3 -- indra/llui/llpanel.cpp | 70 +++++++++++++++-------------------------- indra/llui/lluictrl.cpp | 21 ++++++++++--- indra/llui/lluictrl.h | 6 ++++ indra/llui/llview.cpp | 5 ++- 5 files changed, 52 insertions(+), 53 deletions(-) diff --git a/indra/llui/llbutton.h b/indra/llui/llbutton.h index 5710585fd..219b0dfec 100644 --- a/indra/llui/llbutton.h +++ b/indra/llui/llbutton.h @@ -207,9 +207,6 @@ public: void setImageFlash(LLPointer image); void setImagePressed(LLPointer image); - void setCommitOnReturn(BOOL commit) { mCommitOnReturn = commit; } - BOOL getCommitOnReturn() const { return mCommitOnReturn; } - static void onHeldDown(void *userdata); // to be called by gIdleCallbacks void setHelpURLCallback(const std::string &help_url); const std::string& getHelpURL() const { return mHelpURL; } diff --git a/indra/llui/llpanel.cpp b/indra/llui/llpanel.cpp index d9e1c7e94..c6ff2fa03 100644 --- a/indra/llui/llpanel.cpp +++ b/indra/llui/llpanel.cpp @@ -159,8 +159,12 @@ void LLPanel::addBorder(LLViewBorder::EBevel border_bevel, void LLPanel::removeBorder() { - delete mBorder; - mBorder = NULL; + if (mBorder) + { + removeChild(mBorder); + delete mBorder; + mBorder = NULL; + } } @@ -277,7 +281,7 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask ) // handle user hitting ESC to defocus if (key == KEY_ESCAPE && mask == MASK_NONE) { - gFocusMgr.setKeyboardFocus(NULL); + setFocus(FALSE); return TRUE; } else if( (mask == MASK_SHIFT) && (KEY_TAB == key)) @@ -304,29 +308,25 @@ BOOL LLPanel::handleKeyHere( KEY key, MASK mask ) } } } - - // If we have a default button, click it when - // return is pressed, unless current focus is a return-capturing button - // in which case *that* button will handle the return key - LLButton* focused_button = dynamic_cast(cur_focus); - if (cur_focus && !(focused_button && focused_button->getCommitOnReturn())) + + // If RETURN was pressed and something has focus, call onCommit() + if (!handled && cur_focus && key == KEY_RETURN && mask == MASK_NONE) { - // RETURN key means hit default button in this case - if (key == KEY_RETURN && mask == MASK_NONE - && mDefaultBtn != NULL - && mDefaultBtn->getVisible() - && mDefaultBtn->getEnabled()) + if (cur_focus->getCommitOnReturn()) { + // current focus is a return-capturing element, + // let *that* element handle the return key + handled = FALSE; + } + else if (mDefaultBtn && mDefaultBtn->getVisible() && mDefaultBtn->getEnabled()) + { + // If we have a default button, click it when return is pressed mDefaultBtn->onCommit(); handled = TRUE; } - } - - if (key == KEY_RETURN && mask == MASK_NONE) - { - // set keyboard focus to self to trigger commitOnFocusLost behavior on current ctrl - if (cur_focus && cur_focus->acceptsTextInput()) + else if (cur_focus->acceptsTextInput()) { + // call onCommit for text input handling control cur_focus->onCommit(); handled = TRUE; } @@ -363,34 +363,16 @@ void LLPanel::handleVisibilityChange ( BOOL new_visibility ) void LLPanel::setFocus(BOOL b) { - if( b ) + if( b && !hasFocus()) { - if (!gFocusMgr.childHasKeyboardFocus(this)) - { - //refresh(); - if (!focusFirstItem()) - { - LLUICtrl::setFocus(TRUE); - } - onFocusReceived(); - } + // give ourselves focus preemptively, to avoid infinite loop + LLUICtrl::setFocus(TRUE); + // then try to pass to first valid child + focusFirstItem(); } else { - if( this == gFocusMgr.getKeyboardFocus() ) - { - gFocusMgr.setKeyboardFocus( NULL ); - } - else - { - //RN: why is this here? - LLView::ctrl_list_t ctrls = getCtrlList(); - for (LLView::ctrl_list_t::iterator ctrl_it = ctrls.begin(); ctrl_it != ctrls.end(); ++ctrl_it) - { - LLUICtrl* ctrl = *ctrl_it; - ctrl->setFocus( FALSE ); - } - } + LLUICtrl::setFocus(b); } } diff --git a/indra/llui/lluictrl.cpp b/indra/llui/lluictrl.cpp index b70737c27..56bac0e92 100644 --- a/indra/llui/lluictrl.cpp +++ b/indra/llui/lluictrl.cpp @@ -56,7 +56,8 @@ LLUICtrl::LLUICtrl() : mDoubleClickSignal(NULL), mTentative(FALSE), mTabStop(TRUE), - mIsChrome(FALSE) + mIsChrome(FALSE), + mCommitOnReturn(FALSE) { } @@ -78,7 +79,8 @@ LLUICtrl::LLUICtrl(const std::string& name, const LLRect rect, BOOL mouse_opaque mDoubleClickSignal(NULL), mTentative( FALSE ), mTabStop( TRUE ), - mIsChrome(FALSE) + mIsChrome(FALSE), + mCommitOnReturn(FALSE) { if(commit_callback) setCommitCallback(commit_callback); @@ -178,6 +180,13 @@ BOOL LLUICtrl::handleDoubleClick(S32 x, S32 y, MASK mask) return handled; } +// can't tab to children of a non-tab-stop widget +BOOL LLUICtrl::canFocusChildren() const +{ + return TRUE;//hasTabStop(); +} + + void LLUICtrl::onCommit() { if (mCommitSignal) @@ -528,7 +537,8 @@ BOOL LLUICtrl::focusNextItem(BOOL text_fields_only) { // this assumes that this method is called on the focus root. LLCtrlQuery query = getTabOrderQuery(); - if(text_fields_only || LLUI::sConfigGroup->getBOOL("TabToTextFieldsOnly")) + static LLUICachedControl tab_to_text_fields_only ("TabToTextFieldsOnly", false); + if(text_fields_only || tab_to_text_fields_only) { query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); } @@ -540,7 +550,8 @@ BOOL LLUICtrl::focusPrevItem(BOOL text_fields_only) { // this assumes that this method is called on the focus root. LLCtrlQuery query = getTabOrderQuery(); - if(text_fields_only || LLUI::sConfigGroup->getBOOL("TabToTextFieldsOnly")) + static LLUICachedControl tab_to_text_fields_only ("TabToTextFieldsOnly", false); + if(text_fields_only || tab_to_text_fields_only) { query.addPreFilter(LLUICtrl::LLTextInputFilter::getInstance()); } @@ -552,7 +563,7 @@ LLUICtrl* LLUICtrl::findRootMostFocusRoot() { LLUICtrl* focus_root = NULL; LLUICtrl* next_view = this; - while(next_view) + while(next_view/* && next_view->hasTabStop()*/) { if (next_view->isFocusRoot()) { diff --git a/indra/llui/lluictrl.h b/indra/llui/lluictrl.h index b7ebc5bcc..ba6acc98e 100644 --- a/indra/llui/lluictrl.h +++ b/indra/llui/lluictrl.h @@ -70,6 +70,7 @@ public: /*virtual*/ BOOL isCtrl() const; /*virtual*/ void onMouseEnter(S32 x, S32 y, MASK mask); /*virtual*/ void onMouseLeave(S32 x, S32 y, MASK mask); + /*virtual*/ BOOL canFocusChildren() const; /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleMouseUp(S32 x, S32 y, MASK mask); /*virtual*/ BOOL handleRightMouseDown(S32 x, S32 y, MASK mask); @@ -132,6 +133,9 @@ public: LLUICtrl* getParentUICtrl() const; + void setCommitOnReturn(BOOL commit) { mCommitOnReturn = commit; } + BOOL getCommitOnReturn() const { return mCommitOnReturn; } + //Start using these! boost::signals2::connection setCommitCallback( const commit_signal_t::slot_type& cb ); boost::signals2::connection setValidateCallback( const enable_signal_t::slot_type& cb ); @@ -198,6 +202,8 @@ private: BOOL mIsChrome; BOOL mTentative; + bool mCommitOnReturn; + class DefaultTabGroupFirstSorter; }; diff --git a/indra/llui/llview.cpp b/indra/llui/llview.cpp index 6d2ae643a..12c6ef34d 100644 --- a/indra/llui/llview.cpp +++ b/indra/llui/llview.cpp @@ -1377,7 +1377,10 @@ void LLView::reshape(S32 width, S32 height, BOOL called_from_parent) S32 delta_x = child_rect.mLeft - viewp->getRect().mLeft; S32 delta_y = child_rect.mBottom - viewp->getRect().mBottom; viewp->translate( delta_x, delta_y ); - viewp->reshape(child_rect.getWidth(), child_rect.getHeight()); + if (child_rect.getWidth() != viewp->getRect().getWidth() || child_rect.getHeight() != viewp->getRect().getHeight()) + { + viewp->reshape(child_rect.getWidth(), child_rect.getHeight()); + } } }