Chromium Code Reviews| 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..74248dc4d2cf8468808ee5d4dfb071012003fac5 |
| --- /dev/null |
| +++ b/third_party/libaddressinput/chromium/suggestions.h |
| @@ -0,0 +1,105 @@ |
| +// 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" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/region_data_builder.h" |
| + |
| +namespace i18n { |
| +namespace addressinput { |
| +class PreloadSupplier; |
| +class RegionData; |
| +struct AddressData; |
| +} // namespace addressinput |
| +} // namespace i18n |
| + |
| +namespace autofill { |
| + |
| +class Suggestions { |
| + public: |
| + // Does not take ownership of |supplier|, which should not be NULL. |
| + explicit Suggestions(::i18n::addressinput::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. |
|
please use gerrit instead
2014/06/05 22:22:49
Reduce reviewer burden: Remove extra newline.
please use gerrit instead
2014/06/09 23:28:17
Done.
|
| + // The |suggestions| parameter should not be NULL. |
| + void GetSuggestions( |
| + const ::i18n::addressinput::AddressData& user_input, |
| + ::i18n::addressinput::AddressField focused_field, |
| + size_t suggestion_limit, |
| + std::vector< ::i18n::addressinput::AddressData>* suggestions); |
| + |
| + private: |
| + class CanonicalizerImpl; |
| + |
| + // The types of fields that describe a region. |
| + enum RegionIdentityField { |
| + KEY, |
| + NAME, |
| + REGION_IDENTITY_FIELDS_SIZE |
| + }; |
| + |
| + // Recursively adds and initializes the Trie objects for the sub-regions of |
| + // |parent|, placing them all into |field_map|. |
| + typedef Trie<const ::i18n::addressinput::RegionData*> RegionDataTrie; |
| + typedef std::map<RegionIdentityField, RegionDataTrie*> IdMap; |
| + typedef std::map< ::i18n::addressinput::AddressField, IdMap*> FieldMap; |
| + void AddTriesForSubRegionsOf(const ::i18n::addressinput::RegionData& parent, |
| + ::i18n::addressinput::AddressField parent_field, |
| + FieldMap* field_map); |
| + |
| + // Returns the tries for |user_input|. Builds the tries if necessary. |
| + const FieldMap& GetTries(const ::i18n::addressinput::AddressData& user_input); |
| + |
| + // A mapping of the country-level RegionData objects to a collection of Trie |
| + // objects. All of the map and Trie objects are owned, but the RegionData |
| + // objects are not owned. |
| + typedef std::map<const ::i18n::addressinput::RegionData*, FieldMap*> |
| + RegionMap; |
| + RegionMap tries_; |
| + |
| + // The data source for the region names. |
| + ::i18n::addressinput::RegionDataBuilder region_data_builder_; |
| + |
| + // 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_ |