Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: third_party/libaddressinput/chromium/suggestions.h

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/region_dat a_builder.h"
17
18 namespace i18n {
19 namespace addressinput {
20 class PreloadSupplier;
21 class RegionData;
22 struct AddressData;
23 } // namespace addressinput
24 } // namespace i18n
25
26 namespace autofill {
27
28 class Suggestions {
29 public:
30 // Does not take ownership of |supplier|, which should not be NULL.
31 explicit Suggestions(::i18n::addressinput::PreloadSupplier* supplier);
32 ~Suggestions();
33
34 // Fills in |suggestions| for the partially typed in |user_input|, assuming
35 // the user is typing in the |focused_field|. If the number of |suggestions|
36 // is over the |suggestion_limit|, then returns no |suggestions| at all.
37 //
38 // Sample user input 1:
39 // country code = "US"
40 // postal code = "90066"
41 // focused field = POSTAL_CODE
42 // suggestions limit = 1
43 // Suggestion:
44 // [{administrative_area: "CA"}]
45 //
46 // Sample user input 2:
47 // country code = "CN"
48 // dependent locality = "Zongyang"
49 // focused field = DEPENDENT_LOCALITY
50 // suggestions limit = 10
51 // Suggestion:
52 // [{dependent_locality: "Zongyang Xian",
53 // locality: "Anqing Shi",
54 // administrative_area: "Anhui Sheng"}]
55 //
56 // 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.
57 // The |suggestions| parameter should not be NULL.
58 void GetSuggestions(
59 const ::i18n::addressinput::AddressData& user_input,
60 ::i18n::addressinput::AddressField focused_field,
61 size_t suggestion_limit,
62 std::vector< ::i18n::addressinput::AddressData>* suggestions);
63
64 private:
65 class CanonicalizerImpl;
66
67 // The types of fields that describe a region.
68 enum RegionIdentityField {
69 KEY,
70 NAME,
71 REGION_IDENTITY_FIELDS_SIZE
72 };
73
74 // Recursively adds and initializes the Trie objects for the sub-regions of
75 // |parent|, placing them all into |field_map|.
76 typedef Trie<const ::i18n::addressinput::RegionData*> RegionDataTrie;
77 typedef std::map<RegionIdentityField, RegionDataTrie*> IdMap;
78 typedef std::map< ::i18n::addressinput::AddressField, IdMap*> FieldMap;
79 void AddTriesForSubRegionsOf(const ::i18n::addressinput::RegionData& parent,
80 ::i18n::addressinput::AddressField parent_field,
81 FieldMap* field_map);
82
83 // Returns the tries for |user_input|. Builds the tries if necessary.
84 const FieldMap& GetTries(const ::i18n::addressinput::AddressData& user_input);
85
86 // A mapping of the country-level RegionData objects to a collection of Trie
87 // objects. All of the map and Trie objects are owned, but the RegionData
88 // objects are not owned.
89 typedef std::map<const ::i18n::addressinput::RegionData*, FieldMap*>
90 RegionMap;
91 RegionMap tries_;
92
93 // The data source for the region names.
94 ::i18n::addressinput::RegionDataBuilder region_data_builder_;
95
96 // Canonicalizes keys and names to enable case and diacritic insensitive
97 // search.
98 scoped_ptr<CanonicalizerImpl> canonicalizer_;
99
100 DISALLOW_COPY_AND_ASSIGN(Suggestions);
101 };
102
103 } // namespace autofill
104
105 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_SUGGESTIONS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698