Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/bookmarks/bookmark_sync_promo_view.h" | |
| 6 | |
| 7 #include "base/strings/string16.h" | |
| 8 #include "chrome/browser/ui/chrome_pages.h" | |
| 9 #include "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" | |
| 18 | |
| 19 namespace { | |
| 20 // Background color of the promo. | |
| 21 const SkColor kBackgroundColor = SkColorSetRGB(245, 245, 245); | |
| 22 | |
| 23 // Color of the top border of the promo. | |
| 24 const SkColor kBorderColor = SkColorSetRGB(229, 229, 229); | |
| 25 | |
| 26 // Width of the top border of the promo. | |
| 27 const int kBorderWidth = 1; | |
| 28 | |
| 29 // Color of the text of the promo. | |
| 30 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); | |
| 31 | |
| 32 // Vertical padding of the promo (dp). | |
| 33 const int kVerticalPadding = 15; | |
|
fdoray
2013/07/16 17:58:56
This comes from the designer. Not defined in layou
sky
2013/07/16 21:23:00
There is a reason why we try to use the same const
fdoray
2013/07/17 15:01:59
I sent a screenshot of the result with a common co
| |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 BookmarkSyncPromoView::BookmarkSyncPromoView(Browser* browser) | |
| 38 : browser_(browser) { | |
| 39 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 40 set_border(views::Border::CreateSolidSidedBorder(kBorderWidth, | |
| 41 0, | |
| 42 0, | |
| 43 0, | |
| 44 kBorderColor)); | |
| 45 size_t offset; | |
| 46 string16 link_text = l10n_util::GetStringUTF16(IDS_BOOKMARK_SYNC_PROMO_LINK); | |
| 47 string16 promo_text = l10n_util::GetStringFUTF16( | |
| 48 IDS_BOOKMARK_SYNC_PROMO_MESSAGE, | |
| 49 link_text, | |
| 50 &offset); | |
| 51 | |
| 52 views::StyledLabel* promo_label = new views::StyledLabel(promo_text, this); | |
| 53 promo_label->SetDisplayedOnBackgroundColor(kBackgroundColor); | |
| 54 | |
| 55 views::StyledLabel::RangeStyleInfo link_style = | |
| 56 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
| 57 link_style.font_style = gfx::Font::NORMAL; | |
| 58 promo_label->AddStyleRange(ui::Range(offset, offset + link_text.length()), | |
| 59 link_style); | |
| 60 | |
| 61 views::StyledLabel::RangeStyleInfo promo_style; | |
| 62 promo_style.color = kTextColor; | |
| 63 ui::Range before_link_range(0, offset); | |
| 64 if (!before_link_range.is_empty()) | |
| 65 promo_label->AddStyleRange(before_link_range, promo_style); | |
| 66 ui::Range after_link_range(offset + link_text.length(), promo_text.length()); | |
| 67 if (!after_link_range.is_empty()) | |
| 68 promo_label->AddStyleRange(after_link_range, promo_style); | |
| 69 | |
| 70 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kVertical, | |
| 71 views::kButtonHEdgeMarginNew, | |
| 72 kVerticalPadding, | |
| 73 0); | |
| 74 SetLayoutManager(layout); | |
| 75 AddChildView(promo_label); | |
| 76 } | |
| 77 | |
| 78 void BookmarkSyncPromoView::StyledLabelLinkClicked(const ui::Range& range, | |
| 79 int event_flags) { | |
| 80 chrome::ShowBrowserSignin(browser_, SyncPromoUI::SOURCE_BOOKMARK_BUBBLE); | |
| 81 } | |
| OLD | NEW |