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