зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1494713 - Add `nsWindow::From`. r=jchen
Differential Revision: https://phabricator.services.mozilla.com/D11289 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
aa4bb114b9
Коммит
994f3a458c
|
@ -145,11 +145,9 @@ SessionAccessibility::GetInstanceFor(Accessible* aAccessible)
|
|||
nsCOMPtr<nsIWidget> rootWidget;
|
||||
vm->GetRootWidget(getter_AddRefs(rootWidget));
|
||||
// `rootWidget` can be one of several types. Here we make sure it is an
|
||||
// android nsWindow that implemented NS_NATIVE_WIDGET to return itself.
|
||||
if (rootWidget &&
|
||||
rootWidget->WindowType() == nsWindowType::eWindowType_toplevel &&
|
||||
rootWidget->GetNativeData(NS_NATIVE_WIDGET) == rootWidget) {
|
||||
return static_cast<nsWindow*>(rootWidget.get())->GetSessionAccessibility();
|
||||
// android nsWindow.
|
||||
if (RefPtr<nsWindow> window = nsWindow::From(rootWidget)) {
|
||||
return window->GetSessionAccessibility();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -818,24 +818,10 @@ __attribute__ ((visibility("default")))
|
|||
jobject JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *env, jclass, jlong size);
|
||||
|
||||
static RefPtr<nsWindow>
|
||||
GetWidget(mozIDOMWindowProxy* aWindow)
|
||||
{
|
||||
MOZ_ASSERT(aWindow);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> domWindow = nsPIDOMWindowOuter::From(aWindow);
|
||||
nsCOMPtr<nsIWidget> widget =
|
||||
widget::WidgetUtils::DOMWindowToWidget(domWindow);
|
||||
MOZ_ASSERT(widget);
|
||||
|
||||
return RefPtr<nsWindow>(static_cast<nsWindow*>(widget.get()));
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::ContentDocumentChanged(mozIDOMWindowProxy* aWindow)
|
||||
{
|
||||
auto widget = GetWidget(aWindow);
|
||||
if (widget) {
|
||||
if (RefPtr<nsWindow> widget = nsWindow::From(nsPIDOMWindowOuter::From(aWindow))) {
|
||||
widget->SetContentDocumentDisplayed(false);
|
||||
}
|
||||
}
|
||||
|
@ -843,8 +829,7 @@ AndroidBridge::ContentDocumentChanged(mozIDOMWindowProxy* aWindow)
|
|||
bool
|
||||
AndroidBridge::IsContentDocumentDisplayed(mozIDOMWindowProxy* aWindow)
|
||||
{
|
||||
auto widget = GetWidget(aWindow);
|
||||
if (widget) {
|
||||
if (RefPtr<nsWindow> widget = nsWindow::From(nsPIDOMWindowOuter::From(aWindow))) {
|
||||
return widget->IsContentDocumentDisplayed();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -47,10 +47,10 @@ public:
|
|||
int64_t aContentId, int64_t aTabId)
|
||||
{
|
||||
nsCOMPtr<nsIWidget> widget = GetWidget(aContentId, aTabId);
|
||||
if (widget && widget->GetNativeData(NS_NATIVE_WIDGET) == widget) {
|
||||
if (RefPtr<nsWindow> window = nsWindow::From(widget)) {
|
||||
java::GeckoProcessManager::SetEditableChildParent(
|
||||
aEditableChild,
|
||||
static_cast<nsWindow*>(widget.get())->GetEditableParent());
|
||||
window->GetEditableParent());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -618,18 +618,7 @@ nsAppShell::Observe(nsISupports* aSubject,
|
|||
// for this particular GeckoView.
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aSubject);
|
||||
MOZ_ASSERT(doc);
|
||||
nsCOMPtr<nsIWidget> widget =
|
||||
widget::WidgetUtils::DOMWindowToWidget(doc->GetWindow());
|
||||
|
||||
// `widget` may be one of several different types in the parent
|
||||
// process, including the Android nsWindow, PuppetWidget, etc. To
|
||||
// ensure that we only accept the Android nsWindow, we check that the
|
||||
// widget is a top-level window and that its NS_NATIVE_WIDGET value is
|
||||
// non-null, which is not the case for non-native widgets like
|
||||
// PuppetWidget.
|
||||
if (widget &&
|
||||
widget->WindowType() == nsWindowType::eWindowType_toplevel &&
|
||||
widget->GetNativeData(NS_NATIVE_WIDGET) == widget) {
|
||||
if (const RefPtr<nsWindow> window = nsWindow::From(doc->GetWindow())) {
|
||||
if (jni::IsAvailable()) {
|
||||
// When our first window has loaded, assume any JS
|
||||
// initialization has run and set Gecko to ready.
|
||||
|
@ -637,7 +626,6 @@ nsAppShell::Observe(nsISupports* aSubject,
|
|||
java::GeckoThread::State::PROFILE_READY(),
|
||||
java::GeckoThread::State::RUNNING());
|
||||
}
|
||||
const auto window = static_cast<nsWindow*>(widget.get());
|
||||
window->OnGeckoViewReady();
|
||||
}
|
||||
} else if (!strcmp(aTopic, "quit-application")) {
|
||||
|
|
|
@ -1263,10 +1263,8 @@ nsWindow::GeckoViewSupport::Open(const jni::Class::LocalRef& aCls,
|
|||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> pdomWindow =
|
||||
nsPIDOMWindowOuter::From(domWindow);
|
||||
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(pdomWindow);
|
||||
MOZ_ASSERT(widget);
|
||||
|
||||
const auto window = static_cast<nsWindow*>(widget.get());
|
||||
const RefPtr<nsWindow> window = nsWindow::From(pdomWindow);
|
||||
MOZ_ASSERT(window);
|
||||
window->SetScreenId(aScreenId);
|
||||
|
||||
// Attach a new GeckoView support object to the new window.
|
||||
|
@ -1404,6 +1402,32 @@ nsWindow::InitNatives()
|
|||
a11y::SessionAccessibility::Init();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsWindow>
|
||||
nsWindow::From(nsPIDOMWindowOuter* aDOMWindow)
|
||||
{
|
||||
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aDOMWindow);
|
||||
return From(widget);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsWindow>
|
||||
nsWindow::From(nsIWidget* aWidget)
|
||||
{
|
||||
// `widget` may be one of several different types in the parent
|
||||
// process, including the Android nsWindow, PuppetWidget, etc. To
|
||||
// ensure that the cast to the Android nsWindow is valid, we check that the
|
||||
// widget is a top-level window and that its NS_NATIVE_WIDGET value is
|
||||
// non-null, which is not the case for non-native widgets like
|
||||
// PuppetWidget.
|
||||
if (aWidget &&
|
||||
aWidget->WindowType() == nsWindowType::eWindowType_toplevel &&
|
||||
aWidget->GetNativeData(NS_NATIVE_WIDGET) == aWidget) {
|
||||
|
||||
RefPtr<nsWindow> window = static_cast<nsWindow*>(aWidget);
|
||||
return window.forget();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsWindow*
|
||||
nsWindow::TopWindow()
|
||||
{
|
||||
|
|
|
@ -207,6 +207,9 @@ private:
|
|||
mozilla::Atomic<bool, mozilla::ReleaseAcquire> mContentDocumentDisplayed;
|
||||
|
||||
public:
|
||||
static already_AddRefed<nsWindow> From(nsPIDOMWindowOuter* aDOMWindow);
|
||||
static already_AddRefed<nsWindow> From(nsIWidget* aWidget);
|
||||
|
||||
static nsWindow* TopWindow();
|
||||
|
||||
static mozilla::Modifiers GetModifiers(int32_t aMetaState);
|
||||
|
|
Загрузка…
Ссылка в новой задаче