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" |
11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "grit/locale_settings.h" | 15 #include "grit/locale_settings.h" |
16 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/native_theme/native_theme.h" | 19 #include "ui/native_theme/native_theme.h" |
20 #include "ui/views/controls/button/checkbox.h" | 20 #include "ui/views/controls/button/checkbox.h" |
21 #include "ui/views/controls/button/label_button.h" | 21 #include "ui/views/controls/button/label_button.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/controls/menu/menu_runner.h" | |
23 #include "ui/views/controls/scroll_view.h" | 24 #include "ui/views/controls/scroll_view.h" |
24 #include "ui/views/controls/separator.h" | 25 #include "ui/views/controls/separator.h" |
25 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
26 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
27 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
28 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
30 #include "ui/views/window/dialog_client_view.h" | 31 #include "ui/views/window/dialog_client_view.h" |
31 | 32 |
32 using web_modal::WebContentsModalDialogManager; | 33 using web_modal::WebContentsModalDialogManager; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 views::View* checkbox_view = checkbox->parent(); | 229 views::View* checkbox_view = checkbox->parent(); |
229 DCHECK_EQ(2, checkbox_view->child_count()); | 230 DCHECK_EQ(2, checkbox_view->child_count()); |
230 views::Label* secondary_text = | 231 views::Label* secondary_text = |
231 static_cast<views::Label*>(checkbox_view->child_at(1)); | 232 static_cast<views::Label*>(checkbox_view->child_at(1)); |
232 secondary_text->SetText(details); | 233 secondary_text->SetText(details); |
233 return false; | 234 return false; |
234 } | 235 } |
235 | 236 |
236 views::Checkbox* checkbox = new views::Checkbox(label); | 237 views::Checkbox* checkbox = new views::Checkbox(label); |
237 checkbox->set_listener(this); | 238 checkbox->set_listener(this); |
239 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
240 checkbox->set_context_menu_controller(this); | |
238 checkbox->SetTooltipText(tooltip_text); | 241 checkbox->SetTooltipText(tooltip_text); |
239 views::Label* secondary_text = new views::Label(details); | 242 views::Label* secondary_text = new views::Label(details); |
243 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
244 secondary_text->set_context_menu_controller(this); | |
240 secondary_text->SetTooltipText(tooltip_text); | 245 secondary_text->SetTooltipText(tooltip_text); |
241 secondary_text->SetEnabledColor(kDeemphasizedTextColor); | 246 secondary_text->SetEnabledColor(kDeemphasizedTextColor); |
242 secondary_text->SetTooltipText(tooltip_text); | 247 secondary_text->SetTooltipText(tooltip_text); |
243 secondary_text->set_border(views::Border::CreateEmptyBorder( | 248 secondary_text->set_border(views::Border::CreateEmptyBorder( |
244 0, | 249 0, |
245 views::kRelatedControlSmallHorizontalSpacing, | 250 views::kRelatedControlSmallHorizontalSpacing, |
246 0, | 251 0, |
247 views::kRelatedControlSmallHorizontalSpacing)); | 252 views::kRelatedControlSmallHorizontalSpacing)); |
248 | 253 |
249 views::View* checkbox_view = new views::View(); | 254 views::View* checkbox_view = new views::View(); |
255 if (gallery.pref_id != kInvalidMediaGalleryPrefId) | |
256 checkbox_view->set_context_menu_controller(this); | |
250 checkbox_view->set_border(views::Border::CreateEmptyBorder( | 257 checkbox_view->set_border(views::Border::CreateEmptyBorder( |
251 0, | 258 0, |
252 views::kPanelHorizMargin, | 259 views::kPanelHorizMargin, |
253 trailing_vertical_space, | 260 trailing_vertical_space, |
254 0)); | 261 0)); |
255 checkbox_view->SetLayoutManager( | 262 checkbox_view->SetLayoutManager( |
256 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 263 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
257 checkbox_view->AddChildView(checkbox); | 264 checkbox_view->AddChildView(checkbox); |
258 checkbox_view->AddChildView(secondary_text); | 265 checkbox_view->AddChildView(secondary_text); |
259 | 266 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 } | 365 } |
359 } | 366 } |
360 for (NewCheckboxMap::const_iterator iter = new_checkbox_map_.begin(); | 367 for (NewCheckboxMap::const_iterator iter = new_checkbox_map_.begin(); |
361 iter != new_checkbox_map_.end(); ++iter) { | 368 iter != new_checkbox_map_.end(); ++iter) { |
362 if (sender == iter->first) { | 369 if (sender == iter->first) { |
363 controller_->DidToggleNewGallery(iter->second, iter->first->checked()); | 370 controller_->DidToggleNewGallery(iter->second, iter->first->checked()); |
364 } | 371 } |
365 } | 372 } |
366 } | 373 } |
367 | 374 |
375 void MediaGalleriesDialogViews::ShowContextMenuForView( | |
376 views::View* source, | |
377 const gfx::Point& point, | |
378 ui::MenuSourceType source_type) { | |
379 for (CheckboxMap::const_iterator iter = checkbox_map_.begin(); | |
380 iter != checkbox_map_.end(); ++iter) { | |
381 if (iter->second->parent()->Contains(source)) { | |
382 ShowContextMenu(point, source_type, iter->first); | |
383 return; | |
384 } | |
385 } | |
386 } | |
387 | |
388 void MediaGalleriesDialogViews::ShowContextMenu(const gfx::Point& point, | |
sky
2013/10/29 01:19:50
Position should match that of header. Maybe a bunc
Greg Billock
2013/10/29 17:04:06
I put this after ButtonPressed in both, but yes, I
| |
389 ui::MenuSourceType source_type, | |
390 MediaGalleryPrefId id) { | |
391 context_menu_runner_.reset(new views::MenuRunner( | |
392 controller_->GetContextMenuModel(id))); | |
393 | |
394 if (context_menu_runner_->RunMenuAt( | |
395 GetWidget(), NULL, gfx::Rect(point.x(), point.y(), 0, 0), | |
396 views::MenuItemView::TOPLEFT, source_type, | |
397 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) == | |
398 views::MenuRunner::MENU_DELETED) { | |
399 return; | |
400 } | |
401 } | |
402 | |
368 // MediaGalleriesDialogViewsController ----------------------------------------- | 403 // MediaGalleriesDialogViewsController ----------------------------------------- |
369 | 404 |
370 // static | 405 // static |
371 MediaGalleriesDialog* MediaGalleriesDialog::Create( | 406 MediaGalleriesDialog* MediaGalleriesDialog::Create( |
372 MediaGalleriesDialogController* controller) { | 407 MediaGalleriesDialogController* controller) { |
373 return new MediaGalleriesDialogViews(controller); | 408 return new MediaGalleriesDialogViews(controller); |
374 } | 409 } |
OLD | NEW |