OLD | NEW |
(Empty) | |
| 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/chromeos/login/captcha_view.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/login/image_downloader.h" |
| 11 #include "grit/chromium_strings.h" |
| 12 #include "grit/generated_resources.h" |
| 13 #include "grit/locale_settings.h" |
| 14 #include "views/controls/image_view.h" |
| 15 #include "views/controls/label.h" |
| 16 #include "views/grid_layout.h" |
| 17 #include "views/standard_layout.h" |
| 18 #include "views/widget/widget_gtk.h" |
| 19 #include "views/window/window.h" |
| 20 |
| 21 using views::Label; |
| 22 using views::Textfield; |
| 23 using views::WidgetGtk; |
| 24 |
| 25 namespace chromeos { |
| 26 |
| 27 CaptchaView::CaptchaView(const GURL& captcha_url) |
| 28 : delegate_(NULL), |
| 29 captcha_url_(captcha_url), |
| 30 captcha_image_(NULL), |
| 31 captcha_textfield_(NULL) { |
| 32 } |
| 33 |
| 34 bool CaptchaView::Accept() { |
| 35 if (delegate_) |
| 36 delegate_->OnCaptchaEntered(UTF16ToUTF8(captcha_textfield_->text())); |
| 37 return true; |
| 38 } |
| 39 |
| 40 std::wstring CaptchaView::GetWindowTitle() const { |
| 41 return l10n_util::GetString(IDS_LOGIN_CAPTCHA_DIALOG_TITLE); |
| 42 } |
| 43 |
| 44 gfx::Size CaptchaView::GetPreferredSize() { |
| 45 // TODO(nkostylev): Once UI is finalized, create locale settings. |
| 46 return gfx::Size(views::Window::GetLocalizedContentsSize( |
| 47 IDS_CAPTCHA_INPUT_DIALOG_WIDTH_CHARS, |
| 48 IDS_CAPTCHA_INPUT_DIALOG_HEIGHT_LINES)); |
| 49 } |
| 50 |
| 51 void CaptchaView::ViewHierarchyChanged(bool is_add, |
| 52 views::View* parent, |
| 53 views::View* child) { |
| 54 // Can't init before we're inserted into a Container, because we require |
| 55 // a HWND to parent native child controls to. |
| 56 if (is_add && child == this) |
| 57 Init(); |
| 58 } |
| 59 |
| 60 bool CaptchaView::HandleKeystroke(views::Textfield* sender, |
| 61 const views::Textfield::Keystroke& keystroke) { |
| 62 return false; |
| 63 } |
| 64 |
| 65 void CaptchaView::OnImageDecoded(const SkBitmap& decoded_image) { |
| 66 captcha_image_->SetImage(decoded_image); |
| 67 SchedulePaint(); |
| 68 Layout(); |
| 69 } |
| 70 |
| 71 void CaptchaView::Init() { |
| 72 views::GridLayout* layout = CreatePanelGridLayout(this); |
| 73 SetLayoutManager(layout); |
| 74 |
| 75 int column_view_set_id = 0; |
| 76 views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id); |
| 77 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 78 views::GridLayout::USE_PREF, 0, 0); |
| 79 layout->StartRow(0, column_view_set_id); |
| 80 Label* label = |
| 81 new views::Label(l10n_util::GetString(IDS_LOGIN_CAPTCHA_INSTRUCTIONS)); |
| 82 label->SetMultiLine(true); |
| 83 layout->AddView(label); |
| 84 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 85 |
| 86 layout->StartRow(0, column_view_set_id); |
| 87 captcha_image_ = new views::ImageView(); |
| 88 layout->AddView(captcha_image_); |
| 89 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 90 |
| 91 layout->StartRow(0, column_view_set_id); |
| 92 captcha_textfield_ = new views::Textfield( |
| 93 views::Textfield::STYLE_DEFAULT); |
| 94 captcha_textfield_->SetController(this); |
| 95 layout->AddView(captcha_textfield_); |
| 96 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 97 |
| 98 layout->StartRow(0, column_view_set_id); |
| 99 label = new views::Label( |
| 100 l10n_util::GetString(IDS_SYNC_GAIA_CAPTCHA_CASE_INSENSITIVE_TIP)); |
| 101 label->SetMultiLine(true); |
| 102 layout->AddView(label); |
| 103 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 104 |
| 105 captcha_textfield_->RequestFocus(); |
| 106 |
| 107 // ImageDownloader will disable itself once URL is fetched. |
| 108 new ImageDownloader(this, GURL(captcha_url_), std::string()); |
| 109 } |
| 110 |
| 111 } // namespace chromeos |
OLD | NEW |