Chromium Code Reviews| 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 } | |
| 42 SetAccessibleName( | 47 SetAccessibleName( |
| 43 app_list::switches::IsExperimentalAppListEnabled() | 48 app_list::switches::IsExperimentalAppListEnabled() |
| 44 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) | 49 ? l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE) |
| 45 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); | 50 : l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_TITLE)); |
| 46 SetSize( | 51 SetSize( |
| 47 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE))); | 52 gfx::Size(GetShelfConstant(SHELF_SIZE), GetShelfConstant(SHELF_SIZE))); |
| 48 SetFocusPainter(views::Painter::CreateSolidFocusPainter( | 53 SetFocusPainter(views::Painter::CreateSolidFocusPainter( |
| 49 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); | 54 kFocusBorderColor, gfx::Insets(1, 1, 1, 1))); |
| 50 set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 55 set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
| 51 } | 56 } |
| 52 | 57 |
| 53 AppListButton::~AppListButton() {} | 58 AppListButton::~AppListButton() {} |
| 54 | 59 |
| 60 void AppListButton::OnAppListShown() { | |
| 61 AnimateInkDrop(views::InkDropState::ACTIVATED); | |
| 62 } | |
| 63 | |
| 64 void AppListButton::OnAppListDismissed() { | |
| 65 AnimateInkDrop(views::InkDropState::DEACTIVATED); | |
| 66 } | |
| 67 | |
| 55 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { | 68 bool AppListButton::OnMousePressed(const ui::MouseEvent& event) { |
| 56 ImageButton::OnMousePressed(event); | 69 ImageButton::OnMousePressed(event); |
| 57 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); | 70 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event); |
| 58 return true; | 71 return true; |
| 59 } | 72 } |
| 60 | 73 |
| 61 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { | 74 void AppListButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 62 ImageButton::OnMouseReleased(event); | 75 ImageButton::OnMouseReleased(event); |
| 63 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); | 76 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false); |
| 64 } | 77 } |
| 65 | 78 |
| 66 void AppListButton::OnMouseCaptureLost() { | 79 void AppListButton::OnMouseCaptureLost() { |
| 67 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); | 80 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true); |
| 68 ImageButton::OnMouseCaptureLost(); | 81 ImageButton::OnMouseCaptureLost(); |
| 69 } | 82 } |
| 70 | 83 |
| 71 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { | 84 bool AppListButton::OnMouseDragged(const ui::MouseEvent& event) { |
| 72 ImageButton::OnMouseDragged(event); | 85 ImageButton::OnMouseDragged(event); |
| 73 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); | 86 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event); |
| 74 return true; | 87 return true; |
| 75 } | 88 } |
| 76 | 89 |
| 77 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { | 90 void AppListButton::OnGestureEvent(ui::GestureEvent* event) { |
| 91 bool is_material = ash::MaterialDesignController::IsShelfMaterial(); | |
|
bruthig
2016/06/17 17:58:45
nit: const, same below
mohsen
2016/06/18 06:25:15
Done.
| |
| 92 bool touch_feedback = !is_material && switches::IsTouchFeedbackEnabled(); | |
| 78 switch (event->type()) { | 93 switch (event->type()) { |
| 79 case ui::ET_GESTURE_SCROLL_BEGIN: | 94 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 80 if (switches::IsTouchFeedbackEnabled()) | 95 if (touch_feedback) |
| 81 SetDrawBackgroundAsActive(false); | 96 SetDrawBackgroundAsActive(false); |
| 97 else if (is_material) | |
| 98 AnimateInkDrop(views::InkDropState::HIDDEN); | |
| 82 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); | 99 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event); |
| 83 event->SetHandled(); | 100 event->SetHandled(); |
| 84 return; | 101 return; |
| 85 case ui::ET_GESTURE_SCROLL_UPDATE: | 102 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 86 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); | 103 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event); |
| 87 event->SetHandled(); | 104 event->SetHandled(); |
| 88 return; | 105 return; |
| 89 case ui::ET_GESTURE_SCROLL_END: | 106 case ui::ET_GESTURE_SCROLL_END: |
| 90 case ui::ET_SCROLL_FLING_START: | 107 case ui::ET_SCROLL_FLING_START: |
| 91 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); | 108 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); |
| 92 event->SetHandled(); | 109 event->SetHandled(); |
| 93 return; | 110 return; |
| 94 case ui::ET_GESTURE_TAP_DOWN: | 111 case ui::ET_GESTURE_TAP_DOWN: |
| 95 if (switches::IsTouchFeedbackEnabled()) | 112 if (touch_feedback) |
| 96 SetDrawBackgroundAsActive(true); | 113 SetDrawBackgroundAsActive(true); |
| 114 else if (is_material && !Shell::GetInstance()->IsApplistVisible()) | |
| 115 AnimateInkDrop(views::InkDropState::ACTION_PENDING); | |
| 97 ImageButton::OnGestureEvent(event); | 116 ImageButton::OnGestureEvent(event); |
| 98 break; | 117 break; |
| 99 case ui::ET_GESTURE_TAP_CANCEL: | 118 case ui::ET_GESTURE_TAP_CANCEL: |
| 100 case ui::ET_GESTURE_TAP: | 119 case ui::ET_GESTURE_TAP: |
| 101 if (switches::IsTouchFeedbackEnabled()) | 120 if (touch_feedback) |
| 102 SetDrawBackgroundAsActive(false); | 121 SetDrawBackgroundAsActive(false); |
| 103 ImageButton::OnGestureEvent(event); | 122 ImageButton::OnGestureEvent(event); |
| 123 if (is_material && !Shell::GetInstance()->GetAppListTargetVisibility()) | |
| 124 AnimateInkDrop(views::InkDropState::HIDDEN); | |
|
bruthig
2016/06/17 17:58:45
What's the use case for this? Won't the ripple be
mohsen
2016/06/18 06:25:15
I guess this was needed for when default gesture h
| |
| 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) { |
| 112 // Call the base class first to paint any background/borders. | 133 // Call the base class first to paint any background/borders. |
| 113 View::OnPaint(canvas); | 134 View::OnPaint(canvas); |
| (...skipping 28 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, GetInkDropCenter(), GetInkDropBaseColor()); | |
| 265 ink_drop_ripple->set_activated_shape(views::SquareInkDropRipple::CIRCLE); | |
| 266 return base::WrapUnique(ink_drop_ripple); | |
| 267 } | |
| 268 | |
| 244 void AppListButton::NotifyClick(const ui::Event& event) { | 269 void AppListButton::NotifyClick(const ui::Event& event) { |
| 245 ImageButton::NotifyClick(event); | 270 ImageButton::NotifyClick(event); |
| 246 if (listener_) | 271 if (listener_) |
| 247 listener_->ButtonPressed(this, event, ink_drop()); | 272 listener_->ButtonPressed(this, event, ink_drop()); |
| 248 } | 273 } |
| 249 | 274 |
| 275 bool AppListButton::ShouldEnterPushedState(const ui::Event& event) { | |
| 276 return !Shell::GetInstance()->IsApplistVisible(); | |
| 277 } | |
| 278 | |
| 279 bool AppListButton::ShouldShowInkDropHighlight() const { | |
| 280 return false; | |
| 281 } | |
| 282 | |
| 250 void AppListButton::SetDrawBackgroundAsActive( | 283 void AppListButton::SetDrawBackgroundAsActive( |
| 251 bool draw_background_as_active) { | 284 bool draw_background_as_active) { |
| 252 if (draw_background_as_active_ == draw_background_as_active) | 285 if (draw_background_as_active_ == draw_background_as_active) |
| 253 return; | 286 return; |
| 254 draw_background_as_active_ = draw_background_as_active; | 287 draw_background_as_active_ = draw_background_as_active; |
| 255 SchedulePaint(); | 288 SchedulePaint(); |
| 256 } | 289 } |
| 257 | 290 |
| 258 } // namespace ash | 291 } // namespace ash |
| OLD | NEW |