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 related_control_vert_spacing = layout_delegate->GetMetric( | |
tapted
2017/03/20 03:41:52
vertical_padding?
Patti Lor
2017/03/21 06:24:30
Done.
| |
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, related_control_vert_spacing); |
124 | 126 |
125 // Scrollable area for checkboxes. | 127 // Scrollable area for checkboxes. |
126 ScrollableView* scroll_container = new ScrollableView(); | 128 ScrollableView* scroll_container = new ScrollableView(); |
127 scroll_container->SetLayoutManager(new views::BoxLayout( | 129 scroll_container->SetLayoutManager(new views::BoxLayout( |
128 views::BoxLayout::kVertical, 0, 0, | 130 views::BoxLayout::kVertical, 0, 0, related_control_vert_spacing)); |
129 views::kRelatedControlSmallVerticalSpacing)); | 131 scroll_container->SetBorder(views::CreateEmptyBorder( |
130 scroll_container->SetBorder( | 132 related_control_vert_spacing, 0, related_control_vert_spacing, 0)); |
131 views::CreateEmptyBorder(views::kRelatedControlVerticalSpacing, 0, | |
132 views::kRelatedControlVerticalSpacing, 0)); | |
133 | 133 |
134 std::vector<base::string16> section_headers = | 134 std::vector<base::string16> section_headers = |
135 controller_->GetSectionHeaders(); | 135 controller_->GetSectionHeaders(); |
136 for (size_t i = 0; i < section_headers.size(); i++) { | 136 for (size_t i = 0; i < section_headers.size(); i++) { |
137 MediaGalleriesDialogController::Entries entries = | 137 MediaGalleriesDialogController::Entries entries = |
138 controller_->GetSectionEntries(i); | 138 controller_->GetSectionEntries(i); |
139 | 139 |
140 // Header and separator line. | 140 // Header and separator line. |
141 if (!section_headers[i].empty() && !entries.empty()) { | 141 if (!section_headers[i].empty() && !entries.empty()) { |
142 views::Separator* separator = new views::Separator(); | 142 views::Separator* separator = new views::Separator(); |
143 scroll_container->AddChildView(separator); | 143 scroll_container->AddChildView(separator); |
144 | 144 |
145 views::Label* header = new views::Label(section_headers[i]); | 145 views::Label* header = new views::Label(section_headers[i]); |
146 header->SetMultiLine(true); | 146 header->SetMultiLine(true); |
147 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 147 header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
148 header->SetBorder(views::CreateEmptyBorder( | 148 header->SetBorder(views::CreateEmptyBorder( |
149 views::kRelatedControlVerticalSpacing, | 149 related_control_vert_spacing, |
150 LayoutDelegate::Get()->GetMetric( | 150 layout_delegate->GetMetric( |
151 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), | 151 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), |
152 views::kRelatedControlVerticalSpacing, 0)); | 152 related_control_vert_spacing, 0)); |
153 scroll_container->AddChildView(header); | 153 scroll_container->AddChildView(header); |
154 } | 154 } |
155 | 155 |
156 // Checkboxes. | 156 // Checkboxes. |
157 MediaGalleriesDialogController::Entries::const_iterator iter; | 157 MediaGalleriesDialogController::Entries::const_iterator iter; |
158 for (iter = entries.begin(); iter != entries.end(); ++iter) { | 158 for (iter = entries.begin(); iter != entries.end(); ++iter) { |
159 int spacing = 0; | 159 int spacing = |
160 if (iter + 1 == entries.end()) | 160 iter + 1 == entries.end() ? related_control_vert_spacing : 0; |
161 spacing = views::kRelatedControlSmallVerticalSpacing; | |
162 AddOrUpdateGallery(*iter, scroll_container, spacing); | 161 AddOrUpdateGallery(*iter, scroll_container, spacing); |
163 } | 162 } |
164 } | 163 } |
165 | 164 |
166 confirm_available_ = controller_->IsAcceptAllowed(); | 165 confirm_available_ = controller_->IsAcceptAllowed(); |
167 | 166 |
168 // Add the scrollable area to the outer dialog view. It will squeeze against | 167 // 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. | 168 // the title/subtitle and buttons to occupy all available space in the dialog. |
170 views::ScrollView* scroll_view = | 169 views::ScrollView* scroll_view = |
171 views::ScrollView::CreateScrollViewWithBorder(); | 170 views::ScrollView::CreateScrollViewWithBorder(); |
172 scroll_view->SetContents(scroll_container); | 171 scroll_view->SetContents(scroll_container); |
173 layout->StartRowWithPadding(1, column_set_id, | 172 layout->StartRowWithPadding(1, column_set_id, 0, |
174 0, views::kRelatedControlVerticalSpacing); | 173 related_control_vert_spacing); |
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 |