OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/views/download/download_in_progress_dialog_view.h" | 5 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "grit/chromium_strings.h" | 11 #include "grit/chromium_strings.h" |
12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
13 #include "grit/locale_settings.h" | 13 #include "grit/locale_settings.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
17 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
18 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/message_box_view.h" |
19 #include "ui/views/layout/grid_layout.h" | 19 #include "ui/views/layout/grid_layout.h" |
20 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
21 | 21 |
22 // static | 22 // static |
23 void DownloadInProgressDialogView::Show(Browser* browser, | 23 void DownloadInProgressDialogView::Show(Browser* browser, |
24 gfx::NativeWindow parent_window) { | 24 gfx::NativeWindow parent_window) { |
25 DownloadInProgressDialogView* window = | 25 DownloadInProgressDialogView* window = |
26 new DownloadInProgressDialogView(browser); | 26 new DownloadInProgressDialogView(browser); |
27 views::Widget::CreateWindowWithParent(window, parent_window)->Show(); | 27 views::Widget::CreateWindowWithParent(window, parent_window)->Show(); |
28 } | 28 } |
29 | 29 |
30 DownloadInProgressDialogView::DownloadInProgressDialogView(Browser* browser) | 30 DownloadInProgressDialogView::DownloadInProgressDialogView(Browser* browser) |
31 : browser_(browser), | 31 : browser_(browser), |
32 warning_(NULL), | 32 message_box_view_(NULL) { |
33 explanation_(NULL) { | |
34 int download_count; | 33 int download_count; |
35 Browser::DownloadClosePreventionType type = | 34 Browser::DownloadClosePreventionType dialog_type = |
36 browser_->OkToCloseWithInProgressDownloads(&download_count); | 35 browser_->OkToCloseWithInProgressDownloads(&download_count); |
37 | 36 |
38 // This dialog should have been created within the same thread invocation | 37 string16 explanation_text; |
39 // as the original test that lead to us, so it should always not be ok | 38 switch (dialog_type) { |
40 // to close. | 39 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN: |
41 DCHECK_NE(Browser::DOWNLOAD_CLOSE_OK, type); | 40 if (download_count == 1) { |
| 41 title_text_ = l10n_util::GetStringUTF16( |
| 42 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE); |
| 43 explanation_text = l10n_util::GetStringUTF16( |
| 44 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); |
| 45 } else { |
| 46 title_text_ = l10n_util::GetStringUTF16( |
| 47 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE); |
| 48 explanation_text = l10n_util::GetStringUTF16( |
| 49 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); |
| 50 } |
| 51 ok_button_text_ = l10n_util::GetStringUTF16( |
| 52 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
| 53 break; |
| 54 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE: |
| 55 if (download_count == 1) { |
| 56 title_text_ = l10n_util::GetStringUTF16( |
| 57 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE); |
| 58 explanation_text = l10n_util::GetStringUTF16( |
| 59 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); |
| 60 } else { |
| 61 title_text_ = l10n_util::GetStringUTF16( |
| 62 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE); |
| 63 explanation_text = l10n_util::GetStringUTF16( |
| 64 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); |
| 65 } |
| 66 ok_button_text_ = l10n_util::GetStringUTF16( |
| 67 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); |
| 68 break; |
| 69 default: |
| 70 // This dialog should have been created within the same thread invocation |
| 71 // as the original test that lead to us, so it should always not be ok |
| 72 // to close. |
| 73 NOTREACHED(); |
| 74 } |
| 75 cancel_button_text_ = l10n_util::GetStringUTF16( |
| 76 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); |
42 | 77 |
43 // TODO(rdsmith): This dialog should be different depending on whether we're | 78 message_box_view_ = new views::MessageBoxView( |
44 // closing the last incognito window of a profile or doing browser shutdown. | 79 views::MessageBoxView::NO_OPTIONS, explanation_text, string16()); |
45 // See http://crbug.com/88421. | |
46 | |
47 string16 warning_text; | |
48 string16 explanation_text; | |
49 if (download_count == 1) { | |
50 warning_text = l10n_util::GetStringUTF16( | |
51 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_WARNING); | |
52 explanation_text = l10n_util::GetStringUTF16( | |
53 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); | |
54 ok_button_text_ = l10n_util::GetStringUTF16( | |
55 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); | |
56 cancel_button_text_ = l10n_util::GetStringUTF16( | |
57 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); | |
58 } else { | |
59 warning_text = l10n_util::GetStringFUTF16( | |
60 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_WARNING, | |
61 base::IntToString16(download_count)); | |
62 explanation_text = l10n_util::GetStringUTF16( | |
63 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); | |
64 ok_button_text_ = l10n_util::GetStringUTF16( | |
65 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_OK_BUTTON_LABEL); | |
66 cancel_button_text_ = l10n_util::GetStringUTF16( | |
67 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); | |
68 } | |
69 | |
70 // There are two lines of text: the bold warning label and the text | |
71 // explanation label. | |
72 views::GridLayout* layout = new views::GridLayout(this); | |
73 SetLayoutManager(layout); | |
74 const int columnset_id = 0; | |
75 views::ColumnSet* column_set = layout->AddColumnSet(columnset_id); | |
76 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, | |
77 views::GridLayout::USE_PREF, 0, 0); | |
78 | |
79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
80 gfx::Font bold_font = rb.GetFont( | |
81 ui::ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD); | |
82 warning_ = new views::Label(warning_text, bold_font); | |
83 warning_->SetMultiLine(true); | |
84 warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
85 warning_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10)); | |
86 layout->StartRow(0, columnset_id); | |
87 layout->AddView(warning_); | |
88 | |
89 explanation_ = new views::Label(explanation_text); | |
90 explanation_->SetMultiLine(true); | |
91 explanation_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
92 explanation_->set_border(views::Border::CreateEmptyBorder(10, 10, 10, 10)); | |
93 layout->StartRow(0, columnset_id); | |
94 layout->AddView(explanation_); | |
95 | |
96 dialog_dimensions_ = views::Widget::GetLocalizedContentsSize( | |
97 IDS_DOWNLOAD_IN_PROGRESS_WIDTH_CHARS, | |
98 IDS_DOWNLOAD_IN_PROGRESS_MINIMUM_HEIGHT_LINES); | |
99 const int height = | |
100 warning_->GetHeightForWidth(dialog_dimensions_.width()) + | |
101 explanation_->GetHeightForWidth(dialog_dimensions_.width()); | |
102 dialog_dimensions_.set_height(std::max(height, | |
103 dialog_dimensions_.height())); | |
104 } | 80 } |
105 | 81 |
106 DownloadInProgressDialogView::~DownloadInProgressDialogView() {} | 82 DownloadInProgressDialogView::~DownloadInProgressDialogView() {} |
107 | 83 |
108 gfx::Size DownloadInProgressDialogView::GetPreferredSize() { | 84 int DownloadInProgressDialogView::GetDefaultDialogButton() const { |
109 return dialog_dimensions_; | 85 return ui::DIALOG_BUTTON_CANCEL; |
110 } | 86 } |
111 | 87 |
112 string16 DownloadInProgressDialogView::GetDialogButtonLabel( | 88 string16 DownloadInProgressDialogView::GetDialogButtonLabel( |
113 ui::DialogButton button) const { | 89 ui::DialogButton button) const { |
114 return (button == ui::DIALOG_BUTTON_OK) ? | 90 return (button == ui::DIALOG_BUTTON_OK) ? |
115 ok_button_text_ : cancel_button_text_; | 91 ok_button_text_ : cancel_button_text_; |
116 } | 92 } |
117 | 93 |
118 int DownloadInProgressDialogView::GetDefaultDialogButton() const { | |
119 return ui::DIALOG_BUTTON_CANCEL; | |
120 } | |
121 | |
122 bool DownloadInProgressDialogView::Cancel() { | 94 bool DownloadInProgressDialogView::Cancel() { |
123 browser_->InProgressDownloadResponse(false); | 95 browser_->InProgressDownloadResponse(false); |
124 return true; | 96 return true; |
125 } | 97 } |
126 | 98 |
127 bool DownloadInProgressDialogView::Accept() { | 99 bool DownloadInProgressDialogView::Accept() { |
128 browser_->InProgressDownloadResponse(true); | 100 browser_->InProgressDownloadResponse(true); |
129 return true; | 101 return true; |
130 } | 102 } |
131 | 103 |
132 ui::ModalType DownloadInProgressDialogView::GetModalType() const { | 104 ui::ModalType DownloadInProgressDialogView::GetModalType() const { |
133 return ui::MODAL_TYPE_WINDOW; | 105 return ui::MODAL_TYPE_WINDOW; |
134 } | 106 } |
135 | 107 |
136 string16 DownloadInProgressDialogView::GetWindowTitle() const { | 108 string16 DownloadInProgressDialogView::GetWindowTitle() const { |
137 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | 109 return title_text_; |
| 110 } |
| 111 |
| 112 void DownloadInProgressDialogView::DeleteDelegate() { |
| 113 delete this; |
| 114 } |
| 115 |
| 116 views::Widget* DownloadInProgressDialogView::GetWidget() { |
| 117 return message_box_view_->GetWidget(); |
| 118 } |
| 119 |
| 120 const views::Widget* DownloadInProgressDialogView::GetWidget() const { |
| 121 return message_box_view_->GetWidget(); |
138 } | 122 } |
139 | 123 |
140 views::View* DownloadInProgressDialogView::GetContentsView() { | 124 views::View* DownloadInProgressDialogView::GetContentsView() { |
141 return this; | 125 return message_box_view_; |
142 } | 126 } |
OLD | NEW |