OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/tray/tray_popup_item_container.h" | 5 #include "ash/common/system/tray/tray_popup_item_container.h" |
6 | 6 |
7 #include "ash/common/system/tray/tray_constants.h" | 7 #include "ash/common/system/tray/tray_constants.h" |
8 #include "ui/base/ui_base_switches_util.h" | 8 #include "ui/base/ui_base_switches_util.h" |
9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
10 #include "ui/views/border.h" | 10 #include "ui/views/border.h" |
11 #include "ui/views/layout/box_layout.h" | 11 #include "ui/views/layout/box_layout.h" |
12 | 12 |
13 namespace ash { | 13 namespace ash { |
14 | 14 |
15 TrayPopupItemContainer::TrayPopupItemContainer(views::View* view, | 15 TrayPopupItemContainer::TrayPopupItemContainer(views::View* view, |
16 bool change_background, | 16 bool change_background, |
17 bool draw_border) | 17 bool draw_border) |
18 : active_(false), | 18 : active_(false), change_background_(change_background) { |
19 change_background_(change_background) { | |
20 set_notify_enter_exit_on_child(true); | 19 set_notify_enter_exit_on_child(true); |
21 if (draw_border) { | 20 if (draw_border) { |
22 SetBorder( | 21 SetBorder( |
23 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); | 22 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); |
24 } | 23 } |
25 views::BoxLayout* layout = new views::BoxLayout( | 24 views::BoxLayout* layout = |
26 views::BoxLayout::kVertical, 0, 0, 0); | 25 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
27 layout->SetDefaultFlex(1); | 26 layout->SetDefaultFlex(1); |
28 SetLayoutManager(layout); | 27 SetLayoutManager(layout); |
29 if (view->layer()) { | 28 if (view->layer()) { |
30 SetPaintToLayer(true); | 29 SetPaintToLayer(true); |
31 layer()->SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | 30 layer()->SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); |
32 } | 31 } |
33 AddChildView(view); | 32 AddChildView(view); |
34 SetVisible(view->visible()); | 33 SetVisible(view->visible()); |
35 } | 34 } |
36 | 35 |
37 TrayPopupItemContainer::~TrayPopupItemContainer() { | 36 TrayPopupItemContainer::~TrayPopupItemContainer() {} |
38 } | |
39 | 37 |
40 void TrayPopupItemContainer::SetActive(bool active) { | 38 void TrayPopupItemContainer::SetActive(bool active) { |
41 if (!change_background_ || active_ == active) | 39 if (!change_background_ || active_ == active) |
42 return; | 40 return; |
43 active_ = active; | 41 active_ = active; |
44 SchedulePaint(); | 42 SchedulePaint(); |
45 } | 43 } |
46 | 44 |
47 void TrayPopupItemContainer::ChildVisibilityChanged(View* child) { | 45 void TrayPopupItemContainer::ChildVisibilityChanged(View* child) { |
48 if (visible() == child->visible()) | 46 if (visible() == child->visible()) |
(...skipping 24 matching lines...) Expand all Loading... |
73 SetActive(false); | 71 SetActive(false); |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 void TrayPopupItemContainer::OnPaintBackground(gfx::Canvas* canvas) { | 75 void TrayPopupItemContainer::OnPaintBackground(gfx::Canvas* canvas) { |
78 if (child_count() == 0) | 76 if (child_count() == 0) |
79 return; | 77 return; |
80 | 78 |
81 views::View* view = child_at(0); | 79 views::View* view = child_at(0); |
82 if (!view->background()) { | 80 if (!view->background()) { |
83 canvas->FillRect(gfx::Rect(size()), (active_) ? kHoverBackgroundColor | 81 canvas->FillRect(gfx::Rect(size()), |
84 : kBackgroundColor); | 82 (active_) ? kHoverBackgroundColor : kBackgroundColor); |
85 } | 83 } |
86 } | 84 } |
87 | 85 |
88 } // namespace ash | 86 } // namespace ash |
OLD | NEW |