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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_api.cc

Issue 1833773002: [Extensions] Convert APIs to use movable types [8] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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
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 = style.length ? *style.length : description.length();
326 omnibox::SuggestResult::DescriptionStylesType* style = i->get(); 326 size_t offset = style.offset >= 0
327 327 ? style.offset
328 int length = description.length(); 328 : std::max(0, static_cast<int>(description.length()) +
329 if (style->length) 329 style.offset);
330 length = *style->length;
331
332 size_t offset = style->offset >= 0 ? style->offset :
333 std::max(0, static_cast<int>(description.length()) + style->offset);
334 330
335 int type_class; 331 int type_class;
336 switch (style->type) { 332 switch (style.type) {
337 case omnibox::DESCRIPTION_STYLE_TYPE_URL: 333 case omnibox::DESCRIPTION_STYLE_TYPE_URL:
338 type_class = AutocompleteMatch::ACMatchClassification::URL; 334 type_class = AutocompleteMatch::ACMatchClassification::URL;
339 break; 335 break;
340 case omnibox::DESCRIPTION_STYLE_TYPE_MATCH: 336 case omnibox::DESCRIPTION_STYLE_TYPE_MATCH:
341 type_class = AutocompleteMatch::ACMatchClassification::MATCH; 337 type_class = AutocompleteMatch::ACMatchClassification::MATCH;
342 break; 338 break;
343 case omnibox::DESCRIPTION_STYLE_TYPE_DIM: 339 case omnibox::DESCRIPTION_STYLE_TYPE_DIM:
344 type_class = AutocompleteMatch::ACMatchClassification::DIM; 340 type_class = AutocompleteMatch::ACMatchClassification::DIM;
345 break; 341 break;
346 default: 342 default:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 for (size_t i = 0; i < description_styles.size(); ++i) { 391 for (size_t i = 0; i < description_styles.size(); ++i) {
396 if (description_styles[i].offset > placeholder) 392 if (description_styles[i].offset > placeholder)
397 description_styles[i].offset += replacement.length() - 2; 393 description_styles[i].offset += replacement.length() - 2;
398 } 394 }
399 } 395 }
400 396
401 match->contents.assign(description); 397 match->contents.assign(description);
402 } 398 }
403 399
404 } // namespace extensions 400 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698