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/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
25 #include "components/omnibox/browser/autocomplete_input.h" | 25 #include "components/omnibox/browser/autocomplete_input.h" |
26 #include "components/omnibox/browser/autocomplete_match.h" | 26 #include "components/omnibox/browser/autocomplete_match.h" |
27 #include "components/omnibox/browser/omnibox_edit_controller.h" | 27 #include "components/omnibox/browser/omnibox_edit_controller.h" |
28 #include "components/omnibox/browser/omnibox_edit_model.h" | 28 #include "components/omnibox/browser/omnibox_edit_model.h" |
29 #include "components/omnibox/browser/omnibox_field_trial.h" | 29 #include "components/omnibox/browser/omnibox_field_trial.h" |
30 #include "components/omnibox/browser/omnibox_popup_model.h" | 30 #include "components/omnibox/browser/omnibox_popup_model.h" |
31 #include "components/strings/grit/components_strings.h" | 31 #include "components/strings/grit/components_strings.h" |
32 #include "components/toolbar/toolbar_model.h" | 32 #include "components/toolbar/toolbar_model.h" |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
34 #include "extensions/common/constants.h" | |
35 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
36 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
37 #include "ui/accessibility/ax_action_data.h" | 36 #include "ui/accessibility/ax_action_data.h" |
38 #include "ui/accessibility/ax_node_data.h" | 37 #include "ui/accessibility/ax_node_data.h" |
39 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 38 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
40 #include "ui/base/dragdrop/drag_drop_types.h" | 39 #include "ui/base/dragdrop/drag_drop_types.h" |
41 #include "ui/base/dragdrop/os_exchange_data.h" | 40 #include "ui/base/dragdrop/os_exchange_data.h" |
42 #include "ui/base/ime/input_method.h" | 41 #include "ui/base/ime/input_method.h" |
43 #include "ui/base/ime/text_edit_commands.h" | 42 #include "ui/base/ime/text_edit_commands.h" |
44 #include "ui/base/ime/text_input_client.h" | 43 #include "ui/base/ime/text_input_client.h" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 } | 556 } |
558 | 557 |
559 void OmniboxViewViews::OnMatchOpened(AutocompleteMatch::Type match_type) { | 558 void OmniboxViewViews::OnMatchOpened(AutocompleteMatch::Type match_type) { |
560 } | 559 } |
561 | 560 |
562 int OmniboxViewViews::GetOmniboxTextLength() const { | 561 int OmniboxViewViews::GetOmniboxTextLength() const { |
563 // TODO(oshima): Support IME. | 562 // TODO(oshima): Support IME. |
564 return static_cast<int>(text().length()); | 563 return static_cast<int>(text().length()); |
565 } | 564 } |
566 | 565 |
| 566 void OmniboxViewViews::SetEmphasis(bool emphasize, const gfx::Range& range) { |
| 567 SkColor color = location_bar_view_->GetColor( |
| 568 emphasize ? LocationBarView::TEXT : LocationBarView::DEEMPHASIZED_TEXT); |
| 569 if (range.IsValid()) |
| 570 ApplyColor(color, range); |
| 571 else |
| 572 SetColor(color); |
| 573 } |
| 574 |
| 575 void OmniboxViewViews::UpdateSchemeStyle(const gfx::Range& range) { |
| 576 DCHECK(range.IsValid()); |
| 577 const SkColor security_color = |
| 578 location_bar_view_->GetSecureTextColor(security_level_); |
| 579 const bool strike = security_level_ == security_state::DANGEROUS; |
| 580 ApplyColor(security_color, range); |
| 581 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, range); |
| 582 } |
| 583 |
567 void OmniboxViewViews::EmphasizeURLComponents() { | 584 void OmniboxViewViews::EmphasizeURLComponents() { |
568 if (!location_bar_view_) | 585 if (!location_bar_view_) |
569 return; | 586 return; |
570 | 587 |
571 // If the current contents is a URL, force left-to-right rendering at the | 588 // If the current contents is a URL, force left-to-right rendering at the |
572 // paragraph level. Right-to-left runs are still rendered RTL, but will not | 589 // paragraph level. Right-to-left runs are still rendered RTL, but will not |
573 // flip the whole URL around. For example (if "ABC" is Hebrew), this will | 590 // flip the whole URL around. For example (if "ABC" is Hebrew), this will |
574 // render "ABC.com" as "CBA.com", rather than "com.CBA". | 591 // render "ABC.com" as "CBA.com", rather than "com.CBA". |
575 bool text_is_url = model()->CurrentTextIsURL(); | 592 bool text_is_url = model()->CurrentTextIsURL(); |
576 GetRenderText()->SetDirectionalityMode(text_is_url | 593 GetRenderText()->SetDirectionalityMode(text_is_url |
577 ? gfx::DIRECTIONALITY_FORCE_LTR | 594 ? gfx::DIRECTIONALITY_FORCE_LTR |
578 : gfx::DIRECTIONALITY_FROM_TEXT); | 595 : gfx::DIRECTIONALITY_FROM_TEXT); |
579 | |
580 // See whether the contents are a URL with a non-empty host portion, which we | |
581 // should emphasize. To check for a URL, rather than using the type returned | |
582 // by Parse(), ask the model, which will check the desired page transition for | |
583 // this input. This can tell us whether an UNKNOWN input string is going to | |
584 // be treated as a search or a navigation, and is the same method the Paste | |
585 // And Go system uses. | |
586 url::Component scheme, host; | |
587 AutocompleteInput::ParseForEmphasizeComponents( | |
588 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host); | |
589 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | |
590 base::UTF8ToUTF16(extensions::kExtensionScheme); | |
591 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); | |
592 SetColor(location_bar_view_->GetColor( | |
593 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | |
594 if (grey_base && !grey_out_url) { | |
595 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), | |
596 gfx::Range(host.begin, host.end())); | |
597 } | |
598 | |
599 // Emphasize the scheme for security UI display purposes (if necessary). | |
600 // Note that we check CurrentTextIsURL() because if we're replacing search | |
601 // URLs with search terms, we may have a non-URL even when the user is not | |
602 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | |
603 // may have incorrectly identified a qualifier as a scheme. | |
604 SetStyle(gfx::DIAGONAL_STRIKE, false); | 596 SetStyle(gfx::DIAGONAL_STRIKE, false); |
605 if (!model()->user_input_in_progress() && text_is_url && | 597 UpdateTextStyle(text(), ChromeAutocompleteSchemeClassifier(profile_)); |
606 scheme.is_nonempty() && (security_level_ != security_state::NONE)) { | |
607 SkColor security_color = | |
608 location_bar_view_->GetSecureTextColor(security_level_); | |
609 const bool strike = (security_level_ == security_state::DANGEROUS); | |
610 const gfx::Range scheme_range(scheme.begin, scheme.end()); | |
611 ApplyColor(security_color, scheme_range); | |
612 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | |
613 } | |
614 } | 598 } |
615 | 599 |
616 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { | 600 bool OmniboxViewViews::IsItemForCommandIdDynamic(int command_id) const { |
617 return command_id == IDS_PASTE_AND_GO; | 601 return command_id == IDS_PASTE_AND_GO; |
618 } | 602 } |
619 | 603 |
620 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { | 604 base::string16 OmniboxViewViews::GetLabelForCommandId(int command_id) const { |
621 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); | 605 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); |
622 return l10n_util::GetStringUTF16( | 606 return l10n_util::GetStringUTF16( |
623 model()->IsPasteAndSearch(GetClipboardText()) ? | 607 model()->IsPasteAndSearch(GetClipboardText()) ? |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); | 1049 paste_position + 1, IDS_PASTE_AND_GO, IDS_PASTE_AND_GO); |
1066 | 1050 |
1067 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); | 1051 menu_contents->AddSeparator(ui::NORMAL_SEPARATOR); |
1068 | 1052 |
1069 // Minor note: We use IDC_ for command id here while the underlying textfield | 1053 // Minor note: We use IDC_ for command id here while the underlying textfield |
1070 // is using IDS_ for all its command ids. This is because views cannot depend | 1054 // is using IDS_ for all its command ids. This is because views cannot depend |
1071 // on IDC_ for now. | 1055 // on IDC_ for now. |
1072 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1056 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1073 IDS_EDIT_SEARCH_ENGINES); | 1057 IDS_EDIT_SEARCH_ENGINES); |
1074 } | 1058 } |
OLD | NEW |