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_(false), | |
38 host_(host), | 41 host_(host), |
39 shelf_widget_(shelf_widget) { | 42 shelf_widget_(shelf_widget) { |
40 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); | 43 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); |
41 SetSize(gfx::Size(kShelfSize, kShelfSize)); | 44 SetSize(gfx::Size(kShelfSize, kShelfSize)); |
42 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 45 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
43 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 46 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
47 | |
48 if (CommandLine::ForCurrentProcess()-> | |
49 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) { | |
50 touch_feedback_enabled_ = true; | |
flackr
2014/09/11 21:01:02
initializer list.
jonross
2014/09/12 17:16:08
Done.
| |
51 } | |
44 } | 52 } |
45 | 53 |
46 AppListButton::~AppListButton() { | 54 AppListButton::~AppListButton() { |
47 } | 55 } |
48 | 56 |
49 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { | 57 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
50 ImageButton::OnMousePressed(event); | 58 ImageButton::OnMousePressed(event); |
51 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); | 59 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); |
52 return true; | 60 return true; |
53 } | 61 } |
(...skipping 25 matching lines...) Expand all Loading... | |
79 } | 87 } |
80 | 88 |
81 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { | 89 void AppListButton::OnMouseExited(const ui::MouseEvent& event) { |
82 ImageButton::OnMouseExited(event); | 90 ImageButton::OnMouseExited(event); |
83 host_->MouseExitedButton(this); | 91 host_->MouseExitedButton(this); |
84 } | 92 } |
85 | 93 |
86 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { | 94 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
87 switch (event->type()) { | 95 switch (event->type()) { |
88 case ui::ET_GESTURE_SCROLL_BEGIN: | 96 case ui::ET_GESTURE_SCROLL_BEGIN: |
97 if (touch_feedback_enabled_) | |
98 SetDrawBackgroundAsActive(false); | |
89 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); | 99 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); |
90 event->SetHandled(); | 100 event->SetHandled(); |
91 return; | 101 return; |
92 case ui::ET_GESTURE_SCROLL_UPDATE: | 102 case ui::ET_GESTURE_SCROLL_UPDATE: |
93 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); | 103 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); |
94 event->SetHandled(); | 104 event->SetHandled(); |
95 return; | 105 return; |
96 case ui::ET_GESTURE_SCROLL_END: | 106 case ui::ET_GESTURE_SCROLL_END: |
97 case ui::ET_SCROLL_FLING_START: | 107 case ui::ET_SCROLL_FLING_START: |
98 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); | 108 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); |
99 event->SetHandled(); | 109 event->SetHandled(); |
100 return; | 110 return; |
111 case ui::ET_GESTURE_TAP_DOWN: | |
112 if (touch_feedback_enabled_) | |
113 SetDrawBackgroundAsActive(true); | |
114 ImageButton::OnGestureEvent(event); | |
115 break; | |
116 case ui::ET_GESTURE_TAP_CANCEL: | |
117 case ui::ET_GESTURE_TAP: | |
118 if (touch_feedback_enabled_) | |
119 SetDrawBackgroundAsActive(false); | |
120 ImageButton::OnGestureEvent(event); | |
121 break; | |
101 default: | 122 default: |
102 ImageButton::OnGestureEvent(event); | 123 ImageButton::OnGestureEvent(event); |
103 return; | 124 return; |
104 } | 125 } |
105 } | 126 } |
106 | 127 |
107 void AppListButton::OnPaint(gfx::Canvas* canvas) { | 128 void AppListButton::OnPaint(gfx::Canvas* canvas) { |
108 // Call the base class first to paint any background/borders. | 129 // Call the base class first to paint any background/borders. |
109 View::OnPaint(canvas); | 130 View::OnPaint(canvas); |
110 | 131 |
111 int background_image_id = 0; | 132 int background_image_id = 0; |
112 if (Shell::GetInstance()->GetAppListTargetVisibility()) { | 133 if (Shell::GetInstance()->GetAppListTargetVisibility() || |
134 draw_background_as_active_) { | |
113 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 135 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
114 } else { | 136 } else { |
115 if (shelf_widget_->GetDimsShelf()) | 137 if (shelf_widget_->GetDimsShelf()) |
116 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 138 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
117 else | 139 else |
118 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 140 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
119 } | 141 } |
120 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 142 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
121 const gfx::ImageSkia* background_image = | 143 const gfx::ImageSkia* background_image = |
122 rb.GetImageNamed(background_image_id).ToImageSkia(); | 144 rb.GetImageNamed(background_image_id).ToImageSkia(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 forground_bounds.y()); | 181 forground_bounds.y()); |
160 | 182 |
161 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | 183 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
162 } | 184 } |
163 | 185 |
164 void AppListButton::GetAccessibleState(ui::AXViewState* state) { | 186 void AppListButton::GetAccessibleState(ui::AXViewState* state) { |
165 state->role = ui::AX_ROLE_BUTTON; | 187 state->role = ui::AX_ROLE_BUTTON; |
166 state->name = host_->GetAccessibleName(this); | 188 state->name = host_->GetAccessibleName(this); |
167 } | 189 } |
168 | 190 |
191 void AppListButton::SetDrawBackgroundAsActive( | |
192 bool draw_background_as_active) { | |
193 if (draw_background_as_active_ == draw_background_as_active) | |
194 return; | |
195 draw_background_as_active_ = draw_background_as_active; | |
196 SchedulePaint(); | |
197 } | |
198 | |
169 } // namespace ash | 199 } // namespace ash |
OLD | NEW |