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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 120503005: Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix touch drag and drop unit test. Created 6 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) 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/ui/views/omnibox/omnibox_view_views.h" 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 26 matching lines...) Expand all
37 #include "ui/base/ime/text_input_type.h" 37 #include "ui/base/ime/text_input_type.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/models/simple_menu_model.h" 39 #include "ui/base/models/simple_menu_model.h"
40 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
41 #include "ui/events/event.h" 41 #include "ui/events/event.h"
42 #include "ui/gfx/canvas.h" 42 #include "ui/gfx/canvas.h"
43 #include "ui/gfx/font_list.h" 43 #include "ui/gfx/font_list.h"
44 #include "ui/gfx/selection_model.h" 44 #include "ui/gfx/selection_model.h"
45 #include "ui/views/border.h" 45 #include "ui/views/border.h"
46 #include "ui/views/button_drag_utils.h" 46 #include "ui/views/button_drag_utils.h"
47 #include "ui/views/controls/textfield/native_textfield_views.h"
48 #include "ui/views/controls/textfield/textfield.h" 47 #include "ui/views/controls/textfield/textfield.h"
49 #include "ui/views/ime/input_method.h" 48 #include "ui/views/ime/input_method.h"
50 #include "ui/views/layout/fill_layout.h" 49 #include "ui/views/layout/fill_layout.h"
51 #include "ui/views/views_delegate.h" 50 #include "ui/views/views_delegate.h"
52 #include "ui/views/widget/widget.h" 51 #include "ui/views/widget/widget.h"
53 #include "url/gurl.h" 52 #include "url/gurl.h"
54 53
55 #if defined(OS_WIN) 54 #if defined(OS_WIN)
56 #include "chrome/browser/browser_process.h" 55 #include "chrome/browser/browser_process.h"
57 #endif 56 #endif
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 ToolbarModel::NONE, LocationBarView::BACKGROUND)); 168 ToolbarModel::NONE, LocationBarView::BACKGROUND));
170 169
171 if (popup_window_mode_) 170 if (popup_window_mode_)
172 SetReadOnly(true); 171 SetReadOnly(true);
173 172
174 if (chrome::ShouldDisplayOriginChip()) 173 if (chrome::ShouldDisplayOriginChip())
175 set_placeholder_text(l10n_util::GetStringUTF16(IDS_OMNIBOX_EMPTY_HINT)); 174 set_placeholder_text(l10n_util::GetStringUTF16(IDS_OMNIBOX_EMPTY_HINT));
176 175
177 // Initialize the popup view using the same font. 176 // Initialize the popup view using the same font.
178 popup_view_.reset(OmniboxPopupContentsView::Create( 177 popup_view_.reset(OmniboxPopupContentsView::Create(
179 font_list(), this, model(), location_bar_view_)); 178 GetFontList(), this, model(), location_bar_view_));
180 179
181 #if defined(OS_CHROMEOS) 180 #if defined(OS_CHROMEOS)
182 chromeos::input_method::InputMethodManager::Get()-> 181 chromeos::input_method::InputMethodManager::Get()->
183 AddCandidateWindowObserver(this); 182 AddCandidateWindowObserver(this);
184 #endif 183 #endif
185 } 184 }
186 185
187 //////////////////////////////////////////////////////////////////////////////// 186 ////////////////////////////////////////////////////////////////////////////////
188 // OmniboxViewViews, views::Textfield implementation: 187 // OmniboxViewViews, views::Textfield implementation:
189 188
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // Note the parallel with SkipDefaultKeyEventProcessing above. 345 // Note the parallel with SkipDefaultKeyEventProcessing above.
347 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { 346 if (views::FocusManager::IsTabTraversalKeyEvent(event)) {
348 if (model()->is_keyword_hint() && !event.IsShiftDown()) { 347 if (model()->is_keyword_hint() && !event.IsShiftDown()) {
349 model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB); 348 model()->AcceptKeyword(ENTERED_KEYWORD_MODE_VIA_TAB);
350 return true; 349 return true;
351 } 350 }
352 if (model()->popup_model()->IsOpen()) { 351 if (model()->popup_model()->IsOpen()) {
353 if (event.IsShiftDown() && 352 if (event.IsShiftDown() &&
354 model()->popup_model()->selected_line_state() == 353 model()->popup_model()->selected_line_state() ==
355 OmniboxPopupModel::KEYWORD) { 354 OmniboxPopupModel::KEYWORD) {
356 model()->ClearKeyword(text()); 355 model()->ClearKeyword(GetText());
357 } else { 356 } else {
358 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1); 357 model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
359 } 358 }
360 return true; 359 return true;
361 } 360 }
362 } 361 }
363 362
364 return false; 363 return false;
365 } 364 }
366 365
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 // Something visibly changed. Re-enable URL replacement. 449 // Something visibly changed. Re-enable URL replacement.
451 controller()->GetToolbarModel()->set_url_replacement_enabled(true); 450 controller()->GetToolbarModel()->set_url_replacement_enabled(true);
452 model()->UpdatePermanentText(); 451 model()->UpdatePermanentText();
453 452
454 // Tweak: if the user had all the text selected, select all the new text. 453 // Tweak: if the user had all the text selected, select all the new text.
455 // This makes one particular case better: the user clicks in the box to 454 // This makes one particular case better: the user clicks in the box to
456 // change it right before the permanent URL is changed. Since the new URL 455 // change it right before the permanent URL is changed. Since the new URL
457 // is still fully selected, the user's typing will replace the edit contents 456 // is still fully selected, the user's typing will replace the edit contents
458 // as they'd intended. 457 // as they'd intended.
459 const gfx::Range range(GetSelectedRange()); 458 const gfx::Range range(GetSelectedRange());
460 const bool was_select_all = (range.length() == text().length()); 459 const bool was_select_all = (range.length() == GetText().length());
461 460
462 RevertAll(); 461 RevertAll();
463 462
464 // Only select all when we have focus. If we don't have focus, selecting 463 // Only select all when we have focus. If we don't have focus, selecting
465 // all is unnecessary since the selection will change on regaining focus, 464 // all is unnecessary since the selection will change on regaining focus,
466 // and can in fact cause artifacts, e.g. if the user is on the NTP and 465 // and can in fact cause artifacts, e.g. if the user is on the NTP and
467 // clicks a link to navigate, causing |was_select_all| to be vacuously true 466 // clicks a link to navigate, causing |was_select_all| to be vacuously true
468 // for the empty omnibox, and we then select all here, leading to the 467 // for the empty omnibox, and we then select all here, leading to the
469 // trailing portion of a long URL being scrolled into view. We could try 468 // trailing portion of a long URL being scrolled into view. We could try
470 // and address cases like this, but it seems better to just not muck with 469 // and address cases like this, but it seems better to just not muck with
471 // things when the omnibox isn't focused to begin with. 470 // things when the omnibox isn't focused to begin with.
472 if (was_select_all && model()->has_focus()) 471 if (was_select_all && model()->has_focus())
473 SelectAll(range.is_reversed()); 472 SelectAll(range.is_reversed());
474 } else if (old_security_level != security_level_) { 473 } else if (old_security_level != security_level_) {
475 EmphasizeURLComponents(); 474 EmphasizeURLComponents();
476 } 475 }
477 } 476 }
478 477
479 base::string16 OmniboxViewViews::GetText() const { 478 base::string16 OmniboxViewViews::GetText() const {
480 // TODO(oshima): IME support 479 // TODO(oshima): IME support
481 return text(); 480 return Textfield::GetText();
482 } 481 }
483 482
484 void OmniboxViewViews::SetUserText(const base::string16& text, 483 void OmniboxViewViews::SetUserText(const base::string16& text,
485 const base::string16& display_text, 484 const base::string16& display_text,
486 bool update_popup) { 485 bool update_popup) {
487 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); 486 saved_selection_for_focus_change_ = gfx::Range::InvalidRange();
488 OmniboxView::SetUserText(text, display_text, update_popup); 487 OmniboxView::SetUserText(text, display_text, update_popup);
489 } 488 }
490 489
491 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text, 490 void OmniboxViewViews::SetWindowTextAndCaretPos(const base::string16& text,
492 size_t caret_pos, 491 size_t caret_pos,
493 bool update_popup, 492 bool update_popup,
494 bool notify_text_changed) { 493 bool notify_text_changed) {
495 const gfx::Range range(caret_pos, caret_pos); 494 const gfx::Range range(caret_pos, caret_pos);
496 SetTextAndSelectedRange(text, range); 495 SetTextAndSelectedRange(text, range);
497 496
498 if (update_popup) 497 if (update_popup)
499 UpdatePopup(); 498 UpdatePopup();
500 499
501 if (notify_text_changed) 500 if (notify_text_changed)
502 TextChanged(); 501 TextChanged();
503 } 502 }
504 503
505 void OmniboxViewViews::SetForcedQuery() { 504 void OmniboxViewViews::SetForcedQuery() {
506 const base::string16 current_text(text()); 505 const base::string16 current_text(GetText());
507 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16); 506 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16);
508 if (start == base::string16::npos || (current_text[start] != '?')) 507 if (start == base::string16::npos || (current_text[start] != '?'))
509 OmniboxView::SetUserText(base::ASCIIToUTF16("?")); 508 OmniboxView::SetUserText(base::ASCIIToUTF16("?"));
510 else 509 else
511 SelectRange(gfx::Range(current_text.size(), start + 1)); 510 SelectRange(gfx::Range(current_text.size(), start + 1));
512 } 511 }
513 512
514 bool OmniboxViewViews::IsSelectAll() const { 513 bool OmniboxViewViews::IsSelectAll() const {
515 // TODO(oshima): IME support. 514 // TODO(oshima): IME support.
516 return text() == GetSelectedText(); 515 return GetText() == GetSelectedText();
517 } 516 }
518 517
519 bool OmniboxViewViews::DeleteAtEndPressed() { 518 bool OmniboxViewViews::DeleteAtEndPressed() {
520 return delete_at_end_pressed_; 519 return delete_at_end_pressed_;
521 } 520 }
522 521
523 void OmniboxViewViews::GetSelectionBounds( 522 void OmniboxViewViews::GetSelectionBounds(
524 base::string16::size_type* start, 523 base::string16::size_type* start,
525 base::string16::size_type* end) const { 524 base::string16::size_type* end) const {
526 const gfx::Range range = GetSelectedRange(); 525 const gfx::Range range = GetSelectedRange();
(...skipping 14 matching lines...) Expand all
541 model()->SetInputInProgress(true); 540 model()->SetInputInProgress(true);
542 if (!model()->has_focus()) 541 if (!model()->has_focus())
543 return; 542 return;
544 543
545 // Prevent inline autocomplete when the caret isn't at the end of the text, 544 // Prevent inline autocomplete when the caret isn't at the end of the text,
546 // and during IME composition editing unless 545 // and during IME composition editing unless
547 // |kEnableOmniboxAutoCompletionForIme| is enabled. 546 // |kEnableOmniboxAutoCompletionForIme| is enabled.
548 const gfx::Range sel = GetSelectedRange(); 547 const gfx::Range sel = GetSelectedRange();
549 model()->StartAutocomplete( 548 model()->StartAutocomplete(
550 !sel.is_empty(), 549 !sel.is_empty(),
551 sel.GetMax() < text().length() || 550 sel.GetMax() < GetText().length() ||
552 (IsIMEComposing() && !IsOmniboxAutoCompletionForImeEnabled())); 551 (IsIMEComposing() && !IsOmniboxAutoCompletionForImeEnabled()));
553 } 552 }
554 553
555 void OmniboxViewViews::SetFocus() { 554 void OmniboxViewViews::SetFocus() {
556 RequestFocus(); 555 RequestFocus();
557 // Restore caret visibility if focus is explicitly requested. This is 556 // Restore caret visibility if focus is explicitly requested. This is
558 // necessary because if we already have invisible focus, the RequestFocus() 557 // necessary because if we already have invisible focus, the RequestFocus()
559 // call above will short-circuit, preventing us from reaching 558 // call above will short-circuit, preventing us from reaching
560 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the 559 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the
561 // omnibox regains focus after losing focus. 560 // omnibox regains focus after losing focus.
(...skipping 11 matching lines...) Expand all
573 if (save_original_selection) 572 if (save_original_selection)
574 saved_temporary_selection_ = GetSelectedRange(); 573 saved_temporary_selection_ = GetSelectedRange();
575 574
576 SetWindowTextAndCaretPos(display_text, display_text.length(), false, 575 SetWindowTextAndCaretPos(display_text, display_text.length(), false,
577 notify_text_changed); 576 notify_text_changed);
578 } 577 }
579 578
580 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged( 579 bool OmniboxViewViews::OnInlineAutocompleteTextMaybeChanged(
581 const base::string16& display_text, 580 const base::string16& display_text,
582 size_t user_text_length) { 581 size_t user_text_length) {
583 if (display_text == text()) 582 if (display_text == GetText())
584 return false; 583 return false;
585 584
586 if (IsIMEComposing()) { 585 if (IsIMEComposing()) {
587 location_bar_view_->SetImeInlineAutocompletion( 586 location_bar_view_->SetImeInlineAutocompletion(
588 display_text.substr(user_text_length)); 587 display_text.substr(user_text_length));
589 } else { 588 } else {
590 gfx::Range range(display_text.size(), user_text_length); 589 gfx::Range range(display_text.size(), user_text_length);
591 SetTextAndSelectedRange(display_text, range); 590 SetTextAndSelectedRange(display_text, range);
592 } 591 }
593 TextChanged(); 592 TextChanged();
594 return true; 593 return true;
595 } 594 }
596 595
597 void OmniboxViewViews::OnInlineAutocompleteTextCleared() { 596 void OmniboxViewViews::OnInlineAutocompleteTextCleared() {
598 // Hide the inline autocompletion for IME users. 597 // Hide the inline autocompletion for IME users.
599 location_bar_view_->SetImeInlineAutocompletion(base::string16()); 598 location_bar_view_->SetImeInlineAutocompletion(base::string16());
600 } 599 }
601 600
602 void OmniboxViewViews::OnRevertTemporaryText() { 601 void OmniboxViewViews::OnRevertTemporaryText() {
603 SelectRange(saved_temporary_selection_); 602 SelectRange(saved_temporary_selection_);
604 // We got here because the user hit the Escape key. We explicitly don't call 603 // We got here because the user hit the Escape key. We explicitly don't call
605 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already 604 // TextChanged(), since OmniboxPopupModel::ResetToDefaultMatch() has already
606 // been called by now, and it would've called TextChanged() if it was 605 // been called by now, and it would've called TextChanged() if it was
607 // warranted. 606 // warranted.
608 } 607 }
609 608
610 void OmniboxViewViews::OnBeforePossibleChange() { 609 void OmniboxViewViews::OnBeforePossibleChange() {
611 // Record our state. 610 // Record our state.
612 text_before_change_ = text(); 611 text_before_change_ = GetText();
613 sel_before_change_ = GetSelectedRange(); 612 sel_before_change_ = GetSelectedRange();
614 ime_composing_before_change_ = IsIMEComposing(); 613 ime_composing_before_change_ = IsIMEComposing();
615 } 614 }
616 615
617 bool OmniboxViewViews::OnAfterPossibleChange() { 616 bool OmniboxViewViews::OnAfterPossibleChange() {
618 // See if the text or selection have changed since OnBeforePossibleChange(). 617 // See if the text or selection have changed since OnBeforePossibleChange().
619 const base::string16 new_text = text(); 618 const base::string16 new_text = GetText();
620 const gfx::Range new_sel = GetSelectedRange(); 619 const gfx::Range new_sel = GetSelectedRange();
621 const bool text_changed = (new_text != text_before_change_) || 620 const bool text_changed = (new_text != text_before_change_) ||
622 (ime_composing_before_change_ != IsIMEComposing()); 621 (ime_composing_before_change_ != IsIMEComposing());
623 const bool selection_differs = 622 const bool selection_differs =
624 !((sel_before_change_.is_empty() && new_sel.is_empty()) || 623 !((sel_before_change_.is_empty() && new_sel.is_empty()) ||
625 sel_before_change_.EqualsIgnoringDirection(new_sel)); 624 sel_before_change_.EqualsIgnoringDirection(new_sel));
626 625
627 // When the user has deleted text, we don't allow inline autocomplete. Make 626 // When the user has deleted text, we don't allow inline autocomplete. Make
628 // sure to not flag cases like selecting part of the text and then pasting 627 // sure to not flag cases like selecting part of the text and then pasting
629 // (or typing) the prefix of that selection. (We detect these by making 628 // (or typing) the prefix of that selection. (We detect these by making
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 666
668 base::string16 OmniboxViewViews::GetGrayTextAutocompletion() const { 667 base::string16 OmniboxViewViews::GetGrayTextAutocompletion() const {
669 #if defined(OS_WIN) || defined(USE_AURA) 668 #if defined(OS_WIN) || defined(USE_AURA)
670 return location_bar_view_->GetGrayTextAutocompletion(); 669 return location_bar_view_->GetGrayTextAutocompletion();
671 #else 670 #else
672 return base::string16(); 671 return base::string16();
673 #endif 672 #endif
674 } 673 }
675 674
676 int OmniboxViewViews::GetTextWidth() const { 675 int OmniboxViewViews::GetTextWidth() const {
677 return textfield_view_->GetWidthNeededForText(); 676 // Returns the width necessary to display the current text, including any
677 // necessary space for the cursor or border/margin.
678 return GetRenderText()->GetContentWidth() + GetInsets().width();
678 } 679 }
679 680
680 int OmniboxViewViews::GetWidth() const { 681 int OmniboxViewViews::GetWidth() const {
681 return location_bar_view_->width(); 682 return location_bar_view_->width();
682 } 683 }
683 684
684 bool OmniboxViewViews::IsImeComposing() const { 685 bool OmniboxViewViews::IsImeComposing() const {
685 return IsIMEComposing(); 686 return IsIMEComposing();
686 } 687 }
687 688
(...skipping 16 matching lines...) Expand all
704 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, 705 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
705 const ui::KeyEvent& event) { 706 const ui::KeyEvent& event) {
706 delete_at_end_pressed_ = false; 707 delete_at_end_pressed_ = false;
707 708
708 if (event.key_code() == ui::VKEY_BACK) { 709 if (event.key_code() == ui::VKEY_BACK) {
709 // No extra handling is needed in keyword search mode, if there is a 710 // No extra handling is needed in keyword search mode, if there is a
710 // non-empty selection, or if the cursor is not leading the text. 711 // non-empty selection, or if the cursor is not leading the text.
711 if (model()->is_keyword_hint() || model()->keyword().empty() || 712 if (model()->is_keyword_hint() || model()->keyword().empty() ||
712 HasSelection() || GetCursorPosition() != 0) 713 HasSelection() || GetCursorPosition() != 0)
713 return false; 714 return false;
714 model()->ClearKeyword(text()); 715 model()->ClearKeyword(GetText());
715 return true; 716 return true;
716 } 717 }
717 718
718 if (event.key_code() == ui::VKEY_DELETE && !event.IsAltDown()) { 719 if (event.key_code() == ui::VKEY_DELETE && !event.IsAltDown()) {
719 delete_at_end_pressed_ = 720 delete_at_end_pressed_ =
720 (!HasSelection() && GetCursorPosition() == text().length()); 721 (!HasSelection() && GetCursorPosition() == GetText().length());
721 } 722 }
722 723
723 // Handle the right-arrow key for LTR text and the left-arrow key for RTL text 724 // Handle the right-arrow key for LTR text and the left-arrow key for RTL text
724 // if there is gray text that needs to be committed. 725 // if there is gray text that needs to be committed.
725 if (GetCursorPosition() == text().length()) { 726 if (GetCursorPosition() == GetText().length()) {
726 base::i18n::TextDirection direction = GetTextDirection(); 727 base::i18n::TextDirection direction = GetTextDirection();
727 if ((direction == base::i18n::LEFT_TO_RIGHT && 728 if ((direction == base::i18n::LEFT_TO_RIGHT &&
728 event.key_code() == ui::VKEY_RIGHT) || 729 event.key_code() == ui::VKEY_RIGHT) ||
729 (direction == base::i18n::RIGHT_TO_LEFT && 730 (direction == base::i18n::RIGHT_TO_LEFT &&
730 event.key_code() == ui::VKEY_LEFT)) { 731 event.key_code() == ui::VKEY_LEFT)) {
731 return model()->CommitSuggestedText(); 732 return model()->CommitSuggestedText();
732 } 733 }
733 } 734 }
734 735
735 return false; 736 return false;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 chromeos::input_method::InputMethodManager* manager) { 912 chromeos::input_method::InputMethodManager* manager) {
912 ime_candidate_window_open_ = false; 913 ime_candidate_window_open_ = false;
913 } 914 }
914 #endif 915 #endif
915 916
916 //////////////////////////////////////////////////////////////////////////////// 917 ////////////////////////////////////////////////////////////////////////////////
917 // OmniboxViewViews, private: 918 // OmniboxViewViews, private:
918 919
919 int OmniboxViewViews::GetOmniboxTextLength() const { 920 int OmniboxViewViews::GetOmniboxTextLength() const {
920 // TODO(oshima): Support IME. 921 // TODO(oshima): Support IME.
921 return static_cast<int>(text().length()); 922 return static_cast<int>(GetText().length());
922 } 923 }
923 924
924 void OmniboxViewViews::EmphasizeURLComponents() { 925 void OmniboxViewViews::EmphasizeURLComponents() {
925 // See whether the contents are a URL with a non-empty host portion, which we 926 // See whether the contents are a URL with a non-empty host portion, which we
926 // should emphasize. To check for a URL, rather than using the type returned 927 // should emphasize. To check for a URL, rather than using the type returned
927 // by Parse(), ask the model, which will check the desired page transition for 928 // by Parse(), ask the model, which will check the desired page transition for
928 // this input. This can tell us whether an UNKNOWN input string is going to 929 // this input. This can tell us whether an UNKNOWN input string is going to
929 // be treated as a search or a navigation, and is the same method the Paste 930 // be treated as a search or a navigation, and is the same method the Paste
930 // And Go system uses. 931 // And Go system uses.
931 url_parse::Component scheme, host; 932 url_parse::Component scheme, host;
932 AutocompleteInput::ParseForEmphasizeComponents(text(), &scheme, &host); 933 AutocompleteInput::ParseForEmphasizeComponents(GetText(), &scheme, &host);
933 bool grey_out_url = text().substr(scheme.begin, scheme.len) == 934 bool grey_out_url = GetText().substr(scheme.begin, scheme.len) ==
934 base::UTF8ToUTF16(extensions::kExtensionScheme); 935 base::UTF8ToUTF16(extensions::kExtensionScheme);
935 bool grey_base = model()->CurrentTextIsURL() && 936 bool grey_base = model()->CurrentTextIsURL() &&
936 (host.is_nonempty() || grey_out_url); 937 (host.is_nonempty() || grey_out_url);
937 SetColor(location_bar_view_->GetColor( 938 SetColor(location_bar_view_->GetColor(
938 security_level_, 939 security_level_,
939 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); 940 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
940 if (grey_base && !grey_out_url) { 941 if (grey_base && !grey_out_url) {
941 ApplyColor( 942 ApplyColor(
942 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), 943 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT),
943 gfx::Range(host.begin, host.end())); 944 gfx::Range(host.begin, host.end()));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 const base::string16 text(GetClipboardText()); 976 const base::string16 text(GetClipboardText());
976 if (!text.empty()) { 977 if (!text.empty()) {
977 // Record this paste, so we can do different behavior. 978 // Record this paste, so we can do different behavior.
978 model()->OnPaste(); 979 model()->OnPaste();
979 // Force a Paste operation to trigger the text_changed code in 980 // Force a Paste operation to trigger the text_changed code in
980 // OnAfterPossibleChange(), even if identical contents are pasted. 981 // OnAfterPossibleChange(), even if identical contents are pasted.
981 text_before_change_.clear(); 982 text_before_change_.clear();
982 InsertOrReplaceText(text); 983 InsertOrReplaceText(text);
983 } 984 }
984 } 985 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698