OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher_button.h" | 5 #include "ash/launcher/launcher_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/launcher_button_host.h" | 9 #include "ash/launcher/launcher_button_host.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 host_->MouseExitedButton(this); | 385 host_->MouseExitedButton(this); |
386 } | 386 } |
387 | 387 |
388 void LauncherButton::GetAccessibleState(ui::AccessibleViewState* state) { | 388 void LauncherButton::GetAccessibleState(ui::AccessibleViewState* state) { |
389 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 389 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
390 state->name = host_->GetAccessibleName(this); | 390 state->name = host_->GetAccessibleName(this); |
391 } | 391 } |
392 | 392 |
393 void LauncherButton::Layout() { | 393 void LauncherButton::Layout() { |
394 const gfx::Rect button_bounds(GetContentsBounds()); | 394 const gfx::Rect button_bounds(GetContentsBounds()); |
395 | 395 int x_offset = 0, y_offset = 0; |
396 int x_offset = shelf_layout_manager_->SelectValueForShelfAlignment( | 396 gfx::Rect icon_bounds; |
397 0, kIconPad, kIconPad, 0); | 397 if (shelf_layout_manager_->IsHorizontalAlignment()) { |
398 int y_offset = shelf_layout_manager_->SelectValueForShelfAlignment( | 398 icon_bounds.SetRect( |
399 kIconPad, 0, 0, kIconPad); | 399 button_bounds.x(), button_bounds.y() + kIconPad, |
400 | 400 button_bounds.width(), kIconSize); |
401 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset); | 401 } else { |
402 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset); | 402 icon_bounds.SetRect( |
403 | 403 button_bounds.x() + kIconPad, button_bounds.y(), |
404 x_offset = std::max(x_offset, (button_bounds.width() - icon_width) / 2); | 404 kIconSize, button_bounds.height()); |
405 y_offset = std::max(y_offset, (button_bounds.height() - icon_height) / 2); | 405 } |
406 | 406 |
407 if (ShouldHop(state_)) { | 407 if (ShouldHop(state_)) { |
408 x_offset += shelf_layout_manager_->SelectValueForShelfAlignment( | 408 x_offset += shelf_layout_manager_->SelectValueForShelfAlignment( |
409 0, kHopSpacing, -kHopSpacing, 0); | 409 0, kHopSpacing, -kHopSpacing, 0); |
410 y_offset += shelf_layout_manager_->SelectValueForShelfAlignment( | 410 y_offset += shelf_layout_manager_->SelectValueForShelfAlignment( |
411 -kHopSpacing, 0, 0, kHopSpacing); | 411 -kHopSpacing, 0, 0, kHopSpacing); |
412 } | 412 } |
413 | 413 |
414 gfx::Rect icon_bounds( | 414 icon_bounds.Offset(x_offset, y_offset); |
415 button_bounds.x() + x_offset, | |
416 button_bounds.y() + y_offset, | |
417 icon_width, | |
418 icon_height); | |
419 icon_view_->SetBoundsRect(icon_bounds); | 415 icon_view_->SetBoundsRect(icon_bounds); |
420 bar_->SetBarBoundsRect(GetContentsBounds()); | 416 bar_->SetBarBoundsRect(GetContentsBounds()); |
421 UpdateState(); | 417 UpdateState(); |
422 } | 418 } |
423 | 419 |
424 void LauncherButton::ChildPreferredSizeChanged(views::View* child) { | 420 void LauncherButton::ChildPreferredSizeChanged(views::View* child) { |
425 Layout(); | 421 Layout(); |
426 } | 422 } |
427 | 423 |
428 void LauncherButton::OnFocus() { | 424 void LauncherButton::OnFocus() { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 views::ImageView::TRAILING, | 520 views::ImageView::TRAILING, |
525 views::ImageView::CENTER, | 521 views::ImageView::CENTER, |
526 views::ImageView::CENTER, | 522 views::ImageView::CENTER, |
527 views::ImageView::LEADING)); | 523 views::ImageView::LEADING)); |
528 bar_->SchedulePaint(); | 524 bar_->SchedulePaint(); |
529 SchedulePaint(); | 525 SchedulePaint(); |
530 } | 526 } |
531 | 527 |
532 } // namespace internal | 528 } // namespace internal |
533 } // namespace ash | 529 } // namespace ash |
OLD | NEW |