1 // Copyright (c) 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 "ash/system/tray/tray_popup_item_container.h"
7 #include "ash/system/tray/tray_constants.h"
8 #include "base/command_line.h"
9 #include "ui/base/ui_base_switches_util.h"
10 #include "ui/gfx/canvas.h"
11 #include "ui/views/border.h"
12 #include "ui/views/layout/box_layout.h"
16 TrayPopupItemContainer::TrayPopupItemContainer(views::View
* view
,
17 bool change_background
,
20 change_background_(change_background
) {
21 set_notify_enter_exit_on_child(true);
24 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor
));
26 views::BoxLayout
* layout
= new views::BoxLayout(
27 views::BoxLayout::kVertical
, 0, 0, 0);
28 layout
->SetDefaultFlex(1);
29 SetLayoutManager(layout
);
30 SetPaintToLayer(view
->layer() != NULL
);
32 SetFillsBoundsOpaquely(view
->layer()->fills_bounds_opaquely());
34 SetVisible(view
->visible());
37 TrayPopupItemContainer::~TrayPopupItemContainer() {
40 void TrayPopupItemContainer::SetActive(bool active
) {
41 if (!change_background_
|| active_
== active
)
47 void TrayPopupItemContainer::ChildVisibilityChanged(View
* child
) {
48 if (visible() == child
->visible())
50 SetVisible(child
->visible());
51 PreferredSizeChanged();
54 void TrayPopupItemContainer::ChildPreferredSizeChanged(View
* child
) {
55 PreferredSizeChanged();
58 void TrayPopupItemContainer::OnMouseEntered(const ui::MouseEvent
& event
) {
62 void TrayPopupItemContainer::OnMouseExited(const ui::MouseEvent
& event
) {
66 void TrayPopupItemContainer::OnGestureEvent(ui::GestureEvent
* event
) {
67 if (!switches::IsTouchFeedbackEnabled())
69 if (event
->type() == ui::ET_GESTURE_TAP_DOWN
) {
71 } else if (event
->type() == ui::ET_GESTURE_TAP_CANCEL
||
72 event
->type() == ui::ET_GESTURE_TAP
) {
77 void TrayPopupItemContainer::OnPaintBackground(gfx::Canvas
* canvas
) {
78 if (child_count() == 0)
81 views::View
* view
= child_at(0);
82 if (!view
->background()) {
83 canvas
->FillRect(gfx::Rect(size()), (active_
) ? kHoverBackgroundColor