PageRenderTime 8ms CodeModel.GetById 11ms app.highlight 69ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llui/llscrollcontainer.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 714 lines | 534 code | 94 blank | 86 comment | 67 complexity | b9606b990136015315e8b87a8177cfb5 MD5 | raw file
  1/** 
  2 * @file llscrollcontainer.cpp
  3 * @brief LLScrollContainer base class
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27
 28#include "linden_common.h"
 29
 30#include "llscrollcontainer.h"
 31
 32#include "llrender.h"
 33#include "llcontainerview.h"
 34#include "lllocalcliprect.h"
 35// #include "llfolderview.h"
 36#include "llscrollingpanellist.h"
 37#include "llscrollbar.h"
 38#include "llui.h"
 39#include "llkeyboard.h"
 40#include "llviewborder.h"
 41#include "llfocusmgr.h"
 42#include "llframetimer.h"
 43#include "lluictrlfactory.h"
 44#include "llpanel.h"
 45#include "llfontgl.h"
 46
 47///----------------------------------------------------------------------------
 48/// Local function declarations, constants, enums, and typedefs
 49///----------------------------------------------------------------------------
 50
 51static const S32 HORIZONTAL_MULTIPLE = 8;
 52static const S32 VERTICAL_MULTIPLE = 16;
 53static const F32 AUTO_SCROLL_RATE_ACCEL = 120.f;
 54
 55///----------------------------------------------------------------------------
 56/// Class LLScrollContainer
 57///----------------------------------------------------------------------------
 58
 59static LLDefaultChildRegistry::Register<LLScrollContainer> r("scroll_container");
 60
 61#include "llscrollingpanellist.h"
 62#include "llcontainerview.h"
 63#include "llpanel.h"
 64
 65static ScrollContainerRegistry::Register<LLScrollingPanelList> r1("scrolling_panel_list");
 66static ScrollContainerRegistry::Register<LLContainerView> r2("container_view");
 67static ScrollContainerRegistry::Register<LLPanel> r3("panel", &LLPanel::fromXML);
 68
 69LLScrollContainer::Params::Params()
 70:	is_opaque("opaque"),
 71	bg_color("color"),
 72	border_visible("border_visible"),
 73	hide_scrollbar("hide_scrollbar"),
 74	min_auto_scroll_rate("min_auto_scroll_rate", 100),
 75	max_auto_scroll_rate("max_auto_scroll_rate", 1000),
 76	reserve_scroll_corner("reserve_scroll_corner", false)
 77{}
 78
 79
 80// Default constructor
 81LLScrollContainer::LLScrollContainer(const LLScrollContainer::Params& p)
 82:	LLUICtrl(p),
 83	mAutoScrolling( FALSE ),
 84	mAutoScrollRate( 0.f ),
 85	mBackgroundColor(p.bg_color()),
 86	mIsOpaque(p.is_opaque),
 87	mHideScrollbar(p.hide_scrollbar),
 88	mReserveScrollCorner(p.reserve_scroll_corner),
 89	mMinAutoScrollRate(p.min_auto_scroll_rate),
 90	mMaxAutoScrollRate(p.max_auto_scroll_rate),
 91	mScrolledView(NULL)
 92{
 93	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
 94	LLRect border_rect( 0, getRect().getHeight(), getRect().getWidth(), 0 );
 95	LLViewBorder::Params params;
 96	params.name("scroll border");
 97	params.rect(border_rect);
 98	params.visible(p.border_visible);
 99	params.bevel_style(LLViewBorder::BEVEL_IN);
100	mBorder = LLUICtrlFactory::create<LLViewBorder> (params);
101	LLView::addChild( mBorder );
102
103	mInnerRect.set( 0, getRect().getHeight(), getRect().getWidth(), 0 );
104	mInnerRect.stretch( -getBorderWidth()  );
105
106	LLRect vertical_scroll_rect = mInnerRect;
107	vertical_scroll_rect.mLeft = vertical_scroll_rect.mRight - scrollbar_size;
108	LLScrollbar::Params sbparams;
109	sbparams.name("scrollable vertical");
110	sbparams.rect(vertical_scroll_rect);
111	sbparams.orientation(LLScrollbar::VERTICAL);
112	sbparams.doc_size(mInnerRect.getHeight());
113	sbparams.doc_pos(0);
114	sbparams.page_size(mInnerRect.getHeight());
115	sbparams.step_size(VERTICAL_MULTIPLE);
116	sbparams.follows.flags(FOLLOWS_RIGHT | FOLLOWS_TOP | FOLLOWS_BOTTOM);
117	sbparams.visible(false);
118	sbparams.change_callback(p.scroll_callback);
119	mScrollbar[VERTICAL] = LLUICtrlFactory::create<LLScrollbar> (sbparams);
120	LLView::addChild( mScrollbar[VERTICAL] );
121	
122	LLRect horizontal_scroll_rect = mInnerRect;
123	horizontal_scroll_rect.mTop = horizontal_scroll_rect.mBottom + scrollbar_size;
124	sbparams.name("scrollable horizontal");
125	sbparams.rect(horizontal_scroll_rect);
126	sbparams.orientation(LLScrollbar::HORIZONTAL);
127	sbparams.doc_size(mInnerRect.getWidth());
128	sbparams.doc_pos(0);
129	sbparams.page_size(mInnerRect.getWidth());
130	sbparams.step_size(VERTICAL_MULTIPLE);
131	sbparams.visible(false);
132	sbparams.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT);
133	sbparams.change_callback(p.scroll_callback);
134	mScrollbar[HORIZONTAL] = LLUICtrlFactory::create<LLScrollbar> (sbparams);
135	LLView::addChild( mScrollbar[HORIZONTAL] );
136}
137
138// Destroys the object
139LLScrollContainer::~LLScrollContainer( void )
140{
141	// mScrolledView and mScrollbar are child views, so the LLView
142	// destructor takes care of memory deallocation.
143	for( S32 i = 0; i < SCROLLBAR_COUNT; i++ )
144	{
145		mScrollbar[i] = NULL;
146	}
147	mScrolledView = NULL;
148}
149
150// internal scrollbar handlers
151// virtual
152void LLScrollContainer::scrollHorizontal( S32 new_pos )
153{
154	//llinfos << "LLScrollContainer::scrollHorizontal()" << llendl;
155	if( mScrolledView )
156	{
157		LLRect doc_rect = mScrolledView->getRect();
158		S32 old_pos = -(doc_rect.mLeft - mInnerRect.mLeft);
159		mScrolledView->translate( -(new_pos - old_pos), 0 );
160	}
161}
162
163// virtual
164void LLScrollContainer::scrollVertical( S32 new_pos )
165{
166	// llinfos << "LLScrollContainer::scrollVertical() " << new_pos << llendl;
167	if( mScrolledView )
168	{
169		LLRect doc_rect = mScrolledView->getRect();
170		S32 old_pos = doc_rect.mTop - mInnerRect.mTop;
171		mScrolledView->translate( 0, new_pos - old_pos );
172	}
173}
174
175// LLView functionality
176void LLScrollContainer::reshape(S32 width, S32 height,
177										BOOL called_from_parent)
178{
179	LLUICtrl::reshape( width, height, called_from_parent );
180
181	mInnerRect = getLocalRect();
182	mInnerRect.stretch( -getBorderWidth() );
183
184	if (mScrolledView)
185	{
186		const LLRect& scrolled_rect = mScrolledView->getRect();
187
188		S32 visible_width = 0;
189		S32 visible_height = 0;
190		BOOL show_v_scrollbar = FALSE;
191		BOOL show_h_scrollbar = FALSE;
192		calcVisibleSize( &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar );
193
194		mScrollbar[VERTICAL]->setDocSize( scrolled_rect.getHeight() );
195		mScrollbar[VERTICAL]->setPageSize( visible_height );
196
197		mScrollbar[HORIZONTAL]->setDocSize( scrolled_rect.getWidth() );
198		mScrollbar[HORIZONTAL]->setPageSize( visible_width );
199		updateScroll();
200	}
201}
202
203BOOL LLScrollContainer::handleKeyHere(KEY key, MASK mask)
204{
205	// allow scrolled view to handle keystrokes in case it delegated keyboard focus
206	// to the scroll container.  
207	// NOTE: this should not recurse indefinitely as handleKeyHere
208	// should not propagate to parent controls, so mScrolledView should *not*
209	// call LLScrollContainer::handleKeyHere in turn
210	if (mScrolledView && mScrolledView->handleKeyHere(key, mask))
211	{
212		return TRUE;
213	}
214	for( S32 i = 0; i < SCROLLBAR_COUNT; i++ )
215	{
216		if( mScrollbar[i]->handleKeyHere(key, mask) )
217		{
218			updateScroll();
219			return TRUE;
220		}
221	}	
222
223	return FALSE;
224}
225
226BOOL LLScrollContainer::handleUnicodeCharHere(llwchar uni_char)
227{
228	if (mScrolledView && mScrolledView->handleUnicodeCharHere(uni_char))
229	{
230		return TRUE;
231	}
232	return FALSE;
233}
234
235BOOL LLScrollContainer::handleScrollWheel( S32 x, S32 y, S32 clicks )
236{
237	// Give event to my child views - they may have scroll bars
238	// (Bad UI design, but technically possible.)
239	if (LLUICtrl::handleScrollWheel(x,y,clicks))
240		return TRUE;
241
242	// When the vertical scrollbar is visible, scroll wheel
243	// only affects vertical scrolling.  It's confusing to have
244	// scroll wheel perform both vertical and horizontal in a
245	// single container.
246	LLScrollbar* vertical = mScrollbar[VERTICAL];
247	if (vertical->getVisible()
248		&& vertical->getEnabled())
249	{
250		// Pretend the mouse is over the scrollbar
251		if (vertical->handleScrollWheel( 0, 0, clicks ) )
252		{
253			updateScroll();
254		}
255		// Always eat the event
256		return TRUE;
257	}
258
259	LLScrollbar* horizontal = mScrollbar[HORIZONTAL];
260	// Test enablement and visibility for consistency with
261	// LLView::childrenHandleScrollWheel().
262	if (horizontal->getVisible()
263		&& horizontal->getEnabled()
264		&& horizontal->handleScrollWheel( 0, 0, clicks ) )
265	{
266		updateScroll();
267		return TRUE;
268	}
269	return FALSE;
270}
271
272BOOL LLScrollContainer::handleDragAndDrop(S32 x, S32 y, MASK mask,
273												  BOOL drop,
274												  EDragAndDropType cargo_type,
275												  void* cargo_data,
276												  EAcceptance* accept,
277												  std::string& tooltip_msg)
278{
279	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
280	// Scroll folder view if needed.  Never accepts a drag or drop.
281	*accept = ACCEPT_NO;
282	BOOL handled = autoScroll(x, y);
283
284	if( !handled )
285	{
286		handled = childrenHandleDragAndDrop(x, y, mask, drop, cargo_type,
287											cargo_data, accept, tooltip_msg) != NULL;
288	}
289
290	return TRUE;
291}
292
293bool LLScrollContainer::autoScroll(S32 x, S32 y)
294{
295	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
296
297	bool scrolling = false;
298	if( mScrollbar[HORIZONTAL]->getVisible() || mScrollbar[VERTICAL]->getVisible() )
299	{
300		LLRect screen_local_extents;
301		screenRectToLocal(getRootView()->getLocalRect(), &screen_local_extents);
302
303		LLRect inner_rect_local( 0, mInnerRect.getHeight(), mInnerRect.getWidth(), 0 );
304		if(	mScrollbar[HORIZONTAL]->getVisible() )
305		{
306			inner_rect_local.mBottom += scrollbar_size;
307		}
308		if(	mScrollbar[VERTICAL]->getVisible() )
309		{
310			inner_rect_local.mRight -= scrollbar_size;
311		}
312
313		// clip rect against root view
314		inner_rect_local.intersectWith(screen_local_extents);
315
316		S32 auto_scroll_speed = llround(mAutoScrollRate * LLFrameTimer::getFrameDeltaTimeF32());
317		// autoscroll region should take up no more than one third of visible scroller area
318		S32 auto_scroll_region_width = llmin(inner_rect_local.getWidth() / 3, 10); 
319		S32 auto_scroll_region_height = llmin(inner_rect_local.getHeight() / 3, 10); 
320
321		if(	mScrollbar[HORIZONTAL]->getVisible() )
322		{
323			LLRect left_scroll_rect = screen_local_extents;
324			left_scroll_rect.mRight = inner_rect_local.mLeft + auto_scroll_region_width;
325			if( left_scroll_rect.pointInRect( x, y ) && (mScrollbar[HORIZONTAL]->getDocPos() > 0) )
326			{
327				mScrollbar[HORIZONTAL]->setDocPos( mScrollbar[HORIZONTAL]->getDocPos() - auto_scroll_speed );
328				mAutoScrolling = TRUE;
329				scrolling = true;
330			}
331
332			LLRect right_scroll_rect = screen_local_extents;
333			right_scroll_rect.mLeft = inner_rect_local.mRight - auto_scroll_region_width;
334			if( right_scroll_rect.pointInRect( x, y ) && (mScrollbar[HORIZONTAL]->getDocPos() < mScrollbar[HORIZONTAL]->getDocPosMax()) )
335			{
336				mScrollbar[HORIZONTAL]->setDocPos( mScrollbar[HORIZONTAL]->getDocPos() + auto_scroll_speed );
337				mAutoScrolling = TRUE;
338				scrolling = true;
339			}
340		}
341		if(	mScrollbar[VERTICAL]->getVisible() )
342		{
343			LLRect bottom_scroll_rect = screen_local_extents;
344			bottom_scroll_rect.mTop = inner_rect_local.mBottom + auto_scroll_region_height;
345			if( bottom_scroll_rect.pointInRect( x, y ) && (mScrollbar[VERTICAL]->getDocPos() < mScrollbar[VERTICAL]->getDocPosMax()) )
346			{
347				mScrollbar[VERTICAL]->setDocPos( mScrollbar[VERTICAL]->getDocPos() + auto_scroll_speed );
348				mAutoScrolling = TRUE;
349				scrolling = true;
350			}
351
352			LLRect top_scroll_rect = screen_local_extents;
353			top_scroll_rect.mBottom = inner_rect_local.mTop - auto_scroll_region_height;
354			if( top_scroll_rect.pointInRect( x, y ) && (mScrollbar[VERTICAL]->getDocPos() > 0) )
355			{
356				mScrollbar[VERTICAL]->setDocPos( mScrollbar[VERTICAL]->getDocPos() - auto_scroll_speed );
357				mAutoScrolling = TRUE;
358				scrolling = true;
359			}
360		}
361	}
362	return scrolling;
363}
364
365void LLScrollContainer::calcVisibleSize( S32 *visible_width, S32 *visible_height, BOOL* show_h_scrollbar, BOOL* show_v_scrollbar ) const
366{
367	const LLRect& doc_rect = getScrolledViewRect();
368	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
369	S32 doc_width = doc_rect.getWidth();
370	S32 doc_height = doc_rect.getHeight();
371
372	S32 border_width = getBorderWidth();
373	*visible_width = getRect().getWidth() - 2 * border_width;
374	*visible_height = getRect().getHeight() - 2 * border_width;
375	
376	*show_v_scrollbar = FALSE;
377	*show_h_scrollbar = FALSE;
378
379	if (!mHideScrollbar)
380	{
381		if( *visible_height < doc_height )
382		{
383			*show_v_scrollbar = TRUE;
384			*visible_width -= scrollbar_size;
385		}
386
387		if( *visible_width < doc_width )
388		{
389			*show_h_scrollbar = TRUE;
390			*visible_height -= scrollbar_size;
391
392			// Must retest now that visible_height has changed
393			if( !*show_v_scrollbar && (*visible_height < doc_height) )
394			{
395				*show_v_scrollbar = TRUE;
396				*visible_width -= scrollbar_size;
397			}
398		}
399	}
400}
401	
402
403void LLScrollContainer::draw()
404{
405	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
406	if (mAutoScrolling)
407	{
408		// add acceleration to autoscroll
409		mAutoScrollRate = llmin(mAutoScrollRate + (LLFrameTimer::getFrameDeltaTimeF32() * AUTO_SCROLL_RATE_ACCEL), mMaxAutoScrollRate);
410	}
411	else
412	{
413		// reset to minimum for next time
414		mAutoScrollRate = mMinAutoScrollRate;
415	}
416	// clear this flag to be set on next call to autoScroll
417	mAutoScrolling = FALSE;
418
419	// auto-focus when scrollbar active
420	// this allows us to capture user intent (i.e. stop automatically scrolling the view/etc)
421	if (!hasFocus() 
422		&& (mScrollbar[VERTICAL]->hasMouseCapture() || mScrollbar[HORIZONTAL]->hasMouseCapture()))
423	{
424		focusFirstItem();
425	}
426
427	if (getRect().isValid()) 
428	{
429		// Draw background
430		if( mIsOpaque )
431		{
432			F32 alpha = getCurrentTransparency();
433
434			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
435			gl_rect_2d(mInnerRect, mBackgroundColor.get() % alpha);
436		}
437	
438		// Draw mScrolledViews and update scroll bars.
439		// get a scissor region ready, and draw the scrolling view. The
440		// scissor region ensures that we don't draw outside of the bounds
441		// of the rectangle.
442		if( mScrolledView )
443		{
444			updateScroll();
445
446			// Draw the scrolled area.
447			{
448				S32 visible_width = 0;
449				S32 visible_height = 0;
450				BOOL show_v_scrollbar = FALSE;
451				BOOL show_h_scrollbar = FALSE;
452				calcVisibleSize( &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar );
453
454				LLLocalClipRect clip(LLRect(mInnerRect.mLeft, 
455						mInnerRect.mBottom + (show_h_scrollbar ? scrollbar_size : 0) + visible_height,
456						mInnerRect.mRight - (show_v_scrollbar ? scrollbar_size: 0),
457						mInnerRect.mBottom + (show_h_scrollbar ? scrollbar_size : 0)
458						));
459				drawChild(mScrolledView);
460			}
461		}
462
463		// Highlight border if a child of this container has keyboard focus
464		if( mBorder->getVisible() )
465		{
466			mBorder->setKeyboardFocusHighlight( gFocusMgr.childHasKeyboardFocus(this) );
467		}
468
469		// Draw all children except mScrolledView
470		// Note: scrollbars have been adjusted by above drawing code
471		for (child_list_const_reverse_iter_t child_iter = getChildList()->rbegin();
472			 child_iter != getChildList()->rend(); ++child_iter)
473		{
474			LLView *viewp = *child_iter;
475			if( sDebugRects )
476			{
477				sDepth++;
478			}
479			if( (viewp != mScrolledView) && viewp->getVisible() )
480			{
481				drawChild(viewp);
482			}
483			if( sDebugRects )
484			{
485				sDepth--;
486			}
487		}
488	}
489} // end draw
490
491bool LLScrollContainer::addChild(LLView* view, S32 tab_group)
492{
493	if (!mScrolledView)
494	{
495		// Use the first panel or container as the scrollable view (bit of a hack)
496		mScrolledView = view;
497	}
498
499	bool ret_val = LLView::addChild(view, tab_group);
500
501	//bring the scrollbars to the front
502	sendChildToFront( mScrollbar[HORIZONTAL] );
503	sendChildToFront( mScrollbar[VERTICAL] );
504
505	return ret_val;
506}
507
508void LLScrollContainer::updateScroll()
509{
510	if (!mScrolledView)
511	{
512		return;
513	}
514	static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
515	LLRect doc_rect = mScrolledView->getRect();
516	S32 doc_width = doc_rect.getWidth();
517	S32 doc_height = doc_rect.getHeight();
518	S32 visible_width = 0;
519	S32 visible_height = 0;
520	BOOL show_v_scrollbar = FALSE;
521	BOOL show_h_scrollbar = FALSE;
522	calcVisibleSize( &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar );
523
524	S32 border_width = getBorderWidth();
525	if( show_v_scrollbar )
526	{
527		if( doc_rect.mTop < getRect().getHeight() - border_width )
528		{
529			mScrolledView->translate( 0, getRect().getHeight() - border_width - doc_rect.mTop );
530		}
531
532		scrollVertical(	mScrollbar[VERTICAL]->getDocPos() );
533		mScrollbar[VERTICAL]->setVisible( TRUE );
534
535		S32 v_scrollbar_height = visible_height;
536		if( !show_h_scrollbar && mReserveScrollCorner )
537		{
538			v_scrollbar_height -= scrollbar_size;
539		}
540		mScrollbar[VERTICAL]->reshape( scrollbar_size, v_scrollbar_height, TRUE );
541
542		// Make room for the horizontal scrollbar (or not)
543		S32 v_scrollbar_offset = 0;
544		if( show_h_scrollbar || mReserveScrollCorner )
545		{
546			v_scrollbar_offset = scrollbar_size;
547		}
548		LLRect r = mScrollbar[VERTICAL]->getRect();
549		r.translate( 0, mInnerRect.mBottom - r.mBottom + v_scrollbar_offset );
550		mScrollbar[VERTICAL]->setRect( r );
551	}
552	else
553	{
554		mScrolledView->translate( 0, getRect().getHeight() - border_width - doc_rect.mTop );
555
556		mScrollbar[VERTICAL]->setVisible( FALSE );
557		mScrollbar[VERTICAL]->setDocPos( 0 );
558	}
559		
560	if( show_h_scrollbar )
561	{
562		if( doc_rect.mLeft > border_width )
563		{
564			mScrolledView->translate( border_width - doc_rect.mLeft, 0 );
565			mScrollbar[HORIZONTAL]->setDocPos( 0 );
566		}
567		else
568		{
569			scrollHorizontal( mScrollbar[HORIZONTAL]->getDocPos() );
570		}
571	
572		mScrollbar[HORIZONTAL]->setVisible( TRUE );
573		S32 h_scrollbar_width = visible_width;
574		if( !show_v_scrollbar && mReserveScrollCorner )
575		{
576			h_scrollbar_width -= scrollbar_size;
577		}
578		mScrollbar[HORIZONTAL]->reshape( h_scrollbar_width, scrollbar_size, TRUE );
579	}
580	else
581	{
582		mScrolledView->translate( border_width - doc_rect.mLeft, 0 );
583		
584		mScrollbar[HORIZONTAL]->setVisible( FALSE );
585		mScrollbar[HORIZONTAL]->setDocPos( 0 );
586	}
587
588	mScrollbar[HORIZONTAL]->setDocSize( doc_width );
589	mScrollbar[HORIZONTAL]->setPageSize( visible_width );
590
591	mScrollbar[VERTICAL]->setDocSize( doc_height );
592	mScrollbar[VERTICAL]->setPageSize( visible_height );
593} // end updateScroll
594
595void LLScrollContainer::setBorderVisible(BOOL b)
596{
597	mBorder->setVisible( b );
598	// Recompute inner rect, as border visibility changes it
599	mInnerRect = getLocalRect();
600	mInnerRect.stretch( -getBorderWidth() );
601}
602
603LLRect LLScrollContainer::getVisibleContentRect()
604{
605	updateScroll();
606	LLRect visible_rect = getContentWindowRect();
607	LLRect contents_rect = mScrolledView->getRect();
608	visible_rect.translate(-contents_rect.mLeft, -contents_rect.mBottom);
609	return visible_rect;
610}
611
612LLRect LLScrollContainer::getContentWindowRect()
613{
614	updateScroll();
615	LLRect scroller_view_rect;
616	S32 visible_width = 0;
617	S32 visible_height = 0;
618	BOOL show_h_scrollbar = FALSE;
619	BOOL show_v_scrollbar = FALSE;
620	calcVisibleSize( &visible_width, &visible_height, &show_h_scrollbar, &show_v_scrollbar );
621	S32 border_width = getBorderWidth();
622	scroller_view_rect.setOriginAndSize(border_width, 
623										show_h_scrollbar ? mScrollbar[HORIZONTAL]->getRect().mTop : border_width, 
624										visible_width, 
625										visible_height);
626	return scroller_view_rect;
627}
628
629// rect is in document coordinates, constraint is in display coordinates relative to content window rect
630void LLScrollContainer::scrollToShowRect(const LLRect& rect, const LLRect& constraint)
631{
632	if (!mScrolledView)
633	{
634		llwarns << "LLScrollContainer::scrollToShowRect with no view!" << llendl;
635		return;
636	}
637
638	LLRect content_window_rect = getContentWindowRect();
639	// get document rect
640	LLRect scrolled_rect = mScrolledView->getRect();
641
642	// shrink target rect to fit within constraint region, biasing towards top left
643	LLRect rect_to_constrain = rect;
644	rect_to_constrain.mBottom = llmax(rect_to_constrain.mBottom, rect_to_constrain.mTop - constraint.getHeight());
645	rect_to_constrain.mRight = llmin(rect_to_constrain.mRight, rect_to_constrain.mLeft + constraint.getWidth());
646
647	// calculate allowable positions for scroller window in document coordinates
648	LLRect allowable_scroll_rect(rect_to_constrain.mRight - constraint.mRight,
649								rect_to_constrain.mBottom - constraint.mBottom,
650								rect_to_constrain.mLeft - constraint.mLeft,
651								rect_to_constrain.mTop - constraint.mTop);
652
653	// translate from allowable region for lower left corner to upper left corner
654	allowable_scroll_rect.translate(0, content_window_rect.getHeight());
655
656	S32 vert_pos = llclamp(mScrollbar[VERTICAL]->getDocPos(), 
657					mScrollbar[VERTICAL]->getDocSize() - allowable_scroll_rect.mTop, // min vertical scroll
658					mScrollbar[VERTICAL]->getDocSize() - allowable_scroll_rect.mBottom); // max vertical scroll	
659
660	mScrollbar[VERTICAL]->setDocSize( scrolled_rect.getHeight() );
661	mScrollbar[VERTICAL]->setPageSize( content_window_rect.getHeight() );
662	mScrollbar[VERTICAL]->setDocPos( vert_pos );
663
664	S32 horizontal_pos = llclamp(mScrollbar[HORIZONTAL]->getDocPos(), 
665								allowable_scroll_rect.mLeft,
666								allowable_scroll_rect.mRight);
667
668	mScrollbar[HORIZONTAL]->setDocSize( scrolled_rect.getWidth() );
669	mScrollbar[HORIZONTAL]->setPageSize( content_window_rect.getWidth() );
670	mScrollbar[HORIZONTAL]->setDocPos( horizontal_pos );
671
672	// propagate scroll to document
673	updateScroll();
674
675	// In case we are in accordion tab notify parent to show selected rectangle
676	LLRect screen_rc;
677	localRectToScreen(rect_to_constrain, &screen_rc);
678	notifyParent(LLSD().with("scrollToShowRect",screen_rc.getValue()));
679}
680
681void LLScrollContainer::pageUp(S32 overlap)
682{
683	mScrollbar[VERTICAL]->pageUp(overlap);
684	updateScroll();
685}
686
687void LLScrollContainer::pageDown(S32 overlap)
688{
689	mScrollbar[VERTICAL]->pageDown(overlap);
690	updateScroll();
691}
692
693void LLScrollContainer::goToTop()
694{
695	mScrollbar[VERTICAL]->setDocPos(0);
696	updateScroll();
697}
698
699void LLScrollContainer::goToBottom()
700{
701	mScrollbar[VERTICAL]->setDocPos(mScrollbar[VERTICAL]->getDocSize());
702	updateScroll();
703}
704
705S32 LLScrollContainer::getBorderWidth() const
706{
707	if (mBorder->getVisible())
708	{
709		return mBorder->getBorderWidth();
710	}
711
712	return 0;
713}
714