| 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 "ui/app_list/app_list_item_view.h" | 5 #include "ui/app_list/app_list_item_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/synchronization/cancellation_flag.h" | 11 #include "base/synchronization/cancellation_flag.h" |
| 12 #include "base/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "ui/app_list/app_list_item_model.h" | 14 #include "ui/app_list/app_list_item_model.h" |
| 15 #include "ui/app_list/app_list_model_view.h" | 15 #include "ui/app_list/apps_grid_view.h" |
| 16 #include "ui/app_list/drop_shadow_label.h" | 16 #include "ui/app_list/drop_shadow_label.h" |
| 17 #include "ui/app_list/icon_cache.h" | 17 #include "ui/app_list/icon_cache.h" |
| 18 #include "ui/base/accessibility/accessible_view_state.h" | 18 #include "ui/base/accessibility/accessible_view_state.h" |
| 19 #include "ui/base/animation/throb_animation.h" | 19 #include "ui/base/animation/throb_animation.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/font.h" | 22 #include "ui/gfx/font.h" |
| 23 #include "ui/gfx/shadow_value.h" | 23 #include "ui/gfx/shadow_value.h" |
| 24 #include "ui/gfx/skbitmap_operations.h" | 24 #include "ui/gfx/skbitmap_operations.h" |
| 25 #include "ui/views/controls/image_view.h" | 25 #include "ui/views/controls/image_view.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 friend class base::RefCountedThreadSafe<AppListItemView::IconOperation>; | 173 friend class base::RefCountedThreadSafe<AppListItemView::IconOperation>; |
| 174 | 174 |
| 175 base::CancellationFlag cancel_flag_; | 175 base::CancellationFlag cancel_flag_; |
| 176 | 176 |
| 177 SkBitmap bitmap_; | 177 SkBitmap bitmap_; |
| 178 const gfx::Size size_; | 178 const gfx::Size size_; |
| 179 | 179 |
| 180 DISALLOW_COPY_AND_ASSIGN(IconOperation); | 180 DISALLOW_COPY_AND_ASSIGN(IconOperation); |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 AppListItemView::AppListItemView(AppListModelView* list_model_view, | 183 AppListItemView::AppListItemView(AppsGridView* list_model_view, |
| 184 AppListItemModel* model, | 184 AppListItemModel* model, |
| 185 views::ButtonListener* listener) | 185 views::ButtonListener* listener) |
| 186 : CustomButton(listener), | 186 : CustomButton(listener), |
| 187 model_(model), | 187 model_(model), |
| 188 list_model_view_(list_model_view), | 188 list_model_view_(list_model_view), |
| 189 icon_(new StaticImageView), | 189 icon_(new StaticImageView), |
| 190 title_(new DropShadowLabel), | 190 title_(new DropShadowLabel), |
| 191 selected_(false), | 191 selected_(false), |
| 192 ALLOW_THIS_IN_INITIALIZER_LIST(apply_shadow_factory_(this)) { | 192 ALLOW_THIS_IN_INITIALIZER_LIST(apply_shadow_factory_(this)) { |
| 193 title_->SetBackgroundColor(0); | 193 title_->SetBackgroundColor(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 207 | 207 |
| 208 AddChildView(icon_); | 208 AddChildView(icon_); |
| 209 AddChildView(title_); | 209 AddChildView(title_); |
| 210 | 210 |
| 211 ItemIconChanged(); | 211 ItemIconChanged(); |
| 212 ItemTitleChanged(); | 212 ItemTitleChanged(); |
| 213 model_->AddObserver(this); | 213 model_->AddObserver(this); |
| 214 | 214 |
| 215 set_context_menu_controller(this); | 215 set_context_menu_controller(this); |
| 216 set_request_focus_on_press(false); | 216 set_request_focus_on_press(false); |
| 217 set_focusable(true); | 217 |
| 218 // Don't take focus for v2 so that focus stays with the search box. |
| 219 if (!list_model_view_->fixed_layout()) |
| 220 set_focusable(true); |
| 218 } | 221 } |
| 219 | 222 |
| 220 AppListItemView::~AppListItemView() { | 223 AppListItemView::~AppListItemView() { |
| 221 model_->RemoveObserver(this); | 224 model_->RemoveObserver(this); |
| 222 CancelPendingIconOperation(); | 225 CancelPendingIconOperation(); |
| 223 } | 226 } |
| 224 | 227 |
| 225 // static | 228 // static |
| 226 gfx::Size AppListItemView::GetPreferredSizeForIconSize( | 229 gfx::Size AppListItemView::GetPreferredSizeForIconSize( |
| 227 const gfx::Size& icon_size) { | 230 const gfx::Size& icon_size) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 icon_size_ = size; | 263 icon_size_ = size; |
| 261 title_->SetFont(GetTitleFontForIconSize(size, | 264 title_->SetFont(GetTitleFontForIconSize(size, |
| 262 list_model_view_->fixed_layout())); | 265 list_model_view_->fixed_layout())); |
| 263 UpdateIcon(); | 266 UpdateIcon(); |
| 264 } | 267 } |
| 265 | 268 |
| 266 void AppListItemView::SetSelected(bool selected) { | 269 void AppListItemView::SetSelected(bool selected) { |
| 267 if (selected == selected_) | 270 if (selected == selected_) |
| 268 return; | 271 return; |
| 269 | 272 |
| 270 RequestFocus(); | 273 if (focusable()) |
| 274 RequestFocus(); |
| 271 selected_ = selected; | 275 selected_ = selected; |
| 272 SchedulePaint(); | 276 SchedulePaint(); |
| 273 } | 277 } |
| 274 | 278 |
| 275 void AppListItemView::UpdateIcon() { | 279 void AppListItemView::UpdateIcon() { |
| 276 // Skip if |icon_size_| has not been determined. | 280 // Skip if |icon_size_| has not been determined. |
| 277 if (icon_size_.IsEmpty()) | 281 if (icon_size_.IsEmpty()) |
| 278 return; | 282 return; |
| 279 | 283 |
| 280 SkBitmap icon = model_->icon(); | 284 SkBitmap icon = model_->icon(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 void AppListItemView::StateChanged() { | 407 void AppListItemView::StateChanged() { |
| 404 if (state() == BS_HOT || state() == BS_PUSHED) { | 408 if (state() == BS_HOT || state() == BS_PUSHED) { |
| 405 list_model_view_->SetSelectedItem(this); | 409 list_model_view_->SetSelectedItem(this); |
| 406 } else { | 410 } else { |
| 407 list_model_view_->ClearSelectedItem(this); | 411 list_model_view_->ClearSelectedItem(this); |
| 408 model_->SetHighlighted(false); | 412 model_->SetHighlighted(false); |
| 409 } | 413 } |
| 410 } | 414 } |
| 411 | 415 |
| 412 } // namespace app_list | 416 } // namespace app_list |
| OLD | NEW |