| 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/extensions/media_gallery_checkbox_view.h" | 9 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" |
| 9 #include "components/web_modal/web_contents_modal_dialog_host.h" | |
| 10 #include "components/web_modal/web_contents_modal_dialog_manager.h" | |
| 11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | |
| 12 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 13 #include "grit/generated_resources.h" | 11 #include "grit/generated_resources.h" |
| 14 #include "grit/locale_settings.h" | 12 #include "grit/locale_settings.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/border.h" | 15 #include "ui/views/border.h" |
| 18 #include "ui/views/controls/button/checkbox.h" | 16 #include "ui/views/controls/button/checkbox.h" |
| 19 #include "ui/views/controls/button/label_button.h" | 17 #include "ui/views/controls/button/label_button.h" |
| 20 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/controls/menu/menu_runner.h" | 19 #include "ui/views/controls/menu/menu_runner.h" |
| 22 #include "ui/views/controls/scroll_view.h" | 20 #include "ui/views/controls/scroll_view.h" |
| 23 #include "ui/views/controls/separator.h" | 21 #include "ui/views/controls/separator.h" |
| 24 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
| 26 #include "ui/views/layout/layout_constants.h" | 24 #include "ui/views/layout/layout_constants.h" |
| 27 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
| 28 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/window/dialog_client_view.h" | 27 #include "ui/views/window/dialog_client_view.h" |
| 30 | 28 |
| 31 using web_modal::WebContentsModalDialogManager; | |
| 32 using web_modal::WebContentsModalDialogManagerDelegate; | |
| 33 | |
| 34 namespace { | 29 namespace { |
| 35 | 30 |
| 36 const int kScrollAreaHeight = 192; | 31 const int kScrollAreaHeight = 192; |
| 37 | 32 |
| 38 // This container has the right Layout() impl to use within a ScrollView. | 33 // This container has the right Layout() impl to use within a ScrollView. |
| 39 class ScrollableView : public views::View { | 34 class ScrollableView : public views::View { |
| 40 public: | 35 public: |
| 41 ScrollableView() {} | 36 ScrollableView() {} |
| 42 virtual ~ScrollableView() {} | 37 virtual ~ScrollableView() {} |
| 43 | 38 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 } | 56 } |
| 62 | 57 |
| 63 } // namespace | 58 } // namespace |
| 64 | 59 |
| 65 typedef MediaGalleriesDialogController::GalleryPermissionsVector | 60 typedef MediaGalleriesDialogController::GalleryPermissionsVector |
| 66 GalleryPermissionsVector; | 61 GalleryPermissionsVector; |
| 67 | 62 |
| 68 MediaGalleriesDialogViews::MediaGalleriesDialogViews( | 63 MediaGalleriesDialogViews::MediaGalleriesDialogViews( |
| 69 MediaGalleriesDialogController* controller) | 64 MediaGalleriesDialogController* controller) |
| 70 : controller_(controller), | 65 : controller_(controller), |
| 71 window_(NULL), | |
| 72 contents_(new views::View()), | 66 contents_(new views::View()), |
| 73 add_gallery_button_(NULL), | 67 add_gallery_button_(NULL), |
| 74 confirm_available_(false), | 68 confirm_available_(false), |
| 75 accepted_(false) { | 69 accepted_(false) { |
| 76 InitChildViews(); | 70 InitChildViews(); |
| 77 | 71 if (ControllerHasWebContents()) |
| 78 if (ControllerHasWebContents()) { | 72 ShowWebModalDialogViews(this, controller->web_contents()); |
| 79 // Ownership of |contents_| is handed off by this call. |window_| will take | |
| 80 // care of deleting itself after calling DeleteDelegate(). | |
| 81 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | |
| 82 WebContentsModalDialogManager::FromWebContents( | |
| 83 controller->web_contents()); | |
| 84 DCHECK(web_contents_modal_dialog_manager); | |
| 85 WebContentsModalDialogManagerDelegate* modal_delegate = | |
| 86 web_contents_modal_dialog_manager->delegate(); | |
| 87 DCHECK(modal_delegate); | |
| 88 window_ = views::Widget::CreateWindowAsFramelessChild( | |
| 89 this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView()); | |
| 90 web_contents_modal_dialog_manager->ShowModalDialog( | |
| 91 window_->GetNativeView()); | |
| 92 } | |
| 93 } | 73 } |
| 94 | 74 |
| 95 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() { | 75 MediaGalleriesDialogViews::~MediaGalleriesDialogViews() { |
| 96 if (!ControllerHasWebContents()) | 76 if (!ControllerHasWebContents()) |
| 97 delete contents_; | 77 delete contents_; |
| 98 } | 78 } |
| 99 | 79 |
| 100 void MediaGalleriesDialogViews::InitChildViews() { | 80 void MediaGalleriesDialogViews::InitChildViews() { |
| 101 // Outer dialog layout. | 81 // Outer dialog layout. |
| 102 contents_->RemoveAllChildViews(true); | 82 contents_->RemoveAllChildViews(true); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 IDS_MEDIA_GALLERIES_DIALOG_CONFIRM : | 230 IDS_MEDIA_GALLERIES_DIALOG_CONFIRM : |
| 251 IDS_MEDIA_GALLERIES_DIALOG_CANCEL); | 231 IDS_MEDIA_GALLERIES_DIALOG_CANCEL); |
| 252 } | 232 } |
| 253 | 233 |
| 254 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( | 234 bool MediaGalleriesDialogViews::IsDialogButtonEnabled( |
| 255 ui::DialogButton button) const { | 235 ui::DialogButton button) const { |
| 256 return button != ui::DIALOG_BUTTON_OK || confirm_available_; | 236 return button != ui::DIALOG_BUTTON_OK || confirm_available_; |
| 257 } | 237 } |
| 258 | 238 |
| 259 ui::ModalType MediaGalleriesDialogViews::GetModalType() const { | 239 ui::ModalType MediaGalleriesDialogViews::GetModalType() const { |
| 260 #if defined(USE_ASH) | |
| 261 return ui::MODAL_TYPE_CHILD; | 240 return ui::MODAL_TYPE_CHILD; |
| 262 #else | |
| 263 return views::WidgetDelegate::GetModalType(); | |
| 264 #endif | |
| 265 } | 241 } |
| 266 | 242 |
| 267 views::View* MediaGalleriesDialogViews::CreateExtraView() { | 243 views::View* MediaGalleriesDialogViews::CreateExtraView() { |
| 268 DCHECK(!add_gallery_button_); | 244 DCHECK(!add_gallery_button_); |
| 269 add_gallery_button_ = new views::LabelButton(this, | 245 add_gallery_button_ = new views::LabelButton(this, |
| 270 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); | 246 l10n_util::GetStringUTF16(IDS_MEDIA_GALLERIES_DIALOG_ADD_GALLERY)); |
| 271 add_gallery_button_->SetStyle(views::Button::STYLE_BUTTON); | 247 add_gallery_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 272 return add_gallery_button_; | 248 return add_gallery_button_; |
| 273 } | 249 } |
| 274 | 250 |
| 275 bool MediaGalleriesDialogViews::Cancel() { | 251 bool MediaGalleriesDialogViews::Cancel() { |
| 276 return true; | 252 return true; |
| 277 } | 253 } |
| 278 | 254 |
| 279 bool MediaGalleriesDialogViews::Accept() { | 255 bool MediaGalleriesDialogViews::Accept() { |
| 280 accepted_ = true; | 256 accepted_ = true; |
| 281 | |
| 282 return true; | 257 return true; |
| 283 } | 258 } |
| 284 | 259 |
| 285 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, | 260 void MediaGalleriesDialogViews::ButtonPressed(views::Button* sender, |
| 286 const ui::Event& /* event */) { | 261 const ui::Event& /* event */) { |
| 287 confirm_available_ = true; | 262 confirm_available_ = true; |
| 288 | 263 |
| 289 if (ControllerHasWebContents()) | 264 if (ControllerHasWebContents()) |
| 290 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); | 265 GetWidget()->client_view()->AsDialogClientView()->UpdateDialogButtons(); |
| 291 | 266 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 return controller_->web_contents() != NULL; | 314 return controller_->web_contents() != NULL; |
| 340 } | 315 } |
| 341 | 316 |
| 342 // MediaGalleriesDialogViewsController ----------------------------------------- | 317 // MediaGalleriesDialogViewsController ----------------------------------------- |
| 343 | 318 |
| 344 // static | 319 // static |
| 345 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 320 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
| 346 MediaGalleriesDialogController* controller) { | 321 MediaGalleriesDialogController* controller) { |
| 347 return new MediaGalleriesDialogViews(controller); | 322 return new MediaGalleriesDialogViews(controller); |
| 348 } | 323 } |
| OLD | NEW |