OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 5 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 | 313 |
314 // This function converts style information populated by the JSON schema | 314 // This function converts style information populated by the JSON schema |
315 // compiler into an ACMatchClassifications object. | 315 // compiler into an ACMatchClassifications object. |
316 ACMatchClassifications StyleTypesToACMatchClassifications( | 316 ACMatchClassifications StyleTypesToACMatchClassifications( |
317 const omnibox::SuggestResult &suggestion) { | 317 const omnibox::SuggestResult &suggestion) { |
318 ACMatchClassifications match_classifications; | 318 ACMatchClassifications match_classifications; |
319 if (suggestion.description_styles) { | 319 if (suggestion.description_styles) { |
320 base::string16 description = base::UTF8ToUTF16(suggestion.description); | 320 base::string16 description = base::UTF8ToUTF16(suggestion.description); |
321 std::vector<int> styles(description.length(), 0); | 321 std::vector<int> styles(description.length(), 0); |
322 | 322 |
323 for (std::vector<linked_ptr<omnibox::SuggestResult::DescriptionStylesType> > | 323 for (const omnibox::SuggestResult::DescriptionStylesType& style : |
324 ::iterator i = suggestion.description_styles->begin(); | 324 *suggestion.description_styles) { |
325 i != suggestion.description_styles->end(); ++i) { | 325 int length = description.length(); |
326 omnibox::SuggestResult::DescriptionStylesType* style = i->get(); | 326 if (style.length) |
327 length = *style.length; | |
stevenjb
2016/03/29 00:52:37
nit: int length = style.length ? :
Devlin
2016/03/29 20:20:35
Done.
| |
327 | 328 |
328 int length = description.length(); | 329 size_t offset = style.offset >= 0 |
329 if (style->length) | 330 ? style.offset |
330 length = *style->length; | 331 : std::max(0, static_cast<int>(description.length()) + |
stevenjb
2016/03/29 00:52:37
optional nit: clean this up too (casting seems bac
Devlin
2016/03/29 20:20:35
Wrong how?
stevenjb
2016/03/29 20:31:45
Oh, I guess we have to cast to an int to do the si
| |
331 | 332 style.offset); |
332 size_t offset = style->offset >= 0 ? style->offset : | |
333 std::max(0, static_cast<int>(description.length()) + style->offset); | |
334 | 333 |
335 int type_class; | 334 int type_class; |
336 switch (style->type) { | 335 switch (style.type) { |
337 case omnibox::DESCRIPTION_STYLE_TYPE_URL: | 336 case omnibox::DESCRIPTION_STYLE_TYPE_URL: |
338 type_class = AutocompleteMatch::ACMatchClassification::URL; | 337 type_class = AutocompleteMatch::ACMatchClassification::URL; |
339 break; | 338 break; |
340 case omnibox::DESCRIPTION_STYLE_TYPE_MATCH: | 339 case omnibox::DESCRIPTION_STYLE_TYPE_MATCH: |
341 type_class = AutocompleteMatch::ACMatchClassification::MATCH; | 340 type_class = AutocompleteMatch::ACMatchClassification::MATCH; |
342 break; | 341 break; |
343 case omnibox::DESCRIPTION_STYLE_TYPE_DIM: | 342 case omnibox::DESCRIPTION_STYLE_TYPE_DIM: |
344 type_class = AutocompleteMatch::ACMatchClassification::DIM; | 343 type_class = AutocompleteMatch::ACMatchClassification::DIM; |
345 break; | 344 break; |
346 default: | 345 default: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 for (size_t i = 0; i < description_styles.size(); ++i) { | 394 for (size_t i = 0; i < description_styles.size(); ++i) { |
396 if (description_styles[i].offset > placeholder) | 395 if (description_styles[i].offset > placeholder) |
397 description_styles[i].offset += replacement.length() - 2; | 396 description_styles[i].offset += replacement.length() - 2; |
398 } | 397 } |
399 } | 398 } |
400 | 399 |
401 match->contents.assign(description); | 400 match->contents.assign(description); |
402 } | 401 } |
403 | 402 |
404 } // namespace extensions | 403 } // namespace extensions |
OLD | NEW |