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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" | 11 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" |
12 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | 12 #include "chrome/browser/ui/views/harmony/layout_delegate.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "chrome/grit/locale_settings.h" | 14 #include "chrome/grit/locale_settings.h" |
15 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/native_theme/native_theme.h" | 19 #include "ui/native_theme/native_theme.h" |
20 #include "ui/views/border.h" | 20 #include "ui/views/border.h" |
21 #include "ui/views/controls/button/checkbox.h" | 21 #include "ui/views/controls/button/checkbox.h" |
22 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
23 #include "ui/views/controls/button/md_text_button.h" | 23 #include "ui/views/controls/button/md_text_button.h" |
24 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
25 #include "ui/views/controls/menu/menu_runner.h" | 25 #include "ui/views/controls/menu/menu_runner.h" |
26 #include "ui/views/controls/scroll_view.h" | 26 #include "ui/views/controls/scroll_view.h" |
27 #include "ui/views/controls/separator.h" | 27 #include "ui/views/controls/separator.h" |
28 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
30 #include "ui/views/layout/layout_constants.h" | |
31 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
32 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
33 #include "ui/views/window/dialog_client_view.h" | 32 #include "ui/views/window/dialog_client_view.h" |
34 | 33 |
35 namespace { | 34 namespace { |
36 | 35 |
37 const int kScrollAreaHeight = 192; | 36 const int kScrollAreaHeight = 192; |
38 | 37 |
39 // This container has the right Layout() impl to use within a ScrollView. | 38 // This container has the right Layout() impl to use within a ScrollView. |
40 class ScrollableView : public views::View { | 39 class ScrollableView : public views::View { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 int column_set_id = 0; | 104 int column_set_id = 0; |
106 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | 105 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); |
107 columns->AddColumn(views::GridLayout::LEADING, | 106 columns->AddColumn(views::GridLayout::LEADING, |
108 views::GridLayout::LEADING, | 107 views::GridLayout::LEADING, |
109 1, | 108 1, |
110 views::GridLayout::FIXED, | 109 views::GridLayout::FIXED, |
111 dialog_content_width, | 110 dialog_content_width, |
112 0); | 111 0); |
113 | 112 |
114 // Message text. | 113 // Message text. |
| 114 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); |
| 115 const int vertical_padding = layout_delegate->GetMetric( |
| 116 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); |
115 views::Label* subtext = new views::Label(controller_->GetSubtext()); | 117 views::Label* subtext = new views::Label(controller_->GetSubtext()); |
116 subtext->SetMultiLine(true); | 118 subtext->SetMultiLine(true); |
117 subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 119 subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
118 layout->StartRow(0, column_set_id); | 120 layout->StartRow(0, column_set_id); |
119 layout->AddView( | 121 layout->AddView( |
120 subtext, 1, 1, | 122 subtext, 1, 1, |
121 views::GridLayout::FILL, views::GridLayout::LEADING, | 123 views::GridLayout::FILL, views::GridLayout::LEADING, |
122 dialog_content_width, subtext->GetHeightForWidth(dialog_content_width)); | 124 dialog_content_width, subtext->GetHeightForWidth(dialog_content_width)); |
123 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 125 layout->AddPaddingRow(0, vertical_padding); |
124 | 126 |
125 // Scrollable area for checkboxes. | 127 // Scrollable area for checkboxes. |
| 128 const int small_vertical_padding = LayoutDelegate::Get()->GetMetric( |
| 129 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL); |
126 ScrollableView* scroll_container = new ScrollableView(); | 130 ScrollableView* scroll_container = new ScrollableView(); |
127 scroll_container->SetLayoutManager(new views::BoxLayout( | 131 scroll_container->SetLayoutManager(new views::BoxLayout( |
128 views::BoxLayout::kVertical, 0, 0, | 132 views::BoxLayout::kVertical, 0, 0, small_vertical_padding)); |
129 views::kRelatedControlSmallVerticalSpacing)); | |
130 scroll_container->SetBorder( | 133 scroll_container->SetBorder( |
131 views::CreateEmptyBorder(views::kRelatedControlVerticalSpacing, 0, | 134 views::CreateEmptyBorder(vertical_padding, 0, vertical_padding, 0)); |
132 views::kRelatedControlVerticalSpacing, 0)); | |
133 | 135 |
134 std::vector<base::string16> section_headers = | 136 std::vector<base::string16> section_headers = |
135 controller_->GetSectionHeaders(); | 137 controller_->GetSectionHeaders(); |
136 for (size_t i = 0; i < section_headers.size(); i++) { | 138 for (size_t i = 0; i < section_headers.size(); i++) { |
137 MediaGalleriesDialogController::Entries entries = | 139 MediaGalleriesDialogController::Entries entries = |
138 controller_->GetSectionEntries(i); | 140 controller_->GetSectionEntries(i); |
139 | 141 |
140 // Header and separator line. | 142 // Header and separator line. |
141 if (!section_headers[i].empty() && !entries.empty()) { | 143 if (!section_headers[i].empty() && !entries.empty()) { |
142 views::Separator* separator = new views::Separator(); | 144 views::Separator* separator = new views::Separator(); |
143 scroll_container->AddChildView(separator); | 145 scroll_container->AddChildView(separator); |
144 | 146 |
145 views::Label* header = new views::Label(section_headers[i]); | 147 views::Label* header = new views::Label(section_headers[i]); |
146 header->SetMultiLine(true); | 148 header->SetMultiLine(true); |
147 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 149 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
148 header->SetBorder(views::CreateEmptyBorder( | 150 header->SetBorder(views::CreateEmptyBorder( |
149 views::kRelatedControlVerticalSpacing, | 151 vertical_padding, |
150 LayoutDelegate::Get()->GetMetric( | 152 layout_delegate->GetMetric( |
151 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), | 153 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), |
152 views::kRelatedControlVerticalSpacing, 0)); | 154 vertical_padding, 0)); |
153 scroll_container->AddChildView(header); | 155 scroll_container->AddChildView(header); |
154 } | 156 } |
155 | 157 |
156 // Checkboxes. | 158 // Checkboxes. |
157 MediaGalleriesDialogController::Entries::const_iterator iter; | 159 MediaGalleriesDialogController::Entries::const_iterator iter; |
158 for (iter = entries.begin(); iter != entries.end(); ++iter) { | 160 for (iter = entries.begin(); iter != entries.end(); ++iter) { |
159 int spacing = 0; | 161 int spacing = iter + 1 == entries.end() ? small_vertical_padding : 0; |
160 if (iter + 1 == entries.end()) | |
161 spacing = views::kRelatedControlSmallVerticalSpacing; | |
162 AddOrUpdateGallery(*iter, scroll_container, spacing); | 162 AddOrUpdateGallery(*iter, scroll_container, spacing); |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 confirm_available_ = controller_->IsAcceptAllowed(); | 166 confirm_available_ = controller_->IsAcceptAllowed(); |
167 | 167 |
168 // Add the scrollable area to the outer dialog view. It will squeeze against | 168 // Add the scrollable area to the outer dialog view. It will squeeze against |
169 // the title/subtitle and buttons to occupy all available space in the dialog. | 169 // the title/subtitle and buttons to occupy all available space in the dialog. |
170 views::ScrollView* scroll_view = | 170 views::ScrollView* scroll_view = |
171 views::ScrollView::CreateScrollViewWithBorder(); | 171 views::ScrollView::CreateScrollViewWithBorder(); |
172 scroll_view->SetContents(scroll_container); | 172 scroll_view->SetContents(scroll_container); |
173 layout->StartRowWithPadding(1, column_set_id, | 173 layout->StartRowWithPadding(1, column_set_id, 0, vertical_padding); |
174 0, views::kRelatedControlVerticalSpacing); | |
175 layout->AddView(scroll_view, 1, 1, | 174 layout->AddView(scroll_view, 1, 1, |
176 views::GridLayout::FILL, views::GridLayout::FILL, | 175 views::GridLayout::FILL, views::GridLayout::FILL, |
177 dialog_content_width, kScrollAreaHeight); | 176 dialog_content_width, kScrollAreaHeight); |
178 } | 177 } |
179 | 178 |
180 void MediaGalleriesDialogViews::UpdateGalleries() { | 179 void MediaGalleriesDialogViews::UpdateGalleries() { |
181 InitChildViews(); | 180 InitChildViews(); |
182 contents_->Layout(); | 181 contents_->Layout(); |
183 | 182 |
184 if (ControllerHasWebContents()) | 183 if (ControllerHasWebContents()) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 context_menu_runner_.reset(); | 322 context_menu_runner_.reset(); |
324 } | 323 } |
325 | 324 |
326 // MediaGalleriesDialogViewsController ----------------------------------------- | 325 // MediaGalleriesDialogViewsController ----------------------------------------- |
327 | 326 |
328 // static | 327 // static |
329 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 328 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
330 MediaGalleriesDialogController* controller) { | 329 MediaGalleriesDialogController* controller) { |
331 return new MediaGalleriesDialogViews(controller); | 330 return new MediaGalleriesDialogViews(controller); |
332 } | 331 } |
OLD | NEW |