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"
|
2017-04-13 08:46:28 +03:00
|
|
|
#include "mozilla/dom/TabGroup.h"
|
2017-02-14 21:15:50 +03:00
|
|
|
#include "mozilla/gfx/gfxVars.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"
|
2016-01-08 22:17:39 +03:00
|
|
|
#include "mozilla/layers/APZChild.h"
|
2013-04-24 22:42:40 +04:00
|
|
|
#include "mozilla/layers/PLayerTransactionChild.h"
|
2016-11-16 16:54:51 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.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"
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-02-12 22:38:34 +03:00
|
|
|
#include "BasicLayers.h"
|
2010-08-21 03:24:40 +04:00
|
|
|
#include "PuppetWidget.h"
|
2015-10-26 19:14:47 +03:00
|
|
|
#include "nsContentUtils.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsIWidgetListener.h"
|
2016-05-27 23:46:25 +03:00
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsView.h"
|
2017-05-08 14:07:56 +03:00
|
|
|
#include "nsPrintfCString.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
|
2015-11-23 07:32:29 +03:00
|
|
|
InvalidateRegion(nsIWidget* aWidget, const LayoutDeviceIntRegion& aRegion)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
2016-01-19 04:20:59 +03:00
|
|
|
for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) {
|
|
|
|
aWidget->Invalidate(iter.Get());
|
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;
|
|
|
|
|
2017-02-17 21:59:12 +03:00
|
|
|
static bool gRemoteDesktopBehaviorEnabled = false;
|
|
|
|
static bool gRemoteDesktopBehaviorInitialized = false;
|
|
|
|
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(PuppetWidget, nsBaseWidget
|
|
|
|
, TextEventDispatcherListener)
|
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)
|
2015-05-20 10:45:41 +03:00
|
|
|
, mMemoryPressureObserver(nullptr)
|
2010-12-03 04:24:04 +03:00
|
|
|
, mDPI(-1)
|
2017-05-19 13:20:18 +03:00
|
|
|
, mRounding(1)
|
2013-05-02 03:06:19 +04:00
|
|
|
, mDefaultScale(-1)
|
2015-05-20 04:28:57 +03:00
|
|
|
, mCursorHotspotX(0)
|
|
|
|
, mCursorHotspotY(0)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 05:27:56 +03:00
|
|
|
// Setting 'Unknown' means "not yet cached".
|
|
|
|
mInputContext.mIMEState.mEnabled = IMEState::UNKNOWN;
|
2017-02-17 21:59:12 +03:00
|
|
|
|
|
|
|
if (!gRemoteDesktopBehaviorInitialized) {
|
|
|
|
Preferences::AddBoolVarCache(&gRemoteDesktopBehaviorEnabled, "browser.tabs.remote.desktopbehavior", false);
|
|
|
|
gRemoteDesktopBehaviorInitialized = true;
|
|
|
|
}
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PuppetWidget::~PuppetWidget()
|
|
|
|
{
|
2015-05-21 11:08:43 +03:00
|
|
|
Destroy();
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
2016-08-19 02:03:17 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::InfallibleCreate(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const LayoutDeviceIntRect& aRect,
|
|
|
|
nsWidgetInitData* aInitData)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
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
|
|
|
|
2016-01-13 10:32:55 +03:00
|
|
|
BaseCreate(nullptr, aInitData);
|
2010-08-21 03:24:40 +04:00
|
|
|
|
2015-11-23 07:32:29 +03: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-05-20 10:45:41 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
mMemoryPressureObserver = new MemoryPressureObserver(this);
|
|
|
|
obs->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
|
|
|
|
}
|
2016-08-19 02:03:17 +03:00
|
|
|
}
|
2010-08-21 03:24:40 +04:00
|
|
|
|
2016-08-19 02:03:17 +03:00
|
|
|
nsresult
|
|
|
|
PuppetWidget::Create(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const LayoutDeviceIntRect& aRect,
|
|
|
|
nsWidgetInitData* aInitData)
|
|
|
|
{
|
|
|
|
InfallibleCreate(aParent, aNativeParent, aRect, aInitData);
|
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) {
|
2015-06-05 12:28:20 +03:00
|
|
|
mContentCache.Clear();
|
2015-07-17 07:30:01 +03:00
|
|
|
mTabChild->SendUpdateContentCache(mContentCache);
|
2017-04-11 15:24:55 +03:00
|
|
|
mIMENotificationRequestsOfParent = IMENotificationRequests();
|
2012-08-29 19:26:18 +04:00
|
|
|
mNeedIMEStateInit = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
already_AddRefed<nsIWidget>
|
2015-11-16 11:35:18 +03:00
|
|
|
PuppetWidget::CreateChild(const LayoutDeviceIntRect& aRect,
|
|
|
|
nsWidgetInitData* aInitData,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-08-10 03:04:11 +03:00
|
|
|
void
|
2010-08-21 03:24:40 +04:00
|
|
|
PuppetWidget::Destroy()
|
|
|
|
{
|
2015-12-11 09:15:58 +03:00
|
|
|
if (mOnDestroyCalled) {
|
2016-08-10 03:04:11 +03:00
|
|
|
return;
|
2015-12-11 09:15:58 +03:00
|
|
|
}
|
|
|
|
mOnDestroyCalled = true;
|
|
|
|
|
2011-03-30 00:14:44 +04:00
|
|
|
Base::OnDestroy();
|
2010-08-21 03:24:40 +04:00
|
|
|
Base::Destroy();
|
|
|
|
mPaintTask.Revoke();
|
2015-05-20 10:45:41 +03:00
|
|
|
if (mMemoryPressureObserver) {
|
|
|
|
mMemoryPressureObserver->Remove();
|
|
|
|
}
|
|
|
|
mMemoryPressureObserver = nullptr;
|
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
|
|
|
}
|
|
|
|
|
2016-12-21 03:12:54 +03:00
|
|
|
void
|
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) {
|
2016-12-16 23:54:49 +03:00
|
|
|
// The previously attached widget listener is handy if
|
|
|
|
// we're transitioning from page to page without dropping
|
|
|
|
// layers (since we'll continue to show the old layers
|
|
|
|
// associated with that old widget listener). If the
|
|
|
|
// PuppetWidget was hidden, those layers are dropped,
|
|
|
|
// so the previously attached widget listener is really
|
|
|
|
// of no use anymore (and is actually actively harmful - see
|
|
|
|
// bug 1323586).
|
|
|
|
mPreviouslyAttachedWidgetListener = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
Resize(mBounds.width, mBounds.height, false);
|
2015-11-23 07:32:29 +03:00
|
|
|
Invalidate(mBounds);
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 12:54:03 +03:00
|
|
|
void
|
2012-12-12 13:57:38 +04:00
|
|
|
PuppetWidget::Resize(double aWidth,
|
|
|
|
double aHeight,
|
|
|
|
bool aRepaint)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
2015-11-23 07:32:29 +03:00
|
|
|
LayoutDeviceIntRect oldBounds = mBounds;
|
|
|
|
mBounds.SizeTo(LayoutDeviceIntSize(NSToIntRound(aWidth),
|
|
|
|
NSToIntRound(aHeight)));
|
2010-08-21 03:24:40 +04:00
|
|
|
|
|
|
|
if (mChild) {
|
2016-12-19 12:54:03 +03:00
|
|
|
mChild->Resize(aWidth, aHeight, aRepaint);
|
|
|
|
return;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: roc says that |aRepaint| dictates whether or not to
|
|
|
|
// invalidate the expanded area
|
|
|
|
if (oldBounds.Size() < mBounds.Size() && aRepaint) {
|
2015-11-23 07:32:29 +03:00
|
|
|
LayoutDeviceIntRegion dirty(mBounds);
|
|
|
|
dirty.Sub(dirty, oldBounds);
|
2010-08-21 03:24:40 +04:00
|
|
|
InvalidateRegion(this, dirty);
|
|
|
|
}
|
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
// call WindowResized() on both the current listener, and possibly
|
|
|
|
// also the previous one if we're in a state where we're drawing that one
|
|
|
|
// because the current one is paint suppressed
|
2012-08-15 22:53:14 +04:00
|
|
|
if (!oldBounds.IsEqualEdges(mBounds) && mAttachedWidgetListener) {
|
2015-07-22 04:09:02 +03:00
|
|
|
if (GetCurrentWidgetListener() &&
|
|
|
|
GetCurrentWidgetListener() != mAttachedWidgetListener) {
|
|
|
|
GetCurrentWidgetListener()->WindowResized(this, mBounds.width, mBounds.height);
|
|
|
|
}
|
2012-08-15 22:53:14 +04:00
|
|
|
mAttachedWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
2015-05-25 21:45:00 +03:00
|
|
|
PuppetWidget* w = static_cast<PuppetWidget*>(configuration.mChild.get());
|
2014-11-12 23:59:19 +03:00
|
|
|
NS_ASSERTION(w->GetParent() == this,
|
|
|
|
"Configured widget is not a child");
|
|
|
|
w->SetWindowClipRegion(configuration.mClipRegion, true);
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect bounds = w->GetBounds();
|
2014-11-12 23:59:19 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-12-21 03:13:08 +03:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
PuppetWidget::SetFocus(bool aRaise)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
2015-10-06 16:14:49 +03:00
|
|
|
if (aRaise && mTabChild) {
|
|
|
|
mTabChild->SendRequestFocus(true);
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-20 01:55:32 +03:00
|
|
|
void
|
2015-11-17 08:18:31 +03:00
|
|
|
PuppetWidget::Invalidate(const LayoutDeviceIntRect& aRect)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2016-03-31 21:42:13 +03:00
|
|
|
debug_DumpInvalidate(stderr, this, &aRect, "PuppetWidget", 0);
|
2010-08-21 03:24:40 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mChild) {
|
2016-12-20 01:55:32 +03:00
|
|
|
mChild->Invalidate(aRect);
|
|
|
|
return;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDirtyRegion.Or(mDirtyRegion, aRect);
|
|
|
|
|
2017-04-13 08:46:28 +03:00
|
|
|
if (mTabChild && !mDirtyRegion.IsEmpty() && !mPaintTask.IsPending()) {
|
2010-08-21 03:24:40 +04:00
|
|
|
mPaintTask = new PaintTask(this);
|
2017-04-13 08:46:28 +03:00
|
|
|
nsCOMPtr<nsIRunnable> event(mPaintTask.get());
|
2017-07-26 11:13:35 +03:00
|
|
|
mTabChild->TabGroup()->Dispatch(TaskCategory::Other, event.forget());
|
2016-12-20 01:55:32 +03:00
|
|
|
return;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:28:15 +04:00
|
|
|
void
|
2017-01-19 11:27:15 +03:00
|
|
|
PuppetWidget::InitEvent(WidgetGUIEvent& aEvent, LayoutDeviceIntPoint* aPoint)
|
2010-09-24 07:28:15 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr == aPoint) {
|
2017-01-19 11:27:15 +03:00
|
|
|
aEvent.mRefPoint = LayoutDeviceIntPoint(0, 0);
|
2015-11-10 08:37:32 +03:00
|
|
|
} else {
|
2010-09-24 07:28:15 +04:00
|
|
|
// use the point override if provided
|
2017-01-19 11:27:15 +03:00
|
|
|
aEvent.mRefPoint = *aPoint;
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
2017-01-19 11:27:15 +03:00
|
|
|
aEvent.mTime = PR_Now() / 1000;
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2016-12-21 03:18:40 +03:00
|
|
|
nsresult
|
2017-01-19 11:27:15 +03:00
|
|
|
PuppetWidget::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2017-01-19 11:27:15 +03:00
|
|
|
debug_DumpEvent(stdout, aEvent->mWidget, aEvent, "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
|
|
|
|
2017-05-19 11:24:20 +03:00
|
|
|
MOZ_ASSERT(!aEvent->AsKeyboardEvent() ||
|
|
|
|
aEvent->mFlags.mIsSynthesizedForTests ||
|
|
|
|
aEvent->AsKeyboardEvent()->AreAllEditCommandsInitialized(),
|
|
|
|
"Non-sysnthesized keyboard events should have edit commands for all types "
|
|
|
|
"before dispatched");
|
|
|
|
|
2017-01-19 11:27:15 +03:00
|
|
|
if (aEvent->mClass == eCompositionEventClass) {
|
2015-12-11 09:15:57 +03:00
|
|
|
// Store the latest native IME context of parent process's widget or
|
|
|
|
// TextEventDispatcher if it's in this process.
|
2017-01-19 11:27:15 +03:00
|
|
|
WidgetCompositionEvent* compositionEvent = aEvent->AsCompositionEvent();
|
2015-12-11 09:15:57 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (mNativeIMEContext.IsValid() &&
|
|
|
|
mNativeIMEContext != compositionEvent->mNativeIMEContext) {
|
|
|
|
RefPtr<TextComposition> composition =
|
|
|
|
IMEStateManager::GetTextCompositionFor(this);
|
|
|
|
MOZ_ASSERT(!composition,
|
|
|
|
"When there is composition caused by old native IME context, "
|
|
|
|
"composition events caused by different native IME context are not "
|
|
|
|
"allowed");
|
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
mNativeIMEContext = compositionEvent->mNativeIMEContext;
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:27:31 +03:00
|
|
|
// If the event is a composition event or a keyboard event, it should be
|
|
|
|
// dispatched with TextEventDispatcher if we could do that with current
|
|
|
|
// design. However, we cannot do that without big changes and the behavior
|
|
|
|
// is not so complicated for now. Therefore, we should just notify it
|
|
|
|
// of dispatching events and TextEventDispatcher should emulate the state
|
|
|
|
// with events here.
|
|
|
|
if (aEvent->mClass == eCompositionEventClass ||
|
|
|
|
aEvent->mClass == eKeyboardEventClass) {
|
|
|
|
TextEventDispatcher* dispatcher = GetTextEventDispatcher();
|
|
|
|
// However, if the event is being dispatched by the text event dispatcher
|
|
|
|
// or, there is native text event dispatcher listener, that means that
|
|
|
|
// native text input event handler is in this process like on Android,
|
|
|
|
// and the event is not synthesized for tests, the event is coming from
|
|
|
|
// the TextEventDispatcher. In these cases, we shouldn't notify
|
|
|
|
// TextEventDispatcher of dispatching the event.
|
|
|
|
if (!dispatcher->IsDispatchingEvent() &&
|
|
|
|
!(mNativeTextEventDispatcherListener &&
|
|
|
|
!aEvent->mFlags.mIsSynthesizedForTests)) {
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
dispatcher->BeginInputTransactionFor(aEvent, this);
|
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"The text event dispatcher should always succeed to start input "
|
|
|
|
"transaction for the event");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
2011-02-09 23:13:18 +03:00
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
if (GetCurrentWidgetListener()) {
|
2017-01-19 11:27:15 +03:00
|
|
|
aStatus =
|
|
|
|
GetCurrentWidgetListener()->HandleEvent(aEvent, mUseAttachedEvents);
|
2013-01-25 23:51:16 +04:00
|
|
|
}
|
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)
|
2015-03-07 01:26:59 +03:00
|
|
|
{
|
2015-06-04 23:51:10 +03:00
|
|
|
if (!AsyncPanZoomEnabled()) {
|
2015-03-07 01:26:59 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
DispatchEvent(aEvent, status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTabChild) {
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent->mClass) {
|
|
|
|
case eWheelEventClass:
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused <<
|
2015-03-25 01:00:52 +03:00
|
|
|
mTabChild->SendDispatchWheelEvent(*aEvent->AsWheelEvent());
|
2015-03-07 01:26:59 +03:00
|
|
|
break;
|
2016-03-11 02:25:48 +03:00
|
|
|
case eMouseEventClass:
|
|
|
|
Unused <<
|
|
|
|
mTabChild->SendDispatchMouseEvent(*aEvent->AsMouseEvent());
|
|
|
|
break;
|
|
|
|
case eKeyboardEventClass:
|
|
|
|
Unused <<
|
|
|
|
mTabChild->SendDispatchKeyboardEvent(*aEvent->AsKeyboardEvent());
|
|
|
|
break;
|
2015-03-07 01:26:59 +03:00
|
|
|
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,
|
2017-01-19 11:57:20 +03:00
|
|
|
aModifierFlags, nsString(aCharacters),
|
|
|
|
nsString(aUnmodifiedCharacters),
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
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,
|
2017-01-19 11:57:20 +03:00
|
|
|
aModifierFlags,
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
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
|
2017-01-19 11:57:20 +03:00
|
|
|
PuppetWidget::SynthesizeNativeMouseScrollEvent(
|
|
|
|
mozilla::LayoutDeviceIntPoint aPoint,
|
|
|
|
uint32_t aNativeMessage,
|
|
|
|
double aDeltaX,
|
|
|
|
double aDeltaY,
|
|
|
|
double aDeltaZ,
|
|
|
|
uint32_t aModifierFlags,
|
|
|
|
uint32_t aAdditionalFlags,
|
|
|
|
nsIObserver* aObserver)
|
2015-04-14 18:36:36 +03:00
|
|
|
{
|
|
|
|
AutoObserverNotifier notifier(aObserver, "mousescrollevent");
|
|
|
|
if (!mTabChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mTabChild->SendSynthesizeNativeMouseScrollEvent(aPoint, aNativeMessage,
|
2017-01-19 11:57:20 +03:00
|
|
|
aDeltaX, aDeltaY, aDeltaZ,
|
|
|
|
aModifierFlags,
|
|
|
|
aAdditionalFlags,
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PuppetWidget::SynthesizeNativeTouchPoint(uint32_t aPointerId,
|
|
|
|
TouchPointerState aPointerState,
|
2016-04-15 13:39:36 +03:00
|
|
|
LayoutDeviceIntPoint aPoint,
|
2015-04-14 18:36:36 +03:00
|
|
|
double aPointerPressure,
|
|
|
|
uint32_t aPointerOrientation,
|
|
|
|
nsIObserver* aObserver)
|
|
|
|
{
|
|
|
|
AutoObserverNotifier notifier(aObserver, "touchpoint");
|
|
|
|
if (!mTabChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mTabChild->SendSynthesizeNativeTouchPoint(aPointerId, aPointerState,
|
2017-01-19 11:57:20 +03:00
|
|
|
aPoint, aPointerPressure,
|
|
|
|
aPointerOrientation,
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-04-15 13:39:36 +03:00
|
|
|
PuppetWidget::SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
|
2015-04-14 18:36:36 +03:00
|
|
|
bool aLongTap,
|
|
|
|
nsIObserver* aObserver)
|
|
|
|
{
|
|
|
|
AutoObserverNotifier notifier(aObserver, "touchtap");
|
|
|
|
if (!mTabChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-04-15 13:39:36 +03:00
|
|
|
mTabChild->SendSynthesizeNativeTouchTap(aPoint, aLongTap,
|
2017-01-19 11:57:20 +03:00
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
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;
|
|
|
|
}
|
2017-05-08 14:07:56 +03:00
|
|
|
|
2015-04-14 19:24:32 +03:00
|
|
|
void
|
2017-01-19 11:57:20 +03:00
|
|
|
PuppetWidget::SetConfirmedTargetAPZC(
|
|
|
|
uint64_t aInputBlockId,
|
|
|
|
const nsTArray<ScrollableLayerGuid>& aTargets) const
|
2015-04-14 19:24:32 +03:00
|
|
|
{
|
|
|
|
if (mTabChild) {
|
2016-01-08 22:17:39 +03:00
|
|
|
mTabChild->SetTargetAPZC(aInputBlockId, aTargets);
|
2015-04-14 19:24:32 +03:00
|
|
|
}
|
|
|
|
}
|
2015-04-14 18:36:36 +03:00
|
|
|
|
2015-06-17 19:32:42 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::UpdateZoomConstraints(const uint32_t& aPresShellId,
|
|
|
|
const FrameMetrics::ViewID& aViewId,
|
|
|
|
const Maybe<ZoomConstraints>& aConstraints)
|
|
|
|
{
|
|
|
|
if (mTabChild) {
|
|
|
|
mTabChild->DoUpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 23:51:10 +03:00
|
|
|
bool
|
|
|
|
PuppetWidget::AsyncPanZoomEnabled() const
|
|
|
|
{
|
|
|
|
return mTabChild && mTabChild->AsyncPanZoomEnabled();
|
|
|
|
}
|
|
|
|
|
2017-05-19 11:49:41 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::GetEditCommands(NativeKeyBindingsType aType,
|
|
|
|
const WidgetKeyboardEvent& aEvent,
|
|
|
|
nsTArray<CommandInt>& aCommands)
|
2014-03-20 19:46:29 +04:00
|
|
|
{
|
2017-05-19 11:49:41 +03:00
|
|
|
// Validate the arguments.
|
|
|
|
nsIWidget::GetEditCommands(aType, aEvent, aCommands);
|
2014-03-20 19:46:29 +04:00
|
|
|
|
2017-05-19 12:46:02 +03:00
|
|
|
mTabChild->RequestEditCommands(aType, aEvent, aCommands);
|
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,
|
2016-06-24 03:53:27 +03:00
|
|
|
LayerManagerPersistence aPersistence)
|
2010-08-21 03:24:40 +04:00
|
|
|
{
|
|
|
|
if (!mLayerManager) {
|
2017-02-12 22:38:34 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// On the parent process there is no CompositorBridgeChild which confuses
|
|
|
|
// some layers code, so we use basic layers instead. Note that we create
|
|
|
|
// a non-retaining layer manager since we don't care about performance.
|
|
|
|
mLayerManager = new BasicLayerManager(BasicLayerManager::BLM_OFFSCREEN);
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2017-10-13 17:32:36 +03:00
|
|
|
// If we know for sure that the parent side of this TabChild is not
|
|
|
|
// connected to the compositor, we don't want to use a "remote" layer
|
|
|
|
// manager like WebRender or Client. Instead we use a Basic one which
|
|
|
|
// can do drawing in this process.
|
|
|
|
MOZ_ASSERT(!mTabChild || mTabChild->IsLayersConnected() != Some(true));
|
|
|
|
mLayerManager = new BasicLayerManager(this);
|
2013-11-01 10:36:02 +04:00
|
|
|
}
|
2017-02-12 22:38:34 +03:00
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2017-07-18 16:35:07 +03:00
|
|
|
bool
|
2017-10-13 17:32:36 +03:00
|
|
|
PuppetWidget::CreateRemoteLayerManager(const std::function<bool(LayerManager*)>& aInitializeFunc)
|
2016-09-20 11:19:32 +03:00
|
|
|
{
|
2017-07-18 16:35:07 +03:00
|
|
|
RefPtr<LayerManager> lm;
|
2017-01-24 16:03:08 +03:00
|
|
|
MOZ_ASSERT(mTabChild);
|
2017-11-03 10:38:34 +03:00
|
|
|
if (mTabChild->GetCompositorOptions().UseWebRender()) {
|
2017-07-18 16:35:07 +03:00
|
|
|
lm = new WebRenderLayerManager(this);
|
2016-12-04 11:40:52 +03:00
|
|
|
} else {
|
2017-07-18 16:35:07 +03:00
|
|
|
lm = new ClientLayerManager(this);
|
2016-12-04 11:40:52 +03:00
|
|
|
}
|
2017-07-18 16:35:07 +03:00
|
|
|
|
|
|
|
if (!aInitializeFunc(lm)) {
|
|
|
|
return false;
|
2016-11-08 18:42:26 +03:00
|
|
|
}
|
2017-07-18 16:35:07 +03:00
|
|
|
|
|
|
|
// Force the old LM to self destruct, otherwise if the reference dangles we
|
|
|
|
// could fail to revoke the most recent transaction. We only want to replace
|
|
|
|
// it if we successfully create its successor because a partially initialized
|
|
|
|
// layer manager is worse than a fully initialized but shutdown layer manager.
|
|
|
|
DestroyLayerManager();
|
|
|
|
mLayerManager = lm.forget();
|
|
|
|
return true;
|
2016-09-20 11:19:32 +03:00
|
|
|
}
|
|
|
|
|
2010-09-24 07:28:15 +04:00
|
|
|
nsresult
|
2015-12-11 09:15:58 +03:00
|
|
|
PuppetWidget::RequestIMEToCommitComposition(bool aCancel)
|
2010-09-24 07:28:15 +04:00
|
|
|
{
|
2015-12-11 09:15:58 +03:00
|
|
|
if (!mTabChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!Destroyed());
|
2013-01-29 03:56:28 +04:00
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
// There must not be composition which is caused by the PuppetWidget instance.
|
|
|
|
if (NS_WARN_IF(!mNativeIMEContext.IsValid())) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
RefPtr<TextComposition> composition =
|
|
|
|
IMEStateManager::GetTextCompositionFor(this);
|
|
|
|
// This method shouldn't be called when there is no text composition instance.
|
|
|
|
if (NS_WARN_IF(!composition)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCommitted = false;
|
|
|
|
nsAutoString committedString;
|
|
|
|
if (NS_WARN_IF(!mTabChild->SendRequestIMEToCommitComposition(
|
|
|
|
aCancel, &isCommitted, &committedString))) {
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-12-15 22:22:15 +03:00
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
// If the composition wasn't committed synchronously, we need to wait async
|
|
|
|
// composition events for destroying the TextComposition instance.
|
|
|
|
if (!isCommitted) {
|
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-12-11 09:15:58 +03:00
|
|
|
// Dispatch eCompositionCommit event.
|
|
|
|
WidgetCompositionEvent compositionCommitEvent(true, eCompositionCommit, this);
|
|
|
|
InitEvent(compositionCommitEvent, nullptr);
|
|
|
|
compositionCommitEvent.mData = committedString;
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-02-17 05:30:38 +03:00
|
|
|
DispatchEvent(&compositionCommitEvent, status);
|
2015-12-11 09:15:58 +03:00
|
|
|
|
2017-06-27 17:41:12 +03:00
|
|
|
Unused <<
|
|
|
|
mTabChild->SendOnEventNeedingAckHandled(eCompositionCommitRequestHandled);
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
// NOTE: PuppetWidget might be destroyed already.
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-16 02:55:18 +03:00
|
|
|
nsresult
|
2015-02-20 19:37:02 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-25 06:43:27 +03:00
|
|
|
void
|
2015-02-20 19:37:02 +03:00
|
|
|
PuppetWidget::SetPluginFocused(bool& aFocused)
|
|
|
|
{
|
2016-08-25 06:43:27 +03:00
|
|
|
if (mTabChild) {
|
|
|
|
mTabChild->SendSetPluginFocused(aFocused);
|
2015-02-20 19:37:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::DefaultProcOfPluginEvent(const WidgetPluginEvent& aEvent)
|
|
|
|
{
|
|
|
|
if (!mTabChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mTabChild->SendDefaultProcOfPluginEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
2016-12-21 07:27:20 +03:00
|
|
|
void
|
2011-11-27 15:51:52 +04:00
|
|
|
PuppetWidget::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-09-24 07:28:15 +04:00
|
|
|
{
|
2015-10-10 04:21:02 +03:00
|
|
|
mInputContext = aContext;
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 05:27:56 +03:00
|
|
|
// Any widget instances cannot cache IME open state because IME open state
|
|
|
|
// can be changed by user but native IME may not notify us of changing the
|
|
|
|
// open state on some platforms.
|
|
|
|
mInputContext.mIMEState.mOpen = IMEState::OPEN_STATE_NOT_SUPPORTED;
|
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,
|
2017-07-30 20:45:03 +03:00
|
|
|
aContext.mInPrivateBrowsing,
|
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
|
|
|
}
|
|
|
|
|
2016-12-21 07:27:20 +03:00
|
|
|
InputContext
|
2011-11-27 15:51:52 +04:00
|
|
|
PuppetWidget::GetInputContext()
|
2010-09-24 07:28:15 +04:00
|
|
|
{
|
Bug 1251063 PuppetWidget should cache InputContext which is set with SetInputContext() and use it in GetInputContext() only when it is the widget which has active input context in the process r=smaug
PuppetWidget::GetInputContext() needs to communicate with its parent process with synchronous IPC. This is very expensive for focus move.
Currently, IMEStateManager uses nsIWidget::GetInputContext() only for checking the IME enabled state. Therefore, it's enough to cache input context when nsIWidget::SetInputContext() is called. Then, we can avoid to communicate with synchronous IPC with PuppetWidget::GetInputContext() in most cases.
This patch makes IMEStateManager stores the last widget which sets input context. When PuppetWidget uses its input context cache, it should check if it is the last widget to set input context with IMEStateManager since an input context may be shared with other widgets and another one may have update the input context. I.e., PuppetWidget's input context cache may be already outdated after IMEStateManager sets input context with another widget.
This patch gives up to support retrieving IME open state from child process. However, perhaps, this is not necessary for everybody including add-on developers because the only user of IME open state in child process is nsIDOMWindowUtils. So, add-ons can send IME open state from chrome process instead. If this decision is wrong, unfortunately, we should support it again in another bug. It's easy to support with creating another nsIWidget::GetInputContext() or adding additional argument to it.
MozReview-Commit-ID: B2d2CCTsPKj
--HG--
extra : rebase_source : 4117330ba7871753176da960063b612e96f11752
2016-05-28 05:27:56 +03:00
|
|
|
// XXX Currently, we don't support retrieving IME open state from child
|
|
|
|
// process.
|
|
|
|
|
|
|
|
// When this widget caches input context and currently managed by
|
|
|
|
// IMEStateManager, the cache is valid. Only in this case, we can
|
|
|
|
// avoid to use synchronous IPC.
|
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::UNKNOWN &&
|
|
|
|
IMEStateManager::GetWidgetForActiveInputContext() == this) {
|
|
|
|
return mInputContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("PuppetWidget::GetInputContext() needs to retrieve it with IPC");
|
|
|
|
|
|
|
|
// Don't cache InputContext here because this process isn't managing IME
|
|
|
|
// state of the chrome widget. So, we cannot modify mInputContext when
|
|
|
|
// chrome widget is set to new context.
|
2011-11-27 15:51:52 +04:00
|
|
|
InputContext context;
|
|
|
|
if (mTabChild) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t enabled, open;
|
2015-12-11 09:15:57 +03:00
|
|
|
mTabChild->SendGetInputContext(&enabled, &open);
|
2011-11-27 15:51:53 +04:00
|
|
|
context.mIMEState.mEnabled = static_cast<IMEState::Enabled>(enabled);
|
|
|
|
context.mIMEState.mOpen = static_cast<IMEState::Open>(open);
|
2011-11-27 15:51:52 +04:00
|
|
|
}
|
|
|
|
return context;
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2016-12-21 07:27:20 +03:00
|
|
|
NativeIMEContext
|
2015-12-11 09:15:57 +03:00
|
|
|
PuppetWidget::GetNativeIMEContext()
|
|
|
|
{
|
|
|
|
return mNativeIMEContext;
|
|
|
|
}
|
|
|
|
|
2013-03-06 10:14:31 +04:00
|
|
|
nsresult
|
2015-06-05 12:28:20 +03:00
|
|
|
PuppetWidget::NotifyIMEOfFocusChange(const IMENotification& aIMENotification)
|
2010-09-24 07:28:15 +04:00
|
|
|
{
|
2017-01-19 11:57:20 +03:00
|
|
|
if (!mTabChild) {
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-01-19 11:57:20 +03:00
|
|
|
}
|
2010-09-24 07:28:15 +04:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
bool gotFocus = aIMENotification.mMessage == NOTIFY_IME_OF_FOCUS;
|
|
|
|
if (gotFocus) {
|
2015-10-10 04:21:02 +03:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN) {
|
|
|
|
// When IME gets focus, we should initalize all information of the
|
|
|
|
// content.
|
|
|
|
if (NS_WARN_IF(!mContentCache.CacheAll(this, &aIMENotification))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// However, if a plugin has focus, only the editor rect information is
|
|
|
|
// available.
|
|
|
|
if (NS_WARN_IF(!mContentCache.CacheEditorRect(this, &aIMENotification))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
2015-06-05 12:28:20 +03:00
|
|
|
// When IME loses focus, we don't need to store anything.
|
2015-06-05 12:28:20 +03:00
|
|
|
mContentCache.Clear();
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2017-05-08 14:07:56 +03:00
|
|
|
mIMENotificationRequestsOfParent =
|
|
|
|
IMENotificationRequests(IMENotificationRequests::NOTIFY_ALL);
|
|
|
|
RefPtr<PuppetWidget> self = this;
|
|
|
|
mTabChild->SendNotifyIMEFocus(mContentCache, aIMENotification)->Then(
|
|
|
|
mTabChild->TabGroup()->EventTargetFor(TaskCategory::UI),
|
|
|
|
__func__,
|
|
|
|
[self] (IMENotificationRequests aRequests) {
|
|
|
|
self->mIMENotificationRequestsOfParent = aRequests;
|
|
|
|
},
|
2017-11-16 23:12:06 +03:00
|
|
|
[self] (mozilla::ipc::ResponseRejectReason aReason) {
|
2017-05-08 14:07:56 +03:00
|
|
|
NS_WARNING("SendNotifyIMEFocus got rejected.");
|
|
|
|
});
|
|
|
|
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-07 04:11:11 +04:00
|
|
|
nsresult
|
2015-07-17 07:30:01 +03:00
|
|
|
PuppetWidget::NotifyIMEOfCompositionUpdate(
|
2015-06-05 12:28:20 +03:00
|
|
|
const IMENotification& aIMENotification)
|
2013-11-07 04:11:11 +04:00
|
|
|
{
|
2017-01-19 11:57:20 +03:00
|
|
|
if (NS_WARN_IF(!mTabChild)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2013-11-07 04:11:11 +04:00
|
|
|
|
2015-10-10 04:21:02 +03:00
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
|
|
|
NS_WARN_IF(!mContentCache.CacheSelection(this, &aIMENotification))) {
|
2014-12-15 12:37:00 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2015-07-17 07:30:01 +03:00
|
|
|
mTabChild->SendNotifyIMECompositionUpdate(mContentCache, aIMENotification);
|
2014-12-15 12:37:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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");
|
2017-01-19 11:57:20 +03:00
|
|
|
if (!mTabChild) {
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-01-19 11:57:20 +03:00
|
|
|
}
|
2010-09-24 07:28:15 +04:00
|
|
|
|
2015-10-10 04:21:02 +03:00
|
|
|
// While a plugin has focus, text change notification shouldn't be available.
|
|
|
|
if (NS_WARN_IF(mInputContext.mIMEState.mEnabled == IMEState::PLUGIN)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
// FYI: text change notification is the first notification after
|
|
|
|
// a user operation changes the content. So, we need to modify
|
|
|
|
// the cache as far as possible here.
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (NS_WARN_IF(!mContentCache.CacheText(this, &aIMENotification))) {
|
2015-06-05 12:28:20 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
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.
|
2017-04-11 15:24:55 +03:00
|
|
|
if (mIMENotificationRequestsOfParent.WantTextChange()) {
|
2015-07-17 07:30:01 +03:00
|
|
|
mTabChild->SendNotifyIMETextChange(mContentCache, aIMENotification);
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
|
|
|
mTabChild->SendUpdateContentCache(mContentCache);
|
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");
|
2017-01-19 11:57:20 +03:00
|
|
|
if (!mTabChild) {
|
2010-09-24 07:28:15 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2017-01-19 11:57:20 +03:00
|
|
|
}
|
2010-09-24 07:28:15 +04:00
|
|
|
|
2015-10-10 04:21:02 +03:00
|
|
|
// While a plugin has focus, selection change notification shouldn't be
|
|
|
|
// available.
|
|
|
|
if (NS_WARN_IF(mInputContext.mIMEState.mEnabled == IMEState::PLUGIN)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
// Note that selection change must be notified after text change if it occurs.
|
|
|
|
// Therefore, we don't need to query text content again here.
|
2015-06-05 12:28:20 +03:00
|
|
|
mContentCache.SetSelection(
|
2017-05-08 14:07:56 +03:00
|
|
|
this,
|
2015-06-05 12:28:20 +03:00
|
|
|
aIMENotification.mSelectionChangeData.mOffset,
|
2015-07-22 06:40:32 +03:00
|
|
|
aIMENotification.mSelectionChangeData.Length(),
|
2015-06-05 12:28:20 +03:00
|
|
|
aIMENotification.mSelectionChangeData.mReversed,
|
|
|
|
aIMENotification.mSelectionChangeData.GetWritingMode());
|
|
|
|
|
2016-06-28 10:51:59 +03:00
|
|
|
mTabChild->SendNotifyIMESelection(mContentCache, aIMENotification);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-10 04:21:02 +03:00
|
|
|
// While a plugin has focus, mouse button event notification shouldn't be
|
|
|
|
// available.
|
|
|
|
if (NS_WARN_IF(mInputContext.mIMEState.mEnabled == IMEState::PLUGIN)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 17:46:17 +04:00
|
|
|
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
|
2015-06-05 12:28:20 +03:00
|
|
|
PuppetWidget::NotifyIMEOfPositionChange(const IMENotification& aIMENotification)
|
2014-12-15 12:37:00 +03:00
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mTabChild)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-10 04:21:02 +03:00
|
|
|
if (NS_WARN_IF(!mContentCache.CacheEditorRect(this, &aIMENotification))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
// While a plugin has focus, selection range isn't available. So, we don't
|
|
|
|
// need to cache it at that time.
|
|
|
|
if (mInputContext.mIMEState.mEnabled != IMEState::PLUGIN &&
|
2015-06-05 12:28:20 +03:00
|
|
|
NS_WARN_IF(!mContentCache.CacheSelection(this, &aIMENotification))) {
|
2014-12-15 12:37:00 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2017-04-11 15:24:55 +03:00
|
|
|
if (mIMENotificationRequestsOfParent.WantPositionChanged()) {
|
2015-10-10 04:21:01 +03:00
|
|
|
mTabChild->SendNotifyIMEPositionChange(mContentCache, aIMENotification);
|
|
|
|
} else {
|
|
|
|
mTabChild->SendUpdateContentCache(mContentCache);
|
2014-12-15 12:37:00 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-21 03:13:08 +03:00
|
|
|
void
|
2011-06-22 04:32:43 +04:00
|
|
|
PuppetWidget::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
2015-12-22 01:19:15 +03:00
|
|
|
// Don't cache on windows, Windowless flash breaks this via async cursor updates.
|
|
|
|
#if !defined(XP_WIN)
|
2015-05-20 04:28:57 +03:00
|
|
|
if (mCursor == aCursor && !mCustomCursor && !mUpdateCursor) {
|
2016-12-21 03:13:08 +03:00
|
|
|
return;
|
2012-09-12 08:48:13 +04:00
|
|
|
}
|
2015-12-22 01:19:15 +03:00
|
|
|
#endif
|
2012-09-12 08:48:13 +04:00
|
|
|
|
2015-05-20 04:28:57 +03:00
|
|
|
mCustomCursor = nullptr;
|
|
|
|
|
2014-05-28 05:12:29 +04:00
|
|
|
if (mTabChild &&
|
|
|
|
!mTabChild->SendSetCursor(aCursor, mUpdateCursor)) {
|
2016-12-21 03:13:08 +03:00
|
|
|
return;
|
2011-06-22 04:32:43 +04:00
|
|
|
}
|
2012-09-12 08:48:13 +04:00
|
|
|
|
|
|
|
mCursor = aCursor;
|
2014-05-28 05:12:29 +04:00
|
|
|
mUpdateCursor = false;
|
2015-05-20 04:28:57 +03:00
|
|
|
}
|
|
|
|
|
2016-12-21 03:13:08 +03:00
|
|
|
nsresult
|
2015-05-20 04:28:57 +03:00
|
|
|
PuppetWidget::SetCursor(imgIContainer* aCursor,
|
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
|
|
|
{
|
|
|
|
if (!aCursor || !mTabChild) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-22 01:19:15 +03:00
|
|
|
#if !defined(XP_WIN)
|
2015-05-20 04:28:57 +03:00
|
|
|
if (mCustomCursor == aCursor &&
|
|
|
|
mCursorHotspotX == aHotspotX &&
|
|
|
|
mCursorHotspotY == aHotspotY &&
|
|
|
|
!mUpdateCursor) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-12-22 01:19:15 +03:00
|
|
|
#endif
|
2015-05-20 04:28:57 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::SourceSurface> surface =
|
2015-05-20 04:28:57 +03:00
|
|
|
aCursor->GetFrame(imgIContainer::FRAME_CURRENT,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE);
|
|
|
|
if (!surface) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::DataSourceSurface> dataSurface =
|
2015-05-20 04:28:57 +03:00
|
|
|
surface->GetDataSurface();
|
2016-05-03 17:04:21 +03:00
|
|
|
if (!dataSurface) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-05-20 04:28:57 +03:00
|
|
|
size_t length;
|
|
|
|
int32_t stride;
|
|
|
|
mozilla::UniquePtr<char[]> surfaceData =
|
2016-05-27 02:49:25 +03:00
|
|
|
nsContentUtils::GetSurfaceData(WrapNotNull(dataSurface), &length, &stride);
|
2015-05-20 04:28:57 +03:00
|
|
|
|
2016-04-20 18:50:45 +03:00
|
|
|
nsDependentCString cursorData(surfaceData.get(), length);
|
2015-05-20 04:28:57 +03:00
|
|
|
mozilla::gfx::IntSize size = dataSurface->GetSize();
|
|
|
|
if (!mTabChild->SendSetCustomCursor(cursorData, size.width, size.height, stride,
|
|
|
|
static_cast<uint8_t>(dataSurface->GetFormat()),
|
|
|
|
aHotspotX, aHotspotY, mUpdateCursor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-09-15 07:34:37 +03:00
|
|
|
mCursor = eCursorInvalid;
|
2015-05-20 04:28:57 +03:00
|
|
|
mCustomCursor = aCursor;
|
|
|
|
mCursorHotspotX = aHotspotX;
|
|
|
|
mCursorHotspotY = aHotspotY;
|
|
|
|
mUpdateCursor = false;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PuppetWidget::ClearCachedCursor()
|
|
|
|
{
|
|
|
|
nsBaseWidget::ClearCachedCursor();
|
|
|
|
mCustomCursor = nullptr;
|
2011-06-22 04:32:43 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
if (!GetCurrentWidgetListener())
|
2012-08-15 22:52:42 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2015-11-17 08:18:31 +03:00
|
|
|
LayoutDeviceIntRegion region = mDirtyRegion;
|
2010-08-21 03:24:40 +04:00
|
|
|
|
|
|
|
// reset repaint tracking
|
|
|
|
mDirtyRegion.SetEmpty();
|
|
|
|
mPaintTask.Revoke();
|
|
|
|
|
2016-05-11 06:58:47 +03:00
|
|
|
RefPtr<PuppetWidget> strongThis(this);
|
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
GetCurrentWidgetListener()->WillPaintWindow(this);
|
2013-01-28 23:34:03 +04:00
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
if (GetCurrentWidgetListener()) {
|
2010-08-21 03:24:40 +04:00
|
|
|
#ifdef DEBUG
|
2015-11-17 08:18:31 +03:00
|
|
|
debug_DumpPaintEvent(stderr, this, region.ToUnknownRegion(),
|
2016-03-31 21:42:13 +03:00
|
|
|
"PuppetWidget", 0);
|
2010-08-21 03:24:40 +04:00
|
|
|
#endif
|
|
|
|
|
2017-04-11 09:12:35 +03:00
|
|
|
if (mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_CLIENT ||
|
2017-10-13 17:32:36 +03:00
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LayersBackend::LAYERS_WR ||
|
|
|
|
(mozilla::layers::LayersBackend::LAYERS_BASIC == mLayerManager->GetBackendType() &&
|
|
|
|
mTabChild && mTabChild->IsLayersConnected().isSome())) {
|
2013-05-01 09:03:25 +04:00
|
|
|
// Do nothing, the compositor will handle drawing
|
|
|
|
if (mTabChild) {
|
|
|
|
mTabChild->NotifyPainted();
|
|
|
|
}
|
2016-11-07 19:38:45 +03:00
|
|
|
} else if (mozilla::layers::LayersBackend::LAYERS_BASIC == mLayerManager->GetBackendType()) {
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> ctx = gfxContext::CreateOrNull(mDrawTarget);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!ctx) {
|
|
|
|
gfxDevCrash(LogReason::InvalidContext) << "PuppetWidget context problem " << gfx::hexa(mDrawTarget);
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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);
|
2015-12-03 08:45:41 +03:00
|
|
|
GetCurrentWidgetListener()->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
|
|
|
}
|
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
if (GetCurrentWidgetListener()) {
|
|
|
|
GetCurrentWidgetListener()->DidPaintWindow();
|
2012-12-13 01:57:08 +04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::PaintNowIfNeeded()
|
|
|
|
{
|
|
|
|
if (IsVisible() && mPaintTask.IsPending()) {
|
|
|
|
Paint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 10:45:41 +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;
|
|
|
|
}
|
|
|
|
|
2015-07-14 11:32:05 +03:00
|
|
|
if (strcmp("memory-pressure", aTopic) == 0 &&
|
|
|
|
!NS_LITERAL_STRING("lowering-priority").Equals(aData)) {
|
2015-05-20 10:45:41 +03:00
|
|
|
if (!mWidget->mVisible && mWidget->mLayerManager &&
|
2015-07-04 04:29:00 +03:00
|
|
|
XRE_IsContentProcess()) {
|
2015-05-20 10:45:41 +03:00
|
|
|
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
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess() &&
|
2017-02-17 21:59:12 +03:00
|
|
|
gRemoteDesktopBehaviorEnabled &&
|
2014-11-20 20:28:58 +03:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
return mDPI;
|
|
|
|
}
|
|
|
|
|
2013-05-02 03:06:19 +04:00
|
|
|
double
|
|
|
|
PuppetWidget::GetDefaultScaleInternal()
|
|
|
|
{
|
|
|
|
return mDefaultScale;
|
|
|
|
}
|
|
|
|
|
2016-09-27 09:37:07 +03:00
|
|
|
int32_t
|
|
|
|
PuppetWidget::RoundsWidgetCoordinatesTo()
|
|
|
|
{
|
|
|
|
return mRounding;
|
|
|
|
}
|
|
|
|
|
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: {
|
2017-06-13 20:37:31 +03:00
|
|
|
// NOTE: We can not have a tab child in some situations, such as when we're
|
|
|
|
// rendering to a fake widget for thumbnails.
|
|
|
|
if (!mTabChild) {
|
|
|
|
NS_WARNING("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) {
|
2017-06-13 20:37:31 +03:00
|
|
|
nativeData = mTabChild->WidgetNativeData();
|
2013-04-02 22:32:59 +04:00
|
|
|
}
|
2012-05-09 01:36:07 +04:00
|
|
|
return (void*)nativeData;
|
|
|
|
}
|
2016-01-26 01:13:50 +03:00
|
|
|
case NS_NATIVE_WINDOW:
|
2015-07-25 20:43:27 +03:00
|
|
|
case NS_NATIVE_WIDGET:
|
2012-05-09 01:36:07 +04:00
|
|
|
case NS_NATIVE_DISPLAY:
|
2016-01-26 01:13:50 +03:00
|
|
|
// These types are ignored (see bug 1183828, bug 1240891).
|
2015-07-25 20:43:27 +03:00
|
|
|
break;
|
2015-12-11 09:15:57 +03:00
|
|
|
case NS_RAW_NATIVE_IME_CONTEXT:
|
|
|
|
MOZ_CRASH("You need to call GetNativeIMEContext() instead");
|
2012-05-09 01:36:07 +04:00
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
|
|
|
case NS_NATIVE_SHELLWIDGET:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-08-12 18:00:26 +03:00
|
|
|
#if defined(XP_WIN)
|
|
|
|
void
|
|
|
|
PuppetWidget::SetNativeData(uint32_t aDataType, uintptr_t aVal)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_CHILD_OF_SHAREABLE_WINDOW:
|
|
|
|
MOZ_ASSERT(mTabChild, "Need TabChild to send the message.");
|
|
|
|
if (mTabChild) {
|
|
|
|
mTabChild->SendSetNativeChildOfShareableWindow(aVal);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("SetNativeData called with unsupported data type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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-11-07 06:13:40 +03:00
|
|
|
return GetOwningTabChild()->GetChromeDisplacement().ToUnknownPoint();
|
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());
|
2016-03-08 22:14:43 +03:00
|
|
|
return nsIntPoint(winX, winY) + GetOwningTabChild()->GetClientOffset().ToUnknownPoint();
|
2014-12-11 17:44:07 +03:00
|
|
|
}
|
|
|
|
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect
|
|
|
|
PuppetWidget::GetScreenBounds()
|
|
|
|
{
|
|
|
|
return LayoutDeviceIntRect(WidgetToScreenOffset(), mBounds.Size());
|
2015-03-31 23:39:02 +03:00
|
|
|
}
|
|
|
|
|
2015-05-08 04:29:00 +03:00
|
|
|
uint32_t PuppetWidget::GetMaxTouchPoints() const
|
|
|
|
{
|
2017-03-15 02:48:41 +03:00
|
|
|
uint32_t maxTouchPoints = 0;
|
2015-05-08 04:29:00 +03:00
|
|
|
if (mTabChild) {
|
2017-03-15 02:48:41 +03:00
|
|
|
mTabChild->GetMaxTouchPoints(&maxTouchPoints);
|
2015-05-08 04:29:00 +03:00
|
|
|
}
|
2017-03-15 02:48:41 +03:00
|
|
|
return maxTouchPoints;
|
2015-05-08 04:29:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-29 00:00:25 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics)
|
|
|
|
{
|
2016-01-08 22:17:39 +03:00
|
|
|
mTabChild->StartScrollbarDrag(aDragMetrics);
|
2015-09-29 00:00:25 +03:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
nsIWidgetListener*
|
|
|
|
PuppetWidget::GetCurrentWidgetListener()
|
|
|
|
{
|
|
|
|
if (!mPreviouslyAttachedWidgetListener ||
|
|
|
|
!mAttachedWidgetListener) {
|
|
|
|
return mAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAttachedWidgetListener->GetView()->IsPrimaryFramePaintSuppressed()) {
|
|
|
|
return mPreviouslyAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void
|
2016-02-02 11:05:56 +03:00
|
|
|
PuppetWidget::SetCandidateWindowForPlugin(
|
|
|
|
const CandidateWindowPosition& aPosition)
|
2015-12-29 16:57:38 +03:00
|
|
|
{
|
|
|
|
if (!mTabChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-02 11:05:56 +03:00
|
|
|
mTabChild->SendSetCandidateWindowForPlugin(aPosition);
|
2015-12-29 16:57:38 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 04:44:44 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::ZoomToRect(const uint32_t& aPresShellId,
|
|
|
|
const FrameMetrics::ViewID& aViewId,
|
|
|
|
const CSSRect& aRect,
|
|
|
|
const uint32_t& aFlags)
|
|
|
|
{
|
|
|
|
if (!mTabChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-08 22:17:39 +03:00
|
|
|
mTabChild->ZoomToRect(aPresShellId, aViewId, aRect, aFlags);
|
2016-01-20 04:44:44 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 11:18:04 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::LookUpDictionary(
|
|
|
|
const nsAString& aText,
|
|
|
|
const nsTArray<mozilla::FontRange>& aFontRangeArray,
|
|
|
|
const bool aIsVertical,
|
|
|
|
const LayoutDeviceIntPoint& aPoint)
|
|
|
|
{
|
|
|
|
if (!mTabChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTabChild->SendLookUpDictionary(nsString(aText), aFontRangeArray, aIsVertical, aPoint);
|
|
|
|
}
|
|
|
|
|
2016-03-29 10:03:54 +03:00
|
|
|
bool
|
|
|
|
PuppetWidget::HasPendingInputEvent()
|
|
|
|
{
|
|
|
|
if (!mTabChild) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
2016-04-13 04:51:34 +03:00
|
|
|
mTabChild->GetIPCChannel()->PeekMessages(
|
|
|
|
[&ret](const IPC::Message& aMsg) -> bool {
|
2017-08-09 23:59:27 +03:00
|
|
|
if (nsContentUtils::IsMessageInputEvent(aMsg)) {
|
|
|
|
ret = true;
|
|
|
|
return false; // Stop peeking.
|
2016-03-29 10:03:54 +03:00
|
|
|
}
|
2016-04-13 04:51:34 +03:00
|
|
|
return true;
|
2016-03-29 10:03:54 +03:00
|
|
|
}
|
2016-04-13 04:51:34 +03:00
|
|
|
);
|
2016-03-29 10:03:54 +03:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
Bug 1257759 part.5 PluginInstanceChild should post received native key event to chrome process if the key combination may be a shortcut key r=jimm
When PluginInstanceChild receives native key events, it should post the events to the chrome process first for checking if the key combination is reserved. However, posting all key events to the chrome process may make damage to the performance of text input. Therefore, this patch starts to post a key event whose key combination may be a shortcut key. However, for avoiding to shuffle the event order, it posts following key events until all posted key events are handled by the chrome process.
For receiving response from widget, this patch defines nsIKeyEventInPluginCallback. It's specified by nsIWidget::OnWindowedPluginKeyEvent() for ensuring the caller will receive the reply. Basically, the caller of nsIWidget::OnWindowedPluginKeyEvent() should reply to the child process. However, if the widget is a PuppetWidget, it cannot return the result synchronously. Therefore, PuppetWidget::OnWindowedPluginKeyEvent() returns NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY and stores the callback to mKeyEventInPluginCallbacks. Then, TabParent::HandledWindowedPluginKeyEvent() will call PuppetWidget::HandledWindowedPluginKeyEvent().
MozReview-Commit-ID: G6brOU26NwQ
--HG--
extra : rebase_source : 8140456de278956d2d594e85c7b397ae366b4962
2016-04-19 14:09:37 +03:00
|
|
|
void
|
|
|
|
PuppetWidget::HandledWindowedPluginKeyEvent(
|
|
|
|
const NativeEventData& aKeyEventData,
|
|
|
|
bool aIsConsumed)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(mKeyEventInPluginCallbacks.IsEmpty())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIKeyEventInPluginCallback> callback =
|
|
|
|
mKeyEventInPluginCallbacks[0];
|
|
|
|
MOZ_ASSERT(callback);
|
|
|
|
mKeyEventInPluginCallbacks.RemoveElementAt(0);
|
|
|
|
callback->HandledWindowedPluginKeyEvent(aKeyEventData, aIsConsumed);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PuppetWidget::OnWindowedPluginKeyEvent(const NativeEventData& aKeyEventData,
|
|
|
|
nsIKeyEventInPluginCallback* aCallback)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mTabChild)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!mTabChild->SendOnWindowedPluginKeyEvent(aKeyEventData))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mKeyEventInPluginCallbacks.AppendElement(aCallback);
|
|
|
|
return NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY;
|
|
|
|
}
|
|
|
|
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
// TextEventDispatcherListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::NotifyIME(TextEventDispatcher* aTextEventDispatcher,
|
Bug 1384027 - part2: Move PuppetWidget::NotifyIMEInternal() implementation to PuppetWidget::NotifyIME() which is a method of TextEventDispatcherListener, not nsIWidget r=m_kato
nsIWidget::NotifyIME() should call only TextEventDispatcher::NotifyIME() if it's necessary. Then, TextEventDispatcher::NotifyIME() calls TextEventDispatcherListener::NotifyIME() if it's necessary. E.g., requests to IME are necessary only for TextInputProcessor or native IME handler because the composition is only owned by one of them. However, notifications are necessary for both of them since focused editor contents and its focus state are shared.
So, it doesn't need to call nsBaseWidget::NotifyIMEInternal() if all NotifyIMEInternal() implementations are moved to proper TextEventDispatcherListener::NotifyIME(). Currently, nsBaseWidget::NotifyIMEInternal() is implemented only by PuppetWidget. It sends notifications and requests to the parent process for native IME. Therefore, we can move NotifyIMEInternal() implementation to TextEventDispatcherListener::NotifyIME() which is implemented by PuppetWidget.
This patch moves PuppetWidget::NotifyIMEInternal() implementation to PuppetWidget::NotifyIME() of TextEventDispatcherListener class, not of nsIWidget and removes NotifyIMEInternal() completely.
With this change, handling order is changed. Old behavior is, TextEventDispatcher::NotifyIME() calls TextEventDispatcherListener::NotifyIME() before handling NOTIFY_IME_OF_FOCUS and then, nsBaseWidget::NotifyIME() sends the notification to the parent process. However, new behavior is, the notification is sent before TextEventDispatcher::NotifyIME() handles NOTIFY_IME_OF_FOCUS. Therefore, with new handling order, TextEventDispatcher can have IME notification requests after setting focus correctly. Additionally, TextEventDispatcher for PuppetWidget updates the notification requests at every event dispatch via TextEventDispatcher::BeginInputTransactionInternal() by the previous patch.
So, with those patches, IMEContentObserver can refer actual IME notification requests correctly even after we'll make focus notification to async message.
MozReview-Commit-ID: JwdQ68BjTXL
--HG--
extra : rebase_source : fbc7e311d83aab3b38fdd5c1b5c24d85458eb77b
2017-07-25 18:09:41 +03:00
|
|
|
const IMENotification& aIMENotification)
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTextEventDispatcher == mTextEventDispatcher);
|
Bug 1384027 - part2: Move PuppetWidget::NotifyIMEInternal() implementation to PuppetWidget::NotifyIME() which is a method of TextEventDispatcherListener, not nsIWidget r=m_kato
nsIWidget::NotifyIME() should call only TextEventDispatcher::NotifyIME() if it's necessary. Then, TextEventDispatcher::NotifyIME() calls TextEventDispatcherListener::NotifyIME() if it's necessary. E.g., requests to IME are necessary only for TextInputProcessor or native IME handler because the composition is only owned by one of them. However, notifications are necessary for both of them since focused editor contents and its focus state are shared.
So, it doesn't need to call nsBaseWidget::NotifyIMEInternal() if all NotifyIMEInternal() implementations are moved to proper TextEventDispatcherListener::NotifyIME(). Currently, nsBaseWidget::NotifyIMEInternal() is implemented only by PuppetWidget. It sends notifications and requests to the parent process for native IME. Therefore, we can move NotifyIMEInternal() implementation to TextEventDispatcherListener::NotifyIME() which is implemented by PuppetWidget.
This patch moves PuppetWidget::NotifyIMEInternal() implementation to PuppetWidget::NotifyIME() of TextEventDispatcherListener class, not of nsIWidget and removes NotifyIMEInternal() completely.
With this change, handling order is changed. Old behavior is, TextEventDispatcher::NotifyIME() calls TextEventDispatcherListener::NotifyIME() before handling NOTIFY_IME_OF_FOCUS and then, nsBaseWidget::NotifyIME() sends the notification to the parent process. However, new behavior is, the notification is sent before TextEventDispatcher::NotifyIME() handles NOTIFY_IME_OF_FOCUS. Therefore, with new handling order, TextEventDispatcher can have IME notification requests after setting focus correctly. Additionally, TextEventDispatcher for PuppetWidget updates the notification requests at every event dispatch via TextEventDispatcher::BeginInputTransactionInternal() by the previous patch.
So, with those patches, IMEContentObserver can refer actual IME notification requests correctly even after we'll make focus notification to async message.
MozReview-Commit-ID: JwdQ68BjTXL
--HG--
extra : rebase_source : fbc7e311d83aab3b38fdd5c1b5c24d85458eb77b
2017-07-25 18:09:41 +03:00
|
|
|
|
|
|
|
// If there is different text event dispatcher listener for handling
|
|
|
|
// text event dispatcher, that means that native keyboard events and
|
|
|
|
// IME events are handled in this process. Therefore, we don't need
|
|
|
|
// to send any requests and notifications to the parent process.
|
|
|
|
if (mNativeTextEventDispatcherListener) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aIMENotification.mMessage) {
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
return RequestIMEToCommitComposition(false);
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
return RequestIMEToCommitComposition(true);
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
return NotifyIMEOfFocusChange(aIMENotification);
|
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
return NotifyIMEOfSelectionChange(aIMENotification);
|
|
|
|
case NOTIFY_IME_OF_TEXT_CHANGE:
|
|
|
|
return NotifyIMEOfTextChange(aIMENotification);
|
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
|
|
|
return NotifyIMEOfCompositionUpdate(aIMENotification);
|
|
|
|
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
|
|
|
|
return NotifyIMEOfMouseButtonEvent(aIMENotification);
|
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
|
|
|
return NotifyIMEOfPositionChange(aIMENotification);
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
Bug 1217700 part.1 nsIWidget should return reference to IMENotificationRequests r=m_kato
IMEContentObserver may need to change notifications to send when TextInputProcessor begins input transaction. In current design, IMEContentObserver needs to retrieve IMENotificationRequests at every change. However, if nsIWidget returns a reference to its IMENotificationRequests, IMEContentObserver can call it only once.
For that purpose, this patch changes nsIWidget::GetIMENotificationRequests() to nsIWidget::IMENotificationRequestsRef() and make it return |const IMENotificationRequests&|. However, if the lifetime of the instance of IMENotificationRequest is shorter than the widget instance's, it's dangerous. Therefore, it always returns TextEventDispatcher::mIMENotificationRequests. TextEventDispatcher's lifetime is longer than the widget. Therefore, this guarantees the lifetime.
On the other hand, widget needs to update TextEventDispatcher::mIMENotificationRequests before calls of nsIWidget::IMENotificationRequestsRef(). Therefore, this patch makes TextEventDispatcher update proper IMENotificationRequests when it gets focus or starts new input transaction and clear mIMENotificationRequests when it loses focus.
Note that TextEventDispatcher gets proper requests both from native text event dispatcher listener (typically, implemented by native IME handler class) and TextInputProcessor when TextInputProcessor has input transaction because even if TextInputProcessor overrides native IME, native IME still needs to know the content changes since they may get new input transaction after that.
However, there may not be native IME handler in content process. If it runs in Android, PuppetWidget may have native IME handler because widget directly handles IME in e10s mode for Android. Otherwise, native IME handler is in its parent process. So, if TextInputHandler has input transaction in content process, PuppetWidget needs to behave as native event handler. Therefore, this patch makes PuppetWidget inherit TextEventDispatcherListener and implements PuppetWidget::IMENotificationRequestsRef().
MozReview-Commit-ID: 2SW3moONTOX
--HG--
extra : rebase_source : d2634ada6c33dbf7a966fadb68608411ee24bfab
2017-04-14 19:35:58 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(IMENotificationRequests)
|
|
|
|
PuppetWidget::GetIMENotificationRequests()
|
|
|
|
{
|
|
|
|
if (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN) {
|
|
|
|
// If a plugin has focus, we cannot receive text nor selection change
|
|
|
|
// in the plugin. Therefore, PuppetWidget needs to receive only position
|
|
|
|
// change event for updating the editor rect cache.
|
|
|
|
return IMENotificationRequests(
|
|
|
|
mIMENotificationRequestsOfParent.mWantUpdates |
|
|
|
|
IMENotificationRequests::NOTIFY_POSITION_CHANGE);
|
|
|
|
}
|
|
|
|
return IMENotificationRequests(
|
|
|
|
mIMENotificationRequestsOfParent.mWantUpdates |
|
|
|
|
IMENotificationRequests::NOTIFY_TEXT_CHANGE |
|
|
|
|
IMENotificationRequests::NOTIFY_POSITION_CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PuppetWidget::OnRemovedFrom(TextEventDispatcher* aTextEventDispatcher)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTextEventDispatcher == mTextEventDispatcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PuppetWidget::WillDispatchKeyboardEvent(
|
|
|
|
TextEventDispatcher* aTextEventDispatcher,
|
|
|
|
WidgetKeyboardEvent& aKeyboardEvent,
|
|
|
|
uint32_t aIndexOfKeypress,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aTextEventDispatcher == mTextEventDispatcher);
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|