OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_list/app_list_item_view.h" | 5 #include "ash/app_list/app_list_item_view.h" |
6 | 6 |
7 #include "ash/app_list/app_list_item_model.h" | 7 #include "ash/app_list/app_list_item_model.h" |
8 #include "ash/app_list/app_list_model_view.h" | 8 #include "ash/app_list/app_list_model_view.h" |
9 #include "ash/app_list/drop_shadow_label.h" | 9 #include "ash/app_list/drop_shadow_label.h" |
10 #include "ash/app_list/icon_cache.h" | 10 #include "ash/app_list/icon_cache.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/synchronization/cancellation_flag.h" | 13 #include "base/synchronization/cancellation_flag.h" |
14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "ui/base/accessibility/accessible_view_state.h" |
16 #include "ui/base/animation/throb_animation.h" | 17 #include "ui/base/animation/throb_animation.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/font.h" | 20 #include "ui/gfx/font.h" |
20 #include "ui/gfx/shadow_value.h" | 21 #include "ui/gfx/shadow_value.h" |
21 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
22 #include "ui/views/controls/image_view.h" | 23 #include "ui/views/controls/image_view.h" |
23 #include "ui/views/controls/menu/menu_item_view.h" | 24 #include "ui/views/controls/menu/menu_item_view.h" |
24 #include "ui/views/controls/menu/menu_model_adapter.h" | 25 #include "ui/views/controls/menu/menu_model_adapter.h" |
25 #include "ui/views/controls/menu/menu_runner.h" | 26 #include "ui/views/controls/menu/menu_runner.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 | 197 |
197 AddChildView(icon_); | 198 AddChildView(icon_); |
198 AddChildView(title_); | 199 AddChildView(title_); |
199 | 200 |
200 ItemIconChanged(); | 201 ItemIconChanged(); |
201 ItemTitleChanged(); | 202 ItemTitleChanged(); |
202 model_->AddObserver(this); | 203 model_->AddObserver(this); |
203 | 204 |
204 set_context_menu_controller(this); | 205 set_context_menu_controller(this); |
205 set_request_focus_on_press(false); | 206 set_request_focus_on_press(false); |
| 207 set_focusable(true); |
206 } | 208 } |
207 | 209 |
208 AppListItemView::~AppListItemView() { | 210 AppListItemView::~AppListItemView() { |
209 model_->RemoveObserver(this); | 211 model_->RemoveObserver(this); |
210 CancelPendingIconOperation(); | 212 CancelPendingIconOperation(); |
211 } | 213 } |
212 | 214 |
213 // static | 215 // static |
214 gfx::Size AppListItemView::GetPreferredSizeForIconSize( | 216 gfx::Size AppListItemView::GetPreferredSizeForIconSize( |
215 const gfx::Size& icon_size) { | 217 const gfx::Size& icon_size) { |
(...skipping 28 matching lines...) Expand all Loading... |
244 | 246 |
245 icon_size_ = size; | 247 icon_size_ = size; |
246 title_->SetFont(GetTitleFontForIconSize(size)); | 248 title_->SetFont(GetTitleFontForIconSize(size)); |
247 UpdateIcon(); | 249 UpdateIcon(); |
248 } | 250 } |
249 | 251 |
250 void AppListItemView::SetSelected(bool selected) { | 252 void AppListItemView::SetSelected(bool selected) { |
251 if (selected == selected_) | 253 if (selected == selected_) |
252 return; | 254 return; |
253 | 255 |
| 256 RequestFocus(); |
254 selected_ = selected; | 257 selected_ = selected; |
255 SchedulePaint(); | 258 SchedulePaint(); |
256 } | 259 } |
257 | 260 |
258 void AppListItemView::UpdateIcon() { | 261 void AppListItemView::UpdateIcon() { |
259 // Skip if |icon_size_| has not been determined. | 262 // Skip if |icon_size_| has not been determined. |
260 if (icon_size_.IsEmpty()) | 263 if (icon_size_.IsEmpty()) |
261 return; | 264 return; |
262 | 265 |
263 SkBitmap icon = model_->icon(); | 266 SkBitmap icon = model_->icon(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 int alpha = SkColorGetA(kHoverAndPushedColor) * | 356 int alpha = SkColorGetA(kHoverAndPushedColor) * |
354 hover_animation_->GetCurrentValue(); | 357 hover_animation_->GetCurrentValue(); |
355 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); | 358 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); |
356 } else if (state() == BS_HOT || state() == BS_PUSHED) { | 359 } else if (state() == BS_HOT || state() == BS_PUSHED) { |
357 canvas->FillRect(rect, kHoverAndPushedColor); | 360 canvas->FillRect(rect, kHoverAndPushedColor); |
358 } else if (selected_) { | 361 } else if (selected_) { |
359 canvas->FillRect(rect, kSelectedColor); | 362 canvas->FillRect(rect, kSelectedColor); |
360 } | 363 } |
361 } | 364 } |
362 | 365 |
| 366 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 367 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 368 state->name = UTF8ToUTF16(model_->title()); |
| 369 } |
| 370 |
363 void AppListItemView::ShowContextMenuForView(views::View* source, | 371 void AppListItemView::ShowContextMenuForView(views::View* source, |
364 const gfx::Point& point) { | 372 const gfx::Point& point) { |
365 ui::MenuModel* menu_model = model_->GetContextMenuModel(); | 373 ui::MenuModel* menu_model = model_->GetContextMenuModel(); |
366 if (!menu_model) | 374 if (!menu_model) |
367 return; | 375 return; |
368 | 376 |
369 views::MenuModelAdapter menu_adapter(menu_model); | 377 views::MenuModelAdapter menu_adapter(menu_model); |
370 context_menu_runner_.reset( | 378 context_menu_runner_.reset( |
371 new views::MenuRunner(new views::MenuItemView(&menu_adapter))); | 379 new views::MenuRunner(new views::MenuItemView(&menu_adapter))); |
372 menu_adapter.BuildMenu(context_menu_runner_->GetMenu()); | 380 menu_adapter.BuildMenu(context_menu_runner_->GetMenu()); |
373 if (context_menu_runner_->RunMenuAt( | 381 if (context_menu_runner_->RunMenuAt( |
374 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 382 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
375 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 383 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
376 views::MenuRunner::MENU_DELETED) | 384 views::MenuRunner::MENU_DELETED) |
377 return; | 385 return; |
378 } | 386 } |
379 | 387 |
380 void AppListItemView::StateChanged() { | 388 void AppListItemView::StateChanged() { |
381 if (state() == BS_HOT || state() == BS_PUSHED) { | 389 if (state() == BS_HOT || state() == BS_PUSHED) { |
382 list_model_view_->SetSelectedItem(this); | 390 list_model_view_->SetSelectedItem(this); |
383 } else { | 391 } else { |
384 list_model_view_->ClearSelectedItem(this); | 392 list_model_view_->ClearSelectedItem(this); |
385 model_->SetHighlighted(false); | 393 model_->SetHighlighted(false); |
386 } | 394 } |
387 } | 395 } |
388 | 396 |
389 } // namespace ash | 397 } // namespace ash |
OLD | NEW |