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