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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/constrained_window_views.h" | 8 #include "chrome/browser/ui/views/constrained_window_views.h" |
9 #include "components/web_modal/web_contents_modal_dialog_host.h" | 9 #include "components/web_modal/web_contents_modal_dialog_host.h" |
10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | 72 MediaGalleriesDialogViews::MediaGalleriesDialogViews( |
73 MediaGalleriesDialogController* controller) | 73 MediaGalleriesDialogController* controller) |
74 : controller_(controller), | 74 : controller_(controller), |
75 window_(NULL), | 75 window_(NULL), |
76 contents_(new views::View()), | 76 contents_(new views::View()), |
77 add_gallery_button_(NULL), | 77 add_gallery_button_(NULL), |
78 confirm_available_(false), | 78 confirm_available_(false), |
79 accepted_(false) { | 79 accepted_(false) { |
80 InitChildViews(); | 80 InitChildViews(); |
81 | 81 |
82 // Ownership of |contents_| is handed off by this call. |window_| will take | 82 // May be NULL during tests. |
83 // care of deleting itself after calling DeleteDelegate(). | 83 if (controller->web_contents()) { |
84 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 84 // Ownership of |contents_| is handed off by this call. |window_| will take |
85 WebContentsModalDialogManager::FromWebContents( | 85 // care of deleting itself after calling DeleteDelegate(). |
86 controller->web_contents()); | 86 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
87 DCHECK(web_contents_modal_dialog_manager); | 87 WebContentsModalDialogManager::FromWebContents( |
88 WebContentsModalDialogManagerDelegate* modal_delegate = | 88 controller->web_contents()); |
89 web_contents_modal_dialog_manager->delegate(); | 89 DCHECK(web_contents_modal_dialog_manager); |
90 DCHECK(modal_delegate); | 90 WebContentsModalDialogManagerDelegate* modal_delegate = |
91 window_ = views::Widget::CreateWindowAsFramelessChild( | 91 web_contents_modal_dialog_manager->delegate(); |
92 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | 92 DCHECK(modal_delegate); |
93 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); | 93 window_ = views::Widget::CreateWindowAsFramelessChild( |
| 94 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); |
| 95 web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView()); |
| 96 } |
94 } | 97 } |
95 | 98 |
96 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() {} | 99 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() { |
| 100 if (!controller_->web_contents()) |
| 101 delete contents_; |
| 102 } |
97 | 103 |
98 void MediaGalleriesDialogViews::InitChildViews() { | 104 void MediaGalleriesDialogViews::InitChildViews() { |
99 // Outer dialog layout. | 105 // Outer dialog layout. |
100 contents_->RemoveAllChildViews(true); | 106 contents_->RemoveAllChildViews(true); |
101 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( | 107 int dialog_content_width = views::Widget::GetLocalizedContentsWidth( |
102 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); | 108 IDS_MEDIA_GALLERIES_DIALOG_CONTENT_WIDTH_CHARS); |
103 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); | 109 views::GridLayout* layout = views::GridLayout::CreatePanel(contents_); |
104 contents_->SetLayoutManager(layout); | 110 contents_->SetLayoutManager(layout); |
105 | 111 |
106 int column_set_id = 0; | 112 int column_set_id = 0; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // on all dialogs. | 327 // on all dialogs. |
322 views::NonClientFrameView* MediaGalleriesDialogViews::CreateNonClientFrameView( | 328 views::NonClientFrameView* MediaGalleriesDialogViews::CreateNonClientFrameView( |
323 views::Widget* widget) { | 329 views::Widget* widget) { |
324 return CreateConstrainedStyleNonClientFrameView( | 330 return CreateConstrainedStyleNonClientFrameView( |
325 widget, | 331 widget, |
326 controller_->web_contents()->GetBrowserContext()); | 332 controller_->web_contents()->GetBrowserContext()); |
327 } | 333 } |
328 | 334 |
329 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, | 335 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, |
330 const ui::Event& event) { | 336 const ui::Event& event) { |
| 337 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); |
| 338 |
| 339 ButtonPressedAction(sender); |
| 340 } |
| 341 |
| 342 void MediaGalleriesDialogViews::ButtonPressedAction(views::Button* sender) { |
331 confirm_available_ = true; | 343 confirm_available_ = true; |
332 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); | |
333 | 344 |
334 if (sender == add_gallery_button_) { | 345 if (sender == add_gallery_button_) { |
335 controller_->OnAddFolderClicked(); | 346 controller_->OnAddFolderClicked(); |
336 return; | 347 return; |
337 } | 348 } |
338 | 349 |
339 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | 350 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); |
340 iter != checkbox_map_.end(); ++iter) { | 351 iter != checkbox_map_.end(); ++iter) { |
341 if (sender == iter->second) { | 352 if (sender == iter->second) { |
342 controller_->DidToggleGalleryId(iter->first, | 353 controller_->DidToggleGalleryId(iter->first, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 391 } |
381 } | 392 } |
382 | 393 |
383 // MediaGalleriesDialogViewsController ----------------------------------------- | 394 // MediaGalleriesDialogViewsController ----------------------------------------- |
384 | 395 |
385 // static | 396 // static |
386 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 397 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
387 MediaGalleriesDialogController* controller) { | 398 MediaGalleriesDialogController* controller) { |
388 return new MediaGalleriesDialogViews(controller); | 399 return new MediaGalleriesDialogViews(controller); |
389 } | 400 } |
OLD | NEW |