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

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

Issue 271013002: Compute minimum widths for the toolbar components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 #if !defined(OS_CHROMEOS) 99 #if !defined(OS_CHROMEOS)
100 #include "chrome/browser/ui/views/first_run_bubble.h" 100 #include "chrome/browser/ui/views/first_run_bubble.h"
101 #endif 101 #endif
102 102
103 using content::WebContents; 103 using content::WebContents;
104 using views::View; 104 using views::View;
105 105
106 namespace { 106 namespace {
107 107
108 // The search button images are made to look as if they overlay the normal edge
109 // images, but to align things, the search button needs to be inset horizontally
110 // by 1 px.
111 const int kSearchButtonInset = 1;
Greg Billock 2014/05/12 23:09:44 Would it make sense to shift the images to include
Peter Kasting 2014/05/13 00:55:33 I think that's reasonable. I'd rather do it separ
112
108 #if !defined(OS_CHROMEOS) 113 #if !defined(OS_CHROMEOS)
109 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { 114 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) {
110 WebContents* web_contents = delegate->GetWebContents(); 115 WebContents* web_contents = delegate->GetWebContents();
111 return web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; 116 return web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL;
112 } 117 }
113 #endif 118 #endif
114 119
115 // Given a containing |height| and a |base_font_list|, shrinks the font size 120 // Given a containing |height| and a |base_font_list|, shrinks the font size
116 // until the font list will fit within |height| while having its cap height 121 // until the font list will fit within |height| while having its cap height
117 // vertically centered. Returns the correctly-sized font list. 122 // vertically centered. Returns the correctly-sized font list.
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 695
691 if (is_popup_mode_) { 696 if (is_popup_mode_) {
692 state->AddStateFlag(ui::AX_STATE_READ_ONLY); 697 state->AddStateFlag(ui::AX_STATE_READ_ONLY);
693 } else { 698 } else {
694 state->set_value_callback = 699 state->set_value_callback =
695 base::Bind(&LocationBarView::AccessibilitySetValue, 700 base::Bind(&LocationBarView::AccessibilitySetValue,
696 weak_ptr_factory_.GetWeakPtr()); 701 weak_ptr_factory_.GetWeakPtr());
697 } 702 }
698 } 703 }
699 704
700 gfx::Size LocationBarView::GetPreferredSize() { 705 gfx::Size LocationBarView::GetPreferredSize() {
Greg Billock 2014/05/12 23:09:44 I was expecting to see this in a new GetMinimumSiz
Peter Kasting 2014/05/13 00:55:33 Yeah, there's no such thing as a "preferred size"
701 gfx::Size background_min_size(border_painter_->GetMinimumSize()); 706 // Compute minimum height.
707 gfx::Size min_size(border_painter_->GetMinimumSize());
702 if (!IsInitialized()) 708 if (!IsInitialized())
703 return background_min_size; 709 return min_size;
710 gfx::Size search_button_min_size(search_button_->GetMinimumSize());
711 min_size.SetToMax(search_button_min_size);
704 712
705 gfx::Size origin_chip_view_min_size(origin_chip_view_->GetMinimumSize()); 713 // Compute width of omnibox-leading content.
706 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); 714 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
707 gfx::Size min_size(background_min_size); 715 int leading_width = horizontal_edge_thickness;
708 min_size.SetToMax(search_button_min_size); 716 if (origin_chip_view_->ShouldShow())
Greg Billock 2014/05/12 23:09:44 This is origin_chip_view_->visible() in the Layout
Peter Kasting 2014/05/13 00:55:33 Layout() sets |origin_chip_view_| to be visible ba
709 min_size.set_width(origin_chip_view_min_size.width() + 717 leading_width += origin_chip_view_->GetMinimumSize().width();
710 background_min_size.width() + 718 if (!omnibox_view_->model()->keyword().empty() &&
711 search_button_min_size.width()); 719 !omnibox_view_->model()->is_keyword_hint()) {
720 // The selected keyword view can collapse completely.
721 } else if (!toolbar_origin_chip_view_ &&
722 !chrome::ShouldDisplayOriginChipV2() &&
723 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) {
724 leading_width += kBubblePadding +
725 ev_bubble_view_->GetMinimumSizeForLabelText(
726 GetToolbarModel()->GetEVCertName()).width();
Greg Billock 2014/05/12 23:09:44 I remember the GetEVCertName being sensitive to in
Peter Kasting 2014/05/13 00:55:33 I don't think I understand what you're referencing
Greg Billock 2014/05/13 16:08:15 I think IsInitialized will do it -- basically I re
Peter Kasting 2014/05/13 20:50:14 I think I recall the problem you're referencing, a
727 } else if (!origin_chip_view_->visible()) {
728 leading_width +=
729 kItemPadding + location_icon_view_->GetMinimumSize().width();
730 }
Greg Billock 2014/05/12 23:09:44 I'm not sure I'd be willing to swear this is all t
Peter Kasting 2014/05/13 00:55:33 Better state accessors for what? I don't know wha
Greg Billock 2014/05/13 16:08:15 Basically a way to collapse these multi-clause con
Peter Kasting 2014/05/13 20:50:14 Ah. Sure, that's reasonable. Done. It's unfortu
731 leading_width += kItemPadding - (base::i18n::IsRTL() ? 1 : 0);
Greg Billock 2014/05/12 23:09:44 Maybe bump kEditLeadingInternalSpace out of Layout
Peter Kasting 2014/05/13 00:55:33 Yeah, that seems like a good idea. Done.
732
733 // Compute width of omnibox-trailing content.
734 int trailing_width = search_button_->visible() ?
735 (search_button_->GetMinimumSize().width() + kSearchButtonInset) :
736 horizontal_edge_thickness;
737 trailing_width += IncrementalMinimumWidth(star_view_) +
Greg Billock 2014/05/12 23:09:44 Should this be delegated to a LocationBarLayout me
Peter Kasting 2014/05/13 00:55:33 That won't help (it will make code strictly longer
738 IncrementalMinimumWidth(translate_icon_view_) +
739 IncrementalMinimumWidth(open_pdf_in_reader_view_) +
740 IncrementalMinimumWidth(manage_passwords_icon_view_) +
741 IncrementalMinimumWidth(zoom_view_) +
742 IncrementalMinimumWidth(generated_credit_card_view_) +
743 IncrementalMinimumWidth(mic_search_view_) + kItemPadding;
744 for (PageActionViews::const_iterator i(page_action_views_.begin());
745 i != page_action_views_.end(); ++i)
746 trailing_width += IncrementalMinimumWidth((*i));
747 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
748 i != content_setting_views_.end(); ++i)
749 trailing_width += IncrementalMinimumWidth((*i));
Greg Billock 2014/05/12 23:09:44 Need the keyword hint view here? Or since that's o
Peter Kasting 2014/05/13 00:55:33 Shouldn't be included since it auto-collapses and
750
751 const int kMinimumOmniboxWidth = 150;
752 min_size.set_width(leading_width + kMinimumOmniboxWidth + trailing_width);
712 return min_size; 753 return min_size;
713 } 754 }
714 755
715 void LocationBarView::Layout() { 756 void LocationBarView::Layout() {
716 if (!IsInitialized()) 757 if (!IsInitialized())
717 return; 758 return;
718 759
719 animated_host_label_->SetVisible(false); 760 animated_host_label_->SetVisible(false);
720 origin_chip_view_->SetVisible(origin_chip_view_->ShouldShow()); 761 origin_chip_view_->SetVisible(origin_chip_view_->ShouldShow());
721 selected_keyword_view_->SetVisible(false); 762 selected_keyword_view_->SetVisible(false);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 location_height, true, 0, kItemPadding, 914 location_height, true, 0, kItemPadding,
874 kItemPadding, keyword_hint_view_); 915 kItemPadding, keyword_hint_view_);
875 if (keyword_hint_view_->keyword() != keyword) 916 if (keyword_hint_view_->keyword() != keyword)
876 keyword_hint_view_->SetKeyword(keyword); 917 keyword_hint_view_->SetKeyword(keyword);
877 } 918 }
878 919
879 // Perform layout. 920 // Perform layout.
880 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); 921 const int horizontal_edge_thickness = GetHorizontalEdgeThickness();
881 int full_width = width() - horizontal_edge_thickness - origin_chip_width; 922 int full_width = width() - horizontal_edge_thickness - origin_chip_width;
882 923
883 // The search button images are made to look as if they overlay the normal
884 // edge images, but to align things, the search button needs to be inset
885 // horizontally by 1 px.
886 const int kSearchButtonInset = 1;
887 const gfx::Size search_button_size(search_button_->GetPreferredSize()); 924 const gfx::Size search_button_size(search_button_->GetPreferredSize());
888 const int search_button_reserved_width = 925 const int search_button_reserved_width =
889 search_button_size.width() + kSearchButtonInset; 926 search_button_size.width() + kSearchButtonInset;
890 full_width -= search_button_->visible() ? 927 full_width -= search_button_->visible() ?
891 search_button_reserved_width : horizontal_edge_thickness; 928 search_button_reserved_width : horizontal_edge_thickness;
892 int entry_width = full_width; 929 int entry_width = full_width;
893 leading_decorations.LayoutPass1(&entry_width); 930 leading_decorations.LayoutPass1(&entry_width);
894 trailing_decorations.LayoutPass1(&entry_width); 931 trailing_decorations.LayoutPass1(&entry_width);
895 leading_decorations.LayoutPass2(&entry_width); 932 leading_decorations.LayoutPass2(&entry_width);
896 trailing_decorations.LayoutPass2(&entry_width); 933 trailing_decorations.LayoutPass2(&entry_width);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 return delegate_->GetToolbarModel(); 1073 return delegate_->GetToolbarModel();
1037 } 1074 }
1038 1075
1039 WebContents* LocationBarView::GetWebContents() { 1076 WebContents* LocationBarView::GetWebContents() {
1040 return delegate_->GetWebContents(); 1077 return delegate_->GetWebContents();
1041 } 1078 }
1042 1079
1043 //////////////////////////////////////////////////////////////////////////////// 1080 ////////////////////////////////////////////////////////////////////////////////
1044 // LocationBarView, private: 1081 // LocationBarView, private:
1045 1082
1083 // static
1084 int LocationBarView::IncrementalMinimumWidth(views::View* view) {
Greg Billock 2014/05/12 23:09:44 MinimumWidthIncludingPadding ?
Peter Kasting 2014/05/13 00:55:33 I would agree if this returned the value unconditi
1085 return view->visible() ? (kItemPadding + view->GetMinimumSize().width()) : 0;
1086 }
1087
1046 int LocationBarView::GetHorizontalEdgeThickness() const { 1088 int LocationBarView::GetHorizontalEdgeThickness() const {
1047 // In maximized popup mode, there isn't any edge. 1089 // In maximized popup mode, there isn't any edge.
1048 return (is_popup_mode_ && browser_ && browser_->window() && 1090 return (is_popup_mode_ && browser_ && browser_->window() &&
1049 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); 1091 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness();
1050 } 1092 }
1051 1093
1052 bool LocationBarView::RefreshContentSettingViews() { 1094 bool LocationBarView::RefreshContentSettingViews() {
1053 bool visibility_changed = false; 1095 bool visibility_changed = false;
1054 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 1096 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
1055 i != content_setting_views_.end(); ++i) { 1097 i != content_setting_views_.end(); ++i) {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 bounds().x()); 1448 bounds().x());
1407 1449
1408 OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view(); 1450 OmniboxPopupView* popup = omnibox_view_->model()->popup_model()->view();
1409 if (popup->IsOpen()) 1451 if (popup->IsOpen())
1410 popup->UpdatePopupAppearance(); 1452 popup->UpdatePopupAppearance();
1411 } 1453 }
1412 1454
1413 void LocationBarView::OnFocus() { 1455 void LocationBarView::OnFocus() {
1414 // Focus the view widget first which implements accessibility for 1456 // Focus the view widget first which implements accessibility for
1415 // Chrome OS. It is noop on Win. This should be removed once 1457 // Chrome OS. It is noop on Win. This should be removed once
1416 // Chrome OS migrates to aura, which uses Views' textfield that receives 1458 // Chrome OS migrates to aura, which uses Views' textfield that receives
Greg Billock 2014/05/13 16:08:15 So we've migrated to Aura now, which is why we can
Peter Kasting 2014/05/13 20:50:14 IIRC, msw is actually removing this in another cha
1417 // focus. See crbug.com/106428. 1459 // focus. See crbug.com/106428.
1418 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, false); 1460 NotifyAccessibilityEvent(ui::AX_EVENT_FOCUS, false);
1419 1461
1420 // Then focus the native location view which implements accessibility for 1462 // Then focus the native location view which implements accessibility for
1421 // Windows. 1463 // Windows.
1422 omnibox_view_->SetFocus(); 1464 omnibox_view_->SetFocus();
1423 } 1465 }
1424 1466
1425 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1467 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1426 View::OnPaint(canvas); 1468 View::OnPaint(canvas);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1694 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1653 const SearchModel::State& new_state) { 1695 const SearchModel::State& new_state) {
1654 const bool visible = !GetToolbarModel()->input_in_progress() && 1696 const bool visible = !GetToolbarModel()->input_in_progress() &&
1655 new_state.voice_search_supported; 1697 new_state.voice_search_supported;
1656 if (mic_search_view_->visible() != visible) { 1698 if (mic_search_view_->visible() != visible) {
1657 mic_search_view_->SetVisible(visible); 1699 mic_search_view_->SetVisible(visible);
1658 Layout(); 1700 Layout();
1659 } 1701 }
1660 } 1702 }
1661 1703
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698