| OLD | NEW |
| 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/input_window_dialog.h" | 5 #include "chrome/browser/ui/input_window_dialog.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/task.h" | 9 #include "base/task.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "views/controls/label.h" | 11 #include "views/controls/label.h" |
| 12 #include "views/controls/textfield/textfield.h" | 12 #include "views/controls/textfield/textfield.h" |
| 13 #include "views/controls/textfield/textfield_controller.h" |
| 13 #include "views/layout/grid_layout.h" | 14 #include "views/layout/grid_layout.h" |
| 14 #include "views/layout/layout_constants.h" | 15 #include "views/layout/layout_constants.h" |
| 15 #include "views/window/dialog_delegate.h" | 16 #include "views/window/dialog_delegate.h" |
| 16 #include "views/window/window.h" | 17 #include "views/window/window.h" |
| 17 | 18 |
| 18 // Width to make the text field, in pixels. | 19 // Width to make the text field, in pixels. |
| 19 static const int kTextfieldWidth = 200; | 20 static const int kTextfieldWidth = 200; |
| 20 | 21 |
| 21 class ContentView; | 22 class ContentView; |
| 22 | 23 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 49 std::wstring contents_; | 50 std::wstring contents_; |
| 50 | 51 |
| 51 // Our delegate. Consumes the window's output. | 52 // Our delegate. Consumes the window's output. |
| 52 scoped_ptr<InputWindowDialog::Delegate> delegate_; | 53 scoped_ptr<InputWindowDialog::Delegate> delegate_; |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 // ContentView, as the name implies, is the content view for the InputWindow. | 56 // ContentView, as the name implies, is the content view for the InputWindow. |
| 56 // It registers accelerators that accept/cancel the input. | 57 // It registers accelerators that accept/cancel the input. |
| 57 class ContentView : public views::View, | 58 class ContentView : public views::View, |
| 58 public views::DialogDelegate, | 59 public views::DialogDelegate, |
| 59 public views::Textfield::Controller { | 60 public views::TextfieldController { |
| 60 public: | 61 public: |
| 61 explicit ContentView(WinInputWindowDialog* delegate) | 62 explicit ContentView(WinInputWindowDialog* delegate) |
| 62 : delegate_(delegate), | 63 : delegate_(delegate), |
| 63 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { | 64 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { |
| 64 DCHECK(delegate_); | 65 DCHECK(delegate_); |
| 65 } | 66 } |
| 66 | 67 |
| 67 // views::DialogDelegate overrides: | 68 // views::DialogDelegate: |
| 68 virtual bool IsDialogButtonEnabled( | 69 virtual bool IsDialogButtonEnabled( |
| 69 MessageBoxFlags::DialogButton button) const; | 70 MessageBoxFlags::DialogButton button) const; |
| 70 virtual bool Accept(); | 71 virtual bool Accept(); |
| 71 virtual bool Cancel(); | 72 virtual bool Cancel(); |
| 72 virtual void DeleteDelegate(); | 73 virtual void DeleteDelegate(); |
| 73 virtual std::wstring GetWindowTitle() const; | 74 virtual std::wstring GetWindowTitle() const; |
| 74 virtual bool IsModal() const { return true; } | 75 virtual bool IsModal() const { return true; } |
| 75 virtual views::View* GetContentsView(); | 76 virtual views::View* GetContentsView(); |
| 76 | 77 |
| 77 // views::Textfield::Controller overrides: | 78 // views::TextfieldController: |
| 78 virtual void ContentsChanged(views::Textfield* sender, | 79 virtual void ContentsChanged(views::Textfield* sender, |
| 79 const std::wstring& new_contents); | 80 const std::wstring& new_contents); |
| 80 virtual bool HandleKeyEvent(views::Textfield*, | 81 virtual bool HandleKeyEvent(views::Textfield*, |
| 81 const views::KeyEvent&) { | 82 const views::KeyEvent&) { |
| 82 return false; | 83 return false; |
| 83 } | 84 } |
| 84 | 85 |
| 85 protected: | 86 protected: |
| 86 // views::View overrides: | 87 // views::View: |
| 87 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, | 88 virtual void ViewHierarchyChanged(bool is_add, |
| 89 views::View* parent, |
| 88 views::View* child); | 90 views::View* child); |
| 89 | 91 |
| 90 private: | 92 private: |
| 91 // Set up dialog controls and layout. | 93 // Set up dialog controls and layout. |
| 92 void InitControlLayout(); | 94 void InitControlLayout(); |
| 93 | 95 |
| 94 // Sets focus to the first focusable element within the dialog. | 96 // Sets focus to the first focusable element within the dialog. |
| 95 void FocusFirstFocusableControl(); | 97 void FocusFirstFocusableControl(); |
| 96 | 98 |
| 97 // The Textfield that the user can type into. | 99 // The Textfield that the user can type into. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 137 |
| 136 std::wstring ContentView::GetWindowTitle() const { | 138 std::wstring ContentView::GetWindowTitle() const { |
| 137 return delegate_->window_title(); | 139 return delegate_->window_title(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 views::View* ContentView::GetContentsView() { | 142 views::View* ContentView::GetContentsView() { |
| 141 return this; | 143 return this; |
| 142 } | 144 } |
| 143 | 145 |
| 144 /////////////////////////////////////////////////////////////////////////////// | 146 /////////////////////////////////////////////////////////////////////////////// |
| 145 // ContentView, views::Textfield::Controller implementation: | 147 // ContentView, views::TextfieldController implementation: |
| 146 | 148 |
| 147 void ContentView::ContentsChanged(views::Textfield* sender, | 149 void ContentView::ContentsChanged(views::Textfield* sender, |
| 148 const std::wstring& new_contents) { | 150 const std::wstring& new_contents) { |
| 149 GetDialogClientView()->UpdateDialogButtons(); | 151 GetDialogClientView()->UpdateDialogButtons(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 /////////////////////////////////////////////////////////////////////////////// | 154 /////////////////////////////////////////////////////////////////////////////// |
| 153 // ContentView, protected: | 155 // ContentView, protected: |
| 154 | 156 |
| 155 void ContentView::ViewHierarchyChanged(bool is_add, | 157 void ContentView::ViewHierarchyChanged(bool is_add, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 const std::wstring& window_title, | 228 const std::wstring& window_title, |
| 227 const std::wstring& label, | 229 const std::wstring& label, |
| 228 const std::wstring& contents, | 230 const std::wstring& contents, |
| 229 Delegate* delegate) { | 231 Delegate* delegate) { |
| 230 return new WinInputWindowDialog(parent, | 232 return new WinInputWindowDialog(parent, |
| 231 window_title, | 233 window_title, |
| 232 label, | 234 label, |
| 233 contents, | 235 contents, |
| 234 delegate); | 236 delegate); |
| 235 } | 237 } |
| OLD | NEW |