| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/desktop_media_picker_views.h" | 5 #include "chrome/browser/ui/views/desktop_media_picker_views.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/media/desktop_media_list.h" | 10 #include "chrome/browser/media/desktop_media_list.h" |
| 9 #include "chrome/browser/ui/ash/ash_util.h" | 11 #include "chrome/browser/ui/ash/ash_util.h" |
| 10 #include "chrome/browser/ui/views/constrained_window_views.h" | 12 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 13 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/web_modal/popup_manager.h" | 15 #include "components/web_modal/popup_manager.h" |
| 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 14 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
| 17 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
| 18 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 19 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
| 20 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
| 21 #include "ui/views/bubble/bubble_frame_view.h" | 25 #include "ui/views/bubble/bubble_frame_view.h" |
| 22 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 196 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 193 RequestFocus(); | 197 RequestFocus(); |
| 194 event->SetHandled(); | 198 event->SetHandled(); |
| 195 } | 199 } |
| 196 } | 200 } |
| 197 | 201 |
| 198 DesktopMediaListView::DesktopMediaListView( | 202 DesktopMediaListView::DesktopMediaListView( |
| 199 DesktopMediaPickerDialogView* parent, | 203 DesktopMediaPickerDialogView* parent, |
| 200 scoped_ptr<DesktopMediaList> media_list) | 204 scoped_ptr<DesktopMediaList> media_list) |
| 201 : parent_(parent), | 205 : parent_(parent), |
| 202 media_list_(media_list.Pass()) { | 206 media_list_(media_list.Pass()), |
| 207 weak_factory_(this) { |
| 203 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 208 media_list_->SetThumbnailSize(gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
| 204 } | 209 } |
| 205 | 210 |
| 206 DesktopMediaListView::~DesktopMediaListView() {} | 211 DesktopMediaListView::~DesktopMediaListView() {} |
| 207 | 212 |
| 208 void DesktopMediaListView::StartUpdating(DesktopMediaID::Id dialog_window_id) { | 213 void DesktopMediaListView::StartUpdating(DesktopMediaID::Id dialog_window_id) { |
| 209 media_list_->SetViewDialogWindowId(dialog_window_id); | 214 media_list_->SetViewDialogWindowId(dialog_window_id); |
| 210 media_list_->StartUpdating(this); | 215 media_list_->StartUpdating(this); |
| 211 } | 216 } |
| 212 | 217 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 DesktopMediaSourceView* source_view = | 312 DesktopMediaSourceView* source_view = |
| 308 new DesktopMediaSourceView(this, source.id); | 313 new DesktopMediaSourceView(this, source.id); |
| 309 source_view->SetName(source.name); | 314 source_view->SetName(source.name); |
| 310 source_view->SetGroup(kDesktopMediaSourceViewGroupId); | 315 source_view->SetGroup(kDesktopMediaSourceViewGroupId); |
| 311 AddChildViewAt(source_view, index); | 316 AddChildViewAt(source_view, index); |
| 312 | 317 |
| 313 PreferredSizeChanged(); | 318 PreferredSizeChanged(); |
| 314 | 319 |
| 315 if (child_count() % kListColumns == 1) | 320 if (child_count() % kListColumns == 1) |
| 316 parent_->OnMediaListRowsChanged(); | 321 parent_->OnMediaListRowsChanged(); |
| 322 |
| 323 std::string autoselect_source = |
| 324 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 325 switches::kAutoSelectDesktopCaptureSource); |
| 326 if (!autoselect_source.empty() && |
| 327 base::ASCIIToUTF16(autoselect_source) == source.name) { |
| 328 // Select, then accept and close the dialog when we're done adding sources. |
| 329 source_view->OnFocus(); |
| 330 content::BrowserThread::PostTask( |
| 331 content::BrowserThread::UI, FROM_HERE, |
| 332 base::Bind(&DesktopMediaListView::AcceptSelection, |
| 333 weak_factory_.GetWeakPtr())); |
| 334 } |
| 317 } | 335 } |
| 318 | 336 |
| 319 void DesktopMediaListView::OnSourceRemoved(int index) { | 337 void DesktopMediaListView::OnSourceRemoved(int index) { |
| 320 DesktopMediaSourceView* view = | 338 DesktopMediaSourceView* view = |
| 321 static_cast<DesktopMediaSourceView*>(child_at(index)); | 339 static_cast<DesktopMediaSourceView*>(child_at(index)); |
| 322 DCHECK(view); | 340 DCHECK(view); |
| 323 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); | 341 DCHECK_EQ(view->GetClassName(), kDesktopMediaSourceViewClassName); |
| 324 bool was_selected = view->is_selected(); | 342 bool was_selected = view->is_selected(); |
| 325 RemoveChildView(view); | 343 RemoveChildView(view); |
| 326 delete view; | 344 delete view; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 348 source_view->SetName(source.name); | 366 source_view->SetName(source.name); |
| 349 } | 367 } |
| 350 | 368 |
| 351 void DesktopMediaListView::OnSourceThumbnailChanged(int index) { | 369 void DesktopMediaListView::OnSourceThumbnailChanged(int index) { |
| 352 const DesktopMediaList::Source& source = media_list_->GetSource(index); | 370 const DesktopMediaList::Source& source = media_list_->GetSource(index); |
| 353 DesktopMediaSourceView* source_view = | 371 DesktopMediaSourceView* source_view = |
| 354 static_cast<DesktopMediaSourceView*>(child_at(index)); | 372 static_cast<DesktopMediaSourceView*>(child_at(index)); |
| 355 source_view->SetThumbnail(source.thumbnail); | 373 source_view->SetThumbnail(source.thumbnail); |
| 356 } | 374 } |
| 357 | 375 |
| 376 void DesktopMediaListView::AcceptSelection() { |
| 377 OnSelectionChanged(); |
| 378 OnDoubleClick(); |
| 379 } |
| 380 |
| 358 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( | 381 DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( |
| 359 content::WebContents* parent_web_contents, | 382 content::WebContents* parent_web_contents, |
| 360 gfx::NativeWindow context, | 383 gfx::NativeWindow context, |
| 361 gfx::NativeWindow parent_window, | 384 gfx::NativeWindow parent_window, |
| 362 DesktopMediaPickerViews* parent, | 385 DesktopMediaPickerViews* parent, |
| 363 const base::string16& app_name, | 386 const base::string16& app_name, |
| 364 const base::string16& target_name, | 387 const base::string16& target_name, |
| 365 scoped_ptr<DesktopMediaList> media_list) | 388 scoped_ptr<DesktopMediaList> media_list) |
| 366 : parent_(parent), | 389 : parent_(parent), |
| 367 app_name_(app_name), | 390 app_name_(app_name), |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 content::BrowserThread::PostTask( | 594 content::BrowserThread::PostTask( |
| 572 content::BrowserThread::UI, FROM_HERE, | 595 content::BrowserThread::UI, FROM_HERE, |
| 573 base::Bind(callback_, source)); | 596 base::Bind(callback_, source)); |
| 574 callback_.Reset(); | 597 callback_.Reset(); |
| 575 } | 598 } |
| 576 | 599 |
| 577 // static | 600 // static |
| 578 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { | 601 scoped_ptr<DesktopMediaPicker> DesktopMediaPicker::Create() { |
| 579 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); | 602 return scoped_ptr<DesktopMediaPicker>(new DesktopMediaPickerViews()); |
| 580 } | 603 } |
| OLD | NEW |