2010-08-20 16:24:40 -07:00
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim : sw = 2 ts = 8 et :
*/
2012-05-21 04:12:37 -07:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/. */
2010-08-20 16:24:40 -07:00
2012-07-17 16:59:45 -07:00
# include "base/basictypes.h"
2010-08-20 16:24:40 -07:00
# include "BasicLayers.h"
2012-07-17 16:59:45 -07:00
# include "gfxPlatform.h"
2011-08-09 12:38:27 -07:00
# if defined(MOZ_ENABLE_D3D10_LAYER)
# include "LayerManagerD3D10.h"
# endif
2012-07-17 16:59:45 -07:00
# include "mozilla/dom/TabChild.h"
2012-05-08 14:36:07 -07:00
# include "mozilla/Hal.h"
2012-07-17 16:59:45 -07:00
# include "mozilla/layers/CompositorChild.h"
# include "mozilla/layers/PLayersChild.h"
2010-08-20 16:24:40 -07:00
# include "PuppetWidget.h"
2012-08-15 11:52:42 -07:00
# include "nsIWidgetListener.h"
2010-08-20 16:24:40 -07:00
2012-05-08 14:36:07 -07:00
using namespace mozilla : : dom ;
using namespace mozilla : : hal ;
2010-08-20 16:24:40 -07:00
using namespace mozilla : : layers ;
using namespace mozilla : : widget ;
static void
InvalidateRegion ( nsIWidget * aWidget , const nsIntRegion & aRegion )
{
nsIntRegionRectIterator it ( aRegion ) ;
while ( const nsIntRect * r = it . Next ( ) ) {
2011-12-23 19:52:21 -08:00
aWidget - > Invalidate ( * r ) ;
2010-08-20 16:24:40 -07:00
}
}
/*static*/ already_AddRefed < nsIWidget >
2012-07-17 16:59:45 -07:00
nsIWidget : : CreatePuppetWidget ( TabChild * aTabChild )
2010-08-20 16:24:40 -07:00
{
2013-04-04 07:58:33 -07:00
NS_ABORT_IF_FALSE ( nsIWidget : : UsePuppetWidgets ( ) ,
2010-08-20 16:24:40 -07:00
" PuppetWidgets not allowed in this configuration " ) ;
2010-09-23 20:28:15 -07:00
nsCOMPtr < nsIWidget > widget = new PuppetWidget ( aTabChild ) ;
2010-08-20 16:24:40 -07:00
return widget . forget ( ) ;
}
namespace mozilla {
namespace widget {
2011-02-23 09:45:09 -08:00
static bool
IsPopup ( const nsWidgetInitData * aInitData )
{
return aInitData & & aInitData - > mWindowType = = eWindowType_popup ;
}
static bool
MightNeedIMEFocus ( const nsWidgetInitData * aInitData )
{
// In the puppet-widget world, popup widgets are just dummies and
// shouldn't try to mess with IME state.
2013-01-28 15:56:28 -08:00
# ifdef MOZ_CROSS_PROCESS_IME
2011-02-23 09:45:09 -08:00
return ! IsPopup ( aInitData ) ;
2013-01-28 15:56:28 -08:00
# else
return false ;
# endif
2011-02-23 09:45:09 -08:00
}
2010-08-20 16:24:40 -07:00
// Arbitrary, fungible.
const size_t PuppetWidget : : kMaxDimension = 4000 ;
NS_IMPL_ISUPPORTS_INHERITED1 ( PuppetWidget , nsBaseWidget ,
nsISupportsWeakReference )
2012-07-17 16:59:45 -07:00
PuppetWidget : : PuppetWidget ( TabChild * aTabChild )
2010-09-23 20:28:15 -07:00
: mTabChild ( aTabChild )
2010-12-02 17:24:04 -08:00
, mDPI ( - 1 )
2010-08-20 16:24:40 -07:00
{
MOZ_COUNT_CTOR ( PuppetWidget ) ;
}
PuppetWidget : : ~ PuppetWidget ( )
{
MOZ_COUNT_DTOR ( PuppetWidget ) ;
}
NS_IMETHODIMP
PuppetWidget : : Create ( nsIWidget * aParent ,
nsNativeWidget aNativeParent ,
const nsIntRect & aRect ,
2011-04-16 18:22:44 -07:00
nsDeviceContext * aContext ,
2010-08-20 16:24:40 -07:00
nsWidgetInitData * aInitData )
{
NS_ABORT_IF_FALSE ( ! aNativeParent , " got a non-Puppet native parent " ) ;
2012-08-15 11:53:09 -07:00
BaseCreate ( nullptr , aRect , aContext , aInitData ) ;
2010-08-20 16:24:40 -07:00
mBounds = aRect ;
2011-10-17 07:59:28 -07:00
mEnabled = true ;
mVisible = true ;
2010-08-20 16:24:40 -07:00
mSurface = gfxPlatform : : GetPlatform ( )
- > CreateOffscreenSurface ( gfxIntSize ( 1 , 1 ) ,
2010-09-16 14:34:53 -07:00
gfxASurface : : ContentFromFormat ( gfxASurface : : ImageFormatARGB32 ) ) ;
2010-08-20 16:24:40 -07:00
2011-10-17 07:59:28 -07:00
mIMEComposing = false ;
2012-08-29 08:26:18 -07:00
mNeedIMEStateInit = MightNeedIMEFocus ( aInitData ) ;
2010-09-23 20:28:15 -07:00
2010-08-20 16:24:40 -07:00
PuppetWidget * parent = static_cast < PuppetWidget * > ( aParent ) ;
if ( parent ) {
parent - > SetChild ( this ) ;
2010-08-20 16:24:41 -07:00
mLayerManager = parent - > GetLayerManager ( ) ;
2010-08-20 16:24:40 -07:00
}
else {
2011-10-17 07:59:28 -07:00
Resize ( mBounds . x , mBounds . y , mBounds . width , mBounds . height , false ) ;
2010-08-20 16:24:40 -07:00
}
return NS_OK ;
}
2012-08-29 08:26:18 -07:00
void
PuppetWidget : : InitIMEState ( )
{
if ( mNeedIMEStateInit ) {
uint32_t chromeSeqno ;
2013-04-02 11:32:59 -07:00
if ( mTabChild ) {
mTabChild - > SendNotifyIMEFocus ( false , & mIMEPreference , & chromeSeqno ) ;
}
2012-08-29 08:26:18 -07:00
mIMELastBlurSeqno = mIMELastReceivedSeqno = chromeSeqno ;
mNeedIMEStateInit = false ;
}
}
2010-08-20 16:24:40 -07:00
already_AddRefed < nsIWidget >
PuppetWidget : : CreateChild ( const nsIntRect & aRect ,
2011-04-16 18:22:44 -07:00
nsDeviceContext * aContext ,
2010-08-20 16:24:40 -07:00
nsWidgetInitData * aInitData ,
2011-09-28 23:19:26 -07:00
bool aForceUseIWidgetParent )
2010-08-20 16:24:40 -07:00
{
2011-02-23 09:45:09 -08:00
bool isPopup = IsPopup ( aInitData ) ;
2010-09-23 20:28:15 -07:00
nsCOMPtr < nsIWidget > widget = nsIWidget : : CreatePuppetWidget ( mTabChild ) ;
2010-08-20 16:24:40 -07:00
return ( ( widget & &
2012-07-30 07:20:58 -07:00
NS_SUCCEEDED ( widget - > Create ( isPopup ? nullptr : this , nullptr , aRect ,
2011-10-25 08:05:32 -07:00
aContext , aInitData ) ) ) ?
2012-07-30 07:20:58 -07:00
widget . forget ( ) : nullptr ) ;
2010-08-20 16:24:40 -07:00
}
2010-08-20 16:24:40 -07:00
NS_IMETHODIMP
PuppetWidget : : Destroy ( )
{
2011-03-29 13:14:44 -07:00
Base : : OnDestroy ( ) ;
2010-08-20 16:24:40 -07:00
Base : : Destroy ( ) ;
mPaintTask . Revoke ( ) ;
2012-07-30 07:20:58 -07:00
mChild = nullptr ;
2010-12-06 18:05:25 -08:00
if ( mLayerManager ) {
mLayerManager - > Destroy ( ) ;
}
2012-07-30 07:20:58 -07:00
mLayerManager = nullptr ;
mTabChild = nullptr ;
2010-08-20 16:24:40 -07:00
return NS_OK ;
}
2010-08-20 16:24:40 -07:00
NS_IMETHODIMP
2011-09-28 23:19:26 -07:00
PuppetWidget : : Show ( bool aState )
2010-08-20 16:24:40 -07:00
{
NS_ASSERTION ( mEnabled ,
" does it make sense to Show()/Hide() a disabled widget? " ) ;
2011-09-28 23:19:26 -07:00
bool wasVisible = mVisible ;
2010-08-20 16:24:40 -07:00
mVisible = aState ;
2012-11-07 19:51:55 -08:00
if ( mChild ) {
mChild - > mVisible = aState ;
}
if ( ! mVisible & & mLayerManager ) {
mLayerManager - > ClearCachedResources ( ) ;
}
2010-08-20 16:24:40 -07:00
if ( ! wasVisible & & mVisible ) {
2011-10-17 07:59:28 -07:00
Resize ( mBounds . width , mBounds . height , false ) ;
2012-11-07 19:51:55 -08:00
Invalidate ( mBounds ) ;
2010-08-20 16:24:40 -07:00
}
return NS_OK ;
}
NS_IMETHODIMP
2012-12-12 01:57:38 -08:00
PuppetWidget : : Resize ( double aWidth ,
double aHeight ,
bool aRepaint )
2010-08-20 16:24:40 -07:00
{
nsIntRect oldBounds = mBounds ;
2012-12-12 01:57:38 -08:00
mBounds . SizeTo ( nsIntSize ( NSToIntRound ( aWidth ) , NSToIntRound ( aHeight ) ) ) ;
2010-08-20 16:24:40 -07:00
if ( mChild ) {
return mChild - > Resize ( aWidth , aHeight , aRepaint ) ;
}
// XXX: roc says that |aRepaint| dictates whether or not to
// invalidate the expanded area
if ( oldBounds . Size ( ) < mBounds . Size ( ) & & aRepaint ) {
nsIntRegion dirty ( mBounds ) ;
dirty . Sub ( dirty , oldBounds ) ;
InvalidateRegion ( this , dirty ) ;
}
2012-08-15 11:53:14 -07:00
if ( ! oldBounds . IsEqualEdges ( mBounds ) & & mAttachedWidgetListener ) {
mAttachedWidgetListener - > WindowResized ( this , mBounds . width , mBounds . height ) ;
2010-08-20 16:24:40 -07:00
}
return NS_OK ;
}
NS_IMETHODIMP
2011-09-28 23:19:26 -07:00
PuppetWidget : : SetFocus ( bool aRaise )
2010-08-20 16:24:40 -07:00
{
// XXX/cjones: someone who knows about event handling needs to
// decide how this should work.
return NS_OK ;
}
NS_IMETHODIMP
2011-12-23 19:52:21 -08:00
PuppetWidget : : Invalidate ( const nsIntRect & aRect )
2010-08-20 16:24:40 -07:00
{
# ifdef DEBUG
2011-12-23 19:52:21 -08:00
debug_DumpInvalidate ( stderr , this , & aRect ,
2012-09-01 19:35:17 -07:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-20 16:24:40 -07:00
# endif
if ( mChild ) {
2011-12-23 19:52:21 -08:00
return mChild - > Invalidate ( aRect ) ;
2010-08-20 16:24:40 -07:00
}
mDirtyRegion . Or ( mDirtyRegion , aRect ) ;
2011-12-23 19:52:21 -08:00
if ( ! mDirtyRegion . IsEmpty ( ) & & ! mPaintTask . IsPending ( ) ) {
2010-08-20 16:24:40 -07:00
mPaintTask = new PaintTask ( this ) ;
return NS_DispatchToCurrentThread ( mPaintTask . get ( ) ) ;
}
return NS_OK ;
}
2010-09-23 20:28:15 -07:00
void
PuppetWidget : : InitEvent ( nsGUIEvent & event , nsIntPoint * aPoint )
{
2012-07-30 07:20:58 -07:00
if ( nullptr = = aPoint ) {
2010-09-23 20:28:15 -07:00
event . refPoint . x = 0 ;
event . refPoint . y = 0 ;
}
else {
// use the point override if provided
event . refPoint . x = aPoint - > x ;
event . refPoint . y = aPoint - > y ;
}
event . time = PR_Now ( ) / 1000 ;
}
2010-08-20 16:24:40 -07:00
NS_IMETHODIMP
PuppetWidget : : DispatchEvent ( nsGUIEvent * event , nsEventStatus & aStatus )
{
# ifdef DEBUG
debug_DumpEvent ( stdout , event - > widget , event ,
2012-09-01 19:35:17 -07:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-20 16:24:40 -07:00
# endif
2011-02-09 12:13:18 -08:00
NS_ABORT_IF_FALSE ( ! mChild | | mChild - > mWindowType = = eWindowType_popup ,
" Unexpected event dispatch! " ) ;
2010-08-20 16:24:40 -07:00
aStatus = nsEventStatus_eIgnore ;
2011-02-09 12:13:18 -08:00
if ( event - > message = = NS_COMPOSITION_START ) {
2011-10-17 07:59:28 -07:00
mIMEComposing = true ;
2011-02-09 12:13:18 -08:00
}
switch ( event - > eventStructType ) {
case NS_COMPOSITION_EVENT :
mIMELastReceivedSeqno = static_cast < nsCompositionEvent * > ( event ) - > seqno ;
if ( mIMELastReceivedSeqno < mIMELastBlurSeqno )
return NS_OK ;
break ;
case NS_TEXT_EVENT :
mIMELastReceivedSeqno = static_cast < nsTextEvent * > ( event ) - > seqno ;
if ( mIMELastReceivedSeqno < mIMELastBlurSeqno )
return NS_OK ;
break ;
case NS_SELECTION_EVENT :
mIMELastReceivedSeqno = static_cast < nsSelectionEvent * > ( event ) - > seqno ;
if ( mIMELastReceivedSeqno < mIMELastBlurSeqno )
return NS_OK ;
break ;
2012-11-19 22:05:56 -08:00
default :
break ;
2011-02-09 12:13:18 -08:00
}
2012-08-15 11:53:09 -07:00
2013-01-25 11:51:16 -08:00
if ( mAttachedWidgetListener ) {
aStatus = mAttachedWidgetListener - > HandleEvent ( event , mUseAttachedEvents ) ;
}
2011-02-09 12:13:18 -08:00
if ( event - > message = = NS_COMPOSITION_END ) {
2011-10-17 07:59:28 -07:00
mIMEComposing = false ;
2010-08-20 16:24:40 -07:00
}
return NS_OK ;
}
LayerManager *
2011-08-09 12:38:26 -07:00
PuppetWidget : : GetLayerManager ( PLayersChild * aShadowManager ,
LayersBackend aBackendHint ,
LayerManagerPersistence aPersistence ,
bool * aAllowRetaining )
2010-08-20 16:24:40 -07:00
{
if ( ! mLayerManager ) {
2011-08-09 12:38:27 -07:00
// The backend hint is a temporary placeholder until Azure, when
// all content-process layer managers will be BasicLayerManagers.
# if defined(MOZ_ENABLE_D3D10_LAYER)
2012-07-18 09:31:40 -07:00
if ( mozilla : : layers : : LAYERS_D3D10 = = aBackendHint ) {
2011-08-09 12:38:27 -07:00
nsRefPtr < LayerManagerD3D10 > m = new LayerManagerD3D10 ( this ) ;
m - > AsShadowForwarder ( ) - > SetShadowManager ( aShadowManager ) ;
if ( m - > Initialize ( ) ) {
mLayerManager = m ;
}
}
# endif
if ( ! mLayerManager ) {
mLayerManager = new BasicShadowLayerManager ( this ) ;
mLayerManager - > AsShadowForwarder ( ) - > SetShadowManager ( aShadowManager ) ;
}
2010-08-20 16:24:40 -07:00
}
2010-10-15 03:34:29 -07:00
if ( aAllowRetaining ) {
* aAllowRetaining = true ;
}
2010-08-20 16:24:40 -07:00
return mLayerManager ;
}
gfxASurface *
PuppetWidget : : GetThebesSurface ( )
{
return mSurface ;
}
2010-09-23 20:28:15 -07:00
nsresult
2011-09-28 23:19:26 -07:00
PuppetWidget : : IMEEndComposition ( bool aCancel )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-23 20:28:15 -07:00
nsEventStatus status ;
2011-10-17 07:59:28 -07:00
nsTextEvent textEvent ( true , NS_TEXT_TEXT , this ) ;
2012-07-30 07:20:58 -07:00
InitEvent ( textEvent , nullptr ) ;
2011-02-23 08:21:07 -08:00
textEvent . seqno = mIMELastReceivedSeqno ;
2010-12-15 11:22:15 -08:00
// SendEndIMEComposition is always called since ResetInputState
// should always be called even if we aren't composing something.
2010-09-23 20:28:15 -07:00
if ( ! mTabChild | |
! mTabChild - > SendEndIMEComposition ( aCancel , & textEvent . theText ) ) {
return NS_ERROR_FAILURE ;
}
2010-12-15 11:22:15 -08:00
if ( ! mIMEComposing )
return NS_OK ;
2010-09-23 20:28:15 -07:00
DispatchEvent ( & textEvent , status ) ;
2011-10-17 07:59:28 -07:00
nsCompositionEvent compEvent ( true , NS_COMPOSITION_END , this ) ;
2012-07-30 07:20:58 -07:00
InitEvent ( compEvent , nullptr ) ;
2011-02-23 08:21:07 -08:00
compEvent . seqno = mIMELastReceivedSeqno ;
2010-09-23 20:28:15 -07:00
DispatchEvent ( & compEvent , status ) ;
return NS_OK ;
}
NS_IMETHODIMP
2013-03-05 22:14:31 -08:00
PuppetWidget : : NotifyIME ( NotificationToIME aNotification )
2010-09-23 20:28:15 -07:00
{
2013-03-05 22:14:31 -08:00
switch ( aNotification ) {
case NOTIFY_IME_OF_CURSOR_POS_CHANGED :
case REQUEST_TO_COMMIT_COMPOSITION :
return IMEEndComposition ( false ) ;
case REQUEST_TO_CANCEL_COMPOSITION :
return IMEEndComposition ( true ) ;
case NOTIFY_IME_OF_FOCUS :
return NotifyIMEOfFocusChange ( true ) ;
case NOTIFY_IME_OF_BLUR :
return NotifyIMEOfFocusChange ( false ) ;
case NOTIFY_IME_OF_SELECTION_CHANGE :
return NotifyIMEOfSelectionChange ( ) ;
default :
return NS_ERROR_NOT_IMPLEMENTED ;
}
2010-09-23 20:28:15 -07:00
}
2011-11-27 03:51:52 -08:00
NS_IMETHODIMP_ ( void )
PuppetWidget : : SetInputContext ( const InputContext & aContext ,
const InputContextAction & aAction )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return ;
# endif
2011-11-27 03:51:52 -08:00
if ( ! mTabChild ) {
return ;
}
2011-11-27 03:51:53 -08:00
mTabChild - > SendSetInputContext (
2012-08-22 08:56:38 -07:00
static_cast < int32_t > ( aContext . mIMEState . mEnabled ) ,
static_cast < int32_t > ( aContext . mIMEState . mOpen ) ,
2011-11-27 03:51:53 -08:00
aContext . mHTMLInputType ,
2012-08-26 19:16:22 -07:00
aContext . mHTMLInputInputmode ,
2011-11-27 03:51:53 -08:00
aContext . mActionHint ,
2012-08-22 08:56:38 -07:00
static_cast < int32_t > ( aAction . mCause ) ,
static_cast < int32_t > ( aAction . mFocusChange ) ) ;
2010-09-23 20:28:15 -07:00
}
2011-11-27 03:51:52 -08:00
NS_IMETHODIMP_ ( InputContext )
PuppetWidget : : GetInputContext ( )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return InputContext ( ) ;
# endif
2011-11-27 03:51:52 -08:00
InputContext context ;
if ( mTabChild ) {
2012-08-22 08:56:38 -07:00
int32_t enabled , open ;
2012-10-29 18:58:29 -07:00
intptr_t nativeIMEContext ;
2012-10-26 16:35:20 -07:00
mTabChild - > SendGetInputContext ( & enabled , & open , & nativeIMEContext ) ;
2011-11-27 03:51:53 -08:00
context . mIMEState . mEnabled = static_cast < IMEState : : Enabled > ( enabled ) ;
context . mIMEState . mOpen = static_cast < IMEState : : Open > ( open ) ;
2012-10-26 16:35:20 -07:00
context . mNativeIMEContext = reinterpret_cast < void * > ( nativeIMEContext ) ;
2011-11-27 03:51:52 -08:00
}
return context ;
2010-09-23 20:28:15 -07:00
}
2013-03-05 22:14:31 -08:00
nsresult
PuppetWidget : : NotifyIMEOfFocusChange ( bool aFocus )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-23 20:28:15 -07:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
if ( aFocus ) {
nsEventStatus status ;
2011-10-17 07:59:28 -07:00
nsQueryContentEvent queryEvent ( true , NS_QUERY_TEXT_CONTENT , this ) ;
2012-07-30 07:20:58 -07:00
InitEvent ( queryEvent , nullptr ) ;
2010-09-23 20:28:15 -07:00
// Query entire content
2012-09-27 23:57:33 -07:00
queryEvent . InitForQueryTextContent ( 0 , UINT32_MAX ) ;
2010-09-23 20:28:15 -07:00
DispatchEvent ( & queryEvent , status ) ;
if ( queryEvent . mSucceeded ) {
mTabChild - > SendNotifyIMETextHint ( queryEvent . mReply . mString ) ;
}
2010-09-23 20:28:15 -07:00
} else {
2013-03-05 22:14:31 -08:00
// Might not have been committed composition yet
IMEEndComposition ( false ) ;
2010-09-23 20:28:15 -07:00
}
2012-08-22 08:56:38 -07:00
uint32_t chromeSeqno ;
2011-10-17 07:59:28 -07:00
mIMEPreference . mWantUpdates = false ;
mIMEPreference . mWantHints = false ;
2010-10-01 07:17:37 -07:00
if ( ! mTabChild - > SendNotifyIMEFocus ( aFocus , & mIMEPreference , & chromeSeqno ) )
2010-09-23 20:28:15 -07:00
return NS_ERROR_FAILURE ;
if ( aFocus ) {
2012-11-13 05:04:44 -08:00
if ( mIMEPreference . mWantUpdates & & mIMEPreference . mWantHints ) {
2013-03-05 22:14:31 -08:00
NotifyIMEOfSelectionChange ( ) ; // Update selection
2012-11-13 05:04:44 -08:00
}
2010-10-01 07:17:37 -07:00
} else {
mIMELastBlurSeqno = chromeSeqno ;
2010-09-23 20:28:15 -07:00
}
return NS_OK ;
}
2012-11-13 05:04:44 -08:00
nsIMEUpdatePreference
PuppetWidget : : GetIMEUpdatePreference ( )
{
return mIMEPreference ;
}
2010-09-23 20:28:15 -07:00
NS_IMETHODIMP
2013-03-05 22:14:34 -08:00
PuppetWidget : : NotifyIMEOfTextChange ( uint32_t aStart ,
uint32_t aEnd ,
uint32_t aNewEnd )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-23 20:28:15 -07:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
if ( mIMEPreference . mWantHints ) {
nsEventStatus status ;
2011-10-17 07:59:28 -07:00
nsQueryContentEvent queryEvent ( true , NS_QUERY_TEXT_CONTENT , this ) ;
2012-07-30 07:20:58 -07:00
InitEvent ( queryEvent , nullptr ) ;
2012-09-27 23:57:33 -07:00
queryEvent . InitForQueryTextContent ( 0 , UINT32_MAX ) ;
2010-09-23 20:28:15 -07:00
DispatchEvent ( & queryEvent , status ) ;
if ( queryEvent . mSucceeded ) {
mTabChild - > SendNotifyIMETextHint ( queryEvent . mReply . mString ) ;
}
}
if ( mIMEPreference . mWantUpdates ) {
mTabChild - > SendNotifyIMETextChange ( aStart , aEnd , aNewEnd ) ;
}
return NS_OK ;
}
2013-03-05 22:14:31 -08:00
nsresult
PuppetWidget : : NotifyIMEOfSelectionChange ( )
2010-09-23 20:28:15 -07:00
{
2013-01-28 15:56:28 -08:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-23 20:28:15 -07:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
if ( mIMEPreference . mWantUpdates ) {
nsEventStatus status ;
2011-10-17 07:59:28 -07:00
nsQueryContentEvent queryEvent ( true , NS_QUERY_SELECTED_TEXT , this ) ;
2012-07-30 07:20:58 -07:00
InitEvent ( queryEvent , nullptr ) ;
2010-09-23 20:28:15 -07:00
DispatchEvent ( & queryEvent , status ) ;
if ( queryEvent . mSucceeded ) {
2010-10-01 07:17:37 -07:00
mTabChild - > SendNotifyIMESelection ( mIMELastReceivedSeqno ,
queryEvent . GetSelectionStart ( ) ,
2010-09-23 20:28:15 -07:00
queryEvent . GetSelectionEnd ( ) ) ;
}
}
return NS_OK ;
}
2011-06-21 17:32:43 -07:00
NS_IMETHODIMP
PuppetWidget : : SetCursor ( nsCursor aCursor )
{
2012-09-11 21:48:13 -07:00
if ( mCursor = = aCursor ) {
return NS_OK ;
}
2013-04-02 11:32:59 -07:00
if ( mTabChild & & ! mTabChild - > SendSetCursor ( aCursor ) ) {
2011-06-21 17:32:43 -07:00
return NS_ERROR_FAILURE ;
}
2012-09-11 21:48:13 -07:00
mCursor = aCursor ;
2011-06-21 17:32:43 -07:00
return NS_OK ;
}
2010-08-20 16:24:40 -07:00
nsresult
2012-08-15 11:52:42 -07:00
PuppetWidget : : Paint ( )
2010-08-20 16:24:40 -07:00
{
NS_ABORT_IF_FALSE ( ! mDirtyRegion . IsEmpty ( ) , " paint event logic messed up " ) ;
2012-08-15 11:53:14 -07:00
if ( ! mAttachedWidgetListener )
2012-08-15 11:52:42 -07:00
return NS_OK ;
nsIntRegion region = mDirtyRegion ;
2010-08-20 16:24:40 -07:00
// reset repaint tracking
mDirtyRegion . SetEmpty ( ) ;
mPaintTask . Revoke ( ) ;
2013-01-28 11:34:08 -08:00
mAttachedWidgetListener - > WillPaintWindow ( this ) ;
2013-01-28 11:34:03 -08:00
if ( mAttachedWidgetListener ) {
2010-08-20 16:24:40 -07:00
# ifdef DEBUG
2012-08-15 11:52:42 -07:00
debug_DumpPaintEvent ( stderr , this , region ,
2012-09-01 19:35:17 -07:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-20 16:24:40 -07:00
# endif
2012-07-18 09:31:40 -07:00
if ( mozilla : : layers : : LAYERS_D3D10 = = mLayerManager - > GetBackendType ( ) ) {
2013-01-28 11:34:06 -08:00
mAttachedWidgetListener - > PaintWindow ( this , region , 0 ) ;
2011-08-09 12:38:27 -07:00
} else {
nsRefPtr < gfxContext > ctx = new gfxContext ( mSurface ) ;
2012-02-10 11:22:21 -08:00
ctx - > Rectangle ( gfxRect ( 0 , 0 , 0 , 0 ) ) ;
ctx - > Clip ( ) ;
2011-08-09 12:38:27 -07:00
AutoLayerManagerSetup setupLayerManager ( this , ctx ,
2012-07-30 17:42:26 -07:00
BUFFER_NONE ) ;
2013-01-28 11:34:06 -08:00
mAttachedWidgetListener - > PaintWindow ( this , region , 0 ) ;
2013-04-02 11:32:59 -07:00
if ( mTabChild ) {
mTabChild - > NotifyPainted ( ) ;
}
2011-08-09 12:38:27 -07:00
}
2010-08-20 16:24:40 -07:00
}
2012-12-12 13:57:08 -08:00
if ( mAttachedWidgetListener ) {
mAttachedWidgetListener - > DidPaintWindow ( ) ;
}
2010-08-20 16:24:40 -07:00
return NS_OK ;
}
void
PuppetWidget : : SetChild ( PuppetWidget * aChild )
{
NS_ABORT_IF_FALSE ( this ! = aChild , " can't parent a widget to itself " ) ;
NS_ABORT_IF_FALSE ( ! aChild - > mChild ,
" fake widget 'hierarchy' only expected to have one level " ) ;
mChild = aChild ;
}
NS_IMETHODIMP
PuppetWidget : : PaintTask : : Run ( )
{
if ( mWidget ) {
2012-08-15 11:52:42 -07:00
mWidget - > Paint ( ) ;
2010-08-20 16:24:40 -07:00
}
return NS_OK ;
}
2012-11-07 19:51:55 -08:00
bool
PuppetWidget : : NeedsPaint ( )
{
return mVisible ;
}
2010-12-02 17:24:04 -08:00
float
PuppetWidget : : GetDPI ( )
{
if ( mDPI < 0 ) {
2013-04-02 11:32:59 -07:00
if ( mTabChild ) {
mTabChild - > GetDPI ( & mDPI ) ;
} else {
mDPI = 96.0 ;
}
2010-12-02 17:24:04 -08:00
}
return mDPI ;
}
2011-08-31 12:01:38 -07:00
void *
2012-08-22 08:56:38 -07:00
PuppetWidget : : GetNativeData ( uint32_t aDataType )
2011-08-31 12:01:38 -07:00
{
2012-05-08 14:36:07 -07:00
switch ( aDataType ) {
case NS_NATIVE_SHAREABLE_WINDOW : {
NS_ABORT_IF_FALSE ( mTabChild , " Need TabChild to get the nativeWindow from! " ) ;
2012-07-20 04:16:17 -07:00
mozilla : : WindowsHandle nativeData = 0 ;
2013-04-02 11:32:59 -07:00
if ( mTabChild ) {
mTabChild - > SendGetWidgetNativeData ( & nativeData ) ;
}
2012-05-08 14:36:07 -07:00
return ( void * ) nativeData ;
}
case NS_NATIVE_WINDOW :
case NS_NATIVE_DISPLAY :
case NS_NATIVE_PLUGIN_PORT :
case NS_NATIVE_GRAPHIC :
case NS_NATIVE_SHELLWIDGET :
case NS_NATIVE_WIDGET :
NS_WARNING ( " nsWindow::GetNativeData not implemented for this type " ) ;
break ;
default :
NS_WARNING ( " nsWindow::GetNativeData called with bad value " ) ;
break ;
}
2012-07-30 07:20:58 -07:00
return nullptr ;
2012-05-08 14:36:07 -07:00
}
PuppetScreen : : PuppetScreen ( void * nativeScreen )
{
}
PuppetScreen : : ~ PuppetScreen ( )
{
}
static ScreenConfiguration
ScreenConfig ( )
{
ScreenConfiguration config ;
hal : : GetCurrentScreenConfiguration ( & config ) ;
return config ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : GetRect ( int32_t * outLeft , int32_t * outTop ,
int32_t * outWidth , int32_t * outHeight )
2012-05-08 14:36:07 -07:00
{
nsIntRect r = ScreenConfig ( ) . rect ( ) ;
* outLeft = r . x ;
* outTop = r . y ;
* outWidth = r . width ;
* outHeight = r . height ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : GetAvailRect ( int32_t * outLeft , int32_t * outTop ,
int32_t * outWidth , int32_t * outHeight )
2012-05-08 14:36:07 -07:00
{
return GetRect ( outLeft , outTop , outWidth , outHeight ) ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : GetPixelDepth ( int32_t * aPixelDepth )
2012-05-08 14:36:07 -07:00
{
* aPixelDepth = ScreenConfig ( ) . pixelDepth ( ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : GetColorDepth ( int32_t * aColorDepth )
2012-05-08 14:36:07 -07:00
{
* aColorDepth = ScreenConfig ( ) . colorDepth ( ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : GetRotation ( uint32_t * aRotation )
2012-05-08 14:36:07 -07:00
{
NS_WARNING ( " Attempt to get screen rotation through nsIScreen::GetRotation(). Nothing should know or care this in sandboxed contexts. If you want *orientation*, use hal. " ) ;
return NS_ERROR_NOT_AVAILABLE ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreen : : SetRotation ( uint32_t aRotation )
2012-05-08 14:36:07 -07:00
{
NS_WARNING ( " Attempt to set screen rotation through nsIScreen::GetRotation(). Nothing should know or care this in sandboxed contexts. If you want *orientation*, use hal. " ) ;
return NS_ERROR_NOT_AVAILABLE ;
}
NS_IMPL_ISUPPORTS1 ( PuppetScreenManager , nsIScreenManager )
PuppetScreenManager : : PuppetScreenManager ( )
{
2012-07-30 07:20:58 -07:00
mOneScreen = new PuppetScreen ( nullptr ) ;
2012-05-08 14:36:07 -07:00
}
PuppetScreenManager : : ~ PuppetScreenManager ( )
{
}
NS_IMETHODIMP
PuppetScreenManager : : GetPrimaryScreen ( nsIScreen * * outScreen )
{
NS_IF_ADDREF ( * outScreen = mOneScreen . get ( ) ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreenManager : : ScreenForRect ( int32_t inLeft ,
int32_t inTop ,
int32_t inWidth ,
int32_t inHeight ,
2012-05-08 14:36:07 -07:00
nsIScreen * * outScreen )
{
return GetPrimaryScreen ( outScreen ) ;
}
NS_IMETHODIMP
PuppetScreenManager : : ScreenForNativeWidget ( void * aWidget ,
nsIScreen * * outScreen )
{
return GetPrimaryScreen ( outScreen ) ;
}
NS_IMETHODIMP
2012-08-22 08:56:38 -07:00
PuppetScreenManager : : GetNumberOfScreens ( uint32_t * aNumberOfScreens )
2012-05-08 14:36:07 -07:00
{
* aNumberOfScreens = 1 ;
return NS_OK ;
2011-08-31 12:01:38 -07:00
}
2010-08-20 16:24:40 -07:00
} // namespace widget
} // namespace mozilla