| 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 #ifndef CHROME_BROWSER_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ |
| 6 #define CHROME_BROWSER_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ |
| 7 |
| 8 #include "chrome/browser/input_window_dialog.h" |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "base/task.h" |
| 13 #include "views/controls/label.h" |
| 14 #include "views/controls/textfield/textfield.h" |
| 15 #include "views/window/dialog_delegate.h" |
| 16 #include "views/window/window.h" |
| 17 |
| 18 // The Windows implementation of the cross platform input dialog interface. |
| 19 class InputWindowDialogWin : public InputWindowDialog { |
| 20 public: |
| 21 InputWindowDialogWin(gfx::NativeWindow parent, |
| 22 const std::wstring& window_title, |
| 23 const std::wstring& label, |
| 24 const std::wstring& contents, |
| 25 Delegate* delegate); |
| 26 virtual ~InputWindowDialogWin(); |
| 27 |
| 28 virtual void Show(); |
| 29 virtual void Close(); |
| 30 |
| 31 const std::wstring& window_title() const { return window_title_; } |
| 32 const std::wstring& label() const { return label_; } |
| 33 const std::wstring& contents() const { return contents_; } |
| 34 |
| 35 InputWindowDialog::Delegate* delegate() { return delegate_.get(); } |
| 36 |
| 37 private: |
| 38 // Our chrome views window. |
| 39 views::Window* window_; |
| 40 |
| 41 // Strings to feed to the on screen window. |
| 42 std::wstring window_title_; |
| 43 std::wstring label_; |
| 44 std::wstring contents_; |
| 45 |
| 46 // Our delegate. Consumes the window's output. |
| 47 scoped_ptr<InputWindowDialog::Delegate> delegate_; |
| 48 }; |
| 49 |
| 50 // ContentView, as the name implies, is the content view for the InputWindow. |
| 51 // It registers accelerators that accept/cancel the input. |
| 52 class ContentView : public views::View, |
| 53 public views::DialogDelegate, |
| 54 public views::Textfield::Controller { |
| 55 public: |
| 56 explicit ContentView(InputWindowDialogWin* delegate) |
| 57 : delegate_(delegate), |
| 58 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { |
| 59 DCHECK(delegate_); |
| 60 } |
| 61 |
| 62 // views::DialogDelegate overrides: |
| 63 virtual bool IsDialogButtonEnabled( |
| 64 MessageBoxFlags::DialogButton button) const; |
| 65 virtual bool Accept(); |
| 66 virtual bool Cancel(); |
| 67 virtual void DeleteDelegate() { delete delegate_; } |
| 68 virtual std::wstring GetWindowTitle() const; |
| 69 virtual bool IsModal() const { return true; } |
| 70 virtual views::View* GetContentsView() { return this; } |
| 71 |
| 72 // views::Textfield::Controller overrides: |
| 73 virtual void ContentsChanged(views::Textfield* sender, |
| 74 const std::wstring& new_contents); |
| 75 virtual bool HandleKeystroke(views::Textfield*, |
| 76 const views::Textfield::Keystroke&) { |
| 77 return false; |
| 78 } |
| 79 |
| 80 protected: |
| 81 // views::View overrides: |
| 82 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 83 views::View* child); |
| 84 |
| 85 private: |
| 86 // Set up dialog controls and layout. |
| 87 void InitControlLayout(); |
| 88 |
| 89 // Sets focus to the first focusable element within the dialog. |
| 90 void FocusFirstFocusableControl(); |
| 91 |
| 92 // The Textfield that the user can type into. |
| 93 views::Textfield* text_field_; |
| 94 |
| 95 // The delegate that the ContentView uses to communicate changes to the |
| 96 // caller. |
| 97 InputWindowDialogWin* delegate_; |
| 98 |
| 99 // Helps us set focus to the first Textfield in the window. |
| 100 ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(ContentView); |
| 103 }; |
| 104 |
| 105 #endif // CHROME_BROWSER_VIEWS_INPUT_WINDOW_DIALOG_WIN_H_ |
| OLD | NEW |