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/extensions/media_galleries_dialog_views.h" | 5 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/constrained_window_views.h" | 8 #include "chrome/browser/ui/views/constrained_window_views.h" |
9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 9 #include "components/web_modal/web_contents_modal_dialog_host.h" |
10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_view.h" | |
14 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
15 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
16 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | |
19 #include "ui/native_theme/native_theme.h" | 17 #include "ui/native_theme/native_theme.h" |
20 #include "ui/views/controls/button/checkbox.h" | 18 #include "ui/views/controls/button/checkbox.h" |
21 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
22 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
23 #include "ui/views/controls/menu/menu_runner.h" | 21 #include "ui/views/controls/menu/menu_runner.h" |
24 #include "ui/views/controls/scroll_view.h" | 22 #include "ui/views/controls/scroll_view.h" |
25 #include "ui/views/controls/separator.h" | 23 #include "ui/views/controls/separator.h" |
26 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
27 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
28 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Ownership of |contents_| is handed off by this call. |window_| will take | 81 // Ownership of |contents_| is handed off by this call. |window_| will take |
84 // care of deleting itself after calling DeleteDelegate(). | 82 // care of deleting itself after calling DeleteDelegate(). |
85 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 83 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
86 WebContentsModalDialogManager::FromWebContents( | 84 WebContentsModalDialogManager::FromWebContents( |
87 controller->web_contents()); | 85 controller->web_contents()); |
88 DCHECK(web_contents_modal_dialog_manager); | 86 DCHECK(web_contents_modal_dialog_manager); |
89 WebContentsModalDialogManagerDelegate* modal_delegate = | 87 WebContentsModalDialogManagerDelegate* modal_delegate = |
90 web_contents_modal_dialog_manager->delegate(); | 88 web_contents_modal_dialog_manager->delegate(); |
91 DCHECK(modal_delegate); | 89 DCHECK(modal_delegate); |
92 window_ = views::Widget::CreateWindowAsFramelessChild( | 90 window_ = views::Widget::CreateWindowAsFramelessChild( |
93 this, | 91 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
94 controller->web_contents()->GetView()->GetNativeView(), | |
95 modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | |
96 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); | 92 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); |
97 } | 93 } |
98 | 94 |
99 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {} | 95 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {} |
100 | 96 |
101 void MediaGalleriesDialogViews::InitChildViews() { | 97 void MediaGalleriesDialogViews::InitChildViews() { |
102 // Outer dialog layout. | 98 // Outer dialog layout. |
103 contents_->RemoveAllChildViews(true); | 99 contents_->RemoveAllChildViews(true); |
104 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( | 100 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( |
105 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); | 101 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); |
106 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); | 102 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); |
107 contents_->SetLayoutManager(layout); | 103 contents_->SetLayoutManager(layout); |
108 | 104 |
109 int column_set_id = 0; | 105 int column_set_id = 0; |
110 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | 106 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); |
111 columns->AddColumn(views::GridLayout::LEADING, | 107 columns->AddColumn(views::GridLayout::LEADING, |
112 views::GridLayout::LEADING, | 108 views::GridLayout::LEADING, |
113 1, | 109 1, |
114 views::GridLayout::FIXED, | 110 views::GridLayout::FIXED, |
115 dialog_content_width, | 111 dialog_content_width, |
116 0); | 112 0); |
117 | 113 |
118 if (!DialogDelegate::UseNewStyle()) { | |
119 // Header text. | |
120 views::Label* header = new views::Label(controller_->GetHeader()); | |
121 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
122 header->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | |
123 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
124 layout->StartRow(0, column_set_id); | |
125 layout->AddView(header); | |
126 } | |
127 | |
128 // Message text. | 114 // Message text. |
129 views::Label* subtext = new views::Label(controller_->GetSubtext()); | 115 views::Label* subtext = new views::Label(controller_->GetSubtext()); |
130 subtext->SetMultiLine(true); | 116 subtext->SetMultiLine(true); |
131 subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 117 subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
132 layout->StartRow(0, column_set_id); | 118 layout->StartRow(0, column_set_id); |
133 layout->AddView( | 119 layout->AddView( |
134 subtext, 1, 1, | 120 subtext, 1, 1, |
135 views::GridLayout::FILL, views::GridLayout::LEADING, | 121 views::GridLayout::FILL, views::GridLayout::LEADING, |
136 dialog_content_width, subtext->GetHeightForWidth(dialog_content_width)); | 122 dialog_content_width, subtext->GetHeightForWidth(dialog_content_width)); |
137 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 123 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 else | 258 else |
273 new_checkbox_map_[checkbox] = gallery; | 259 new_checkbox_map_[checkbox] = gallery; |
274 | 260 |
275 return true; | 261 return true; |
276 } | 262 } |
277 | 263 |
278 string16 MediaGalleriesDialogViews::GetWindowTitle() const { | 264 string16 MediaGalleriesDialogViews::GetWindowTitle() const { |
279 return controller_->GetHeader(); | 265 return controller_->GetHeader(); |
280 } | 266 } |
281 | 267 |
282 bool MediaGalleriesDialogViews::ShouldShowWindowTitle() const { | |
283 return DialogDelegate::UseNewStyle(); | |
284 } | |
285 | |
286 void MediaGalleriesDialogViews::DeleteDelegate() { | 268 void MediaGalleriesDialogViews::DeleteDelegate() { |
287 controller_->DialogFinished(accepted_); | 269 controller_->DialogFinished(accepted_); |
288 } | 270 } |
289 | 271 |
290 views::Widget* MediaGalleriesDialogViews::GetWidget() { | 272 views::Widget* MediaGalleriesDialogViews::GetWidget() { |
291 return contents_->GetWidget(); | 273 return contents_->GetWidget(); |
292 } | 274 } |
293 | 275 |
294 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { | 276 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { |
295 return contents_->GetWidget(); | 277 return contents_->GetWidget(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 } | 382 } |
401 } | 383 } |
402 | 384 |
403 // MediaGalleriesDialogViewsController ----------------------------------------- | 385 // MediaGalleriesDialogViewsController ----------------------------------------- |
404 | 386 |
405 // static | 387 // static |
406 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 388 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
407 MediaGalleriesDialogController* controller) { | 389 MediaGalleriesDialogController* controller) { |
408 return new MediaGalleriesDialogViews(controller); | 390 return new MediaGalleriesDialogViews(controller); |
409 } | 391 } |
OLD | NEW |