OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_item_more.h" | 5 #include "ash/common/system/tray/tray_item_more.h" |
6 | 6 |
7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
8 #include "ash/common/system/tray/fixed_sized_image_view.h" | |
9 #include "ash/common/system/tray/system_tray_item.h" | 8 #include "ash/common/system/tray/system_tray_item.h" |
10 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
11 #include "ash/common/system/tray/tray_popup_item_style.h" | 10 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 11 #include "ash/common/system/tray/tray_popup_utils.h" |
| 12 #include "ash/common/system/tray/tri_view.h" |
12 #include "ash/resources/vector_icons/vector_icons.h" | 13 #include "ash/resources/vector_icons/vector_icons.h" |
13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
14 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
15 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/paint_vector_icon.h" | 19 #include "ui/gfx/paint_vector_icon.h" |
19 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
| 23 #include "ui/views/layout/fill_layout.h" |
22 | 24 |
23 namespace ash { | 25 namespace ash { |
24 | 26 |
25 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) | 27 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more) |
26 : ActionableView(owner), | 28 : ActionableView(owner), |
27 show_more_(show_more), | 29 show_more_(show_more), |
28 icon_(nullptr), | 30 icon_(nullptr), |
29 label_(nullptr), | 31 label_(nullptr), |
30 more_(nullptr) { | 32 more_(nullptr) { |
31 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 33 TriView* tri_view = TrayPopupUtils::CreateDefaultRowView(); |
32 kTrayPopupPaddingHorizontal, 0, | 34 AddChildView(tri_view); |
33 kTrayPopupPaddingBetweenItems)); | 35 SetLayoutManager(new views::FillLayout); |
34 | 36 |
35 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 37 icon_ = TrayPopupUtils::CreateMainImageView(); |
36 AddChildView(icon_); | 38 tri_view->AddView(TriView::Container::START, icon_); |
37 | 39 |
38 label_ = new views::Label; | 40 label_ = TrayPopupUtils::CreateDefaultLabel(); |
39 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 41 tri_view->AddView(TriView::Container::CENTER, label_); |
40 AddChildView(label_); | |
41 | 42 |
42 if (show_more) { | 43 if (show_more) { |
43 more_ = new views::ImageView; | 44 more_ = TrayPopupUtils::CreateMoreImageView(); |
44 more_->EnableCanvasFlippingForRTLUI(true); | |
45 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | 45 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { |
46 // The icon doesn't change in non-md. | 46 // The icon doesn't change in non-md. |
47 more_->SetImage(ui::ResourceBundle::GetSharedInstance() | 47 more_->SetImage(ui::ResourceBundle::GetSharedInstance() |
48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) | 48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) |
49 .ToImageSkia()); | 49 .ToImageSkia()); |
50 } | 50 } |
51 AddChildView(more_); | 51 tri_view->AddView(TriView::Container::END, more_); |
| 52 } else { |
| 53 tri_view->SetContainerVisible(TriView::Container::END, false); |
52 } | 54 } |
53 } | 55 } |
54 | 56 |
55 TrayItemMore::~TrayItemMore() {} | 57 TrayItemMore::~TrayItemMore() {} |
56 | 58 |
57 void TrayItemMore::SetLabel(const base::string16& label) { | 59 void TrayItemMore::SetLabel(const base::string16& label) { |
58 label_->SetText(label); | 60 label_->SetText(label); |
59 Layout(); | 61 Layout(); |
60 SchedulePaint(); | 62 SchedulePaint(); |
61 } | 63 } |
(...skipping 25 matching lines...) Expand all Loading... |
87 } | 89 } |
88 | 90 |
89 bool TrayItemMore::PerformAction(const ui::Event& event) { | 91 bool TrayItemMore::PerformAction(const ui::Event& event) { |
90 if (!show_more_) | 92 if (!show_more_) |
91 return false; | 93 return false; |
92 | 94 |
93 owner()->TransitionDetailedView(); | 95 owner()->TransitionDetailedView(); |
94 return true; | 96 return true; |
95 } | 97 } |
96 | 98 |
97 void TrayItemMore::Layout() { | |
98 // Let the box-layout do the layout first. Then move the '>' arrow to right | |
99 // align. | |
100 views::View::Layout(); | |
101 | |
102 if (!show_more_) | |
103 return; | |
104 | |
105 // Make sure the chevron always has the full size. | |
106 gfx::Size size = more_->GetPreferredSize(); | |
107 gfx::Rect bounds(size); | |
108 bounds.set_x(width() - size.width() - kTrayPopupPaddingBetweenItems); | |
109 bounds.set_y((height() - size.height()) / 2); | |
110 more_->SetBoundsRect(bounds); | |
111 | |
112 // Adjust the label's bounds in case it got cut off by |more_|. | |
113 if (label_->bounds().Intersects(more_->bounds())) { | |
114 gfx::Rect bounds = label_->bounds(); | |
115 bounds.set_width(more_->x() - kTrayPopupPaddingBetweenItems - label_->x()); | |
116 label_->SetBoundsRect(bounds); | |
117 } | |
118 } | |
119 | |
120 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { | 99 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { |
121 ActionableView::GetAccessibleState(state); | 100 ActionableView::GetAccessibleState(state); |
122 if (!accessible_name_.empty()) | 101 if (!accessible_name_.empty()) |
123 state->name = accessible_name_; | 102 state->name = accessible_name_; |
124 } | 103 } |
125 | 104 |
126 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 105 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
127 ActionableView::OnNativeThemeChanged(theme); | 106 ActionableView::OnNativeThemeChanged(theme); |
128 UpdateStyle(); | 107 UpdateStyle(); |
129 } | 108 } |
130 | 109 |
131 } // namespace ash | 110 } // namespace ash |
OLD | NEW |