Safebrowsing aura linux_redux compile fixes.
[chromium-blink-merge.git] / ash / shelf / alternate_app_list_button.cc
blob4ce283418bc47b6e1f16fcfb9b2f21c7fc8ce02d
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
3 // found in the LICENSE file.
5 #include "ash/shelf/alternate_app_list_button.h"
7 #include "ash/ash_switches.h"
8 #include "ash/launcher/launcher_types.h"
9 #include "ash/shelf/shelf_button_host.h"
10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h"
15 #include "ui/base/accessibility/accessible_view_state.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h"
19 #include "ui/compositor/layer_animation_element.h"
20 #include "ui/compositor/layer_animation_sequence.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/views/controls/button/image_button.h"
26 namespace ash {
27 namespace internal {
29 // static
30 const int AlternateAppListButton::kImageBoundsSize = 7;
33 AlternateAppListButton::AlternateAppListButton(views::ButtonListener* listener,
34 ShelfButtonHost* host,
35 ShelfWidget* shelf_widget)
36 : views::ImageButton(listener),
37 host_(host),
38 shelf_widget_(shelf_widget) {
39 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE));
40 SetSize(gfx::Size(ShelfLayoutManager::kShelfSize,
41 ShelfLayoutManager::kShelfSize));
44 AlternateAppListButton::~AlternateAppListButton() {
47 bool AlternateAppListButton::OnMousePressed(const ui::MouseEvent& event) {
48 ImageButton::OnMousePressed(event);
49 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event);
50 return true;
53 void AlternateAppListButton::OnMouseReleased(const ui::MouseEvent& event) {
54 ImageButton::OnMouseReleased(event);
55 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false);
58 void AlternateAppListButton::OnMouseCaptureLost() {
59 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, true);
60 ImageButton::OnMouseCaptureLost();
63 bool AlternateAppListButton::OnMouseDragged(const ui::MouseEvent& event) {
64 ImageButton::OnMouseDragged(event);
65 host_->PointerDraggedOnButton(this, ShelfButtonHost::MOUSE, event);
66 return true;
69 void AlternateAppListButton::OnMouseMoved(const ui::MouseEvent& event) {
70 ImageButton::OnMouseMoved(event);
71 host_->MouseMovedOverButton(this);
74 void AlternateAppListButton::OnMouseEntered(const ui::MouseEvent& event) {
75 ImageButton::OnMouseEntered(event);
76 host_->MouseEnteredButton(this);
79 void AlternateAppListButton::OnMouseExited(const ui::MouseEvent& event) {
80 ImageButton::OnMouseExited(event);
81 host_->MouseExitedButton(this);
84 void AlternateAppListButton::OnGestureEvent(ui::GestureEvent* event) {
85 switch (event->type()) {
86 case ui::ET_GESTURE_SCROLL_BEGIN:
87 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event);
88 event->SetHandled();
89 return;
90 case ui::ET_GESTURE_SCROLL_UPDATE:
91 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event);
92 event->SetHandled();
93 return;
94 case ui::ET_GESTURE_SCROLL_END:
95 case ui::ET_SCROLL_FLING_START:
96 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false);
97 event->SetHandled();
98 return;
99 default:
100 ImageButton::OnGestureEvent(event);
101 return;
105 void AlternateAppListButton::OnPaint(gfx::Canvas* canvas) {
106 // Call the base class first to paint any background/borders.
107 View::OnPaint(canvas);
109 int background_image_id = 0;
110 if (Shell::GetInstance()->GetAppListTargetVisibility()) {
111 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
112 } else {
113 if (shelf_widget_->GetDimsShelf())
114 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
115 else
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
118 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
119 const gfx::ImageSkia* background_image =
120 rb.GetImageNamed(background_image_id).ToImageSkia();
121 const gfx::ImageSkia* forground_image =
122 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_ALTERNATE).ToImageSkia();
124 gfx::Rect contents_bounds = GetContentsBounds();
125 gfx::Rect background_bounds, forground_bounds;
127 ShelfAlignment alignment = shelf_widget_->GetAlignment();
128 background_bounds.set_size(background_image->size());
129 if (alignment == SHELF_ALIGNMENT_LEFT) {
130 background_bounds.set_x(contents_bounds.width() -
131 ShelfLayoutManager::kShelfItemInset - background_image->width());
132 background_bounds.set_y(contents_bounds.y() +
133 (contents_bounds.height() - background_image->height()) / 2);
134 } else if(alignment == SHELF_ALIGNMENT_RIGHT) {
135 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset);
136 background_bounds.set_y(contents_bounds.y() +
137 (contents_bounds.height() - background_image->height()) / 2);
138 } else {
139 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset);
140 background_bounds.set_x(contents_bounds.x() +
141 (contents_bounds.width() - background_image->width()) / 2);
144 forground_bounds.set_size(forground_image->size());
145 forground_bounds.set_x(background_bounds.x() +
146 std::max(0,
147 (background_bounds.width() - forground_bounds.width()) / 2));
148 forground_bounds.set_y(background_bounds.y() +
149 std::max(0,
150 (background_bounds.height() - forground_bounds.height()) / 2));
152 canvas->DrawImageInt(*background_image,
153 background_bounds.x(),
154 background_bounds.y());
155 canvas->DrawImageInt(*forground_image,
156 forground_bounds.x(),
157 forground_bounds.y());
159 OnPaintFocusBorder(canvas);
162 void AlternateAppListButton::GetAccessibleState(
163 ui::AccessibleViewState* state) {
164 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
165 state->name = host_->GetAccessibleName(this);
168 } // namespace internal
169 } // namespace ash