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 "views/window/dialog_client_view.h" | 5 #include "views/window/dialog_client_view.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 ui::DialogButton type, | 70 ui::DialogButton type, |
71 const string16& title, | 71 const string16& title, |
72 bool is_default) | 72 bool is_default) |
73 : NativeTextButton(listener, title), | 73 : NativeTextButton(listener, title), |
74 owner_(owner), | 74 owner_(owner), |
75 type_(type) { | 75 type_(type) { |
76 SetIsDefault(is_default); | 76 SetIsDefault(is_default); |
77 } | 77 } |
78 | 78 |
79 // Overridden to forward to the delegate. | 79 // Overridden to forward to the delegate. |
80 virtual bool AcceleratorPressed(const Accelerator& accelerator) { | 80 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
81 if (!owner_->widget_delegate()->AsDialogDelegate()-> | 81 if (!owner_->widget_delegate()->AsDialogDelegate()-> |
82 AreAcceleratorsEnabled(type_)) { | 82 AreAcceleratorsEnabled(type_)) { |
83 return false; | 83 return false; |
84 } | 84 } |
85 return NativeTextButton::AcceleratorPressed(accelerator); | 85 return NativeTextButton::AcceleratorPressed(accelerator); |
86 } | 86 } |
87 | 87 |
88 private: | 88 private: |
89 Widget* owner_; | 89 Widget* owner_; |
90 const ui::DialogButton type_; | 90 const ui::DialogButton type_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; | 135 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; |
136 ok_button_ = new DialogButton(this, | 136 ok_button_ = new DialogButton(this, |
137 GetWidget(), | 137 GetWidget(), |
138 ui::DIALOG_BUTTON_OK, | 138 ui::DIALOG_BUTTON_OK, |
139 label, | 139 label, |
140 is_default_button); | 140 is_default_button); |
141 ok_button_->SetGroup(kButtonGroup); | 141 ok_button_->SetGroup(kButtonGroup); |
142 if (is_default_button) | 142 if (is_default_button) |
143 default_button_ = ok_button_; | 143 default_button_ = ok_button_; |
144 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) | 144 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
145 ok_button_->AddAccelerator(Accelerator(ui::VKEY_ESCAPE, | 145 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, |
146 false, false, false)); | 146 false, false, false)); |
147 AddChildView(ok_button_); | 147 AddChildView(ok_button_); |
148 } | 148 } |
149 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { | 149 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { |
150 string16 label = | 150 string16 label = |
151 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); | 151 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); |
152 if (label.empty()) { | 152 if (label.empty()) { |
153 if (buttons & ui::DIALOG_BUTTON_OK) { | 153 if (buttons & ui::DIALOG_BUTTON_OK) { |
154 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); | 154 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); |
155 } else { | 155 } else { |
156 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); | 156 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); |
157 } | 157 } |
158 } | 158 } |
159 bool is_default_button = | 159 bool is_default_button = |
160 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 160 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
161 != 0; | 161 != 0; |
162 cancel_button_ = new DialogButton(this, | 162 cancel_button_ = new DialogButton(this, |
163 GetWidget(), | 163 GetWidget(), |
164 ui::DIALOG_BUTTON_CANCEL, | 164 ui::DIALOG_BUTTON_CANCEL, |
165 label, | 165 label, |
166 is_default_button); | 166 is_default_button); |
167 cancel_button_->SetGroup(kButtonGroup); | 167 cancel_button_->SetGroup(kButtonGroup); |
168 cancel_button_->AddAccelerator(Accelerator(ui::VKEY_ESCAPE, | 168 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, |
169 false, false, false)); | 169 false, false, false)); |
170 if (is_default_button) | 170 if (is_default_button) |
171 default_button_ = ok_button_; | 171 default_button_ = ok_button_; |
172 AddChildView(cancel_button_); | 172 AddChildView(cancel_button_); |
173 } | 173 } |
174 if (!buttons) { | 174 if (!buttons) { |
175 // Register the escape key as an accelerator which will close the window | 175 // Register the escape key as an accelerator which will close the window |
176 // if there are no dialog buttons. | 176 // if there are no dialog buttons. |
177 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, false, false, false)); | 177 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, false, false, false)); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { | 181 void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { |
182 if (default_button_ && default_button_ != new_default_button) { | 182 if (default_button_ && default_button_ != new_default_button) { |
183 default_button_->SetIsDefault(false); | 183 default_button_->SetIsDefault(false); |
184 default_button_ = NULL; | 184 default_button_ = NULL; |
185 } | 185 } |
186 | 186 |
187 if (new_default_button) { | 187 if (new_default_button) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 399 } |
400 } | 400 } |
401 if (bottom_view_) { | 401 if (bottom_view_) { |
402 gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); | 402 gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); |
403 prefsize.Enlarge(0, bottom_pref.height() + kButtonVEdgeMargin); | 403 prefsize.Enlarge(0, bottom_pref.height() + kButtonVEdgeMargin); |
404 } | 404 } |
405 prefsize.Enlarge(0, button_height); | 405 prefsize.Enlarge(0, button_height); |
406 return prefsize; | 406 return prefsize; |
407 } | 407 } |
408 | 408 |
409 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { | 409 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
410 // We only expect Escape key. | 410 // We only expect Escape key. |
411 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); | 411 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); |
412 Close(); | 412 Close(); |
413 return true; | 413 return true; |
414 } | 414 } |
415 | 415 |
416 //////////////////////////////////////////////////////////////////////////////// | 416 //////////////////////////////////////////////////////////////////////////////// |
417 // DialogClientView, ButtonListener implementation: | 417 // DialogClientView, ButtonListener implementation: |
418 | 418 |
419 void DialogClientView::ButtonPressed( | 419 void DialogClientView::ButtonPressed( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 void DialogClientView::InitClass() { | 582 void DialogClientView::InitClass() { |
583 static bool initialized = false; | 583 static bool initialized = false; |
584 if (!initialized) { | 584 if (!initialized) { |
585 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 585 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
586 dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); | 586 dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); |
587 initialized = true; | 587 initialized = true; |
588 } | 588 } |
589 } | 589 } |
590 | 590 |
591 } // namespace views | 591 } // namespace views |
OLD | NEW |