| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/system/tray/tray_popup_item_container.h" | |
| 6 | |
| 7 #include "ash/common/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" | |
| 13 | |
| 14 namespace ash { | |
| 15 | |
| 16 TrayPopupItemContainer::TrayPopupItemContainer(views::View* view, | |
| 17 bool change_background, | |
| 18 bool draw_border) | |
| 19 : active_(false), | |
| 20 change_background_(change_background) { | |
| 21 set_notify_enter_exit_on_child(true); | |
| 22 if (draw_border) { | |
| 23 SetBorder( | |
| 24 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); | |
| 25 } | |
| 26 views::BoxLayout* layout = new views::BoxLayout( | |
| 27 views::BoxLayout::kVertical, 0, 0, 0); | |
| 28 layout->SetDefaultFlex(1); | |
| 29 SetLayoutManager(layout); | |
| 30 if (view->layer()) { | |
| 31 SetPaintToLayer(true); | |
| 32 layer()->SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | |
| 33 } | |
| 34 AddChildView(view); | |
| 35 SetVisible(view->visible()); | |
| 36 } | |
| 37 | |
| 38 TrayPopupItemContainer::~TrayPopupItemContainer() { | |
| 39 } | |
| 40 | |
| 41 void TrayPopupItemContainer::SetActive(bool active) { | |
| 42 if (!change_background_ || active_ == active) | |
| 43 return; | |
| 44 active_ = active; | |
| 45 SchedulePaint(); | |
| 46 } | |
| 47 | |
| 48 void TrayPopupItemContainer::ChildVisibilityChanged(View* child) { | |
| 49 if (visible() == child->visible()) | |
| 50 return; | |
| 51 SetVisible(child->visible()); | |
| 52 PreferredSizeChanged(); | |
| 53 } | |
| 54 | |
| 55 void TrayPopupItemContainer::ChildPreferredSizeChanged(View* child) { | |
| 56 PreferredSizeChanged(); | |
| 57 } | |
| 58 | |
| 59 void TrayPopupItemContainer::OnMouseEntered(const ui::MouseEvent& event) { | |
| 60 SetActive(true); | |
| 61 } | |
| 62 | |
| 63 void TrayPopupItemContainer::OnMouseExited(const ui::MouseEvent& event) { | |
| 64 SetActive(false); | |
| 65 } | |
| 66 | |
| 67 void TrayPopupItemContainer::OnGestureEvent(ui::GestureEvent* event) { | |
| 68 if (!switches::IsTouchFeedbackEnabled()) | |
| 69 return; | |
| 70 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 71 SetActive(true); | |
| 72 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
| 73 event->type() == ui::ET_GESTURE_TAP) { | |
| 74 SetActive(false); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void TrayPopupItemContainer::OnPaintBackground(gfx::Canvas* canvas) { | |
| 79 if (child_count() == 0) | |
| 80 return; | |
| 81 | |
| 82 views::View* view = child_at(0); | |
| 83 if (!view->background()) { | |
| 84 canvas->FillRect(gfx::Rect(size()), (active_) ? kHoverBackgroundColor | |
| 85 : kBackgroundColor); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 } // namespace ash | |
| OLD | NEW |