| 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/browser/ui/views/harmony/layout_delegate.h" | 8 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/views/border.h" | 11 #include "ui/views/border.h" |
| 12 #include "ui/views/context_menu_controller.h" | 12 #include "ui/views/context_menu_controller.h" |
| 13 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/button/checkbox.h" | 14 #include "ui/views/controls/button/checkbox.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // Equal to the #9F9F9F color used in spec (note WebUI color is #999). | 20 // Equal to the #9F9F9F color used in spec (note WebUI color is #999). |
| 21 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); | 21 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 MediaGalleryCheckboxView::MediaGalleryCheckboxView( | 25 MediaGalleryCheckboxView::MediaGalleryCheckboxView( |
| 26 const MediaGalleryPrefInfo& pref_info, | 26 const MediaGalleryPrefInfo& pref_info, |
| 27 int trailing_vertical_space, | 27 int trailing_vertical_space, |
| 28 views::ButtonListener* button_listener, | 28 views::ButtonListener* button_listener, |
| 29 views::ContextMenuController* menu_controller) { | 29 views::ContextMenuController* menu_controller) { |
| 30 DCHECK(button_listener != NULL); | 30 DCHECK(button_listener != NULL); |
| 31 SetLayoutManager( | 31 SetLayoutManager( |
| 32 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 32 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 33 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | 33 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
| 34 const int border_horiz_margin = | 34 const int border_horiz_margin = |
| 35 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | 35 provider->GetDistanceMetric(DISTANCE_PANEL_CONTENT_MARGIN); |
| 36 SetBorder(views::CreateEmptyBorder( | 36 SetBorder(views::CreateEmptyBorder( |
| 37 0, border_horiz_margin, trailing_vertical_space, border_horiz_margin)); | 37 0, border_horiz_margin, trailing_vertical_space, border_horiz_margin)); |
| 38 if (menu_controller) | 38 if (menu_controller) |
| 39 set_context_menu_controller(menu_controller); | 39 set_context_menu_controller(menu_controller); |
| 40 | 40 |
| 41 checkbox_ = new views::Checkbox(pref_info.GetGalleryDisplayName()); | 41 checkbox_ = new views::Checkbox(pref_info.GetGalleryDisplayName()); |
| 42 checkbox_->set_listener(button_listener); | 42 checkbox_->set_listener(button_listener); |
| 43 if (menu_controller) | 43 if (menu_controller) |
| 44 checkbox_->set_context_menu_controller(menu_controller); | 44 checkbox_->set_context_menu_controller(menu_controller); |
| 45 checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE); | 45 checkbox_->SetElideBehavior(gfx::ELIDE_MIDDLE); |
| 46 base::string16 tooltip_text = pref_info.GetGalleryTooltip(); | 46 base::string16 tooltip_text = pref_info.GetGalleryTooltip(); |
| 47 checkbox_->SetTooltipText(tooltip_text); | 47 checkbox_->SetTooltipText(tooltip_text); |
| 48 | 48 |
| 49 base::string16 details = pref_info.GetGalleryAdditionalDetails(); | 49 base::string16 details = pref_info.GetGalleryAdditionalDetails(); |
| 50 secondary_text_ = new views::Label(details); | 50 secondary_text_ = new views::Label(details); |
| 51 if (menu_controller) | 51 if (menu_controller) |
| 52 secondary_text_->set_context_menu_controller(menu_controller); | 52 secondary_text_->set_context_menu_controller(menu_controller); |
| 53 secondary_text_->SetVisible(details.length() > 0); | 53 secondary_text_->SetVisible(details.length() > 0); |
| 54 secondary_text_->SetEnabledColor(kDeemphasizedTextColor); | 54 secondary_text_->SetEnabledColor(kDeemphasizedTextColor); |
| 55 secondary_text_->SetElideBehavior(gfx::ELIDE_HEAD); | 55 secondary_text_->SetElideBehavior(gfx::ELIDE_HEAD); |
| 56 secondary_text_->SetTooltipText(tooltip_text); | 56 secondary_text_->SetTooltipText(tooltip_text); |
| 57 secondary_text_->SetBorder(views::CreateEmptyBorder( | 57 secondary_text_->SetBorder(views::CreateEmptyBorder( |
| 58 0, | 58 0, provider->GetDistanceMetric(DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL), |
| 59 layout_delegate->GetMetric( | |
| 60 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING_SMALL), | |
| 61 0, 0)); | 59 0, 0)); |
| 62 | 60 |
| 63 AddChildView(checkbox_); | 61 AddChildView(checkbox_); |
| 64 AddChildView(secondary_text_); | 62 AddChildView(secondary_text_); |
| 65 } | 63 } |
| 66 | 64 |
| 67 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} | 65 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} |
| 68 | 66 |
| 69 void MediaGalleryCheckboxView::Layout() { | 67 void MediaGalleryCheckboxView::Layout() { |
| 70 views::View::Layout(); | 68 views::View::Layout(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 86 std::max(area.width() / 2, area.width() - checkbox_width); | 84 std::max(area.width() / 2, area.width() - checkbox_width); |
| 87 } | 85 } |
| 88 checkbox_width = area.width() - secondary_text_width; | 86 checkbox_width = area.width() - secondary_text_width; |
| 89 | 87 |
| 90 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); | 88 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); |
| 91 if (secondary_text_->visible()) { | 89 if (secondary_text_->visible()) { |
| 92 secondary_text_->SetBounds(checkbox_->x() + checkbox_width, area.y(), | 90 secondary_text_->SetBounds(checkbox_->x() + checkbox_width, area.y(), |
| 93 secondary_text_width, area.height()); | 91 secondary_text_width, area.height()); |
| 94 } | 92 } |
| 95 } | 93 } |
| OLD | NEW |