| 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/wm/shelf_layout_manager.h" |
| 10 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
| 11 #include "skia/ext/image_operations.h" | 12 #include "skia/ext/image_operations.h" |
| 12 #include "ui/base/accessibility/accessible_view_state.h" | 13 #include "ui/base/accessibility/accessible_view_state.h" |
| 13 #include "ui/base/animation/animation_delegate.h" | 14 #include "ui/base/animation/animation_delegate.h" |
| 14 #include "ui/base/animation/throb_animation.h" | 15 #include "ui/base/animation/throb_animation.h" |
| 15 #include "ui/base/events/event_constants.h" | 16 #include "ui/base/events/event_constants.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" | 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 106 } |
| 106 | 107 |
| 107 bool LauncherButton::IconView::HitTestRect(const gfx::Rect& rect) const { | 108 bool LauncherButton::IconView::HitTestRect(const gfx::Rect& rect) const { |
| 108 // Return false so that LauncherButton gets all the mouse events. | 109 // Return false so that LauncherButton gets all the mouse events. |
| 109 return false; | 110 return false; |
| 110 } | 111 } |
| 111 | 112 |
| 112 //////////////////////////////////////////////////////////////////////////////// | 113 //////////////////////////////////////////////////////////////////////////////// |
| 113 // LauncherButton | 114 // LauncherButton |
| 114 | 115 |
| 115 LauncherButton* LauncherButton::Create(views::ButtonListener* listener, | 116 LauncherButton* LauncherButton::Create( |
| 116 LauncherButtonHost* host) { | 117 views::ButtonListener* listener, |
| 117 LauncherButton* button = new LauncherButton(listener, host); | 118 LauncherButtonHost* host, |
| 119 ShelfLayoutManager* shelf_layout_manager) { |
| 120 LauncherButton* button = |
| 121 new LauncherButton(listener, host, shelf_layout_manager); |
| 118 button->Init(); | 122 button->Init(); |
| 119 return button; | 123 return button; |
| 120 } | 124 } |
| 121 | 125 |
| 122 LauncherButton::LauncherButton(views::ButtonListener* listener, | 126 LauncherButton::LauncherButton(views::ButtonListener* listener, |
| 123 LauncherButtonHost* host) | 127 LauncherButtonHost* host, |
| 128 ShelfLayoutManager* shelf_layout_manager) |
| 124 : CustomButton(listener), | 129 : CustomButton(listener), |
| 125 host_(host), | 130 host_(host), |
| 126 icon_view_(NULL), | 131 icon_view_(NULL), |
| 127 bar_(new BarView), | 132 bar_(new BarView), |
| 128 state_(STATE_NORMAL) { | 133 state_(STATE_NORMAL), |
| 134 shelf_layout_manager_(shelf_layout_manager) { |
| 129 set_accessibility_focusable(true); | 135 set_accessibility_focusable(true); |
| 130 | 136 |
| 131 const gfx::ShadowValue kShadows[] = { | 137 const gfx::ShadowValue kShadows[] = { |
| 132 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), | 138 gfx::ShadowValue(gfx::Point(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 133 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), | 139 gfx::ShadowValue(gfx::Point(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), |
| 134 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), | 140 gfx::ShadowValue(gfx::Point(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), |
| 135 }; | 141 }; |
| 136 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); | 142 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); |
| 137 | 143 |
| 138 AddChildView(bar_); | 144 AddChildView(bar_); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void LauncherButton::GetAccessibleState(ui::AccessibleViewState* state) { | 268 void LauncherButton::GetAccessibleState(ui::AccessibleViewState* state) { |
| 263 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 269 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 264 state->name = host_->GetAccessibleName(this); | 270 state->name = host_->GetAccessibleName(this); |
| 265 } | 271 } |
| 266 | 272 |
| 267 void LauncherButton::Layout() { | 273 void LauncherButton::Layout() { |
| 268 const gfx::Rect button_bounds(GetContentsBounds()); | 274 const gfx::Rect button_bounds(GetContentsBounds()); |
| 269 int x_offset = 0, y_offset = 0; | 275 int x_offset = 0, y_offset = 0; |
| 270 gfx::Rect icon_bounds; | 276 gfx::Rect icon_bounds; |
| 271 | 277 |
| 272 if (host_->GetShelfAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 278 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 273 icon_bounds.SetRect( | 279 icon_bounds.SetRect( |
| 274 button_bounds.x(), button_bounds.y() + kIconPad, | 280 button_bounds.x(), button_bounds.y() + kIconPad, |
| 275 button_bounds.width(), kIconSize); | 281 button_bounds.width(), kIconSize); |
| 276 if (ShouldHop(state_)) | 282 if (ShouldHop(state_)) |
| 277 y_offset -= kHopSpacing; | 283 y_offset -= kHopSpacing; |
| 278 } else { | 284 } else { |
| 279 icon_bounds.SetRect( | 285 icon_bounds.SetRect( |
| 280 button_bounds.x() + kIconPad, button_bounds.y(), | 286 button_bounds.x() + kIconPad, button_bounds.y(), |
| 281 kIconSize, button_bounds.height()); | 287 kIconSize, button_bounds.height()); |
| 282 if (!ShouldHop(state_)) | 288 if (!ShouldHop(state_)) |
| 283 x_offset += kHopSpacing; | 289 x_offset += kHopSpacing; |
| 284 } | 290 } |
| 285 | 291 |
| 286 if (host_->GetShelfAlignment() == SHELF_ALIGNMENT_LEFT) | 292 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_LEFT) |
| 287 x_offset = -x_offset; | 293 x_offset = -x_offset; |
| 288 icon_bounds.Offset(x_offset, y_offset); | 294 icon_bounds.Offset(x_offset, y_offset); |
| 289 icon_view_->SetBoundsRect(icon_bounds); | 295 icon_view_->SetBoundsRect(icon_bounds); |
| 290 bar_->SetBoundsRect(GetContentsBounds()); | 296 bar_->SetBoundsRect(GetContentsBounds()); |
| 291 } | 297 } |
| 292 | 298 |
| 293 void LauncherButton::ChildPreferredSizeChanged(views::View* child) { | 299 void LauncherButton::ChildPreferredSizeChanged(views::View* child) { |
| 294 Layout(); | 300 Layout(); |
| 295 } | 301 } |
| 296 | 302 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 icon_view_->SetVerticalAlignment(views::ImageView::LEADING); | 346 icon_view_->SetVerticalAlignment(views::ImageView::LEADING); |
| 341 | 347 |
| 342 AddChildView(icon_view_); | 348 AddChildView(icon_view_); |
| 343 } | 349 } |
| 344 | 350 |
| 345 LauncherButton::IconView* LauncherButton::CreateIconView() { | 351 LauncherButton::IconView* LauncherButton::CreateIconView() { |
| 346 return new IconView; | 352 return new IconView; |
| 347 } | 353 } |
| 348 | 354 |
| 349 bool LauncherButton::IsShelfHorizontal() const { | 355 bool LauncherButton::IsShelfHorizontal() const { |
| 350 return host_->GetShelfAlignment() == SHELF_ALIGNMENT_BOTTOM; | 356 return shelf_layout_manager_->IsHorizontalAlignment(); |
| 351 } | 357 } |
| 352 | 358 |
| 353 void LauncherButton::UpdateState() { | 359 void LauncherButton::UpdateState() { |
| 354 if (state_ == STATE_NORMAL) { | 360 if (state_ == STATE_NORMAL) { |
| 355 bar_->SetVisible(false); | 361 bar_->SetVisible(false); |
| 356 } else { | 362 } else { |
| 357 int bar_id; | 363 int bar_id; |
| 358 if (IsShelfHorizontal()) { | 364 if (state_ & STATE_ACTIVE) { |
| 359 if (state_ & STATE_ACTIVE) | 365 bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( |
| 360 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_ACTIVE; | 366 IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_ACTIVE, |
| 361 else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) | 367 IDR_AURA_LAUNCHER_UNDERLINE_LEFT_ACTIVE, |
| 362 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_HOVER; | 368 IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_ACTIVE); |
| 363 else | 369 } else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) { |
| 364 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_RUNNING; | 370 bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( |
| 371 IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_HOVER, |
| 372 IDR_AURA_LAUNCHER_UNDERLINE_LEFT_HOVER, |
| 373 IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_HOVER); |
| 365 } else { | 374 } else { |
| 366 if (state_ & STATE_ACTIVE) | 375 bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( |
| 367 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_ACTIVE; | 376 IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_RUNNING, |
| 368 else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) | 377 IDR_AURA_LAUNCHER_UNDERLINE_LEFT_RUNNING, |
| 369 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_HOVER; | 378 IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_RUNNING); |
| 370 else | |
| 371 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_RUNNING; | |
| 372 } | 379 } |
| 373 | |
| 374 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 380 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 375 bar_->SetImage(rb.GetImageNamed(bar_id).ToImageSkia()); | 381 bar_->SetImage(rb.GetImageNamed(bar_id).ToImageSkia()); |
| 376 bar_->SetVisible(true); | 382 bar_->SetVisible(true); |
| 377 } | 383 } |
| 384 bool rtl = base::i18n::IsRTL(); |
| 385 bar_->SetHorizontalAlignment( |
| 386 shelf_layout_manager_->SelectValueForShelfAlignment( |
| 387 views::ImageView::CENTER, |
| 388 rtl ? views::ImageView::TRAILING : views::ImageView::LEADING, |
| 389 rtl ? views::ImageView::LEADING : views::ImageView::TRAILING)); |
| 390 bar_->SetVerticalAlignment( |
| 391 shelf_layout_manager_->SelectValueForShelfAlignment( |
| 392 views::ImageView::TRAILING, |
| 393 views::ImageView::CENTER, |
| 394 views::ImageView::CENTER)); |
| 378 | 395 |
| 379 switch (host_->GetShelfAlignment()) { | 396 switch (shelf_layout_manager_->GetAlignment()) { |
| 380 case SHELF_ALIGNMENT_BOTTOM: | 397 case SHELF_ALIGNMENT_BOTTOM: |
| 381 bar_->SetHorizontalAlignment(views::ImageView::CENTER); | 398 bar_->SetHorizontalAlignment(views::ImageView::CENTER); |
| 382 bar_->SetVerticalAlignment(views::ImageView::TRAILING); | 399 bar_->SetVerticalAlignment(views::ImageView::TRAILING); |
| 383 break; | 400 break; |
| 384 case SHELF_ALIGNMENT_LEFT: | 401 case SHELF_ALIGNMENT_LEFT: |
| 385 bar_->SetHorizontalAlignment( | 402 bar_->SetHorizontalAlignment( |
| 386 base::i18n::IsRTL() ? views::ImageView::TRAILING : | 403 base::i18n::IsRTL() ? views::ImageView::TRAILING : |
| 387 views::ImageView::LEADING); | 404 views::ImageView::LEADING); |
| 388 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 405 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 389 break; | 406 break; |
| 390 case SHELF_ALIGNMENT_RIGHT: | 407 case SHELF_ALIGNMENT_RIGHT: |
| 391 bar_->SetHorizontalAlignment( | 408 bar_->SetHorizontalAlignment( |
| 392 base::i18n::IsRTL() ? views::ImageView::LEADING : | 409 base::i18n::IsRTL() ? views::ImageView::LEADING : |
| 393 views::ImageView::TRAILING); | 410 views::ImageView::TRAILING); |
| 394 bar_->SetVerticalAlignment(views::ImageView::CENTER); | 411 bar_->SetVerticalAlignment(views::ImageView::CENTER); |
| 395 break; | 412 break; |
| 396 } | 413 } |
| 397 | 414 |
| 415 // Force bar to layout as alignment may have changed but not bounds. |
| 416 bar_->Layout(); |
| 398 Layout(); | 417 Layout(); |
| 418 bar_->SchedulePaint(); |
| 399 SchedulePaint(); | 419 SchedulePaint(); |
| 400 } | 420 } |
| 401 | 421 |
| 402 } // namespace internal | 422 } // namespace internal |
| 403 } // namespace ash | 423 } // namespace ash |
| OLD | NEW |