2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2006-05-17 06:21:07 +04:00
|
|
|
|
|
|
|
#include "inLayoutUtils.h"
|
|
|
|
|
|
|
|
#include "nsIDocument.h"
|
2013-08-22 10:30:55 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2006-05-17 06:21:07 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2006-05-17 06:38:51 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2006-05-17 06:21:07 +04:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIPresShell.h"
|
2006-05-17 06:38:40 +04:00
|
|
|
#include "nsPresContext.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2013-07-24 03:39:17 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2006-05-17 06:21:07 +04:00
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2006-05-17 06:21:07 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager*
|
2006-05-17 06:21:07 +04:00
|
|
|
inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
|
|
|
|
{
|
2006-05-17 06:37:43 +04:00
|
|
|
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 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-05-17 06:37:43 +04:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2008-12-16 16:16:33 +03:00
|
|
|
if (!shell)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-05-17 06:37:43 +04:00
|
|
|
|
2006-05-17 06:38:41 +04:00
|
|
|
return shell->GetPresContext()->EventStateManager();
|
2006-05-17 06:21:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMDocument*
|
|
|
|
inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2006-05-17 06:33:39 +04:00
|
|
|
if (content) {
|
2014-08-23 00:11:27 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = content->GetComposedDoc();
|
2006-05-17 06:33:39 +04:00
|
|
|
if (doc) {
|
2006-05-17 06:38:19 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content)));
|
2006-05-17 06:34:00 +04:00
|
|
|
|
|
|
|
return domdoc;
|
2006-05-17 06:33:39 +04:00
|
|
|
}
|
2006-05-17 06:21:07 +04:00
|
|
|
}
|
2013-07-24 03:39:17 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-05-17 06:21:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNode*
|
2013-07-24 03:39:17 +04:00
|
|
|
inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
|
2006-05-17 06:21:07 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* pwin = aDoc.GetWindow();
|
2013-07-24 03:39:17 +04:00
|
|
|
if (!pwin) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2006-05-17 06:33:39 +04:00
|
|
|
|
2013-07-24 03:39:17 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
|
|
|
|
return node;
|
2006-05-17 06:21:07 +04:00
|
|
|
}
|
|
|
|
|