OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/extensions/media_galleries_dialog_views.h" | |
6 | |
7 #include "chrome/browser/ui/views/constrained_window_views.h" | |
8 #include "grit/generated_resources.h" | |
9 #include "ui/base/l10n/l10n_util.h" | |
10 #include "ui/views/controls/button/checkbox.h" | |
11 #include "ui/views/controls/button/text_button.h" | |
12 #include "ui/views/controls/label.h" | |
13 #include "ui/views/layout/box_layout.h" | |
14 #include "ui/views/layout/grid_layout.h" | |
15 #include "ui/views/layout/layout_constants.h" | |
16 #include "ui/views/view.h" | |
17 | |
18 namespace chrome { | |
19 | |
20 typedef MediaGalleriesDialogController::KnownGalleryPermissions | |
21 GalleryPermissions; | |
22 | |
23 namespace { | |
24 | |
25 // Heading font size correction. | |
Peter Kasting
2012/08/11 23:09:14
Nit: Can you say more here? I have no idea what t
Evan Stade
2012/08/13 23:10:30
There are a couple other places which use this pat
Peter Kasting
2012/08/14 18:44:01
I'm following up on this separately with the CrOS
| |
26 #if defined(CROS_FONTS_USING_BCI) | |
27 const int kHeadingFontSizeDelta = 0; | |
28 #else | |
29 const int kHeadingFontSizeDelta = 1; | |
30 #endif | |
31 | |
32 const int kContentWidth = 450; | |
33 | |
34 } // namespace | |
35 | |
36 using views::BoxLayout; | |
37 using views::GridLayout; | |
Peter Kasting
2012/08/11 23:09:14
Nit: We normally avoid using statements unless the
Evan Stade
2012/08/13 23:10:30
Done.
| |
38 | |
39 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | |
40 MediaGalleriesDialogController* controller) | |
41 : controller_(controller), | |
42 window_(NULL), | |
43 contents_(new views::View()), | |
Peter Kasting
2012/08/11 23:09:14
Who owns this?
Evan Stade
2012/08/13 23:10:30
its parent View (a RootView)
| |
44 confirm_available_(false), | |
45 accepted_(false) { | |
46 InitChildViews(); | |
47 | |
48 window_ = new ConstrainedWindowViews(controller->tab_contents(), this); | |
Peter Kasting
2012/08/11 23:09:14
Who owns this?
Evan Stade
2012/08/13 23:10:30
the TabContents (first arg)
| |
49 } | |
50 | |
51 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {} | |
52 | |
53 void MediaGalleriesDialogViews::InitChildViews() { | |
54 // Layout. | |
55 GridLayout* layout = new GridLayout(contents_); | |
56 layout->SetInsets(views::kPanelVertMargin, views::kPanelHorizMargin, | |
57 0, views::kPanelHorizMargin); | |
58 int column_set_id = 0; | |
59 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); | |
60 columns->AddColumn(GridLayout::LEADING, | |
61 GridLayout::LEADING, | |
62 1, | |
63 GridLayout::FIXED, | |
64 kContentWidth, | |
65 0); | |
66 contents_->SetLayoutManager(layout); | |
67 | |
68 // Header text. | |
69 views::Label* header = new views::Label(controller_->GetHeader()); | |
70 header->SetFont(header->font().DeriveFont(kHeadingFontSizeDelta, | |
71 gfx::Font::BOLD)); | |
72 header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
73 layout->StartRow(0, column_set_id); | |
74 layout->AddView(header); | |
75 | |
76 // Message text. | |
77 views::Label* subtext = new views::Label(controller_->GetSubtext()); | |
78 subtext->SetMultiLine(true); | |
79 subtext->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
80 layout->StartRowWithPadding(0, column_set_id, | |
81 0, views::kRelatedControlVerticalSpacing); | |
82 layout->AddView(subtext); | |
83 | |
84 // Checkboxes. | |
85 checkbox_container_ = new views::View(); | |
86 checkbox_container_->SetLayoutManager( | |
87 new BoxLayout(BoxLayout::kVertical, | |
88 views::kPanelHorizIndentation, | |
89 0, | |
90 views::kRelatedControlSmallVerticalSpacing)); | |
91 layout->StartRowWithPadding(0, column_set_id, | |
92 0, views::kRelatedControlVerticalSpacing); | |
93 layout->AddView(checkbox_container_); | |
94 | |
95 const GalleryPermissions& permissions = controller_->permissions(); | |
96 for (GalleryPermissions::const_iterator iter = permissions.begin(); | |
97 iter != permissions.end(); iter++) { | |
Peter Kasting
2012/08/11 23:09:14
Nit: Preincrement
Evan Stade
2012/08/13 23:10:30
Done.
| |
98 AddOrUpdateGallery(&iter->second.pref_info, iter->second.allowed); | |
99 if (iter->second.allowed) | |
100 confirm_available_ = true; | |
101 } | |
102 | |
103 // Add Gallery button. | |
104 add_gallery_ = new views::NativeTextButton( | |
105 this, l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); | |
106 layout->StartRowWithPadding(0, column_set_id, | |
107 0, views::kRelatedControlVerticalSpacing); | |
108 layout->AddView(add_gallery_); | |
109 } | |
110 | |
111 void MediaGalleriesDialogViews::UpdateGallery( | |
112 const MediaGalleryPrefInfo* gallery, bool permitted) { | |
Peter Kasting
2012/08/11 23:09:14
Nit: One arg per line (2 places)
Evan Stade
2012/08/13 23:10:30
Done.
| |
113 // After adding a new checkbox, we have to update the size of the dialog. | |
114 if (AddOrUpdateGallery(gallery, permitted)) | |
115 GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize()); | |
116 } | |
117 | |
118 bool MediaGalleriesDialogViews::AddOrUpdateGallery( | |
119 const MediaGalleryPrefInfo* gallery, bool permitted) { | |
120 CheckboxMap::iterator iter = checkbox_map_.find(gallery); | |
121 | |
122 bool new_checkbox = false; | |
Peter Kasting
2012/08/11 23:09:14
Nit: How about:
CheckboxMap::iterator iter = ch
Evan Stade
2012/08/13 23:10:30
Done.
| |
123 views::Checkbox* checkbox = NULL; | |
124 if (iter != checkbox_map_.end()) { | |
125 checkbox = iter->second; | |
126 } else { | |
127 new_checkbox = true; | |
128 checkbox = new views::Checkbox(gallery->display_name); | |
129 checkbox->set_listener(this); | |
130 checkbox->SetTooltipText(gallery->path.LossyDisplayName()); | |
Evan Stade
2012/08/10 21:58:13
Sailesh: note this (I haven't yet done this for Li
sail
2012/08/10 22:09:04
Sounds good, will add to Cocoa.
| |
131 checkbox_container_->AddChildView(checkbox); | |
132 checkbox_map_[gallery] = checkbox; | |
133 } | |
134 | |
135 checkbox->SetChecked(permitted); | |
136 return new_checkbox; | |
137 } | |
138 | |
139 string16 MediaGalleriesDialogViews::GetDialogButtonLabel( | |
140 ui::DialogButton button) const { | |
141 if (button == ui::DIALOG_BUTTON_OK) | |
Peter Kasting
2012/08/11 23:09:14
Nit: Most places we just do:
return l10n_util::
Evan Stade
2012/08/13 23:10:30
Done.
| |
142 return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CONFIRM); | |
143 | |
144 if (button == ui::DIALOG_BUTTON_CANCEL) | |
145 return l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_CANCEL); | |
146 | |
147 return string16(); | |
148 } | |
149 | |
150 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( | |
151 ui::DialogButton button) const { | |
152 return !(button == ui::DIALOG_BUTTON_OK && !confirm_available_); | |
Peter Kasting
2012/08/11 23:09:14
Nit: Please factor ! through, as nested !s make my
Evan Stade
2012/08/13 23:10:30
Done.
| |
153 } | |
154 | |
155 bool MediaGalleriesDialogViews::Cancel() { | |
156 return true; | |
157 } | |
158 | |
159 bool MediaGalleriesDialogViews::Accept() { | |
160 accepted_ = true; | |
161 return true; | |
162 } | |
163 | |
164 views::View* MediaGalleriesDialogViews::GetContentsView() { | |
165 return contents_; | |
166 } | |
167 | |
168 views::Widget* MediaGalleriesDialogViews::GetWidget() { | |
169 return contents_->GetWidget(); | |
170 } | |
171 | |
172 const views::Widget* MediaGalleriesDialogViews::GetWidget() const { | |
173 return contents_->GetWidget(); | |
174 } | |
175 | |
176 void MediaGalleriesDialogViews::DeleteDelegate() { | |
177 controller_->DialogFinished(accepted_); | |
178 } | |
179 | |
180 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, | |
181 const ui::Event& event) { | |
182 EnableConfirm(); | |
183 | |
184 if (sender == add_gallery_) { | |
185 controller_->OnAddFolderClicked(); | |
186 return; | |
187 } | |
188 | |
189 for (CheckboxMap::iterator iter = checkbox_map_.begin(); | |
190 iter != checkbox_map_.end(); ++iter) { | |
191 if (iter->second == sender) { | |
Peter Kasting
2012/08/11 23:09:14
Tiny nit: For consistency with conditional above,
Evan Stade
2012/08/13 23:10:30
Done.
| |
192 controller_->GalleryToggled( | |
193 iter->first, static_cast<views::Checkbox*>(sender)->checked()); | |
194 return; | |
195 } | |
196 } | |
197 | |
198 NOTREACHED(); | |
199 return; | |
Peter Kasting
2012/08/11 23:09:14
Nit: No need for return here
Evan Stade
2012/08/13 23:10:30
Done.
| |
200 } | |
201 | |
202 void MediaGalleriesDialogViews::EnableConfirm() { | |
Peter Kasting
2012/08/11 23:09:14
Nit: Any particular reason to factor this out into
Evan Stade
2012/08/13 23:10:30
Done. (I originally had it called twice.)
| |
203 confirm_available_ = true; | |
204 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); | |
205 } | |
206 | |
207 // MediaGalleriesDialogViewsController ----------------------------------------- | |
208 | |
209 // static | |
210 MediaGalleriesDialog* MediaGalleriesDialog::Create( | |
211 MediaGalleriesDialogController* controller) { | |
212 return new MediaGalleriesDialogViews(controller); | |
213 } | |
214 | |
215 } // namespace chrome | |
OLD | NEW |