inLayoutUtils.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "inLayoutUtils.h"
  6. #include "nsIDocument.h"
  7. #include "nsIDOMDocument.h"
  8. #include "nsIContent.h"
  9. #include "nsIContentViewer.h"
  10. #include "nsPIDOMWindow.h"
  11. #include "nsIDocShell.h"
  12. #include "nsIPresShell.h"
  13. #include "nsPresContext.h"
  14. #include "mozilla/EventStateManager.h"
  15. #include "mozilla/dom/Element.h"
  16. using namespace mozilla;
  17. ///////////////////////////////////////////////////////////////////////////////
  18. EventStateManager*
  19. inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
  20. {
  21. NS_PRECONDITION(aElement, "Passing in a null element is bad");
  22. nsCOMPtr<nsIDOMDocument> domDoc;
  23. aElement->GetOwnerDocument(getter_AddRefs(domDoc));
  24. nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
  25. if (!doc) {
  26. NS_WARNING("Could not get an nsIDocument!");
  27. return nullptr;
  28. }
  29. nsIPresShell *shell = doc->GetShell();
  30. if (!shell)
  31. return nullptr;
  32. return shell->GetPresContext()->EventStateManager();
  33. }
  34. nsIDOMDocument*
  35. inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
  36. {
  37. nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
  38. if (content) {
  39. nsCOMPtr<nsIDocument> doc = content->GetComposedDoc();
  40. if (doc) {
  41. nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content)));
  42. return domdoc;
  43. }
  44. }
  45. return nullptr;
  46. }
  47. nsIDOMNode*
  48. inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
  49. {
  50. nsPIDOMWindowOuter* pwin = aDoc.GetWindow();
  51. if (!pwin) {
  52. return nullptr;
  53. }
  54. nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
  55. return node;
  56. }