SL-11172 Scroll to focused object if object is not in visible area

master
andreykproductengine 2020-01-09 20:54:36 +02:00
parent 7633285f9a
commit 941c1ee7f8
7 changed files with 74 additions and 0 deletions

View File

@ -655,6 +655,37 @@ void LLAccordionCtrl::onScrollPosChangeCallback(S32, LLScrollbar*)
{
updateLayout(getRect().getWidth(),getRect().getHeight());
}
// virtual
void LLAccordionCtrl::onChildGotFocus(const LLUICtrl *cntrl)
{
if (mScrollbar && mScrollbar->getVisible())
{
// same as scrollToShowRect
LLRect rect;
cntrl->localRectToOtherView(cntrl->getLocalRect(), &rect, this);
// Translate to parent coordinatess to check if we are in visible rectangle
rect.translate(getRect().mLeft, getRect().mBottom);
if (!getRect().contains(rect))
{
// for accordition's scroll, height is in pixels
// Back to local coords and calculate position for scroller
S32 bottom = mScrollbar->getDocPos() - rect.mBottom + getRect().mBottom;
S32 top = mScrollbar->getDocPos() - rect.mTop + getRect().mTop;
S32 scroll_pos = llclamp(mScrollbar->getDocPos(),
bottom, // min vertical scroll
top); // max vertical scroll
mScrollbar->setDocPos(scroll_pos);
}
}
LLUICtrl::onChildGotFocus(cntrl);
}
void LLAccordionCtrl::onOpen (const LLSD& key)
{
for(size_t i=0;i<mAccordionTabs.size();++i)

View File

@ -111,6 +111,7 @@ public:
void draw();
void onScrollPosChangeCallback(S32, LLScrollbar*);
virtual void onChildGotFocus(const LLUICtrl * cntrl);
void onOpen (const LLSD& key);
S32 notifyParent(const LLSD& info);

View File

@ -452,6 +452,35 @@ void LLAccordionCtrlTab::onVisibilityChange(BOOL new_visibility)
notifyParent(LLSD().with("child_visibility_change", new_visibility));
}
// virtual
void LLAccordionCtrlTab::onChildGotFocus(const LLUICtrl *cntrl)
{
if (mScrollbar && mScrollbar->getVisible())
{
LLRect rect;
cntrl->localRectToOtherView(cntrl->getLocalRect(), &rect, this);
// Translate to parent coordinatess to check if we are in visible rectangle
rect.translate(getRect().mLeft, getRect().mBottom);
if (!getRect().contains(rect))
{
// for accordition's scroll, height is in pixels
// Back to local coords and calculate position for scroller
S32 bottom = mScrollbar->getDocPos() - rect.mBottom + getRect().mBottom;
S32 top = mScrollbar->getDocPos() - rect.mTop + getRect().mTop;
S32 scroll_pos = llclamp(mScrollbar->getDocPos(),
bottom, // min vertical scroll
top); // max vertical scroll
mScrollbar->setDocPos(scroll_pos);
}
}
LLUICtrl::onChildGotFocus(cntrl);
}
BOOL LLAccordionCtrlTab::handleMouseDown(S32 x, S32 y, MASK mask)
{
if(mCollapsible && mHeaderVisible && mCanOpenClose)

View File

@ -159,6 +159,7 @@ public:
* Raises notifyParent event with "child_visibility_change" = new_visibility
*/
void onVisibilityChange(BOOL new_visibility);
virtual void onChildGotFocus(const LLUICtrl * cntrl);
// Changes expand/collapse state and triggers expand/collapse callbacks
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);

View File

@ -679,6 +679,7 @@ void LLUICtrl::setFocus(BOOL b)
if (!hasFocus())
{
gFocusMgr.setKeyboardFocus( this );
onChildGotFocus(this);
}
}
else

View File

@ -640,6 +640,16 @@ void LLView::onVisibilityChange ( BOOL new_visibility )
}
}
// virtual
void LLView::onChildGotFocus(const LLUICtrl * cntrl)
{
LLView* parent_view = getParent();
if (parent_view)
{
parent_view->onChildGotFocus(cntrl);
}
}
// virtual
void LLView::translate(S32 x, S32 y)
{

View File

@ -301,6 +301,7 @@ public:
virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text );
virtual void onVisibilityChange ( BOOL new_visibility );
virtual void onChildGotFocus(const LLUICtrl * cntrl);
void pushVisible(BOOL visible) { mLastVisible = mVisible; setVisible(visible); }
void popVisible() { setVisible(mLastVisible); }