| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" | 5 #include "chrome/browser/ui/views/sync/bubble_sync_promo_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" | 10 #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
| 14 #include "ui/views/controls/styled_label.h" | 14 #include "ui/views/controls/styled_label.h" |
| 15 #include "ui/views/layout/fill_layout.h" | 15 #include "ui/views/layout/fill_layout.h" |
| 16 #include "ui/views/layout/layout_constants.h" | 16 #include "ui/views/layout/layout_constants.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Color of the text of the promo. | 20 // Color of the text of the promo. |
| 21 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); | 21 const SkColor kTextColor = SkColorSetRGB(102, 102, 102); |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 BubbleSyncPromoView::BubbleSyncPromoView(BubbleSyncPromoDelegate* delegate, | 25 BubbleSyncPromoView::BubbleSyncPromoView(BubbleSyncPromoDelegate* delegate, |
| 26 int link_text_resource_id, | 26 int link_text_resource_id, |
| 27 int message_text_resource_id) | 27 int message_text_resource_id) |
| 28 : delegate_(delegate) { | 28 : StyledLabel(base::string16(), this), delegate_(delegate) { |
| 29 size_t offset = 0; | 29 size_t offset = 0; |
| 30 base::string16 link_text = l10n_util::GetStringUTF16(link_text_resource_id); | 30 base::string16 link_text = l10n_util::GetStringUTF16(link_text_resource_id); |
| 31 base::string16 promo_text = | 31 base::string16 promo_text = |
| 32 l10n_util::GetStringFUTF16(message_text_resource_id, link_text, &offset); | 32 l10n_util::GetStringFUTF16(message_text_resource_id, link_text, &offset); |
| 33 | 33 SetText(promo_text); |
| 34 views::StyledLabel* promo_label = new views::StyledLabel(promo_text, this); | |
| 35 | 34 |
| 36 views::StyledLabel::RangeStyleInfo link_style = | 35 views::StyledLabel::RangeStyleInfo link_style = |
| 37 views::StyledLabel::RangeStyleInfo::CreateForLink(); | 36 views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 38 link_style.font_style = gfx::Font::NORMAL; | 37 link_style.font_style = gfx::Font::NORMAL; |
| 39 promo_label->AddStyleRange(gfx::Range(offset, offset + link_text.length()), | 38 AddStyleRange(gfx::Range(offset, offset + link_text.length()), link_style); |
| 40 link_style); | |
| 41 | 39 |
| 42 views::StyledLabel::RangeStyleInfo promo_style; | 40 views::StyledLabel::RangeStyleInfo promo_style; |
| 43 promo_style.color = kTextColor; | 41 promo_style.color = kTextColor; |
| 44 gfx::Range before_link_range(0, offset); | 42 gfx::Range before_link_range(0, offset); |
| 45 if (!before_link_range.is_empty()) | 43 if (!before_link_range.is_empty()) |
| 46 promo_label->AddStyleRange(before_link_range, promo_style); | 44 AddStyleRange(before_link_range, promo_style); |
| 47 gfx::Range after_link_range(offset + link_text.length(), promo_text.length()); | 45 gfx::Range after_link_range(offset + link_text.length(), promo_text.length()); |
| 48 if (!after_link_range.is_empty()) | 46 if (!after_link_range.is_empty()) |
| 49 promo_label->AddStyleRange(after_link_range, promo_style); | 47 AddStyleRange(after_link_range, promo_style); |
| 50 | |
| 51 SetLayoutManager(new views::FillLayout()); | |
| 52 AddChildView(promo_label); | |
| 53 } | 48 } |
| 54 | 49 |
| 55 BubbleSyncPromoView::~BubbleSyncPromoView() {} | 50 BubbleSyncPromoView::~BubbleSyncPromoView() {} |
| 56 | 51 |
| 52 const char* BubbleSyncPromoView::GetClassName() const { |
| 53 return "BubbleSyncPromoView"; |
| 54 } |
| 55 |
| 57 void BubbleSyncPromoView::StyledLabelLinkClicked(views::StyledLabel* label, | 56 void BubbleSyncPromoView::StyledLabelLinkClicked(views::StyledLabel* label, |
| 58 const gfx::Range& range, | 57 const gfx::Range& range, |
| 59 int event_flags) { | 58 int event_flags) { |
| 60 delegate_->OnSignInLinkClicked(); | 59 delegate_->OnSignInLinkClicked(); |
| 61 } | 60 } |
| 62 | |
| 63 const char* BubbleSyncPromoView::GetClassName() const { | |
| 64 return "BubbleSyncPromoView"; | |
| 65 } | |
| OLD | NEW |