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

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

Issue 2070133004: Adjust omnibox and dropdown text position to be correct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #endif 98 #endif
99 99
100 using content::WebContents; 100 using content::WebContents;
101 using views::View; 101 using views::View;
102 102
103 namespace { 103 namespace {
104 104
105 // The border color for MD windows, as well as non-MD popup windows. 105 // The border color for MD windows, as well as non-MD popup windows.
106 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D); 106 const SkColor kBorderColor = SkColorSetA(SK_ColorBLACK, 0x4D);
107 107
108 int GetEditLeadingInternalSpace() {
109 // The textfield has 1 px of whitespace before the text.
110 if (ui::MaterialDesignController::IsModeMaterial())
111 return 1;
112
113 // For legacy reasons, we only apply this in the RTL case in pre-MD.
114 return base::i18n::IsRTL() ? 1 : 0;
115 }
116
117 } // namespace 108 } // namespace
118 109
119 110
120 // LocationBarView ----------------------------------------------------------- 111 // LocationBarView -----------------------------------------------------------
121 112
122 // static 113 // static
123 const char LocationBarView::kViewClassName[] = "LocationBarView"; 114 const char LocationBarView::kViewClassName[] = "LocationBarView";
124 115
125 LocationBarView::LocationBarView(Browser* browser, 116 LocationBarView::LocationBarView(Browser* browser,
126 Profile* profile, 117 Profile* profile,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 star_view_->SetToggled(on); 413 star_view_->SetToggled(on);
423 } 414 }
424 415
425 gfx::Point LocationBarView::GetOmniboxViewOrigin() const { 416 gfx::Point LocationBarView::GetOmniboxViewOrigin() const {
426 gfx::Point origin(omnibox_view_->bounds().origin()); 417 gfx::Point origin(omnibox_view_->bounds().origin());
427 origin.set_x(GetMirroredXInView(origin.x())); 418 origin.set_x(GetMirroredXInView(origin.x()));
428 views::View::ConvertPointToScreen(this, &origin); 419 views::View::ConvertPointToScreen(this, &origin);
429 return origin; 420 return origin;
430 } 421 }
431 422
423 int LocationBarView::GetLocationIconWidth() const {
424 if (ui::MaterialDesignController::IsModeMaterial()) {
425 constexpr int kVectorIconSize = 16;
426 return kVectorIconSize;
427 }
428 return GetThemeProvider()->GetImageSkiaNamed(
429 AutocompleteMatch::TypeToIcon(
430 AutocompleteMatchType::URL_WHAT_YOU_TYPED))->width();
431 }
432
432 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) { 433 void LocationBarView::SetImeInlineAutocompletion(const base::string16& text) {
433 ime_inline_autocomplete_view_->SetText(text); 434 ime_inline_autocomplete_view_->SetText(text);
434 ime_inline_autocomplete_view_->SetVisible(!text.empty()); 435 ime_inline_autocomplete_view_->SetVisible(!text.empty());
435 } 436 }
436 437
437 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) { 438 void LocationBarView::SetGrayTextAutocompletion(const base::string16& text) {
438 if (suggested_text_view_->text() != text) { 439 if (suggested_text_view_->text() != text) {
439 suggested_text_view_->SetText(text); 440 suggested_text_view_->SetText(text);
440 suggested_text_view_->SetVisible(!text.empty()); 441 suggested_text_view_->SetVisible(!text.empty());
441 Layout(); 442 Layout();
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 void LocationBarView::Layout() { 564 void LocationBarView::Layout() {
564 if (!IsInitialized()) 565 if (!IsInitialized())
565 return; 566 return;
566 567
567 selected_keyword_view_->SetVisible(false); 568 selected_keyword_view_->SetVisible(false);
568 location_icon_view_->SetVisible(false); 569 location_icon_view_->SetVisible(false);
569 keyword_hint_view_->SetVisible(false); 570 keyword_hint_view_->SetVisible(false);
570 571
571 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING); 572 const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
572 const int edge_thickness = GetHorizontalEdgeThickness(); 573 const int edge_thickness = GetHorizontalEdgeThickness();
573 int trailing_edge_item_padding = 0;
574 if (!ui::MaterialDesignController::IsModeMaterial()) {
575 trailing_edge_item_padding =
576 item_padding - edge_thickness - omnibox_view_->GetInsets().right();
577 }
578 574
579 LocationBarLayout leading_decorations( 575 LocationBarLayout leading_decorations(
580 LocationBarLayout::LEFT_EDGE, item_padding, 576 LocationBarLayout::LEFT_EDGE, item_padding,
581 item_padding - omnibox_view_->GetInsets().left() - 577 item_padding - omnibox_view_->GetInsets().left());
582 GetEditLeadingInternalSpace());
583 LocationBarLayout trailing_decorations( 578 LocationBarLayout trailing_decorations(
584 LocationBarLayout::RIGHT_EDGE, item_padding, trailing_edge_item_padding); 579 LocationBarLayout::RIGHT_EDGE, item_padding,
580 item_padding - omnibox_view_->GetInsets().right());
585 581
586 const base::string16 keyword(omnibox_view_->model()->keyword()); 582 const base::string16 keyword(omnibox_view_->model()->keyword());
587 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want 583 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want
588 // to position our child views in this case, because other things may be 584 // to position our child views in this case, because other things may be
589 // positioned relative to them (e.g. the "bookmark added" bubble if the user 585 // positioned relative to them (e.g. the "bookmark added" bubble if the user
590 // hits ctrl-d). 586 // hits ctrl-d).
591 const int bubble_horizontal_padding = 587 const int bubble_horizontal_padding =
592 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING); 588 GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING);
593 const int vertical_padding = GetVerticalEdgeThicknessWithPadding(); 589 const int vertical_padding = GetVerticalEdgeThicknessWithPadding();
594 const int location_height = std::max(height() - (vertical_padding * 2), 0); 590 const int location_height = std::max(height() - (vertical_padding * 2), 0);
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING); 852 GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
857 } 853 }
858 854
859 void LocationBarView::RefreshLocationIcon() { 855 void LocationBarView::RefreshLocationIcon() {
860 // |omnibox_view_| may not be ready yet if Init() has not been called. The 856 // |omnibox_view_| may not be ready yet if Init() has not been called. The
861 // icon will be set soon by OnChanged(). 857 // icon will be set soon by OnChanged().
862 if (!omnibox_view_) 858 if (!omnibox_view_)
863 return; 859 return;
864 860
865 if (ui::MaterialDesignController::IsModeMaterial()) { 861 if (ui::MaterialDesignController::IsModeMaterial()) {
866 const int kIconSize = 16;
867 security_state::SecurityStateModel::SecurityLevel security_level = 862 security_state::SecurityStateModel::SecurityLevel security_level =
868 GetToolbarModel()->GetSecurityLevel(false); 863 GetToolbarModel()->GetSecurityLevel(false);
869 SkColor icon_color = 864 SkColor icon_color =
870 (security_level == security_state::SecurityStateModel::NONE) 865 (security_level == security_state::SecurityStateModel::NONE)
871 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) 866 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT))
872 : GetSecureTextColor(security_level); 867 : GetSecureTextColor(security_level);
873 location_icon_view_->SetImage(gfx::CreateVectorIcon( 868 location_icon_view_->SetImage(gfx::CreateVectorIcon(
874 omnibox_view_->GetVectorIcon(), kIconSize, icon_color)); 869 omnibox_view_->GetVectorIcon(), GetLocationIconWidth(), icon_color));
875 } else { 870 } else {
876 location_icon_view_->SetImage( 871 location_icon_view_->SetImage(
877 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); 872 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon()));
878 } 873 }
879 } 874 }
880 875
881 bool LocationBarView::RefreshContentSettingViews() { 876 bool LocationBarView::RefreshContentSettingViews() {
882 bool visibility_changed = false; 877 bool visibility_changed = false;
883 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 878 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
884 i != content_setting_views_.end(); ++i) { 879 i != content_setting_views_.end(); ++i) {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 // LocationBarView, private TemplateURLServiceObserver implementation: 1384 // LocationBarView, private TemplateURLServiceObserver implementation:
1390 1385
1391 void LocationBarView::OnTemplateURLServiceChanged() { 1386 void LocationBarView::OnTemplateURLServiceChanged() {
1392 template_url_service_->RemoveObserver(this); 1387 template_url_service_->RemoveObserver(this);
1393 template_url_service_ = nullptr; 1388 template_url_service_ = nullptr;
1394 // If the browser is no longer active, let's not show the info bubble, as this 1389 // If the browser is no longer active, let's not show the info bubble, as this
1395 // would make the browser the active window again. 1390 // would make the browser the active window again.
1396 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) 1391 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive())
1397 ShowFirstRunBubble(); 1392 ShowFirstRunBubble();
1398 } 1393 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_result_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698