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

Side by Side Diff: chrome/browser/ui/views/first_run_bubble.cc

Issue 9016036: Implement the new first run bubble, clean up old bubbles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 8 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
1 // Copyright (c) 2011 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/bind.h"
8 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/first_run/first_run.h"
10 #include "chrome/browser/search_engines/util.h" 8 #include "chrome/browser/search_engines/util.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/views/window.h" 10 #include "chrome/browser/ui/views/window.h"
15 #include "content/public/browser/user_metrics.h"
16 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
18 #include "grit/locale_settings.h"
19 #include "grit/theme_resources_standard.h"
20 #include "ui/base/l10n/l10n_font_util.h"
21 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/views/controls/button/image_button.h"
24 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
25 #include "ui/views/events/event.h" 15 #include "ui/views/controls/link.h"
26 #include "ui/views/layout/grid_layout.h" 16 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/layout/layout_constants.h" 17 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/widget/widget.h"
29
30 using content::UserMetricsAction;
31 18
32 namespace { 19 namespace {
33 const int kAnchorVerticalInset = 5; 20 const int kAnchorVerticalInset = 5;
34 const int kLayoutTopInset = 1; 21 const int kTopInset = 1;
35 const int kLayoutLeftInset = 2; 22 const int kLeftInset = 2;
36 const int kLayoutBottomInset = 7; 23 const int kBottomInset = 7;
37 const int kLayoutRightInset = 2; 24 const int kRightInset = 2;
38 } 25 }
39 26
40 // static 27 // static
41 FirstRunBubble* FirstRunBubble::ShowBubble( 28 FirstRunBubble* FirstRunBubble::ShowBubble(Profile* profile,
42 Profile* profile, 29 views::View* anchor_view) {
43 views::View* anchor_view, 30 FirstRunBubble* delegate = new FirstRunBubble(profile, anchor_view);
44 views::BubbleBorder::ArrowLocation arrow_location,
45 FirstRun::BubbleType bubble_type) {
46 FirstRunBubble* delegate =
47 new FirstRunBubble(profile,
48 anchor_view,
49 arrow_location,
50 bubble_type);
51 browser::CreateViewsBubble(delegate); 31 browser::CreateViewsBubble(delegate);
52 delegate->StartFade(true); 32 delegate->StartFade(true);
53 return delegate; 33 return delegate;
54 } 34 }
55 35
56 void FirstRunBubble::Init() { 36 void FirstRunBubble::Init() {
57 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 37 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
58 const gfx::Font& original_font = rb.GetFont(ResourceBundle::MediumFont); 38 const gfx::Font& original_font = rb.GetFont(ResourceBundle::MediumFont);
59 const gfx::Font& derived_font = original_font.DeriveFont(2, gfx::Font::BOLD);
60 39
61 views::Label* label1 = new views::Label(l10n_util::GetStringFUTF16( 40 views::Label* title = new views::Label(l10n_util::GetStringFUTF16(
62 IDS_FR_SE_BUBBLE_TITLE, 41 IDS_FR_BUBBLE_TITLE, GetDefaultSearchEngineName(profile_)));
63 GetDefaultSearchEngineName(profile_))); 42 title->SetFont(original_font.DeriveFont(2, gfx::Font::BOLD));
64 label1->SetFont(derived_font);
65 43
66 views::Label* label2 = 44 views::Link* change =
45 new views::Link(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE));
46 change->SetFont(original_font);
47 change->set_listener(this);
48
49 views::Label* subtext =
67 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); 50 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT));
68 label2->SetFont(original_font); 51 subtext->SetFont(original_font);
69
70 views::ImageButton* close_button = new views::ImageButton(this);
71 close_button->SetImage(views::CustomButton::BS_NORMAL,
72 rb.GetBitmapNamed(IDR_CLOSE_BAR));
73 close_button->SetImage(views::CustomButton::BS_HOT,
74 rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
75 close_button->SetImage(views::CustomButton::BS_PUSHED,
76 rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
77 52
78 views::GridLayout* layout = views::GridLayout::CreatePanel(this); 53 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
79 SetLayoutManager(layout); 54 SetLayoutManager(layout);
80 layout->SetInsets(kLayoutTopInset, 55 layout->SetInsets(kTopInset, kLeftInset, kBottomInset, kRightInset);
81 kLayoutLeftInset,
82 kLayoutBottomInset,
83 kLayoutRightInset);
84 56
85 views::ColumnSet* column_set = layout->AddColumnSet(0); 57 views::ColumnSet* columns = layout->AddColumnSet(0);
86 column_set->AddColumn(views::GridLayout::LEADING, 58 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
87 views::GridLayout::LEADING, 1, 59 views::GridLayout::USE_PREF, 0, 0);
88 views::GridLayout::USE_PREF, 0, 0); 60 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
89 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0, 61 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
90 views::GridLayout::USE_PREF, 0, 0); 62 views::GridLayout::USE_PREF, 0, 0);
63 columns->AddPaddingColumn(1, 0);
91 64
92 layout->StartRow(0, 0); 65 layout->StartRow(0, 0);
93 layout->AddView(label1); 66 layout->AddView(title);
94 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING, 67 layout->AddView(change);
95 views::GridLayout::LEADING); 68 layout->StartRowWithPadding(0, 0, 0,
96 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 69 views::kRelatedControlSmallVerticalSpacing);
97 70 layout->AddView(subtext, columns->num_columns(), 1);
98 layout->StartRow(0, 0);
99 layout->AddView(label2);
100 } 71 }
101 72
102 gfx::Rect FirstRunBubble::GetAnchorRect() { 73 gfx::Rect FirstRunBubble::GetAnchorRect() {
103 // Compensate for padding in anchor. 74 // Compensate for padding in anchor.
104 gfx::Rect rect(BubbleDelegateView::GetAnchorRect()); 75 gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
105 rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0); 76 rect.Inset(0, anchor_view() ? kAnchorVerticalInset : 0);
106 return rect; 77 return rect;
107 } 78 }
108 79
109 FirstRunBubble::FirstRunBubble( 80 FirstRunBubble::FirstRunBubble(Profile* profile, views::View* anchor_view)
110 Profile* profile, 81 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
111 views::View* anchor_view, 82 profile_(profile) {
112 views::BubbleBorder::ArrowLocation arrow_location,
113 FirstRun::BubbleType bubble_type)
114 : views::BubbleDelegateView(anchor_view, arrow_location),
115 profile_(profile),
116 bubble_type_(bubble_type) {
117 } 83 }
118 84
119 FirstRunBubble::~FirstRunBubble() { 85 FirstRunBubble::~FirstRunBubble() {
120 } 86 }
121 87
122 void FirstRunBubble::ButtonPressed(views::Button* sender, 88 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) {
123 const views::Event& event) { 89 // Get |profile_|'s browser before closing the bubble, which deletes |this|.
124 if (bubble_type_ == FirstRun::OEM_BUBBLE) { 90 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
125 content::RecordAction(
126 UserMetricsAction("FirstRunOEMBubbleView_Clicked"));
127 }
128 GetWidget()->Close(); 91 GetWidget()->Close();
92 if (browser)
93 browser->OpenSearchEngineOptionsDialog();
129 } 94 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/first_run_bubble.h ('k') | chrome/browser/ui/views/first_run_bubble_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698