| 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 "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/common/shelf/shelf_constants.h" |
| 11 #include "ash/material_design/material_design_controller.h" | 12 #include "ash/material_design/material_design_controller.h" |
| 12 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_constants.h" | |
| 14 #include "ash/shelf/shelf_view.h" | 14 #include "ash/shelf/shelf_view.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 17 #include "skia/ext/image_operations.h" | 17 #include "skia/ext/image_operations.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "ui/accessibility/ax_view_state.h" | 19 #include "ui/accessibility/ax_view_state.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/events/event_constants.h" | 23 #include "ui/events/event_constants.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 Shelf* shelf = shelf_view_->shelf(); | 388 Shelf* shelf = shelf_view_->shelf(); |
| 389 int icon_pad = shelf->PrimaryAxisValue(kIconPad, kIconPadVertical); | 389 int icon_pad = shelf->PrimaryAxisValue(kIconPad, kIconPadVertical); |
| 390 int x_offset = shelf->PrimaryAxisValue(0, icon_pad); | 390 int x_offset = shelf->PrimaryAxisValue(0, icon_pad); |
| 391 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0); | 391 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0); |
| 392 | 392 |
| 393 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 393 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); |
| 394 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 394 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); |
| 395 | 395 |
| 396 // If on the left or top 'invert' the inset so the constant gap is on | 396 // If on the left or top 'invert' the inset so the constant gap is on |
| 397 // the interior (towards the center of display) edge of the shelf. | 397 // the interior (towards the center of display) edge of the shelf. |
| 398 if (wm::SHELF_ALIGNMENT_LEFT == shelf->alignment()) | 398 if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) |
| 399 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 399 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| 400 | 400 |
| 401 // Center icon with respect to the secondary axis, and ensure | 401 // Center icon with respect to the secondary axis, and ensure |
| 402 // that the icon doesn't occlude the bar highlight. | 402 // that the icon doesn't occlude the bar highlight. |
| 403 if (shelf->IsHorizontalAlignment()) { | 403 if (shelf->IsHorizontalAlignment()) { |
| 404 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 404 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
| 405 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 405 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
| 406 icon_height = button_bounds.height() - (y_offset + kBarSize); | 406 icon_height = button_bounds.height() - (y_offset + kBarSize); |
| 407 } else { | 407 } else { |
| 408 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 408 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 gfx::Size size(kShelfButtonSize, kShelfSize); | 512 gfx::Size size(kShelfButtonSize, kShelfSize); |
| 513 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); | 513 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */); |
| 514 PaintIndicatorOnCanvas(&canvas, size); | 514 PaintIndicatorOnCanvas(&canvas, size); |
| 515 image = gfx::ImageSkia(canvas.ExtractImageRep()); | 515 image = gfx::ImageSkia(canvas.ExtractImageRep()); |
| 516 } else { | 516 } else { |
| 517 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); | 517 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); |
| 518 image = *rb->GetImageNamed(bar_id).ToImageSkia(); | 518 image = *rb->GetImageNamed(bar_id).ToImageSkia(); |
| 519 } | 519 } |
| 520 if (!shelf->IsHorizontalAlignment()) { | 520 if (!shelf->IsHorizontalAlignment()) { |
| 521 image = gfx::ImageSkiaOperations::CreateRotatedImage( | 521 image = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 522 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT | 522 image, shelf->alignment() == SHELF_ALIGNMENT_LEFT |
| 523 ? SkBitmapOperations::ROTATION_90_CW | 523 ? SkBitmapOperations::ROTATION_90_CW |
| 524 : SkBitmapOperations::ROTATION_270_CW); | 524 : SkBitmapOperations::ROTATION_270_CW); |
| 525 } | 525 } |
| 526 bar_->SetImage(image); | 526 bar_->SetImage(image); |
| 527 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( | 527 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( |
| 528 views::ImageView::CENTER, views::ImageView::LEADING, | 528 views::ImageView::CENTER, views::ImageView::LEADING, |
| 529 views::ImageView::TRAILING)); | 529 views::ImageView::TRAILING)); |
| 530 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( | 530 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( |
| 531 views::ImageView::TRAILING, views::ImageView::CENTER, | 531 views::ImageView::TRAILING, views::ImageView::CENTER, |
| 532 views::ImageView::CENTER)); | 532 views::ImageView::CENTER)); |
| 533 bar_->SchedulePaint(); | 533 bar_->SchedulePaint(); |
| 534 } | 534 } |
| 535 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 535 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
| 536 } | 536 } |
| 537 | 537 |
| 538 } // namespace ash | 538 } // namespace ash |
| OLD | NEW |