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"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.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"
|
2019-04-13 04:53:10 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2020-04-07 18:17:47 +03:00
|
|
|
#include "mozilla/SchedulerGroup.h"
|
2019-08-26 23:25:42 +03:00
|
|
|
#include "mozilla/StaticPrefs_browser.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"
|
2019-02-02 01:07:26 +03:00
|
|
|
#include "nsXPLookAndFeel.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;
|
|
|
|
|
2015-11-23 07:32:29 +03:00
|
|
|
static void InvalidateRegion(nsIWidget* aWidget,
|
|
|
|
const LayoutDeviceIntRegion& aRegion) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:13:48 +03:00
|
|
|
/*static*/
|
2019-04-10 01:39:01 +03:00
|
|
|
already_AddRefed<nsIWidget> nsIWidget::CreatePuppetWidget(
|
|
|
|
BrowserChild* aBrowserChild) {
|
|
|
|
MOZ_ASSERT(!aBrowserChild || nsIWidget::UsePuppetWidgets(),
|
2015-02-10 01:34:50 +03:00
|
|
|
"PuppetWidgets not allowed in this configuration");
|
2010-08-21 03:24:40 +04:00
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget = new PuppetWidget(aBrowserChild);
|
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;
|
|
|
|
|
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
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
PuppetWidget::PuppetWidget(BrowserChild* aBrowserChild)
|
|
|
|
: mBrowserChild(aBrowserChild),
|
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),
|
2018-06-15 17:48:51 +03:00
|
|
|
mEnabled(false),
|
|
|
|
mVisible(false),
|
|
|
|
mNeedIMEStateInit(false),
|
2017-11-27 14:34:01 +03:00
|
|
|
mIgnoreCompositionEvents(false) {
|
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;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PuppetWidget::~PuppetWidget() { Destroy(); }
|
|
|
|
|
2016-08-19 02:03:17 +03:00
|
|
|
void PuppetWidget::InfallibleCreate(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const LayoutDeviceIntRect& 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
|
|
|
|
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 {
|
2018-01-10 19:14:16 +03:00
|
|
|
Resize(mBounds.X(), mBounds.Y(), mBounds.Width(), mBounds.Height(), false);
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
2018-08-10 18:15:18 +03:00
|
|
|
mMemoryPressureObserver = MemoryPressureObserver::Create(this);
|
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() {
|
2019-04-10 01:39:01 +03:00
|
|
|
MOZ_ASSERT(mBrowserChild);
|
2012-08-29 19:26:18 +04:00
|
|
|
if (mNeedIMEStateInit) {
|
2015-06-05 12:28:20 +03:00
|
|
|
mContentCache.Clear();
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->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> PuppetWidget::CreateChild(
|
2015-11-16 11:35:18 +03:00
|
|
|
const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData,
|
|
|
|
bool aForceUseIWidgetParent) {
|
2011-02-23 20:45:09 +03:00
|
|
|
bool isPopup = IsPopup(aInitData);
|
2019-04-10 01:39:01 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget = nsIWidget::CreatePuppetWidget(mBrowserChild);
|
2012-07-30 18:20:58 +04:00
|
|
|
return ((widget && NS_SUCCEEDED(widget->Create(isPopup ? nullptr : this,
|
|
|
|
nullptr, aRect, aInitData)))
|
|
|
|
? widget.forget()
|
|
|
|
: nullptr);
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
void 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) {
|
2018-08-10 18:15:18 +03:00
|
|
|
mMemoryPressureObserver->Unregister();
|
|
|
|
mMemoryPressureObserver = nullptr;
|
2015-05-20 10:45:41 +03:00
|
|
|
}
|
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;
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild = nullptr;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void 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;
|
2018-01-10 19:14:16 +03: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-12 13:57:38 +04:00
|
|
|
void PuppetWidget::Resize(double aWidth, double aHeight, bool aRepaint) {
|
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) {
|
2018-01-10 19:14:16 +03:00
|
|
|
GetCurrentWidgetListener()->WindowResized(this, mBounds.Width(),
|
|
|
|
mBounds.Height());
|
2015-07-22 04:09:02 +03:00
|
|
|
}
|
2018-01-10 19:14:16 +03: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()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
w->Resize(configuration.mBounds.X(), configuration.mBounds.Y(),
|
|
|
|
configuration.mBounds.Width(), configuration.mBounds.Height(),
|
2014-11-12 23:59:19 +03:00
|
|
|
true);
|
|
|
|
} else if (bounds.TopLeft() != configuration.mBounds.TopLeft()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
w->Move(configuration.mBounds.X(), configuration.mBounds.Y());
|
2014-11-12 23:59:19 +03:00
|
|
|
}
|
|
|
|
w->SetWindowClipRegion(configuration.mClipRegion, false);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-16 17:38:40 +03:00
|
|
|
void PuppetWidget::SetFocus(Raise aRaise, CallerType aCallerType) {
|
2019-06-01 01:13:56 +03:00
|
|
|
if (aRaise == Raise::Yes && mBrowserChild) {
|
2020-01-16 17:38:40 +03:00
|
|
|
mBrowserChild->SendRequestFocus(true, aCallerType);
|
2015-10-06 16:14:49 +03:00
|
|
|
}
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
2015-11-17 08:18:31 +03:00
|
|
|
void 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);
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild && !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());
|
2020-04-07 18:17:47 +03:00
|
|
|
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
|
2016-12-20 01:55:32 +03:00
|
|
|
return;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-09 13:26:31 +03:00
|
|
|
mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
|
|
|
|
PuppetWidget::WidgetToTopLevelWidgetTransform() {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!GetOwningBrowserChild()) {
|
2019-04-09 13:26:31 +03:00
|
|
|
NS_WARNING("PuppetWidget without Tab does not have transform information.");
|
|
|
|
return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
return GetOwningBrowserChild()->GetChildToParentConversionMatrix();
|
2019-04-09 13:26:31 +03:00
|
|
|
}
|
|
|
|
|
2017-01-19 11:27:15 +03:00
|
|
|
void PuppetWidget::InitEvent(WidgetGUIEvent& aEvent,
|
|
|
|
LayoutDeviceIntPoint* aPoint) {
|
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
|
|
|
}
|
|
|
|
|
2017-01-19 11:27:15 +03:00
|
|
|
nsresult 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) {
|
2017-11-27 14:34:01 +03:00
|
|
|
// If we've already requested to commit/cancel the latest composition,
|
|
|
|
// TextComposition for the old composition has been destroyed. Then,
|
|
|
|
// the DOM tree needs to listen to next eCompositionStart and its
|
|
|
|
// following events. So, until we meet new eCompositionStart, let's
|
|
|
|
// discard all unnecessary composition events here.
|
|
|
|
if (mIgnoreCompositionEvents) {
|
|
|
|
if (aEvent->mMessage != eCompositionStart) {
|
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Now, we receive new eCompositionStart. Let's restart to handle
|
|
|
|
// composition in this process.
|
|
|
|
mIgnoreCompositionEvents = false;
|
|
|
|
}
|
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-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;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-03-07 01:26:59 +03:00
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
2020-04-28 12:43:11 +03:00
|
|
|
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
|
|
|
|
// Because the root resolution is conceptually at the parent/child process
|
|
|
|
// boundary, we need to apply that resolution here because we're sending
|
|
|
|
// the event from the child to the parent process.
|
|
|
|
LayoutDevicePoint pt(aEvent->mRefPoint);
|
|
|
|
pt = pt * presShell->GetResolution();
|
|
|
|
aEvent->mRefPoint = LayoutDeviceIntPoint::Round(pt);
|
|
|
|
}
|
|
|
|
|
2015-03-07 01:26:59 +03:00
|
|
|
switch (aEvent->mClass) {
|
|
|
|
case eWheelEventClass:
|
2019-04-10 01:39:01 +03:00
|
|
|
Unused << mBrowserChild->SendDispatchWheelEvent(*aEvent->AsWheelEvent());
|
2015-03-07 01:26:59 +03:00
|
|
|
break;
|
2016-03-11 02:25:48 +03:00
|
|
|
case eMouseEventClass:
|
2019-04-10 01:39:01 +03:00
|
|
|
Unused << mBrowserChild->SendDispatchMouseEvent(*aEvent->AsMouseEvent());
|
2016-03-11 02:25:48 +03:00
|
|
|
break;
|
|
|
|
case eKeyboardEventClass:
|
2019-04-10 01:39:01 +03:00
|
|
|
Unused << mBrowserChild->SendDispatchKeyboardEvent(
|
2016-03-11 02:25:48 +03:00
|
|
|
*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");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeKeyEvent(
|
|
|
|
aNativeKeyboardLayout, aNativeKeyCode, 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");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeMouseEvent(
|
2017-01-19 11:57:20 +03:00
|
|
|
aPoint, aNativeMessage, 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");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeMouseMove(aPoint, notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-01-19 11:57:20 +03:00
|
|
|
nsresult 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");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeMouseScrollEvent(
|
2017-01-19 11:57:20 +03:00
|
|
|
aPoint, aNativeMessage, 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, double aPointerPressure,
|
2015-04-14 18:36:36 +03:00
|
|
|
uint32_t aPointerOrientation, nsIObserver* aObserver) {
|
|
|
|
AutoObserverNotifier notifier(aObserver, "touchpoint");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeTouchPoint(
|
2017-01-19 11:57:20 +03:00
|
|
|
aPointerId, aPointerState, aPoint, aPointerPressure, aPointerOrientation,
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-15 13:39:36 +03:00
|
|
|
nsresult PuppetWidget::SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
|
2015-04-14 18:36:36 +03:00
|
|
|
bool aLongTap,
|
|
|
|
nsIObserver* aObserver) {
|
|
|
|
AutoObserverNotifier notifier(aObserver, "touchtap");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSynthesizeNativeTouchTap(aPoint, aLongTap,
|
|
|
|
notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PuppetWidget::ClearNativeTouchSequence(nsIObserver* aObserver) {
|
|
|
|
AutoObserverNotifier notifier(aObserver, "cleartouch");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendClearNativeTouchSequence(notifier.SaveObserver());
|
2015-04-14 18:36:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-05-08 14:07:56 +03:00
|
|
|
|
2017-01-19 11:57:20 +03:00
|
|
|
void PuppetWidget::SetConfirmedTargetAPZC(
|
|
|
|
uint64_t aInputBlockId,
|
2020-03-27 20:44:21 +03:00
|
|
|
const nsTArray<ScrollableLayerGuid>& aTargets) const {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->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(
|
2018-11-01 23:15:46 +03:00
|
|
|
const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
|
2015-06-17 19:32:42 +03:00
|
|
|
const Maybe<ZoomConstraints>& aConstraints) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->DoUpdateZoomConstraints(aPresShellId, aViewId, aConstraints);
|
2015-06-17 19:32:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 23:51:10 +03:00
|
|
|
bool PuppetWidget::AsyncPanZoomEnabled() const {
|
2019-04-10 01:39:01 +03:00
|
|
|
return mBrowserChild && mBrowserChild->AsyncPanZoomEnabled();
|
2015-06-04 23:51:10 +03:00
|
|
|
}
|
|
|
|
|
2019-11-08 14:32:51 +03:00
|
|
|
bool PuppetWidget::GetEditCommands(NativeKeyBindingsType aType,
|
2017-05-19 11:49:41 +03:00
|
|
|
const WidgetKeyboardEvent& aEvent,
|
|
|
|
nsTArray<CommandInt>& aCommands) {
|
|
|
|
// Validate the arguments.
|
2019-11-08 14:32:51 +03:00
|
|
|
if (NS_WARN_IF(!nsIWidget::GetEditCommands(aType, aEvent, aCommands))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!mBrowserChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->RequestEditCommands(aType, aEvent, aCommands);
|
2019-11-08 14:32:51 +03:00
|
|
|
return true;
|
2014-03-20 19:46:29 +04:00
|
|
|
}
|
|
|
|
|
2013-04-24 22:42:40 +04:00
|
|
|
LayerManager* PuppetWidget::GetLayerManager(
|
2011-08-09 23:38:26 +04:00
|
|
|
PLayerTransactionChild* aShadowManager, 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;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
// If we know for sure that the parent side of this BrowserChild is not
|
2017-10-13 17:32:36 +03:00
|
|
|
// 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.
|
2019-04-10 01:39:01 +03:00
|
|
|
MOZ_ASSERT(!mBrowserChild ||
|
|
|
|
mBrowserChild->IsLayersConnected() != Some(true));
|
2017-10-13 17:32:36 +03:00
|
|
|
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-10-13 17:32:36 +03:00
|
|
|
bool PuppetWidget::CreateRemoteLayerManager(
|
|
|
|
const std::function<bool(LayerManager*)>& aInitializeFunc) {
|
2017-07-18 16:35:07 +03:00
|
|
|
RefPtr<LayerManager> lm;
|
2019-04-10 01:39:01 +03:00
|
|
|
MOZ_ASSERT(mBrowserChild);
|
|
|
|
if (mBrowserChild->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();
|
2020-02-13 17:38:48 +03:00
|
|
|
mLayerManager = std::move(lm);
|
2017-07-18 16:35:07 +03:00
|
|
|
return true;
|
2016-09-20 11:19:32 +03:00
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
nsresult PuppetWidget::RequestIMEToCommitComposition(bool aCancel) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-12-11 09:15:58 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-27 14:34:01 +03:00
|
|
|
// We've already requested to commit/cancel composition.
|
|
|
|
if (NS_WARN_IF(mIgnoreCompositionEvents)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
RefPtr<TextComposition> composition =
|
|
|
|
IMEStateManager::GetTextCompositionFor(this);
|
|
|
|
MOZ_ASSERT(!composition);
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-11-20 16:59:04 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
composition->IsRequestingCommitOrCancelComposition(),
|
|
|
|
"Requesting commit or cancel composition should be requested via "
|
|
|
|
"TextComposition instance");
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
bool isCommitted = false;
|
|
|
|
nsAutoString committedString;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (NS_WARN_IF(!mBrowserChild->SendRequestIMEToCommitComposition(
|
2015-12-11 09:15:58 +03:00
|
|
|
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-11-27 14:34:01 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
RefPtr<TextComposition> currentComposition =
|
|
|
|
IMEStateManager::GetTextCompositionFor(this);
|
|
|
|
MOZ_ASSERT(!currentComposition);
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
|
|
|
// Ignore the following composition events until we receive new
|
|
|
|
// eCompositionStart event.
|
|
|
|
mIgnoreCompositionEvents = true;
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
Unused << mBrowserChild->SendOnEventNeedingAckHandled(
|
2017-06-27 17:41:12 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-09 04:29:42 +03:00
|
|
|
nsresult PuppetWidget::StartPluginIME(const WidgetKeyboardEvent& aKeyboardEvent,
|
2015-02-20 19:37:02 +03:00
|
|
|
int32_t aPanelX, int32_t aPanelY,
|
|
|
|
nsString& aCommitted) {
|
2018-10-09 04:29:42 +03:00
|
|
|
DebugOnly<bool> propagationAlreadyStopped =
|
|
|
|
aKeyboardEvent.mFlags.mPropagationStopped;
|
|
|
|
DebugOnly<bool> immediatePropagationAlreadyStopped =
|
|
|
|
aKeyboardEvent.mFlags.mImmediatePropagationStopped;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild || !mBrowserChild->SendStartPluginIME(
|
|
|
|
aKeyboardEvent, aPanelX, aPanelY, &aCommitted)) {
|
2015-02-20 19:37:02 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
// BrowserChild::SendStartPluginIME() sends back the keyboard event to the
|
|
|
|
// main process synchronously. At this time,
|
|
|
|
// ParamTraits<WidgetEvent>::Write() marks the event as "posted to remote
|
|
|
|
// process". However, this is not correct here since the event has been
|
|
|
|
// handled synchronously in the main process. So, we adjust the cross process
|
|
|
|
// dispatching state here.
|
2018-10-09 04:29:42 +03:00
|
|
|
const_cast<WidgetKeyboardEvent&>(aKeyboardEvent)
|
|
|
|
.ResetCrossProcessDispatchingState();
|
|
|
|
// Although it shouldn't occur in content process,
|
|
|
|
// ResetCrossProcessDispatchingState() may reset propagation state too
|
|
|
|
// if the event was posted to a remote process and we're waiting its
|
|
|
|
// result. So, if you saw hitting the following assertions, you'd
|
|
|
|
// need to restore the propagation state too.
|
|
|
|
MOZ_ASSERT(propagationAlreadyStopped ==
|
|
|
|
aKeyboardEvent.mFlags.mPropagationStopped);
|
|
|
|
MOZ_ASSERT(immediatePropagationAlreadyStopped ==
|
|
|
|
aKeyboardEvent.mFlags.mImmediatePropagationStopped);
|
2015-02-20 19:37:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetWidget::SetPluginFocused(bool& aFocused) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->SendSetPluginFocused(aFocused);
|
2015-02-20 19:37:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
void PuppetWidget::DefaultProcOfPluginEvent(const WidgetPluginEvent& aEvent) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-12-29 16:57:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendDefaultProcOfPluginEvent(aEvent);
|
2015-12-29 16:57:38 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 08:47:55 +03:00
|
|
|
// When this widget caches input context and currently managed by
|
|
|
|
// IMEStateManager, the cache is valid.
|
|
|
|
bool PuppetWidget::HaveValidInputContextCache() const {
|
|
|
|
return (mInputContext.mIMEState.mEnabled != IMEState::UNKNOWN &&
|
|
|
|
IMEStateManager::GetWidgetForActiveInputContext() == this);
|
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
void PuppetWidget::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction) {
|
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;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2011-11-27 15:51:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSetInputContext(aContext, aAction);
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:52 +04:00
|
|
|
InputContext PuppetWidget::GetInputContext() {
|
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.
|
|
|
|
|
2018-05-17 08:47:55 +03:00
|
|
|
// If the cache of input context is valid, we can avoid to use synchronous
|
|
|
|
// IPC.
|
|
|
|
if (HaveValidInputContextCache()) {
|
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
|
|
|
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;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->SendGetInputContext(&context.mIMEState);
|
2011-11-27 15:51:52 +04:00
|
|
|
}
|
|
|
|
return context;
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
NativeIMEContext PuppetWidget::GetNativeIMEContext() {
|
|
|
|
return mNativeIMEContext;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
nsresult PuppetWidget::NotifyIMEOfFocusChange(
|
|
|
|
const IMENotification& aIMENotification) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
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;
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendNotifyIMEFocus(mContentCache, aIMENotification)
|
2017-05-08 14:07:56 +03:00
|
|
|
->Then(
|
2020-04-07 18:17:47 +03:00
|
|
|
GetMainThreadSerialEventTarget(), __func__,
|
2018-12-11 22:22:26 +03:00
|
|
|
[self](IMENotificationRequests&& aRequests) {
|
2017-05-08 14:07:56 +03:00
|
|
|
self->mIMENotificationRequestsOfParent = aRequests;
|
2019-05-29 15:23:22 +03:00
|
|
|
if (TextEventDispatcher* dispatcher =
|
|
|
|
self->GetTextEventDispatcher()) {
|
|
|
|
dispatcher->OnWidgetChangeIMENotificationRequests(self);
|
|
|
|
}
|
2017-05-08 14:07:56 +03:00
|
|
|
},
|
2018-12-11 22:22:26 +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;
|
|
|
|
}
|
|
|
|
|
2015-07-17 07:30:01 +03:00
|
|
|
nsresult PuppetWidget::NotifyIMEOfCompositionUpdate(
|
2015-06-05 12:28:20 +03:00
|
|
|
const IMENotification& aIMENotification) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (NS_WARN_IF(!mBrowserChild)) {
|
2017-01-19 11:57:20 +03:00
|
|
|
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;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->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) {
|
2014-02-26 04:48:02 +04:00
|
|
|
MOZ_ASSERT(aIMENotification.mMessage == NOTIFY_IME_OF_TEXT_CHANGE,
|
|
|
|
"Passed wrong notification");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
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
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// BrowserParent doesn't this this to cache. we don't send the notification
|
2014-01-29 13:32:39 +04:00
|
|
|
// if parent process doesn't request NOTIFY_TEXT_CHANGE.
|
2017-04-11 15:24:55 +03:00
|
|
|
if (mIMENotificationRequestsOfParent.WantTextChange()) {
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendNotifyIMETextChange(mContentCache, aIMENotification);
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendUpdateContentCache(mContentCache);
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-26 04:48:02 +04:00
|
|
|
nsresult PuppetWidget::NotifyIMEOfSelectionChange(
|
|
|
|
const IMENotification& aIMENotification) {
|
|
|
|
MOZ_ASSERT(aIMENotification.mMessage == NOTIFY_IME_OF_SELECTION_CHANGE,
|
|
|
|
"Passed wrong notification");
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
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(
|
|
|
|
this, 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());
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendNotifyIMESelection(mContentCache, aIMENotification);
|
2016-06-28 10:51:59 +03:00
|
|
|
|
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) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2014-09-11 17:46:17 +04:00
|
|
|
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;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild->SendNotifyIMEMouseButtonEvent(aIMENotification,
|
|
|
|
&consumedByIME)) {
|
2014-09-11 17:46:17 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumedByIME ? NS_SUCCESS_EVENT_CONSUMED : NS_OK;
|
2010-09-24 07:28:15 +04:00
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
nsresult PuppetWidget::NotifyIMEOfPositionChange(
|
|
|
|
const IMENotification& aIMENotification) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (NS_WARN_IF(!mBrowserChild)) {
|
2014-12-15 12:37:00 +03:00
|
|
|
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()) {
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendNotifyIMEPositionChange(mContentCache, aIMENotification);
|
2015-10-10 04:21:01 +03:00
|
|
|
} else {
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendUpdateContentCache(mContentCache);
|
2014-12-15 12:37:00 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-15 16:56:52 +03:00
|
|
|
struct CursorSurface {
|
|
|
|
UniquePtr<char[]> mData;
|
|
|
|
IntSize mSize;
|
|
|
|
};
|
|
|
|
|
2019-02-02 01:07:26 +03:00
|
|
|
void PuppetWidget::SetCursor(nsCursor aCursor, imgIContainer* aCursorImage,
|
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2019-01-15 16:56:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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)
|
2019-01-15 16:56:52 +03:00
|
|
|
if (!mUpdateCursor && mCursor == aCursor && mCustomCursor == aCursorImage &&
|
|
|
|
(!aCursorImage ||
|
|
|
|
(mCursorHotspotX == aHotspotX && mCursorHotspotY == aHotspotY))) {
|
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
|
|
|
|
2019-01-15 16:56:52 +03:00
|
|
|
bool hasCustomCursor = false;
|
|
|
|
UniquePtr<char[]> customCursorData;
|
|
|
|
size_t length = 0;
|
|
|
|
IntSize customCursorSize;
|
|
|
|
int32_t stride = 0;
|
|
|
|
auto format = SurfaceFormat::B8G8R8A8;
|
|
|
|
bool force = mUpdateCursor;
|
|
|
|
|
|
|
|
if (aCursorImage) {
|
|
|
|
RefPtr<SourceSurface> surface = aCursorImage->GetFrame(
|
2019-09-03 18:36:23 +03:00
|
|
|
imgIContainer::FRAME_CURRENT,
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY);
|
2019-01-15 16:56:52 +03:00
|
|
|
if (surface) {
|
|
|
|
if (RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface()) {
|
|
|
|
hasCustomCursor = true;
|
|
|
|
customCursorData = nsContentUtils::GetSurfaceData(
|
|
|
|
WrapNotNull(dataSurface), &length, &stride);
|
|
|
|
customCursorSize = dataSurface->GetSize();
|
|
|
|
format = dataSurface->GetFormat();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-20 04:28:57 +03:00
|
|
|
mCustomCursor = nullptr;
|
|
|
|
|
2019-02-02 01:07:26 +03:00
|
|
|
nsDependentCString cursorData(customCursorData ? customCursorData.get() : "",
|
|
|
|
length);
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild->SendSetCursor(aCursor, hasCustomCursor, cursorData,
|
|
|
|
customCursorSize.width,
|
|
|
|
customCursorSize.height, stride, format,
|
|
|
|
aHotspotX, aHotspotY, force)) {
|
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;
|
2019-01-15 16:56:52 +03:00
|
|
|
mCustomCursor = aCursorImage;
|
2015-05-20 04:28:57 +03:00
|
|
|
mCursorHotspotX = aHotspotX;
|
|
|
|
mCursorHotspotY = aHotspotY;
|
|
|
|
mUpdateCursor = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetWidget::ClearCachedCursor() {
|
|
|
|
nsBaseWidget::ClearCachedCursor();
|
|
|
|
mCustomCursor = nullptr;
|
2011-06-22 04:32:43 +04:00
|
|
|
}
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
nsresult PuppetWidget::Paint() {
|
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()) return NS_OK;
|
2012-08-15 22:52:42 +04:00
|
|
|
|
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(), "PuppetWidget",
|
2016-03-31 21:42:13 +03:00
|
|
|
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() &&
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild && mBrowserChild->IsLayersConnected().isSome())) {
|
2013-05-01 09:03:25 +04:00
|
|
|
// Do nothing, the compositor will handle drawing
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->NotifyPainted();
|
2013-05-01 09:03:25 +04:00
|
|
|
}
|
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);
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->NotifyPainted();
|
2013-04-02 22:32:59 +04:00
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 18:15:18 +03:00
|
|
|
void PuppetWidget::OnMemoryPressure(layers::MemoryPressureReason aWhy) {
|
|
|
|
if (aWhy != MemoryPressureReason::LOW_MEMORY_ONGOING && !mVisible &&
|
|
|
|
mLayerManager && XRE_IsContentProcess()) {
|
|
|
|
mLayerManager->ClearCachedResources();
|
2015-05-20 10:45:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2019-08-26 23:25:42 +03:00
|
|
|
if (XRE_IsContentProcess() &&
|
|
|
|
StaticPrefs::browser_tabs_remote_desktopbehavior() &&
|
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; }
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void* PuppetWidget::GetNativeData(uint32_t aDataType) {
|
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.
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
|
|
|
NS_WARNING("Need BrowserChild to get the nativeWindow from!");
|
2017-06-13 20:37:31 +03:00
|
|
|
}
|
2012-07-20 15:16:17 +04:00
|
|
|
mozilla::WindowsHandle nativeData = 0;
|
2019-04-10 01:39:01 +03:00
|
|
|
if (mBrowserChild) {
|
|
|
|
nativeData = mBrowserChild->WidgetNativeData();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-05-09 01:36:07 +04:00
|
|
|
return (void*)nativeData;
|
2013-04-02 22:32:59 +04:00
|
|
|
}
|
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:
|
2019-04-10 01:39:01 +03:00
|
|
|
MOZ_ASSERT(mBrowserChild, "Need BrowserChild to send the message.");
|
|
|
|
if (mBrowserChild) {
|
|
|
|
mBrowserChild->SendSetNativeChildOfShareableWindow(aVal);
|
2015-08-12 18:00:26 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("SetNativeData called with unsupported data type.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-22 22:21:37 +03:00
|
|
|
LayoutDeviceIntPoint PuppetWidget::GetChromeOffset() {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!GetOwningBrowserChild()) {
|
2014-12-11 17:44:07 +03:00
|
|
|
NS_WARNING("PuppetWidget without Tab does not have chrome information.");
|
2017-11-22 22:21:37 +03:00
|
|
|
return LayoutDeviceIntPoint();
|
2014-12-11 17:44:07 +03:00
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
return GetOwningBrowserChild()->GetChromeOffset();
|
2014-12-11 17:44:07 +03:00
|
|
|
}
|
|
|
|
|
2020-02-12 04:44:28 +03:00
|
|
|
LayoutDeviceIntPoint PuppetWidget::WidgetToScreenOffset() {
|
|
|
|
auto positionRalativeToWindow =
|
|
|
|
WidgetToTopLevelWidgetTransform().TransformPoint(LayoutDevicePoint());
|
|
|
|
|
|
|
|
return GetWindowPosition() +
|
|
|
|
LayoutDeviceIntPoint::Round(positionRalativeToWindow);
|
|
|
|
}
|
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
LayoutDeviceIntPoint PuppetWidget::GetWindowPosition() {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!GetOwningBrowserChild()) {
|
2017-11-22 22:21:37 +03:00
|
|
|
return LayoutDeviceIntPoint();
|
2014-12-11 17:44:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t winX, winY, winW, winH;
|
2017-11-22 22:21:37 +03:00
|
|
|
NS_ENSURE_SUCCESS(
|
2019-04-10 01:39:01 +03:00
|
|
|
GetOwningBrowserChild()->GetDimensions(0, &winX, &winY, &winW, &winH),
|
2017-11-22 22:21:37 +03:00
|
|
|
LayoutDeviceIntPoint());
|
|
|
|
return LayoutDeviceIntPoint(winX, winY) +
|
2019-04-10 01:39:01 +03:00
|
|
|
GetOwningBrowserChild()->GetClientOffset();
|
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
|
|
|
}
|
|
|
|
|
2019-06-19 21:20:52 +03:00
|
|
|
LayoutDeviceIntSize PuppetWidget::GetCompositionSize() {
|
2019-06-25 06:16:31 +03:00
|
|
|
Maybe<LayoutDeviceIntRect> visibleRect =
|
|
|
|
mBrowserChild ? mBrowserChild->GetVisibleRect() : Nothing();
|
|
|
|
if (!visibleRect) {
|
2019-06-19 21:20:52 +03:00
|
|
|
return nsBaseWidget::GetCompositionSize();
|
|
|
|
}
|
2019-06-25 06:16:31 +03:00
|
|
|
return visibleRect->Size();
|
2019-06-19 21:20:52 +03:00
|
|
|
}
|
|
|
|
|
2015-05-08 04:29:00 +03:00
|
|
|
uint32_t PuppetWidget::GetMaxTouchPoints() const {
|
2019-07-19 01:45:16 +03:00
|
|
|
return mBrowserChild ? mBrowserChild->MaxTouchPoints() : 0;
|
2015-05-08 04:29:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-29 00:00:25 +03:00
|
|
|
void PuppetWidget::StartAsyncScrollbarDrag(
|
|
|
|
const AsyncDragMetrics& aDragMetrics) {
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->StartScrollbarDrag(aDragMetrics);
|
2015-09-29 00:00:25 +03:00
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
PuppetScreen::PuppetScreen(void* nativeScreen) {}
|
|
|
|
|
2020-03-16 13:56:57 +03:00
|
|
|
PuppetScreen::~PuppetScreen() = default;
|
2012-05-09 01:36:07 +04:00
|
|
|
|
|
|
|
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();
|
2018-01-10 19:14:16 +03:00
|
|
|
return nsIntSize(r.Width(), r.Height());
|
2014-12-11 17:44:07 +03:00
|
|
|
}
|
|
|
|
|
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();
|
2018-01-10 19:14:16 +03:00
|
|
|
r.GetRect(outLeft, outTop, outWidth, outHeight);
|
2012-05-09 01:36:07 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-03-16 13:56:57 +03:00
|
|
|
PuppetScreenManager::~PuppetScreenManager() = default;
|
2012-05-09 01:36:07 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetScreenManager::GetPrimaryScreen(nsIScreen** outScreen) {
|
|
|
|
NS_IF_ADDREF(*outScreen = mOneScreen.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-10-02 21:48:11 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetScreenManager::GetTotalScreenPixels(int64_t* aTotalScreenPixels) {
|
|
|
|
MOZ_ASSERT(aTotalScreenPixels);
|
|
|
|
if (mOneScreen) {
|
|
|
|
int32_t x, y, width, height;
|
|
|
|
x = y = width = height = 0;
|
|
|
|
mOneScreen->GetRect(&x, &y, &width, &height);
|
|
|
|
*aTotalScreenPixels = width * height;
|
|
|
|
} else {
|
|
|
|
*aTotalScreenPixels = 0;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-04 11:16:31 +03:00
|
|
|
ScreenIntMargin PuppetWidget::GetSafeAreaInsets() const {
|
|
|
|
return mSafeAreaInsets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetWidget::UpdateSafeAreaInsets(
|
|
|
|
const ScreenIntMargin& aSafeAreaInsets) {
|
|
|
|
mSafeAreaInsets = aSafeAreaInsets;
|
|
|
|
}
|
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
nsIWidgetListener* PuppetWidget::GetCurrentWidgetListener() {
|
|
|
|
if (!mPreviouslyAttachedWidgetListener || !mAttachedWidgetListener) {
|
|
|
|
return mAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAttachedWidgetListener->GetView()->IsPrimaryFramePaintSuppressed()) {
|
|
|
|
return mPreviouslyAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAttachedWidgetListener;
|
|
|
|
}
|
|
|
|
|
2016-02-02 11:05:56 +03:00
|
|
|
void PuppetWidget::SetCandidateWindowForPlugin(
|
|
|
|
const CandidateWindowPosition& aPosition) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2015-12-29 16:57:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSetCandidateWindowForPlugin(aPosition);
|
2015-12-29 16:57:38 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 08:47:55 +03:00
|
|
|
void PuppetWidget::EnableIMEForPlugin(bool aEnable) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2018-05-17 08:47:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If current IME state isn't plugin, we ignore this call.
|
|
|
|
if (NS_WARN_IF(HaveValidInputContextCache() &&
|
|
|
|
mInputContext.mIMEState.mEnabled != IMEState::UNKNOWN &&
|
|
|
|
mInputContext.mIMEState.mEnabled != IMEState::PLUGIN)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't have valid state in cache or state is plugin, so delegate to
|
|
|
|
// chrome process.
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendEnableIMEForPlugin(aEnable);
|
2018-05-17 08:47:55 +03:00
|
|
|
}
|
|
|
|
|
2016-01-20 04:44:44 +03:00
|
|
|
void PuppetWidget::ZoomToRect(const uint32_t& aPresShellId,
|
2018-11-01 23:15:46 +03:00
|
|
|
const ScrollableLayerGuid::ViewID& aViewId,
|
2016-01-20 04:44:44 +03:00
|
|
|
const CSSRect& aRect, const uint32_t& aFlags) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2016-01-20 04:44:44 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->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) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2016-04-26 11:18:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendLookUpDictionary(nsString(aText), aFontRangeArray,
|
|
|
|
aIsVertical, aPoint);
|
2016-04-26 11:18:04 +03:00
|
|
|
}
|
|
|
|
|
2016-03-29 10:03:54 +03:00
|
|
|
bool PuppetWidget::HasPendingInputEvent() {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2016-03-29 10:03:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->GetIPCChannel()->PeekMessages(
|
2016-04-13 04:51:34 +03:00
|
|
|
[&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
|
|
|
|
|
|
|
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) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (NS_WARN_IF(!mBrowserChild)) {
|
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
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
if (NS_WARN_IF(!mBrowserChild->SendOnWindowedPluginKeyEvent(aKeyEventData))) {
|
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
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-08-07 05:58:36 +03:00
|
|
|
nsresult PuppetWidget::SetSystemFont(const nsCString& aFontName) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2018-08-07 05:58:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSetSystemFont(aFontName);
|
2018-08-07 05:58:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PuppetWidget::GetSystemFont(nsCString& aFontName) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2018-08-07 05:58:36 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendGetSystemFont(&aFontName);
|
2018-08-07 05:58:36 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-15 04:00:07 +03:00
|
|
|
nsresult PuppetWidget::SetPrefersReducedMotionOverrideForTest(bool aValue) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2018-09-15 04:00:07 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendSetPrefersReducedMotionOverrideForTest(aValue);
|
2018-09-15 04:00:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult PuppetWidget::ResetPrefersReducedMotionOverrideForTest() {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2018-09-15 04:00:07 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
mBrowserChild->SendResetPrefersReducedMotionOverrideForTest();
|
2018-09-15 04:00:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|