Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/dom/Text.h"
8 : #include "nsTextNode.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 : already_AddRefed<Text>
14 0 : Text::SplitText(uint32_t aOffset, ErrorResult& rv)
15 : {
16 0 : nsCOMPtr<nsIContent> newChild;
17 0 : rv = SplitData(aOffset, getter_AddRefs(newChild));
18 0 : if (rv.Failed()) {
19 0 : return nullptr;
20 : }
21 0 : return newChild.forget().downcast<Text>();
22 : }
23 :
24 : /* static */ already_AddRefed<Text>
25 0 : Text::Constructor(const GlobalObject& aGlobal,
26 : const nsAString& aData, ErrorResult& aRv)
27 : {
28 0 : nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
29 0 : if (!window || !window->GetDoc()) {
30 0 : aRv.Throw(NS_ERROR_FAILURE);
31 0 : return nullptr;
32 : }
33 :
34 0 : return window->GetDoc()->CreateTextNode(aData);
35 : }
36 :
37 : } // namespace dom
38 : } // namespace mozilla
|