OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shelf/app_list_button.h" | 5 #include "ash/shelf/app_list_button.h" |
6 | 6 |
7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
9 #include "ash/shelf/shelf_button.h" | 9 #include "ash/shelf/shelf_button.h" |
10 #include "ash/shelf/shelf_button_host.h" | 10 #include "ash/shelf/shelf_button_host.h" |
11 #include "ash/shelf/shelf_item_types.h" | 11 #include "ash/shelf/shelf_item_types.h" |
12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "base/command_line.h" |
15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
17 #include "ui/accessibility/ax_view_state.h" | 18 #include "ui/accessibility/ax_view_state.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
21 #include "ui/compositor/layer_animation_element.h" | 22 #include "ui/compositor/layer_animation_element.h" |
22 #include "ui/compositor/layer_animation_sequence.h" | 23 #include "ui/compositor/layer_animation_sequence.h" |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
25 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
26 #include "ui/views/controls/button/image_button.h" | 27 #include "ui/views/controls/button/image_button.h" |
27 #include "ui/views/painter.h" | 28 #include "ui/views/painter.h" |
28 | 29 |
29 namespace ash { | 30 namespace ash { |
30 // static | 31 // static |
31 const int AppListButton::kImageBoundsSize = 7; | 32 const int AppListButton::kImageBoundsSize = 7; |
32 | 33 |
33 | 34 |
34 AppListButton::AppListButton(views::ButtonListener* listener, | 35 AppListButton::AppListButton(views::ButtonListener* listener, |
35 ShelfButtonHost* host, | 36 ShelfButtonHost* host, |
36 ShelfWidget* shelf_widget) | 37 ShelfWidget* shelf_widget) |
37 : views::ImageButton(listener), | 38 : views::ImageButton(listener), |
| 39 draw_background_as_active_(false), |
| 40 touch_feedback_enabled_(CommandLine::ForCurrentProcess()-> |
| 41 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)), |
38 host_(host), | 42 host_(host), |
39 shelf_widget_(shelf_widget) { | 43 shelf_widget_(shelf_widget) { |
40 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); | 44 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); |
41 SetSize(gfx::Size(kShelfSize, kShelfSize)); | 45 SetSize(gfx::Size(kShelfSize, kShelfSize)); |
42 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 46 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
43 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 47 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
44 } | 48 } |
45 | 49 |
46 AppListButton::~AppListButton() { | 50 AppListButton::~AppListButton() { |
47 } | 51 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 83 } |
80 | 84 |
81 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { | 85 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { |
82 ImageButton::OnMouseExited(event); | 86 ImageButton::OnMouseExited(event); |
83 host_->MouseExitedButton(this); | 87 host_->MouseExitedButton(this); |
84 } | 88 } |
85 | 89 |
86 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { | 90 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
87 switch (event->type()) { | 91 switch (event->type()) { |
88 case ui::ET_GESTURE_SCROLL_BEGIN: | 92 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 93 if (touch_feedback_enabled_) |
| 94 SetDrawBackgroundAsActive(false); |
89 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); | 95 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); |
90 event->SetHandled(); | 96 event->SetHandled(); |
91 return; | 97 return; |
92 case ui::ET_GESTURE_SCROLL_UPDATE: | 98 case ui::ET_GESTURE_SCROLL_UPDATE: |
93 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); | 99 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); |
94 event->SetHandled(); | 100 event->SetHandled(); |
95 return; | 101 return; |
96 case ui::ET_GESTURE_SCROLL_END: | 102 case ui::ET_GESTURE_SCROLL_END: |
97 case ui::ET_SCROLL_FLING_START: | 103 case ui::ET_SCROLL_FLING_START: |
98 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); | 104 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); |
99 event->SetHandled(); | 105 event->SetHandled(); |
100 return; | 106 return; |
| 107 case ui::ET_GESTURE_TAP_DOWN: |
| 108 if (touch_feedback_enabled_) |
| 109 SetDrawBackgroundAsActive(true); |
| 110 ImageButton::OnGestureEvent(event); |
| 111 break; |
| 112 case ui::ET_GESTURE_TAP_CANCEL: |
| 113 case ui::ET_GESTURE_TAP: |
| 114 if (touch_feedback_enabled_) |
| 115 SetDrawBackgroundAsActive(false); |
| 116 ImageButton::OnGestureEvent(event); |
| 117 break; |
101 default: | 118 default: |
102 ImageButton::OnGestureEvent(event); | 119 ImageButton::OnGestureEvent(event); |
103 return; | 120 return; |
104 } | 121 } |
105 } | 122 } |
106 | 123 |
107 void AppListButton::OnPaint(gfx::Canvas* canvas) { | 124 void AppListButton::OnPaint(gfx::Canvas* canvas) { |
108 // Call the base class first to paint any background/borders. | 125 // Call the base class first to paint any background/borders. |
109 View::OnPaint(canvas); | 126 View::OnPaint(canvas); |
110 | 127 |
111 int background_image_id = 0; | 128 int background_image_id = 0; |
112 if (Shell::GetInstance()->GetAppListTargetVisibility()) { | 129 if (Shell::GetInstance()->GetAppListTargetVisibility() || |
| 130 draw_background_as_active_) { |
113 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 131 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
114 } else { | 132 } else { |
115 if (shelf_widget_->GetDimsShelf()) | 133 if (shelf_widget_->GetDimsShelf()) |
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 134 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
117 else | 135 else |
118 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 136 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
119 } | 137 } |
120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 138 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
121 const gfx::ImageSkia* background_image = | 139 const gfx::ImageSkia* background_image = |
122 rb.GetImageNamed(background_image_id).ToImageSkia(); | 140 rb.GetImageNamed(background_image_id).ToImageSkia(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 forground_bounds.y()); | 177 forground_bounds.y()); |
160 | 178 |
161 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | 179 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
162 } | 180 } |
163 | 181 |
164 void AppListButton::GetAccessibleState(ui::AXViewState* state) { | 182 void AppListButton::GetAccessibleState(ui::AXViewState* state) { |
165 state->role = ui::AX_ROLE_BUTTON; | 183 state->role = ui::AX_ROLE_BUTTON; |
166 state->name = host_->GetAccessibleName(this); | 184 state->name = host_->GetAccessibleName(this); |
167 } | 185 } |
168 | 186 |
| 187 void AppListButton::SetDrawBackgroundAsActive( |
| 188 bool draw_background_as_active) { |
| 189 if (draw_background_as_active_ == draw_background_as_active) |
| 190 return; |
| 191 draw_background_as_active_ = draw_background_as_active; |
| 192 SchedulePaint(); |
| 193 } |
| 194 |
169 } // namespace ash | 195 } // namespace ash |
OLD | NEW |