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