| 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/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/shelf/shelf_constants.h" | 9 #include "ash/common/shelf/shelf_constants.h" |
| 10 #include "ash/common/shelf/shelf_item_types.h" | 10 #include "ash/common/shelf/shelf_item_types.h" |
| 11 #include "ash/common/shelf/shelf_types.h" | 11 #include "ash/common/shelf/shelf_types.h" |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
| 13 #include "ash/shelf/ink_drop_button_listener.h" | 13 #include "ash/shelf/ink_drop_button_listener.h" |
| 14 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
| 15 #include "ash/shelf/shelf_view.h" | 15 #include "ash/shelf/shelf_view.h" |
| 16 #include "ash/shelf/shelf_widget.h" | 16 #include "ash/shelf/shelf_widget.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "grit/ash_resources.h" | 19 #include "grit/ash_resources.h" |
| 20 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/app_list/app_list_switches.h" | 22 #include "ui/app_list/app_list_switches.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/base/ui_base_switches_util.h" | 25 #include "ui/base/ui_base_switches_util.h" |
| 26 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
| 28 #include "ui/gfx/vector_icons_public.h" | 28 #include "ui/gfx/vector_icons_public.h" |
| 29 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 29 #include "ui/views/painter.h" | 30 #include "ui/views/painter.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 AppListButton::AppListButton(InkDropButtonListener* listener, | 34 AppListButton::AppListButton(InkDropButtonListener* listener, |
| 34 ShelfView* shelf_view) | 35 ShelfView* shelf_view) |
| 35 : views::ImageButton(nullptr), | 36 : views::ImageButton(nullptr), |
| 36 draw_background_as_active_(false), | 37 draw_background_as_active_(false), |
| 37 listener_(listener), | 38 listener_(listener), |
| 38 shelf_view_(shelf_view) { | 39 shelf_view_(shelf_view) { |
| 40 if (ash::MaterialDesignController::IsShelfMaterial()) { |
| 41 SetInkDropMode(INK_DROP_WITHOUT_GESTURE_HANDLING); |
| 42 set_ink_drop_base_color(kShelfInkDropBaseColor); |
| 43 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
| 44 } |
| 39 SetAccessibleName( | 45 SetAccessibleName( |
| 40 app_list::switches::IsExperimentalAppListEnabled() | 46 app_list::switches::IsExperimentalAppListEnabled() |
| 41 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) | 47 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) |
| 42 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); | 48 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); |
| 43 SetSize( | 49 SetSize( |
| 44 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE))); | 50 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE))); |
| 45 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 51 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
| 46 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 52 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
| 47 set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 53 set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 48 } | 54 } |
| 49 | 55 |
| 50 AppListButton::~AppListButton() {} | 56 AppListButton::~AppListButton() {} |
| 51 | 57 |
| 58 void AppListButton::OnAppListShown() { |
| 59 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); |
| 60 } |
| 61 |
| 62 void AppListButton::OnAppListDismissed() { |
| 63 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); |
| 64 } |
| 65 |
| 52 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { | 66 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
| 53 ImageButton::OnMousePressed(event); | 67 ImageButton::OnMousePressed(event); |
| 54 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); | 68 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); |
| 55 return true; | 69 return true; |
| 56 } | 70 } |
| 57 | 71 |
| 58 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { | 72 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 59 ImageButton::OnMouseReleased(event); | 73 ImageButton::OnMouseReleased(event); |
| 60 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); | 74 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); |
| 61 } | 75 } |
| 62 | 76 |
| 63 void AppListButton::OnMouseCaptureLost() { | 77 void AppListButton::OnMouseCaptureLost() { |
| 64 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); | 78 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); |
| 65 ImageButton::OnMouseCaptureLost(); | 79 ImageButton::OnMouseCaptureLost(); |
| 66 } | 80 } |
| 67 | 81 |
| 68 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { | 82 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 69 ImageButton::OnMouseDragged(event); | 83 ImageButton::OnMouseDragged(event); |
| 70 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); | 84 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); |
| 71 return true; | 85 return true; |
| 72 } | 86 } |
| 73 | 87 |
| 74 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { | 88 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
| 89 const bool is_material = ash::MaterialDesignController::IsShelfMaterial(); |
| 90 const bool touch_feedback = |
| 91 !is_material && switches::IsTouchFeedbackEnabled(); |
| 75 switch (event->type()) { | 92 switch (event->type()) { |
| 76 case ui::ET_GESTURE_SCROLL_BEGIN: | 93 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 77 if (switches::IsTouchFeedbackEnabled()) | 94 if (touch_feedback) |
| 78 SetDrawBackgroundAsActive(false); | 95 SetDrawBackgroundAsActive(false); |
| 96 else if (is_material) |
| 97 AnimateInkDrop(views::InkDropState::HIDDEN, event); |
| 79 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); | 98 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); |
| 80 event->SetHandled(); | 99 event->SetHandled(); |
| 81 return; | 100 return; |
| 82 case ui::ET_GESTURE_SCROLL_UPDATE: | 101 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 83 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); | 102 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); |
| 84 event->SetHandled(); | 103 event->SetHandled(); |
| 85 return; | 104 return; |
| 86 case ui::ET_GESTURE_SCROLL_END: | 105 case ui::ET_GESTURE_SCROLL_END: |
| 87 case ui::ET_SCROLL_FLING_START: | 106 case ui::ET_SCROLL_FLING_START: |
| 88 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); | 107 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); |
| 89 event->SetHandled(); | 108 event->SetHandled(); |
| 90 return; | 109 return; |
| 91 case ui::ET_GESTURE_TAP_DOWN: | 110 case ui::ET_GESTURE_TAP_DOWN: |
| 92 if (switches::IsTouchFeedbackEnabled()) | 111 if (touch_feedback) |
| 93 SetDrawBackgroundAsActive(true); | 112 SetDrawBackgroundAsActive(true); |
| 113 else if (is_material && !Shell::GetInstance()->IsApplistVisible()) |
| 114 AnimateInkDrop(views::InkDropState::ACTION_PENDING, event); |
| 94 ImageButton::OnGestureEvent(event); | 115 ImageButton::OnGestureEvent(event); |
| 95 break; | 116 break; |
| 96 case ui::ET_GESTURE_TAP_CANCEL: | 117 case ui::ET_GESTURE_TAP_CANCEL: |
| 97 case ui::ET_GESTURE_TAP: | 118 case ui::ET_GESTURE_TAP: |
| 98 if (switches::IsTouchFeedbackEnabled()) | 119 if (touch_feedback) |
| 99 SetDrawBackgroundAsActive(false); | 120 SetDrawBackgroundAsActive(false); |
| 100 ImageButton::OnGestureEvent(event); | 121 ImageButton::OnGestureEvent(event); |
| 101 break; | 122 break; |
| 102 default: | 123 default: |
| 103 ImageButton::OnGestureEvent(event); | 124 ImageButton::OnGestureEvent(event); |
| 104 return; | 125 return; |
| 105 } | 126 } |
| 106 } | 127 } |
| 107 | 128 |
| 108 void AppListButton::OnPaint(gfx::Canvas* canvas) { | 129 void AppListButton::OnPaint(gfx::Canvas* canvas) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 136 shelf_widget->GetBackgroundType() == | 157 shelf_widget->GetBackgroundType() == |
| 137 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { | 158 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
| 138 background_paint.setColor( | 159 background_paint.setColor( |
| 139 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA))); | 160 SkColorSetA(kShelfBaseColor, GetShelfConstant(SHELF_BACKGROUND_ALPHA))); |
| 140 } | 161 } |
| 141 | 162 |
| 142 // Paint the circular background of AppList button. | 163 // Paint the circular background of AppList button. |
| 143 gfx::Point circle_center = GetContentsBounds().CenterPoint(); | 164 gfx::Point circle_center = GetContentsBounds().CenterPoint(); |
| 144 if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment())) | 165 if (!IsHorizontalAlignment(shelf_view_->shelf()->alignment())) |
| 145 circle_center = gfx::Point(circle_center.y(), circle_center.x()); | 166 circle_center = gfx::Point(circle_center.y(), circle_center.x()); |
| 167 |
| 146 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint); | 168 canvas->DrawCircle(circle_center, kAppListButtonRadius, background_paint); |
| 147 | |
| 148 if (Shell::GetInstance()->GetAppListTargetVisibility() || | |
| 149 draw_background_as_active_) { | |
| 150 SkPaint highlight_paint; | |
| 151 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | |
| 152 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 153 highlight_paint.setStyle(SkPaint::kFill_Style); | |
| 154 canvas->DrawCircle(circle_center, kAppListButtonRadius, highlight_paint); | |
| 155 } | |
| 156 } | 169 } |
| 157 | 170 |
| 158 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, | 171 void AppListButton::PaintForegroundMD(gfx::Canvas* canvas, |
| 159 const gfx::ImageSkia& foreground_image) { | 172 const gfx::ImageSkia& foreground_image) { |
| 160 gfx::Rect foreground_bounds(foreground_image.size()); | 173 gfx::Rect foreground_bounds(foreground_image.size()); |
| 161 gfx::Rect contents_bounds = GetContentsBounds(); | 174 gfx::Rect contents_bounds = GetContentsBounds(); |
| 162 | 175 |
| 163 if (IsHorizontalAlignment(shelf_view_->shelf()->alignment())) { | 176 if (IsHorizontalAlignment(shelf_view_->shelf()->alignment())) { |
| 164 foreground_bounds.set_x( | 177 foreground_bounds.set_x( |
| 165 (contents_bounds.width() - foreground_bounds.width()) / 2); | 178 (contents_bounds.width() - foreground_bounds.width()) / 2); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 (background_bounds.height() - foreground_bounds.height()) / 2)); | 240 (background_bounds.height() - foreground_bounds.height()) / 2)); |
| 228 canvas->DrawImageInt(foreground_image, foreground_bounds.x(), | 241 canvas->DrawImageInt(foreground_image, foreground_bounds.x(), |
| 229 foreground_bounds.y()); | 242 foreground_bounds.y()); |
| 230 } | 243 } |
| 231 | 244 |
| 232 void AppListButton::GetAccessibleState(ui::AXViewState* state) { | 245 void AppListButton::GetAccessibleState(ui::AXViewState* state) { |
| 233 state->role = ui::AX_ROLE_BUTTON; | 246 state->role = ui::AX_ROLE_BUTTON; |
| 234 state->name = shelf_view_->GetTitleForView(this); | 247 state->name = shelf_view_->GetTitleForView(this); |
| 235 } | 248 } |
| 236 | 249 |
| 250 std::unique_ptr<views::InkDropRipple> AppListButton::CreateInkDropRipple() |
| 251 const { |
| 252 // TODO(mohsen): A circular SquareInkDropRipple is created with equal small |
| 253 // and large sizes to mimic a circular flood fill. Replace with an actual |
| 254 // flood fill when circular flood fills are implemented. |
| 255 gfx::Size ripple_size(2 * kAppListButtonRadius, 2 * kAppListButtonRadius); |
| 256 auto ink_drop_ripple = new views::SquareInkDropRipple( |
| 257 ripple_size, 0, ripple_size, 0, GetContentsBounds().CenterPoint(), |
| 258 GetInkDropBaseColor(), ink_drop_visible_opacity()); |
| 259 ink_drop_ripple->set_activated_shape(views::SquareInkDropRipple::CIRCLE); |
| 260 return base::WrapUnique(ink_drop_ripple); |
| 261 } |
| 262 |
| 237 void AppListButton::NotifyClick(const ui::Event& event) { | 263 void AppListButton::NotifyClick(const ui::Event& event) { |
| 238 ImageButton::NotifyClick(event); | 264 ImageButton::NotifyClick(event); |
| 239 if (listener_) | 265 if (listener_) |
| 240 listener_->ButtonPressed(this, event, ink_drop()); | 266 listener_->ButtonPressed(this, event, ink_drop()); |
| 241 } | 267 } |
| 242 | 268 |
| 269 bool AppListButton::ShouldEnterPushedState(const ui::Event& event) { |
| 270 return !Shell::GetInstance()->IsApplistVisible(); |
| 271 } |
| 272 |
| 273 bool AppListButton::ShouldShowInkDropHighlight() const { |
| 274 return false; |
| 275 } |
| 276 |
| 243 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { | 277 void AppListButton::SetDrawBackgroundAsActive(bool draw_background_as_active) { |
| 244 if (draw_background_as_active_ == draw_background_as_active) | 278 if (draw_background_as_active_ == draw_background_as_active) |
| 245 return; | 279 return; |
| 246 draw_background_as_active_ = draw_background_as_active; | 280 draw_background_as_active_ = draw_background_as_active; |
| 247 SchedulePaint(); | 281 SchedulePaint(); |
| 248 } | 282 } |
| 249 | 283 |
| 250 } // namespace ash | 284 } // namespace ash |
| OLD | NEW |