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..edefc90423f50ce21b0d45a0c3623be41c3f5ad2 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,52 @@ 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; |
+ // TODO(pkasting): Make the origin chip min width sane, and make the chip |
+ // handle being shrunken down more gracefully; then uncomment this. |
+ /*if (GetToolbarModel()->ShouldShowOriginChip()) |
+ leading_width += origin_chip_view_->GetMinimumSize().width();*/ |
+ if (ShouldShowKeywordBubble()) { |
+ // The selected keyword view can collapse completely. |
+ } else if (ShouldShowEVBubble()) { |
+ 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 += IncrementalMinimumWidth(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 +761,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); |
@@ -775,16 +812,15 @@ void LocationBarView::Layout() { |
origin_chip_view_->GetPreferredSize().width() : 0; |
origin_chip_view_->SetBounds(0, 0, origin_chip_width, height()); |
- const base::string16 keyword(omnibox_view_->model()->keyword()); |
- const bool is_keyword_hint(omnibox_view_->model()->is_keyword_hint()); |
const int bubble_location_y = vertical_edge_thickness() + kBubblePadding; |
+ const base::string16 keyword(omnibox_view_->model()->keyword()); |
// In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
// to position our child views in this case, because other things may be |
// positioned relative to them (e.g. the "bookmark added" bubble if the user |
// hits ctrl-d). |
const int location_height = GetInternalHeight(false); |
const int bubble_height = std::max(location_height - (kBubblePadding * 2), 0); |
- if (!keyword.empty() && !is_keyword_hint) { |
+ if (ShouldShowKeywordBubble()) { |
leading_decorations.AddDecoration(bubble_location_y, bubble_height, true, 0, |
kBubblePadding, kItemPadding, |
selected_keyword_view_); |
@@ -805,9 +841,7 @@ void LocationBarView::Layout() { |
selected_keyword_view_->set_is_extension_icon(false); |
} |
} |
- } else if (!toolbar_origin_chip_view_ && |
- !chrome::ShouldDisplayOriginChipV2() && |
- (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE)) { |
+ } else if (ShouldShowEVBubble()) { |
ev_bubble_view_->SetLabel(GetToolbarModel()->GetEVCertName()); |
// The largest fraction of the omnibox that can be taken by the EV bubble. |
const double kMaxBubbleFraction = 0.5; |
@@ -868,7 +902,8 @@ void LocationBarView::Layout() { |
} |
// Because IMEs may eat the tab key, we don't show "press tab to search" while |
// IME composition is in progress. |
- if (!keyword.empty() && is_keyword_hint && !omnibox_view_->IsImeComposing()) { |
+ if (!keyword.empty() && omnibox_view_->model()->is_keyword_hint() && |
+ !omnibox_view_->IsImeComposing()) { |
trailing_decorations.AddDecoration(vertical_edge_thickness(), |
location_height, true, 0, kItemPadding, |
kItemPadding, keyword_hint_view_); |
@@ -880,10 +915,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 +1074,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 +1228,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 |
} |
@@ -1211,6 +1248,16 @@ bool LocationBarView::HasValidSuggestText() const { |
!suggested_text_view_->size().IsEmpty(); |
} |
+bool LocationBarView::ShouldShowKeywordBubble() const { |
+ return !omnibox_view_->model()->keyword().empty() && |
+ !omnibox_view_->model()->is_keyword_hint(); |
+} |
+ |
+bool LocationBarView::ShouldShowEVBubble() const { |
+ return !toolbar_origin_chip_view_ && !chrome::ShouldDisplayOriginChipV2() && |
+ (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); |
+} |
+ |
void LocationBarView::OnShowURLAnimationEnded() { |
animated_host_label_->SetVisible(false); |
omnibox_view_->SetVisible(true); |