OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmark_app_bubble_view.h" | 5 #include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h" |
6 | 6 |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/string_util.h" | |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
10 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
11 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
12 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
15 #include "ui/gfx/geometry/safe_integer_conversions.h" | 16 #include "ui/gfx/geometry/safe_integer_conversions.h" |
16 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
17 #include "ui/gfx/image/image_skia_source.h" | 18 #include "ui/gfx/image/image_skia_source.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 172 |
172 gfx::Size image_size(kIconSize, kIconSize); | 173 gfx::Size image_size(kIconSize, kIconSize); |
173 gfx::ImageSkia image(new WebAppInfoImageSource(kIconSize, web_app_info_), | 174 gfx::ImageSkia image(new WebAppInfoImageSource(kIconSize, web_app_info_), |
174 image_size); | 175 image_size); |
175 icon_image_view_->SetImageSize(image_size); | 176 icon_image_view_->SetImageSize(image_size); |
176 icon_image_view_->SetImage(image); | 177 icon_image_view_->SetImage(image); |
177 layout->AddView(icon_image_view_); | 178 layout->AddView(icon_image_view_); |
178 | 179 |
179 title_tf_ = new views::Textfield(); | 180 title_tf_ = new views::Textfield(); |
180 title_tf_->SetText(web_app_info_.title); | 181 title_tf_->SetText(web_app_info_.title); |
182 title_tf_->set_controller(this); | |
181 layout->AddView(title_tf_); | 183 layout->AddView(title_tf_); |
182 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 184 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
183 | 185 |
184 layout->StartRow(0, CONTENT_COLUMN_SET_ID); | 186 layout->StartRow(0, CONTENT_COLUMN_SET_ID); |
185 open_as_window_checkbox_ = new views::Checkbox( | 187 open_as_window_checkbox_ = new views::Checkbox( |
186 l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)); | 188 l10n_util::GetStringUTF16(IDS_BOOKMARK_APP_BUBBLE_OPEN_AS_WINDOW)); |
187 open_as_window_checkbox_->SetChecked(web_app_info_.open_as_window); | 189 open_as_window_checkbox_->SetChecked(web_app_info_.open_as_window); |
188 layout->AddView(open_as_window_checkbox_); | 190 layout->AddView(open_as_window_checkbox_); |
189 layout->AddView(add_button_); | 191 layout->AddView(add_button_); |
190 layout->AddView(cancel_button_); | 192 layout->AddView(cancel_button_); |
191 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 193 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
192 | 194 |
193 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 195 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
196 UpdateAddButtonState(); | |
194 } | 197 } |
195 | 198 |
196 views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() { | 199 views::View* BookmarkAppBubbleView::GetInitiallyFocusedView() { |
197 return title_tf_; | 200 return title_tf_; |
198 } | 201 } |
199 | 202 |
200 void BookmarkAppBubbleView::WindowClosing() { | 203 void BookmarkAppBubbleView::WindowClosing() { |
201 callback_.Run(user_accepted_, web_app_info_); | 204 callback_.Run(user_accepted_, web_app_info_); |
202 } | 205 } |
203 | 206 |
(...skipping 10 matching lines...) Expand all Loading... | |
214 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); | 217 gfx::Size size(views::BubbleDelegateView::GetPreferredSize()); |
215 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); | 218 size.SetToMax(gfx::Size(kMinBubbleWidth, 0)); |
216 return size; | 219 return size; |
217 } | 220 } |
218 | 221 |
219 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, | 222 void BookmarkAppBubbleView::ButtonPressed(views::Button* sender, |
220 const ui::Event& event) { | 223 const ui::Event& event) { |
221 HandleButtonPressed(sender); | 224 HandleButtonPressed(sender); |
222 } | 225 } |
223 | 226 |
227 void BookmarkAppBubbleView::ContentsChanged( | |
228 views::Textfield* sender, | |
229 const base::string16& new_contents) { | |
230 DCHECK(sender == title_tf_); | |
Lei Zhang
2015/02/06 22:41:27
DCHECK_EQ()
benwells
2015/02/07 03:17:38
Done.
| |
231 UpdateAddButtonState(); | |
232 } | |
233 | |
224 void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) { | 234 void BookmarkAppBubbleView::HandleButtonPressed(views::Button* sender) { |
225 if (sender == add_button_) { | 235 if (sender == add_button_) { |
226 user_accepted_ = true; | 236 user_accepted_ = true; |
227 web_app_info_.title = title_tf_->text(); | 237 web_app_info_.title = GetTrimmedTitle(); |
228 web_app_info_.open_as_window = open_as_window_checkbox_->checked(); | 238 web_app_info_.open_as_window = open_as_window_checkbox_->checked(); |
229 } | 239 } |
230 | 240 |
231 GetWidget()->Close(); | 241 GetWidget()->Close(); |
232 } | 242 } |
243 | |
244 void BookmarkAppBubbleView::UpdateAddButtonState() { | |
245 add_button_->SetEnabled(!GetTrimmedTitle().empty()); | |
246 } | |
247 | |
248 base::string16 BookmarkAppBubbleView::GetTrimmedTitle() { | |
249 base::string16 title(title_tf_->text()); | |
250 base::TrimWhitespace(title, base::TRIM_ALL, &title); | |
251 return title; | |
252 } | |
OLD | NEW |