Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / system / tray / tray_item_more.cc
blob29799eabac9d1238278a8717b1b8c5d08aaa705b
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
3 // found in the LICENSE file.
5 #include "ash/system/tray/tray_item_more.h"
7 #include "ash/system/tray/fixed_sized_image_view.h"
8 #include "ash/system/tray/system_tray_item.h"
9 #include "ash/system/tray/tray_constants.h"
10 #include "grit/ash_resources.h"
11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image.h"
14 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/layout/box_layout.h"
18 namespace ash {
20 TrayItemMore::TrayItemMore(SystemTrayItem* owner, bool show_more)
21 : owner_(owner),
22 show_more_(show_more),
23 icon_(NULL),
24 label_(NULL),
25 more_(NULL) {
26 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
27 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems));
29 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
30 AddChildView(icon_);
32 label_ = new views::Label;
33 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
34 AddChildView(label_);
36 if (show_more) {
37 more_ = new views::ImageView;
38 more_->EnableCanvasFlippingForRTLUI(true);
39 more_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
40 IDR_AURA_UBER_TRAY_MORE).ToImageSkia());
41 AddChildView(more_);
45 TrayItemMore::~TrayItemMore() {
48 void TrayItemMore::SetLabel(const base::string16& label) {
49 label_->SetText(label);
50 Layout();
51 SchedulePaint();
54 void TrayItemMore::SetImage(const gfx::ImageSkia* image_skia) {
55 icon_->SetImage(image_skia);
56 SchedulePaint();
59 void TrayItemMore::SetAccessibleName(const base::string16& name) {
60 accessible_name_ = name;
63 void TrayItemMore::ReplaceIcon(views::View* view) {
64 delete icon_;
65 icon_ = NULL;
66 AddChildViewAt(view, 0);
69 bool TrayItemMore::PerformAction(const ui::Event& event) {
70 if (!show_more_)
71 return false;
73 owner()->TransitionDetailedView();
74 return true;
77 void TrayItemMore::Layout() {
78 // Let the box-layout do the layout first. Then move the '>' arrow to right
79 // align.
80 views::View::Layout();
82 if (!show_more_)
83 return;
85 // Make sure the chevron always has the full size.
86 gfx::Size size = more_->GetPreferredSize();
87 gfx::Rect bounds(size);
88 bounds.set_x(width() - size.width() - kTrayPopupPaddingBetweenItems);
89 bounds.set_y((height() - size.height()) / 2);
90 more_->SetBoundsRect(bounds);
92 // Adjust the label's bounds in case it got cut off by |more_|.
93 if (label_->bounds().Intersects(more_->bounds())) {
94 gfx::Rect bounds = label_->bounds();
95 bounds.set_width(more_->x() - kTrayPopupPaddingBetweenItems - label_->x());
96 label_->SetBoundsRect(bounds);
100 void TrayItemMore::GetAccessibleState(ui::AXViewState* state) {
101 state->role = ui::AX_ROLE_BUTTON;
102 state->name = accessible_name_;
105 } // namespace ash