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 c923a07aa062ead570208f23c5ab2fa9f84aeb8a..29ddc1de408c351dc61416e24e9f8793ce58fd95 100644 |
| --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc |
| +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc |
| @@ -40,6 +40,7 @@ |
| #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
| #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" |
| +#include "chrome/browser/ui/views/location_bar/location_bar_separator_view.h" |
| #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
| @@ -76,6 +77,7 @@ |
| #include "ui/views/border.h" |
| #include "ui/views/button_drag_utils.h" |
| #include "ui/views/controls/label.h" |
| +#include "ui/views/layout/layout_constants.h" |
| #include "ui/views/widget/widget.h" |
| #if defined(OS_WIN) |
| @@ -178,6 +180,8 @@ LocationBarView::LocationBarView(Browser* browser, |
| selected_keyword_view_(NULL), |
| suggested_text_view_(NULL), |
| keyword_hint_view_(NULL), |
| + search_token_view_(NULL), |
| + search_token_separator_view_(NULL), |
| zoom_view_(NULL), |
| open_pdf_in_reader_view_(NULL), |
| script_bubble_icon_view_(NULL), |
| @@ -231,17 +235,17 @@ void LocationBarView::Init() { |
| font_ = font_.DeriveFont(-1); |
| location_icon_view_ = new LocationIconView(this); |
| - AddChildView(location_icon_view_); |
| location_icon_view_->SetVisible(true); |
| location_icon_view_->set_drag_controller(this); |
| + AddChildView(location_icon_view_); |
| ev_bubble_view_ = |
| new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
| GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), |
| this); |
| - AddChildView(ev_bubble_view_); |
| ev_bubble_view_->SetVisible(false); |
|
Peter Kasting
2013/01/17 04:14:23
Nit: Are all these SetVisible(false) calls even ne
kuan
2013/01/17 17:57:43
Done.
|
| ev_bubble_view_->set_drag_controller(this); |
| + AddChildView(ev_bubble_view_); |
| // URL edit field. |
| // View container for URL edit field. |
| @@ -256,14 +260,22 @@ void LocationBarView::Init() { |
| kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
| GetColor(ToolbarModel::NONE, TEXT), |
| profile_); |
| - AddChildView(selected_keyword_view_); |
| - selected_keyword_view_->SetFont(font_); |
| selected_keyword_view_->SetVisible(false); |
| + selected_keyword_view_->SetFont(font_); |
| + AddChildView(selected_keyword_view_); |
| keyword_hint_view_ = new KeywordHintView(profile_, this); |
| - AddChildView(keyword_hint_view_); |
| keyword_hint_view_->SetVisible(false); |
| keyword_hint_view_->SetFont(font_); |
| + AddChildView(keyword_hint_view_); |
| + |
| + search_token_view_ = new views::Label(string16(), font_); |
| + search_token_view_->SetAutoColorReadabilityEnabled(false); |
| + search_token_view_->SetVisible(false); |
| + AddChildView(search_token_view_); |
| + search_token_separator_view_ = new LocationBarSeparatorView(); |
| + search_token_separator_view_->SetVisible(false); |
| + AddChildView(search_token_separator_view_); |
| for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| ContentSettingImageView* content_blocked_view = |
| @@ -272,8 +284,8 @@ void LocationBarView::Init() { |
| font_, |
| GetColor(ToolbarModel::NONE, TEXT)); |
| content_setting_views_.push_back(content_blocked_view); |
| - AddChildView(content_blocked_view); |
| content_blocked_view->SetVisible(false); |
| + AddChildView(content_blocked_view); |
| } |
| zoom_view_ = new ZoomView(model_, delegate_); |
| @@ -289,24 +301,24 @@ void LocationBarView::Init() { |
| AddChildView(open_pdf_in_reader_view_); |
| script_bubble_icon_view_ = new ScriptBubbleIconView(delegate()); |
| - AddChildView(script_bubble_icon_view_); |
| script_bubble_icon_view_->SetVisible(false); |
| + AddChildView(script_bubble_icon_view_); |
| if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
| // Note: condition above means that the star icon is hidden in popups and in |
| // the app launcher. |
| star_view_ = new StarView(command_updater_); |
| - AddChildView(star_view_); |
| star_view_->SetVisible(true); |
| + AddChildView(star_view_); |
| } |
| if (extensions::FeatureSwitch::action_box()->IsEnabled() && |
| mode_ == NORMAL && browser_) { |
| + if (star_view_) |
| + star_view_->SetVisible(false); |
| + |
| action_box_button_view_ = new ActionBoxButtonView(browser_, |
| gfx::Point(kNormalHorizontalEdgeThickness, kVerticalEdgeThickness)); |
| AddChildView(action_box_button_view_); |
| - |
| - if (star_view_) |
| - star_view_->SetVisible(false); |
| } |
| registrar_.Add(this, |
| @@ -425,6 +437,27 @@ void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
| if (star_view_ && !extensions::FeatureSwitch::action_box()->IsEnabled()) |
| star_view_->SetVisible(star_enabled); |
| + string16 search_provider; |
| + if (!model_->GetInputInProgress() && |
| + model_->WouldReplaceSearchURLWithSearchTerms()) { |
| + const TemplateURL* template_url = |
| + TemplateURLServiceFactory::GetForProfile(profile_)-> |
| + GetDefaultSearchProvider(); |
| + if (template_url && !template_url->short_name().empty()) { |
| + search_provider = l10n_util::GetStringFUTF16( |
| + IDS_OMNIBOX_SEARCH_TOKEN_TEXT, template_url->short_name()); |
| + search_token_view_->SetBackgroundColor(GetColor( |
| + model_->GetSecurityLevel(), LocationBarView::BACKGROUND)); |
| + SkColor text_color = GetColor( |
| + model_->GetSecurityLevel(), LocationBarView::DEEMPHASIZED_TEXT); |
| + search_token_view_->SetEnabledColor(text_color); |
| + search_token_separator_view_->set_separator_color( |
| + SkColorSetA(text_color, 64)); // 25% alpha. |
| + } |
| + } |
| + // If |search_provider| is empty, |search_token_view_| is hidden. |
| + search_token_view_->SetText(search_provider); |
| + |
| // Don't Update in app launcher mode so that the location entry does not show |
| // a URL or security background. |
| if (mode_ != APP_LAUNCHER) |
| @@ -673,11 +706,16 @@ void LocationBarView::Layout() { |
| location_icon_view_->SetVisible(false); |
| ev_bubble_view_->SetVisible(false); |
| keyword_hint_view_->SetVisible(false); |
| + search_token_view_->SetVisible(false); |
| + search_token_separator_view_->SetVisible(false); |
| const string16 keyword(location_entry_->model()->keyword()); |
| const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); |
| - const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; |
| - const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; |
| + const bool show_search_token = !search_token_view_->text().empty(); |
| + const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint && |
| + !show_search_token; |
| + const bool show_keyword_hint = !keyword.empty() && is_keyword_hint && |
| + !show_search_token; |
| if (show_selected_keyword) { |
| left_decorations.AddDecoration( |
| kBubbleLocationY, 0, true, 0, kBubbleHorizontalPadding, |
| @@ -763,6 +801,17 @@ void LocationBarView::Layout() { |
| if (keyword_hint_view_->keyword() != keyword) |
| keyword_hint_view_->SetKeyword(keyword); |
| } |
| + if (show_search_token) { |
| + right_decorations.AddSeparator(kVerticalEdgeThickness, location_height, |
| + GetItemPadding(), search_token_separator_view_); |
| + // This must be the last item in the right decorations list, otherwise |
| + // right_decorations.set_item_padding() makes no sense. |
| + right_decorations.AddDecoration( |
| + kVerticalEdgeThickness, location_height, true, 0, GetEdgeItemPadding(), |
| + GetItemPadding() * 2, 0, search_token_view_); |
| + right_decorations.set_item_edit_padding( |
| + views::kUnrelatedControlLargeHorizontalSpacing); |
| + } |
| // Perform layout. |
| int full_width = width() - 2 * kEdgeThickness; |