| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/chromeos/login/image_decoder.h" | 11 #include "chrome/browser/chromeos/login/image_decoder.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "views/controls/button/button.h" | 13 #include "views/controls/button/button.h" |
| 14 #include "views/controls/textfield/textfield.h" | 14 #include "views/controls/textfield/textfield_controller.h" |
| 15 #include "views/window/dialog_delegate.h" | 15 #include "views/window/dialog_delegate.h" |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 class ImageView; | 18 class ImageView; |
| 19 class TextButton; | 19 class TextButton; |
| 20 class View; | 20 class View; |
| 21 class Window; | 21 class Window; |
| 22 } // namespace views | 22 } // namespace views |
| 23 | 23 |
| 24 namespace chromeos { | 24 namespace chromeos { |
| 25 | 25 |
| 26 // A dialog box that shows a CAPTCHA image and allows user to input response. | 26 // A dialog box that shows a CAPTCHA image and allows user to input response. |
| 27 class CaptchaView : public views::View, | 27 class CaptchaView : public views::View, |
| 28 public views::DialogDelegate, | 28 public views::DialogDelegate, |
| 29 public views::Textfield::Controller, | 29 public views::TextfieldController, |
| 30 public ImageDecoder::Delegate, | 30 public ImageDecoder::Delegate, |
| 31 public views::ButtonListener { | 31 public views::ButtonListener { |
| 32 public: | 32 public: |
| 33 class Delegate { | 33 class Delegate { |
| 34 public: | 34 public: |
| 35 // Called when CAPTCHA answer has been entered. | 35 // Called when CAPTCHA answer has been entered. |
| 36 virtual void OnCaptchaEntered(const std::string& captcha) = 0; | 36 virtual void OnCaptchaEntered(const std::string& captcha) = 0; |
| 37 | 37 |
| 38 protected: | 38 protected: |
| 39 virtual ~Delegate() {} | 39 virtual ~Delegate() {} |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 // |captcha_url| represents CAPTCHA image URL. | 42 // |captcha_url| represents CAPTCHA image URL. |
| 43 // |is_standalone| is true when CaptchaView is not presented as dialog. | 43 // |is_standalone| is true when CaptchaView is not presented as dialog. |
| 44 CaptchaView(const GURL& captcha_url, bool is_standalone); | 44 CaptchaView(const GURL& captcha_url, bool is_standalone); |
| 45 virtual ~CaptchaView() {} | 45 virtual ~CaptchaView() {} |
| 46 | 46 |
| 47 // views::DialogDelegate overrides: | 47 // views::DialogDelegate: |
| 48 virtual bool Accept(); | 48 virtual bool Accept(); |
| 49 | |
| 50 // views::WindowDelegate overrides: | |
| 51 virtual bool IsModal() const { return true; } | 49 virtual bool IsModal() const { return true; } |
| 52 virtual views::View* GetContentsView() { return this; } | 50 virtual views::View* GetContentsView() { return this; } |
| 53 | |
| 54 // views::View overrides: | |
| 55 virtual std::wstring GetWindowTitle() const; | 51 virtual std::wstring GetWindowTitle() const; |
| 56 | 52 |
| 57 // views::Textfield::Controller implementation: | 53 // views::TextfieldController: |
| 58 virtual void ContentsChanged(views::Textfield* sender, | 54 virtual void ContentsChanged(views::Textfield* sender, |
| 59 const string16& new_contents) {} | 55 const string16& new_contents) {} |
| 60 virtual bool HandleKeyEvent(views::Textfield* sender, | 56 virtual bool HandleKeyEvent(views::Textfield* sender, |
| 61 const views::KeyEvent& key_event); | 57 const views::KeyEvent& key_event); |
| 62 | 58 |
| 63 // Overriden from ImageDownloader::Delegate: | 59 // ImageDownloader::Delegate: |
| 64 virtual void OnImageDecoded(const SkBitmap& decoded_image); | 60 virtual void OnImageDecoded(const SkBitmap& decoded_image); |
| 65 | 61 |
| 66 // Overridden from views::ButtonListener. | 62 // views::ButtonListener: |
| 67 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | 63 virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
| 68 | 64 |
| 69 // Initializes UI. | 65 // Initializes UI. |
| 70 void Init(); | 66 void Init(); |
| 71 | 67 |
| 72 void set_delegate(Delegate* delegate) { | 68 void set_delegate(Delegate* delegate) { |
| 73 delegate_ = delegate; | 69 delegate_ = delegate; |
| 74 } | 70 } |
| 75 | 71 |
| 76 // Instructs to download and display another captcha image. | 72 // Instructs to download and display another captcha image. |
| 77 // Is used when same CaptchaView is reused. | 73 // Is used when same CaptchaView is reused. |
| 78 void SetCaptchaURL(const GURL& captcha_url); | 74 void SetCaptchaURL(const GURL& captcha_url); |
| 79 | 75 |
| 80 protected: | 76 protected: |
| 81 // views::View overrides: | 77 // views::View: |
| 82 virtual gfx::Size GetPreferredSize(); | 78 virtual gfx::Size GetPreferredSize(); |
| 83 virtual void ViewHierarchyChanged(bool is_add, | 79 virtual void ViewHierarchyChanged(bool is_add, |
| 84 views::View* parent, | 80 views::View* parent, |
| 85 views::View* child); | 81 views::View* child); |
| 86 | 82 |
| 87 private: | 83 private: |
| 88 Delegate* delegate_; | 84 Delegate* delegate_; |
| 89 GURL captcha_url_; | 85 GURL captcha_url_; |
| 90 views::ImageView* captcha_image_; | 86 views::ImageView* captcha_image_; |
| 91 views::Textfield* captcha_textfield_; | 87 views::Textfield* captcha_textfield_; |
| 92 | 88 |
| 93 // True when view is not hosted inside dialog, | 89 // True when view is not hosted inside dialog, |
| 94 // thus should draw OK button/background. | 90 // thus should draw OK button/background. |
| 95 bool is_standalone_; | 91 bool is_standalone_; |
| 96 | 92 |
| 97 // Used in standalone mode. | 93 // Used in standalone mode. |
| 98 views::TextButton* ok_button_; | 94 views::TextButton* ok_button_; |
| 99 | 95 |
| 100 DISALLOW_COPY_AND_ASSIGN(CaptchaView); | 96 DISALLOW_COPY_AND_ASSIGN(CaptchaView); |
| 101 }; | 97 }; |
| 102 | 98 |
| 103 } // namespace chromeos | 99 } // namespace chromeos |
| 104 | 100 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ | 101 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_CAPTCHA_VIEW_H_ |
| OLD | NEW |