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

Side by Side Diff: ash/system/chromeos/screen_security/screen_tray_item.cc

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/system/chromeos/screen_security/screen_tray_item.h" 5 #include "ash/system/chromeos/screen_security/screen_tray_item.h"
6 6
7 #include "ash/common/shelf/wm_shelf_util.h" 7 #include "ash/common/shelf/wm_shelf_util.h"
8 #include "ash/common/system/tray/fixed_sized_image_view.h" 8 #include "ash/common/system/tray/fixed_sized_image_view.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/shelf/shelf_util.h" 10 #include "ash/shelf/shelf_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/message_center/message_center.h" 12 #include "ui/message_center/message_center.h"
13 #include "ui/views/controls/label.h" 13 #include "ui/views/controls/label.h"
14 #include "ui/views/layout/box_layout.h" 14 #include "ui/views/layout/box_layout.h"
15 15
16 namespace { 16 namespace {
17 const int kStopButtonRightPadding = 18; 17 const int kStopButtonRightPadding = 18;
18 } // namespace 18 } // namespace
19 19
20 namespace ash { 20 namespace ash {
21 namespace tray { 21 namespace tray {
22 22
23 // ScreenTrayView implementations. 23 // ScreenTrayView implementations.
24 ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id) 24 ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id)
25 : TrayItemView(screen_tray_item), 25 : TrayItemView(screen_tray_item), screen_tray_item_(screen_tray_item) {
26 screen_tray_item_(screen_tray_item) {
27 CreateImageView(); 26 CreateImageView();
28 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() 27 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance()
29 .GetImageNamed(icon_id).ToImageSkia()); 28 .GetImageNamed(icon_id)
29 .ToImageSkia());
30 30
31 Update(); 31 Update();
32 } 32 }
33 33
34 ScreenTrayView::~ScreenTrayView() { 34 ScreenTrayView::~ScreenTrayView() {}
35 }
36 35
37 void ScreenTrayView::Update() { 36 void ScreenTrayView::Update() {
38 SetVisible(screen_tray_item_->is_started()); 37 SetVisible(screen_tray_item_->is_started());
39 } 38 }
40 39
41
42 // ScreenStatusView implementations. 40 // ScreenStatusView implementations.
43 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, 41 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item,
44 int icon_id, 42 int icon_id,
45 const base::string16& label_text, 43 const base::string16& label_text,
46 const base::string16& stop_button_text) 44 const base::string16& stop_button_text)
47 : screen_tray_item_(screen_tray_item), 45 : screen_tray_item_(screen_tray_item),
48 icon_(NULL), 46 icon_(NULL),
49 label_(NULL), 47 label_(NULL),
50 stop_button_(NULL), 48 stop_button_(NULL),
51 icon_id_(icon_id), 49 icon_id_(icon_id),
52 label_text_(label_text), 50 label_text_(label_text),
53 stop_button_text_(stop_button_text) { 51 stop_button_text_(stop_button_text) {
54 CreateItems(); 52 CreateItems();
55 Update(); 53 Update();
56 } 54 }
57 55
58 ScreenStatusView::~ScreenStatusView() { 56 ScreenStatusView::~ScreenStatusView() {}
59 }
60 57
61 void ScreenStatusView::Layout() { 58 void ScreenStatusView::Layout() {
62 views::View::Layout(); 59 views::View::Layout();
63 60
64 // Give the stop button the space it requests. 61 // Give the stop button the space it requests.
65 gfx::Size stop_size = stop_button_->GetPreferredSize(); 62 gfx::Size stop_size = stop_button_->GetPreferredSize();
66 gfx::Rect stop_bounds(stop_size); 63 gfx::Rect stop_bounds(stop_size);
67 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding); 64 stop_bounds.set_x(width() - stop_size.width() - kStopButtonRightPadding);
68 stop_bounds.set_y((height() - stop_size.height()) / 2); 65 stop_bounds.set_y((height() - stop_size.height()) / 2);
69 stop_button_->SetBoundsRect(stop_bounds); 66 stop_button_->SetBoundsRect(stop_bounds);
70 67
71 // Adjust the label's bounds in case it got cut off by |stop_button_|. 68 // Adjust the label's bounds in case it got cut off by |stop_button_|.
72 if (label_->bounds().Intersects(stop_button_->bounds())) { 69 if (label_->bounds().Intersects(stop_button_->bounds())) {
73 gfx::Rect label_bounds = label_->bounds(); 70 gfx::Rect label_bounds = label_->bounds();
74 label_bounds.set_width( 71 label_bounds.set_width(stop_button_->x() - kTrayPopupPaddingBetweenItems -
75 stop_button_->x() - kTrayPopupPaddingBetweenItems - label_->x()); 72 label_->x());
76 label_->SetBoundsRect(label_bounds); 73 label_->SetBoundsRect(label_bounds);
77 } 74 }
78 } 75 }
79 76
80 void ScreenStatusView::ButtonPressed( 77 void ScreenStatusView::ButtonPressed(views::Button* sender,
81 views::Button* sender, 78 const ui::Event& event) {
82 const ui::Event& event) {
83 DCHECK(sender == stop_button_); 79 DCHECK(sender == stop_button_);
84 screen_tray_item_->Stop(); 80 screen_tray_item_->Stop();
85 } 81 }
86 82
87 void ScreenStatusView::CreateItems() { 83 void ScreenStatusView::CreateItems() {
88 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 84 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
89 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 85 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
90 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 86 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
91 kTrayPopupPaddingHorizontal, 87 kTrayPopupPaddingHorizontal, 0,
92 0,
93 kTrayPopupPaddingBetweenItems)); 88 kTrayPopupPaddingBetweenItems));
94 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight); 89 icon_ = new FixedSizedImageView(0, kTrayPopupItemHeight);
95 icon_->SetImage(bundle.GetImageNamed(icon_id_).ToImageSkia()); 90 icon_->SetImage(bundle.GetImageNamed(icon_id_).ToImageSkia());
96 AddChildView(icon_); 91 AddChildView(icon_);
97 label_ = new views::Label; 92 label_ = new views::Label;
98 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 93 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
99 label_->SetMultiLine(true); 94 label_->SetMultiLine(true);
100 label_->SetText(label_text_); 95 label_->SetText(label_text_);
101 AddChildView(label_); 96 AddChildView(label_);
102 97
103 stop_button_ = new TrayPopupLabelButton(this, stop_button_text_); 98 stop_button_ = new TrayPopupLabelButton(this, stop_button_text_);
104 AddChildView(stop_button_); 99 AddChildView(stop_button_);
105 } 100 }
106 101
107 void ScreenStatusView::Update() { 102 void ScreenStatusView::Update() {
108 // Hide the notification bubble when the ash tray bubble opens. 103 // Hide the notification bubble when the ash tray bubble opens.
109 screen_tray_item_->HideNotificationView(); 104 screen_tray_item_->HideNotificationView();
110 SetVisible(screen_tray_item_->is_started()); 105 SetVisible(screen_tray_item_->is_started());
111 } 106 }
112 107
113 ScreenNotificationDelegate::ScreenNotificationDelegate( 108 ScreenNotificationDelegate::ScreenNotificationDelegate(
114 ScreenTrayItem* screen_tray) 109 ScreenTrayItem* screen_tray)
115 : screen_tray_(screen_tray) { 110 : screen_tray_(screen_tray) {}
116 }
117 111
118 ScreenNotificationDelegate::~ScreenNotificationDelegate() { 112 ScreenNotificationDelegate::~ScreenNotificationDelegate() {}
119 }
120 113
121 void ScreenNotificationDelegate::ButtonClick(int button_index) { 114 void ScreenNotificationDelegate::ButtonClick(int button_index) {
122 DCHECK_EQ(0, button_index); 115 DCHECK_EQ(0, button_index);
123 screen_tray_->Stop(); 116 screen_tray_->Stop();
124 } 117 }
125 118
126 } // namespace tray 119 } // namespace tray
127 120
128 ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray) 121 ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray)
129 : SystemTrayItem(system_tray), 122 : SystemTrayItem(system_tray),
130 tray_view_(NULL), 123 tray_view_(NULL),
131 default_view_(NULL), 124 default_view_(NULL),
132 is_started_(false), 125 is_started_(false),
133 stop_callback_(base::Bind(&base::DoNothing)) { 126 stop_callback_(base::Bind(&base::DoNothing)) {}
134 }
135 127
136 ScreenTrayItem::~ScreenTrayItem() {} 128 ScreenTrayItem::~ScreenTrayItem() {}
137 129
138 void ScreenTrayItem::Update() { 130 void ScreenTrayItem::Update() {
139 if (tray_view_) 131 if (tray_view_)
140 tray_view_->Update(); 132 tray_view_->Update();
141 if (default_view_) 133 if (default_view_)
142 default_view_->Update(); 134 default_view_->Update();
143 if (is_started_) { 135 if (is_started_) {
144 CreateOrUpdateNotification(); 136 CreateOrUpdateNotification();
145 } else { 137 } else {
146 message_center::MessageCenter::Get()->RemoveNotification( 138 message_center::MessageCenter::Get()->RemoveNotification(
147 GetNotificationId(), false /* by_user */); 139 GetNotificationId(), false /* by_user */);
148 } 140 }
149 } 141 }
150 142
151 void ScreenTrayItem::Start(const base::Closure& stop_callback) { 143 void ScreenTrayItem::Start(const base::Closure& stop_callback) {
152 stop_callback_ = stop_callback; 144 stop_callback_ = stop_callback;
153 is_started_ = true; 145 is_started_ = true;
154 146
155 if (tray_view_) 147 if (tray_view_)
156 tray_view_->Update(); 148 tray_view_->Update();
157 149
158 if (default_view_) 150 if (default_view_)
159 default_view_->Update(); 151 default_view_->Update();
160 152
161 if (!system_tray()->HasSystemBubbleType( 153 if (!system_tray()->HasSystemBubbleType(
162 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { 154 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) {
163 CreateOrUpdateNotification(); 155 CreateOrUpdateNotification();
164 } 156 }
165 } 157 }
166 158
167 void ScreenTrayItem::Stop() { 159 void ScreenTrayItem::Stop() {
168 is_started_ = false; 160 is_started_ = false;
169 Update(); 161 Update();
170 162
171 if (stop_callback_.is_null()) 163 if (stop_callback_.is_null())
172 return; 164 return;
(...skipping 17 matching lines...) Expand all
190 182
191 // Center the item dependent on the orientation of the shelf. 183 // Center the item dependent on the orientation of the shelf.
192 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) 184 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment)
193 ? views::BoxLayout::kHorizontal 185 ? views::BoxLayout::kHorizontal
194 : views::BoxLayout::kVertical; 186 : views::BoxLayout::kVertical;
195 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); 187 tray_view_->SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0));
196 tray_view_->Layout(); 188 tray_view_->Layout();
197 } 189 }
198 190
199 } // namespace ash 191 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698