PageRenderTime 1514ms CodeModel.GetById 393ms app.highlight 629ms RepoModel.GetById 478ms app.codeStats 1ms

/indra/newview/llpanelprimmediacontrols.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 1380 lines | 1066 code | 188 blank | 126 comment | 158 complexity | 9ed2e03068db42eecd838d87866ccc65 MD5 | raw file
   1/** 
   2 * @file llpanelprimmediacontrols.cpp
   3 * @brief media controls popup panel
   4 *
   5 * $LicenseInfo:firstyear=2003&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#include "llviewerprecompiledheaders.h"
  28
  29#include "llagent.h"
  30#include "llagentcamera.h"
  31#include "llparcel.h"
  32#include "llpanel.h"
  33#include "llselectmgr.h"
  34#include "llmediaentry.h"
  35#include "llrender.h"
  36#include "lldrawable.h"
  37#include "llviewerwindow.h"
  38#include "lluictrlfactory.h"
  39#include "llbutton.h"
  40#include "llface.h"
  41#include "llcombobox.h"
  42#include "lllayoutstack.h"
  43#include "llslider.h"
  44#include "llhudview.h"
  45#include "lliconctrl.h"
  46#include "lltoolpie.h"
  47#include "llviewercamera.h"
  48#include "llviewerobjectlist.h"
  49#include "llpanelprimmediacontrols.h"
  50#include "llpluginclassmedia.h"
  51#include "llprogressbar.h"
  52#include "llsliderctrl.h"
  53#include "llstring.h"
  54#include "llviewercontrol.h"
  55#include "llviewerdisplay.h"
  56#include "llviewerparcelmgr.h"
  57#include "llviewermedia.h"
  58#include "llviewermediafocus.h"
  59#include "llvovolume.h"
  60#include "llweb.h"
  61#include "llwindow.h"
  62#include "llwindowshade.h"
  63#include "llfloatertools.h"  // to enable hide if build tools are up
  64#include "llvector4a.h"
  65
  66// Functions pulled from pipeline.cpp
  67glh::matrix4f glh_get_current_modelview();
  68glh::matrix4f glh_get_current_projection();
  69// Functions pulled from llviewerdisplay.cpp
  70bool get_hud_matrices(glh::matrix4f &proj, glh::matrix4f &model);
  71
  72// Warning: make sure these two match!
  73const LLPanelPrimMediaControls::EZoomLevel LLPanelPrimMediaControls::kZoomLevels[] = { ZOOM_NONE, ZOOM_MEDIUM };
  74const int LLPanelPrimMediaControls::kNumZoomLevels = 2;
  75
  76//
  77// LLPanelPrimMediaControls
  78//
  79
  80LLPanelPrimMediaControls::LLPanelPrimMediaControls() : 
  81	mAlpha(1.f),
  82	mCurrentURL(""),
  83	mPreviousURL(""),
  84	mPauseFadeout(false),
  85	mUpdateSlider(true),
  86	mClearFaceOnFade(false),
  87	mCurrentRate(0.0),
  88	mMovieDuration(0.0),
  89	mTargetObjectID(LLUUID::null),
  90	mTargetObjectFace(0),
  91	mTargetImplID(LLUUID::null),
  92	mTargetObjectNormal(LLVector3::zero),
  93	mZoomObjectID(LLUUID::null),
  94	mZoomObjectFace(0),
  95	mVolumeSliderVisible(0),
  96	mWindowShade(NULL),
  97	mHideImmediately(false)
  98{
  99	mCommitCallbackRegistrar.add("MediaCtrl.Close",		boost::bind(&LLPanelPrimMediaControls::onClickClose, this));
 100	mCommitCallbackRegistrar.add("MediaCtrl.Back",		boost::bind(&LLPanelPrimMediaControls::onClickBack, this));
 101	mCommitCallbackRegistrar.add("MediaCtrl.Forward",	boost::bind(&LLPanelPrimMediaControls::onClickForward, this));
 102	mCommitCallbackRegistrar.add("MediaCtrl.Home",		boost::bind(&LLPanelPrimMediaControls::onClickHome, this));
 103	mCommitCallbackRegistrar.add("MediaCtrl.Stop",		boost::bind(&LLPanelPrimMediaControls::onClickStop, this));
 104	mCommitCallbackRegistrar.add("MediaCtrl.MediaStop",		boost::bind(&LLPanelPrimMediaControls::onClickMediaStop, this));
 105	mCommitCallbackRegistrar.add("MediaCtrl.Reload",	boost::bind(&LLPanelPrimMediaControls::onClickReload, this));
 106	mCommitCallbackRegistrar.add("MediaCtrl.Play",		boost::bind(&LLPanelPrimMediaControls::onClickPlay, this));
 107	mCommitCallbackRegistrar.add("MediaCtrl.Pause",		boost::bind(&LLPanelPrimMediaControls::onClickPause, this));
 108	mCommitCallbackRegistrar.add("MediaCtrl.Open",		boost::bind(&LLPanelPrimMediaControls::onClickOpen, this));
 109	mCommitCallbackRegistrar.add("MediaCtrl.Zoom",		boost::bind(&LLPanelPrimMediaControls::onClickZoom, this));
 110	mCommitCallbackRegistrar.add("MediaCtrl.CommitURL",	boost::bind(&LLPanelPrimMediaControls::onCommitURL, this));
 111	mCommitCallbackRegistrar.add("MediaCtrl.JumpProgress",		boost::bind(&LLPanelPrimMediaControls::onCommitSlider, this));
 112	mCommitCallbackRegistrar.add("MediaCtrl.CommitVolumeUp",	boost::bind(&LLPanelPrimMediaControls::onCommitVolumeUp, this));
 113	mCommitCallbackRegistrar.add("MediaCtrl.CommitVolumeDown",	boost::bind(&LLPanelPrimMediaControls::onCommitVolumeDown, this));
 114	mCommitCallbackRegistrar.add("MediaCtrl.Volume",	boost::bind(&LLPanelPrimMediaControls::onCommitVolumeSlider, this));
 115	mCommitCallbackRegistrar.add("MediaCtrl.ToggleMute",		boost::bind(&LLPanelPrimMediaControls::onToggleMute, this));
 116	mCommitCallbackRegistrar.add("MediaCtrl.ShowVolumeSlider",		boost::bind(&LLPanelPrimMediaControls::showVolumeSlider, this));
 117	mCommitCallbackRegistrar.add("MediaCtrl.HideVolumeSlider",		boost::bind(&LLPanelPrimMediaControls::hideVolumeSlider, this));
 118	mCommitCallbackRegistrar.add("MediaCtrl.SkipBack",		boost::bind(&LLPanelPrimMediaControls::onClickSkipBack, this));
 119	mCommitCallbackRegistrar.add("MediaCtrl.SkipForward",	boost::bind(&LLPanelPrimMediaControls::onClickSkipForward, this));
 120	
 121	buildFromFile( "panel_prim_media_controls.xml");
 122	mInactivityTimer.reset();
 123	mFadeTimer.stop();
 124	mCurrentZoom = ZOOM_NONE;
 125	mScrollState = SCROLL_NONE;
 126
 127	mPanelHandle.bind(this);
 128	
 129	mInactiveTimeout = gSavedSettings.getF32("MediaControlTimeout");
 130	mControlFadeTime = gSavedSettings.getF32("MediaControlFadeTime");
 131}
 132
 133LLPanelPrimMediaControls::~LLPanelPrimMediaControls()
 134{
 135}
 136
 137BOOL LLPanelPrimMediaControls::postBuild()
 138{
 139	mMediaRegion			= getChild<LLView>("media_region");
 140	mBackCtrl				= getChild<LLUICtrl>("back");
 141	mFwdCtrl				= getChild<LLUICtrl>("fwd");
 142	mReloadCtrl				= getChild<LLUICtrl>("reload");
 143	mPlayCtrl				= getChild<LLUICtrl>("play");
 144	mPauseCtrl				= getChild<LLUICtrl>("pause");
 145	mStopCtrl				= getChild<LLUICtrl>("stop");
 146	mMediaStopCtrl			= getChild<LLUICtrl>("media_stop");
 147	mHomeCtrl				= getChild<LLUICtrl>("home");
 148	mUnzoomCtrl				= getChild<LLUICtrl>("close"); // This is actually "unzoom" 
 149	mOpenCtrl				= getChild<LLUICtrl>("new_window");
 150	mZoomCtrl				= getChild<LLUICtrl>("zoom_frame");
 151	mMediaProgressPanel		= getChild<LLPanel>("media_progress_indicator");
 152	mMediaProgressBar		= getChild<LLProgressBar>("media_progress_bar");
 153	mMediaAddressCtrl		= getChild<LLUICtrl>("media_address");
 154	mMediaAddress			= getChild<LLUICtrl>("media_address_url");
 155	mMediaPlaySliderPanel	= getChild<LLUICtrl>("media_play_position");
 156	mMediaPlaySliderCtrl	= getChild<LLUICtrl>("media_play_slider");
 157	mSkipFwdCtrl			= getChild<LLUICtrl>("skip_forward");
 158	mSkipBackCtrl			= getChild<LLUICtrl>("skip_back");
 159	mVolumeCtrl				= getChild<LLUICtrl>("media_volume");
 160	mMuteBtn				= getChild<LLButton>("media_mute_button");
 161	mVolumeSliderCtrl       = getChild<LLSliderCtrl>("volume_slider");
 162	mWhitelistIcon			= getChild<LLIconCtrl>("media_whitelist_flag");
 163	mSecureLockIcon			= getChild<LLIconCtrl>("media_secure_lock_flag");
 164	mMediaControlsStack		= getChild<LLLayoutStack>("media_controls");
 165	mLeftBookend			= getChild<LLUICtrl>("left_bookend");
 166	mRightBookend			= getChild<LLUICtrl>("right_bookend");
 167	mBackgroundImage		= LLUI::getUIImage(getString("control_background_image_name"));
 168	mVolumeSliderBackgroundImage		= LLUI::getUIImage(getString("control_background_image_name"));
 169	LLStringUtil::convertToF32(getString("skip_step"), mSkipStep);
 170	LLStringUtil::convertToS32(getString("min_width"), mMinWidth);
 171	LLStringUtil::convertToS32(getString("min_height"), mMinHeight);
 172	LLStringUtil::convertToF32(getString("zoom_near_padding"), mZoomNearPadding);
 173	LLStringUtil::convertToF32(getString("zoom_medium_padding"), mZoomMediumPadding);
 174	LLStringUtil::convertToF32(getString("zoom_far_padding"), mZoomFarPadding);
 175	LLStringUtil::convertToS32(getString("top_world_view_avoid_zone"), mTopWorldViewAvoidZone);
 176
 177	// These are currently removed...but getChild creates a "dummy" widget.
 178	// This class handles them missing.
 179	mMediaPanelScroll		= findChild<LLUICtrl>("media_panel_scroll");
 180	mScrollUpCtrl			= findChild<LLButton>("scrollup");
 181	mScrollLeftCtrl			= findChild<LLButton>("scrollleft");
 182	mScrollRightCtrl		= findChild<LLButton>("scrollright");
 183	mScrollDownCtrl			= findChild<LLButton>("scrolldown");	
 184	
 185	if (mScrollUpCtrl)
 186	{
 187		mScrollUpCtrl->setClickedCallback(onScrollUp, this);
 188		mScrollUpCtrl->setHeldDownCallback(onScrollUpHeld, this);
 189		mScrollUpCtrl->setMouseUpCallback(onScrollStop, this);
 190	}
 191	if (mScrollLeftCtrl)
 192	{
 193		mScrollLeftCtrl->setClickedCallback(onScrollLeft, this);
 194		mScrollLeftCtrl->setHeldDownCallback(onScrollLeftHeld, this);
 195		mScrollLeftCtrl->setMouseUpCallback(onScrollStop, this);
 196	}
 197	if (mScrollRightCtrl)
 198	{
 199		mScrollRightCtrl->setClickedCallback(onScrollRight, this);
 200		mScrollRightCtrl->setHeldDownCallback(onScrollRightHeld, this);
 201		mScrollRightCtrl->setMouseUpCallback(onScrollStop, this);
 202	}
 203	if (mScrollDownCtrl)
 204	{
 205		mScrollDownCtrl->setClickedCallback(onScrollDown, this);
 206		mScrollDownCtrl->setHeldDownCallback(onScrollDownHeld, this);
 207		mScrollDownCtrl->setMouseUpCallback(onScrollStop, this);
 208	}
 209		
 210	mMediaAddress->setFocusReceivedCallback(boost::bind(&LLPanelPrimMediaControls::onInputURL, _1, this ));
 211	
 212	gAgent.setMouselookModeInCallback(boost::bind(&LLPanelPrimMediaControls::onMouselookModeIn, this));
 213
 214	LLWindowShade::Params window_shade_params;
 215	window_shade_params.name = "window_shade";
 216
 217	mCurrentZoom = ZOOM_NONE;
 218	// clicks on buttons do not remove keyboard focus from media
 219	setIsChrome(TRUE);
 220	return TRUE;
 221}
 222
 223void LLPanelPrimMediaControls::setMediaFace(LLPointer<LLViewerObject> objectp, S32 face, viewer_media_t media_impl, LLVector3 pick_normal)
 224{
 225	if (media_impl.notNull() && objectp.notNull())
 226	{
 227		LLUUID prev_id = mTargetImplID;
 228		mTargetImplID = media_impl->getMediaTextureID();
 229		mTargetObjectID = objectp->getID();
 230		mTargetObjectFace = face;
 231		mTargetObjectNormal = pick_normal;
 232		mClearFaceOnFade = false;
 233		
 234		if (prev_id != mTargetImplID)
 235			mVolumeSliderCtrl->setValue(media_impl->getVolume());
 236	}
 237	else
 238	{
 239		// This happens on a timer now.
 240//		mTargetImplID = LLUUID::null;
 241//		mTargetObjectID = LLUUID::null;
 242//		mTargetObjectFace = 0;
 243		mClearFaceOnFade = true;
 244	}
 245
 246	updateShape();
 247}
 248
 249void LLPanelPrimMediaControls::focusOnTarget()
 250{
 251	// Sets the media focus to the current target of the LLPanelPrimMediaControls.
 252	// This is how we transition from hover to focus when the user clicks on a control.
 253	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
 254	if(media_impl)
 255	{
 256		if(!media_impl->hasFocus())
 257		{	
 258			// The current target doesn't have media focus -- focus on it.
 259			LLViewerObject* objectp = getTargetObject();
 260			LLViewerMediaFocus::getInstance()->setFocusFace(objectp, mTargetObjectFace, media_impl, mTargetObjectNormal);
 261		}
 262	}	
 263}
 264
 265LLViewerMediaImpl* LLPanelPrimMediaControls::getTargetMediaImpl()
 266{
 267	return LLViewerMedia::getMediaImplFromTextureID(mTargetImplID);
 268}
 269
 270LLViewerObject* LLPanelPrimMediaControls::getTargetObject()
 271{
 272	return gObjectList.findObject(mTargetObjectID);
 273}
 274
 275LLPluginClassMedia* LLPanelPrimMediaControls::getTargetMediaPlugin()
 276{
 277	LLViewerMediaImpl* impl = getTargetMediaImpl();
 278	if(impl && impl->hasMedia())
 279	{
 280		return impl->getMediaPlugin();
 281	}
 282	
 283	return NULL;
 284}
 285
 286void LLPanelPrimMediaControls::updateShape()
 287{
 288	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
 289	LLViewerObject* objectp = getTargetObject();
 290	
 291	if(!media_impl || gFloaterTools->getVisible())
 292	{
 293		setVisible(FALSE);
 294		return;
 295	}
 296
 297	LLPluginClassMedia* media_plugin = NULL;
 298	if(media_impl->hasMedia())
 299	{
 300		media_plugin = media_impl->getMediaPlugin();
 301	}
 302	
 303	LLParcel *parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
 304
 305	bool can_navigate = parcel->getMediaAllowNavigate();
 306	bool enabled = false;
 307	bool is_zoomed = (mCurrentZoom != ZOOM_NONE) && (mTargetObjectID == mZoomObjectID) && (mTargetObjectFace == mZoomObjectFace);
 308	// There is no such thing as "has_focus" being different from normal controls set
 309	// anymore (as of user feedback from bri 10/09).  So we cheat here and force 'has_focus'
 310	// to 'true' (or, actually, we use a setting)
 311	bool has_focus = (gSavedSettings.getBOOL("PrimMediaControlsUseHoverControlSet")) ? media_impl->hasFocus() : true;
 312	setVisible(enabled);
 313
 314	if (objectp)
 315	{
 316		bool mini_controls = false;
 317		LLMediaEntry *media_data = objectp->getTE(mTargetObjectFace)->getMediaData();
 318		if (media_data && NULL != dynamic_cast<LLVOVolume*>(objectp))
 319		{
 320			// Don't show the media controls if we do not have permissions
 321			enabled = dynamic_cast<LLVOVolume*>(objectp)->hasMediaPermission(media_data, LLVOVolume::MEDIA_PERM_CONTROL);
 322			mini_controls = (LLMediaEntry::MINI == media_data->getControls());
 323		}
 324		const bool is_hud = objectp->isHUDAttachment();
 325		
 326		//
 327		// Set the state of the buttons
 328		//
 329		
 330		// XXX RSP: TODO: FIXME: clean this up so that it is clearer what mode we are in,
 331		// and that only the proper controls get made visible/enabled according to that mode. 
 332		mBackCtrl->setVisible(has_focus);
 333		mFwdCtrl->setVisible(has_focus);
 334		mReloadCtrl->setVisible(has_focus);
 335		mStopCtrl->setVisible(false);
 336		mHomeCtrl->setVisible(has_focus);
 337		mZoomCtrl->setVisible(!is_zoomed);
 338		mUnzoomCtrl->setVisible(is_zoomed);
 339		mOpenCtrl->setVisible(true);
 340		mMediaAddressCtrl->setVisible(has_focus && !mini_controls);
 341		mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls);
 342		mVolumeCtrl->setVisible(false);
 343		
 344		mWhitelistIcon->setVisible(!mini_controls && (media_data)?media_data->getWhiteListEnable():false);
 345		// Disable zoom if HUD
 346		mZoomCtrl->setEnabled(!is_hud);
 347		mUnzoomCtrl->setEnabled(!is_hud);
 348		mSecureLockIcon->setVisible(false);
 349		mCurrentURL = media_impl->getCurrentMediaURL();
 350		
 351		mBackCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateBack() && can_navigate);
 352		mFwdCtrl->setEnabled((media_impl != NULL) && media_impl->canNavigateForward() && can_navigate);
 353		mStopCtrl->setEnabled(has_focus && can_navigate);
 354		mHomeCtrl->setEnabled(has_focus && can_navigate);
 355		LLPluginClassMediaOwner::EMediaStatus result = ((media_impl != NULL) && media_impl->hasMedia()) ? media_plugin->getStatus() : LLPluginClassMediaOwner::MEDIA_NONE;
 356		
 357		mVolumeCtrl->setVisible(has_focus);
 358		mVolumeCtrl->setEnabled(has_focus);
 359		mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible());
 360		mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible());
 361
 362		if(media_plugin && media_plugin->pluginSupportsMediaTime())
 363		{
 364			mReloadCtrl->setEnabled(false);
 365			mReloadCtrl->setVisible(false);
 366			mMediaStopCtrl->setVisible(has_focus);
 367			mHomeCtrl->setVisible(has_focus);
 368			mBackCtrl->setVisible(false);
 369			mFwdCtrl->setVisible(false);
 370			mMediaAddressCtrl->setVisible(false);
 371			mMediaAddressCtrl->setEnabled(false);
 372			mMediaPlaySliderPanel->setVisible(has_focus && !mini_controls);
 373			mMediaPlaySliderPanel->setEnabled(has_focus && !mini_controls);
 374			mSkipFwdCtrl->setVisible(has_focus && !mini_controls);
 375			mSkipFwdCtrl->setEnabled(has_focus && !mini_controls);
 376			mSkipBackCtrl->setVisible(has_focus && !mini_controls);
 377			mSkipBackCtrl->setEnabled(has_focus && !mini_controls);
 378			
 379			mVolumeCtrl->setVisible(has_focus);
 380			mVolumeCtrl->setEnabled(has_focus);
 381			mVolumeSliderCtrl->setEnabled(has_focus && shouldVolumeSliderBeVisible());
 382			mVolumeSliderCtrl->setVisible(has_focus && shouldVolumeSliderBeVisible());
 383			
 384			mWhitelistIcon->setVisible(false);
 385			mSecureLockIcon->setVisible(false);
 386			if (mMediaPanelScroll)
 387			{
 388				mMediaPanelScroll->setVisible(false);
 389				mScrollUpCtrl->setVisible(false);
 390				mScrollDownCtrl->setVisible(false);
 391				mScrollRightCtrl->setVisible(false);
 392				mScrollDownCtrl->setVisible(false);
 393			}
 394			
 395			F32 volume = media_impl->getVolume();
 396			// movie's url changed
 397			if(mCurrentURL!=mPreviousURL)
 398			{
 399				mMovieDuration = media_plugin->getDuration();
 400				mPreviousURL = mCurrentURL;
 401			}
 402			
 403			if(mMovieDuration == 0) 
 404			{
 405				mMovieDuration = media_plugin->getDuration();
 406				mMediaPlaySliderCtrl->setValue(0);
 407				mMediaPlaySliderCtrl->setEnabled(false);
 408			}
 409			// TODO: What if it's not fully loaded
 410			
 411			if(mUpdateSlider && mMovieDuration!= 0)
 412			{
 413				F64 current_time =  media_plugin->getCurrentTime();
 414				F32 percent = current_time / mMovieDuration;
 415				mMediaPlaySliderCtrl->setValue(percent);
 416				mMediaPlaySliderCtrl->setEnabled(true);
 417			}
 418			
 419			// video vloume
 420			if(volume <= 0.0)
 421			{
 422				mMuteBtn->setToggleState(true);
 423			}
 424			else if (volume >= 1.0)
 425			{
 426				mMuteBtn->setToggleState(false);
 427			}
 428			else
 429			{
 430				mMuteBtn->setToggleState(false);
 431			}
 432			
 433			switch(result)
 434			{
 435				case LLPluginClassMediaOwner::MEDIA_PLAYING:
 436					mPlayCtrl->setEnabled(FALSE);
 437					mPlayCtrl->setVisible(FALSE);
 438					mPauseCtrl->setEnabled(TRUE);
 439					mPauseCtrl->setVisible(has_focus);
 440					
 441					break;
 442				case LLPluginClassMediaOwner::MEDIA_PAUSED:
 443				default:
 444					mPauseCtrl->setEnabled(FALSE);
 445					mPauseCtrl->setVisible(FALSE);
 446					mPlayCtrl->setEnabled(TRUE);
 447					mPlayCtrl->setVisible(has_focus);
 448					break;
 449			}
 450		}
 451		else   // web based
 452		{
 453			if(media_plugin)
 454			{
 455				mCurrentURL = media_plugin->getLocation();
 456			}
 457			else
 458			{
 459				mCurrentURL.clear();
 460			}
 461			
 462			mPlayCtrl->setVisible(FALSE);
 463			mPauseCtrl->setVisible(FALSE);
 464			mMediaStopCtrl->setVisible(FALSE);
 465			mMediaAddressCtrl->setVisible(has_focus && !mini_controls);
 466			mMediaAddressCtrl->setEnabled(has_focus && !mini_controls);
 467			mMediaPlaySliderPanel->setVisible(FALSE);
 468			mMediaPlaySliderPanel->setEnabled(FALSE);
 469			mSkipFwdCtrl->setVisible(FALSE);
 470			mSkipFwdCtrl->setEnabled(FALSE);
 471			mSkipBackCtrl->setVisible(FALSE);
 472			mSkipBackCtrl->setEnabled(FALSE);
 473			
 474			if(media_impl->getVolume() <= 0.0)
 475			{
 476				mMuteBtn->setToggleState(true);
 477			}
 478			else
 479			{
 480				mMuteBtn->setToggleState(false);
 481			}
 482
 483			if (mMediaPanelScroll)
 484			{
 485				mMediaPanelScroll->setVisible(has_focus);
 486				mScrollUpCtrl->setVisible(has_focus);
 487				mScrollDownCtrl->setVisible(has_focus);
 488				mScrollRightCtrl->setVisible(has_focus);
 489				mScrollDownCtrl->setVisible(has_focus);
 490			}
 491			// TODO: get the secure lock bool from media plug in
 492			std::string prefix =  std::string("https://");
 493			std::string test_prefix = mCurrentURL.substr(0, prefix.length());
 494			LLStringUtil::toLower(test_prefix);
 495			if(test_prefix == prefix)
 496			{
 497				mSecureLockIcon->setVisible(has_focus);
 498			}
 499			
 500			if(mCurrentURL!=mPreviousURL)
 501			{
 502				setCurrentURL();
 503				mPreviousURL = mCurrentURL;
 504			}
 505			
 506			if(result == LLPluginClassMediaOwner::MEDIA_LOADING)
 507			{
 508				mReloadCtrl->setEnabled(FALSE);
 509				mReloadCtrl->setVisible(FALSE);
 510				mStopCtrl->setEnabled(TRUE);
 511				mStopCtrl->setVisible(has_focus);
 512			}
 513			else
 514			{
 515				mReloadCtrl->setEnabled(TRUE);
 516				mReloadCtrl->setVisible(has_focus);
 517				mStopCtrl->setEnabled(FALSE);
 518				mStopCtrl->setVisible(FALSE);
 519			}
 520		}
 521		
 522		
 523		if(media_plugin)
 524		{
 525			//
 526			// Handle progress bar
 527			//
 528			if(LLPluginClassMediaOwner::MEDIA_LOADING == media_plugin->getStatus())
 529			{	
 530				mMediaProgressPanel->setVisible(true);
 531				mMediaProgressBar->setValue(media_plugin->getProgressPercent());
 532			}
 533			else
 534			{
 535				mMediaProgressPanel->setVisible(false);
 536			}
 537		}
 538		
 539		if(media_impl)
 540		{
 541			//
 542			// Handle Scrolling
 543			//
 544			switch (mScrollState) 
 545			{
 546				case SCROLL_UP:
 547					media_impl->scrollWheel(0, -1, MASK_NONE);
 548					break;
 549				case SCROLL_DOWN:
 550					media_impl->scrollWheel(0, 1, MASK_NONE);
 551					break;
 552				case SCROLL_LEFT:
 553					media_impl->scrollWheel(1, 0, MASK_NONE);
 554					//				media_impl->handleKeyHere(KEY_LEFT, MASK_NONE);
 555					break;
 556				case SCROLL_RIGHT:
 557					media_impl->scrollWheel(-1, 0, MASK_NONE);
 558					//				media_impl->handleKeyHere(KEY_RIGHT, MASK_NONE);
 559					break;
 560				case SCROLL_NONE:
 561				default:
 562					break;
 563			}
 564		}
 565		
 566		setVisible(enabled);
 567		
 568		//
 569		// Calculate position and shape of the controls
 570		//
 571		std::vector<LLVector3>::iterator vert_it;
 572		std::vector<LLVector3>::iterator vert_end;
 573		std::vector<LLVector3> vect_face;
 574		
 575		LLVolume* volume = objectp->getVolume();
 576		
 577		if (volume)
 578		{
 579			const LLVolumeFace& vf = volume->getVolumeFace(mTargetObjectFace);
 580			
 581			LLVector3 ext[2];
 582			ext[0].set(vf.mExtents[0].getF32ptr());
 583			ext[1].set(vf.mExtents[1].getF32ptr());
 584			
 585			LLVector3 center = (ext[0]+ext[1])*0.5f;
 586			LLVector3 size = (ext[1]-ext[0])*0.5f;
 587			LLVector3 vert[] =
 588			{
 589				center + size.scaledVec(LLVector3(1,1,1)),
 590				center + size.scaledVec(LLVector3(-1,1,1)),
 591				center + size.scaledVec(LLVector3(1,-1,1)),
 592				center + size.scaledVec(LLVector3(-1,-1,1)),
 593				center + size.scaledVec(LLVector3(1,1,-1)),
 594				center + size.scaledVec(LLVector3(-1,1,-1)),
 595				center + size.scaledVec(LLVector3(1,-1,-1)),
 596				center + size.scaledVec(LLVector3(-1,-1,-1)),
 597			};
 598			
 599			LLVOVolume* vo = (LLVOVolume*) objectp;
 600			
 601			for (U32 i = 0; i < 8; i++)
 602			{
 603				vect_face.push_back(vo->volumePositionToAgent(vert[i]));
 604			}
 605		}
 606		vert_it = vect_face.begin();
 607		vert_end = vect_face.end();
 608		
 609		glh::matrix4f mat;
 610		if (!is_hud) 
 611		{
 612			mat = glh_get_current_projection() * glh_get_current_modelview();
 613		}
 614		else {
 615			glh::matrix4f proj, modelview;
 616			if (get_hud_matrices(proj, modelview))
 617				mat = proj * modelview;
 618		}
 619		LLVector3 min = LLVector3(1,1,1);
 620		LLVector3 max = LLVector3(-1,-1,-1);
 621		for(; vert_it != vert_end; ++vert_it)
 622		{
 623			// project silhouette vertices into screen space
 624			glh::vec3f screen_vert = glh::vec3f(vert_it->mV); 
 625			mat.mult_matrix_vec(screen_vert);
 626			
 627			// add to screenspace bounding box
 628			update_min_max(min, max, LLVector3(screen_vert.v));
 629		}
 630		
 631		// convert screenspace bbox to pixels (in screen coords)
 632		LLRect window_rect = gViewerWindow->getWorldViewRectScaled();
 633		LLCoordGL screen_min;
 634		screen_min.mX = llround((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (min.mV[VX] + 1.f) * 0.5f);
 635		screen_min.mY = llround((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (min.mV[VY] + 1.f) * 0.5f);
 636		
 637		LLCoordGL screen_max;
 638		screen_max.mX = llround((F32)window_rect.mLeft + (F32)window_rect.getWidth() * (max.mV[VX] + 1.f) * 0.5f);
 639		screen_max.mY = llround((F32)window_rect.mBottom + (F32)window_rect.getHeight() * (max.mV[VY] + 1.f) * 0.5f);
 640		
 641		// grow panel so that screenspace bounding box fits inside "media_region" element of panel
 642		LLRect media_panel_rect;
 643		// Get the height of the controls (less the volume slider)
 644		S32 controls_height = mMediaControlsStack->getRect().getHeight() - mVolumeSliderCtrl->getRect().getHeight();
 645		getParent()->screenRectToLocal(LLRect(screen_min.mX, screen_max.mY, screen_max.mX, screen_min.mY), &media_panel_rect);
 646		media_panel_rect.mTop += controls_height;
 647		
 648		// keep all parts of panel on-screen
 649		// Area of the top of the world view to avoid putting the controls
 650		window_rect.mTop -= mTopWorldViewAvoidZone;
 651		// Don't include "spacing" bookends on left & right of the media controls
 652		window_rect.mLeft -= mLeftBookend->getRect().getWidth();
 653		window_rect.mRight += mRightBookend->getRect().getWidth();
 654		// Don't include the volume slider
 655		window_rect.mBottom -= mVolumeSliderCtrl->getRect().getHeight();
 656		media_panel_rect.intersectWith(window_rect);
 657		
 658		// clamp to minimum size, keeping rect inside window
 659		S32 centerX = media_panel_rect.getCenterX();
 660		S32 centerY = media_panel_rect.getCenterY();
 661		// Shrink screen rect by min width and height, to ensure containment
 662		window_rect.stretch(-mMinWidth/2, -mMinHeight/2);
 663		window_rect.clampPointToRect(centerX, centerY);
 664		media_panel_rect.setCenterAndSize(centerX, centerY, 
 665										  llmax(mMinWidth, media_panel_rect.getWidth()),
 666										  llmax(mMinHeight, media_panel_rect.getHeight()));
 667		
 668		// Finally set the size of the panel
 669		setShape(media_panel_rect, true);
 670		
 671		// Test mouse position to see if the cursor is stationary
 672		LLCoordWindow cursor_pos_window;
 673		getWindow()->getCursorPosition(&cursor_pos_window);
 674		
 675		// If last pos is not equal to current pos, the mouse has moved
 676		// We need to reset the timer, and make sure the panel is visible
 677		if(cursor_pos_window.mX != mLastCursorPos.mX ||
 678		   cursor_pos_window.mY != mLastCursorPos.mY ||
 679		   mScrollState != SCROLL_NONE)
 680		{
 681			mInactivityTimer.start();
 682			mLastCursorPos = cursor_pos_window;
 683		}
 684		
 685		if(isMouseOver() || hasFocus())
 686		{
 687			// Never fade the controls if the mouse is over them or they have keyboard focus.
 688			mFadeTimer.stop();
 689		}
 690		else if(!mClearFaceOnFade && (mInactivityTimer.getElapsedTimeF32() < mInactiveTimeout))
 691		{
 692			// Mouse is over the object, but has not been stationary for long enough to fade the UI
 693			mFadeTimer.stop();
 694		}
 695		else if(! mFadeTimer.getStarted() )
 696		{
 697			// we need to start fading the UI (and we have not already started)
 698			mFadeTimer.reset();
 699			mFadeTimer.start();
 700		}
 701		else
 702		{
 703			// I don't think this is correct anymore.  This is done in draw() after the fade has completed.
 704			//			setVisible(FALSE);
 705		}
 706	}
 707}
 708
 709/*virtual*/
 710void LLPanelPrimMediaControls::draw()
 711{
 712	LLViewerMediaImpl* impl = getTargetMediaImpl();
 713	if (impl)
 714	{
 715		LLNotificationPtr notification = impl->getCurrentNotification();
 716		if (notification != mActiveNotification)
 717		{
 718			mActiveNotification = notification;
 719			if (notification)
 720			{
 721				showNotification(notification);
 722			}
 723			else
 724			{
 725				hideNotification();
 726			}
 727		}
 728	}
 729
 730	F32 alpha = getDrawContext().mAlpha;
 731	if(mHideImmediately)
 732	{
 733		//hide this panel
 734		clearFaceOnFade();
 735
 736		mHideImmediately = false;
 737	}
 738	else if(mFadeTimer.getStarted())
 739	{
 740		F32 time = mFadeTimer.getElapsedTimeF32();
 741		alpha *= llmax(lerp(1.0, 0.0, time / mControlFadeTime), 0.0f);
 742
 743		if(time >= mControlFadeTime)
 744		{
 745			//hide this panel
 746			clearFaceOnFade();
 747		}
 748	}
 749	
 750	// Build rect for icon area in coord system of this panel
 751	// Assumes layout_stack is a direct child of this panel
 752	mMediaControlsStack->updateLayout();
 753	
 754	// adjust for layout stack spacing
 755	S32 space = mMediaControlsStack->getPanelSpacing() + 2;
 756	LLRect controls_bg_area = mMediaControlsStack->getRect();
 757	
 758	controls_bg_area.mTop += space + 2;
 759	
 760	// adjust to ignore space from volume slider
 761	controls_bg_area.mBottom += mVolumeSliderCtrl->getRect().getHeight();
 762	
 763	// adjust to ignore space from left bookend padding
 764	controls_bg_area.mLeft += mLeftBookend->getRect().getWidth() - space;
 765	
 766	// ignore space from right bookend padding
 767	controls_bg_area.mRight -= mRightBookend->getRect().getWidth() - space - 2;
 768		
 769	// draw control background UI image
 770	mBackgroundImage->draw( controls_bg_area, UI_VERTEX_COLOR % alpha);
 771	
 772	// draw volume slider background UI image
 773	if (mVolumeSliderCtrl->getVisible())
 774	{
 775		LLRect volume_slider_rect;
 776		screenRectToLocal(mVolumeSliderCtrl->calcScreenRect(), &volume_slider_rect);
 777		mVolumeSliderBackgroundImage->draw(volume_slider_rect, UI_VERTEX_COLOR % alpha);
 778	}
 779	
 780	{
 781		LLViewDrawContext context(alpha);
 782		LLPanel::draw();
 783	}
 784}
 785
 786BOOL LLPanelPrimMediaControls::handleScrollWheel(S32 x, S32 y, S32 clicks)
 787{
 788	mInactivityTimer.start();
 789	return LLViewerMediaFocus::getInstance()->handleScrollWheel(x, y, clicks);
 790}
 791
 792BOOL LLPanelPrimMediaControls::handleMouseDown(S32 x, S32 y, MASK mask)
 793{
 794	mInactivityTimer.start();
 795	return LLPanel::handleMouseDown(x, y, mask);
 796}
 797
 798BOOL LLPanelPrimMediaControls::handleMouseUp(S32 x, S32 y, MASK mask)
 799{
 800	mInactivityTimer.start();
 801	return LLPanel::handleMouseUp(x, y, mask);
 802}
 803
 804BOOL LLPanelPrimMediaControls::handleKeyHere( KEY key, MASK mask )
 805{
 806	mInactivityTimer.start();
 807	return LLPanel::handleKeyHere(key, mask);
 808}
 809
 810bool LLPanelPrimMediaControls::isMouseOver()
 811{
 812	bool result = false;
 813	
 814	if( getVisible() )
 815	{
 816		LLCoordWindow cursor_pos_window;
 817		LLCoordScreen cursor_pos_screen;
 818		LLCoordGL cursor_pos_gl;
 819		S32 x, y;
 820		getWindow()->getCursorPosition(&cursor_pos_window);
 821		getWindow()->convertCoords(cursor_pos_window, &cursor_pos_gl);
 822				
 823		if(mMediaControlsStack->getVisible())
 824		{
 825			mMediaControlsStack->screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &x, &y);
 826
 827			LLView *hit_child = mMediaControlsStack->childFromPoint(x, y);
 828			if(hit_child && hit_child->getVisible())
 829			{
 830				// This was useful for debugging both coordinate translation and view hieararchy problems...
 831				// llinfos << "mouse coords: " << x << ", " << y << " hit child " << hit_child->getName() << llendl;
 832
 833				// This will be a direct child of the LLLayoutStack, which should be a layout_panel.
 834				// These may not shown/hidden by the logic in updateShape(), so we need to do another hit test on the children of the layout panel,
 835				// which are the actual controls.
 836				hit_child->screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, &x, &y);
 837				
 838				LLView *hit_child_2 = hit_child->childFromPoint(x, y);
 839				if(hit_child_2 && hit_child_2->getVisible())
 840				{
 841					// This was useful for debugging both coordinate translation and view hieararchy problems...
 842					// llinfos << "    mouse coords: " << x << ", " << y << " hit child 2 " << hit_child_2->getName() << llendl;
 843					result = true;
 844				}
 845			}
 846		}
 847	}
 848
 849	return result;
 850}
 851
 852
 853void LLPanelPrimMediaControls::onClickClose()
 854{
 855	close();
 856}
 857
 858void LLPanelPrimMediaControls::close()
 859{
 860	resetZoomLevel(true);
 861	LLViewerMediaFocus::getInstance()->clearFocus();
 862	setVisible(FALSE);
 863}
 864
 865
 866void LLPanelPrimMediaControls::onClickBack()
 867{
 868	focusOnTarget();
 869
 870	LLViewerMediaImpl* impl =getTargetMediaImpl();
 871	
 872	if (impl)
 873	{
 874		impl->navigateBack();
 875	}
 876}
 877
 878void LLPanelPrimMediaControls::onClickForward()
 879{
 880	focusOnTarget();
 881
 882	LLViewerMediaImpl* impl = getTargetMediaImpl();
 883
 884	if (impl)
 885	{
 886		impl->navigateForward();
 887	}
 888}
 889
 890void LLPanelPrimMediaControls::onClickHome()
 891{
 892	focusOnTarget();
 893
 894	LLViewerMediaImpl* impl = getTargetMediaImpl();
 895
 896	if(impl)
 897	{
 898		impl->navigateHome();
 899	}
 900}
 901
 902void LLPanelPrimMediaControls::onClickOpen()
 903{
 904	LLViewerMediaImpl* impl = getTargetMediaImpl();
 905	if(impl)
 906	{
 907		LLWeb::loadURL(impl->getCurrentMediaURL());
 908	}	
 909}
 910
 911void LLPanelPrimMediaControls::onClickReload()
 912{
 913	focusOnTarget();
 914
 915	//LLViewerMedia::navigateHome();
 916	LLViewerMediaImpl* impl = getTargetMediaImpl();
 917
 918	if(impl)
 919	{
 920		impl->navigateReload();
 921	}
 922}
 923
 924void LLPanelPrimMediaControls::onClickPlay()
 925{
 926	focusOnTarget();
 927
 928	LLViewerMediaImpl* impl = getTargetMediaImpl();
 929
 930	if(impl)
 931	{
 932		impl->play();
 933	}
 934}
 935
 936void LLPanelPrimMediaControls::onClickPause()
 937{
 938	focusOnTarget();
 939
 940	LLViewerMediaImpl* impl = getTargetMediaImpl();
 941
 942	if(impl)
 943	{
 944		impl->pause();
 945	}
 946}
 947
 948void LLPanelPrimMediaControls::onClickStop()
 949{
 950	focusOnTarget();
 951
 952	LLViewerMediaImpl* impl = getTargetMediaImpl();
 953
 954	if(impl)
 955	{
 956		impl->navigateStop();
 957	}
 958}
 959
 960void LLPanelPrimMediaControls::onClickMediaStop()
 961{
 962	focusOnTarget();
 963
 964	LLViewerMediaImpl* impl = getTargetMediaImpl();
 965
 966	if(impl)
 967	{
 968		impl->stop();
 969	}
 970}
 971
 972void LLPanelPrimMediaControls::onClickSkipBack()
 973{
 974	focusOnTarget();
 975
 976	LLViewerMediaImpl* impl =getTargetMediaImpl();
 977	
 978	if (impl)
 979	{
 980		impl->skipBack(mSkipStep);
 981	}
 982}
 983
 984void LLPanelPrimMediaControls::onClickSkipForward()
 985{
 986	focusOnTarget();
 987
 988	LLViewerMediaImpl* impl = getTargetMediaImpl();
 989
 990	if (impl)
 991	{
 992		impl->skipForward(mSkipStep);
 993	}
 994}
 995
 996void LLPanelPrimMediaControls::onClickZoom()
 997{
 998	focusOnTarget();
 999	
1000	if(mCurrentZoom == ZOOM_NONE)
1001	{
1002		nextZoomLevel();
1003	}
1004}
1005
1006void LLPanelPrimMediaControls::nextZoomLevel()
1007{
1008	LLViewerObject* objectp = getTargetObject();
1009	if(objectp && objectp->isHUDAttachment())
1010	{
1011		// Never allow zooming on HUD attachments.
1012		return;
1013	}
1014	
1015	int index = 0;
1016	while (index < kNumZoomLevels)
1017	{
1018		if (kZoomLevels[index] == mCurrentZoom) 
1019		{
1020			index++;
1021			break;
1022		}
1023		index++;
1024	}
1025	mCurrentZoom = kZoomLevels[index % kNumZoomLevels];
1026	updateZoom();
1027}
1028
1029void LLPanelPrimMediaControls::resetZoomLevel(bool reset_camera)
1030{
1031	if(mCurrentZoom != ZOOM_NONE)
1032	{
1033		mCurrentZoom = ZOOM_NONE;
1034		if(reset_camera)
1035		{
1036			updateZoom();
1037		}
1038	}
1039}
1040
1041void LLPanelPrimMediaControls::updateZoom()
1042{
1043	F32 zoom_padding = 0.0f;
1044	switch (mCurrentZoom)
1045	{
1046	case ZOOM_NONE:
1047		{
1048			gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
1049			break;
1050		}
1051	case ZOOM_FAR:
1052		{
1053			zoom_padding = mZoomFarPadding;
1054			break;
1055		}
1056	case ZOOM_MEDIUM:
1057		{
1058			zoom_padding = mZoomMediumPadding;
1059			break;
1060		}
1061	case ZOOM_NEAR:
1062		{
1063			zoom_padding = mZoomNearPadding;
1064			break;
1065		}
1066	default:
1067		{
1068			gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
1069			break;
1070		}
1071	}
1072
1073	if (zoom_padding > 0.0f)
1074	{	
1075		// since we only zoom into medium for now, always set zoom_in constraint to true
1076		LLViewerMediaFocus::setCameraZoom(getTargetObject(), mTargetObjectNormal, zoom_padding, true);
1077	}
1078	
1079	// Remember the object ID/face we zoomed into, so we can update the zoom icon appropriately
1080	mZoomObjectID = mTargetObjectID;
1081	mZoomObjectFace = mTargetObjectFace;
1082}
1083
1084void LLPanelPrimMediaControls::onScrollUp(void* user_data)
1085{
1086	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1087	this_panel->focusOnTarget();
1088
1089	LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
1090	
1091	if(impl)
1092	{
1093		impl->scrollWheel(0, -1, MASK_NONE);
1094	}
1095}
1096void LLPanelPrimMediaControls::onScrollUpHeld(void* user_data)
1097{
1098	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1099	this_panel->mScrollState = SCROLL_UP;
1100}
1101void LLPanelPrimMediaControls::onScrollRight(void* user_data)
1102{
1103	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1104	this_panel->focusOnTarget();
1105
1106	LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
1107
1108	if(impl)
1109	{
1110		impl->scrollWheel(-1, 0, MASK_NONE);
1111//		impl->handleKeyHere(KEY_RIGHT, MASK_NONE);
1112	}
1113}
1114void LLPanelPrimMediaControls::onScrollRightHeld(void* user_data)
1115{
1116	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1117	this_panel->mScrollState = SCROLL_RIGHT;
1118}
1119
1120void LLPanelPrimMediaControls::onScrollLeft(void* user_data)
1121{
1122	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1123	this_panel->focusOnTarget();
1124
1125	LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
1126
1127	if(impl)
1128	{
1129		impl->scrollWheel(1, 0, MASK_NONE);
1130//		impl->handleKeyHere(KEY_LEFT, MASK_NONE);
1131	}
1132}
1133void LLPanelPrimMediaControls::onScrollLeftHeld(void* user_data)
1134{
1135	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1136	this_panel->mScrollState = SCROLL_LEFT;
1137}
1138
1139void LLPanelPrimMediaControls::onScrollDown(void* user_data)
1140{
1141	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1142	this_panel->focusOnTarget();
1143
1144	LLViewerMediaImpl* impl = this_panel->getTargetMediaImpl();
1145	
1146	if(impl)
1147	{
1148		impl->scrollWheel(0, 1, MASK_NONE);
1149	}
1150}
1151void LLPanelPrimMediaControls::onScrollDownHeld(void* user_data)
1152{
1153	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1154	this_panel->mScrollState = SCROLL_DOWN;
1155}
1156
1157void LLPanelPrimMediaControls::onScrollStop(void* user_data)
1158{
1159	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (user_data);
1160	this_panel->mScrollState = SCROLL_NONE;
1161}
1162
1163void LLPanelPrimMediaControls::onCommitURL()
1164{
1165	focusOnTarget();
1166
1167	std::string url = mMediaAddress->getValue().asString();
1168	if(getTargetMediaImpl() && !url.empty())
1169	{
1170		getTargetMediaImpl()->navigateTo( url, "", true);
1171
1172		// Make sure keyboard focus is set to the media focus object.
1173		gFocusMgr.setKeyboardFocus(LLViewerMediaFocus::getInstance());
1174			
1175	}
1176	mPauseFadeout = false;
1177	mFadeTimer.start();
1178}
1179
1180
1181void LLPanelPrimMediaControls::onInputURL(LLFocusableElement* caller, void *userdata)
1182{
1183
1184	LLPanelPrimMediaControls* this_panel = static_cast<LLPanelPrimMediaControls*> (userdata);
1185	this_panel->focusOnTarget();
1186
1187	this_panel->mPauseFadeout = true;
1188	this_panel->mFadeTimer.stop();
1189	this_panel->mFadeTimer.reset();
1190	
1191}
1192
1193void LLPanelPrimMediaControls::setCurrentURL()
1194{	
1195#ifdef USE_COMBO_BOX_FOR_MEDIA_URL
1196//	LLComboBox* media_address_combo	= getChild<LLComboBox>("media_address_combo");
1197//	// redirects will navigate momentarily to about:blank, don't add to history
1198//	if (media_address_combo && mCurrentURL != "about:blank")
1199//	{
1200//		media_address_combo->remove(mCurrentURL);
1201//		media_address_combo->add(mCurrentURL);
1202//		media_address_combo->selectByValue(mCurrentURL);
1203//	}
1204#else   // USE_COMBO_BOX_FOR_MEDIA_URL
1205	if (mMediaAddress && mCurrentURL != "about:blank")
1206	{
1207		mMediaAddress->setValue(mCurrentURL);
1208	}
1209#endif	// USE_COMBO_BOX_FOR_MEDIA_URL
1210}
1211
1212void LLPanelPrimMediaControls::onCommitSlider()
1213{
1214	focusOnTarget();
1215
1216	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
1217	if (media_impl) 
1218	{
1219		// get slider value
1220		F64 slider_value = mMediaPlaySliderCtrl->getValue().asReal();
1221		if(slider_value <= 0.0)
1222		{	
1223			media_impl->stop();
1224		}
1225		else 
1226		{
1227			media_impl->seek(slider_value*mMovieDuration);
1228			//mUpdateSlider= false;
1229		}
1230	}
1231}		
1232
1233void LLPanelPrimMediaControls::onCommitVolumeUp()
1234{
1235	focusOnTarget();
1236
1237	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
1238	if (media_impl) 
1239	{
1240		F32 volume = media_impl->getVolume();
1241		
1242		volume += 0.1f;
1243		if(volume >= 1.0f)
1244		{
1245			volume = 1.0f;
1246		}
1247		
1248		media_impl->setVolume(volume);
1249		mMuteBtn->setToggleState(false);
1250	}
1251}		
1252
1253void LLPanelPrimMediaControls::onCommitVolumeDown()
1254{
1255	focusOnTarget();
1256
1257	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
1258	if (media_impl) 
1259	{
1260		F32 volume = media_impl->getVolume();
1261		
1262		volume -= 0.1f;
1263		if(volume <= 0.0f)
1264		{
1265			volume = 0.0f;
1266		}
1267
1268		media_impl->setVolume(volume);
1269		mMuteBtn->setToggleState(false);
1270	}
1271}		
1272
1273void LLPanelPrimMediaControls::onCommitVolumeSlider()
1274{
1275	focusOnTarget();
1276
1277	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
1278	if (media_impl) 
1279	{
1280		media_impl->setVolume(mVolumeSliderCtrl->getValueF32());
1281	}
1282}
1283
1284void LLPanelPrimMediaControls::onToggleMute()
1285{
1286	focusOnTarget();
1287
1288	LLViewerMediaImpl* media_impl = getTargetMediaImpl();
1289	if (media_impl) 
1290	{
1291		F32 volume = media_impl->getVolume();
1292		
1293		if(volume > 0.0)
1294		{
1295			media_impl->setVolume(0.0);
1296		}
1297		else if (mVolumeSliderCtrl->getValueF32() == 0.0)
1298		{
1299			media_impl->setVolume(1.0);
1300			mVolumeSliderCtrl->setValue(1.0);
1301		}
1302		else 
1303		{
1304			media_impl->setVolume(mVolumeSliderCtrl->getValueF32());
1305		}
1306	}
1307}
1308
1309void LLPanelPrimMediaControls::showVolumeSlider()
1310{
1311	mVolumeSliderVisible++;
1312}
1313
1314void LLPanelPrimMediaControls::hideVolumeSlider()
1315{
1316	mVolumeSliderVisible--;
1317}
1318
1319bool LLPanelPrimMediaControls::shouldVolumeSliderBeVisible()
1320{
1321	return mVolumeSliderVisible > 0;
1322}
1323
1324
1325void LLPanelPrimMediaControls::clearFaceOnFade()
1326{
1327	if(mClearFaceOnFade)
1328	{
1329		// Hiding this object makes scroll events go missing after it fades out
1330		// (see DEV-41755 for a full description of the train wreck).
1331		// Only hide the controls when we're untargeting.
1332		setVisible(FALSE);
1333
1334		mClearFaceOnFade = false;
1335		mVolumeSliderVisible = 0;
1336		mTargetImplID = LLUUID::null;
1337		mTargetObjectID = LLUUID::null;
1338		mTargetObjectFace = 0;
1339	}
1340}
1341
1342void LLPanelPrimMediaControls::onMouselookModeIn()
1343{
1344	LLViewerMediaFocus::getInstance()->clearHover();
1345	mHideImmediately = true;
1346}
1347
1348void LLPanelPrimMediaControls::showNotification(LLNotificationPtr notify)
1349{
1350	delete mWindowShade;
1351	LLWindowShade::Params params;
1352	params.rect = mMediaRegion->getLocalRect();
1353	params.follows.flags = FOLLOWS_ALL;
1354
1355	//HACK: don't hardcode this
1356	if (notify->getIcon() == "Popup_Caution")
1357	{
1358		params.bg_image.name = "Yellow_Gradient";
1359		params.text_color = LLColor4::black;
1360	}
1361	else
1362	{
1363		//HACK: make this a property of the notification itself, "cancellable"
1364		params.can_close = false;
1365		params.text_color.control = "LabelTextColor";
1366	}
1367
1368	mWindowShade = LLUICtrlFactory::create<LLWindowShade>(params);
1369
1370	mMediaRegion->addChild(mWindowShade);
1371	mWindowShade->show(notify);
1372}
1373
1374void LLPanelPrimMediaControls::hideNotification()
1375{
1376	if (mWindowShade)
1377	{
1378		mWindowShade->hide();
1379	}
1380}