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" |
27 #include "ui/views/widget/widget.h" | |
sky
2012/04/20 15:33:26
Do you really need this include?
Zachary Kuznia
2012/04/23 05:59:23
Done.
| |
26 | 28 |
27 namespace ash { | 29 namespace ash { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 const int kTopBottomPadding = 10; | 33 const int kTopBottomPadding = 10; |
32 const int kIconTitleSpacing = 10; | 34 const int kIconTitleSpacing = 10; |
33 | 35 |
34 const SkColor kTitleColor = SK_ColorWHITE; | 36 const SkColor kTitleColor = SK_ColorWHITE; |
35 | 37 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 | 198 |
197 AddChildView(icon_); | 199 AddChildView(icon_); |
198 AddChildView(title_); | 200 AddChildView(title_); |
199 | 201 |
200 ItemIconChanged(); | 202 ItemIconChanged(); |
201 ItemTitleChanged(); | 203 ItemTitleChanged(); |
202 model_->AddObserver(this); | 204 model_->AddObserver(this); |
203 | 205 |
204 set_context_menu_controller(this); | 206 set_context_menu_controller(this); |
205 set_request_focus_on_press(false); | 207 set_request_focus_on_press(false); |
208 set_focusable(true); | |
206 } | 209 } |
207 | 210 |
208 AppListItemView::~AppListItemView() { | 211 AppListItemView::~AppListItemView() { |
209 model_->RemoveObserver(this); | 212 model_->RemoveObserver(this); |
210 CancelPendingIconOperation(); | 213 CancelPendingIconOperation(); |
211 } | 214 } |
212 | 215 |
213 // static | 216 // static |
214 gfx::Size AppListItemView::GetPreferredSizeForIconSize( | 217 gfx::Size AppListItemView::GetPreferredSizeForIconSize( |
215 const gfx::Size& icon_size) { | 218 const gfx::Size& icon_size) { |
(...skipping 28 matching lines...) Expand all Loading... | |
244 | 247 |
245 icon_size_ = size; | 248 icon_size_ = size; |
246 title_->SetFont(GetTitleFontForIconSize(size)); | 249 title_->SetFont(GetTitleFontForIconSize(size)); |
247 UpdateIcon(); | 250 UpdateIcon(); |
248 } | 251 } |
249 | 252 |
250 void AppListItemView::SetSelected(bool selected) { | 253 void AppListItemView::SetSelected(bool selected) { |
251 if (selected == selected_) | 254 if (selected == selected_) |
252 return; | 255 return; |
253 | 256 |
257 RequestFocus(); | |
254 selected_ = selected; | 258 selected_ = selected; |
255 SchedulePaint(); | 259 SchedulePaint(); |
256 } | 260 } |
257 | 261 |
258 void AppListItemView::UpdateIcon() { | 262 void AppListItemView::UpdateIcon() { |
259 // Skip if |icon_size_| has not been determined. | 263 // Skip if |icon_size_| has not been determined. |
260 if (icon_size_.IsEmpty()) | 264 if (icon_size_.IsEmpty()) |
261 return; | 265 return; |
262 | 266 |
263 SkBitmap icon = model_->icon(); | 267 SkBitmap icon = model_->icon(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 int alpha = SkColorGetA(kHoverAndPushedColor) * | 357 int alpha = SkColorGetA(kHoverAndPushedColor) * |
354 hover_animation_->GetCurrentValue(); | 358 hover_animation_->GetCurrentValue(); |
355 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); | 359 canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha)); |
356 } else if (state() == BS_HOT || state() == BS_PUSHED) { | 360 } else if (state() == BS_HOT || state() == BS_PUSHED) { |
357 canvas->FillRect(rect, kHoverAndPushedColor); | 361 canvas->FillRect(rect, kHoverAndPushedColor); |
358 } else if (selected_) { | 362 } else if (selected_) { |
359 canvas->FillRect(rect, kSelectedColor); | 363 canvas->FillRect(rect, kSelectedColor); |
360 } | 364 } |
361 } | 365 } |
362 | 366 |
367 void AppListItemView::GetAccessibleState(ui::AccessibleViewState* state) { | |
368 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | |
369 state->name = UTF8ToUTF16(model_->title()); | |
370 } | |
371 | |
363 void AppListItemView::ShowContextMenuForView(views::View* source, | 372 void AppListItemView::ShowContextMenuForView(views::View* source, |
364 const gfx::Point& point) { | 373 const gfx::Point& point) { |
365 ui::MenuModel* menu_model = model_->GetContextMenuModel(); | 374 ui::MenuModel* menu_model = model_->GetContextMenuModel(); |
366 if (!menu_model) | 375 if (!menu_model) |
367 return; | 376 return; |
368 | 377 |
369 views::MenuModelAdapter menu_adapter(menu_model); | 378 views::MenuModelAdapter menu_adapter(menu_model); |
370 context_menu_runner_.reset( | 379 context_menu_runner_.reset( |
371 new views::MenuRunner(new views::MenuItemView(&menu_adapter))); | 380 new views::MenuRunner(new views::MenuItemView(&menu_adapter))); |
372 menu_adapter.BuildMenu(context_menu_runner_->GetMenu()); | 381 menu_adapter.BuildMenu(context_menu_runner_->GetMenu()); |
373 if (context_menu_runner_->RunMenuAt( | 382 if (context_menu_runner_->RunMenuAt( |
374 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), | 383 GetWidget(), NULL, gfx::Rect(point, gfx::Size()), |
375 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 384 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
376 views::MenuRunner::MENU_DELETED) | 385 views::MenuRunner::MENU_DELETED) |
377 return; | 386 return; |
378 } | 387 } |
379 | 388 |
380 void AppListItemView::StateChanged() { | 389 void AppListItemView::StateChanged() { |
381 if (state() == BS_HOT || state() == BS_PUSHED) { | 390 if (state() == BS_HOT || state() == BS_PUSHED) { |
382 list_model_view_->SetSelectedItem(this); | 391 list_model_view_->SetSelectedItem(this); |
383 } else { | 392 } else { |
384 list_model_view_->ClearSelectedItem(this); | 393 list_model_view_->ClearSelectedItem(this); |
385 model_->SetHighlighted(false); | 394 model_->SetHighlighted(false); |
386 } | 395 } |
387 } | 396 } |
388 | 397 |
389 } // namespace ash | 398 } // namespace ash |
OLD | NEW |