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

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

Issue 11418229: alternate ntp: implement right-aligned search token (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: re-impl based on philippe's new layout design Created 7 years, 12 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
Index: chrome/browser/ui/views/location_bar/search_token_view.cc
diff --git a/chrome/browser/ui/views/location_bar/search_token_view.cc b/chrome/browser/ui/views/location_bar/search_token_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5d8b9721e4bc25b29f0d8162c307a47a98eed186
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/search_token_view.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/location_bar/search_token_view.h"
+
+#include "base/logging.h"
+#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/controls/label.h"
+
+SearchTokenView::SearchTokenView(const LocationBarView* location_bar_view)
+ : label_(new views::Label()) {
+ label_->SetAutoColorReadabilityEnabled(false);
+ AddChildView(label_);
+}
+
+SearchTokenView::~SearchTokenView() {
+}
+
+void SearchTokenView::SetFont(const gfx::Font& font) {
+ label_->SetFont(font);
+}
+
+void SearchTokenView::SetBackgroundColor(SkColor color) {
+ label_->SetBackgroundColor(color);
+}
+
+void SearchTokenView::SetForegroundColor(SkColor color) {
+ label_->SetEnabledColor(color);
+ border_color_ = SkColorSetA(label_->enabled_color(), 64); // 25% alpha.
+}
+
+void SearchTokenView::SetSearchProvider(const string16& search_provider) {
+ if (search_provider_ == search_provider)
+ return;
+ search_provider_ = search_provider;
+ if (!search_provider_.empty()) {
+ label_->SetText(l10n_util::GetStringFUTF16(IDS_OMNIBOX_SEARCH_TOKEN_TEXT,
+ search_provider_));
+ }
+}
+
+gfx::Size SearchTokenView::GetPreferredSize() {
+ gfx::Size size = label_->GetPreferredSize();
+ size.Enlarge(LocationBarView::GetItemPadding(), 0);
beaudoin 2013/01/07 17:27:53 Comment that the enlarge is not for the padding be
kuan 2013/01/07 17:43:38 actually, cole wants the padding between "Google S
beaudoin 2013/01/07 18:42:30 I'd say the question is more: - Is this meant to s
kuan 2013/01/09 19:52:58 Done.
+ return size;
+}
+
+void SearchTokenView::Layout() {
+ label_->SetBounds(0, 0, label_->GetPreferredSize().width(), height());
+}
+
+void SearchTokenView::OnPaint(gfx::Canvas* canvas) {
+ // Paint the background color.
+ canvas->DrawColor(label_->background_color());
+ // Paint the right border which serves as a separator between this view and
+ // decorations to its right.
+ // Note that views::Border::CreateSolidSidedBorder is not used because it
+ // paints a 2-px thick border in retina display, whereas we want a 1-px thick
+ // border in both regular and retina displays.
+ SkPaint paint;
+ paint.setAntiAlias(false);
+ paint.setStrokeWidth(0);
+ paint.setColor(border_color_);
+ int right = width() - 1;
+ canvas->DrawLine(gfx::Point(right, 0), gfx::Point(right, height()), paint);
+}

Powered by Google App Engine
This is Rietveld 408576698