Index: chrome/browser/ui/views/location_bar/location_bar_view.cc |
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc |
index 8b679a0bf1ac91cc392be8af8bf927fa5918d4c8..e90dd4f997e98f7674f7a867ec784de1170c6a2a 100644 |
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc |
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc |
@@ -105,12 +105,10 @@ using views::View; |
namespace { |
-#if !defined(OS_CHROMEOS) |
-Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { |
- WebContents* web_contents = delegate->GetWebContents(); |
- return web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; |
-} |
-#endif |
+// The search button images are made to look as if they overlay the normal edge |
+// images, but to align things, the search button needs to be inset horizontally |
+// by 1 px. |
+const int kSearchButtonInset = 1; |
// Given a containing |height| and a |base_font_list|, shrinks the font size |
// until the font list will fit within |height| while having its cap height |
@@ -158,6 +156,11 @@ gfx::FontList GetLargestFontListWithHeightBound( |
return font_list; |
} |
+int GetEditLeadingInternalSpace() { |
+ // The textfield has 1 px of whitespace before the text in the RTL case only. |
+ return base::i18n::IsRTL() ? 1 : 0; |
+} |
+ |
// Functor for moving BookmarkManagerPrivate page actions to the right via |
// stable_partition. |
class IsPageActionViewRightAligned { |
@@ -698,17 +701,53 @@ void LocationBarView::GetAccessibleState(ui::AXViewState* state) { |
} |
gfx::Size LocationBarView::GetPreferredSize() { |
- gfx::Size background_min_size(border_painter_->GetMinimumSize()); |
+ // Compute minimum height. |
+ gfx::Size min_size(border_painter_->GetMinimumSize()); |
if (!IsInitialized()) |
- return background_min_size; |
- |
- gfx::Size origin_chip_view_min_size(origin_chip_view_->GetMinimumSize()); |
+ return min_size; |
gfx::Size search_button_min_size(search_button_->GetMinimumSize()); |
- gfx::Size min_size(background_min_size); |
min_size.SetToMax(search_button_min_size); |
- min_size.set_width(origin_chip_view_min_size.width() + |
- background_min_size.width() + |
- search_button_min_size.width()); |
+ |
+ // Compute width of omnibox-leading content. |
+ const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
+ int leading_width = horizontal_edge_thickness; |
+ if (origin_chip_view_->ShouldShow()) |
+ leading_width += origin_chip_view_->GetMinimumSize().width(); |
+ if (!omnibox_view_->model()->keyword().empty() && |
+ !omnibox_view_->model()->is_keyword_hint()) { |
+ // The selected keyword view can collapse completely. |
+ } else if (!toolbar_origin_chip_view_ && |
+ !chrome::ShouldDisplayOriginChipV2() && |
+ (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) { |
+ leading_width += kBubblePadding + |
+ ev_bubble_view_->GetMinimumSizeForLabelText( |
+ GetToolbarModel()->GetEVCertName()).width(); |
+ } else if (!origin_chip_view_->visible()) { |
+ leading_width += |
+ kItemPadding + location_icon_view_->GetMinimumSize().width(); |
+ } |
+ leading_width += kItemPadding - GetEditLeadingInternalSpace(); |
+ |
+ // Compute width of omnibox-trailing content. |
+ int trailing_width = search_button_->visible() ? |
+ (search_button_->GetMinimumSize().width() + kSearchButtonInset) : |
+ horizontal_edge_thickness; |
+ trailing_width += MinimumWidth(star_view_) + |
+ IncrementalMinimumWidth(translate_icon_view_) + |
+ IncrementalMinimumWidth(open_pdf_in_reader_view_) + |
+ IncrementalMinimumWidth(manage_passwords_icon_view_) + |
+ IncrementalMinimumWidth(zoom_view_) + |
+ IncrementalMinimumWidth(generated_credit_card_view_) + |
+ IncrementalMinimumWidth(mic_search_view_) + kItemPadding; |
+ for (PageActionViews::const_iterator i(page_action_views_.begin()); |
+ i != page_action_views_.end(); ++i) |
+ trailing_width += IncrementalMinimumWidth((*i)); |
+ for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
+ i != content_setting_views_.end(); ++i) |
+ trailing_width += IncrementalMinimumWidth((*i)); |
+ |
+ min_size.set_width( |
+ leading_width + omnibox_view_->GetMinimumSize().width() + trailing_width); |
return min_size; |
} |
@@ -723,10 +762,9 @@ void LocationBarView::Layout() { |
ev_bubble_view_->SetVisible(false); |
keyword_hint_view_->SetVisible(false); |
- // The textfield has 1 px of whitespace before the text in the RTL case only. |
- const int kEditLeadingInternalSpace = base::i18n::IsRTL() ? 1 : 0; |
LocationBarLayout leading_decorations( |
- LocationBarLayout::LEFT_EDGE, kItemPadding - kEditLeadingInternalSpace); |
+ LocationBarLayout::LEFT_EDGE, |
+ kItemPadding - GetEditLeadingInternalSpace()); |
LocationBarLayout trailing_decorations(LocationBarLayout::RIGHT_EDGE, |
kItemPadding); |
@@ -880,10 +918,6 @@ void LocationBarView::Layout() { |
const int horizontal_edge_thickness = GetHorizontalEdgeThickness(); |
int full_width = width() - horizontal_edge_thickness - origin_chip_width; |
- // The search button images are made to look as if they overlay the normal |
- // edge images, but to align things, the search button needs to be inset |
- // horizontally by 1 px. |
- const int kSearchButtonInset = 1; |
const gfx::Size search_button_size(search_button_->GetPreferredSize()); |
const int search_button_reserved_width = |
search_button_size.width() + kSearchButtonInset; |
@@ -1043,6 +1077,11 @@ WebContents* LocationBarView::GetWebContents() { |
//////////////////////////////////////////////////////////////////////////////// |
// LocationBarView, private: |
+// static |
+int LocationBarView::IncrementalMinimumWidth(views::View* view) { |
+ return view->visible() ? (kItemPadding + view->GetMinimumSize().width()) : 0; |
+} |
+ |
int LocationBarView::GetHorizontalEdgeThickness() const { |
// In maximized popup mode, there isn't any edge. |
return (is_popup_mode_ && browser_ && browser_->window() && |
@@ -1192,13 +1231,14 @@ bool LocationBarView::RefreshManagePasswordsIconView() { |
} |
void LocationBarView::ShowFirstRunBubbleInternal() { |
-#if !defined(OS_CHROMEOS) |
// First run bubble doesn't make sense for Chrome OS. |
- Browser* browser = GetBrowserFromDelegate(delegate_); |
- if (!browser) |
- return; // Possible when browser is shutting down. |
- |
- FirstRunBubble::ShowBubble(browser, GetLocationBarAnchor()); |
+#if !defined(OS_CHROMEOS) |
+ WebContents* web_contents = delegate_->GetWebContents(); |
+ if (!web_contents) |
+ return; |
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
+ if (browser) |
+ FirstRunBubble::ShowBubble(browser, GetLocationBarAnchor()); |
#endif |
} |