ContainerBoxObject.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "mozilla/dom/ContainerBoxObject.h"
  6. #include "mozilla/dom/ContainerBoxObjectBinding.h"
  7. #include "nsCOMPtr.h"
  8. #include "nsIDocShell.h"
  9. #include "nsIContent.h"
  10. #include "nsIDocument.h"
  11. #include "nsIFrame.h"
  12. #include "nsSubDocumentFrame.h"
  13. namespace mozilla {
  14. namespace dom {
  15. ContainerBoxObject::ContainerBoxObject()
  16. {
  17. }
  18. ContainerBoxObject::~ContainerBoxObject()
  19. {
  20. }
  21. JSObject*
  22. ContainerBoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
  23. {
  24. return ContainerBoxObjectBinding::Wrap(aCx, this, aGivenProto);
  25. }
  26. already_AddRefed<nsIDocShell>
  27. ContainerBoxObject::GetDocShell()
  28. {
  29. nsSubDocumentFrame *subDocFrame = do_QueryFrame(GetFrame(false));
  30. if (subDocFrame) {
  31. // Ok, the frame for mContent is an nsSubDocumentFrame, it knows how
  32. // to reach the docshell, so ask it...
  33. nsCOMPtr<nsIDocShell> ret;
  34. subDocFrame->GetDocShell(getter_AddRefs(ret));
  35. return ret.forget();
  36. }
  37. if (!mContent) {
  38. return nullptr;
  39. }
  40. // No nsSubDocumentFrame available for mContent, try if there's a mapping
  41. // between mContent's document to mContent's subdocument.
  42. nsIDocument *doc = mContent->GetComposedDoc();
  43. if (!doc) {
  44. return nullptr;
  45. }
  46. nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent);
  47. if (!sub_doc) {
  48. return nullptr;
  49. }
  50. nsCOMPtr<nsIDocShell> result = sub_doc->GetDocShell();
  51. return result.forget();
  52. }
  53. } // namespace dom
  54. } // namespace mozilla
  55. nsresult
  56. NS_NewContainerBoxObject(nsIBoxObject** aResult)
  57. {
  58. NS_ADDREF(*aResult = new mozilla::dom::ContainerBoxObject());
  59. return NS_OK;
  60. }