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 #ifndef mozilla_dom_Text_h
8 #define mozilla_dom_Text_h
9
10 #include "mozilla/dom/CharacterData.h"
11
12 namespace mozilla {
13 class ErrorResult;
14
15 namespace dom {
16
17 class Text : public CharacterData {
18 public:
NS_IMPL_FROMNODE_HELPER(Text,IsText ())19 NS_IMPL_FROMNODE_HELPER(Text, IsText())
20
21 explicit Text(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
22 : CharacterData(std::move(aNodeInfo)) {}
23
24 // WebIDL API
25 already_AddRefed<Text> SplitText(uint32_t aOffset, ErrorResult& rv);
26 void GetWholeText(nsAString& aWholeText, ErrorResult& rv);
27
28 static already_AddRefed<Text> Constructor(const GlobalObject& aGlobal,
29 const nsAString& aData,
30 ErrorResult& aRv);
31
32 /**
33 * Method to see if the text node contains data that is useful
34 * for a translation: i.e., it consists of more than just whitespace,
35 * digits and punctuation.
36 */
37 bool HasTextForTranslation();
38 };
39
40 } // namespace dom
41 } // namespace mozilla
42
GetAsText()43 inline mozilla::dom::Text* nsINode::GetAsText() {
44 return IsText() ? AsText() : nullptr;
45 }
46
GetAsText()47 inline const mozilla::dom::Text* nsINode::GetAsText() const {
48 return IsText() ? AsText() : nullptr;
49 }
50
AsText()51 inline mozilla::dom::Text* nsINode::AsText() {
52 MOZ_ASSERT(IsText());
53 return static_cast<mozilla::dom::Text*>(this);
54 }
55
AsText()56 inline const mozilla::dom::Text* nsINode::AsText() const {
57 MOZ_ASSERT(IsText());
58 return static_cast<const mozilla::dom::Text*>(this);
59 }
60
61 #endif // mozilla_dom_Text_h
62