Index: third_party/libaddressinput/chromium/suggestions.h |
diff --git a/third_party/libaddressinput/chromium/suggestions.h b/third_party/libaddressinput/chromium/suggestions.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..711bb63cb184ef057c9fdb79559dde47dea0e2e8 |
--- /dev/null |
+++ b/third_party/libaddressinput/chromium/suggestions.h |
@@ -0,0 +1,104 @@ |
+// Copyright 2014 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. |
+ |
+#ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |
+#define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "third_party/libaddressinput/chromium/trie.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h" |
+ |
+namespace i18n { |
+namespace addressinput { |
+class PreloadSupplier; |
+class RegionData; |
+struct AddressData; |
+} // namespace addressinput |
+} // namespace i18n |
+ |
+namespace autofill { |
+ |
+using ::i18n::addressinput::AddressData; |
+using ::i18n::addressinput::AddressField; |
+using ::i18n::addressinput::PreloadSupplier; |
+using ::i18n::addressinput::RegionData; |
+ |
+class Suggestions { |
+ public: |
+ // Does not take ownership of |supplier|. |
+ explicit Suggestions(const PreloadSupplier* supplier); |
+ ~Suggestions(); |
+ |
+ // Fills in |suggestions| for the partially typed in |user_input|, assuming |
+ // the user is typing in the |focused_field|. If the number of |suggestions| |
+ // is over the |suggestion_limit|, then returns no |suggestions| at all. |
+ // |
+ // Sample user input 1: |
+ // country code = "US" |
+ // postal code = "90066" |
+ // focused field = POSTAL_CODE |
+ // suggestions limit = 1 |
+ // Suggestion: |
+ // [{administrative_area: "CA"}] |
+ // |
+ // Sample user input 2: |
+ // country code = "CN" |
+ // dependent locality = "Zongyang" |
+ // focused field = DEPENDENT_LOCALITY |
+ // suggestions limit = 10 |
+ // Suggestion: |
+ // [{dependent_locality: "Zongyang Xian", |
+ // locality: "Anqing Shi", |
+ // administrative_area: "Anhui Sheng"}] |
+ // |
+ // If the index is not built, then builds it. |
+ // The |suggestions| parameter should not be NULL. |
+ void GetSuggestions(const AddressData& user_input, |
+ AddressField focused_field, |
+ size_t suggestion_limit, |
+ std::vector<AddressData>* suggestions); |
+ |
+ private: |
+ class CanonicalizerImpl; |
+ |
+ // The types of fields that describe a region. |
+ enum RegionIdentityField { |
+ KEY, |
+ NAME, |
+ REGION_IDENTITY_FIELDS_SIZE |
+ }; |
+ |
+ void FindRegionsByPrefix(const std::string& region_code, |
+ const std::string& language_tag, |
+ AddressField address_field, |
+ RegionIdentityField region_identity_field, |
+ const std::string& canonicalized_prefix, |
+ std::set<const RegionData*>* result) const; |
+ |
+ // The tries to lookup regions by a prefix of key or name of the region. Owns |
+ // the map and trie objects. Does not own the region objects. |
+ typedef std::map<RegionIdentityField, Trie<const RegionData*>*> RegionIdMap; |
+ typedef std::map<AddressField, RegionIdMap*> AddressFieldMap; |
+ typedef std::map<std::string, AddressFieldMap*> LanguageTagMap; |
+ typedef std::map<std::string, LanguageTagMap*> RegionCodeMap; |
+ RegionCodeMap tries_; |
+ |
+ // Not owned supplier of reigon data. |
+ const PreloadSupplier* const supplier_; |
+ |
+ // Canonicalizes keys and names to enable case and diacritic insensitive |
+ // search. |
+ scoped_ptr<CanonicalizerImpl> canonicalizer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Suggestions); |
+}; |
+ |
+} // namespace autofill |
+ |
+#endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_ |