Chromium Code Reviews| 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 3a3c56242912321467630f46248f638eaa92c0f5..dc1421afb8e756dbd928e9578260393c23073321 100644 |
| --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc |
| +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc |
| @@ -29,6 +29,7 @@ |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| +#include "chrome/browser/ui/search/search.h" |
| #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| #include "chrome/browser/ui/view_ids.h" |
| #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" |
| @@ -98,6 +99,16 @@ using views::View; |
| namespace { |
| +// Location of EV bubble wrt edit box, in the LTR direction. |
| +// The value is a combination of bit masks. |
| +enum EVBubbleLocation { |
| + EV_BUBBLE_HIDE = 0, // Not visible. |
| + EV_BUBBLE_LEFT = 1 << 0, // On left of edit box. |
| + EV_BUBBLE_RIGHT = 1 << 1, // On right of edit box. |
| + EV_BUBBLE_BESIDE_EDGE = 1 << 2, // Beside left or right edge of location bar. |
| + EV_BUBBLE_BESIDE_EDIT = 1 << 3, // Beside left or right of edit box. |
| +}; |
| + |
| Browser* GetBrowserFromDelegate(LocationBarView::Delegate* delegate) { |
| WebContents* contents = delegate->GetWebContents(); |
| return browser::FindBrowserWithWebContents(contents); |
| @@ -668,10 +679,12 @@ void LocationBarView::Layout() { |
| if (!action_box_button_view_) |
| entry_width -= GetEdgeItemPadding(); |
| - // |location_icon_view_| is visible except when |ev_bubble_view_| or |
| - // |selected_keyword_view_| are visible. |
| + // |location_icon_view_| is visible except when |ev_bubble_view_| on the left |
| + // of edit or |selected_keyword_view_| are visible; if |ev_bubble_view_| is |
| + // visible on the right of edit, |location_icon_view_| could be visible too |
| + // (see comments below for instant extended API). |
| int location_icon_width = 0; |
| - int ev_bubble_width = 0; |
| + int ev_bubble_loc = EV_BUBBLE_HIDE; |
| location_icon_view_->SetVisible(false); |
| ev_bubble_view_->SetVisible(false); |
| @@ -684,19 +697,45 @@ void LocationBarView::Layout() { |
| } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { |
| ev_bubble_view_->SetVisible(true); |
| ev_bubble_view_->SetLabel(model_->GetEVCertName()); |
| - ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); |
| - // We'll adjust this width and take it out of |entry_width| below. |
| + ev_bubble_loc = EV_BUBBLE_LEFT | EV_BUBBLE_BESIDE_EDGE | |
| + EV_BUBBLE_BESIDE_EDIT; |
| } else { |
| location_icon_view_->SetVisible(true); |
| location_icon_width = location_icon_view_->GetPreferredSize().width(); |
| entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
| location_icon_width + kItemEditPadding); |
| + |
| + // For instant extended API, omnibox could be secure and replacing the url |
| + // with query terms, in which case, show the ev bubble view with the search |
| + // provider name on the right of the edit box. |
| + if (chrome::search::IsInstantExtendedAPIEnabled(profile_) && |
| + model_->GetSecurityLevel() == ToolbarModel::SECURE && |
| + model_->WouldReplaceSearchURLWithSearchTerms()) { |
| + const TemplateURL* template_url = |
| + TemplateURLServiceFactory::GetForProfile(profile_)-> |
| + GetDefaultSearchProvider(); |
| + if (template_url) { |
| + ev_bubble_view_->SetVisible(true); |
| + ev_bubble_view_->SetLabel(l10n_util::GetStringFUTF16( |
| + IDS_OMNIBOX_EV_SEARCH_TEXT, template_url->short_name())); |
| + ev_bubble_loc = EV_BUBBLE_RIGHT; |
| + if (!action_box_button_view_) |
| + ev_bubble_loc |= EV_BUBBLE_BESIDE_EDGE; |
| + // We'll determine if EV bubble is beside edit box later. |
|
dhollowa
2012/11/29 17:01:26
nit: "Determine...below".
kuan
2012/11/29 17:19:20
Done.
|
| + } |
| + } |
| } |
| if (action_box_button_view_) { |
| action_box_button_view_->SetVisible(true); |
| entry_width -= action_box_button_view_->width() + GetItemPadding(); |
| } |
| + |
| + // Remember |entry_width| before considering the decorations between right of |
| + // edit box and action box, so as to determine if any other decoration is |
| + // added, which will help determine if right EV bubble is beside the edit box. |
| + int entry_width_for_left_of_action_box = entry_width; |
| + |
| if (star_view_ && star_view_->visible()) |
| entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
| if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { |
| @@ -719,18 +758,35 @@ void LocationBarView::Layout() { |
| entry_width -= web_intents_button_view_->GetPreferredSize().width() + |
| GetItemPadding(); |
| } |
| + |
| + // If EV bubble is on right of edit box and no decoration has been added |
| + // between right of edit box and action box, EV bubble is beside edit box. |
| + if (ev_bubble_loc & EV_BUBBLE_RIGHT && |
| + entry_width_for_left_of_action_box == entry_width) { |
| + ev_bubble_loc |= EV_BUBBLE_BESIDE_EDIT; |
| + } |
| + |
| // The gap between the edit and whatever is to its right is shortened. |
| entry_width += kEditInternalSpace; |
| // Size the EV bubble after taking star/page actions/content settings out of |
| // |entry_width| so we won't take too much space. |
| - if (ev_bubble_width) { |
| + int ev_bubble_width = 0; |
| + if (ev_bubble_loc != EV_BUBBLE_HIDE) { |
| + ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); |
| // Try to elide the bubble to be no larger than half the total available |
| // space, but never elide it any smaller than 150 px. |
| static const int kMinElidedBubbleWidth = 150; |
| static const double kMaxBubbleFraction = 0.5; |
| - const int total_padding = |
| - kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; |
| + int total_padding = 0; |
| + if (ev_bubble_loc & EV_BUBBLE_BESIDE_EDGE) |
| + total_padding += kEdgeThickness + kBubbleHorizontalPadding; |
| + else |
| + total_padding += GetItemPadding(); |
| + if (ev_bubble_loc & EV_BUBBLE_BESIDE_EDIT) |
| + total_padding += kItemEditPadding; |
| + else |
| + total_padding += GetItemPadding(); |
| ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, |
| static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); |
| entry_width -= (total_padding + ev_bubble_width); |
| @@ -775,10 +831,20 @@ void LocationBarView::Layout() { |
| kVerticalEdgeThickness - |
| ActionBoxButtonView::kBorderOverlap)); |
| offset -= GetItemPadding(); |
| + } else if (ev_bubble_loc & EV_BUBBLE_RIGHT) { |
| + offset -= kBubbleHorizontalPadding; |
| } else { |
| offset -= GetEdgeItemPadding(); |
| } |
| + if (ev_bubble_loc & EV_BUBBLE_RIGHT) { |
| + offset -= ev_bubble_width; |
| + ev_bubble_view_->SetBounds(offset, location_y + kBubbleVerticalPadding, |
| + ev_bubble_width, |
| + ev_bubble_view_->GetPreferredSize().height()); |
| + offset -= GetItemPadding(); |
| + } |
| + |
| if (star_view_ && star_view_->visible()) { |
| offset += star_view_->GetBuiltInHorizontalPadding(); |
| int star_width = star_view_->GetPreferredSize().width(); |