| 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" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0); | 370 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0); |
| 371 | 371 |
| 372 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 372 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); |
| 373 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 373 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); |
| 374 | 374 |
| 375 // If on the left or top 'invert' the inset so the constant gap is on | 375 // If on the left or top 'invert' the inset so the constant gap is on |
| 376 // the interior (towards the center of display) edge of the shelf. | 376 // the interior (towards the center of display) edge of the shelf. |
| 377 if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) | 377 if (SHELF_ALIGNMENT_LEFT == shelf->alignment()) |
| 378 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 378 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| 379 | 379 |
| 380 if (SHELF_ALIGNMENT_TOP == shelf->alignment()) | |
| 381 y_offset = button_bounds.height() - (kIconSize + icon_pad); | |
| 382 | |
| 383 // Center icon with respect to the secondary axis, and ensure | 380 // Center icon with respect to the secondary axis, and ensure |
| 384 // that the icon doesn't occlude the bar highlight. | 381 // that the icon doesn't occlude the bar highlight. |
| 385 if (shelf->IsHorizontalAlignment()) { | 382 if (shelf->IsHorizontalAlignment()) { |
| 386 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 383 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
| 387 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 384 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
| 388 icon_height = button_bounds.height() - (y_offset + kBarSize); | 385 icon_height = button_bounds.height() - (y_offset + kBarSize); |
| 389 } else { | 386 } else { |
| 390 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 387 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
| 391 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 388 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
| 392 icon_width = button_bounds.width() - (x_offset + kBarSize); | 389 icon_width = button_bounds.width() - (x_offset + kBarSize); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); | 489 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); |
| 493 | 490 |
| 494 Shelf* shelf = shelf_view_->shelf(); | 491 Shelf* shelf = shelf_view_->shelf(); |
| 495 if (shelf->alignment() == SHELF_ALIGNMENT_BOTTOM) { | 492 if (shelf->alignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 496 bar_->SetImage(*image); | 493 bar_->SetImage(*image); |
| 497 } else { | 494 } else { |
| 498 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage( | 495 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage( |
| 499 *image, shelf->SelectValueForShelfAlignment( | 496 *image, shelf->SelectValueForShelfAlignment( |
| 500 SkBitmapOperations::ROTATION_90_CW, | 497 SkBitmapOperations::ROTATION_90_CW, |
| 501 SkBitmapOperations::ROTATION_90_CW, | 498 SkBitmapOperations::ROTATION_90_CW, |
| 502 SkBitmapOperations::ROTATION_270_CW, | 499 SkBitmapOperations::ROTATION_270_CW))); |
| 503 SkBitmapOperations::ROTATION_180_CW))); | |
| 504 } | 500 } |
| 505 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( | 501 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( |
| 506 views::ImageView::CENTER, views::ImageView::LEADING, | 502 views::ImageView::CENTER, views::ImageView::LEADING, |
| 507 views::ImageView::TRAILING, views::ImageView::CENTER)); | 503 views::ImageView::TRAILING)); |
| 508 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( | 504 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( |
| 509 views::ImageView::TRAILING, views::ImageView::CENTER, | 505 views::ImageView::TRAILING, views::ImageView::CENTER, |
| 510 views::ImageView::CENTER, views::ImageView::LEADING)); | 506 views::ImageView::CENTER)); |
| 511 bar_->SchedulePaint(); | 507 bar_->SchedulePaint(); |
| 512 } | 508 } |
| 513 | 509 |
| 514 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 510 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
| 515 } | 511 } |
| 516 | 512 |
| 517 } // namespace ash | 513 } // namespace ash |
| OLD | NEW |