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

Side by Side Diff: ash/shelf/shelf_button.cc

Issue 1743493002: Cleanup ash shelf accessor functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert ash/shelf/shelf_widget.cc for browser_tests crash... Created 4 years, 9 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
« no previous file with comments | « ash/shelf/shelf_button.h ('k') | ash/shelf/shelf_layout_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shelf/shelf_button.h" 5 #include "ash/shelf/shelf_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/shelf/shelf.h"
11 #include "ash/shelf/shelf_button_host.h" 12 #include "ash/shelf/shelf_button_host.h"
12 #include "ash/shelf/shelf_layout_manager.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "grit/ash_resources.h" 14 #include "grit/ash_resources.h"
15 #include "skia/ext/image_operations.h" 15 #include "skia/ext/image_operations.h"
16 #include "ui/accessibility/ax_view_state.h" 16 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/events/event_constants.h" 20 #include "ui/events/event_constants.h"
21 #include "ui/gfx/animation/animation_delegate.h" 21 #include "ui/gfx/animation/animation_delegate.h"
22 #include "ui/gfx/animation/throb_animation.h" 22 #include "ui/gfx/animation/throb_animation.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void UpdateBounds() { 173 void UpdateBounds() {
174 gfx::Rect bounds = base_bounds_; 174 gfx::Rect bounds = base_bounds_;
175 if (show_attention_) { 175 if (show_attention_) {
176 // Scale from .35 to 1.0 of the total width (which is wider than the 176 // Scale from .35 to 1.0 of the total width (which is wider than the
177 // visible width of the image), so the animation "rests" briefly at full 177 // visible width of the image), so the animation "rests" briefly at full
178 // visible width. Cap bounds length at kIconSize to prevent visual 178 // visible width. Cap bounds length at kIconSize to prevent visual
179 // flutter while centering bar within further expanding bounds. 179 // flutter while centering bar within further expanding bounds.
180 double animation = animating_ ? 180 double animation = animating_ ?
181 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0; 181 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0;
182 double scale = .35 + .65 * animation; 182 double scale = .35 + .65 * animation;
183 if (host_->shelf_layout_manager()->GetAlignment() == 183 if (host_->shelf()->alignment() == SHELF_ALIGNMENT_BOTTOM) {
184 SHELF_ALIGNMENT_BOTTOM) {
185 int width = base_bounds_.width() * scale; 184 int width = base_bounds_.width() * scale;
186 bounds.set_width(std::min(width, kIconSize)); 185 bounds.set_width(std::min(width, kIconSize));
187 int x_offset = (base_bounds_.width() - bounds.width()) / 2; 186 int x_offset = (base_bounds_.width() - bounds.width()) / 2;
188 bounds.set_x(base_bounds_.x() + x_offset); 187 bounds.set_x(base_bounds_.x() + x_offset);
189 UpdateAnimating(bounds.width() == kIconSize); 188 UpdateAnimating(bounds.width() == kIconSize);
190 } else { 189 } else {
191 int height = base_bounds_.height() * scale; 190 int height = base_bounds_.height() * scale;
192 bounds.set_height(std::min(height, kIconSize)); 191 bounds.set_height(std::min(height, kIconSize));
193 int y_offset = (base_bounds_.height() - bounds.height()) / 2; 192 int y_offset = (base_bounds_.height() - bounds.height()) / 2;
194 bounds.set_y(base_bounds_.y() + y_offset); 193 bounds.set_y(base_bounds_.y() + y_offset);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 228 }
230 229
231 //////////////////////////////////////////////////////////////////////////////// 230 ////////////////////////////////////////////////////////////////////////////////
232 // ShelfButton 231 // ShelfButton
233 232
234 // static 233 // static
235 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; 234 const char ShelfButton::kViewClassName[] = "ash/ShelfButton";
236 235
237 ShelfButton* ShelfButton::Create(views::ButtonListener* listener, 236 ShelfButton* ShelfButton::Create(views::ButtonListener* listener,
238 ShelfButtonHost* host, 237 ShelfButtonHost* host,
239 ShelfLayoutManager* shelf_layout_manager) { 238 Shelf* shelf) {
240 ShelfButton* button = new ShelfButton(listener, host, shelf_layout_manager); 239 ShelfButton* button = new ShelfButton(listener, host, shelf);
241 button->Init(); 240 button->Init();
242 return button; 241 return button;
243 } 242 }
244 243
245 ShelfButton::ShelfButton(views::ButtonListener* listener, 244 ShelfButton::ShelfButton(views::ButtonListener* listener,
246 ShelfButtonHost* host, 245 ShelfButtonHost* host,
247 ShelfLayoutManager* shelf_layout_manager) 246 Shelf* shelf)
248 : CustomButton(listener), 247 : CustomButton(listener),
249 host_(host), 248 host_(host),
250 icon_view_(NULL), 249 icon_view_(NULL),
251 bar_(new BarView(this)), 250 bar_(new BarView(this)),
252 state_(STATE_NORMAL), 251 state_(STATE_NORMAL),
253 shelf_layout_manager_(shelf_layout_manager), 252 shelf_(shelf),
254 destroyed_flag_(NULL) { 253 destroyed_flag_(NULL) {
255 SetAccessibilityFocusable(true); 254 SetAccessibilityFocusable(true);
256 255
257 const gfx::ShadowValue kShadows[] = { 256 const gfx::ShadowValue kShadows[] = {
258 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), 257 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)),
259 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), 258 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)),
260 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), 259 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)),
261 }; 260 };
262 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); 261 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows));
263 262
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 host_->MouseExitedButton(this); 394 host_->MouseExitedButton(this);
396 } 395 }
397 396
398 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { 397 void ShelfButton::GetAccessibleState(ui::AXViewState* state) {
399 state->role = ui::AX_ROLE_BUTTON; 398 state->role = ui::AX_ROLE_BUTTON;
400 state->name = host_->GetAccessibleName(this); 399 state->name = host_->GetAccessibleName(this);
401 } 400 }
402 401
403 void ShelfButton::Layout() { 402 void ShelfButton::Layout() {
404 const gfx::Rect button_bounds(GetContentsBounds()); 403 const gfx::Rect button_bounds(GetContentsBounds());
405 int icon_pad = 404 int icon_pad = shelf_->IsHorizontalAlignment() ? kIconPad : kIconPadVertical;
406 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? 405 int x_offset = shelf_->PrimaryAxisValue(0, icon_pad);
407 kIconPadVertical : kIconPad; 406 int y_offset = shelf_->PrimaryAxisValue(icon_pad, 0);
408 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad);
409 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0);
410 407
411 int icon_width = std::min(kIconSize, 408 int icon_width = std::min(kIconSize,
412 button_bounds.width() - x_offset); 409 button_bounds.width() - x_offset);
413 int icon_height = std::min(kIconSize, 410 int icon_height = std::min(kIconSize,
414 button_bounds.height() - y_offset); 411 button_bounds.height() - y_offset);
415 412
416 // If on the left or top 'invert' the inset so the constant gap is on 413 // If on the left or top 'invert' the inset so the constant gap is on
417 // the interior (towards the center of display) edge of the shelf. 414 // the interior (towards the center of display) edge of the shelf.
418 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) 415 if (SHELF_ALIGNMENT_LEFT == shelf_->alignment())
419 x_offset = button_bounds.width() - (kIconSize + icon_pad); 416 x_offset = button_bounds.width() - (kIconSize + icon_pad);
420 417
421 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) 418 if (SHELF_ALIGNMENT_TOP == shelf_->alignment())
422 y_offset = button_bounds.height() - (kIconSize + icon_pad); 419 y_offset = button_bounds.height() - (kIconSize + icon_pad);
423 420
424 // Center icon with respect to the secondary axis, and ensure 421 // Center icon with respect to the secondary axis, and ensure
425 // that the icon doesn't occlude the bar highlight. 422 // that the icon doesn't occlude the bar highlight.
426 if (shelf_layout_manager_->IsHorizontalAlignment()) { 423 if (shelf_->IsHorizontalAlignment()) {
427 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; 424 x_offset = std::max(0, button_bounds.width() - icon_width) / 2;
428 if (y_offset + icon_height + kBarSize > button_bounds.height()) 425 if (y_offset + icon_height + kBarSize > button_bounds.height())
429 icon_height = button_bounds.height() - (y_offset + kBarSize); 426 icon_height = button_bounds.height() - (y_offset + kBarSize);
430 } else { 427 } else {
431 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; 428 y_offset = std::max(0, button_bounds.height() - icon_height) / 2;
432 if (x_offset + icon_width + kBarSize > button_bounds.width()) 429 if (x_offset + icon_width + kBarSize > button_bounds.width())
433 icon_width = button_bounds.width() - (x_offset + kBarSize); 430 icon_width = button_bounds.width() - (x_offset + kBarSize);
434 } 431 }
435 432
436 // Expand bounds to include shadows. 433 // Expand bounds to include shadows.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER); 510 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER);
514 icon_view_->SetVerticalAlignment(views::ImageView::LEADING); 511 icon_view_->SetVerticalAlignment(views::ImageView::LEADING);
515 512
516 AddChildView(icon_view_); 513 AddChildView(icon_view_);
517 } 514 }
518 515
519 ShelfButton::IconView* ShelfButton::CreateIconView() { 516 ShelfButton::IconView* ShelfButton::CreateIconView() {
520 return new IconView; 517 return new IconView;
521 } 518 }
522 519
523 bool ShelfButton::IsShelfHorizontal() const {
524 return shelf_layout_manager_->IsHorizontalAlignment();
525 }
526
527 void ShelfButton::UpdateState() { 520 void ShelfButton::UpdateState() {
528 UpdateBar(); 521 UpdateBar();
529 522
530 icon_view_->SetHorizontalAlignment( 523 icon_view_->SetHorizontalAlignment(shelf_->PrimaryAxisValue(
531 shelf_layout_manager_->PrimaryAxisValue(views::ImageView::CENTER, 524 views::ImageView::CENTER, views::ImageView::LEADING));
532 views::ImageView::LEADING)); 525 icon_view_->SetVerticalAlignment(shelf_->PrimaryAxisValue(
533 icon_view_->SetVerticalAlignment( 526 views::ImageView::LEADING, views::ImageView::CENTER));
534 shelf_layout_manager_->PrimaryAxisValue(views::ImageView::LEADING,
535 views::ImageView::CENTER));
536 SchedulePaint(); 527 SchedulePaint();
537 } 528 }
538 529
539 void ShelfButton::UpdateBar() { 530 void ShelfButton::UpdateBar() {
540 if (state_ & STATE_HIDDEN) { 531 if (state_ & STATE_HIDDEN) {
541 bar_->SetVisible(false); 532 bar_->SetVisible(false);
542 return; 533 return;
543 } 534 }
544 535
545 int bar_id = 0; 536 int bar_id = 0;
546 if (state_ & (STATE_ACTIVE)) 537 if (state_ & (STATE_ACTIVE))
547 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 538 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
548 else if (state_ & STATE_ATTENTION) 539 else if (state_ & STATE_ATTENTION)
549 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 540 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
550 else if (state_ & STATE_RUNNING) 541 else if (state_ & STATE_RUNNING)
551 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 542 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
552 543
553 if (bar_id != 0) { 544 if (bar_id != 0) {
554 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 545 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
555 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); 546 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia();
556 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { 547 if (shelf_->alignment() == SHELF_ALIGNMENT_BOTTOM) {
557 bar_->SetImage(*image); 548 bar_->SetImage(*image);
558 } else { 549 } else {
559 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, 550 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(
560 shelf_layout_manager_->SelectValueForShelfAlignment( 551 *image, shelf_->SelectValueForShelfAlignment(
561 SkBitmapOperations::ROTATION_90_CW, 552 SkBitmapOperations::ROTATION_90_CW,
562 SkBitmapOperations::ROTATION_90_CW, 553 SkBitmapOperations::ROTATION_90_CW,
563 SkBitmapOperations::ROTATION_270_CW, 554 SkBitmapOperations::ROTATION_270_CW,
564 SkBitmapOperations::ROTATION_180_CW))); 555 SkBitmapOperations::ROTATION_180_CW)));
565 } 556 }
566 bar_->SetHorizontalAlignment( 557 bar_->SetHorizontalAlignment(shelf_->SelectValueForShelfAlignment(
567 shelf_layout_manager_->SelectValueForShelfAlignment( 558 views::ImageView::CENTER, views::ImageView::LEADING,
568 views::ImageView::CENTER, 559 views::ImageView::TRAILING, views::ImageView::CENTER));
569 views::ImageView::LEADING, 560 bar_->SetVerticalAlignment(shelf_->SelectValueForShelfAlignment(
570 views::ImageView::TRAILING, 561 views::ImageView::TRAILING, views::ImageView::CENTER,
571 views::ImageView::CENTER)); 562 views::ImageView::CENTER, views::ImageView::LEADING));
572 bar_->SetVerticalAlignment(
573 shelf_layout_manager_->SelectValueForShelfAlignment(
574 views::ImageView::TRAILING,
575 views::ImageView::CENTER,
576 views::ImageView::CENTER,
577 views::ImageView::LEADING));
578 bar_->SchedulePaint(); 563 bar_->SchedulePaint();
579 } 564 }
580 565
581 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 566 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
582 } 567 }
583 568
584 } // namespace ash 569 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_button.h ('k') | ash/shelf/shelf_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698