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