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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_views.cc

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit_view_views.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_views.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 views::TextRange selection; 281 views::TextRange selection;
282 textfield_->GetSelectedRange(&selection); 282 textfield_->GetSelectedRange(&selection);
283 GetStateAccessor()->SetProperty( 283 GetStateAccessor()->SetProperty(
284 tab->property_bag(), 284 tab->property_bag(),
285 AutocompleteEditState(model_state, ViewState(selection))); 285 AutocompleteEditState(model_state, ViewState(selection)));
286 } 286 }
287 287
288 void AutocompleteEditViewViews::Update(const TabContents* contents) { 288 void AutocompleteEditViewViews::Update(const TabContents* contents) {
289 // NOTE: We're getting the URL text here from the ToolbarModel. 289 // NOTE: We're getting the URL text here from the ToolbarModel.
290 bool visibly_changed_permanent_text = 290 bool visibly_changed_permanent_text =
291 model_->UpdatePermanentText(toolbar_model_->GetText()); 291 model_->UpdatePermanentText(WideToUTF16Hack(toolbar_model_->GetText()));
292 292
293 ToolbarModel::SecurityLevel security_level = 293 ToolbarModel::SecurityLevel security_level =
294 toolbar_model_->GetSecurityLevel(); 294 toolbar_model_->GetSecurityLevel();
295 bool changed_security_level = (security_level != security_level_); 295 bool changed_security_level = (security_level != security_level_);
296 security_level_ = security_level; 296 security_level_ = security_level;
297 297
298 // TODO(oshima): Copied from gtk implementation which is 298 // TODO(oshima): Copied from gtk implementation which is
299 // slightly different from WIN impl. Find out the correct implementation 299 // slightly different from WIN impl. Find out the correct implementation
300 // for views-implementation. 300 // for views-implementation.
301 if (contents) { 301 if (contents) {
(...skipping 12 matching lines...) Expand all
314 } else if (changed_security_level) { 314 } else if (changed_security_level) {
315 EmphasizeURLComponents(); 315 EmphasizeURLComponents();
316 } 316 }
317 } 317 }
318 318
319 void AutocompleteEditViewViews::OpenURL(const GURL& url, 319 void AutocompleteEditViewViews::OpenURL(const GURL& url,
320 WindowOpenDisposition disposition, 320 WindowOpenDisposition disposition,
321 PageTransition::Type transition, 321 PageTransition::Type transition,
322 const GURL& alternate_nav_url, 322 const GURL& alternate_nav_url,
323 size_t selected_line, 323 size_t selected_line,
324 const std::wstring& keyword) { 324 const string16& keyword) {
325 if (!url.is_valid()) 325 if (!url.is_valid())
326 return; 326 return;
327 327
328 model_->OpenURL(url, disposition, transition, alternate_nav_url, 328 model_->OpenURL(url, disposition, transition, alternate_nav_url,
329 selected_line, keyword); 329 selected_line, keyword);
330 } 330 }
331 331
332 std::wstring AutocompleteEditViewViews::GetText() const { 332 string16 AutocompleteEditViewViews::GetText() const {
333 // TODO(oshima): IME support 333 // TODO(oshima): IME support
334 return UTF16ToWide(textfield_->text()); 334 return textfield_->text();
335 } 335 }
336 336
337 bool AutocompleteEditViewViews::IsEditingOrEmpty() const { 337 bool AutocompleteEditViewViews::IsEditingOrEmpty() const {
338 return model_->user_input_in_progress() || (GetTextLength() == 0); 338 return model_->user_input_in_progress() || (GetTextLength() == 0);
339 } 339 }
340 340
341 int AutocompleteEditViewViews::GetIcon() const { 341 int AutocompleteEditViewViews::GetIcon() const {
342 return IsEditingOrEmpty() ? 342 return IsEditingOrEmpty() ?
343 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : 343 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) :
344 toolbar_model_->GetIcon(); 344 toolbar_model_->GetIcon();
345 } 345 }
346 346
347 void AutocompleteEditViewViews::SetUserText(const std::wstring& text) { 347 void AutocompleteEditViewViews::SetUserText(const string16& text) {
348 SetUserText(text, text, true); 348 SetUserText(text, text, true);
349 } 349 }
350 350
351 void AutocompleteEditViewViews::SetUserText(const std::wstring& text, 351 void AutocompleteEditViewViews::SetUserText(const string16& text,
352 const std::wstring& display_text, 352 const string16& display_text,
353 bool update_popup) { 353 bool update_popup) {
354 model_->SetUserText(text); 354 model_->SetUserText(text);
355 SetWindowTextAndCaretPos(display_text, display_text.length()); 355 SetWindowTextAndCaretPos(display_text, display_text.length());
356 if (update_popup) 356 if (update_popup)
357 UpdatePopup(); 357 UpdatePopup();
358 TextChanged(); 358 TextChanged();
359 } 359 }
360 360
361 void AutocompleteEditViewViews::SetWindowTextAndCaretPos( 361 void AutocompleteEditViewViews::SetWindowTextAndCaretPos(
362 const std::wstring& text, 362 const string16& text,
363 size_t caret_pos) { 363 size_t caret_pos) {
364 const views::TextRange range(caret_pos, caret_pos); 364 const views::TextRange range(caret_pos, caret_pos);
365 SetTextAndSelectedRange(text, range); 365 SetTextAndSelectedRange(text, range);
366 } 366 }
367 367
368 void AutocompleteEditViewViews::SetForcedQuery() { 368 void AutocompleteEditViewViews::SetForcedQuery() {
369 const std::wstring current_text(GetText()); 369 const string16 current_text(GetText());
370 const size_t start = current_text.find_first_not_of(kWhitespaceWide); 370 const size_t start = current_text.find_first_not_of(kWhitespaceUTF16);
371 if (start == std::wstring::npos || (current_text[start] != '?')) { 371 if (start == string16::npos || (current_text[start] != '?')) {
372 SetUserText(L"?"); 372 SetUserText(ASCIIToUTF16("?"));
373 } else { 373 } else {
374 SelectRange(current_text.size(), start + 1); 374 SelectRange(current_text.size(), start + 1);
375 } 375 }
376 } 376 }
377 377
378 bool AutocompleteEditViewViews::IsSelectAll() { 378 bool AutocompleteEditViewViews::IsSelectAll() {
379 // TODO(oshima): IME support. 379 // TODO(oshima): IME support.
380 return textfield_->text() == textfield_->GetSelectedText(); 380 return textfield_->text() == textfield_->GetSelectedText();
381 } 381 }
382 382
383 bool AutocompleteEditViewViews::DeleteAtEndPressed() { 383 bool AutocompleteEditViewViews::DeleteAtEndPressed() {
384 return delete_at_end_pressed_; 384 return delete_at_end_pressed_;
385 } 385 }
386 386
387 void AutocompleteEditViewViews::GetSelectionBounds( 387 void AutocompleteEditViewViews::GetSelectionBounds(
388 std::wstring::size_type* start, 388 string16::size_type* start,
389 std::wstring::size_type* end) { 389 string16::size_type* end) {
390 views::TextRange range; 390 views::TextRange range;
391 textfield_->GetSelectedRange(&range); 391 textfield_->GetSelectedRange(&range);
392 *start = static_cast<size_t>(range.end()); 392 *start = static_cast<size_t>(range.end());
393 *end = static_cast<size_t>(range.start()); 393 *end = static_cast<size_t>(range.start());
394 } 394 }
395 395
396 void AutocompleteEditViewViews::SelectAll(bool reversed) { 396 void AutocompleteEditViewViews::SelectAll(bool reversed) {
397 if (reversed) 397 if (reversed)
398 SelectRange(GetTextLength(), 0); 398 SelectRange(GetTextLength(), 0);
399 else 399 else
(...skipping 28 matching lines...) Expand all
428 popup_view_->GetModel()->StopAutocomplete(); 428 popup_view_->GetModel()->StopAutocomplete();
429 } 429 }
430 430
431 void AutocompleteEditViewViews::SetFocus() { 431 void AutocompleteEditViewViews::SetFocus() {
432 // In views-implementation, the focus is on textfield rather than 432 // In views-implementation, the focus is on textfield rather than
433 // AutocompleteEditView. 433 // AutocompleteEditView.
434 textfield_->RequestFocus(); 434 textfield_->RequestFocus();
435 } 435 }
436 436
437 void AutocompleteEditViewViews::OnTemporaryTextMaybeChanged( 437 void AutocompleteEditViewViews::OnTemporaryTextMaybeChanged(
438 const std::wstring& display_text, 438 const string16& display_text,
439 bool save_original_selection) { 439 bool save_original_selection) {
440 if (save_original_selection) 440 if (save_original_selection)
441 textfield_->GetSelectedRange(&saved_temporary_selection_); 441 textfield_->GetSelectedRange(&saved_temporary_selection_);
442 442
443 SetWindowTextAndCaretPos(display_text, display_text.length()); 443 SetWindowTextAndCaretPos(display_text, display_text.length());
444 TextChanged(); 444 TextChanged();
445 } 445 }
446 446
447 bool AutocompleteEditViewViews::OnInlineAutocompleteTextMaybeChanged( 447 bool AutocompleteEditViewViews::OnInlineAutocompleteTextMaybeChanged(
448 const std::wstring& display_text, 448 const string16& display_text,
449 size_t user_text_length) { 449 size_t user_text_length) {
450 if (display_text == GetText()) 450 if (display_text == GetText())
451 return false; 451 return false;
452 views::TextRange range(display_text.size(), user_text_length); 452 views::TextRange range(display_text.size(), user_text_length);
453 SetTextAndSelectedRange(display_text, range); 453 SetTextAndSelectedRange(display_text, range);
454 TextChanged(); 454 TextChanged();
455 return true; 455 return true;
456 } 456 }
457 457
458 void AutocompleteEditViewViews::OnRevertTemporaryText() { 458 void AutocompleteEditViewViews::OnRevertTemporaryText() {
(...skipping 16 matching lines...) Expand all
475 content_maybe_changed_by_key_press_ = true; 475 content_maybe_changed_by_key_press_ = true;
476 return false; 476 return false;
477 } 477 }
478 views::TextRange new_sel; 478 views::TextRange new_sel;
479 textfield_->GetSelectedRange(&new_sel); 479 textfield_->GetSelectedRange(&new_sel);
480 480
481 size_t length = GetTextLength(); 481 size_t length = GetTextLength();
482 bool at_end_of_edit = (new_sel.start() == length && new_sel.end() == length); 482 bool at_end_of_edit = (new_sel.start() == length && new_sel.end() == length);
483 483
484 // See if the text or selection have changed since OnBeforePossibleChange(). 484 // See if the text or selection have changed since OnBeforePossibleChange().
485 std::wstring new_text = GetText(); 485 string16 new_text = GetText();
486 text_changed_ = (new_text != text_before_change_); 486 text_changed_ = (new_text != text_before_change_);
487 bool selection_differs = 487 bool selection_differs =
488 !((sel_before_change_.is_empty() && new_sel.is_empty()) || 488 !((sel_before_change_.is_empty() && new_sel.is_empty()) ||
489 sel_before_change_.EqualsIgnoringDirection(new_sel)); 489 sel_before_change_.EqualsIgnoringDirection(new_sel));
490 490
491 // When the user has deleted text, we don't allow inline autocomplete. Make 491 // When the user has deleted text, we don't allow inline autocomplete. Make
492 // sure to not flag cases like selecting part of the text and then pasting 492 // sure to not flag cases like selecting part of the text and then pasting
493 // (or typing) the prefix of that selection. (We detect these by making 493 // (or typing) the prefix of that selection. (We detect these by making
494 // sure the caret, which should be after any insertion, hasn't moved 494 // sure the caret, which should be after any insertion, hasn't moved
495 // forward of the old selection start.) 495 // forward of the old selection start.)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 int AutocompleteEditViewViews::TextWidth() const { 536 int AutocompleteEditViewViews::TextWidth() const {
537 // TODO(oshima): add horizontal margin. 537 // TODO(oshima): add horizontal margin.
538 return textfield_->font().GetStringWidth(textfield_->text()); 538 return textfield_->font().GetStringWidth(textfield_->text());
539 } 539 }
540 540
541 bool AutocompleteEditViewViews::IsImeComposing() const { 541 bool AutocompleteEditViewViews::IsImeComposing() const {
542 return false; 542 return false;
543 } 543 }
544 544
545 bool AutocompleteEditViewViews::CommitInstantSuggestion( 545 bool AutocompleteEditViewViews::CommitInstantSuggestion(
546 const std::wstring& typed_text, 546 const string16& typed_text,
547 const std::wstring& suggested_text) { 547 const string16& suggested_text) {
548 model_->FinalizeInstantQuery(typed_text, suggested_text); 548 model_->FinalizeInstantQuery(typed_text, suggested_text);
549 return true; 549 return true;
550 } 550 }
551 551
552 void AutocompleteEditViewViews::SetInstantSuggestion(const string16& input) { 552 void AutocompleteEditViewViews::SetInstantSuggestion(const string16& input) {
553 NOTIMPLEMENTED(); 553 NOTIMPLEMENTED();
554 } 554 }
555 555
556 //////////////////////////////////////////////////////////////////////////////// 556 ////////////////////////////////////////////////////////////////////////////////
557 // AutocompleteEditViewViews, NotificationObserver implementation: 557 // AutocompleteEditViewViews, NotificationObserver implementation:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // TODO(oshima): Update URL visual style 612 // TODO(oshima): Update URL visual style
613 NOTIMPLEMENTED(); 613 NOTIMPLEMENTED();
614 } 614 }
615 615
616 void AutocompleteEditViewViews::TextChanged() { 616 void AutocompleteEditViewViews::TextChanged() {
617 EmphasizeURLComponents(); 617 EmphasizeURLComponents();
618 controller_->OnChanged(); 618 controller_->OnChanged();
619 } 619 }
620 620
621 void AutocompleteEditViewViews::SetTextAndSelectedRange( 621 void AutocompleteEditViewViews::SetTextAndSelectedRange(
622 const std::wstring& text, 622 const string16& text,
623 const views::TextRange& range) { 623 const views::TextRange& range) {
624 if (text != GetText()) 624 if (text != GetText())
625 textfield_->SetText(WideToUTF16(text)); 625 textfield_->SetText(text);
626 textfield_->SelectRange(range); 626 textfield_->SelectRange(range);
627 } 627 }
628 628
629 string16 AutocompleteEditViewViews::GetSelectedText() const { 629 string16 AutocompleteEditViewViews::GetSelectedText() const {
630 // TODO(oshima): Support instant, IME. 630 // TODO(oshima): Support instant, IME.
631 return textfield_->GetSelectedText(); 631 return textfield_->GetSelectedText();
632 } 632 }
633 633
634 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) { 634 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) {
635 const views::TextRange range(caret, end); 635 const views::TextRange range(caret, end);
636 textfield_->SelectRange(range); 636 textfield_->SelectRange(range);
637 } 637 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698