instant_confirm_view.cc revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2010 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/views/instant_confirm_view.h"
6
7#include "app/l10n_util.h"
8#include "base/utf_string_conversions.h"
9#include "chrome/browser/browser_list.h"
10#include "chrome/browser/instant/instant_confirm_dialog.h"
11#include "chrome/browser/instant/instant_controller.h"
12#include "chrome/browser/prefs/pref_service.h"
13#include "chrome/browser/profiles/profile.h"
14#include "chrome/browser/ui/browser.h"
15#include "chrome/common/pref_names.h"
16#include "grit/generated_resources.h"
17#include "grit/chromium_strings.h"
18#include "grit/locale_settings.h"
19#include "views/controls/label.h"
20#include "views/grid_layout.h"
21#include "views/layout_manager.h"
22#include "views/standard_layout.h"
23#include "views/window/window.h"
24
25InstantConfirmView::InstantConfirmView(Profile* profile) : profile_(profile) {
26  views::Label* description_label = new views::Label(
27      UTF16ToWide(l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_MESSAGE)));
28  description_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
29  description_label->SetMultiLine(true);
30
31  views::Link* learn_more_link = new views::Link(
32      UTF16ToWide(l10n_util::GetStringUTF16(IDS_LEARN_MORE)));
33  learn_more_link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
34  learn_more_link->SetController(this);
35
36  views::GridLayout* layout = CreatePanelGridLayout(this);
37  SetLayoutManager(layout);
38
39  const int first_column_set = 1;
40  views::ColumnSet* column_set = layout->AddColumnSet(first_column_set);
41  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1,
42                        views::GridLayout::USE_PREF, 0, 0);
43  layout->StartRow(0, first_column_set);
44  layout->AddView(description_label);
45  layout->StartRow(0, first_column_set);
46  layout->AddView(learn_more_link);
47}
48
49bool InstantConfirmView::Accept(bool window_closing) {
50  return Accept();
51}
52
53bool InstantConfirmView::Accept() {
54  InstantController::Enable(profile_);
55  return true;
56}
57
58bool InstantConfirmView::Cancel() {
59  return true;
60}
61
62views::View* InstantConfirmView::GetContentsView() {
63  return this;
64}
65
66std::wstring InstantConfirmView::GetWindowTitle() const {
67  return UTF16ToWide(l10n_util::GetStringUTF16(IDS_INSTANT_OPT_IN_TITLE));
68}
69
70gfx::Size InstantConfirmView::GetPreferredSize() {
71  DCHECK(GetLayoutManager());
72  int pref_width = views::Window::GetLocalizedContentsWidth(
73      IDS_INSTANT_CONFIRM_DIALOG_WIDTH_CHARS);
74  int pref_height =
75      GetLayoutManager()->GetPreferredHeightForWidth(this, pref_width);
76  return gfx::Size(pref_width, pref_height);
77}
78
79bool InstantConfirmView::IsModal() const {
80  return true;
81}
82
83void InstantConfirmView::LinkActivated(views::Link* source, int event_flags) {
84  Browser* browser = BrowserList::GetLastActive();
85  browser->OpenURL(browser::InstantLearnMoreURL(), GURL(),
86                   NEW_FOREGROUND_TAB, PageTransition::TYPED);
87}
88
89namespace browser {
90
91void ShowInstantConfirmDialog(gfx::NativeWindow parent, Profile* profile) {
92  views::Window::CreateChromeWindow(parent, gfx::Rect(),
93                                    new InstantConfirmView(profile))->Show();
94}
95
96}  // namespace browser
97