| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_gallery_checkbox_view.h" | 5 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" | 7 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "grit/theme_resources.h" | 9 #include "grit/theme_resources.h" |
| 10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/views/border.h" | 13 #include "ui/views/border.h" |
| 15 #include "ui/views/context_menu_controller.h" | 14 #include "ui/views/context_menu_controller.h" |
| 16 #include "ui/views/controls/button/button.h" | 15 #include "ui/views/controls/button/button.h" |
| 17 #include "ui/views/controls/button/checkbox.h" | 16 #include "ui/views/controls/button/checkbox.h" |
| 18 #include "ui/views/controls/button/image_button.h" | |
| 19 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
| 21 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 // Equal to the #9F9F9F color used in spec (note WebUI color is #999). | 23 // Equal to the #9F9F9F color used in spec (note WebUI color is #999). |
| 26 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); | 24 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); |
| 27 | 25 |
| 28 } // namespace | 26 } // namespace |
| 29 | 27 |
| 30 MediaGalleryCheckboxView::MediaGalleryCheckboxView( | 28 MediaGalleryCheckboxView::MediaGalleryCheckboxView( |
| 31 const MediaGalleryPrefInfo& pref_info, | 29 const MediaGalleryPrefInfo& pref_info, |
| 32 bool show_folder_button, | |
| 33 int trailing_vertical_space, | 30 int trailing_vertical_space, |
| 34 views::ButtonListener* button_listener, | 31 views::ButtonListener* button_listener, |
| 35 views::ContextMenuController* menu_controller) { | 32 views::ContextMenuController* menu_controller) { |
| 36 DCHECK(button_listener != NULL); | 33 DCHECK(button_listener != NULL); |
| 37 SetLayoutManager( | 34 SetLayoutManager( |
| 38 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 35 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 39 SetBorder(views::Border::CreateEmptyBorder( | 36 SetBorder(views::Border::CreateEmptyBorder( |
| 40 0, views::kPanelHorizMargin, trailing_vertical_space, | 37 0, views::kPanelHorizMargin, trailing_vertical_space, |
| 41 views::kPanelHorizMargin)); | 38 views::kPanelHorizMargin)); |
| 42 if (menu_controller) | 39 if (menu_controller) |
| 43 set_context_menu_controller(menu_controller); | 40 set_context_menu_controller(menu_controller); |
| 44 | 41 |
| 45 checkbox_ = new views::Checkbox(pref_info.GetGalleryDisplayName()); | 42 checkbox_ = new views::Checkbox(pref_info.GetGalleryDisplayName()); |
| 46 checkbox_->set_listener(button_listener); | 43 checkbox_->set_listener(button_listener); |
| 47 if (menu_controller) | 44 if (menu_controller) |
| 48 checkbox_->set_context_menu_controller(menu_controller); | 45 checkbox_->set_context_menu_controller(menu_controller); |
| 49 checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE); | 46 checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 50 base::string16 tooltip_text = pref_info.GetGalleryTooltip(); | 47 base::string16 tooltip_text = pref_info.GetGalleryTooltip(); |
| 51 checkbox_->SetTooltipText(tooltip_text); | 48 checkbox_->SetTooltipText(tooltip_text); |
| 52 | 49 |
| 53 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 54 folder_viewer_button_ = new views::ImageButton(button_listener); | |
| 55 if (menu_controller) | |
| 56 folder_viewer_button_->set_context_menu_controller(menu_controller); | |
| 57 folder_viewer_button_->SetImage(views::ImageButton::STATE_NORMAL, | |
| 58 rb.GetImageSkiaNamed(IDR_FILE_FOLDER)); | |
| 59 folder_viewer_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 60 views::ImageButton::ALIGN_MIDDLE); | |
| 61 folder_viewer_button_->SetAccessibleName(l10n_util::GetStringUTF16( | |
| 62 IDS_MEDIA_GALLERIES_SCAN_RESULT_OPEN_FOLDER_VIEW_ACCESSIBILITY_NAME)); | |
| 63 folder_viewer_button_->SetFocusable(true); | |
| 64 folder_viewer_button_->SetVisible(show_folder_button); | |
| 65 folder_viewer_button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 66 0, views::kRelatedControlSmallHorizontalSpacing, 0, 0)); | |
| 67 | |
| 68 base::string16 details = pref_info.GetGalleryAdditionalDetails(); | 50 base::string16 details = pref_info.GetGalleryAdditionalDetails(); |
| 69 secondary_text_ = new views::Label(details); | 51 secondary_text_ = new views::Label(details); |
| 70 if (menu_controller) | 52 if (menu_controller) |
| 71 secondary_text_->set_context_menu_controller(menu_controller); | 53 secondary_text_->set_context_menu_controller(menu_controller); |
| 72 secondary_text_->SetVisible(details.length() > 0); | 54 secondary_text_->SetVisible(details.length() > 0); |
| 73 secondary_text_->SetEnabledColor(kDeemphasizedTextColor); | 55 secondary_text_->SetEnabledColor(kDeemphasizedTextColor); |
| 74 secondary_text_->SetElideBehavior(gfx::ELIDE_HEAD); | 56 secondary_text_->SetElideBehavior(gfx::ELIDE_HEAD); |
| 75 secondary_text_->SetTooltipText(tooltip_text); | 57 secondary_text_->SetTooltipText(tooltip_text); |
| 76 secondary_text_->SetBorder(views::Border::CreateEmptyBorder( | 58 secondary_text_->SetBorder(views::Border::CreateEmptyBorder( |
| 77 0, views::kRelatedControlSmallHorizontalSpacing, 0, 0)); | 59 0, views::kRelatedControlSmallHorizontalSpacing, 0, 0)); |
| 78 | 60 |
| 79 AddChildView(checkbox_); | 61 AddChildView(checkbox_); |
| 80 AddChildView(folder_viewer_button_); | |
| 81 AddChildView(secondary_text_); | 62 AddChildView(secondary_text_); |
| 82 } | 63 } |
| 83 | 64 |
| 84 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} | 65 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} |
| 85 | 66 |
| 86 void MediaGalleryCheckboxView::Layout() { | 67 void MediaGalleryCheckboxView::Layout() { |
| 87 views::View::Layout(); | 68 views::View::Layout(); |
| 88 if (GetPreferredSize().width() <= GetLocalBounds().width()) | 69 if (GetPreferredSize().width() <= GetLocalBounds().width()) |
| 89 return; | 70 return; |
| 90 | 71 |
| 91 // If box layout doesn't fit, do custom layout. The folder_viewer_button and | 72 // If box layout doesn't fit, do custom layout. The secondary text should take |
| 92 // the secondary text should take up at most half of the space and the | 73 // up at most half of the space and the checkbox can take up whatever is left. |
| 93 // checkbox can take up what ever is left. | |
| 94 int checkbox_width = checkbox_->GetPreferredSize().width(); | 74 int checkbox_width = checkbox_->GetPreferredSize().width(); |
| 95 int folder_viewer_width = folder_viewer_button_->GetPreferredSize().width(); | |
| 96 int secondary_text_width = secondary_text_->GetPreferredSize().width(); | 75 int secondary_text_width = secondary_text_->GetPreferredSize().width(); |
| 97 if (!folder_viewer_button_->visible()) | |
| 98 folder_viewer_width = 0; | |
| 99 if (!secondary_text_->visible()) | 76 if (!secondary_text_->visible()) |
| 100 secondary_text_width = 0; | 77 secondary_text_width = 0; |
| 101 | 78 |
| 102 gfx::Rect area(GetLocalBounds()); | 79 gfx::Rect area(GetLocalBounds()); |
| 103 area.Inset(GetInsets()); | 80 area.Inset(GetInsets()); |
| 104 | 81 |
| 105 if (folder_viewer_width + secondary_text_width > area.width() / 2) { | 82 if (secondary_text_width > area.width() / 2) { |
| 106 secondary_text_width = | 83 secondary_text_width = |
| 107 std::max(area.width() / 2 - folder_viewer_width, | 84 std::max(area.width() / 2, area.width() - checkbox_width); |
| 108 area.width() - folder_viewer_width - checkbox_width); | |
| 109 } | 85 } |
| 110 checkbox_width = area.width() - folder_viewer_width - secondary_text_width; | 86 checkbox_width = area.width() - secondary_text_width; |
| 111 | 87 |
| 112 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); | 88 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); |
| 113 if (folder_viewer_button_->visible()) { | |
| 114 folder_viewer_button_->SetBounds(checkbox_->x() + checkbox_width, area.y(), | |
| 115 folder_viewer_width, area.height()); | |
| 116 } | |
| 117 if (secondary_text_->visible()) { | 89 if (secondary_text_->visible()) { |
| 118 secondary_text_->SetBounds( | 90 secondary_text_->SetBounds(checkbox_->x() + checkbox_width, area.y(), |
| 119 checkbox_->x() + checkbox_width + folder_viewer_width, | 91 secondary_text_width, area.height()); |
| 120 area.y(), secondary_text_width, area.height()); | |
| 121 } | 92 } |
| 122 } | 93 } |
| OLD | NEW |