Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: ash/common/system/tray/tray_item_more.cc

Issue 2468533002: [ash-md] Applied Material Design layout to TrayItemMore system menu rows. (Closed)
Patch Set: Merge branch 'master' into md_system_menu_tray_item_more_layout Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
tdanderson 2016/11/01 18:59:44 optional: Consider adding something to the class-l
bruthig 2016/11/01 23:00:43 I'm torn on whether this should be documented or n
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 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
tdanderson 2016/11/01 18:59:44 Would it be appropriate to move line 41 into Creat
bruthig 2016/11/01 23:00:43 Good call, done.
40 AddChildView(label_); 42 tri_view->AddView(TriView::Container::CENTER, label_);
41 43
42 if (show_more) { 44 if (show_more) {
43 more_ = new views::ImageView; 45 more_ = TrayPopupUtils::CreateMoreImageView();
44 more_->EnableCanvasFlippingForRTLUI(true); 46 more_->EnableCanvasFlippingForRTLUI(true);
tdanderson 2016/11/01 18:59:44 Similar to above comment, should this be moved int
bruthig 2016/11/01 23:00:43 Done.
45 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { 47 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) {
46 // The icon doesn't change in non-md. 48 // The icon doesn't change in non-md.
47 more_->SetImage(ui::ResourceBundle::GetSharedInstance() 49 more_->SetImage(ui::ResourceBundle::GetSharedInstance()
48 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE) 50 .GetImageNamed(IDR_AURA_UBER_TRAY_MORE)
49 .ToImageSkia()); 51 .ToImageSkia());
50 } 52 }
51 AddChildView(more_); 53 tri_view->AddView(TriView::Container::END, more_);
54 } else {
55 tri_view->SetContainerVisible(TriView::Container::END, false);
tdanderson 2016/11/01 18:59:44 Interesting, I didn't realize this would have been
bruthig 2016/11/01 23:00:43 Setting the END container to hidden would allocate
52 } 56 }
53 } 57 }
54 58
55 TrayItemMore::~TrayItemMore() {} 59 TrayItemMore::~TrayItemMore() {}
56 60
57 void TrayItemMore::SetLabel(const base::string16& label) { 61 void TrayItemMore::SetLabel(const base::string16& label) {
58 label_->SetText(label); 62 label_->SetText(label);
59 Layout(); 63 Layout();
60 SchedulePaint(); 64 SchedulePaint();
61 } 65 }
(...skipping 25 matching lines...) Expand all
87 } 91 }
88 92
89 bool TrayItemMore::PerformAction(const ui::Event& event) { 93 bool TrayItemMore::PerformAction(const ui::Event& event) {
90 if (!show_more_) 94 if (!show_more_)
91 return false; 95 return false;
92 96
93 owner()->TransitionDetailedView(); 97 owner()->TransitionDetailedView();
94 return true; 98 return true;
95 } 99 }
96 100
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());
tdanderson 2016/11/01 18:59:44 Double-checking since it could be easy to forget w
bruthig 2016/11/01 23:00:43 Yup it will. +1 for the TriView.
116 label_->SetBoundsRect(bounds);
117 }
118 }
119
120 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) { 101 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) {
121 ActionableView::GetAccessibleState(state); 102 ActionableView::GetAccessibleState(state);
122 if (!accessible_name_.empty()) 103 if (!accessible_name_.empty())
123 state->name = accessible_name_; 104 state->name = accessible_name_;
124 } 105 }
125 106
126 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) { 107 void TrayItemMore::OnNativeThemeChanged(const ui::NativeTheme* theme) {
127 ActionableView::OnNativeThemeChanged(theme); 108 ActionableView::OnNativeThemeChanged(theme);
128 UpdateStyle(); 109 UpdateStyle();
129 } 110 }
130 111
131 } // namespace ash 112 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698