OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ash/shelf/alternate_app_list_button.h" | |
6 | |
7 #include "ash/ash_constants.h" | |
8 #include "ash/ash_switches.h" | |
9 #include "ash/shelf/shelf_button.h" | |
10 #include "ash/shelf/shelf_button_host.h" | |
11 #include "ash/shelf/shelf_item_types.h" | |
12 #include "ash/shelf/shelf_layout_manager.h" | |
13 #include "ash/shelf/shelf_widget.h" | |
14 #include "ash/shell.h" | |
15 #include "grit/ash_resources.h" | |
16 #include "grit/ash_strings.h" | |
17 #include "ui/accessibility/ax_view_state.h" | |
18 #include "ui/base/l10n/l10n_util.h" | |
19 #include "ui/base/resource/resource_bundle.h" | |
20 #include "ui/compositor/layer.h" | |
21 #include "ui/compositor/layer_animation_element.h" | |
22 #include "ui/compositor/layer_animation_sequence.h" | |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | |
24 #include "ui/gfx/canvas.h" | |
25 #include "ui/gfx/image/image_skia_operations.h" | |
26 #include "ui/views/controls/button/image_button.h" | |
27 #include "ui/views/painter.h" | |
28 | |
29 namespace ash { | |
30 namespace internal { | |
31 | |
32 // static | |
33 const int AlternateAppListButton::kImageBoundsSize = 7; | |
34 | |
35 | |
36 AlternateAppListButton::AlternateAppListButton(views::ButtonListener* listener, | |
37 ShelfButtonHost* host, | |
38 ShelfWidget* shelf_widget) | |
39 : views::ImageButton(listener), | |
40 host_(host), | |
41 shelf_widget_(shelf_widget) { | |
42 SetAccessibleName(l10n_util::GetStringUTF16(IDS_AURA_APP_LIST_TITLE)); | |
43 SetSize(gfx::Size(ShelfLayoutManager::kShelfSize, | |
44 ShelfLayoutManager::kShelfSize)); | |
45 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | |
46 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | |
47 } | |
48 | |
49 AlternateAppListButton::~AlternateAppListButton() { | |
50 } | |
51 | |
52 bool AlternateAppListButton::OnMousePressed(const ui::MouseEvent& event) { | |
53 ImageButton::OnMousePressed(event); | |
54 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); | |
55 return true; | |
56 } | |
57 | |
58 void AlternateAppListButton::OnMouseReleased(const ui::MouseEvent& event) { | |
59 ImageButton::OnMouseReleased(event); | |
60 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false); | |
61 } | |
62 | |
63 void AlternateAppListButton::OnMouseCaptureLost() { | |
64 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, true); | |
65 ImageButton::OnMouseCaptureLost(); | |
66 } | |
67 | |
68 bool AlternateAppListButton::OnMouseDragged(const ui::MouseEvent& event) { | |
69 ImageButton::OnMouseDragged(event); | |
70 host_->PointerDraggedOnButton(this, ShelfButtonHost::MOUSE, event); | |
71 return true; | |
72 } | |
73 | |
74 void AlternateAppListButton::OnMouseMoved(const ui::MouseEvent& event) { | |
75 ImageButton::OnMouseMoved(event); | |
76 host_->MouseMovedOverButton(this); | |
77 } | |
78 | |
79 void AlternateAppListButton::OnMouseEntered(const ui::MouseEvent& event) { | |
80 ImageButton::OnMouseEntered(event); | |
81 host_->MouseEnteredButton(this); | |
82 } | |
83 | |
84 void AlternateAppListButton::OnMouseExited(const ui::MouseEvent& event) { | |
85 ImageButton::OnMouseExited(event); | |
86 host_->MouseExitedButton(this); | |
87 } | |
88 | |
89 void AlternateAppListButton::OnGestureEvent(ui::GestureEvent* event) { | |
90 switch (event->type()) { | |
91 case ui::ET_GESTURE_SCROLL_BEGIN: | |
92 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); | |
93 event->SetHandled(); | |
94 return; | |
95 case ui::ET_GESTURE_SCROLL_UPDATE: | |
96 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); | |
97 event->SetHandled(); | |
98 return; | |
99 case ui::ET_GESTURE_SCROLL_END: | |
100 case ui::ET_SCROLL_FLING_START: | |
101 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); | |
102 event->SetHandled(); | |
103 return; | |
104 default: | |
105 ImageButton::OnGestureEvent(event); | |
106 return; | |
107 } | |
108 } | |
109 | |
110 void AlternateAppListButton::OnPaint(gfx::Canvas* canvas) { | |
111 // Call the base class first to paint any background/borders. | |
112 View::OnPaint(canvas); | |
113 | |
114 int background_image_id = 0; | |
115 if (Shell::GetInstance()->GetAppListTargetVisibility()) { | |
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | |
117 } else { | |
118 if (shelf_widget_->GetDimsShelf()) | |
119 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | |
120 else | |
121 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | |
122 } | |
123 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
124 const gfx::ImageSkia* background_image = | |
125 rb.GetImageNamed(background_image_id).ToImageSkia(); | |
126 const gfx::ImageSkia* forground_image = | |
127 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_ALTERNATE).ToImageSkia(); | |
128 | |
129 gfx::Rect contents_bounds = GetContentsBounds(); | |
130 gfx::Rect background_bounds, forground_bounds; | |
131 | |
132 ShelfAlignment alignment = shelf_widget_->GetAlignment(); | |
133 background_bounds.set_size(background_image->size()); | |
134 if (alignment == SHELF_ALIGNMENT_LEFT) { | |
135 background_bounds.set_x(contents_bounds.width() - | |
136 ShelfLayoutManager::kShelfItemInset - background_image->width()); | |
137 background_bounds.set_y(contents_bounds.y() + | |
138 (contents_bounds.height() - background_image->height()) / 2); | |
139 } else if(alignment == SHELF_ALIGNMENT_RIGHT) { | |
140 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); | |
141 background_bounds.set_y(contents_bounds.y() + | |
142 (contents_bounds.height() - background_image->height()) / 2); | |
143 } else { | |
144 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); | |
145 background_bounds.set_x(contents_bounds.x() + | |
146 (contents_bounds.width() - background_image->width()) / 2); | |
147 } | |
148 | |
149 forground_bounds.set_size(forground_image->size()); | |
150 forground_bounds.set_x(background_bounds.x() + | |
151 std::max(0, | |
152 (background_bounds.width() - forground_bounds.width()) / 2)); | |
153 forground_bounds.set_y(background_bounds.y() + | |
154 std::max(0, | |
155 (background_bounds.height() - forground_bounds.height()) / 2)); | |
156 | |
157 canvas->DrawImageInt(*background_image, | |
158 background_bounds.x(), | |
159 background_bounds.y()); | |
160 canvas->DrawImageInt(*forground_image, | |
161 forground_bounds.x(), | |
162 forground_bounds.y()); | |
163 | |
164 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | |
165 } | |
166 | |
167 void AlternateAppListButton::GetAccessibleState( | |
168 ui::AXViewState* state) { | |
169 state->role = ui::AX_ROLE_BUTTON; | |
170 state->name = host_->GetAccessibleName(this); | |
171 } | |
172 | |
173 } // namespace internal | |
174 } // namespace ash | |
OLD | NEW |