Backed out 3 changesets (bug 1854025) for causing build bustages.
[gecko.git] / widget / ContentData.h
blob3e641a2684555819a1c98ee02dd88c9765a756c5
1 /* -*- Mode: C++; tab-width: 40; 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/. */
6 #ifndef mozilla_ContentData_h
7 #define mozilla_ContentData_h
9 #include <sstream>
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Debug.h"
13 #include "mozilla/EventForwards.h"
14 #include "mozilla/Maybe.h"
15 #include "mozilla/WritingModes.h"
16 #include "mozilla/widget/IMEData.h"
18 /**
19 * This file is intended for declaring classes which store DOM content data for
20 * widget classes. Those data should be retrived by `WidgetQueryContentEvent`,
21 * notified with `IMENotification`, or set assumed data as result of dispatching
22 * widget events such as `WidgetKeyboardEvent`, `WidgetCompositionEvent`,
23 * `WidgetSelectionEvent` etc.
26 namespace mozilla {
28 /**
29 * ContentSelection stores DOM selection in flattend text by
30 * ContentEventHandler. It should be retrieved with `eQuerySelectedText` event,
31 * notified with `NOTIFY_IME_OF_SELECTION_CHANGE` or set by widget itself.
33 class ContentSelection {
34 public:
35 using SelectionChangeDataBase =
36 widget::IMENotification::SelectionChangeDataBase;
37 ContentSelection() = default;
38 explicit ContentSelection(const SelectionChangeDataBase& aSelectionChangeData)
39 : mOffsetAndData(Some(aSelectionChangeData.ToUint32OffsetAndData())),
40 mWritingMode(aSelectionChangeData.GetWritingMode()) {}
41 explicit ContentSelection(const WidgetQueryContentEvent& aSelectedTextEvent);
42 ContentSelection(uint32_t aOffset, const WritingMode& aWritingMode)
43 : mOffsetAndData(Some(OffsetAndData<uint32_t>(
44 aOffset, EmptyString(), OffsetAndDataFor::SelectedString))),
45 mWritingMode(aWritingMode) {}
47 const OffsetAndData<uint32_t>& OffsetAndDataRef() const {
48 return mOffsetAndData.ref();
51 void Collapse(uint32_t aOffset) {
52 if (mOffsetAndData.isSome()) {
53 mOffsetAndData->Collapse(aOffset);
54 } else {
55 mOffsetAndData.emplace(aOffset, EmptyString(),
56 OffsetAndDataFor::SelectedString);
59 void Clear() {
60 mOffsetAndData.reset();
61 mWritingMode = WritingMode();
64 bool HasRange() const { return mOffsetAndData.isSome(); }
65 const WritingMode& WritingModeRef() const { return mWritingMode; }
67 friend std::ostream& operator<<(std::ostream& aStream,
68 const ContentSelection& aContentSelection) {
69 if (aContentSelection.HasRange()) {
70 return aStream << "{ HasRange()=false }";
72 aStream << "{ mOffsetAndData=" << aContentSelection.mOffsetAndData
73 << ", mWritingMode=" << aContentSelection.mWritingMode << " }";
74 return aStream;
77 private:
78 Maybe<OffsetAndData<uint32_t>> mOffsetAndData;
79 WritingMode mWritingMode;
82 } // namespace mozilla
84 #endif // #ifndef mozilla_ContentData_h