Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame^] | 1 | // Copyright 2015 The Chromium Authors |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_ |
| 6 | #define CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_ |
| 7 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 10 | #include <wrl.h> |
| 11 | |
Henrique Ferreiro | 5388077c | 2019-09-09 13:14:36 | [diff] [blame] | 12 | #include <string> |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 16 | #include "base/files/file_path.h" |
Henrique Ferreiro | 5388077c | 2019-09-09 13:14:36 | [diff] [blame] | 17 | #include "mojo/public/cpp/bindings/pending_remote.h" |
| 18 | #include "mojo/public/cpp/bindings/receiver_set.h" |
Dominik Röttsches | 24f9d16 | 2019-01-04 10:43:56 | [diff] [blame] | 19 | #include "third_party/blink/public/mojom/dwrite_font_proxy/dwrite_font_proxy.mojom.h" |
kulshin | 267bf5e | 2016-04-19 18:57:16 | [diff] [blame] | 20 | |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 21 | namespace content { |
| 22 | |
| 23 | class FakeFontCollection; |
| 24 | |
| 25 | // Creates a new FakeFontCollection, seeded with some basic data, and returns a |
| 26 | // Sender that can be used to interact with the collection. |
Henrique Ferreiro | 5388077c | 2019-09-09 13:14:36 | [diff] [blame] | 27 | base::RepeatingCallback< |
| 28 | mojo::PendingRemote<blink::mojom::DWriteFontProxy>(void)> |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 29 | CreateFakeCollectionSender(); |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 30 | |
| 31 | // Helper class for describing a font object. Use FakeFontCollection instead. |
| 32 | class FakeFont { |
| 33 | public: |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 34 | explicit FakeFont(const std::u16string& name); |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 35 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 36 | FakeFont& operator=(const FakeFont&) = delete; |
| 37 | |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 38 | FakeFont(FakeFont&& other); |
vmpstr | bcdec0d | 2016-04-14 01:24:52 | [diff] [blame] | 39 | |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 40 | ~FakeFont(); |
| 41 | |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 42 | FakeFont& AddFilePath(const base::FilePath& file_path) { |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 43 | file_paths_.push_back(file_path); |
| 44 | return *this; |
| 45 | } |
| 46 | |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 47 | FakeFont& AddFileHandle(base::File handle) { |
| 48 | file_handles_.push_back(std::move(handle)); |
kulshin | 96ce8347f | 2016-07-26 00:46:01 | [diff] [blame] | 49 | return *this; |
| 50 | } |
| 51 | |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 52 | FakeFont& AddFamilyName(const std::u16string& locale, |
| 53 | const std::u16string& family_name) { |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 54 | family_names_.emplace_back(locale, family_name); |
| 55 | return *this; |
| 56 | } |
| 57 | |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 58 | const std::u16string& font_name() { return font_name_; } |
kulshin | 267bf5e | 2016-04-19 18:57:16 | [diff] [blame] | 59 | |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 60 | private: |
| 61 | friend FakeFontCollection; |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 62 | std::u16string font_name_; |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 63 | std::vector<base::FilePath> file_paths_; |
| 64 | std::vector<base::File> file_handles_; |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 65 | std::vector<std::pair<std::u16string, std::u16string>> family_names_; |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | // Implements a font collection that supports interaction through sending IPC |
| 69 | // messages from dwrite_font_proxy_messages.h. |
| 70 | // Usage: |
| 71 | // Create a new FakeFontCollection. |
| 72 | // Call AddFont() to add fonts. |
| 73 | // For each font, call methods on the font to configure the font. |
| 74 | // Note: the indices of the fonts will correspond to the order they were |
| 75 | // added. The collection will not sort or reorder fonts in any way. |
| 76 | // Call GetSender()/GetTrackingSender() to obtain an IPC::Sender. |
| 77 | // Call Send() with DWriteFontProxyMsg_* to interact with the collection. |
Daniel Bratell | 9b55042 | 2017-12-11 16:30:50 | [diff] [blame] | 78 | // Call MessageCount()/GetIpcMessage() to inspect sent messages. |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 79 | // |
| 80 | // The internal code flow for GetSender()/Send() is as follows: |
| 81 | // GetSender() returns a new FakeSender, pointing back to the collection. |
| 82 | // FakeSender::Send() will create a new ReplySender and call |
| 83 | // ReplySender::OnMessageReceived() |
| 84 | // ReplySender::OnMessageReceived() contains the message map, which will |
| 85 | // internally call ReplySender::On*() and ReplySender::Send() |
| 86 | // ReplySender::Send() will save the reply message, to be used later. |
| 87 | // FakeSender::Send() will retrieve the reply message and save the output. |
Dominik Röttsches | 24f9d16 | 2019-01-04 10:43:56 | [diff] [blame] | 88 | class FakeFontCollection : public blink::mojom::DWriteFontProxy { |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 89 | public: |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 90 | enum class MessageType { |
| 91 | kFindFamily, |
| 92 | kGetFamilyCount, |
| 93 | kGetFamilyNames, |
| 94 | kGetFontFiles, |
| 95 | kMapCharacters |
| 96 | }; |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 97 | FakeFontCollection(); |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 98 | |
| 99 | FakeFontCollection(const FakeFontCollection&) = delete; |
| 100 | FakeFontCollection& operator=(const FakeFontCollection&) = delete; |
| 101 | |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 102 | ~FakeFontCollection() override; |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 103 | |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 104 | FakeFont& AddFont(const std::u16string& font_name); |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 105 | |
| 106 | size_t MessageCount(); |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 107 | MessageType GetMessageType(size_t id); |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 108 | |
Henrique Ferreiro | 5388077c | 2019-09-09 13:14:36 | [diff] [blame] | 109 | mojo::PendingRemote<blink::mojom::DWriteFontProxy> CreateRemote(); |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 110 | |
| 111 | protected: |
Dominik Röttsches | 24f9d16 | 2019-01-04 10:43:56 | [diff] [blame] | 112 | // blink::mojom::DWriteFontProxy: |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 113 | void FindFamily(const std::u16string& family_name, |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 114 | FindFamilyCallback callback) override; |
| 115 | void GetFamilyCount(GetFamilyCountCallback callback) override; |
| 116 | void GetFamilyNames(uint32_t family_index, |
| 117 | GetFamilyNamesCallback callback) override; |
| 118 | void GetFontFiles(uint32_t family_index, |
| 119 | GetFontFilesCallback callback) override; |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 120 | void MapCharacters(const std::u16string& text, |
Dominik Röttsches | 24f9d16 | 2019-01-04 10:43:56 | [diff] [blame] | 121 | blink::mojom::DWriteFontStylePtr font_style, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 122 | const std::u16string& locale_name, |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 123 | uint32_t reading_direction, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 124 | const std::u16string& base_family_name, |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 125 | MapCharactersCallback callback) override; |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 126 | void MatchUniqueFont(const std::u16string& unique_font_name, |
Dominik Röttsches | 1163828 | 2019-04-12 22:19:03 | [diff] [blame] | 127 | MatchUniqueFontCallback callback) override; |
| 128 | void GetUniqueFontLookupMode( |
| 129 | GetUniqueFontLookupModeCallback callback) override; |
Dominik Röttsches | 1c59996a | 2019-04-03 14:17:09 | [diff] [blame] | 130 | void GetUniqueNameLookupTableIfAvailable( |
| 131 | GetUniqueNameLookupTableIfAvailableCallback callback) override; |
Dominik Röttsches | b0c64465 | 2019-01-09 15:18:37 | [diff] [blame] | 132 | void GetUniqueNameLookupTable( |
| 133 | GetUniqueNameLookupTableCallback callback) override; |
Dominik Röttsches | af596df | 2019-10-01 08:06:07 | [diff] [blame] | 134 | void FallbackFamilyAndStyleForCodepoint( |
Dominik Röttsches | 6323eeff | 2019-07-18 14:12:04 | [diff] [blame] | 135 | const std::string& base_family_name, |
| 136 | const std::string& locale_name, |
| 137 | uint32_t codepoint, |
Dominik Röttsches | af596df | 2019-10-01 08:06:07 | [diff] [blame] | 138 | FallbackFamilyAndStyleForCodepointCallback callback) override; |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 139 | |
| 140 | private: |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 141 | std::vector<FakeFont> fonts_; |
Sam McNally | ae42d32 | 2018-01-09 00:47:55 | [diff] [blame] | 142 | |
| 143 | std::vector<MessageType> message_types_; |
| 144 | |
Henrique Ferreiro | 5388077c | 2019-09-09 13:14:36 | [diff] [blame] | 145 | mojo::ReceiverSet<blink::mojom::DWriteFontProxy> receivers_; |
kulshin | 4039fd5b | 2015-12-14 23:12:54 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace content |
| 149 | |
| 150 | #endif // CONTENT_TEST_DWRITE_FONT_FAKE_SENDER_WIN_H_ |