Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "mash/shelf/shelf_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | |
| 10 #include "ash/ash_switches.h" | |
| 11 #include "ash/shelf/shelf_button_host.h" | |
| 12 #include "ash/shelf/shelf_layout_manager.h" | |
| 13 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 14 #include "grit/ash_resources.h" | 10 #include "mash/shelf/shelf_button_host.h" |
| 15 #include "skia/ext/image_operations.h" | 11 #include "skia/ext/image_operations.h" |
| 16 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
| 19 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 20 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
| 21 #include "ui/gfx/animation/animation_delegate.h" | 17 #include "ui/gfx/animation/animation_delegate.h" |
| 22 #include "ui/gfx/animation/throb_animation.h" | 18 #include "ui/gfx/animation/throb_animation.h" |
| 23 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 24 #include "ui/gfx/geometry/vector2d.h" | 20 #include "ui/gfx/geometry/vector2d.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 96 } |
| 101 | 97 |
| 102 gfx::ThrobAnimation animation_; | 98 gfx::ThrobAnimation animation_; |
| 103 base::ObserverList<Observer> observers_; | 99 base::ObserverList<Observer> observers_; |
| 104 | 100 |
| 105 DISALLOW_COPY_AND_ASSIGN(ShelfButtonAnimation); | 101 DISALLOW_COPY_AND_ASSIGN(ShelfButtonAnimation); |
| 106 }; | 102 }; |
| 107 | 103 |
| 108 } // namespace | 104 } // namespace |
| 109 | 105 |
| 110 namespace ash { | 106 namespace mash { |
| 107 namespace shelf { | |
| 111 | 108 |
| 112 //////////////////////////////////////////////////////////////////////////////// | 109 //////////////////////////////////////////////////////////////////////////////// |
| 113 // ShelfButton::BarView | 110 // ShelfButton::BarView |
| 114 | 111 |
| 115 class ShelfButton::BarView : public views::ImageView, | 112 class ShelfButton::BarView : public views::ImageView, |
| 116 public ShelfButtonAnimation::Observer { | 113 public ShelfButtonAnimation::Observer { |
| 117 public: | 114 public: |
| 118 BarView(ShelfButton* host) | 115 BarView(ShelfButton* host) |
| 119 : host_(host), | 116 : host_(host), |
| 120 show_attention_(false), | 117 show_attention_(false), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 void UpdateBounds() { | 170 void UpdateBounds() { |
| 174 gfx::Rect bounds = base_bounds_; | 171 gfx::Rect bounds = base_bounds_; |
| 175 if (show_attention_) { | 172 if (show_attention_) { |
| 176 // Scale from .35 to 1.0 of the total width (which is wider than the | 173 // 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 | 174 // visible width of the image), so the animation "rests" briefly at full |
| 178 // visible width. Cap bounds length at kIconSize to prevent visual | 175 // visible width. Cap bounds length at kIconSize to prevent visual |
| 179 // flutter while centering bar within further expanding bounds. | 176 // flutter while centering bar within further expanding bounds. |
| 180 double animation = animating_ ? | 177 double animation = animating_ ? |
| 181 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0; | 178 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0; |
| 182 double scale = .35 + .65 * animation; | 179 double scale = .35 + .65 * animation; |
| 183 if (host_->shelf_layout_manager()->GetAlignment() == | 180 if (host_->host()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 184 SHELF_ALIGNMENT_BOTTOM) { | |
| 185 int width = base_bounds_.width() * scale; | 181 int width = base_bounds_.width() * scale; |
| 186 bounds.set_width(std::min(width, kIconSize)); | 182 bounds.set_width(std::min(width, kIconSize)); |
| 187 int x_offset = (base_bounds_.width() - bounds.width()) / 2; | 183 int x_offset = (base_bounds_.width() - bounds.width()) / 2; |
| 188 bounds.set_x(base_bounds_.x() + x_offset); | 184 bounds.set_x(base_bounds_.x() + x_offset); |
| 189 UpdateAnimating(bounds.width() == kIconSize); | 185 UpdateAnimating(bounds.width() == kIconSize); |
| 190 } else { | 186 } else { |
| 191 int height = base_bounds_.height() * scale; | 187 int height = base_bounds_.height() * scale; |
| 192 bounds.set_height(std::min(height, kIconSize)); | 188 bounds.set_height(std::min(height, kIconSize)); |
| 193 int y_offset = (base_bounds_.height() - bounds.height()) / 2; | 189 int y_offset = (base_bounds_.height() - bounds.height()) / 2; |
| 194 bounds.set_y(base_bounds_.y() + y_offset); | 190 bounds.set_y(base_bounds_.y() + y_offset); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 ShelfButton::IconView::~IconView() { | 224 ShelfButton::IconView::~IconView() { |
| 229 } | 225 } |
| 230 | 226 |
| 231 //////////////////////////////////////////////////////////////////////////////// | 227 //////////////////////////////////////////////////////////////////////////////// |
| 232 // ShelfButton | 228 // ShelfButton |
| 233 | 229 |
| 234 // static | 230 // static |
| 235 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; | 231 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; |
| 236 | 232 |
| 237 ShelfButton* ShelfButton::Create(views::ButtonListener* listener, | 233 ShelfButton* ShelfButton::Create(views::ButtonListener* listener, |
| 238 ShelfButtonHost* host, | 234 ShelfButtonHost* host) { |
| 239 ShelfLayoutManager* shelf_layout_manager) { | 235 ShelfButton* button = new ShelfButton(listener, host); |
| 240 ShelfButton* button = new ShelfButton(listener, host, shelf_layout_manager); | |
| 241 button->Init(); | 236 button->Init(); |
| 242 return button; | 237 return button; |
| 243 } | 238 } |
| 244 | 239 |
| 245 ShelfButton::ShelfButton(views::ButtonListener* listener, | 240 ShelfButton::ShelfButton(views::ButtonListener* listener, |
| 246 ShelfButtonHost* host, | 241 ShelfButtonHost* host) |
| 247 ShelfLayoutManager* shelf_layout_manager) | |
| 248 : CustomButton(listener), | 242 : CustomButton(listener), |
| 249 host_(host), | 243 host_(host), |
| 250 icon_view_(NULL), | 244 icon_view_(NULL), |
| 251 bar_(new BarView(this)), | 245 bar_(new BarView(this)), |
| 252 state_(STATE_NORMAL), | 246 state_(STATE_NORMAL), |
| 253 shelf_layout_manager_(shelf_layout_manager), | |
| 254 destroyed_flag_(NULL) { | 247 destroyed_flag_(NULL) { |
| 255 SetAccessibilityFocusable(true); | 248 SetAccessibilityFocusable(true); |
| 256 | 249 |
| 257 const gfx::ShadowValue kShadows[] = { | 250 const gfx::ShadowValue kShadows[] = { |
| 258 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 251 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)), | 252 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)), | 253 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 261 }; | 254 }; |
| 262 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); | 255 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); |
| 263 | 256 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 host_->MouseExitedButton(this); | 388 host_->MouseExitedButton(this); |
| 396 } | 389 } |
| 397 | 390 |
| 398 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { | 391 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { |
| 399 state->role = ui::AX_ROLE_BUTTON; | 392 state->role = ui::AX_ROLE_BUTTON; |
| 400 state->name = host_->GetAccessibleName(this); | 393 state->name = host_->GetAccessibleName(this); |
| 401 } | 394 } |
| 402 | 395 |
| 403 void ShelfButton::Layout() { | 396 void ShelfButton::Layout() { |
| 404 const gfx::Rect button_bounds(GetContentsBounds()); | 397 const gfx::Rect button_bounds(GetContentsBounds()); |
| 405 int icon_pad = | 398 int icon_pad = host_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? |
| 406 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? | |
| 407 kIconPadVertical : kIconPad; | 399 kIconPadVertical : kIconPad; |
| 408 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); | 400 int x_offset = host_->PrimaryAxisValue(0, icon_pad); |
| 409 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); | 401 int y_offset = host_->PrimaryAxisValue(icon_pad, 0); |
| 410 | 402 |
| 411 int icon_width = std::min(kIconSize, | 403 int icon_width = std::min(kIconSize, |
| 412 button_bounds.width() - x_offset); | 404 button_bounds.width() - x_offset); |
| 413 int icon_height = std::min(kIconSize, | 405 int icon_height = std::min(kIconSize, |
| 414 button_bounds.height() - y_offset); | 406 button_bounds.height() - y_offset); |
| 415 | 407 |
| 416 // If on the left or top 'invert' the inset so the constant gap is on | 408 // 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. | 409 // the interior (towards the center of display) edge of the shelf. |
| 418 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) | 410 if (SHELF_ALIGNMENT_LEFT == host_->GetAlignment()) |
| 419 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 411 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| 420 | 412 |
| 421 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) | 413 if (SHELF_ALIGNMENT_TOP == host_->GetAlignment()) |
| 422 y_offset = button_bounds.height() - (kIconSize + icon_pad); | 414 y_offset = button_bounds.height() - (kIconSize + icon_pad); |
| 423 | 415 |
| 424 // Center icon with respect to the secondary axis, and ensure | 416 // Center icon with respect to the secondary axis, and ensure |
| 425 // that the icon doesn't occlude the bar highlight. | 417 // that the icon doesn't occlude the bar highlight. |
| 426 if (shelf_layout_manager_->IsHorizontalAlignment()) { | 418 if (host_->IsHorizontalAlignment()) { |
| 427 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 419 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
| 428 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 420 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
| 429 icon_height = button_bounds.height() - (y_offset + kBarSize); | 421 icon_height = button_bounds.height() - (y_offset + kBarSize); |
| 430 } else { | 422 } else { |
| 431 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 423 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
| 432 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 424 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
| 433 icon_width = button_bounds.width() - (x_offset + kBarSize); | 425 icon_width = button_bounds.width() - (x_offset + kBarSize); |
| 434 } | 426 } |
| 435 | 427 |
| 436 // Expand bounds to include shadows. | 428 // Expand bounds to include shadows. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 467 void ShelfButton::OnBlur() { | 459 void ShelfButton::OnBlur() { |
| 468 ClearState(STATE_FOCUSED); | 460 ClearState(STATE_FOCUSED); |
| 469 CustomButton::OnBlur(); | 461 CustomButton::OnBlur(); |
| 470 } | 462 } |
| 471 | 463 |
| 472 void ShelfButton::OnPaint(gfx::Canvas* canvas) { | 464 void ShelfButton::OnPaint(gfx::Canvas* canvas) { |
| 473 CustomButton::OnPaint(canvas); | 465 CustomButton::OnPaint(canvas); |
| 474 if (HasFocus()) { | 466 if (HasFocus()) { |
| 475 gfx::Rect paint_bounds(GetLocalBounds()); | 467 gfx::Rect paint_bounds(GetLocalBounds()); |
| 476 paint_bounds.Inset(1, 1, 1, 1); | 468 paint_bounds.Inset(1, 1, 1, 1); |
| 469 const SkColor kFocusBorderColor = SkColorSetRGB(64, 128, 250); | |
| 477 canvas->DrawSolidFocusRect(paint_bounds, kFocusBorderColor); | 470 canvas->DrawSolidFocusRect(paint_bounds, kFocusBorderColor); |
| 478 } | 471 } |
| 479 } | 472 } |
| 480 | 473 |
| 481 void ShelfButton::OnGestureEvent(ui::GestureEvent* event) { | 474 void ShelfButton::OnGestureEvent(ui::GestureEvent* event) { |
| 482 switch (event->type()) { | 475 switch (event->type()) { |
| 483 case ui::ET_GESTURE_TAP_DOWN: | 476 case ui::ET_GESTURE_TAP_DOWN: |
| 484 AddState(STATE_HOVERED); | 477 AddState(STATE_HOVERED); |
| 485 return CustomButton::OnGestureEvent(event); | 478 return CustomButton::OnGestureEvent(event); |
| 486 case ui::ET_GESTURE_END: | 479 case ui::ET_GESTURE_END: |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 513 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER); | 506 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER); |
| 514 icon_view_->SetVerticalAlignment(views::ImageView::LEADING); | 507 icon_view_->SetVerticalAlignment(views::ImageView::LEADING); |
| 515 | 508 |
| 516 AddChildView(icon_view_); | 509 AddChildView(icon_view_); |
| 517 } | 510 } |
| 518 | 511 |
| 519 ShelfButton::IconView* ShelfButton::CreateIconView() { | 512 ShelfButton::IconView* ShelfButton::CreateIconView() { |
| 520 return new IconView; | 513 return new IconView; |
| 521 } | 514 } |
| 522 | 515 |
| 523 bool ShelfButton::IsShelfHorizontal() const { | |
| 524 return shelf_layout_manager_->IsHorizontalAlignment(); | |
| 525 } | |
| 526 | |
| 527 void ShelfButton::UpdateState() { | 516 void ShelfButton::UpdateState() { |
| 528 UpdateBar(); | 517 UpdateBar(); |
| 529 | 518 |
| 530 icon_view_->SetHorizontalAlignment( | 519 icon_view_->SetHorizontalAlignment(host_->PrimaryAxisValue( |
| 531 shelf_layout_manager_->PrimaryAxisValue(views::ImageView::CENTER, | 520 views::ImageView::CENTER, views::ImageView::LEADING)); |
| 532 views::ImageView::LEADING)); | 521 icon_view_->SetVerticalAlignment(host_->PrimaryAxisValue( |
| 533 icon_view_->SetVerticalAlignment( | 522 views::ImageView::LEADING, views::ImageView::CENTER)); |
| 534 shelf_layout_manager_->PrimaryAxisValue(views::ImageView::LEADING, | |
| 535 views::ImageView::CENTER)); | |
| 536 SchedulePaint(); | 523 SchedulePaint(); |
| 537 } | 524 } |
| 538 | 525 |
| 539 void ShelfButton::UpdateBar() { | 526 void ShelfButton::UpdateBar() { |
| 540 if (state_ & STATE_HIDDEN) { | 527 if (state_ & STATE_HIDDEN) { |
| 541 bar_->SetVisible(false); | 528 bar_->SetVisible(false); |
| 542 return; | 529 return; |
| 543 } | 530 } |
| 544 | 531 |
| 545 int bar_id = 0; | 532 int bar_id = 0; |
| 546 if (state_ & (STATE_ACTIVE)) | 533 // TODO(msw): Restore shelf button bar images. |
|
msw
2016/01/27 07:43:41
Standardize commenting.
| |
| 547 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; | 534 // if (state_ & (STATE_ACTIVE)) |
| 548 else if (state_ & STATE_ATTENTION) | 535 // bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; |
| 549 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; | 536 // else if (state_ & STATE_ATTENTION) |
| 550 else if (state_ & STATE_RUNNING) | 537 // bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; |
| 551 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; | 538 // else if (state_ & STATE_RUNNING) |
| 539 // bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; | |
| 552 | 540 |
| 553 if (bar_id != 0) { | 541 if (bar_id != 0) { |
| 554 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 542 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 555 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); | 543 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); |
| 556 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 544 if (host_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 557 bar_->SetImage(*image); | 545 bar_->SetImage(*image); |
| 558 } else { | 546 } else { |
| 559 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, | 547 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, |
| 560 shelf_layout_manager_->SelectValueForShelfAlignment( | 548 host_->SelectValueForShelfAlignment( |
| 561 SkBitmapOperations::ROTATION_90_CW, | 549 SkBitmapOperations::ROTATION_90_CW, |
| 562 SkBitmapOperations::ROTATION_90_CW, | 550 SkBitmapOperations::ROTATION_90_CW, |
| 563 SkBitmapOperations::ROTATION_270_CW, | 551 SkBitmapOperations::ROTATION_270_CW, |
| 564 SkBitmapOperations::ROTATION_180_CW))); | 552 SkBitmapOperations::ROTATION_180_CW))); |
| 565 } | 553 } |
| 566 bar_->SetHorizontalAlignment( | 554 bar_->SetHorizontalAlignment(host_->SelectValueForShelfAlignment( |
| 567 shelf_layout_manager_->SelectValueForShelfAlignment( | 555 views::ImageView::CENTER, views::ImageView::LEADING, |
| 568 views::ImageView::CENTER, | 556 views::ImageView::TRAILING, views::ImageView::CENTER)); |
| 569 views::ImageView::LEADING, | 557 bar_->SetVerticalAlignment(host_->SelectValueForShelfAlignment( |
| 570 views::ImageView::TRAILING, | 558 views::ImageView::TRAILING, views::ImageView::CENTER, |
| 571 views::ImageView::CENTER)); | 559 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(); | 560 bar_->SchedulePaint(); |
| 579 } | 561 } |
| 580 | 562 |
| 581 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 563 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
| 582 } | 564 } |
| 583 | 565 |
| 584 } // namespace ash | 566 } // namespace shelf |
| 567 } // namespace mash | |
| OLD | NEW |