/src/mozilla-central/gfx/layers/apz/testutil/APZTestData.cpp
Line | Count | Source (jump to first uncovered line) |
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 "APZTestData.h" |
8 | | #include "mozilla/dom/APZTestDataBinding.h" |
9 | | #include "mozilla/dom/ToJSValue.h" |
10 | | #include "nsString.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace layers { |
14 | | |
15 | | struct APZTestDataToJSConverter { |
16 | | template <typename Key, typename Value, typename KeyValuePair> |
17 | | static void ConvertMap(const std::map<Key, Value>& aFrom, |
18 | | dom::Sequence<KeyValuePair>& aOutTo, |
19 | 0 | void (*aElementConverter)(const Key&, const Value&, KeyValuePair&)) { |
20 | 0 | for (auto it = aFrom.begin(); it != aFrom.end(); ++it) { |
21 | 0 | aOutTo.AppendElement(fallible); |
22 | 0 | aElementConverter(it->first, it->second, aOutTo.LastElement()); |
23 | 0 | } |
24 | 0 | } Unexecuted instantiation: void mozilla::layers::APZTestDataToJSConverter::ConvertMap<unsigned int, mozilla::layers::APZTestData::Bucket, mozilla::dom::APZBucket>(std::__1::map<unsigned int, mozilla::layers::APZTestData::Bucket, std::__1::less<unsigned int>, std::__1::allocator<std::__1::pair<unsigned int const, mozilla::layers::APZTestData::Bucket> > > const&, mozilla::dom::Sequence<mozilla::dom::APZBucket>&, void (*)(unsigned int const&, mozilla::layers::APZTestData::Bucket const&, mozilla::dom::APZBucket&)) Unexecuted instantiation: void mozilla::layers::APZTestDataToJSConverter::ConvertMap<unsigned long, mozilla::layers::APZTestData::ScrollFrameData, mozilla::dom::ScrollFrameData>(std::__1::map<unsigned long, mozilla::layers::APZTestData::ScrollFrameData, std::__1::less<unsigned long>, std::__1::allocator<std::__1::pair<unsigned long const, mozilla::layers::APZTestData::ScrollFrameData> > > const&, mozilla::dom::Sequence<mozilla::dom::ScrollFrameData>&, void (*)(unsigned long const&, mozilla::layers::APZTestData::ScrollFrameData const&, mozilla::dom::ScrollFrameData&)) Unexecuted instantiation: void mozilla::layers::APZTestDataToJSConverter::ConvertMap<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, mozilla::dom::ScrollFrameDataEntry>(std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > const&, mozilla::dom::Sequence<mozilla::dom::ScrollFrameDataEntry>&, void (*)(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, mozilla::dom::ScrollFrameDataEntry&)) |
25 | | |
26 | | template <typename Src, typename Target> |
27 | | static void ConvertList(const nsTArray<Src>& aFrom, |
28 | | dom::Sequence<Target>& aOutTo, |
29 | 0 | void (*aElementConverter)(const Src&, Target&)) { |
30 | 0 | for (auto it = aFrom.begin(); it != aFrom.end(); ++it) { |
31 | 0 | aOutTo.AppendElement(fallible); |
32 | 0 | aElementConverter(*it, aOutTo.LastElement()); |
33 | 0 | } |
34 | 0 | } |
35 | | |
36 | | static void ConvertAPZTestData(const APZTestData& aFrom, |
37 | 0 | dom::APZTestData& aOutTo) { |
38 | 0 | ConvertMap(aFrom.mPaints, aOutTo.mPaints.Construct(), ConvertBucket); |
39 | 0 | ConvertMap(aFrom.mRepaintRequests, aOutTo.mRepaintRequests.Construct(), ConvertBucket); |
40 | 0 | ConvertList(aFrom.mHitResults, aOutTo.mHitResults.Construct(), ConvertHitResult); |
41 | 0 | } |
42 | | |
43 | | static void ConvertBucket(const SequenceNumber& aKey, |
44 | | const APZTestData::Bucket& aValue, |
45 | 0 | dom::APZBucket& aOutKeyValuePair) { |
46 | 0 | aOutKeyValuePair.mSequenceNumber.Construct() = aKey; |
47 | 0 | ConvertMap(aValue, aOutKeyValuePair.mScrollFrames.Construct(), ConvertScrollFrameData); |
48 | 0 | } |
49 | | |
50 | | static void ConvertScrollFrameData(const APZTestData::ViewID& aKey, |
51 | | const APZTestData::ScrollFrameData& aValue, |
52 | 0 | dom::ScrollFrameData& aOutKeyValuePair) { |
53 | 0 | aOutKeyValuePair.mScrollId.Construct() = aKey; |
54 | 0 | ConvertMap(aValue, aOutKeyValuePair.mEntries.Construct(), ConvertEntry); |
55 | 0 | } |
56 | | |
57 | | static void ConvertEntry(const std::string& aKey, |
58 | | const std::string& aValue, |
59 | 0 | dom::ScrollFrameDataEntry& aOutKeyValuePair) { |
60 | 0 | ConvertString(aKey, aOutKeyValuePair.mKey.Construct()); |
61 | 0 | ConvertString(aValue, aOutKeyValuePair.mValue.Construct()); |
62 | 0 | } |
63 | | |
64 | 0 | static void ConvertString(const std::string& aFrom, nsString& aOutTo) { |
65 | 0 | aOutTo = NS_ConvertUTF8toUTF16(aFrom.c_str(), aFrom.size()); |
66 | 0 | } |
67 | | |
68 | | static void ConvertHitResult(const APZTestData::HitResult& aResult, |
69 | 0 | dom::APZHitResult& aOutHitResult) { |
70 | 0 | aOutHitResult.mScreenX.Construct() = aResult.point.x; |
71 | 0 | aOutHitResult.mScreenY.Construct() = aResult.point.y; |
72 | 0 | static_assert(sizeof(aResult.result) == sizeof(uint16_t), |
73 | 0 | "Expected CompositorHitTestInfo to be 16-bit"); |
74 | 0 | aOutHitResult.mHitResult.Construct() = static_cast<uint16_t>(aResult.result); |
75 | 0 | aOutHitResult.mScrollId.Construct() = aResult.scrollId; |
76 | 0 | } |
77 | | }; |
78 | | |
79 | | bool |
80 | | APZTestData::ToJS(JS::MutableHandleValue aOutValue, JSContext* aContext) const |
81 | 0 | { |
82 | 0 | dom::APZTestData result; |
83 | 0 | APZTestDataToJSConverter::ConvertAPZTestData(*this, result); |
84 | 0 | return dom::ToJSValue(aContext, result, aOutValue); |
85 | 0 | } |
86 | | |
87 | | } // namespace layers |
88 | | } // namespace mozilla |