| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/input_window_dialog.h" | 5 #include "chrome/browser/input_window_dialog.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| 11 #include "views/grid_layout.h" | 11 #include "views/grid_layout.h" |
| 12 #include "views/controls/label.h" | 12 #include "views/controls/label.h" |
| 13 #include "views/controls/text_field.h" | 13 #include "views/controls/textfield/textfield.h" |
| 14 #include "views/standard_layout.h" | 14 #include "views/standard_layout.h" |
| 15 #include "views/window/dialog_delegate.h" | 15 #include "views/window/dialog_delegate.h" |
| 16 #include "views/window/window.h" | 16 #include "views/window/window.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 | 18 |
| 19 // Width to make the text field, in pixels. | 19 // Width to make the text field, in pixels. |
| 20 static const int kTextFieldWidth = 200; | 20 static const int kTextfieldWidth = 200; |
| 21 | 21 |
| 22 class ContentView; | 22 class ContentView; |
| 23 | 23 |
| 24 // The Windows implementation of the cross platform input dialog interface. | 24 // The Windows implementation of the cross platform input dialog interface. |
| 25 class WinInputWindowDialog : public InputWindowDialog { | 25 class WinInputWindowDialog : public InputWindowDialog { |
| 26 public: | 26 public: |
| 27 WinInputWindowDialog(HWND parent, | 27 WinInputWindowDialog(HWND parent, |
| 28 const std::wstring& window_title, | 28 const std::wstring& window_title, |
| 29 const std::wstring& label, | 29 const std::wstring& label, |
| 30 const std::wstring& contents, | 30 const std::wstring& contents, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 std::wstring contents_; | 50 std::wstring contents_; |
| 51 | 51 |
| 52 // Our delegate. Consumes the window's output. | 52 // Our delegate. Consumes the window's output. |
| 53 scoped_ptr<InputWindowDialog::Delegate> delegate_; | 53 scoped_ptr<InputWindowDialog::Delegate> delegate_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // 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. |
| 57 // It registers accelerators that accept/cancel the input. | 57 // It registers accelerators that accept/cancel the input. |
| 58 class ContentView : public views::View, | 58 class ContentView : public views::View, |
| 59 public views::DialogDelegate, | 59 public views::DialogDelegate, |
| 60 public views::TextField::Controller { | 60 public views::Textfield::Controller { |
| 61 public: | 61 public: |
| 62 explicit ContentView(WinInputWindowDialog* delegate) | 62 explicit ContentView(WinInputWindowDialog* delegate) |
| 63 : delegate_(delegate), | 63 : delegate_(delegate), |
| 64 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { | 64 ALLOW_THIS_IN_INITIALIZER_LIST(focus_grabber_factory_(this)) { |
| 65 DCHECK(delegate_); | 65 DCHECK(delegate_); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // views::DialogDelegate overrides: | 68 // views::DialogDelegate overrides: |
| 69 virtual bool IsDialogButtonEnabled( | 69 virtual bool IsDialogButtonEnabled( |
| 70 MessageBoxFlags::DialogButton button) const; | 70 MessageBoxFlags::DialogButton button) const; |
| 71 virtual bool Accept(); | 71 virtual bool Accept(); |
| 72 virtual bool Cancel(); | 72 virtual bool Cancel(); |
| 73 virtual void DeleteDelegate(); | 73 virtual void DeleteDelegate(); |
| 74 virtual std::wstring GetWindowTitle() const; | 74 virtual std::wstring GetWindowTitle() const; |
| 75 virtual bool IsModal() const { return true; } | 75 virtual bool IsModal() const { return true; } |
| 76 virtual views::View* GetContentsView(); | 76 virtual views::View* GetContentsView(); |
| 77 | 77 |
| 78 // views::TextField::Controller overrides: | 78 // views::Textfield::Controller overrides: |
| 79 virtual void ContentsChanged(views::TextField* sender, | 79 virtual void ContentsChanged(views::Textfield* sender, |
| 80 const std::wstring& new_contents); | 80 const std::wstring& new_contents); |
| 81 virtual bool HandleKeystroke(views::TextField*, | 81 virtual bool HandleKeystroke(views::Textfield*, |
| 82 const views::TextField::Keystroke&) { | 82 const views::Textfield::Keystroke&) { |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 protected: | 86 protected: |
| 87 // views::View overrides: | 87 // views::View overrides: |
| 88 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, | 88 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, |
| 89 views::View* child); | 89 views::View* child); |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 // Set up dialog controls and layout. | 92 // Set up dialog controls and layout. |
| 93 void InitControlLayout(); | 93 void InitControlLayout(); |
| 94 | 94 |
| 95 // Sets focus to the first focusable element within the dialog. | 95 // Sets focus to the first focusable element within the dialog. |
| 96 void FocusFirstFocusableControl(); | 96 void FocusFirstFocusableControl(); |
| 97 | 97 |
| 98 // The TextField that the user can type into. | 98 // The Textfield that the user can type into. |
| 99 views::TextField* text_field_; | 99 views::Textfield* text_field_; |
| 100 | 100 |
| 101 // The delegate that the ContentView uses to communicate changes to the | 101 // The delegate that the ContentView uses to communicate changes to the |
| 102 // caller. | 102 // caller. |
| 103 WinInputWindowDialog* delegate_; | 103 WinInputWindowDialog* delegate_; |
| 104 | 104 |
| 105 // Helps us set focus to the first TextField in the window. | 105 // Helps us set focus to the first Textfield in the window. |
| 106 ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; | 106 ScopedRunnableMethodFactory<ContentView> focus_grabber_factory_; |
| 107 | 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(ContentView); | 108 DISALLOW_COPY_AND_ASSIGN(ContentView); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
| 112 // ContentView, views::DialogDelegate implementation: | 112 // ContentView, views::DialogDelegate implementation: |
| 113 | 113 |
| 114 bool ContentView::IsDialogButtonEnabled( | 114 bool ContentView::IsDialogButtonEnabled( |
| 115 MessageBoxFlags::DialogButton button) const { | 115 MessageBoxFlags::DialogButton button) const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 136 | 136 |
| 137 std::wstring ContentView::GetWindowTitle() const { | 137 std::wstring ContentView::GetWindowTitle() const { |
| 138 return delegate_->window_title(); | 138 return delegate_->window_title(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 views::View* ContentView::GetContentsView() { | 141 views::View* ContentView::GetContentsView() { |
| 142 return this; | 142 return this; |
| 143 } | 143 } |
| 144 | 144 |
| 145 /////////////////////////////////////////////////////////////////////////////// | 145 /////////////////////////////////////////////////////////////////////////////// |
| 146 // ContentView, views::TextField::Controller implementation: | 146 // ContentView, views::Textfield::Controller implementation: |
| 147 | 147 |
| 148 void ContentView::ContentsChanged(views::TextField* sender, | 148 void ContentView::ContentsChanged(views::Textfield* sender, |
| 149 const std::wstring& new_contents) { | 149 const std::wstring& new_contents) { |
| 150 GetDialogClientView()->UpdateDialogButtons(); | 150 GetDialogClientView()->UpdateDialogButtons(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 /////////////////////////////////////////////////////////////////////////////// | 153 /////////////////////////////////////////////////////////////////////////////// |
| 154 // ContentView, protected: | 154 // ContentView, protected: |
| 155 | 155 |
| 156 void ContentView::ViewHierarchyChanged(bool is_add, | 156 void ContentView::ViewHierarchyChanged(bool is_add, |
| 157 views::View* parent, | 157 views::View* parent, |
| 158 views::View* child) { | 158 views::View* child) { |
| 159 if (is_add && child == this) | 159 if (is_add && child == this) |
| 160 InitControlLayout(); | 160 InitControlLayout(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /////////////////////////////////////////////////////////////////////////////// | 163 /////////////////////////////////////////////////////////////////////////////// |
| 164 // ContentView, private: | 164 // ContentView, private: |
| 165 | 165 |
| 166 void ContentView::InitControlLayout() { | 166 void ContentView::InitControlLayout() { |
| 167 text_field_ = new views::TextField; | 167 text_field_ = new views::Textfield; |
| 168 text_field_->SetText(delegate_->contents()); | 168 text_field_->SetText(delegate_->contents()); |
| 169 text_field_->SetController(this); | 169 text_field_->SetController(this); |
| 170 | 170 |
| 171 using views::ColumnSet; | 171 using views::ColumnSet; |
| 172 using views::GridLayout; | 172 using views::GridLayout; |
| 173 | 173 |
| 174 // TODO(sky): Vertical alignment should be baseline. | 174 // TODO(sky): Vertical alignment should be baseline. |
| 175 GridLayout* layout = CreatePanelGridLayout(this); | 175 GridLayout* layout = CreatePanelGridLayout(this); |
| 176 SetLayoutManager(layout); | 176 SetLayoutManager(layout); |
| 177 | 177 |
| 178 ColumnSet* c1 = layout->AddColumnSet(0); | 178 ColumnSet* c1 = layout->AddColumnSet(0); |
| 179 c1->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 179 c1->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 180 GridLayout::USE_PREF, 0, 0); | 180 GridLayout::USE_PREF, 0, 0); |
| 181 c1->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 181 c1->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 182 c1->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 182 c1->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 183 GridLayout::USE_PREF, kTextFieldWidth, kTextFieldWidth); | 183 GridLayout::USE_PREF, kTextfieldWidth, kTextfieldWidth); |
| 184 | 184 |
| 185 layout->StartRow(0, 0); | 185 layout->StartRow(0, 0); |
| 186 views::Label* label = new views::Label(delegate_->label()); | 186 views::Label* label = new views::Label(delegate_->label()); |
| 187 layout->AddView(label); | 187 layout->AddView(label); |
| 188 layout->AddView(text_field_); | 188 layout->AddView(text_field_); |
| 189 | 189 |
| 190 MessageLoop::current()->PostTask(FROM_HERE, | 190 MessageLoop::current()->PostTask(FROM_HERE, |
| 191 focus_grabber_factory_.NewRunnableMethod( | 191 focus_grabber_factory_.NewRunnableMethod( |
| 192 &ContentView::FocusFirstFocusableControl)); | 192 &ContentView::FocusFirstFocusableControl)); |
| 193 } | 193 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 const std::wstring& window_title, | 227 const std::wstring& window_title, |
| 228 const std::wstring& label, | 228 const std::wstring& label, |
| 229 const std::wstring& contents, | 229 const std::wstring& contents, |
| 230 Delegate* delegate) { | 230 Delegate* delegate) { |
| 231 return new WinInputWindowDialog(parent, | 231 return new WinInputWindowDialog(parent, |
| 232 window_title, | 232 window_title, |
| 233 label, | 233 label, |
| 234 contents, | 234 contents, |
| 235 delegate); | 235 delegate); |
| 236 } | 236 } |
| OLD | NEW |