| 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/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 Loading... |
| 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 #if !defined(OS_CHROMEOS) | 108 // The search button images are made to look as if they overlay the normal edge |
| 109 Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { | 109 // images, but to align things, the search button needs to be inset horizontally |
| 110 WebContents* web_contents = delegate->GetWebContents(); | 110 // by 1 px. |
| 111 return web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; | 111 const int kSearchButtonInset = 1; |
| 112 } | |
| 113 #endif | |
| 114 | 112 |
| 115 // Given a containing |height| and a |base_font_list|, shrinks the font size | 113 // 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 | 114 // until the font list will fit within |height| while having its cap height |
| 117 // vertically centered. Returns the correctly-sized font list. | 115 // vertically centered. Returns the correctly-sized font list. |
| 118 // | 116 // |
| 119 // The expected layout: | 117 // The expected layout: |
| 120 // +--------+-----------------------------------------------+------------+ | 118 // +--------+-----------------------------------------------+------------+ |
| 121 // | | y offset | space | | 119 // | | y offset | space | |
| 122 // | +--------+-------------------+------------------+ above | | 120 // | +--------+-------------------+------------------+ above | |
| 123 // | | | | internal leading | cap height | | 121 // | | | | internal leading | cap height | |
| (...skipping 27 matching lines...) Expand all Loading... |
| 151 font_list.GetCapHeight() : font_list.GetHeight()); | 149 font_list.GetCapHeight() : font_list.GetHeight()); |
| 152 const int y_offset = space / 2 - internal_leading; | 150 const int y_offset = space / 2 - internal_leading; |
| 153 const int space_at_bottom = height - (y_offset + font_list.GetHeight()); | 151 const int space_at_bottom = height - (y_offset + font_list.GetHeight()); |
| 154 if ((y_offset >= 0) && (space_at_bottom >= 0)) | 152 if ((y_offset >= 0) && (space_at_bottom >= 0)) |
| 155 break; | 153 break; |
| 156 font_list = font_list.DeriveWithSizeDelta(-1); | 154 font_list = font_list.DeriveWithSizeDelta(-1); |
| 157 } | 155 } |
| 158 return font_list; | 156 return font_list; |
| 159 } | 157 } |
| 160 | 158 |
| 159 int GetEditLeadingInternalSpace() { |
| 160 // The textfield has 1 px of whitespace before the text in the RTL case only. |
| 161 return base::i18n::IsRTL() ? 1 : 0; |
| 162 } |
| 163 |
| 161 // Functor for moving BookmarkManagerPrivate page actions to the right via | 164 // Functor for moving BookmarkManagerPrivate page actions to the right via |
| 162 // stable_partition. | 165 // stable_partition. |
| 163 class IsPageActionViewRightAligned { | 166 class IsPageActionViewRightAligned { |
| 164 public: | 167 public: |
| 165 explicit IsPageActionViewRightAligned(ExtensionService* extension_service) | 168 explicit IsPageActionViewRightAligned(ExtensionService* extension_service) |
| 166 : extension_service_(extension_service) {} | 169 : extension_service_(extension_service) {} |
| 167 | 170 |
| 168 bool operator()(PageActionWithBadgeView* page_action_view) { | 171 bool operator()(PageActionWithBadgeView* page_action_view) { |
| 169 return extensions::PermissionsData::HasAPIPermission( | 172 return extensions::PermissionsData::HasAPIPermission( |
| 170 extension_service_->GetExtensionById( | 173 extension_service_->GetExtensionById( |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 if (is_popup_mode_) { | 694 if (is_popup_mode_) { |
| 692 state->AddStateFlag(ui::AX_STATE_READ_ONLY); | 695 state->AddStateFlag(ui::AX_STATE_READ_ONLY); |
| 693 } else { | 696 } else { |
| 694 state->set_value_callback = | 697 state->set_value_callback = |
| 695 base::Bind(&LocationBarView::AccessibilitySetValue, | 698 base::Bind(&LocationBarView::AccessibilitySetValue, |
| 696 weak_ptr_factory_.GetWeakPtr()); | 699 weak_ptr_factory_.GetWeakPtr()); |
| 697 } | 700 } |
| 698 } | 701 } |
| 699 | 702 |
| 700 gfx::Size LocationBarView::GetPreferredSize() { | 703 gfx::Size LocationBarView::GetPreferredSize() { |
| 701 gfx::Size background_min_size(border_painter_->GetMinimumSize()); | 704 // Compute minimum height. |
| 705 gfx::Size min_size(border_painter_->GetMinimumSize()); |
| 702 if (!IsInitialized()) | 706 if (!IsInitialized()) |
| 703 return background_min_size; | 707 return min_size; |
| 708 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); |
| 709 min_size.SetToMax(search_button_min_size); |
| 704 | 710 |
| 705 gfx::Size origin_chip_view_min_size(origin_chip_view_->GetMinimumSize()); | 711 // Compute width of omnibox-leading content. |
| 706 gfx::Size search_button_min_size(search_button_->GetMinimumSize()); | 712 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
| 707 gfx::Size min_size(background_min_size); | 713 int leading_width = horizontal_edge_thickness; |
| 708 min_size.SetToMax(search_button_min_size); | 714 if (origin_chip_view_->ShouldShow()) |
| 709 min_size.set_width(origin_chip_view_min_size.width() + | 715 leading_width += origin_chip_view_->GetMinimumSize().width(); |
| 710 background_min_size.width() + | 716 if (!omnibox_view_->model()->keyword().empty() && |
| 711 search_button_min_size.width()); | 717 !omnibox_view_->model()->is_keyword_hint()) { |
| 718 // The selected keyword view can collapse completely. |
| 719 } else if (!toolbar_origin_chip_view_ && |
| 720 !chrome::ShouldDisplayOriginChipV2() && |
| 721 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) { |
| 722 leading_width += kBubblePadding + |
| 723 ev_bubble_view_->GetMinimumSizeForLabelText( |
| 724 GetToolbarModel()->GetEVCertName()).width(); |
| 725 } else if (!origin_chip_view_->visible()) { |
| 726 leading_width += |
| 727 kItemPadding + location_icon_view_->GetMinimumSize().width(); |
| 728 } |
| 729 leading_width += kItemPadding - GetEditLeadingInternalSpace(); |
| 730 |
| 731 // Compute width of omnibox-trailing content. |
| 732 int trailing_width = search_button_->visible() ? |
| 733 (search_button_->GetMinimumSize().width() + kSearchButtonInset) : |
| 734 horizontal_edge_thickness; |
| 735 trailing_width += MinimumWidth(star_view_) + |
| 736 IncrementalMinimumWidth(translate_icon_view_) + |
| 737 IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
| 738 IncrementalMinimumWidth(manage_passwords_icon_view_) + |
| 739 IncrementalMinimumWidth(zoom_view_) + |
| 740 IncrementalMinimumWidth(generated_credit_card_view_) + |
| 741 IncrementalMinimumWidth(mic_search_view_) + kItemPadding; |
| 742 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
| 743 i != page_action_views_.end(); ++i) |
| 744 trailing_width += IncrementalMinimumWidth((*i)); |
| 745 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 746 i != content_setting_views_.end(); ++i) |
| 747 trailing_width += IncrementalMinimumWidth((*i)); |
| 748 |
| 749 min_size.set_width( |
| 750 leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); |
| 712 return min_size; | 751 return min_size; |
| 713 } | 752 } |
| 714 | 753 |
| 715 void LocationBarView::Layout() { | 754 void LocationBarView::Layout() { |
| 716 if (!IsInitialized()) | 755 if (!IsInitialized()) |
| 717 return; | 756 return; |
| 718 | 757 |
| 719 animated_host_label_->SetVisible(false); | 758 animated_host_label_->SetVisible(false); |
| 720 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); | 759 origin_chip_view_->SetVisible(GetToolbarModel()->ShouldShowOriginChip()); |
| 721 selected_keyword_view_->SetVisible(false); | 760 selected_keyword_view_->SetVisible(false); |
| 722 location_icon_view_->SetVisible(false); | 761 location_icon_view_->SetVisible(false); |
| 723 ev_bubble_view_->SetVisible(false); | 762 ev_bubble_view_->SetVisible(false); |
| 724 keyword_hint_view_->SetVisible(false); | 763 keyword_hint_view_->SetVisible(false); |
| 725 | 764 |
| 726 // The textfield has 1 px of whitespace before the text in the RTL case only. | |
| 727 const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0; | |
| 728 LocationBarLayout leading_decorations( | 765 LocationBarLayout leading_decorations( |
| 729 LocationBarLayout::LEFT_EDGE, kItemPadding - kEditLeadingInternalSpace); | 766 LocationBarLayout::LEFT_EDGE, |
| 767 kItemPadding - GetEditLeadingInternalSpace()); |
| 730 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, | 768 LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, |
| 731 kItemPadding); | 769 kItemPadding); |
| 732 | 770 |
| 733 // Show and position the animated host label used in the show and hide URL | 771 // Show and position the animated host label used in the show and hide URL |
| 734 // animations. | 772 // animations. |
| 735 if (show_url_animation_->is_animating() || | 773 if (show_url_animation_->is_animating() || |
| 736 hide_url_animation_->is_animating()) { | 774 hide_url_animation_->is_animating()) { |
| 737 WebContents* web_contents = GetWebContents(); | 775 WebContents* web_contents = GetWebContents(); |
| 738 const GURL url = web_contents ? web_contents->GetURL() : GURL(); | 776 const GURL url = web_contents ? web_contents->GetURL() : GURL(); |
| 739 const base::string16 host = | 777 const base::string16 host = |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 location_height, true, 0, kItemPadding, | 911 location_height, true, 0, kItemPadding, |
| 874 kItemPadding, keyword_hint_view_); | 912 kItemPadding, keyword_hint_view_); |
| 875 if (keyword_hint_view_->keyword() != keyword) | 913 if (keyword_hint_view_->keyword() != keyword) |
| 876 keyword_hint_view_->SetKeyword(keyword); | 914 keyword_hint_view_->SetKeyword(keyword); |
| 877 } | 915 } |
| 878 | 916 |
| 879 // Perform layout. | 917 // Perform layout. |
| 880 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); | 918 const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
| 881 int full_width = width() - horizontal_edge_thickness - origin_chip_width; | 919 int full_width = width() - horizontal_edge_thickness - origin_chip_width; |
| 882 | 920 |
| 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()); | 921 const gfx::Size search_button_size(search_button_->GetPreferredSize()); |
| 888 const int search_button_reserved_width = | 922 const int search_button_reserved_width = |
| 889 search_button_size.width() + kSearchButtonInset; | 923 search_button_size.width() + kSearchButtonInset; |
| 890 full_width -= search_button_->visible() ? | 924 full_width -= search_button_->visible() ? |
| 891 search_button_reserved_width : horizontal_edge_thickness; | 925 search_button_reserved_width : horizontal_edge_thickness; |
| 892 int entry_width = full_width; | 926 int entry_width = full_width; |
| 893 leading_decorations.LayoutPass1(&entry_width); | 927 leading_decorations.LayoutPass1(&entry_width); |
| 894 trailing_decorations.LayoutPass1(&entry_width); | 928 trailing_decorations.LayoutPass1(&entry_width); |
| 895 leading_decorations.LayoutPass2(&entry_width); | 929 leading_decorations.LayoutPass2(&entry_width); |
| 896 trailing_decorations.LayoutPass2(&entry_width); | 930 trailing_decorations.LayoutPass2(&entry_width); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 return delegate_->GetToolbarModel(); | 1070 return delegate_->GetToolbarModel(); |
| 1037 } | 1071 } |
| 1038 | 1072 |
| 1039 WebContents* LocationBarView::GetWebContents() { | 1073 WebContents* LocationBarView::GetWebContents() { |
| 1040 return delegate_->GetWebContents(); | 1074 return delegate_->GetWebContents(); |
| 1041 } | 1075 } |
| 1042 | 1076 |
| 1043 //////////////////////////////////////////////////////////////////////////////// | 1077 //////////////////////////////////////////////////////////////////////////////// |
| 1044 // LocationBarView, private: | 1078 // LocationBarView, private: |
| 1045 | 1079 |
| 1080 // static |
| 1081 int LocationBarView::IncrementalMinimumWidth(views::View* view) { |
| 1082 return view->visible() ? (kItemPadding + view->GetMinimumSize().width()) : 0; |
| 1083 } |
| 1084 |
| 1046 int LocationBarView::GetHorizontalEdgeThickness() const { | 1085 int LocationBarView::GetHorizontalEdgeThickness() const { |
| 1047 // In maximized popup mode, there isn't any edge. | 1086 // In maximized popup mode, there isn't any edge. |
| 1048 return (is_popup_mode_ && browser_ && browser_->window() && | 1087 return (is_popup_mode_ && browser_ && browser_->window() && |
| 1049 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); | 1088 browser_->window()->IsMaximized()) ? 0 : vertical_edge_thickness(); |
| 1050 } | 1089 } |
| 1051 | 1090 |
| 1052 bool LocationBarView::RefreshContentSettingViews() { | 1091 bool LocationBarView::RefreshContentSettingViews() { |
| 1053 bool visibility_changed = false; | 1092 bool visibility_changed = false; |
| 1054 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 1093 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
| 1055 i != content_setting_views_.end(); ++i) { | 1094 i != content_setting_views_.end(); ++i) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 WebContents* web_contents = GetWebContents(); | 1224 WebContents* web_contents = GetWebContents(); |
| 1186 if (!web_contents) | 1225 if (!web_contents) |
| 1187 return false; | 1226 return false; |
| 1188 const bool was_visible = manage_passwords_icon_view_->visible(); | 1227 const bool was_visible = manage_passwords_icon_view_->visible(); |
| 1189 ManagePasswordsUIController::FromWebContents( | 1228 ManagePasswordsUIController::FromWebContents( |
| 1190 web_contents)->UpdateIconAndBubbleState(manage_passwords_icon_view_); | 1229 web_contents)->UpdateIconAndBubbleState(manage_passwords_icon_view_); |
| 1191 return was_visible != manage_passwords_icon_view_->visible(); | 1230 return was_visible != manage_passwords_icon_view_->visible(); |
| 1192 } | 1231 } |
| 1193 | 1232 |
| 1194 void LocationBarView::ShowFirstRunBubbleInternal() { | 1233 void LocationBarView::ShowFirstRunBubbleInternal() { |
| 1234 // First run bubble doesn't make sense for Chrome OS. |
| 1195 #if !defined(OS_CHROMEOS) | 1235 #if !defined(OS_CHROMEOS) |
| 1196 // First run bubble doesn't make sense for Chrome OS. | 1236 WebContents* web_contents = delegate_->GetWebContents(); |
| 1197 Browser* browser = GetBrowserFromDelegate(delegate_); | 1237 if (!web_contents) |
| 1198 if (!browser) | 1238 return; |
| 1199 return; // Possible when browser is shutting down. | 1239 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 1200 | 1240 if (browser) |
| 1201 FirstRunBubble::ShowBubble(browser, GetLocationBarAnchor()); | 1241 FirstRunBubble::ShowBubble(browser, GetLocationBarAnchor()); |
| 1202 #endif | 1242 #endif |
| 1203 } | 1243 } |
| 1204 | 1244 |
| 1205 void LocationBarView::AccessibilitySetValue(const base::string16& new_value) { | 1245 void LocationBarView::AccessibilitySetValue(const base::string16& new_value) { |
| 1206 omnibox_view_->SetUserText(new_value, new_value, true); | 1246 omnibox_view_->SetUserText(new_value, new_value, true); |
| 1207 } | 1247 } |
| 1208 | 1248 |
| 1209 bool LocationBarView::HasValidSuggestText() const { | 1249 bool LocationBarView::HasValidSuggestText() const { |
| 1210 return suggested_text_view_->visible() && | 1250 return suggested_text_view_->visible() && |
| 1211 !suggested_text_view_->size().IsEmpty(); | 1251 !suggested_text_view_->size().IsEmpty(); |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 void LocationBarView::ModelChanged(const SearchModel::State& old_state, | 1682 void LocationBarView::ModelChanged(const SearchModel::State& old_state, |
| 1643 const SearchModel::State& new_state) { | 1683 const SearchModel::State& new_state) { |
| 1644 const bool visible = !GetToolbarModel()->input_in_progress() && | 1684 const bool visible = !GetToolbarModel()->input_in_progress() && |
| 1645 new_state.voice_search_supported; | 1685 new_state.voice_search_supported; |
| 1646 if (mic_search_view_->visible() != visible) { | 1686 if (mic_search_view_->visible() != visible) { |
| 1647 mic_search_view_->SetVisible(visible); | 1687 mic_search_view_->SetVisible(visible); |
| 1648 Layout(); | 1688 Layout(); |
| 1649 } | 1689 } |
| 1650 } | 1690 } |
| 1651 | 1691 |
| OLD | NEW |