OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 |
| 5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |
| 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "third_party/libaddressinput/chromium/trie.h" |
| 15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" |
| 16 |
| 17 namespace i18n { |
| 18 namespace addressinput { |
| 19 class PreloadSupplier; |
| 20 class RegionData; |
| 21 struct AddressData; |
| 22 } // namespace addressinput |
| 23 } // namespace i18n |
| 24 |
| 25 namespace autofill { |
| 26 |
| 27 using ::i18n::addressinput::AddressData; |
| 28 using ::i18n::addressinput::AddressField; |
| 29 using ::i18n::addressinput::PreloadSupplier; |
| 30 using ::i18n::addressinput::RegionData; |
| 31 |
| 32 class Suggestions { |
| 33 public: |
| 34 // Does not take ownership of |supplier|. |
| 35 explicit Suggestions(const PreloadSupplier* supplier); |
| 36 ~Suggestions(); |
| 37 |
| 38 // Fills in |suggestions| for the partially typed in |user_input|, assuming |
| 39 // the user is typing in the |focused_field|. If the number of |suggestions| |
| 40 // is over the |suggestion_limit|, then returns no |suggestions| at all. |
| 41 // |
| 42 // Sample user input 1: |
| 43 // country code = "US" |
| 44 // postal code = "90066" |
| 45 // focused field = POSTAL_CODE |
| 46 // suggestions limit = 1 |
| 47 // Suggestion: |
| 48 // [{administrative_area: "CA"}] |
| 49 // |
| 50 // Sample user input 2: |
| 51 // country code = "CN" |
| 52 // dependent locality = "Zongyang" |
| 53 // focused field = DEPENDENT_LOCALITY |
| 54 // suggestions limit = 10 |
| 55 // Suggestion: |
| 56 // [{dependent_locality: "Zongyang Xian", |
| 57 // locality: "Anqing Shi", |
| 58 // administrative_area: "Anhui Sheng"}] |
| 59 // |
| 60 // If the index is not built, then builds it. |
| 61 // The |suggestions| parameter should not be NULL. |
| 62 void GetSuggestions(const AddressData& user_input, |
| 63 AddressField focused_field, |
| 64 size_t suggestion_limit, |
| 65 std::vector<AddressData>* suggestions); |
| 66 |
| 67 private: |
| 68 class CanonicalizerImpl; |
| 69 |
| 70 // The types of fields that describe a region. |
| 71 enum RegionIdentityField { |
| 72 KEY, |
| 73 NAME, |
| 74 REGION_IDENTITY_FIELDS_SIZE |
| 75 }; |
| 76 |
| 77 void FindRegionsByPrefix(const std::string& region_code, |
| 78 const std::string& language_tag, |
| 79 AddressField address_field, |
| 80 RegionIdentityField region_identity_field, |
| 81 const std::string& canonicalized_prefix, |
| 82 std::set<const RegionData*>* result) const; |
| 83 |
| 84 // The tries to lookup regions by a prefix of key or name of the region. Owns |
| 85 // the map and trie objects. Does not own the region objects. |
| 86 typedef std::map<RegionIdentityField, Trie<const RegionData*>*> RegionIdMap; |
| 87 typedef std::map<AddressField, RegionIdMap*> AddressFieldMap; |
| 88 typedef std::map<std::string, AddressFieldMap*> LanguageTagMap; |
| 89 typedef std::map<std::string, LanguageTagMap*> RegionCodeMap; |
| 90 RegionCodeMap tries_; |
| 91 |
| 92 // Not owned supplier of reigon data. |
| 93 const PreloadSupplier* const supplier_; |
| 94 |
| 95 // Canonicalizes keys and names to enable case and diacritic insensitive |
| 96 // search. |
| 97 scoped_ptr<CanonicalizerImpl> canonicalizer_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(Suggestions); |
| 100 }; |
| 101 |
| 102 } // namespace autofill |
| 103 |
| 104 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |
OLD | NEW |