spellcheck_mojom_traits.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/spellcheck/common/spellcheck_mojom_traits.h"
  5. #include "mojo/public/cpp/base/string16_mojom_traits.h"
  6. namespace mojo {
  7. spellcheck::mojom::Decoration
  8. EnumTraits<spellcheck::mojom::Decoration, SpellCheckResult::Decoration>::
  9. ToMojom(SpellCheckResult::Decoration decoration) {
  10. switch (decoration) {
  11. case SpellCheckResult::SPELLING:
  12. return spellcheck::mojom::Decoration::kSpelling;
  13. case SpellCheckResult::GRAMMAR:
  14. return spellcheck::mojom::Decoration::kGrammar;
  15. }
  16. NOTREACHED();
  17. return spellcheck::mojom::Decoration::kSpelling;
  18. }
  19. bool EnumTraits<spellcheck::mojom::Decoration, SpellCheckResult::Decoration>::
  20. FromMojom(spellcheck::mojom::Decoration input,
  21. SpellCheckResult::Decoration* output) {
  22. switch (input) {
  23. case spellcheck::mojom::Decoration::kSpelling:
  24. *output = SpellCheckResult::SPELLING;
  25. return true;
  26. case spellcheck::mojom::Decoration::kGrammar:
  27. *output = SpellCheckResult::GRAMMAR;
  28. return true;
  29. }
  30. NOTREACHED();
  31. return false;
  32. }
  33. bool StructTraits<
  34. spellcheck::mojom::SpellCheckResultDataView,
  35. SpellCheckResult>::Read(spellcheck::mojom::SpellCheckResultDataView input,
  36. SpellCheckResult* output) {
  37. if (!input.ReadDecoration(&output->decoration))
  38. return false;
  39. output->location = input.location();
  40. output->length = input.length();
  41. if (!input.ReadReplacements(&output->replacements))
  42. return false;
  43. return true;
  44. }
  45. } // namespace mojo