OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/dialog_delegate.h" | 5 #include "chrome/views/dialog_delegate.h" |
6 | 6 |
7 #include "chrome/views/window.h" | 7 #include "chrome/views/window.h" |
8 | 8 |
9 namespace views { | 9 namespace views { |
10 | 10 |
11 // Overridden from WindowDelegate: | 11 // Overridden from WindowDelegate: |
| 12 |
| 13 int DialogDelegate::GetDefaultDialogButton() const { |
| 14 if (GetDialogButtons() & DIALOGBUTTON_OK) |
| 15 return DIALOGBUTTON_OK; |
| 16 if (GetDialogButtons() & DIALOGBUTTON_CANCEL) |
| 17 return DIALOGBUTTON_CANCEL; |
| 18 return DIALOGBUTTON_NONE; |
| 19 } |
| 20 |
12 View* DialogDelegate::GetInitiallyFocusedView() const { | 21 View* DialogDelegate::GetInitiallyFocusedView() const { |
13 // Try to focus the OK then the Cancel button if present. | 22 // Focus the default button if any. |
14 DialogClientView* dcv = GetDialogClientView(); | 23 DialogClientView* dcv = GetDialogClientView(); |
15 if (GetDialogButtons() & DIALOGBUTTON_OK) | 24 int default_button = GetDefaultDialogButton(); |
| 25 if (default_button == DIALOGBUTTON_NONE) |
| 26 return NULL; |
| 27 |
| 28 if ((default_button & GetDialogButtons()) == 0) { |
| 29 // The default button is a button we don't have. |
| 30 NOTREACHED(); |
| 31 return NULL; |
| 32 } |
| 33 |
| 34 if (default_button & DIALOGBUTTON_OK) |
16 return dcv->ok_button(); | 35 return dcv->ok_button(); |
17 if (GetDialogButtons() & DIALOGBUTTON_CANCEL) | 36 if (default_button & DIALOGBUTTON_CANCEL) |
18 return dcv->cancel_button(); | 37 return dcv->cancel_button(); |
19 return NULL; | 38 return NULL; |
20 } | 39 } |
21 | 40 |
22 ClientView* DialogDelegate::CreateClientView(Window* window) { | 41 ClientView* DialogDelegate::CreateClientView(Window* window) { |
23 return new DialogClientView(window, GetContentsView()); | 42 return new DialogClientView(window, GetContentsView()); |
24 } | 43 } |
25 | 44 |
26 DialogClientView* DialogDelegate::GetDialogClientView() const { | 45 DialogClientView* DialogDelegate::GetDialogClientView() const { |
27 ClientView* client_view = window()->client_view(); | 46 ClientView* client_view = window()->client_view(); |
28 DialogClientView* dialog_client_view = client_view->AsDialogClientView(); | 47 DialogClientView* dialog_client_view = client_view->AsDialogClientView(); |
29 DCHECK(dialog_client_view); | 48 DCHECK(dialog_client_view); |
30 return dialog_client_view; | 49 return dialog_client_view; |
31 } | 50 } |
32 | 51 |
33 } // namespace views | 52 } // namespace views |
34 | 53 |
OLD | NEW |