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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/location_bar/search_token_view.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/controls/label.h"
13
14 SearchTokenView::SearchTokenView(const LocationBarView* location_bar_view)
15 : label_(new views::Label()) {
16 label_->SetAutoColorReadabilityEnabled(false);
17 AddChildView(label_);
18 }
19
20 SearchTokenView::~SearchTokenView() {
21 }
22
23 void SearchTokenView::SetFont(const gfx::Font& font) {
24 label_->SetFont(font);
25 }
26
27 void SearchTokenView::SetBackgroundColor(SkColor color) {
28 label_->SetBackgroundColor(color);
29 }
30
31 void SearchTokenView::SetForegroundColor(SkColor color) {
32 label_->SetEnabledColor(color);
33 border_color_ = SkColorSetA(label_->enabled_color(), 64); // 25% alpha.
34 }
35
36 void SearchTokenView::SetSearchProvider(const string16& search_provider) {
37 if (search_provider_ == search_provider)
38 return;
39 search_provider_ = search_provider;
40 if (!search_provider_.empty()) {
41 label_->SetText(l10n_util::GetStringFUTF16(IDS_OMNIBOX_SEARCH_TOKEN_TEXT,
42 search_provider_));
43 }
44 }
45
46 gfx::Size SearchTokenView::GetPreferredSize() {
47 gfx::Size size = label_->GetPreferredSize();
48 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.
49 return size;
50 }
51
52 void SearchTokenView::Layout() {
53 label_->SetBounds(0, 0, label_->GetPreferredSize().width(), height());
54 }
55
56 void SearchTokenView::OnPaint(gfx::Canvas* canvas) {
57 // Paint the background color.
58 canvas->DrawColor(label_->background_color());
59 // Paint the right border which serves as a separator between this view and
60 // decorations to its right.
61 // Note that views::Border::CreateSolidSidedBorder is not used because it
62 // paints a 2-px thick border in retina display, whereas we want a 1-px thick
63 // border in both regular and retina displays.
64 SkPaint paint;
65 paint.setAntiAlias(false);
66 paint.setStrokeWidth(0);
67 paint.setColor(border_color_);
68 int right = width() - 1;
69 canvas->DrawLine(gfx::Point(right, 0), gfx::Point(right, height()), paint);
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698