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

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 2510373003: Cleanup: Remove "gray text" logic from Omnibox (Closed)
Patch Set: review2 Created 4 years 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/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 Delegate* delegate, 122 Delegate* delegate,
123 bool is_popup_mode) 123 bool is_popup_mode)
124 : LocationBar(profile), 124 : LocationBar(profile),
125 ChromeOmniboxEditController(command_updater), 125 ChromeOmniboxEditController(command_updater),
126 browser_(browser), 126 browser_(browser),
127 omnibox_view_(nullptr), 127 omnibox_view_(nullptr),
128 delegate_(delegate), 128 delegate_(delegate),
129 location_icon_view_(nullptr), 129 location_icon_view_(nullptr),
130 ime_inline_autocomplete_view_(nullptr), 130 ime_inline_autocomplete_view_(nullptr),
131 selected_keyword_view_(nullptr), 131 selected_keyword_view_(nullptr),
132 suggested_text_view_(nullptr),
133 keyword_hint_view_(nullptr), 132 keyword_hint_view_(nullptr),
134 zoom_view_(nullptr), 133 zoom_view_(nullptr),
135 open_pdf_in_reader_view_(nullptr), 134 open_pdf_in_reader_view_(nullptr),
136 manage_passwords_icon_view_(nullptr), 135 manage_passwords_icon_view_(nullptr),
137 save_credit_card_icon_view_(nullptr), 136 save_credit_card_icon_view_(nullptr),
138 translate_icon_view_(nullptr), 137 translate_icon_view_(nullptr),
139 star_view_(nullptr), 138 star_view_(nullptr),
140 size_animation_(this), 139 size_animation_(this),
141 is_popup_mode_(is_popup_mode), 140 is_popup_mode_(is_popup_mode),
142 show_focus_rect_(false), 141 show_focus_rect_(false),
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 260 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
262 ime_inline_autocomplete_view_->SetEnabledColor( 261 ime_inline_autocomplete_view_->SetEnabledColor(
263 GetNativeTheme()->GetSystemColor( 262 GetNativeTheme()->GetSystemColor(
264 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 263 ui::NativeTheme::kColorId_TextfieldSelectionColor));
265 ime_inline_autocomplete_view_->SetVisible(false); 264 ime_inline_autocomplete_view_->SetVisible(false);
266 AddChildView(ime_inline_autocomplete_view_); 265 AddChildView(ime_inline_autocomplete_view_);
267 266
268 selected_keyword_view_ = new SelectedKeywordView(font_list, profile()); 267 selected_keyword_view_ = new SelectedKeywordView(font_list, profile());
269 AddChildView(selected_keyword_view_); 268 AddChildView(selected_keyword_view_);
270 269
271 suggested_text_view_ = new views::Label(base::string16(), font_list);
272 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
273 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
274 suggested_text_view_->SetEnabledColor(
275 GetColor(LocationBarView::DEEMPHASIZED_TEXT));
276 suggested_text_view_->SetVisible(false);
277 AddChildView(suggested_text_view_);
278
279 gfx::FontList bubble_font_list = 270 gfx::FontList bubble_font_list =
280 font_list.DeriveWithHeightUpperBound(bubble_height); 271 font_list.DeriveWithHeightUpperBound(bubble_height);
281 keyword_hint_view_ = new KeywordHintView( 272 keyword_hint_view_ = new KeywordHintView(
282 profile(), font_list, bubble_font_list, location_height, 273 profile(), font_list, bubble_font_list, location_height,
283 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color); 274 GetColor(LocationBarView::DEEMPHASIZED_TEXT), background_color);
284 AddChildView(keyword_hint_view_); 275 AddChildView(keyword_hint_view_);
285 276
286 ScopedVector<ContentSettingImageModel> models = 277 ScopedVector<ContentSettingImageModel> models =
287 ContentSettingImageModel::GenerateContentSettingImageModels(); 278 ContentSettingImageModel::GenerateContentSettingImageModels();
288 for (ContentSettingImageModel* model : models.get()) { 279 for (ContentSettingImageModel* model : models.get()) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 origin.set_x(GetMirroredXInView(origin.x())); 416 origin.set_x(GetMirroredXInView(origin.x()));
426 views::View::ConvertPointToScreen(this, &origin); 417 views::View::ConvertPointToScreen(this, &origin);
427 return origin; 418 return origin;
428 } 419 }
429 420
430 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { 421 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
431 ime_inline_autocomplete_view_->SetText(text); 422 ime_inline_autocomplete_view_->SetText(text);
432 ime_inline_autocomplete_view_->SetVisible(!text.empty()); 423 ime_inline_autocomplete_view_->SetVisible(!text.empty());
433 } 424 }
434 425
435 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) {
436 if (suggested_text_view_->text() != text) {
437 suggested_text_view_->SetText(text);
438 suggested_text_view_->SetVisible(!text.empty());
439 Layout();
440 SchedulePaint();
441 }
442 }
443
444 base::string16 LocationBarView::GetGrayTextAutocompletion() const {
445 return HasValidSuggestText() ?
446 suggested_text_view_->text() : base::string16();
447 }
448
449 void LocationBarView::SetShowFocusRect(bool show) { 426 void LocationBarView::SetShowFocusRect(bool show) {
450 show_focus_rect_ = show; 427 show_focus_rect_ = show;
451 SchedulePaint(); 428 SchedulePaint();
452 } 429 }
453 430
454 void LocationBarView::SelectAll() { 431 void LocationBarView::SelectAll() {
455 omnibox_view_->SelectAll(true); 432 omnibox_view_->SelectAll(true);
456 } 433 }
457 434
458 gfx::Point LocationBarView::GetLocationBarAnchorPoint() const { 435 gfx::Point LocationBarView::GetLocationBarAnchorPoint() const {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 645
669 int location_needed_width = omnibox_view_->GetTextWidth(); 646 int location_needed_width = omnibox_view_->GetTextWidth();
670 int available_width = entry_width - location_needed_width; 647 int available_width = entry_width - location_needed_width;
671 // The bounds must be wide enough for all the decorations to fit. 648 // The bounds must be wide enough for all the decorations to fit.
672 gfx::Rect location_bounds(edge_thickness, vertical_padding, 649 gfx::Rect location_bounds(edge_thickness, vertical_padding,
673 std::max(full_width, full_width - entry_width), 650 std::max(full_width, full_width - entry_width),
674 location_height); 651 location_height);
675 leading_decorations.LayoutPass3(&location_bounds, &available_width); 652 leading_decorations.LayoutPass3(&location_bounds, &available_width);
676 trailing_decorations.LayoutPass3(&location_bounds, &available_width); 653 trailing_decorations.LayoutPass3(&location_bounds, &available_width);
677 654
678 // Lay out the suggested text view right-aligned to the location entry. Only
679 // show the suggested text if we can fit the text from one character before
680 // the end of the selection to the end of the text and the suggested text. If
681 // we can't it means either the suggested text is too big, or the user has
682 // scrolled.
683
684 // TODO(sky): We could potentially adjust this to take into account suggested
685 // text to force using minimum size if necessary, but currently the chance of
686 // showing keyword hints and suggested text is minimal and we're not confident
687 // this is the right approach for suggested text.
688
689 int omnibox_view_margin = 0;
690 if (suggested_text_view_->visible()) {
691 // We do not display the suggested text when it contains a mix of RTL and
692 // LTR characters since this could mean the suggestion should be displayed
693 // in the middle of the string.
694 base::i18n::TextDirection text_direction =
695 base::i18n::GetStringDirection(omnibox_view_->GetText());
696 if (text_direction !=
697 base::i18n::GetStringDirection(suggested_text_view_->text()))
698 text_direction = base::i18n::UNKNOWN_DIRECTION;
699
700 // TODO(sky): need to layout when the user changes caret position.
701 gfx::Size suggested_text_size(suggested_text_view_->GetPreferredSize());
702 if (suggested_text_size.width() > available_width ||
703 text_direction == base::i18n::UNKNOWN_DIRECTION) {
704 // Hide the suggested text if the user has scrolled or we can't fit all
705 // the suggested text, or we have a mix of RTL and LTR characters.
706 suggested_text_view_->SetBounds(0, 0, 0, 0);
707 } else {
708 location_needed_width =
709 std::min(location_needed_width,
710 location_bounds.width() - suggested_text_size.width());
711 gfx::Rect suggested_text_bounds(location_bounds.x(), location_bounds.y(),
712 suggested_text_size.width(),
713 location_bounds.height());
714 // TODO(sky): figure out why this needs the -1.
715 suggested_text_bounds.Offset(location_needed_width - 1, 0);
716
717 // We reverse the order of the location entry and suggested text if:
718 // - Chrome is RTL but the text is fully LTR, or
719 // - Chrome is LTR but the text is fully RTL.
720 // This ensures the suggested text is correctly displayed to the right
721 // (or left) of the user text.
722 if (text_direction == (base::i18n::IsRTL() ?
723 base::i18n::LEFT_TO_RIGHT : base::i18n::RIGHT_TO_LEFT)) {
724 // TODO(sky): Figure out why we need the +1.
725 suggested_text_bounds.set_x(location_bounds.x() + 1);
726 // Use a margin to prevent omnibox text from overlapping suggest text.
727 omnibox_view_margin = suggested_text_bounds.width();
728 }
729 suggested_text_view_->SetBoundsRect(suggested_text_bounds);
730 }
731 }
732
733 omnibox_view_->SetBorder(
734 views::CreateEmptyBorder(0, 0, 0, omnibox_view_margin));
735
736 // Layout |ime_inline_autocomplete_view_| next to the user input. 655 // Layout |ime_inline_autocomplete_view_| next to the user input.
737 if (ime_inline_autocomplete_view_->visible()) { 656 if (ime_inline_autocomplete_view_->visible()) {
738 int width = 657 int width =
739 gfx::GetStringWidth(ime_inline_autocomplete_view_->text(), 658 gfx::GetStringWidth(ime_inline_autocomplete_view_->text(),
740 ime_inline_autocomplete_view_->font_list()) + 659 ime_inline_autocomplete_view_->font_list()) +
741 ime_inline_autocomplete_view_->GetInsets().width(); 660 ime_inline_autocomplete_view_->GetInsets().width();
742 // All the target languages (IMEs) are LTR, and we do not need to support 661 // All the target languages (IMEs) are LTR, and we do not need to support
743 // RTL so far. In other words, no testable RTL environment so far. 662 // RTL so far. In other words, no testable RTL environment so far.
744 int x = location_needed_width; 663 int x = location_needed_width;
745 if (width > entry_width) 664 if (width > entry_width)
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 #if !defined(OS_CHROMEOS) 910 #if !defined(OS_CHROMEOS)
992 WebContents* web_contents = delegate_->GetWebContents(); 911 WebContents* web_contents = delegate_->GetWebContents();
993 if (!web_contents) 912 if (!web_contents)
994 return; 913 return;
995 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 914 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
996 if (browser) 915 if (browser)
997 FirstRunBubble::ShowBubble(browser, location_icon_view_); 916 FirstRunBubble::ShowBubble(browser, location_icon_view_);
998 #endif 917 #endif
999 } 918 }
1000 919
1001 bool LocationBarView::HasValidSuggestText() const {
1002 return suggested_text_view_->visible() &&
1003 !suggested_text_view_->size().IsEmpty();
1004 }
1005
1006 base::string16 LocationBarView::GetSecurityText() const { 920 base::string16 LocationBarView::GetSecurityText() const {
1007 bool has_ev_cert = 921 bool has_ev_cert =
1008 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE); 922 (GetToolbarModel()->GetSecurityLevel(false) == security_state::EV_SECURE);
1009 return has_ev_cert ? GetToolbarModel()->GetEVCertName() 923 return has_ev_cert ? GetToolbarModel()->GetEVCertName()
1010 : GetToolbarModel()->GetSecureVerboseText(); 924 : GetToolbarModel()->GetSecureVerboseText();
1011 } 925 }
1012 926
1013 bool LocationBarView::ShouldShowKeywordBubble() const { 927 bool LocationBarView::ShouldShowKeywordBubble() const {
1014 return !omnibox_view_->model()->keyword().empty() && 928 return !omnibox_view_->model()->keyword().empty() &&
1015 !omnibox_view_->model()->is_keyword_hint(); 929 !omnibox_view_->model()->is_keyword_hint();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 // LocationBarView, private TemplateURLServiceObserver implementation: 1262 // LocationBarView, private TemplateURLServiceObserver implementation:
1349 1263
1350 void LocationBarView::OnTemplateURLServiceChanged() { 1264 void LocationBarView::OnTemplateURLServiceChanged() {
1351 template_url_service_->RemoveObserver(this); 1265 template_url_service_->RemoveObserver(this);
1352 template_url_service_ = nullptr; 1266 template_url_service_ = nullptr;
1353 // If the browser is no longer active, let's not show the info bubble, as this 1267 // If the browser is no longer active, let's not show the info bubble, as this
1354 // would make the browser the active window again. 1268 // would make the browser the active window again.
1355 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1269 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1356 ShowFirstRunBubble(); 1270 ShowFirstRunBubble();
1357 } 1271 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698