summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/font_access/font_table_map.cc
blob: 8fad2f5931ee1e0ccd55ac538379e1255825c1b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/font_access/font_table_map.h"

#include "third_party/blink/renderer/platform/bindings/script_state.h"

namespace blink {

void FontTableMap::Trace(Visitor* visitor) const {
  visitor->Trace(table_map_);
  ScriptWrappable::Trace(visitor);
}

class FontTableMapIterationSource final
    : public PairIterable<String, Member<Blob>>::IterationSource {
 public:
  explicit FontTableMapIterationSource(const FontTableMap::MapType& map) {
    for (const auto& table_name : map.Keys()) {
      table_names_.push_back(table_name);
      table_data_.push_back(map.at(table_name));
    }
  }

  bool Next(ScriptState* script_state,
            String& map_key,
            Member<Blob>& map_value,
            ExceptionState&) override {
    if (current_index_ == table_names_.size())
      return false;

    map_key = table_names_[current_index_];
    map_value = table_data_[current_index_];

    ++current_index_;
    return true;
  }

  void Trace(Visitor* visitor) const override {
    visitor->Trace(table_data_);
    PairIterable<String, Member<Blob>>::IterationSource::Trace(visitor);
  }

 private:
  Vector<String> table_names_;
  HeapVector<Member<Blob>> table_data_;
  unsigned current_index_;
};

PairIterable<String, Member<Blob>>::IterationSource*
FontTableMap::StartIteration(ScriptState*, ExceptionState&) {
  return MakeGarbageCollected<FontTableMapIterationSource>(table_map_);
}

bool FontTableMap::GetMapEntry(ScriptState*,
                               const String& key,
                               Member<Blob>& value,
                               ExceptionState&) {
  if (table_map_.Contains(key)) {
    value = table_map_.at(key);
    return true;
  }

  return false;
}

}  // namespace blink