dom/base/nsPIDOMWindowInlines.h
author Kyle Huey <khuey@kylehuey.com>
Sat, 30 Jan 2016 09:05:36 -0800
changeset 320665 e22b3043887ed36bf2c634c2924a7c8d39d226b1
child 321040 00793d7d19d9d5f07f4a8237f5382a918fbeabf3
permissions -rw-r--r--
Bug 1241764: Replace nsPIDOMWindow with nsPIDOMWindowInner/Outer. r=mrbkap,smaug

/* 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->GetFocusedNode();
  }

  return mFocusedNode;
}