gecko-dev/dom/base/nsPIDOMWindowInlines.h
Jorg K a06070b4a3 Bug 1245310 - Restore null check in GetFocusedNode(). r=khuey
--HG--
extra : rebase_source : fba203582cf9c6436879bf2923cf19e19147bf5f
2016-02-02 15:42:00 +01:00

133 lines
2.6 KiB
C++

/* 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/. */
template<class T>
nsPIDOMWindowInner*
nsPIDOMWindow<T>::AsInner()
{
MOZ_ASSERT(IsInnerWindow());
return reinterpret_cast<nsPIDOMWindowInner*>(this);
}
template<class T>
const nsPIDOMWindowInner*
nsPIDOMWindow<T>::AsInner() const
{
MOZ_ASSERT(IsInnerWindow());
return reinterpret_cast<const nsPIDOMWindowInner*>(this);
}
template<class T>
nsPIDOMWindowOuter*
nsPIDOMWindow<T>::AsOuter()
{
MOZ_ASSERT(IsOuterWindow());
return reinterpret_cast<nsPIDOMWindowOuter*>(this);
}
template<class T>
const nsPIDOMWindowOuter*
nsPIDOMWindow<T>::AsOuter() const
{
MOZ_ASSERT(IsOuterWindow());
return reinterpret_cast<const nsPIDOMWindowOuter*>(this);
}
template <class T>
bool
nsPIDOMWindow<T>::IsLoadingOrRunningTimeout() const
{
if (IsOuterWindow()) {
return AsOuter()->GetCurrentInnerWindow()->IsLoadingOrRunningTimeout();
}
return !mIsDocumentLoaded || mRunningTimeout;
}
template <class T>
bool
nsPIDOMWindow<T>::IsLoading() const
{
if (IsOuterWindow()) {
auto* win = AsOuter()->GetCurrentInnerWindow();
if (!win) {
NS_ERROR("No current inner window available!");
return false;
}
return win->IsLoading();
}
if (!mOuterWindow) {
NS_ERROR("IsLoading() called on orphan inner window!");
return false;
}
return !mIsDocumentLoaded;
}
template <class T>
bool
nsPIDOMWindow<T>::IsHandlingResizeEvent() const
{
if (IsOuterWindow()) {
auto* win = AsOuter()->GetCurrentInnerWindow();
if (!win) {
NS_ERROR("No current inner window available!");
return false;
}
return win->IsHandlingResizeEvent();
}
if (!mOuterWindow) {
NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!");
return false;
}
return mIsHandlingResizeEvent;
}
bool
nsPIDOMWindowInner::IsCurrentInnerWindow() const
{
return mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == AsInner();
}
bool
nsPIDOMWindowInner::HasActiveDocument()
{
return IsCurrentInnerWindow() ||
(mOuterWindow &&
mOuterWindow->GetCurrentInnerWindow() &&
mOuterWindow->GetCurrentInnerWindow()->GetDoc() == mDoc);
}
template <class T>
nsIDocShell*
nsPIDOMWindow<T>::GetDocShell() const
{
if (mOuterWindow) {
return mOuterWindow->GetDocShell();
}
return mDocShell;
}
template <class T>
nsIContent*
nsPIDOMWindow<T>::GetFocusedNode() const
{
if (IsOuterWindow()) {
return mInnerWindow ? mInnerWindow->GetFocusedNode() : nullptr;
}
return mFocusedNode;
}