2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "inLayoutUtils.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
2013-08-21 23:30:55 -07:00
|
|
|
#include "nsIDOMDocument.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentViewer.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
2014-03-31 21:09:23 -07:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2013-07-23 16:39:17 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-31 21:09:23 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-03-31 21:09:23 -07:00
|
|
|
EventStateManager*
|
2007-03-22 10:30:00 -07:00
|
|
|
inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aElement, "Passing in a null element is bad");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
aElement->GetOwnerDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
|
|
|
|
|
|
|
if (!doc) {
|
|
|
|
NS_WARNING("Could not get an nsIDocument!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2008-12-16 05:16:33 -08:00
|
|
|
if (!shell)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return shell->GetPresContext()->EventStateManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMDocument*
|
|
|
|
inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (content) {
|
2014-08-22 13:11:27 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetComposedDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content)));
|
|
|
|
|
|
|
|
return domdoc;
|
|
|
|
}
|
|
|
|
}
|
2013-07-23 16:39:17 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2013-07-23 16:39:17 -07:00
|
|
|
inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-07-23 16:39:17 -07:00
|
|
|
nsPIDOMWindow* pwin = aDoc.GetWindow();
|
|
|
|
if (!pwin) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-07-23 16:39:17 -07:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
|
|
|
|
return node;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|