2010-08-21 03:24:40 +04:00
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim : sw = 2 ts = 8 et :
*/
2012-05-21 15:12:37 +04: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-21 03:24:40 +04:00
2012-07-18 03:59:45 +04:00
# include "base/basictypes.h"
2013-05-01 09:03:25 +04:00
# include "ClientLayerManager.h"
2012-07-18 03:59:45 +04:00
# include "gfxPlatform.h"
# include "mozilla/dom/TabChild.h"
2012-05-09 01:36:07 +04:00
# include "mozilla/Hal.h"
2014-03-08 05:20:07 +04:00
# include "mozilla/IMEStateManager.h"
2012-07-18 03:59:45 +04:00
# include "mozilla/layers/CompositorChild.h"
2013-04-24 22:42:40 +04:00
# include "mozilla/layers/PLayerTransactionChild.h"
2014-11-20 20:28:58 +03:00
# include "mozilla/Preferences.h"
2014-04-03 08:18:37 +04:00
# include "mozilla/TextComposition.h"
2013-09-25 15:21:19 +04:00
# include "mozilla/TextEvents.h"
2015-03-25 01:00:52 +03:00
# include "mozilla/unused.h"
2010-08-21 03:24:40 +04:00
# include "PuppetWidget.h"
2012-08-15 22:52:42 +04:00
# include "nsIWidgetListener.h"
2010-08-21 03:24:40 +04:00
2014-06-10 10:02:21 +04:00
using namespace mozilla ;
2012-05-09 01:36:07 +04:00
using namespace mozilla : : dom ;
using namespace mozilla : : hal ;
2014-02-09 12:04:38 +04:00
using namespace mozilla : : gfx ;
2010-08-21 03:24:40 +04: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-24 07:52:21 +04:00
aWidget - > Invalidate ( * r ) ;
2010-08-21 03:24:40 +04:00
}
}
/*static*/ already_AddRefed < nsIWidget >
2012-07-18 03:59:45 +04:00
nsIWidget : : CreatePuppetWidget ( TabChild * aTabChild )
2010-08-21 03:24:40 +04:00
{
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( ! aTabChild | | nsIWidget : : UsePuppetWidgets ( ) ,
" PuppetWidgets not allowed in this configuration " ) ;
2010-08-21 03:24:40 +04:00
2010-09-24 07:28:15 +04:00
nsCOMPtr < nsIWidget > widget = new PuppetWidget ( aTabChild ) ;
2010-08-21 03:24:40 +04:00
return widget . forget ( ) ;
}
namespace mozilla {
namespace widget {
2011-02-23 20:45:09 +03: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-29 03:56:28 +04:00
# ifdef MOZ_CROSS_PROCESS_IME
2011-02-23 20:45:09 +03:00
return ! IsPopup ( aInitData ) ;
2013-01-29 03:56:28 +04:00
# else
return false ;
# endif
2011-02-23 20:45:09 +03:00
}
2010-08-21 03:24:40 +04:00
// Arbitrary, fungible.
const size_t PuppetWidget : : kMaxDimension = 4000 ;
2015-02-18 09:27:53 +03:00
NS_IMPL_ISUPPORTS_INHERITED0 ( PuppetWidget , nsBaseWidget )
2010-08-21 03:24:40 +04:00
2012-07-18 03:59:45 +04:00
PuppetWidget : : PuppetWidget ( TabChild * aTabChild )
2010-09-24 07:28:15 +04:00
: mTabChild ( aTabChild )
2010-12-03 04:24:04 +03:00
, mDPI ( - 1 )
2013-05-02 03:06:19 +04:00
, mDefaultScale ( - 1 )
2014-04-22 00:40:09 +04:00
, mNativeKeyCommandsValid ( false )
2010-08-21 03:24:40 +04:00
{
MOZ_COUNT_CTOR ( PuppetWidget ) ;
2014-03-20 19:46:29 +04:00
mSingleLineCommands . SetCapacity ( 4 ) ;
mMultiLineCommands . SetCapacity ( 4 ) ;
mRichTextCommands . SetCapacity ( 4 ) ;
2010-08-21 03:24:40 +04:00
}
PuppetWidget : : ~ PuppetWidget ( )
{
MOZ_COUNT_DTOR ( PuppetWidget ) ;
}
NS_IMETHODIMP
PuppetWidget : : Create ( nsIWidget * aParent ,
nsNativeWidget aNativeParent ,
const nsIntRect & aRect ,
nsWidgetInitData * aInitData )
{
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( ! aNativeParent , " got a non-Puppet native parent " ) ;
2010-08-21 03:24:40 +04:00
2015-02-05 08:18:30 +03:00
BaseCreate ( nullptr , aRect , aInitData ) ;
2010-08-21 03:24:40 +04:00
mBounds = aRect ;
2011-10-17 18:59:28 +04:00
mEnabled = true ;
mVisible = true ;
2010-08-21 03:24:40 +04:00
2014-06-10 10:02:21 +04:00
mDrawTarget = gfxPlatform : : GetPlatform ( ) - >
CreateOffscreenContentDrawTarget ( IntSize ( 1 , 1 ) , SurfaceFormat : : B8G8R8A8 ) ;
2010-08-21 03:24:40 +04:00
2012-08-29 19:26:18 +04:00
mNeedIMEStateInit = MightNeedIMEFocus ( aInitData ) ;
2010-09-24 07:28:15 +04:00
2010-08-21 03:24:40 +04:00
PuppetWidget * parent = static_cast < PuppetWidget * > ( aParent ) ;
if ( parent ) {
parent - > SetChild ( this ) ;
2010-08-21 03:24:41 +04:00
mLayerManager = parent - > GetLayerManager ( ) ;
2010-08-21 03:24:40 +04:00
}
else {
2011-10-17 18:59:28 +04:00
Resize ( mBounds . x , mBounds . y , mBounds . width , mBounds . height , false ) ;
2010-08-21 03:24:40 +04:00
}
2015-04-29 06:54:04 +03:00
nsCOMPtr < nsIObserverService > obs = mozilla : : services : : GetObserverService ( ) ;
if ( obs ) {
mMemoryPressureObserver = new MemoryPressureObserver ( this ) ;
obs - > AddObserver ( mMemoryPressureObserver , " memory-pressure " , false ) ;
}
2010-08-21 03:24:40 +04:00
return NS_OK ;
}
2012-08-29 19:26:18 +04:00
void
PuppetWidget : : InitIMEState ( )
{
2013-06-17 09:42:20 +04:00
MOZ_ASSERT ( mTabChild ) ;
2012-08-29 19:26:18 +04:00
if ( mNeedIMEStateInit ) {
uint32_t chromeSeqno ;
2014-01-29 13:32:39 +04:00
mTabChild - > SendNotifyIMEFocus ( false , & mIMEPreferenceOfParent , & chromeSeqno ) ;
2012-08-29 19:26:18 +04:00
mIMELastBlurSeqno = mIMELastReceivedSeqno = chromeSeqno ;
mNeedIMEStateInit = false ;
}
}
2010-08-21 03:24:40 +04:00
already_AddRefed < nsIWidget >
PuppetWidget : : CreateChild ( const nsIntRect & aRect ,
nsWidgetInitData * aInitData ,
2011-09-29 10:19:26 +04:00
bool aForceUseIWidgetParent )
2010-08-21 03:24:40 +04:00
{
2011-02-23 20:45:09 +03:00
bool isPopup = IsPopup ( aInitData ) ;
2010-09-24 07:28:15 +04:00
nsCOMPtr < nsIWidget > widget = nsIWidget : : CreatePuppetWidget ( mTabChild ) ;
2010-08-21 03:24:40 +04:00
return ( ( widget & &
2012-07-30 18:20:58 +04:00
NS_SUCCEEDED ( widget - > Create ( isPopup ? nullptr : this , nullptr , aRect ,
2015-02-05 10:35:25 +03:00
aInitData ) ) ) ?
2012-07-30 18:20:58 +04:00
widget . forget ( ) : nullptr ) ;
2010-08-21 03:24:40 +04:00
}
2010-08-21 03:24:40 +04:00
NS_IMETHODIMP
PuppetWidget : : Destroy ( )
{
2011-03-30 00:14:44 +04:00
Base : : OnDestroy ( ) ;
2010-08-21 03:24:40 +04:00
Base : : Destroy ( ) ;
mPaintTask . Revoke ( ) ;
2015-04-29 06:54:04 +03:00
if ( mMemoryPressureObserver ) {
mMemoryPressureObserver - > Remove ( ) ;
}
2012-07-30 18:20:58 +04:00
mChild = nullptr ;
2010-12-07 05:05:25 +03:00
if ( mLayerManager ) {
mLayerManager - > Destroy ( ) ;
}
2012-07-30 18:20:58 +04:00
mLayerManager = nullptr ;
mTabChild = nullptr ;
2010-08-21 03:24:40 +04:00
return NS_OK ;
}
2010-08-21 03:24:40 +04:00
NS_IMETHODIMP
2011-09-29 10:19:26 +04:00
PuppetWidget : : Show ( bool aState )
2010-08-21 03:24:40 +04:00
{
NS_ASSERTION ( mEnabled ,
" does it make sense to Show()/Hide() a disabled widget? " ) ;
2011-09-29 10:19:26 +04:00
bool wasVisible = mVisible ;
2010-08-21 03:24:40 +04:00
mVisible = aState ;
2012-11-08 07:51:55 +04:00
if ( mChild ) {
mChild - > mVisible = aState ;
}
2010-08-21 03:24:40 +04:00
if ( ! wasVisible & & mVisible ) {
2011-10-17 18:59:28 +04:00
Resize ( mBounds . width , mBounds . height , false ) ;
2012-11-08 07:51:55 +04:00
Invalidate ( mBounds ) ;
2010-08-21 03:24:40 +04:00
}
return NS_OK ;
}
NS_IMETHODIMP
2012-12-12 13:57:38 +04:00
PuppetWidget : : Resize ( double aWidth ,
double aHeight ,
bool aRepaint )
2010-08-21 03:24:40 +04:00
{
nsIntRect oldBounds = mBounds ;
2012-12-12 13:57:38 +04:00
mBounds . SizeTo ( nsIntSize ( NSToIntRound ( aWidth ) , NSToIntRound ( aHeight ) ) ) ;
2010-08-21 03:24:40 +04: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 22:53:14 +04:00
if ( ! oldBounds . IsEqualEdges ( mBounds ) & & mAttachedWidgetListener ) {
mAttachedWidgetListener - > WindowResized ( this , mBounds . width , mBounds . height ) ;
2010-08-21 03:24:40 +04:00
}
return NS_OK ;
}
2014-11-12 23:59:19 +03:00
nsresult
PuppetWidget : : ConfigureChildren ( const nsTArray < Configuration > & aConfigurations )
{
for ( uint32_t i = 0 ; i < aConfigurations . Length ( ) ; + + i ) {
const Configuration & configuration = aConfigurations [ i ] ;
PuppetWidget * w = static_cast < PuppetWidget * > ( configuration . mChild ) ;
NS_ASSERTION ( w - > GetParent ( ) = = this ,
" Configured widget is not a child " ) ;
w - > SetWindowClipRegion ( configuration . mClipRegion , true ) ;
nsIntRect bounds ;
w - > GetBounds ( bounds ) ;
if ( bounds . Size ( ) ! = configuration . mBounds . Size ( ) ) {
w - > Resize ( configuration . mBounds . x , configuration . mBounds . y ,
configuration . mBounds . width , configuration . mBounds . height ,
true ) ;
} else if ( bounds . TopLeft ( ) ! = configuration . mBounds . TopLeft ( ) ) {
w - > Move ( configuration . mBounds . x , configuration . mBounds . y ) ;
}
w - > SetWindowClipRegion ( configuration . mClipRegion , false ) ;
}
return NS_OK ;
}
2010-08-21 03:24:40 +04:00
NS_IMETHODIMP
2011-09-29 10:19:26 +04:00
PuppetWidget : : SetFocus ( bool aRaise )
2010-08-21 03:24:40 +04:00
{
// XXX/cjones: someone who knows about event handling needs to
// decide how this should work.
return NS_OK ;
}
NS_IMETHODIMP
2011-12-24 07:52:21 +04:00
PuppetWidget : : Invalidate ( const nsIntRect & aRect )
2010-08-21 03:24:40 +04:00
{
# ifdef DEBUG
2011-12-24 07:52:21 +04:00
debug_DumpInvalidate ( stderr , this , & aRect ,
2012-09-02 06:35:17 +04:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-21 03:24:40 +04:00
# endif
if ( mChild ) {
2011-12-24 07:52:21 +04:00
return mChild - > Invalidate ( aRect ) ;
2010-08-21 03:24:40 +04:00
}
mDirtyRegion . Or ( mDirtyRegion , aRect ) ;
2011-12-24 07:52:21 +04:00
if ( ! mDirtyRegion . IsEmpty ( ) & & ! mPaintTask . IsPending ( ) ) {
2010-08-21 03:24:40 +04:00
mPaintTask = new PaintTask ( this ) ;
return NS_DispatchToCurrentThread ( mPaintTask . get ( ) ) ;
}
return NS_OK ;
}
2010-09-24 07:28:15 +04:00
void
2013-10-02 07:46:03 +04:00
PuppetWidget : : InitEvent ( WidgetGUIEvent & event , nsIntPoint * aPoint )
2010-09-24 07:28:15 +04:00
{
2012-07-30 18:20:58 +04:00
if ( nullptr = = aPoint ) {
2010-09-24 07:28:15 +04: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-21 03:24:40 +04:00
NS_IMETHODIMP
2013-10-02 07:46:03 +04:00
PuppetWidget : : DispatchEvent ( WidgetGUIEvent * event , nsEventStatus & aStatus )
2010-08-21 03:24:40 +04:00
{
# ifdef DEBUG
debug_DumpEvent ( stdout , event - > widget , event ,
2012-09-02 06:35:17 +04:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-21 03:24:40 +04:00
# endif
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( ! mChild | | mChild - > mWindowType = = eWindowType_popup ,
" Unexpected event dispatch! " ) ;
2011-02-09 23:13:18 +03:00
2014-04-22 00:40:09 +04:00
AutoCacheNativeKeyCommands autoCache ( this ) ;
if ( event - > mFlags . mIsSynthesizedForTests & & ! mNativeKeyCommandsValid ) {
WidgetKeyboardEvent * keyEvent = event - > AsKeyboardEvent ( ) ;
if ( keyEvent ) {
mTabChild - > RequestNativeKeyBindings ( & autoCache , keyEvent ) ;
}
}
2010-08-21 03:24:40 +04:00
aStatus = nsEventStatus_eIgnore ;
2011-02-09 23:13:18 +03:00
2014-01-15 18:41:39 +04:00
uint32_t seqno = kLatestSeqno ;
2014-08-04 09:28:46 +04:00
switch ( event - > mClass ) {
2014-08-04 09:28:48 +04:00
case eCompositionEventClass :
2014-01-15 18:41:39 +04:00
seqno = event - > AsCompositionEvent ( ) - > mSeqno ;
2011-02-09 23:13:18 +03:00
break ;
2014-08-04 09:28:49 +04:00
case eSelectionEventClass :
2014-01-15 18:41:39 +04:00
seqno = event - > AsSelectionEvent ( ) - > mSeqno ;
2011-02-09 23:13:18 +03:00
break ;
2012-11-20 10:05:56 +04:00
default :
break ;
2011-02-09 23:13:18 +03:00
}
2014-01-15 18:41:39 +04:00
if ( seqno ! = kLatestSeqno ) {
mIMELastReceivedSeqno = seqno ;
if ( mIMELastReceivedSeqno < mIMELastBlurSeqno ) {
return NS_OK ;
}
}
2012-08-15 22:53:09 +04:00
2013-01-25 23:51:16 +04:00
if ( mAttachedWidgetListener ) {
aStatus = mAttachedWidgetListener - > HandleEvent ( event , mUseAttachedEvents ) ;
}
2011-02-09 23:13:18 +03:00
2010-08-21 03:24:40 +04:00
return NS_OK ;
}
2015-03-25 01:00:52 +03:00
nsEventStatus
PuppetWidget : : DispatchInputEvent ( WidgetInputEvent * aEvent )
{
if ( ! mTabChild ) {
return nsEventStatus_eIgnore ;
}
switch ( aEvent - > mClass ) {
case eMouseEventClass :
unused < <
mTabChild - > SendDispatchMouseEvent ( * aEvent - > AsMouseEvent ( ) ) ;
break ;
case eKeyboardEventClass :
unused < <
mTabChild - > SendDispatchKeyboardEvent ( * aEvent - > AsKeyboardEvent ( ) ) ;
break ;
default :
MOZ_ASSERT_UNREACHABLE ( " unsupported event type " ) ;
}
return nsEventStatus_eIgnore ;
}
2014-03-20 19:46:29 +04:00
2015-03-07 01:26:59 +03:00
nsEventStatus
PuppetWidget : : DispatchAPZAwareEvent ( WidgetInputEvent * aEvent )
{
if ( ! gfxPrefs : : AsyncPanZoomEnabled ( ) ) {
nsEventStatus status = nsEventStatus_eIgnore ;
DispatchEvent ( aEvent , status ) ;
return status ;
}
if ( ! mTabChild ) {
return nsEventStatus_eIgnore ;
}
switch ( aEvent - > mClass ) {
case eWheelEventClass :
2015-03-25 01:00:52 +03:00
unused < <
mTabChild - > SendDispatchWheelEvent ( * aEvent - > AsWheelEvent ( ) ) ;
2015-03-07 01:26:59 +03:00
break ;
default :
MOZ_ASSERT_UNREACHABLE ( " unsupported event type " ) ;
}
return nsEventStatus_eIgnore ;
}
2015-04-14 18:36:36 +03:00
nsresult
PuppetWidget : : SynthesizeNativeKeyEvent ( int32_t aNativeKeyboardLayout ,
int32_t aNativeKeyCode ,
uint32_t aModifierFlags ,
const nsAString & aCharacters ,
const nsAString & aUnmodifiedCharacters ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " keyevent " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeKeyEvent ( aNativeKeyboardLayout , aNativeKeyCode ,
aModifierFlags , nsString ( aCharacters ) , nsString ( aUnmodifiedCharacters ) ,
notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : SynthesizeNativeMouseEvent ( mozilla : : LayoutDeviceIntPoint aPoint ,
uint32_t aNativeMessage ,
uint32_t aModifierFlags ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " mouseevent " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeMouseEvent ( aPoint , aNativeMessage ,
aModifierFlags , notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : SynthesizeNativeMouseMove ( mozilla : : LayoutDeviceIntPoint aPoint ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " mousemove " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeMouseMove ( aPoint , notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : SynthesizeNativeMouseScrollEvent ( mozilla : : LayoutDeviceIntPoint aPoint ,
uint32_t aNativeMessage ,
double aDeltaX ,
double aDeltaY ,
double aDeltaZ ,
uint32_t aModifierFlags ,
uint32_t aAdditionalFlags ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " mousescrollevent " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeMouseScrollEvent ( aPoint , aNativeMessage ,
aDeltaX , aDeltaY , aDeltaZ , aModifierFlags , aAdditionalFlags ,
notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : SynthesizeNativeTouchPoint ( uint32_t aPointerId ,
TouchPointerState aPointerState ,
nsIntPoint aPointerScreenPoint ,
double aPointerPressure ,
uint32_t aPointerOrientation ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " touchpoint " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeTouchPoint ( aPointerId , aPointerState ,
aPointerScreenPoint , aPointerPressure , aPointerOrientation ,
notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : SynthesizeNativeTouchTap ( nsIntPoint aPointerScreenPoint ,
bool aLongTap ,
nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " touchtap " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendSynthesizeNativeTouchTap ( aPointerScreenPoint , aLongTap ,
notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
nsresult
PuppetWidget : : ClearNativeTouchSequence ( nsIObserver * aObserver )
{
AutoObserverNotifier notifier ( aObserver , " cleartouch " ) ;
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendClearNativeTouchSequence ( notifier . SaveObserver ( ) ) ;
return NS_OK ;
}
2015-04-14 19:24:32 +03:00
void
PuppetWidget : : SetConfirmedTargetAPZC ( uint64_t aInputBlockId ,
const nsTArray < ScrollableLayerGuid > & aTargets ) const
{
if ( mTabChild ) {
mTabChild - > SendSetTargetAPZC ( aInputBlockId , aTargets ) ;
}
}
2015-04-14 18:36:36 +03:00
2014-03-20 19:46:29 +04:00
NS_IMETHODIMP_ ( bool )
PuppetWidget : : ExecuteNativeKeyBinding ( NativeKeyBindingsType aType ,
const mozilla : : WidgetKeyboardEvent & aEvent ,
DoCommandCallback aCallback ,
void * aCallbackData )
{
2014-04-22 00:40:09 +04:00
// B2G doesn't have native key bindings.
2015-04-15 22:17:00 +03:00
# ifdef MOZ_WIDGET_GONK
2014-04-22 00:40:09 +04:00
return false ;
2015-04-15 22:17:00 +03:00
# else // #ifdef MOZ_WIDGET_GONK
2014-04-22 00:40:09 +04:00
MOZ_ASSERT ( mNativeKeyCommandsValid ) ;
2014-03-20 19:46:29 +04:00
nsTArray < mozilla : : CommandInt > & commands = mSingleLineCommands ;
switch ( aType ) {
case nsIWidget : : NativeKeyBindingsForSingleLineEditor :
commands = mSingleLineCommands ;
break ;
case nsIWidget : : NativeKeyBindingsForMultiLineEditor :
commands = mMultiLineCommands ;
break ;
case nsIWidget : : NativeKeyBindingsForRichTextEditor :
commands = mRichTextCommands ;
break ;
}
if ( commands . IsEmpty ( ) ) {
return false ;
}
for ( uint32_t i = 0 ; i < commands . Length ( ) ; i + + ) {
aCallback ( static_cast < mozilla : : Command > ( commands [ i ] ) , aCallbackData ) ;
}
return true ;
2014-04-22 00:40:09 +04:00
# endif
2014-03-20 19:46:29 +04:00
}
2010-08-21 03:24:40 +04:00
LayerManager *
2013-04-24 22:42:40 +04:00
PuppetWidget : : GetLayerManager ( PLayerTransactionChild * aShadowManager ,
2011-08-09 23:38:26 +04:00
LayersBackend aBackendHint ,
LayerManagerPersistence aPersistence ,
bool * aAllowRetaining )
2010-08-21 03:24:40 +04:00
{
if ( ! mLayerManager ) {
2014-08-22 04:16:44 +04:00
mLayerManager = new ClientLayerManager ( this ) ;
2010-08-21 03:24:40 +04:00
}
2013-11-01 10:36:02 +04:00
ShadowLayerForwarder * lf = mLayerManager - > AsShadowForwarder ( ) ;
if ( ! lf - > HasShadowManager ( ) & & aShadowManager ) {
lf - > SetShadowManager ( aShadowManager ) ;
}
2010-10-15 14:34:29 +04:00
if ( aAllowRetaining ) {
* aAllowRetaining = true ;
}
2010-08-21 03:24:40 +04:00
return mLayerManager ;
}
2010-09-24 07:28:15 +04:00
nsresult
2011-09-29 10:19:26 +04:00
PuppetWidget : : IMEEndComposition ( bool aCancel )
2010-09-24 07:28:15 +04:00
{
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-24 07:28:15 +04:00
nsEventStatus status ;
2015-02-17 05:30:55 +03:00
bool noCompositionEvent = true ;
2015-02-17 05:30:38 +03:00
WidgetCompositionEvent compositionCommitEvent ( true , NS_COMPOSITION_COMMIT ,
2014-10-07 14:01:49 +04:00
this ) ;
2015-02-17 05:30:38 +03:00
InitEvent ( compositionCommitEvent , nullptr ) ;
2010-12-15 22:22:15 +03:00
// SendEndIMEComposition is always called since ResetInputState
// should always be called even if we aren't composing something.
2010-09-24 07:28:15 +04:00
if ( ! mTabChild | |
2015-02-17 05:30:55 +03:00
! mTabChild - > SendEndIMEComposition ( aCancel , & noCompositionEvent ,
2015-02-17 05:30:38 +03:00
& compositionCommitEvent . mData ) ) {
2010-09-24 07:28:15 +04:00
return NS_ERROR_FAILURE ;
}
2010-12-15 22:22:15 +03:00
2015-02-17 05:30:55 +03:00
if ( noCompositionEvent ) {
2010-12-15 22:22:15 +03:00
return NS_OK ;
2015-02-17 05:30:55 +03:00
}
2010-12-15 22:22:15 +03:00
2015-02-17 05:30:38 +03:00
compositionCommitEvent . mSeqno = mIMELastReceivedSeqno ;
DispatchEvent ( & compositionCommitEvent , status ) ;
2010-09-24 07:28:15 +04:00
return NS_OK ;
}
2015-01-28 09:27:31 +03:00
nsresult
PuppetWidget : : NotifyIMEInternal ( const IMENotification & aIMENotification )
2010-09-24 07:28:15 +04:00
{
2014-02-18 04:00:15 +04:00
switch ( aIMENotification . mMessage ) {
2013-03-06 10:14:31 +04:00
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 :
2014-02-26 04:48:02 +04:00
return NotifyIMEOfSelectionChange ( aIMENotification ) ;
2014-02-18 04:00:15 +04:00
case NOTIFY_IME_OF_TEXT_CHANGE :
return NotifyIMEOfTextChange ( aIMENotification ) ;
2013-11-07 04:11:11 +04:00
case NOTIFY_IME_OF_COMPOSITION_UPDATE :
return NotifyIMEOfUpdateComposition ( ) ;
2014-09-11 17:46:17 +04:00
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT :
return NotifyIMEOfMouseButtonEvent ( aIMENotification ) ;
2014-12-15 12:37:00 +03:00
case NOTIFY_IME_OF_POSITION_CHANGE :
return NotifyIMEOfPositionChange ( ) ;
2013-03-06 10:14:31 +04:00
default :
return NS_ERROR_NOT_IMPLEMENTED ;
}
2010-09-24 07:28:15 +04:00
}
2015-02-20 19:37:02 +03:00
NS_IMETHODIMP
PuppetWidget : : StartPluginIME ( const mozilla : : WidgetKeyboardEvent & aKeyboardEvent ,
int32_t aPanelX , int32_t aPanelY ,
nsString & aCommitted )
{
if ( ! mTabChild | |
! mTabChild - > SendStartPluginIME ( aKeyboardEvent , aPanelX ,
aPanelY , & aCommitted ) ) {
return NS_ERROR_FAILURE ;
}
return NS_OK ;
}
NS_IMETHODIMP
PuppetWidget : : SetPluginFocused ( bool & aFocused )
{
if ( ! mTabChild | | ! mTabChild - > SendSetPluginFocused ( aFocused ) ) {
return NS_ERROR_FAILURE ;
}
return NS_OK ;
}
2011-11-27 15:51:52 +04:00
NS_IMETHODIMP_ ( void )
PuppetWidget : : SetInputContext ( const InputContext & aContext ,
const InputContextAction & aAction )
2010-09-24 07:28:15 +04:00
{
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return ;
# endif
2011-11-27 15:51:52 +04:00
if ( ! mTabChild ) {
return ;
}
2011-11-27 15:51:53 +04:00
mTabChild - > SendSetInputContext (
2012-08-22 19:56:38 +04:00
static_cast < int32_t > ( aContext . mIMEState . mEnabled ) ,
static_cast < int32_t > ( aContext . mIMEState . mOpen ) ,
2011-11-27 15:51:53 +04:00
aContext . mHTMLInputType ,
2012-08-27 06:16:22 +04:00
aContext . mHTMLInputInputmode ,
2011-11-27 15:51:53 +04:00
aContext . mActionHint ,
2012-08-22 19:56:38 +04:00
static_cast < int32_t > ( aAction . mCause ) ,
static_cast < int32_t > ( aAction . mFocusChange ) ) ;
2010-09-24 07:28:15 +04:00
}
2011-11-27 15:51:52 +04:00
NS_IMETHODIMP_ ( InputContext )
PuppetWidget : : GetInputContext ( )
2010-09-24 07:28:15 +04:00
{
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return InputContext ( ) ;
# endif
2011-11-27 15:51:52 +04:00
InputContext context ;
if ( mTabChild ) {
2012-08-22 19:56:38 +04:00
int32_t enabled , open ;
2012-10-30 05:58:29 +04:00
intptr_t nativeIMEContext ;
2012-10-27 03:35:20 +04:00
mTabChild - > SendGetInputContext ( & enabled , & open , & nativeIMEContext ) ;
2011-11-27 15:51:53 +04:00
context . mIMEState . mEnabled = static_cast < IMEState : : Enabled > ( enabled ) ;
context . mIMEState . mOpen = static_cast < IMEState : : Open > ( open ) ;
2012-10-27 03:35:20 +04:00
context . mNativeIMEContext = reinterpret_cast < void * > ( nativeIMEContext ) ;
2011-11-27 15:51:52 +04:00
}
return context ;
2010-09-24 07:28:15 +04:00
}
2013-03-06 10:14:31 +04:00
nsresult
PuppetWidget : : NotifyIMEOfFocusChange ( bool aFocus )
2010-09-24 07:28:15 +04:00
{
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-24 07:28:15 +04:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
if ( aFocus ) {
nsEventStatus status ;
2013-10-01 11:23:00 +04:00
WidgetQueryContentEvent queryEvent ( true , NS_QUERY_TEXT_CONTENT , this ) ;
2012-07-30 18:20:58 +04:00
InitEvent ( queryEvent , nullptr ) ;
2010-09-24 07:28:15 +04:00
// Query entire content
2012-09-28 10:57:33 +04:00
queryEvent . InitForQueryTextContent ( 0 , UINT32_MAX ) ;
2010-09-24 07:28:15 +04:00
DispatchEvent ( & queryEvent , status ) ;
if ( queryEvent . mSucceeded ) {
mTabChild - > SendNotifyIMETextHint ( queryEvent . mReply . mString ) ;
}
}
2012-08-22 19:56:38 +04:00
uint32_t chromeSeqno ;
2014-02-26 04:48:02 +04:00
mIMEPreferenceOfParent = nsIMEUpdatePreference ( ) ;
2014-01-29 13:32:39 +04:00
if ( ! mTabChild - > SendNotifyIMEFocus ( aFocus , & mIMEPreferenceOfParent ,
& chromeSeqno ) ) {
2010-09-24 07:28:15 +04:00
return NS_ERROR_FAILURE ;
2014-01-29 13:32:39 +04:00
}
2010-09-24 07:28:15 +04:00
if ( aFocus ) {
2014-02-26 04:48:02 +04:00
IMENotification notification ( NOTIFY_IME_OF_SELECTION_CHANGE ) ;
notification . mSelectionChangeData . mCausedByComposition = false ;
NotifyIMEOfSelectionChange ( notification ) ; // Update selection
2014-12-15 12:21:20 +03:00
NotifyIMEOfEditorRect ( ) ;
2010-10-01 18:17:37 +04:00
} else {
mIMELastBlurSeqno = chromeSeqno ;
2010-09-24 07:28:15 +04:00
}
return NS_OK ;
}
2013-11-07 04:11:11 +04:00
nsresult
PuppetWidget : : NotifyIMEOfUpdateComposition ( )
{
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
NS_ENSURE_TRUE ( mTabChild , NS_ERROR_FAILURE ) ;
2014-12-15 12:37:00 +03:00
uint32_t startOffset ;
uint32_t targetCauseOffset ;
2015-02-04 23:21:03 +03:00
nsAutoTArray < LayoutDeviceIntRect , 16 > textRectArray ;
2014-12-15 12:37:00 +03:00
if ( ! GetCompositionRects ( startOffset ,
textRectArray ,
targetCauseOffset ) ) {
return NS_ERROR_FAILURE ;
}
2015-02-04 23:21:03 +03:00
LayoutDeviceIntRect caretRect ;
2014-12-15 12:37:00 +03:00
GetCaretRect ( caretRect , targetCauseOffset ) ;
mTabChild - > SendNotifyIMESelectedCompositionRect ( startOffset ,
textRectArray ,
targetCauseOffset ,
caretRect ) ;
return NS_OK ;
}
bool
PuppetWidget : : GetCompositionRects ( uint32_t & aStartOffset ,
2015-02-04 23:21:03 +03:00
nsTArray < LayoutDeviceIntRect > & aTextRectArray ,
2014-12-15 12:37:00 +03:00
uint32_t & aTargetCauseOffset )
{
2014-01-28 12:19:29 +04:00
nsRefPtr < TextComposition > textComposition =
2014-03-08 05:20:07 +04:00
IMEStateManager : : GetTextCompositionFor ( this ) ;
2014-12-15 12:37:00 +03:00
NS_ENSURE_TRUE ( textComposition , false ) ;
2013-11-07 04:11:11 +04:00
nsEventStatus status ;
2014-12-15 12:37:00 +03:00
aTextRectArray . SetCapacity ( textComposition - > String ( ) . Length ( ) ) ;
aStartOffset = textComposition - > NativeOffsetOfStartComposition ( ) ;
aTargetCauseOffset = textComposition - > OffsetOfTargetClause ( ) ;
uint32_t endOffset = textComposition - > String ( ) . Length ( ) + aStartOffset ;
for ( uint32_t i = aStartOffset ; i < endOffset ; i + + ) {
2014-09-15 11:11:08 +04:00
WidgetQueryContentEvent textRect ( true , NS_QUERY_TEXT_RECT , this ) ;
InitEvent ( textRect , nullptr ) ;
textRect . InitForQueryTextRect ( i , 1 ) ;
DispatchEvent ( & textRect , status ) ;
2014-12-15 12:37:00 +03:00
NS_ENSURE_TRUE ( textRect . mSucceeded , false ) ;
2013-11-07 04:11:11 +04:00
2014-12-15 12:37:00 +03:00
aTextRectArray . AppendElement ( textRect . mReply . mRect ) ;
2014-09-15 11:11:08 +04:00
}
2014-12-15 12:37:00 +03:00
return true ;
}
uint32_t
PuppetWidget : : GetCaretOffset ( )
{
nsEventStatus status ;
WidgetQueryContentEvent selection ( true , NS_QUERY_SELECTED_TEXT , this ) ;
InitEvent ( selection , nullptr ) ;
DispatchEvent ( & selection , status ) ;
NS_ENSURE_TRUE ( selection . mSucceeded , 0 ) ;
return selection . mReply . mOffset ;
}
2014-09-15 11:11:08 +04:00
2014-12-15 12:37:00 +03:00
bool
2015-02-04 23:21:03 +03:00
PuppetWidget : : GetCaretRect ( LayoutDeviceIntRect & aCaretRect , uint32_t aCaretOffset )
2014-12-15 12:37:00 +03:00
{
nsEventStatus status ;
2014-01-16 14:04:39 +04:00
WidgetQueryContentEvent caretRect ( true , NS_QUERY_CARET_RECT , this ) ;
InitEvent ( caretRect , nullptr ) ;
2014-12-15 12:37:00 +03:00
caretRect . InitForQueryCaretRect ( aCaretOffset ) ;
2014-01-16 14:04:39 +04:00
DispatchEvent ( & caretRect , status ) ;
2014-12-15 12:37:00 +03:00
NS_ENSURE_TRUE ( caretRect . mSucceeded , false ) ;
2014-01-16 14:04:39 +04:00
2014-12-15 12:37:00 +03:00
aCaretRect = caretRect . mReply . mRect ;
return true ;
2013-11-07 04:11:11 +04:00
}
2014-12-15 12:21:20 +03:00
nsresult
PuppetWidget : : NotifyIMEOfEditorRect ( )
{
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2014-12-15 12:37:00 +03:00
if ( NS_WARN_IF ( ! mTabChild ) ) {
return NS_ERROR_FAILURE ;
}
2014-12-15 12:21:20 +03:00
2015-02-04 23:21:03 +03:00
LayoutDeviceIntRect rect ;
2014-12-15 12:37:00 +03:00
if ( ! GetEditorRect ( rect ) ) {
return NS_ERROR_FAILURE ;
}
mTabChild - > SendNotifyIMEEditorRect ( rect ) ;
return NS_OK ;
}
bool
2015-02-04 23:21:03 +03:00
PuppetWidget : : GetEditorRect ( LayoutDeviceIntRect & aRect )
2014-12-15 12:37:00 +03:00
{
2014-12-15 12:21:20 +03:00
nsEventStatus status ;
WidgetQueryContentEvent editorRectEvent ( true , NS_QUERY_EDITOR_RECT , this ) ;
InitEvent ( editorRectEvent ) ;
DispatchEvent ( & editorRectEvent , status ) ;
2014-12-15 12:37:00 +03:00
if ( NS_WARN_IF ( ! editorRectEvent . mSucceeded ) ) {
return false ;
2014-12-15 12:21:20 +03:00
}
2014-12-15 12:37:00 +03:00
aRect = editorRectEvent . mReply . mRect ;
2014-12-15 12:21:20 +03:00
2014-12-15 12:37:00 +03:00
return true ;
2014-12-15 12:21:20 +03:00
}
2012-11-13 17:04:44 +04:00
nsIMEUpdatePreference
PuppetWidget : : GetIMEUpdatePreference ( )
{
2014-02-25 09:51:01 +04:00
# ifdef MOZ_CROSS_PROCESS_IME
2014-01-29 13:32:39 +04:00
// e10s requires IME information cache into TabParent
return nsIMEUpdatePreference ( mIMEPreferenceOfParent . mWantUpdates |
nsIMEUpdatePreference : : NOTIFY_SELECTION_CHANGE |
2014-12-15 12:37:00 +03:00
nsIMEUpdatePreference : : NOTIFY_TEXT_CHANGE |
nsIMEUpdatePreference : : NOTIFY_POSITION_CHANGE ) ;
2014-01-29 13:32:39 +04:00
# else
// B2G doesn't handle IME as widget-level.
return nsIMEUpdatePreference ( ) ;
# endif
2012-11-13 17:04:44 +04:00
}
2014-02-18 04:00:15 +04:00
nsresult
PuppetWidget : : NotifyIMEOfTextChange ( const IMENotification & aIMENotification )
2010-09-24 07:28:15 +04:00
{
2014-02-26 04:48:02 +04:00
MOZ_ASSERT ( aIMENotification . mMessage = = NOTIFY_IME_OF_TEXT_CHANGE ,
" Passed wrong notification " ) ;
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-24 07:28:15 +04:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
2014-01-29 13:32:35 +04:00
nsEventStatus status ;
WidgetQueryContentEvent queryEvent ( true , NS_QUERY_TEXT_CONTENT , this ) ;
InitEvent ( queryEvent , nullptr ) ;
queryEvent . InitForQueryTextContent ( 0 , UINT32_MAX ) ;
DispatchEvent ( & queryEvent , status ) ;
2010-09-24 07:28:15 +04:00
2014-01-29 13:32:35 +04:00
if ( queryEvent . mSucceeded ) {
mTabChild - > SendNotifyIMETextHint ( queryEvent . mReply . mString ) ;
2010-09-24 07:28:15 +04:00
}
2014-01-29 13:32:39 +04:00
// TabParent doesn't this this to cache. we don't send the notification
// if parent process doesn't request NOTIFY_TEXT_CHANGE.
2014-02-26 04:48:02 +04:00
if ( mIMEPreferenceOfParent . WantTextChange ( ) & &
( mIMEPreferenceOfParent . WantChangesCausedByComposition ( ) | |
! aIMENotification . mTextChangeData . mCausedByComposition ) ) {
2014-02-18 04:00:15 +04:00
mTabChild - > SendNotifyIMETextChange (
aIMENotification . mTextChangeData . mStartOffset ,
aIMENotification . mTextChangeData . mOldEndOffset ,
2014-02-26 04:48:02 +04:00
aIMENotification . mTextChangeData . mNewEndOffset ,
aIMENotification . mTextChangeData . mCausedByComposition ) ;
2010-09-24 07:28:15 +04:00
}
return NS_OK ;
}
2013-03-06 10:14:31 +04:00
nsresult
2014-02-26 04:48:02 +04:00
PuppetWidget : : NotifyIMEOfSelectionChange (
const IMENotification & aIMENotification )
2010-09-24 07:28:15 +04:00
{
2014-02-26 04:48:02 +04:00
MOZ_ASSERT ( aIMENotification . mMessage = = NOTIFY_IME_OF_SELECTION_CHANGE ,
" Passed wrong notification " ) ;
2013-01-29 03:56:28 +04:00
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
2010-09-24 07:28:15 +04:00
if ( ! mTabChild )
return NS_ERROR_FAILURE ;
2015-05-15 04:18:08 +03:00
mTabChild - > SendNotifyIMESelection (
mIMELastReceivedSeqno ,
aIMENotification . mSelectionChangeData . StartOffset ( ) ,
aIMENotification . mSelectionChangeData . EndOffset ( ) ,
aIMENotification . mSelectionChangeData . GetWritingMode ( ) ,
aIMENotification . mSelectionChangeData . mCausedByComposition ) ;
2010-09-24 07:28:15 +04:00
return NS_OK ;
2014-09-11 17:46:17 +04:00
}
nsresult
PuppetWidget : : NotifyIMEOfMouseButtonEvent (
const IMENotification & aIMENotification )
{
if ( ! mTabChild ) {
return NS_ERROR_FAILURE ;
}
bool consumedByIME = false ;
if ( ! mTabChild - > SendNotifyIMEMouseButtonEvent ( aIMENotification ,
& consumedByIME ) ) {
return NS_ERROR_FAILURE ;
}
return consumedByIME ? NS_SUCCESS_EVENT_CONSUMED : NS_OK ;
2010-09-24 07:28:15 +04:00
}
2014-12-15 12:37:00 +03:00
nsresult
PuppetWidget : : NotifyIMEOfPositionChange ( )
{
# ifndef MOZ_CROSS_PROCESS_IME
return NS_OK ;
# endif
if ( NS_WARN_IF ( ! mTabChild ) ) {
return NS_ERROR_FAILURE ;
}
2015-02-04 23:21:03 +03:00
LayoutDeviceIntRect editorRect ;
2014-12-15 12:37:00 +03:00
if ( ! GetEditorRect ( editorRect ) ) {
return NS_ERROR_FAILURE ;
}
uint32_t startOffset ;
uint32_t targetCauseOffset ;
2015-02-04 23:21:03 +03:00
nsAutoTArray < LayoutDeviceIntRect , 16 > textRectArray ;
2014-12-15 12:37:00 +03:00
if ( ! GetCompositionRects ( startOffset ,
textRectArray ,
targetCauseOffset ) ) {
// no composition string, get caret offset by NS_QUERY_SELECTED_TEXT
targetCauseOffset = GetCaretOffset ( ) ;
}
2015-02-04 23:21:03 +03:00
LayoutDeviceIntRect caretRect ;
2014-12-15 12:37:00 +03:00
GetCaretRect ( caretRect , targetCauseOffset ) ;
if ( ! mTabChild - > SendNotifyIMEPositionChange ( editorRect , textRectArray ,
caretRect ) ) {
return NS_ERROR_FAILURE ;
}
return NS_OK ;
}
2011-06-22 04:32:43 +04:00
NS_IMETHODIMP
PuppetWidget : : SetCursor ( nsCursor aCursor )
{
2014-05-28 05:12:29 +04:00
if ( mCursor = = aCursor & & ! mUpdateCursor ) {
2012-09-12 08:48:13 +04:00
return NS_OK ;
}
2014-05-28 05:12:29 +04:00
if ( mTabChild & &
! mTabChild - > SendSetCursor ( aCursor , mUpdateCursor ) ) {
2011-06-22 04:32:43 +04:00
return NS_ERROR_FAILURE ;
}
2012-09-12 08:48:13 +04:00
mCursor = aCursor ;
2014-05-28 05:12:29 +04:00
mUpdateCursor = false ;
2012-09-12 08:48:13 +04:00
2011-06-22 04:32:43 +04:00
return NS_OK ;
}
2010-08-21 03:24:40 +04:00
nsresult
2012-08-15 22:52:42 +04:00
PuppetWidget : : Paint ( )
2010-08-21 03:24:40 +04:00
{
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( ! mDirtyRegion . IsEmpty ( ) , " paint event logic messed up " ) ;
2010-08-21 03:24:40 +04:00
2012-08-15 22:53:14 +04:00
if ( ! mAttachedWidgetListener )
2012-08-15 22:52:42 +04:00
return NS_OK ;
nsIntRegion region = mDirtyRegion ;
2010-08-21 03:24:40 +04:00
// reset repaint tracking
mDirtyRegion . SetEmpty ( ) ;
mPaintTask . Revoke ( ) ;
2013-01-28 23:34:08 +04:00
mAttachedWidgetListener - > WillPaintWindow ( this ) ;
2013-01-28 23:34:03 +04:00
if ( mAttachedWidgetListener ) {
2010-08-21 03:24:40 +04:00
# ifdef DEBUG
2012-08-15 22:52:42 +04:00
debug_DumpPaintEvent ( stderr , this , region ,
2012-09-02 06:35:17 +04:00
nsAutoCString ( " PuppetWidget " ) , 0 ) ;
2010-08-21 03:24:40 +04:00
# endif
2015-05-11 07:22:51 +03:00
if ( mozilla : : layers : : LayersBackend : : LAYERS_CLIENT = = mLayerManager - > GetBackendType ( ) ) {
2013-05-01 09:03:25 +04:00
// Do nothing, the compositor will handle drawing
if ( mTabChild ) {
mTabChild - > NotifyPainted ( ) ;
}
2011-08-09 23:38:27 +04:00
} else {
2014-06-10 10:02:21 +04:00
nsRefPtr < gfxContext > ctx = new gfxContext ( mDrawTarget ) ;
2012-02-10 23:22:21 +04:00
ctx - > Rectangle ( gfxRect ( 0 , 0 , 0 , 0 ) ) ;
ctx - > Clip ( ) ;
2011-08-09 23:38:27 +04:00
AutoLayerManagerSetup setupLayerManager ( this , ctx ,
2014-01-23 22:26:41 +04:00
BufferMode : : BUFFER_NONE ) ;
2013-05-23 18:49:18 +04:00
mAttachedWidgetListener - > PaintWindow ( this , region ) ;
2013-04-02 22:32:59 +04:00
if ( mTabChild ) {
mTabChild - > NotifyPainted ( ) ;
}
2011-08-09 23:38:27 +04:00
}
2010-08-21 03:24:40 +04:00
}
2012-12-13 01:57:08 +04:00
if ( mAttachedWidgetListener ) {
mAttachedWidgetListener - > DidPaintWindow ( ) ;
}
2010-08-21 03:24:40 +04:00
return NS_OK ;
}
void
PuppetWidget : : SetChild ( PuppetWidget * aChild )
{
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( this ! = aChild , " can't parent a widget to itself " ) ;
MOZ_ASSERT ( ! aChild - > mChild ,
" fake widget 'hierarchy' only expected to have one level " ) ;
2010-08-21 03:24:40 +04:00
mChild = aChild ;
}
NS_IMETHODIMP
PuppetWidget : : PaintTask : : Run ( )
{
if ( mWidget ) {
2012-08-15 22:52:42 +04:00
mWidget - > Paint ( ) ;
2010-08-21 03:24:40 +04:00
}
return NS_OK ;
}
2015-04-29 06:54:04 +03:00
NS_IMPL_ISUPPORTS ( PuppetWidget : : MemoryPressureObserver , nsIObserver )
NS_IMETHODIMP
PuppetWidget : : MemoryPressureObserver : : Observe ( nsISupports * aSubject ,
const char * aTopic ,
const char16_t * aData )
{
if ( ! mWidget ) {
return NS_OK ;
}
if ( strcmp ( " memory-pressure " , aTopic ) = = 0 ) {
if ( ! mWidget - > mVisible & & mWidget - > mLayerManager ) {
mWidget - > mLayerManager - > ClearCachedResources ( ) ;
}
}
return NS_OK ;
}
void
PuppetWidget : : MemoryPressureObserver : : Remove ( )
{
nsCOMPtr < nsIObserverService > obs = mozilla : : services : : GetObserverService ( ) ;
if ( obs ) {
obs - > RemoveObserver ( this , " memory-pressure " ) ;
}
mWidget = nullptr ;
}
2012-11-08 07:51:55 +04:00
bool
PuppetWidget : : NeedsPaint ( )
{
2014-11-20 20:28:58 +03:00
// e10s popups are handled by the parent process, so never should be painted here
if ( XRE_GetProcessType ( ) = = GeckoProcessType_Content & &
Preferences : : GetBool ( " browser.tabs.remote.desktopbehavior " , false ) & &
mWindowType = = eWindowType_popup ) {
NS_WARNING ( " Trying to paint an e10s popup in the child process! " ) ;
return false ;
}
2012-11-08 07:51:55 +04:00
return mVisible ;
}
2010-12-03 04:24:04 +03:00
float
PuppetWidget : : GetDPI ( )
{
if ( mDPI < 0 ) {
2013-04-02 22:32:59 +04:00
if ( mTabChild ) {
mTabChild - > GetDPI ( & mDPI ) ;
} else {
mDPI = 96.0 ;
}
2010-12-03 04:24:04 +03:00
}
return mDPI ;
}
2013-05-02 03:06:19 +04:00
double
PuppetWidget : : GetDefaultScaleInternal ( )
{
if ( mDefaultScale < 0 ) {
if ( mTabChild ) {
mTabChild - > GetDefaultScale ( & mDefaultScale ) ;
} else {
mDefaultScale = 1 ;
}
}
return mDefaultScale ;
}
2011-08-31 23:01:38 +04:00
void *
2012-08-22 19:56:38 +04:00
PuppetWidget : : GetNativeData ( uint32_t aDataType )
2011-08-31 23:01:38 +04:00
{
2012-05-09 01:36:07 +04:00
switch ( aDataType ) {
case NS_NATIVE_SHAREABLE_WINDOW : {
2015-02-10 01:34:50 +03:00
MOZ_ASSERT ( mTabChild , " Need TabChild to get the nativeWindow from! " ) ;
2012-07-20 15:16:17 +04:00
mozilla : : WindowsHandle nativeData = 0 ;
2013-04-02 22:32:59 +04:00
if ( mTabChild ) {
mTabChild - > SendGetWidgetNativeData ( & nativeData ) ;
}
2012-05-09 01:36:07 +04: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 18:20:58 +04:00
return nullptr ;
2012-05-09 01:36:07 +04:00
}
2014-12-11 17:44:07 +03:00
nsIntPoint
PuppetWidget : : GetChromeDimensions ( )
{
if ( ! GetOwningTabChild ( ) ) {
NS_WARNING ( " PuppetWidget without Tab does not have chrome information. " ) ;
return nsIntPoint ( ) ;
}
2015-04-21 17:33:56 +03:00
return LayoutDeviceIntPoint : : ToUntyped ( GetOwningTabChild ( ) - > GetChromeDisplacement ( ) ) ;
2014-12-11 17:44:07 +03:00
}
nsIntPoint
PuppetWidget : : GetWindowPosition ( )
{
if ( ! GetOwningTabChild ( ) ) {
return nsIntPoint ( ) ;
}
int32_t winX , winY , winW , winH ;
NS_ENSURE_SUCCESS ( GetOwningTabChild ( ) - > GetDimensions ( 0 , & winX , & winY , & winW , & winH ) , nsIntPoint ( ) ) ;
return nsIntPoint ( winX , winY ) ;
}
2015-03-31 23:39:02 +03:00
NS_METHOD
PuppetWidget : : GetScreenBounds ( nsIntRect & aRect ) {
2015-04-21 18:22:30 +03:00
aRect . MoveTo ( LayoutDeviceIntPoint : : ToUntyped ( WidgetToScreenOffset ( ) ) ) ;
2015-03-31 23:39:02 +03:00
aRect . SizeTo ( mBounds . Size ( ) ) ;
return NS_OK ;
}
2015-05-08 04:29:00 +03:00
uint32_t PuppetWidget : : GetMaxTouchPoints ( ) const
{
static uint32_t sTouchPoints = 0 ;
static bool sIsInitialized = false ;
if ( sIsInitialized ) {
return sTouchPoints ;
}
if ( mTabChild ) {
mTabChild - > GetMaxTouchPoints ( & sTouchPoints ) ;
sIsInitialized = true ;
}
return sTouchPoints ;
}
2012-05-09 01:36:07 +04:00
PuppetScreen : : PuppetScreen ( void * nativeScreen )
{
}
PuppetScreen : : ~ PuppetScreen ( )
{
}
static ScreenConfiguration
ScreenConfig ( )
{
ScreenConfiguration config ;
hal : : GetCurrentScreenConfiguration ( & config ) ;
return config ;
}
2014-12-11 17:44:07 +03:00
nsIntSize
PuppetWidget : : GetScreenDimensions ( )
{
nsIntRect r = ScreenConfig ( ) . rect ( ) ;
return nsIntSize ( r . width , r . height ) ;
}
2014-07-14 21:22:26 +04:00
NS_IMETHODIMP
PuppetScreen : : GetId ( uint32_t * outId )
{
* outId = 1 ;
return NS_OK ;
}
2012-05-09 01:36:07 +04:00
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreen : : GetRect ( int32_t * outLeft , int32_t * outTop ,
int32_t * outWidth , int32_t * outHeight )
2012-05-09 01:36:07 +04: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 19:56:38 +04:00
PuppetScreen : : GetAvailRect ( int32_t * outLeft , int32_t * outTop ,
int32_t * outWidth , int32_t * outHeight )
2012-05-09 01:36:07 +04:00
{
return GetRect ( outLeft , outTop , outWidth , outHeight ) ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreen : : GetPixelDepth ( int32_t * aPixelDepth )
2012-05-09 01:36:07 +04:00
{
* aPixelDepth = ScreenConfig ( ) . pixelDepth ( ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreen : : GetColorDepth ( int32_t * aColorDepth )
2012-05-09 01:36:07 +04:00
{
* aColorDepth = ScreenConfig ( ) . colorDepth ( ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreen : : GetRotation ( uint32_t * aRotation )
2012-05-09 01:36:07 +04: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 19:56:38 +04:00
PuppetScreen : : SetRotation ( uint32_t aRotation )
2012-05-09 01:36:07 +04: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 ;
}
2014-04-27 11:06:00 +04:00
NS_IMPL_ISUPPORTS ( PuppetScreenManager , nsIScreenManager )
2012-05-09 01:36:07 +04:00
PuppetScreenManager : : PuppetScreenManager ( )
{
2012-07-30 18:20:58 +04:00
mOneScreen = new PuppetScreen ( nullptr ) ;
2012-05-09 01:36:07 +04:00
}
PuppetScreenManager : : ~ PuppetScreenManager ( )
{
}
2014-07-14 21:22:26 +04:00
NS_IMETHODIMP
PuppetScreenManager : : ScreenForId ( uint32_t aId ,
nsIScreen * * outScreen )
{
NS_IF_ADDREF ( * outScreen = mOneScreen . get ( ) ) ;
return NS_OK ;
}
2012-05-09 01:36:07 +04:00
NS_IMETHODIMP
PuppetScreenManager : : GetPrimaryScreen ( nsIScreen * * outScreen )
{
NS_IF_ADDREF ( * outScreen = mOneScreen . get ( ) ) ;
return NS_OK ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreenManager : : ScreenForRect ( int32_t inLeft ,
int32_t inTop ,
int32_t inWidth ,
int32_t inHeight ,
2012-05-09 01:36:07 +04:00
nsIScreen * * outScreen )
{
return GetPrimaryScreen ( outScreen ) ;
}
NS_IMETHODIMP
PuppetScreenManager : : ScreenForNativeWidget ( void * aWidget ,
nsIScreen * * outScreen )
{
return GetPrimaryScreen ( outScreen ) ;
}
NS_IMETHODIMP
2012-08-22 19:56:38 +04:00
PuppetScreenManager : : GetNumberOfScreens ( uint32_t * aNumberOfScreens )
2012-05-09 01:36:07 +04:00
{
* aNumberOfScreens = 1 ;
return NS_OK ;
2011-08-31 23:01:38 +04:00
}
2013-04-10 01:07:02 +04:00
NS_IMETHODIMP
PuppetScreenManager : : GetSystemDefaultScale ( float * aDefaultScale )
{
* aDefaultScale = 1.0f ;
return NS_OK ;
}
2010-08-21 03:24:40 +04:00
} // namespace widget
} // namespace mozilla