OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/intent_picker_bubble_view.h" | 5 #include "chrome/browser/ui/views/intent_picker_bubble_view.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 app_info_(app_info) {} | 229 app_info_(app_info) {} |
230 | 230 |
231 IntentPickerBubbleView::~IntentPickerBubbleView() { | 231 IntentPickerBubbleView::~IntentPickerBubbleView() { |
232 SetLayoutManager(nullptr); | 232 SetLayoutManager(nullptr); |
233 } | 233 } |
234 | 234 |
235 // If the widget gets closed without an app being selected we still need to use | 235 // If the widget gets closed without an app being selected we still need to use |
236 // the callback so the caller can Resume the navigation. | 236 // the callback so the caller can Resume the navigation. |
237 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { | 237 void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { |
238 if (!was_callback_run_) { | 238 if (!was_callback_run_) { |
| 239 was_callback_run_ = true; |
239 throttle_cb_.Run( | 240 throttle_cb_.Run( |
240 kAppTagNoneSelected, | 241 kAppTagNoneSelected, |
241 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); | 242 arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); |
242 was_callback_run_ = true; | |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 int IntentPickerBubbleView::GetDialogButtons() const { | 246 int IntentPickerBubbleView::GetDialogButtons() const { |
247 return ui::DIALOG_BUTTON_NONE; | 247 return ui::DIALOG_BUTTON_NONE; |
248 } | 248 } |
249 | 249 |
250 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, | 250 void IntentPickerBubbleView::ButtonPressed(views::Button* sender, |
251 const ui::Event& event) { | 251 const ui::Event& event) { |
252 switch (sender->tag()) { | 252 switch (sender->tag()) { |
253 case static_cast<int>(Option::ALWAYS): | 253 case static_cast<int>(Option::ALWAYS): |
| 254 was_callback_run_ = true; |
254 throttle_cb_.Run(selected_app_tag_, | 255 throttle_cb_.Run(selected_app_tag_, |
255 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); | 256 arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); |
256 was_callback_run_ = true; | |
257 GetWidget()->Close(); | 257 GetWidget()->Close(); |
258 break; | 258 break; |
259 case static_cast<int>(Option::JUST_ONCE): | 259 case static_cast<int>(Option::JUST_ONCE): |
| 260 was_callback_run_ = true; |
260 throttle_cb_.Run( | 261 throttle_cb_.Run( |
261 selected_app_tag_, | 262 selected_app_tag_, |
262 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); | 263 arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); |
263 was_callback_run_ = true; | |
264 GetWidget()->Close(); | 264 GetWidget()->Close(); |
265 break; | 265 break; |
266 default: | 266 default: |
267 // The selected app must be a value in the range [0, app_info_.size()-1]. | 267 // The selected app must be a value in the range [0, app_info_.size()-1]. |
268 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size()); | 268 DCHECK(static_cast<size_t>(sender->tag()) < app_info_.size()); |
269 // The user cannot click on the |always_button_| or |just_once_button_| | 269 // The user cannot click on the |always_button_| or |just_once_button_| |
270 // unless an explicit app has been selected. | 270 // unless an explicit app has been selected. |
271 if (selected_app_tag_ != kAppTagNoneSelected) | 271 if (selected_app_tag_ != kAppTagNoneSelected) |
272 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE); | 272 SetLabelButtonBackgroundColor(selected_app_tag_, SK_ColorWHITE); |
273 selected_app_tag_ = sender->tag(); | 273 selected_app_tag_ = sender->tag(); |
(...skipping 16 matching lines...) Expand all Loading... |
290 apps_height *= kRowHeight; | 290 apps_height *= kRowHeight; |
291 } | 291 } |
292 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); | 292 ps.set_height(apps_height + kHeaderHeight + kFooterHeight); |
293 return ps; | 293 return ps; |
294 } | 294 } |
295 | 295 |
296 // If the actual web_contents gets destroyed in the middle of the process we | 296 // If the actual web_contents gets destroyed in the middle of the process we |
297 // should inform the caller about this error. | 297 // should inform the caller about this error. |
298 void IntentPickerBubbleView::WebContentsDestroyed() { | 298 void IntentPickerBubbleView::WebContentsDestroyed() { |
299 if (!was_callback_run_) { | 299 if (!was_callback_run_) { |
| 300 was_callback_run_ = true; |
300 throttle_cb_.Run(kAppTagNoneSelected, | 301 throttle_cb_.Run(kAppTagNoneSelected, |
301 arc::ArcNavigationThrottle::CloseReason::ERROR); | 302 arc::ArcNavigationThrottle::CloseReason::ERROR); |
302 was_callback_run_ = true; | |
303 } | 303 } |
304 GetWidget()->Close(); | 304 GetWidget()->Close(); |
305 } | 305 } |
306 | 306 |
307 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { | 307 views::LabelButton* IntentPickerBubbleView::GetLabelButtonAt(size_t index) { |
308 views::View* temp_contents = scroll_view_->contents(); | 308 views::View* temp_contents = scroll_view_->contents(); |
309 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); | 309 return static_cast<views::LabelButton*>(temp_contents->child_at(index)); |
310 } | 310 } |
311 | 311 |
312 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, | 312 void IntentPickerBubbleView::SetLabelButtonBackgroundColor(size_t index, |
313 SkColor color) { | 313 SkColor color) { |
314 views::LabelButton* temp_lb = GetLabelButtonAt(index); | 314 views::LabelButton* temp_lb = GetLabelButtonAt(index); |
315 temp_lb->set_background(views::Background::CreateSolidBackground(color)); | 315 temp_lb->set_background(views::Background::CreateSolidBackground(color)); |
316 temp_lb->SchedulePaint(); | 316 temp_lb->SchedulePaint(); |
317 } | 317 } |
OLD | NEW |