OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/window/dialog_delegate.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "views/controls/button/text_button.h" | |
9 #include "views/widget/widget.h" | |
10 | |
11 namespace views { | |
12 | |
13 //////////////////////////////////////////////////////////////////////////////// | |
14 // DialogDelegate: | |
15 | |
16 DialogDelegate* DialogDelegate::AsDialogDelegate() { return this; } | |
17 | |
18 int DialogDelegate::GetDialogButtons() const { | |
19 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | |
20 } | |
21 | |
22 int DialogDelegate::GetDefaultDialogButton() const { | |
23 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) | |
24 return ui::DIALOG_BUTTON_OK; | |
25 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) | |
26 return ui::DIALOG_BUTTON_CANCEL; | |
27 return ui::DIALOG_BUTTON_NONE; | |
28 } | |
29 | |
30 string16 DialogDelegate::GetDialogButtonLabel(ui::DialogButton button) const { | |
31 // Empty string results in defaults for | |
32 // ui::DIALOG_BUTTON_OK or ui::DIALOG_BUTTON_CANCEL. | |
33 return string16(); | |
34 } | |
35 | |
36 bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const { | |
37 return true; | |
38 } | |
39 | |
40 bool DialogDelegate::IsDialogButtonVisible(ui::DialogButton button) const { | |
41 return true; | |
42 } | |
43 | |
44 bool DialogDelegate::AreAcceleratorsEnabled(ui::DialogButton button) { | |
45 return true; | |
46 } | |
47 | |
48 View* DialogDelegate::GetExtraView() { | |
49 return NULL; | |
50 } | |
51 | |
52 bool DialogDelegate::GetSizeExtraViewHeightToButtons() { | |
53 return false; | |
54 } | |
55 | |
56 bool DialogDelegate::Cancel() { | |
57 return true; | |
58 } | |
59 | |
60 bool DialogDelegate::Accept(bool window_closiang) { | |
61 return Accept(); | |
62 } | |
63 | |
64 bool DialogDelegate::Accept() { | |
65 return true; | |
66 } | |
67 | |
68 View* DialogDelegate::GetInitiallyFocusedView() { | |
69 // Focus the default button if any. | |
70 const DialogClientView* dcv = GetDialogClientView(); | |
71 int default_button = GetDefaultDialogButton(); | |
72 if (default_button == ui::DIALOG_BUTTON_NONE) | |
73 return NULL; | |
74 | |
75 if ((default_button & GetDialogButtons()) == 0) { | |
76 // The default button is a button we don't have. | |
77 NOTREACHED(); | |
78 return NULL; | |
79 } | |
80 | |
81 if (default_button & ui::DIALOG_BUTTON_OK) | |
82 return dcv->ok_button(); | |
83 if (default_button & ui::DIALOG_BUTTON_CANCEL) | |
84 return dcv->cancel_button(); | |
85 return NULL; | |
86 } | |
87 | |
88 ClientView* DialogDelegate::CreateClientView(Widget* widget) { | |
89 return new DialogClientView(widget, GetContentsView()); | |
90 } | |
91 | |
92 const DialogClientView* DialogDelegate::GetDialogClientView() const { | |
93 return GetWidget()->client_view()->AsDialogClientView(); | |
94 } | |
95 | |
96 DialogClientView* DialogDelegate::GetDialogClientView() { | |
97 return GetWidget()->client_view()->AsDialogClientView(); | |
98 } | |
99 | |
100 ui::AccessibilityTypes::Role DialogDelegate::GetAccessibleWindowRole() const { | |
101 return ui::AccessibilityTypes::ROLE_DIALOG; | |
102 } | |
103 | |
104 //////////////////////////////////////////////////////////////////////////////// | |
105 // DialogDelegateView: | |
106 | |
107 DialogDelegateView::DialogDelegateView() { | |
108 } | |
109 | |
110 DialogDelegateView::~DialogDelegateView() { | |
111 } | |
112 | |
113 Widget* DialogDelegateView::GetWidget() { | |
114 return View::GetWidget(); | |
115 } | |
116 | |
117 const Widget* DialogDelegateView::GetWidget() const { | |
118 return View::GetWidget(); | |
119 } | |
120 | |
121 } // namespace views | |
OLD | NEW |