Chromium Code Reviews| 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/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 SetPaintToLayer(view->layer() != NULL); | |
| 31 if (view->layer()) | |
| 32 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | |
| 33 AddChildView(view); | |
| 34 SetVisible(view->visible()); | |
| 35 } | |
| 36 | |
| 37 TrayPopupItemContainer::~TrayPopupItemContainer() { | |
| 38 } | |
| 39 | |
| 40 void TrayPopupItemContainer::SetActive(bool active) { | |
| 41 if (!change_background_ || active_ == active) | |
| 42 return; | |
| 43 active_ = active; | |
| 44 SchedulePaint(); | |
| 45 } | |
| 46 | |
| 47 void TrayPopupItemContainer::ChildVisibilityChanged(View* child) { | |
| 48 if (visible() == child->visible()) | |
| 49 return; | |
| 50 SetVisible(child->visible()); | |
| 51 PreferredSizeChanged(); | |
| 52 } | |
| 53 | |
| 54 void TrayPopupItemContainer::ChildPreferredSizeChanged(View* child) { | |
| 55 PreferredSizeChanged(); | |
| 56 } | |
| 57 | |
| 58 void TrayPopupItemContainer::OnMouseEntered(const ui::MouseEvent& event) { | |
| 59 SetActive(true); | |
| 60 } | |
| 61 | |
| 62 void TrayPopupItemContainer::OnMouseExited(const ui::MouseEvent& event) { | |
| 63 SetActive(false); | |
| 64 } | |
| 65 | |
| 66 void TrayPopupItemContainer::OnGestureEvent(ui::GestureEvent* event) { | |
| 67 if (!switches::IsTouchFeedbackEnabled()) | |
| 68 return; | |
| 69 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
| 70 SetActive(true); | |
| 71 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
| 72 event->type() == ui::ET_GESTURE_TAP) { | |
| 73 SetActive(false); | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void TrayPopupItemContainer::OnPaintBackground(gfx::Canvas* canvas) { | |
| 78 if (child_count() == 0) | |
| 79 return; | |
| 80 | |
| 81 views::View* view = child_at(0); | |
| 82 if (!view->background()) { | |
| 83 canvas->FillRect(gfx::Rect(size()), (active_ && change_background_) ? | |
|
flackr
2014/10/01 20:27:17
just check active_ here?
jonross
2014/10/01 20:50:38
Done.
| |
| 84 kHoverBackgroundColor : kBackgroundColor); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 } // namespace ash | |
| OLD | NEW |