Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 11418229: alternate ntp: implement right-aligned search token (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed nits from peter Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d6b1ff45fbf12f165c213a037dad5fe9b5f27ed3 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,15 @@ 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);
ev_bubble_view_->set_drag_controller(this);
+ AddChildView(ev_bubble_view_);
// URL edit field.
// View container for URL edit field.
@@ -256,14 +258,18 @@ 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);
+ 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);
+ AddChildView(search_token_view_);
+ search_token_separator_view_ = new LocationBarSeparatorView();
+ AddChildView(search_token_separator_view_);
for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
ContentSettingImageView* content_blocked_view =
@@ -272,8 +278,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 +295,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 +431,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 +700,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 +795,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;
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698