OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/first_run_bubble.h" | 5 #include "chrome/browser/ui/views/first_run_bubble.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/first_run/first_run.h" | 7 #include "chrome/browser/first_run/first_run.h" |
9 #include "chrome/browser/search_engines/util.h" | 8 #include "chrome/browser/search_engines/util.h" |
| 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/chrome_pages.h" | 10 #include "chrome/browser/ui/chrome_pages.h" |
11 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
15 #include "ui/views/controls/link.h" | 15 #include "ui/views/controls/link.h" |
16 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
17 #include "ui/views/layout/layout_constants.h" | 17 #include "ui/views/layout/layout_constants.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 const int kAnchorVerticalInset = 5; | 21 const int kAnchorVerticalInset = 5; |
22 const int kTopInset = 1; | 22 const int kTopInset = 1; |
23 const int kLeftInset = 2; | 23 const int kLeftInset = 2; |
24 const int kBottomInset = 7; | 24 const int kBottomInset = 7; |
25 const int kRightInset = 2; | 25 const int kRightInset = 2; |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 namespace first_run { | 28 namespace first_run { |
29 void ShowFirstRunDialog(Profile* profile) {} | 29 void ShowFirstRunDialog(Profile* profile) {} |
30 } // namespace first_run | 30 } // namespace first_run |
31 | 31 |
32 // static | 32 // static |
33 FirstRunBubble* FirstRunBubble::ShowBubble(Browser* browser, | 33 FirstRunBubble* FirstRunBubble::ShowBubble(Browser* browser, |
34 Profile* profile, | |
35 views::View* anchor_view) { | 34 views::View* anchor_view) { |
36 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN); | 35 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN); |
37 | 36 |
38 FirstRunBubble* delegate = new FirstRunBubble(browser, profile, anchor_view); | 37 FirstRunBubble* delegate = new FirstRunBubble(browser, anchor_view); |
39 views::BubbleDelegateView::CreateBubble(delegate); | 38 views::BubbleDelegateView::CreateBubble(delegate); |
40 delegate->StartFade(true); | 39 delegate->StartFade(true); |
41 return delegate; | 40 return delegate; |
42 } | 41 } |
43 | 42 |
44 void FirstRunBubble::Init() { | 43 void FirstRunBubble::Init() { |
45 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
46 const gfx::Font& original_font = rb.GetFont(ui::ResourceBundle::MediumFont); | 45 const gfx::Font& original_font = rb.GetFont(ui::ResourceBundle::MediumFont); |
47 | 46 |
48 views::Label* title = new views::Label(l10n_util::GetStringFUTF16( | 47 views::Label* title = new views::Label(l10n_util::GetStringFUTF16( |
49 IDS_FR_BUBBLE_TITLE, GetDefaultSearchEngineName(profile_))); | 48 IDS_FR_BUBBLE_TITLE, browser_ ? |
| 49 GetDefaultSearchEngineName(browser_->profile()) : string16())); |
50 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD)); | 50 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD)); |
51 | 51 |
52 views::Link* change = | 52 views::Link* change = |
53 new views::Link(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE)); | 53 new views::Link(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE)); |
54 change->SetFont(original_font); | 54 change->SetFont(original_font); |
55 change->set_listener(this); | 55 change->set_listener(this); |
56 | 56 |
57 views::Label* subtext = | 57 views::Label* subtext = |
58 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); | 58 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); |
59 subtext->SetFont(original_font); | 59 subtext->SetFont(original_font); |
(...skipping 18 matching lines...) Expand all Loading... |
78 layout->AddView(subtext, columns->num_columns(), 1); | 78 layout->AddView(subtext, columns->num_columns(), 1); |
79 } | 79 } |
80 | 80 |
81 gfx::Rect FirstRunBubble::GetAnchorRect() { | 81 gfx::Rect FirstRunBubble::GetAnchorRect() { |
82 // Compensate for padding in anchor. | 82 // Compensate for padding in anchor. |
83 gfx::Rect rect(BubbleDelegateView::GetAnchorRect()); | 83 gfx::Rect rect(BubbleDelegateView::GetAnchorRect()); |
84 rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0); | 84 rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0); |
85 return rect; | 85 return rect; |
86 } | 86 } |
87 | 87 |
88 FirstRunBubble::FirstRunBubble(Browser* browser, | 88 FirstRunBubble::FirstRunBubble(Browser* browser, views::View* anchor_view) |
89 Profile* profile, | |
90 views::View* anchor_view) | |
91 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 89 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
92 browser_(browser), | 90 browser_(browser) { |
93 profile_(profile) { | |
94 } | 91 } |
95 | 92 |
96 FirstRunBubble::~FirstRunBubble() { | 93 FirstRunBubble::~FirstRunBubble() { |
97 } | 94 } |
98 | 95 |
99 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) { | 96 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) { |
100 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); | 97 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); |
101 | 98 |
102 GetWidget()->Close(); | 99 GetWidget()->Close(); |
103 if (browser_) | 100 if (browser_) |
104 chrome::ShowSearchEngineSettings(browser_); | 101 chrome::ShowSearchEngineSettings(browser_); |
105 } | 102 } |
OLD | NEW |