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"
|
2020-10-15 20:51:36 +03:00
|
|
|
#include "nsRefreshDriver.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),
|
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".
|
2020-12-21 08:52:03 +03:00
|
|
|
mInputContext.mIMEState.mEnabled = IMEEnabled::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);
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager = parent->GetWindowRenderer()->AsLayerManager();
|
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();
|
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;
|
2021-07-29 20:19:48 +03:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
2010-12-07 05:05:25 +03:00
|
|
|
}
|
2021-07-29 20:19:48 +03: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
|
|
|
}
|
|
|
|
|
2021-03-22 23:49:04 +03:00
|
|
|
if (mBrowserChild && !aRect.IsEmpty() && !mWidgetPaintTask.IsPending()) {
|
|
|
|
mWidgetPaintTask = new WidgetPaintTask(this);
|
|
|
|
nsCOMPtr<nsIRunnable> event(mWidgetPaintTask.get());
|
|
|
|
SchedulerGroup::Dispatch(TaskCategory::Other, event.forget());
|
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;
|
2020-11-24 04:31:46 +03:00
|
|
|
mContentCache.OnCompositionEvent(*compositionEvent);
|
2015-12-11 09:15:57 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-14 08:07:56 +03:00
|
|
|
nsIWidget::ContentAndAPZEventStatus PuppetWidget::DispatchInputEvent(
|
|
|
|
WidgetInputEvent* aEvent) {
|
|
|
|
ContentAndAPZEventStatus status;
|
2015-06-04 23:51:10 +03:00
|
|
|
if (!AsyncPanZoomEnabled()) {
|
2021-04-14 08:07:56 +03:00
|
|
|
DispatchEvent(aEvent, status.mContentStatus);
|
2015-03-07 01:26:59 +03:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2021-04-14 08:07:56 +03:00
|
|
|
return status;
|
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;
|
2021-04-22 19:01:26 +03:00
|
|
|
case eTouchEventClass:
|
|
|
|
Unused << mBrowserChild->SendDispatchTouchEvent(*aEvent->AsTouchEvent());
|
|
|
|
break;
|
2015-03-07 01:26:59 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unsupported event type");
|
|
|
|
}
|
|
|
|
|
2021-04-14 08:07:56 +03:00
|
|
|
return status;
|
2015-03-07 01:26:59 +03:00
|
|
|
}
|
|
|
|
|
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(
|
2021-02-24 04:27:10 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage,
|
|
|
|
MouseButton aButton, nsIWidget::Modifiers aModifierFlags,
|
|
|
|
nsIObserver* aObserver) {
|
2015-04-14 18:36:36 +03:00
|
|
|
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(
|
2021-02-24 04:27:10 +03:00
|
|
|
aPoint, static_cast<uint32_t>(aNativeMessage),
|
|
|
|
static_cast<int16_t>(aButton), static_cast<uint32_t>(aModifierFlags),
|
Bug 1691622 - part 4: Make `synthesizeNativeMouseClick*()` aware of modifiers r=smaug,geckoview-reviewers,m_kato
Surprisingly, they don't take modifiers, and
`nsIWidget::SynthesizeNativeMouseEvent()` which are implementations of
`nsIDOMWindowUtils::SendNativeMouseEvent()` treat given modifier flags
are native's ones, and handle modifiers only on macOS. Therefore, this
patch makes them handle native modifiers of Gecko.
Unfortunately, I'm not so familiar with Android API, and in the short
term, I don't need the support on Android. Therefore, this patch just
adds a TODO comment on Android widget.
Additionally, we don't have a simple way to set modifier only while
posting a mouse input on Windows too. It requires complicated code.
Therefore, I don't add the support for it on Windows too.
Differential Revision: https://phabricator.services.mozilla.com/D105758
2021-02-24 04:27:07 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-02-19 08:35:40 +03:00
|
|
|
nsresult PuppetWidget::SynthesizeNativeTouchPadPinch(
|
|
|
|
TouchpadPinchPhase aEventPhase, float aScale, LayoutDeviceIntPoint aPoint,
|
|
|
|
int32_t aModifierFlags) {
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBrowserChild->SendSynthesizeNativeTouchPadPinch(aEventPhase, aScale, aPoint,
|
|
|
|
aModifierFlags);
|
|
|
|
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
|
|
|
|
2021-03-02 21:29:45 +03:00
|
|
|
nsresult PuppetWidget::SynthesizeNativePenInput(
|
|
|
|
uint32_t aPointerId, TouchPointerState aPointerState,
|
|
|
|
LayoutDeviceIntPoint aPoint, double aPressure, uint32_t aRotation,
|
|
|
|
int32_t aTiltX, int32_t aTiltY, nsIObserver* aObserver) {
|
|
|
|
AutoObserverNotifier notifier(aObserver, "peninput");
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBrowserChild->SendSynthesizeNativePenInput(aPointerId, aPointerState, aPoint,
|
|
|
|
aPressure, aRotation, aTiltX,
|
|
|
|
aTiltY, notifier.SaveObserver());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-03-12 05:10:43 +03:00
|
|
|
nsresult PuppetWidget::SynthesizeNativeTouchpadDoubleTap(
|
|
|
|
LayoutDeviceIntPoint aPoint, uint32_t aModifierFlags) {
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
mBrowserChild->SendSynthesizeNativeTouchpadDoubleTap(aPoint, aModifierFlags);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-22 17:56:43 +03:00
|
|
|
void PuppetWidget::LockNativePointer() {
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBrowserChild->SendLockNativePointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetWidget::UnlockNativePointer() {
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mBrowserChild->SendUnlockNativePointer();
|
|
|
|
}
|
|
|
|
|
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) {
|
Bug 1685491 - part.1: Map typical commands to synthesized keyboard events for test on Linux and macOS r=smaug,remote-protocol-reviewers
Currently, we don't allow keyboard events synthesized for tests retrieve native
key bindings in content process. However, due to this, we cannot test keyboard
navigation, deleting per word, etc on Linux and macOS either with mochitest
or WPT. For making better compatibility with the other browsers, we should
write WPT more with the test driver. Therefore, we should allow keyboard
events synthesized for tests retrieve native key bindings.
On the other hand, if we make them retrieve customized keyboard shortcuts
in the environment, some developers may not be able to run tests locally without
resetting their customization. Therefore, this patch makes `NativeKeyBindings`
set "standard" shortcut keys on the platform instead of retrieving actual
shortcut key results.
If referring the default shortcut key bindings is not good thing for
WebDriver/CDP, perhaps, `TextInputProcessor` should have a new flag which can
refer customized shortcut keys even in content process. But I think that it
should be done in another bug because some edit commands are mapped forcibly
like this patch.
https://searchfox.org/mozilla-central/rev/c03e8de87cdb0ce0378c0886d3c0ce8bbf9dc44e/remote/domains/parent/Input.jsm#82-102
Differential Revision: https://phabricator.services.mozilla.com/D102877
2021-02-02 06:02:30 +03:00
|
|
|
MOZ_ASSERT(!aEvent.mFlags.mIsSynthesizedForTests);
|
2017-05-19 11:49:41 +03:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2021-07-23 01:58:57 +03:00
|
|
|
WindowRenderer* PuppetWidget::GetWindowRenderer() {
|
2021-07-29 20:19:48 +03: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.
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager = new BasicLayerManager(BasicLayerManager::BLM_OFFSCREEN);
|
|
|
|
return mLayerManager;
|
2017-02-12 22:38:34 +03:00
|
|
|
}
|
|
|
|
|
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));
|
2021-07-29 20:19:48 +03:00
|
|
|
mLayerManager = new BasicLayerManager(this);
|
2013-11-01 10:36:02 +04:00
|
|
|
}
|
2017-02-12 22:38:34 +03:00
|
|
|
|
2021-07-29 20:19:48 +03:00
|
|
|
return mLayerManager;
|
2010-08-21 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
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();
|
2021-07-29 20:19: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-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 {
|
2020-12-21 08:52:03 +03:00
|
|
|
return (mInputContext.mIMEState.mEnabled != IMEEnabled::Unknown &&
|
2018-05-17 08:47:55 +03:00
|
|
|
IMEStateManager::GetWidgetForActiveInputContext() == this);
|
|
|
|
}
|
|
|
|
|
2020-10-17 21:07:03 +03:00
|
|
|
nsRefreshDriver* PuppetWidget::GetTopLevelRefreshDriver() const {
|
|
|
|
if (!mBrowserChild) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PresShell* presShell = mBrowserChild->GetTopLevelPresShell()) {
|
|
|
|
return presShell->GetRefreshDriver();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
2020-10-14 02:29:29 +03:00
|
|
|
|
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) {
|
2020-12-21 11:26:24 +03:00
|
|
|
// When IME gets focus, we should initialize all information of the
|
|
|
|
// content.
|
|
|
|
if (NS_WARN_IF(!mContentCache.CacheAll(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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
2020-10-14 02:29:29 +03:00
|
|
|
|
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
|
|
|
|
2020-12-21 11:26:24 +03:00
|
|
|
if (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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
2014-02-26 04:48:02 +04:00
|
|
|
MOZ_ASSERT(aIMENotification.mMessage == NOTIFY_IME_OF_TEXT_CHANGE,
|
|
|
|
"Passed wrong notification");
|
2020-10-14 02:29:29 +03:00
|
|
|
|
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
|
|
|
// 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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
2014-02-26 04:48:02 +04:00
|
|
|
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-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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2014-09-11 17:46:17 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2020-10-23 11:07:02 +03:00
|
|
|
MOZ_ASSERT(IMEStateManager::CanSendNotificationToWidget());
|
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;
|
|
|
|
}
|
2020-12-21 11:26:24 +03:00
|
|
|
if (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;
|
|
|
|
};
|
|
|
|
|
2021-04-20 12:47:32 +03:00
|
|
|
void PuppetWidget::SetCursor(const Cursor& aCursor) {
|
2019-04-10 01:39:01 +03:00
|
|
|
if (!mBrowserChild) {
|
2019-01-15 16:56:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-20 12:47:32 +03:00
|
|
|
const bool force = mUpdateCursor;
|
|
|
|
if (!force && mCursor == aCursor) {
|
2016-12-21 03:13:08 +03:00
|
|
|
return;
|
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;
|
2021-05-05 12:41:24 +03:00
|
|
|
ImageResolution resolution = aCursor.mResolution;
|
2021-04-20 12:47:32 +03:00
|
|
|
if (aCursor.IsCustom()) {
|
2021-04-27 14:06:00 +03:00
|
|
|
int32_t width = 0, height = 0;
|
|
|
|
aCursor.mContainer->GetWidth(&width);
|
|
|
|
aCursor.mContainer->GetHeight(&height);
|
|
|
|
const int32_t flags =
|
|
|
|
imgIContainer::FLAG_SYNC_DECODE | imgIContainer::FLAG_ASYNC_NOTIFY;
|
|
|
|
RefPtr<SourceSurface> surface;
|
|
|
|
if (width && height &&
|
|
|
|
aCursor.mContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
// For vector images, scale to device pixels.
|
2021-05-05 12:41:24 +03:00
|
|
|
resolution.ScaleBy(GetDefaultScale().scale);
|
|
|
|
resolution.ApplyInverseTo(width, height);
|
2021-04-27 14:06:00 +03:00
|
|
|
surface = aCursor.mContainer->GetFrameAtSize(
|
2021-05-10 10:15:06 +03:00
|
|
|
{width, height}, imgIContainer::FRAME_CURRENT, flags);
|
2021-04-27 14:06:00 +03:00
|
|
|
} else {
|
|
|
|
// NOTE(emilio): We get the frame at the full size, ignoring resolution,
|
|
|
|
// because we're going to rasterize it, and we'd effectively lose the
|
|
|
|
// extra pixels if we rasterized to CustomCursorSize.
|
|
|
|
surface =
|
|
|
|
aCursor.mContainer->GetFrame(imgIContainer::FRAME_CURRENT, flags);
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 01:07:26 +03:00
|
|
|
nsDependentCString cursorData(customCursorData ? customCursorData.get() : "",
|
|
|
|
length);
|
2021-04-20 12:47:32 +03:00
|
|
|
if (!mBrowserChild->SendSetCursor(
|
|
|
|
aCursor.mDefaultCursor, hasCustomCursor, cursorData,
|
2021-05-10 10:15:06 +03:00
|
|
|
customCursorSize.width, customCursorSize.height, resolution.mX,
|
|
|
|
resolution.mY, stride, format, aCursor.mHotspotX, aCursor.mHotspotY,
|
|
|
|
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;
|
2011-06-22 04:32:43 +04:00
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:40 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-22 23:49:04 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::WidgetPaintTask::Run() {
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->Paint();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PuppetWidget::Paint() {
|
|
|
|
if (!GetCurrentWidgetListener()) return;
|
|
|
|
|
|
|
|
mWidgetPaintTask.Revoke();
|
|
|
|
|
|
|
|
RefPtr<PuppetWidget> strongThis(this);
|
|
|
|
|
|
|
|
GetCurrentWidgetListener()->WillPaintWindow(this);
|
|
|
|
|
|
|
|
if (GetCurrentWidgetListener()) {
|
|
|
|
GetCurrentWidgetListener()->DidPaintWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 02:36:45 +03:00
|
|
|
void PuppetWidget::PaintNowIfNeeded() {
|
2021-03-22 23:49:04 +03:00
|
|
|
if (IsVisible() && mWidgetPaintTask.IsPending()) {
|
|
|
|
Paint();
|
2016-07-23 02:36:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-10 18:15:18 +03:00
|
|
|
void PuppetWidget::OnMemoryPressure(layers::MemoryPressureReason aWhy) {
|
|
|
|
if (aWhy != MemoryPressureReason::LOW_MEMORY_ONGOING && !mVisible &&
|
2021-07-29 20:19:48 +03:00
|
|
|
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; }
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-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 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() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|