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

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: prev was rebased, this changes copyright year Created 8 years 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..a63ec18212018f5bd06abef188c522b48f8bd459
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/search_token_view.cc
@@ -0,0 +1,71 @@
+// 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"
+
+namespace {
+
+// Paddings on the left and right of the label.
+const int kLeftPadding = 25;
+const int kRightPadding = 8;
Peter Kasting 2012/12/17 21:01:00 Don't do this for two reasons. One is that these
kuan 2012/12/20 00:26:14 i've moved the paddings to location_bar_view.cc, b
Peter Kasting 2012/12/20 01:45:39 We shouldn't use different paddings than are avail
kuan 2012/12/20 16:51:22 i dug thru the iteration emails w/ cole and rememb
Peter Kasting 2012/12/20 19:15:07 Don't do this. The location height should have no
+
+} // namespace
+
+SearchTokenView::SearchTokenView(const LocationBarView* location_bar_view)
+ : label_(new views::Label()) {
+ label_->SetAutoColorReadabilityEnabled(false);
+ label_->SetBackgroundColor(location_bar_view->GetColor(
+ ToolbarModel::NONE, LocationBarView::BACKGROUND));
Peter Kasting 2012/12/17 21:01:00 NONE isn't right here (or below). We need to use
kuan 2012/12/20 00:26:14 Done.
+ label_->SetEnabledColor(location_bar_view->GetColor(
+ ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
+ border_color_ = SkColorSetA(location_bar_view->GetColor(
+ ToolbarModel::NONE, LocationBarView::TEXT), 64); // 25% alpha.
Peter Kasting 2012/12/17 21:01:00 Turning off auto-color and manually alpha-blending
kuan 2012/12/20 00:26:14 i removed the disabling of auto-color. the reason
Peter Kasting 2012/12/20 01:45:39 Well, it shouldn't be as dark as the text, it shou
kuan 2012/12/20 16:51:22 i've disabled back auto-coloring. i meant the bor
+ AddChildView(label_);
+}
+
+SearchTokenView::~SearchTokenView() {
+}
+
+void SearchTokenView::SetFont(const gfx::Font& font) {
+ label_->SetFont(font);
+}
+
+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_));
+ } else {
+ SetVisible(false);
Peter Kasting 2012/12/17 21:01:00 It's not right for this class to set itself as inv
kuan 2012/12/20 00:26:14 Done.
+ }
+}
+
+gfx::Size SearchTokenView::GetPreferredSize() {
+ gfx::Size size = label_->GetPreferredSize();
+ size.Enlarge(kLeftPadding + kRightPadding, 0);
+ return size;
+}
+
+void SearchTokenView::Layout() {
+ label_->SetBounds(kLeftPadding, 0, label_->GetPreferredSize().width(),
+ height());
+}
+
+void SearchTokenView::OnPaintBorder(gfx::Canvas* canvas) {
Peter Kasting 2012/12/17 21:01:00 Instead of this, why don't you simply use a real b
kuan 2012/12/20 00:26:14 i tried that, but it paints a 2-px thick right bor
Peter Kasting 2012/12/20 01:45:39 You should add comments to this effect, since futu
kuan 2012/12/20 16:51:22 Done.
+ 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