Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / media_gallery_checkbox_view.cc
blob533539fa5ba1cdac2bf77c5073fe894bc1123fdc
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/extensions/media_gallery_checkbox_view.h"
7 #include "grit/generated_resources.h"
8 #include "grit/theme_resources.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/views/border.h"
14 #include "ui/views/context_menu_controller.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/button/checkbox.h"
17 #include "ui/views/controls/button/image_button.h"
18 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/box_layout.h"
20 #include "ui/views/layout/layout_constants.h"
22 namespace {
24 // Equal to the #9F9F9F color used in spec (note WebUI color is #999).
25 const SkColor kDeemphasizedTextColor = SkColorSetRGB(159, 159, 159);
27 } // namespace
29 MediaGalleryCheckboxView::MediaGalleryCheckboxView(
30 const base::string16& label,
31 const base::string16& tooltip_text,
32 const base::string16& details,
33 bool show_folder_button,
34 int trailing_vertical_space,
35 views::ButtonListener* button_listener,
36 views::ContextMenuController* menu_controller) {
37 DCHECK(button_listener != NULL);
38 SetLayoutManager(
39 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
40 SetBorder(views::Border::CreateEmptyBorder(
41 0, views::kPanelHorizMargin, trailing_vertical_space,
42 views::kPanelHorizMargin));
43 if (menu_controller)
44 set_context_menu_controller(menu_controller);
46 checkbox_ = new views::Checkbox(label);
47 checkbox_->set_listener(button_listener);
48 if (menu_controller)
49 checkbox_->set_context_menu_controller(menu_controller);
50 checkbox_->SetElideBehavior(views::Label::ELIDE_IN_MIDDLE);
51 checkbox_->SetTooltipText(tooltip_text);
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));
68 secondary_text_ = new views::Label(details);
69 if (menu_controller)
70 secondary_text_->set_context_menu_controller(menu_controller);
71 secondary_text_->SetVisible(details.length() > 0);
72 secondary_text_->SetEnabledColor(kDeemphasizedTextColor);
73 secondary_text_->SetElideBehavior(views::Label::ELIDE_AT_BEGINNING);
74 secondary_text_->SetTooltipText(tooltip_text);
75 secondary_text_->SetBorder(views::Border::CreateEmptyBorder(
76 0, views::kRelatedControlSmallHorizontalSpacing, 0, 0));
78 AddChildView(checkbox_);
79 AddChildView(folder_viewer_button_);
80 AddChildView(secondary_text_);
83 MediaGalleryCheckboxView::~MediaGalleryCheckboxView() {}
85 void MediaGalleryCheckboxView::Layout() {
86 views::View::Layout();
87 if (GetPreferredSize().width() <= GetLocalBounds().width())
88 return;
90 // If box layout doesn't fit, do custom layout. The folder_viewer_button and
91 // the secondary text should take up at most half of the space and the
92 // checkbox can take up what ever is left.
93 int checkbox_width = checkbox_->GetPreferredSize().width();
94 int folder_viewer_width = folder_viewer_button_->GetPreferredSize().width();
95 int secondary_text_width = secondary_text_->GetPreferredSize().width();
96 if (!folder_viewer_button_->visible())
97 folder_viewer_width = 0;
98 if (!secondary_text_->visible())
99 secondary_text_width = 0;
101 gfx::Rect area(GetLocalBounds());
102 area.Inset(GetInsets());
104 if (folder_viewer_width + secondary_text_width > area.width() / 2) {
105 secondary_text_width =
106 std::max(area.width() / 2 - folder_viewer_width,
107 area.width() - folder_viewer_width - checkbox_width);
109 checkbox_width = area.width() - folder_viewer_width - secondary_text_width;
111 checkbox_->SetBounds(area.x(), area.y(), checkbox_width, area.height());
112 if (folder_viewer_button_->visible()) {
113 folder_viewer_button_->SetBounds(checkbox_->x() + checkbox_width, area.y(),
114 folder_viewer_width, area.height());
116 if (secondary_text_->visible()) {
117 secondary_text_->SetBounds(
118 checkbox_->x() + checkbox_width + folder_viewer_width,
119 area.y(), secondary_text_width, area.height());