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