| 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/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/shelf/shelf_item_types.h" | 9 #include "ash/common/shelf/shelf_item_types.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" | 11 #include "ash/shelf/shelf_view.h" |
| 11 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "grit/ash_resources.h" | 15 #include "grit/ash_resources.h" |
| 15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
| 16 #include "ui/accessibility/ax_view_state.h" | 17 #include "ui/accessibility/ax_view_state.h" |
| 17 #include "ui/app_list/app_list_switches.h" | 18 #include "ui/app_list/app_list_switches.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/base/ui_base_switches_util.h" | 21 #include "ui/base/ui_base_switches_util.h" |
| 21 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/gfx/vector_icons_public.h" |
| 22 #include "ui/views/painter.h" | 25 #include "ui/views/painter.h" |
| 23 | 26 |
| 24 namespace ash { | 27 namespace ash { |
| 25 | 28 |
| 26 AppListButton::AppListButton(ShelfView* shelf_view) | 29 AppListButton::AppListButton(ShelfView* shelf_view) |
| 27 : views::ImageButton(shelf_view), | 30 : views::ImageButton(shelf_view), |
| 28 draw_background_as_active_(false), | 31 draw_background_as_active_(false), |
| 29 shelf_view_(shelf_view) { | 32 shelf_view_(shelf_view) { |
| 30 SetAccessibleName( | 33 SetAccessibleName( |
| 31 app_list::switches::IsExperimentalAppListEnabled() | 34 app_list::switches::IsExperimentalAppListEnabled() |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 int background_image_id = 0; | 105 int background_image_id = 0; |
| 103 if (Shell::GetInstance()->GetAppListTargetVisibility() || | 106 if (Shell::GetInstance()->GetAppListTargetVisibility() || |
| 104 draw_background_as_active_) { | 107 draw_background_as_active_) { |
| 105 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 108 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 106 } else { | 109 } else { |
| 107 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) | 110 if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) |
| 108 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 111 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 109 else | 112 else |
| 110 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 113 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 111 } | 114 } |
| 115 |
| 112 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 116 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 113 const gfx::ImageSkia* background_image = | 117 const gfx::ImageSkia* background_image = |
| 114 rb.GetImageNamed(background_image_id).ToImageSkia(); | 118 rb.GetImageNamed(background_image_id).ToImageSkia(); |
| 115 // TODO(mgiuca): When the "classic" app list is removed, also remove this | 119 const gfx::ImageSkia& foreground_image = |
| 116 // resource and its icon file. | 120 MaterialDesignController::IsShelfMaterial() |
| 117 int foreground_image_id = app_list::switches::IsExperimentalAppListEnabled() | 121 ? CreateVectorIcon(gfx::VectorIconId::SHELF_APPLIST, kShelfIconColor) |
| 118 ? IDR_ASH_SHELF_ICON_APPLIST | 122 : *rb.GetImageNamed(IDR_ASH_SHELF_ICON_APPLIST).ToImageSkia(); |
| 119 : IDR_ASH_SHELF_ICON_APPLIST_CLASSIC; | |
| 120 const gfx::ImageSkia* forground_image = | |
| 121 rb.GetImageNamed(foreground_image_id).ToImageSkia(); | |
| 122 | 123 |
| 123 gfx::Rect contents_bounds = GetContentsBounds(); | 124 gfx::Rect contents_bounds = GetContentsBounds(); |
| 124 gfx::Rect background_bounds, forground_bounds; | 125 gfx::Rect background_bounds, foreground_bounds; |
| 125 | 126 |
| 126 ShelfAlignment alignment = shelf_view_->shelf()->alignment(); | 127 ShelfAlignment alignment = shelf_view_->shelf()->alignment(); |
| 127 background_bounds.set_size(background_image->size()); | 128 background_bounds.set_size(background_image->size()); |
| 128 if (alignment == SHELF_ALIGNMENT_LEFT) { | 129 if (alignment == SHELF_ALIGNMENT_LEFT) { |
| 129 background_bounds.set_x(contents_bounds.width() - | 130 background_bounds.set_x(contents_bounds.width() - |
| 130 ShelfLayoutManager::kShelfItemInset - background_image->width()); | 131 ShelfLayoutManager::kShelfItemInset - background_image->width()); |
| 131 background_bounds.set_y(contents_bounds.y() + | 132 background_bounds.set_y(contents_bounds.y() + |
| 132 (contents_bounds.height() - background_image->height()) / 2); | 133 (contents_bounds.height() - background_image->height()) / 2); |
| 133 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | 134 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { |
| 134 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); | 135 background_bounds.set_x(ShelfLayoutManager::kShelfItemInset); |
| 135 background_bounds.set_y(contents_bounds.y() + | 136 background_bounds.set_y(contents_bounds.y() + |
| 136 (contents_bounds.height() - background_image->height()) / 2); | 137 (contents_bounds.height() - background_image->height()) / 2); |
| 137 } else { | 138 } else { |
| 138 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); | 139 background_bounds.set_y(ShelfLayoutManager::kShelfItemInset); |
| 139 background_bounds.set_x(contents_bounds.x() + | 140 background_bounds.set_x(contents_bounds.x() + |
| 140 (contents_bounds.width() - background_image->width()) / 2); | 141 (contents_bounds.width() - background_image->width()) / 2); |
| 141 } | 142 } |
| 142 | 143 |
| 143 forground_bounds.set_size(forground_image->size()); | 144 foreground_bounds.set_size(foreground_image.size()); |
| 144 forground_bounds.set_x(background_bounds.x() + | 145 |
| 146 foreground_bounds.set_x(background_bounds.x() + |
| 145 std::max(0, | 147 std::max(0, |
| 146 (background_bounds.width() - forground_bounds.width()) / 2)); | 148 (background_bounds.width() - foreground_bounds.width()) / 2)); |
| 147 forground_bounds.set_y(background_bounds.y() + | 149 foreground_bounds.set_y(background_bounds.y() + |
| 148 std::max(0, | 150 std::max(0, |
| 149 (background_bounds.height() - forground_bounds.height()) / 2)); | 151 (background_bounds.height() - foreground_bounds.height()) / 2)); |
| 150 | 152 |
| 151 canvas->DrawImageInt(*background_image, | 153 canvas->DrawImageInt(*background_image, |
| 152 background_bounds.x(), | 154 background_bounds.x(), |
| 153 background_bounds.y()); | 155 background_bounds.y()); |
| 154 canvas->DrawImageInt(*forground_image, | 156 canvas->DrawImageInt(foreground_image, |
| 155 forground_bounds.x(), | 157 foreground_bounds.x(), |
| 156 forground_bounds.y()); | 158 foreground_bounds.y()); |
| 157 | 159 |
| 158 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); | 160 views::Painter::PaintFocusPainter(this, canvas, focus_painter()); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void AppListButton::GetAccessibleState(ui::AXViewState* state) { | 163 void AppListButton::GetAccessibleState(ui::AXViewState* state) { |
| 162 state->role = ui::AX_ROLE_BUTTON; | 164 state->role = ui::AX_ROLE_BUTTON; |
| 163 state->name = shelf_view_->GetTitleForView(this); | 165 state->name = shelf_view_->GetTitleForView(this); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void AppListButton::SetDrawBackgroundAsActive( | 168 void AppListButton::SetDrawBackgroundAsActive( |
| 167 bool draw_background_as_active) { | 169 bool draw_background_as_active) { |
| 168 if (draw_background_as_active_ == draw_background_as_active) | 170 if (draw_background_as_active_ == draw_background_as_active) |
| 169 return; | 171 return; |
| 170 draw_background_as_active_ = draw_background_as_active; | 172 draw_background_as_active_ = draw_background_as_active; |
| 171 SchedulePaint(); | 173 SchedulePaint(); |
| 172 } | 174 } |
| 173 | 175 |
| 174 } // namespace ash | 176 } // namespace ash |
| OLD | NEW |