Chromium Code Reviews| Index: ash/shelf/app_list_button.cc |
| diff --git a/ash/shelf/app_list_button.cc b/ash/shelf/app_list_button.cc |
| index 3fef94a5c78489da8bbe67c8dd1fc9168a2d99ac..663d94844358f3749e00a6f8e51690f6a02cc5ab 100644 |
| --- a/ash/shelf/app_list_button.cc |
| +++ b/ash/shelf/app_list_button.cc |
| @@ -4,11 +4,14 @@ |
| #include "ash/shelf/app_list_button.h" |
| -#include <vector> |
| - |
| #include "ash/ash_constants.h" |
|
Mr4D (OOO till 08-26)
2014/01/23 19:25:08
Same here as in the .h file as descibed by jamesco
Harry McCleave
2014/01/24 22:48:47
same as .h
|
| +#include "ash/ash_switches.h" |
| +#include "ash/launcher/launcher_types.h" |
| +#include "ash/shelf/shelf_button.h" |
| #include "ash/shelf/shelf_button_host.h" |
| -#include "ash/shelf/shelf_constants.h" |
| +#include "ash/shelf/shelf_layout_manager.h" |
| +#include "ash/shelf/shelf_widget.h" |
| +#include "ash/shell.h" |
| #include "grit/ash_resources.h" |
| #include "grit/ash_strings.h" |
| #include "ui/base/accessibility/accessible_view_state.h" |
| @@ -18,33 +21,27 @@ |
| #include "ui/compositor/layer_animation_element.h" |
| #include "ui/compositor/layer_animation_sequence.h" |
| #include "ui/compositor/scoped_layer_animation_settings.h" |
| +#include "ui/gfx/canvas.h" |
| +#include "ui/gfx/image/image_skia_operations.h" |
| +#include "ui/views/controls/button/image_button.h" |
| #include "ui/views/painter.h" |
| namespace ash { |
| namespace internal { |
| -const int kAnimationDurationInMs = 600; |
| -const float kAnimationOpacity[] = { 1.0f, 0.4f, 1.0f }; |
| +// static |
| +const int AppListButton::kImageBoundsSize = 7; |
| + |
| AppListButton::AppListButton(views::ButtonListener* listener, |
| - ShelfButtonHost* host) |
| + ShelfButtonHost* host, |
| + ShelfWidget* shelf_widget) |
| : views::ImageButton(listener), |
| - host_(host) { |
| - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| - SetImage( |
| - views::CustomButton::STATE_NORMAL, |
| - rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); |
| - SetImage( |
| - views::CustomButton::STATE_HOVERED, |
| - rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT). |
| - ToImageSkia()); |
| - SetImage( |
| - views::CustomButton::STATE_PRESSED, |
| - rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED). |
| - ToImageSkia()); |
| + host_(host), |
| + shelf_widget_(shelf_widget) { |
| SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); |
| - SetSize(gfx::Size(kShelfPreferredSize, kShelfPreferredSize)); |
| - SetImageAlignment(ImageButton::ALIGN_CENTER, ImageButton::ALIGN_TOP); |
| + SetSize(gfx::Size(ShelfLayoutManager::kShelfSize, |
| + ShelfLayoutManager::kShelfSize)); |
| SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
| kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
| } |
| @@ -52,40 +49,6 @@ AppListButton::AppListButton(views::ButtonListener* listener, |
| AppListButton::~AppListButton() { |
| } |
| -void AppListButton::StartLoadingAnimation() { |
| - layer()->GetAnimator()->StopAnimating(); |
| - |
| - scoped_ptr<ui::LayerAnimationSequence> opacity_sequence( |
| - new ui::LayerAnimationSequence()); |
| - |
| - opacity_sequence->set_is_cyclic(true); |
| - |
| - for (size_t i = 0; i < arraysize(kAnimationOpacity); ++i) { |
| - opacity_sequence->AddElement( |
| - ui::LayerAnimationElement::CreateOpacityElement( |
| - kAnimationOpacity[i], |
| - base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| - } |
| - |
| - opacity_sequence->AddElement( |
| - ui::LayerAnimationElement::CreatePauseElement( |
| - ui::LayerAnimationElement::OPACITY, |
| - base::TimeDelta::FromMilliseconds(kAnimationDurationInMs))); |
| - |
| - // LayerAnimator takes ownership of the sequences. |
| - layer()->GetAnimator()->ScheduleAnimation(opacity_sequence.release()); |
| -} |
| - |
| -void AppListButton::StopLoadingAnimation() { |
| - layer()->GetAnimator()->StopAnimating(); |
| - |
| - ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| - settings.SetTransitionDuration( |
| - base::TimeDelta::FromMilliseconds(kAnimationDurationInMs)); |
| - layer()->SetOpacity(1.0f); |
| - layer()->SetTransform(gfx::Transform()); |
| -} |
| - |
| bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
| ImageButton::OnMousePressed(event); |
| host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); |
| @@ -123,7 +86,86 @@ void AppListButton::OnMouseExited(const ui::MouseEvent& event) { |
| host_->MouseExitedButton(this); |
| } |
| -void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { |
| +void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
| + switch (event->type()) { |
| + case ui::ET_GESTURE_SCROLL_BEGIN: |
| + host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); |
| + event->SetHandled(); |
| + return; |
| + case ui::ET_GESTURE_SCROLL_UPDATE: |
| + host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); |
| + event->SetHandled(); |
| + return; |
| + case ui::ET_GESTURE_SCROLL_END: |
| + case ui::ET_SCROLL_FLING_START: |
| + host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); |
| + event->SetHandled(); |
| + return; |
| + default: |
| + ImageButton::OnGestureEvent(event); |
| + return; |
| + } |
| +} |
| + |
| +void AppListButton::OnPaint(gfx::Canvas* canvas) { |
| + // Call the base class first to paint any background/borders. |
| + View::OnPaint(canvas); |
| + |
| + int background_image_id = 0; |
| + if (Shell::GetInstance()->GetAppListTargetVisibility()) { |
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| + } else { |
| + if (shelf_widget_->GetDimsShelf()) |
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| + else |
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| + } |
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| + const gfx::ImageSkia* background_image = |
| + rb.GetImageNamed(background_image_id).ToImageSkia(); |
| + const gfx::ImageSkia* forground_image = |
| + rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_ALTERNATE).ToImageSkia(); |
| + |
| + gfx::Rect contents_bounds = GetContentsBounds(); |
| + gfx::Rect background_bounds, forground_bounds; |
| + |
| + ShelfAlignment alignment = shelf_widget_->GetAlignment(); |
| + background_bounds.set_size(background_image->size()); |
| + if (alignment == SHELF_ALIGNMENT_LEFT) { |
| + background_bounds.set_x(contents_bounds.width() - |
| + ShelfLayoutManager::kShelfItemInset - background_image->width()); |
| + background_bounds.set_y(contents_bounds.y() + |
| + (contents_bounds.height() - background_image->height()) / 2); |
| + } else if(alignment == SHELF_ALIGNMENT_RIGHT) { |
| + background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); |
| + background_bounds.set_y(contents_bounds.y() + |
| + (contents_bounds.height() - background_image->height()) / 2); |
| + } else { |
| + background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); |
| + background_bounds.set_x(contents_bounds.x() + |
| + (contents_bounds.width() - background_image->width()) / 2); |
| + } |
| + |
| + forground_bounds.set_size(forground_image->size()); |
| + forground_bounds.set_x(background_bounds.x() + |
| + std::max(0, |
| + (background_bounds.width() - forground_bounds.width()) / 2)); |
| + forground_bounds.set_y(background_bounds.y() + |
| + std::max(0, |
| + (background_bounds.height() - forground_bounds.height()) / 2)); |
| + |
| + canvas->DrawImageInt(*background_image, |
| + background_bounds.x(), |
| + background_bounds.y()); |
| + canvas->DrawImageInt(*forground_image, |
| + forground_bounds.x(), |
| + forground_bounds.y()); |
| + |
| + views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
| +} |
| + |
| +void AppListButton::GetAccessibleState( |
| + ui::AccessibleViewState* state) { |
| state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| state->name = host_->GetAccessibleName(this); |
| } |