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/layout_delegate.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 #include "ui/views/layout/layout_constants.h" | |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 // 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). |
22 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); | 21 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159); |
23 | 22 |
24 } // namespace | 23 } // namespace |
25 | 24 |
26 MediaGalleryCheckboxView::MediaGalleryCheckboxView( | 25 MediaGalleryCheckboxView::MediaGalleryCheckboxView( |
27 const MediaGalleryPrefInfo& pref_info, | 26 const MediaGalleryPrefInfo& pref_info, |
28 int trailing_vertical_space, | 27 int trailing_vertical_space, |
29 views::ButtonListener* button_listener, | 28 views::ButtonListener* button_listener, |
30 views::ContextMenuController* menu_controller) { | 29 views::ContextMenuController* menu_controller) { |
31 DCHECK(button_listener != NULL); | 30 DCHECK(button_listener != NULL); |
32 SetLayoutManager( | 31 SetLayoutManager( |
33 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 32 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
34 const int border_horiz_margin = LayoutDelegate::Get()->GetMetric( | 33 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); |
35 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | 34 const int border_horiz_margin = |
| 35 layout_delegate->GetMetric(LayoutDelegate::Metric::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, views::kRelatedControlSmallHorizontalSpacing, 0, 0)); | 58 0, |
| 59 layout_delegate->GetMetric( |
| 60 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING_SMALL), |
| 61 0, 0)); |
59 | 62 |
60 AddChildView(checkbox_); | 63 AddChildView(checkbox_); |
61 AddChildView(secondary_text_); | 64 AddChildView(secondary_text_); |
62 } | 65 } |
63 | 66 |
64 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} | 67 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {} |
65 | 68 |
66 void MediaGalleryCheckboxView::Layout() { | 69 void MediaGalleryCheckboxView::Layout() { |
67 views::View::Layout(); | 70 views::View::Layout(); |
68 if (GetPreferredSize().width() <= GetLocalBounds().width()) | 71 if (GetPreferredSize().width() <= GetLocalBounds().width()) |
(...skipping 14 matching lines...) Expand all Loading... |
83 std::max(area.width() / 2, area.width() - checkbox_width); | 86 std::max(area.width() / 2, area.width() - checkbox_width); |
84 } | 87 } |
85 checkbox_width = area.width() - secondary_text_width; | 88 checkbox_width = area.width() - secondary_text_width; |
86 | 89 |
87 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); | 90 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height()); |
88 if (secondary_text_->visible()) { | 91 if (secondary_text_->visible()) { |
89 secondary_text_->SetBounds(checkbox_->x() + checkbox_width, area.y(), | 92 secondary_text_->SetBounds(checkbox_->x() + checkbox_width, area.y(), |
90 secondary_text_width, area.height()); | 93 secondary_text_width, area.height()); |
91 } | 94 } |
92 } | 95 } |
OLD | NEW |