Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / bookmarks / bookmark_sync_promo_view.cc
blob9332471365a81e0c99a004b2a592933487a779b8
1 // Copyright 2013 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.
5 #include "chrome/browser/ui/views/bookmarks/bookmark_sync_promo_view.h"
7 #include "base/strings/string16.h"
8 #include "chrome/browser/ui/bookmarks/bookmark_bubble_delegate.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/gfx/font.h"
13 #include "ui/views/background.h"
14 #include "ui/views/border.h"
15 #include "ui/views/controls/styled_label.h"
16 #include "ui/views/layout/box_layout.h"
17 #include "ui/views/layout/layout_constants.h"
19 namespace {
20 // Background color of the promo.
21 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245);
23 // Color of the top border of the promo.
24 const SkColor kBorderColor = SkColorSetRGB(229, 229, 229);
26 // Width of the top border of the promo.
27 const int kBorderWidth = 1;
29 // Color of the text of the promo.
30 const SkColor kTextColor = SkColorSetRGB(102, 102, 102);
32 } // namespace
34 BookmarkSyncPromoView::BookmarkSyncPromoView(BookmarkBubbleDelegate* delegate)
35 : delegate_(delegate) {
36 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
37 SetBorder(views::Border::CreateSolidSidedBorder(
38 kBorderWidth, 0, 0, 0, kBorderColor));
39 size_t offset;
40 base::string16 link_text =
41 l10n_util::GetStringUTF16(IDS_BOOKMARK_SYNC_PROMO_LINK);
42 base::string16 promo_text = l10n_util::GetStringFUTF16(
43 IDS_BOOKMARK_SYNC_PROMO_MESSAGE,
44 link_text,
45 &offset);
47 views::StyledLabel* promo_label = new views::StyledLabel(promo_text, this);
48 promo_label->SetDisplayedOnBackgroundColor(kBackgroundColor);
50 views::StyledLabel::RangeStyleInfo link_style =
51 views::StyledLabel::RangeStyleInfo::CreateForLink();
52 link_style.font_style = gfx::Font::NORMAL;
53 promo_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()),
54 link_style);
56 views::StyledLabel::RangeStyleInfo promo_style;
57 promo_style.color = kTextColor;
58 gfx::Range before_link_range(0, offset);
59 if (!before_link_range.is_empty())
60 promo_label->AddStyleRange(before_link_range, promo_style);
61 gfx::Range after_link_range(offset + link_text.length(), promo_text.length());
62 if (!after_link_range.is_empty())
63 promo_label->AddStyleRange(after_link_range, promo_style);
65 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical,
66 views::kButtonHEdgeMarginNew,
67 views::kPanelVertMargin,
68 0);
69 SetLayoutManager(layout);
70 AddChildView(promo_label);
73 void BookmarkSyncPromoView::StyledLabelLinkClicked(const gfx::Range& range,
74 int event_flags) {
75 delegate_->OnSignInLinkClicked();
78 const char* BookmarkSyncPromoView::GetClassName() const {
79 return "BookmarkSyncPromoView";