OLD | NEW |
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/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const char OmniboxViewViews::kViewClassName[] = | 139 const char OmniboxViewViews::kViewClassName[] = |
140 "browser/ui/views/omnibox/OmniboxViewViews"; | 140 "browser/ui/views/omnibox/OmniboxViewViews"; |
141 | 141 |
142 OmniboxViewViews::OmniboxViewViews(AutocompleteEditController* controller, | 142 OmniboxViewViews::OmniboxViewViews(AutocompleteEditController* controller, |
143 ToolbarModel* toolbar_model, | 143 ToolbarModel* toolbar_model, |
144 Profile* profile, | 144 Profile* profile, |
145 CommandUpdater* command_updater, | 145 CommandUpdater* command_updater, |
146 bool popup_window_mode, | 146 bool popup_window_mode, |
147 views::View* location_bar) | 147 views::View* location_bar) |
148 : model_(new AutocompleteEditModel(this, controller, profile)), | 148 : model_(new AutocompleteEditModel(this, controller, profile)), |
149 popup_view_(CreatePopupView(profile, location_bar)), | 149 popup_view_(CreatePopupView(location_bar)), |
150 controller_(controller), | 150 controller_(controller), |
151 toolbar_model_(toolbar_model), | 151 toolbar_model_(toolbar_model), |
152 command_updater_(command_updater), | 152 command_updater_(command_updater), |
153 popup_window_mode_(popup_window_mode), | 153 popup_window_mode_(popup_window_mode), |
154 security_level_(ToolbarModel::NONE), | 154 security_level_(ToolbarModel::NONE), |
155 ime_composing_before_change_(false), | 155 ime_composing_before_change_(false), |
156 delete_at_end_pressed_(false) { | 156 delete_at_end_pressed_(false) { |
157 set_border(views::Border::CreateEmptyBorder(kAutocompleteVerticalMargin, 0, | 157 set_border(views::Border::CreateEmptyBorder(kAutocompleteVerticalMargin, 0, |
158 kAutocompleteVerticalMargin, 0)); | 158 kAutocompleteVerticalMargin, 0)); |
159 } | 159 } |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 635 |
636 void OmniboxViewViews::EmphasizeURLComponents() { | 636 void OmniboxViewViews::EmphasizeURLComponents() { |
637 // See whether the contents are a URL with a non-empty host portion, which we | 637 // See whether the contents are a URL with a non-empty host portion, which we |
638 // should emphasize. To check for a URL, rather than using the type returned | 638 // should emphasize. To check for a URL, rather than using the type returned |
639 // by Parse(), ask the model, which will check the desired page transition for | 639 // by Parse(), ask the model, which will check the desired page transition for |
640 // this input. This can tell us whether an UNKNOWN input string is going to | 640 // this input. This can tell us whether an UNKNOWN input string is going to |
641 // be treated as a search or a navigation, and is the same method the Paste | 641 // be treated as a search or a navigation, and is the same method the Paste |
642 // And Go system uses. | 642 // And Go system uses. |
643 string16 text = GetText(); | 643 string16 text = GetText(); |
644 url_parse::Component scheme, host; | 644 url_parse::Component scheme, host; |
645 AutocompleteInput::ParseForEmphasizeComponents( | 645 AutocompleteInput::ParseForEmphasizeComponents(text, model_->GetDesiredTLD(), |
646 text, model_->GetDesiredTLD(), &scheme, &host); | 646 &scheme, &host); |
647 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); | 647 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); |
648 SkColor base_color = emphasize ? kFadedTextColor : kNormalTextColor; | 648 SkColor base_color = emphasize ? kFadedTextColor : kNormalTextColor; |
649 ApplyURLStyle(textfield_, 0, text.length(), base_color, false); | 649 ApplyURLStyle(textfield_, 0, text.length(), base_color, false); |
650 if (emphasize) | 650 if (emphasize) |
651 ApplyURLStyle(textfield_, host.begin, host.end(), kNormalTextColor, false); | 651 ApplyURLStyle(textfield_, host.begin, host.end(), kNormalTextColor, false); |
652 // Emphasize the scheme for security UI display purposes (if necessary). | 652 // Emphasize the scheme for security UI display purposes (if necessary). |
653 if (!model_->user_input_in_progress() && scheme.is_nonempty() && | 653 if (!model_->user_input_in_progress() && scheme.is_nonempty() && |
654 (security_level_ != ToolbarModel::NONE)) { | 654 (security_level_ != ToolbarModel::NONE)) { |
655 const size_t start = scheme.begin, end = scheme.end(); | 655 const size_t start = scheme.begin, end = scheme.end(); |
656 switch (security_level_) { | 656 switch (security_level_) { |
(...skipping 29 matching lines...) Expand all Loading... |
686 // TODO(oshima): Support instant, IME. | 686 // TODO(oshima): Support instant, IME. |
687 return textfield_->GetSelectedText(); | 687 return textfield_->GetSelectedText(); |
688 } | 688 } |
689 | 689 |
690 void OmniboxViewViews::SelectRange(size_t caret, size_t end) { | 690 void OmniboxViewViews::SelectRange(size_t caret, size_t end) { |
691 const ui::Range range(caret, end); | 691 const ui::Range range(caret, end); |
692 textfield_->SelectRange(range); | 692 textfield_->SelectRange(range); |
693 } | 693 } |
694 | 694 |
695 AutocompletePopupView* OmniboxViewViews::CreatePopupView( | 695 AutocompletePopupView* OmniboxViewViews::CreatePopupView( |
696 Profile* profile, | |
697 View* location_bar) { | 696 View* location_bar) { |
698 #if defined(TOUCH_UI) | 697 #if defined(TOUCH_UI) |
699 typedef TouchAutocompletePopupContentsView AutocompleteContentsView; | 698 typedef TouchAutocompletePopupContentsView AutocompleteContentsView; |
700 #else | 699 #else |
701 typedef AutocompletePopupContentsView AutocompleteContentsView; | 700 typedef AutocompletePopupContentsView AutocompleteContentsView; |
702 #endif | 701 #endif |
703 return new AutocompleteContentsView(gfx::Font(), this, model_.get(), | 702 return new AutocompleteContentsView(gfx::Font(), this, model_.get(), |
704 location_bar); | 703 location_bar); |
705 } | 704 } |
OLD | NEW |