| 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/views/app_list_item_view.h" | 5 #include "ui/app_list/views/app_list_item_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/app_list/app_list_constants.h" | 12 #include "ui/app_list/app_list_constants.h" |
| 13 #include "ui/app_list/app_list_folder_item.h" | 13 #include "ui/app_list/app_list_folder_item.h" |
| 14 #include "ui/app_list/app_list_item.h" | 14 #include "ui/app_list/app_list_item.h" |
| 15 #include "ui/app_list/views/apps_grid_view.h" | 15 #include "ui/app_list/views/apps_grid_view.h" |
| 16 #include "ui/app_list/views/cached_label.h" | |
| 17 #include "ui/app_list/views/progress_bar_view.h" | 16 #include "ui/app_list/views/progress_bar_view.h" |
| 18 #include "ui/base/dragdrop/drag_utils.h" | 17 #include "ui/base/dragdrop/drag_utils.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" | 21 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 23 #include "ui/gfx/animation/throb_animation.h" | 22 #include "ui/gfx/animation/throb_animation.h" |
| 24 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/font_list.h" | 24 #include "ui/gfx/font_list.h" |
| 26 #include "ui/gfx/image/image_skia_operations.h" | 25 #include "ui/gfx/image/image_skia_operations.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 63 |
| 65 // static | 64 // static |
| 66 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; | 65 const char AppListItemView::kViewClassName[] = "ui/app_list/AppListItemView"; |
| 67 | 66 |
| 68 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, | 67 AppListItemView::AppListItemView(AppsGridView* apps_grid_view, |
| 69 AppListItem* item) | 68 AppListItem* item) |
| 70 : CustomButton(apps_grid_view), | 69 : CustomButton(apps_grid_view), |
| 71 item_(item), | 70 item_(item), |
| 72 apps_grid_view_(apps_grid_view), | 71 apps_grid_view_(apps_grid_view), |
| 73 icon_(new views::ImageView), | 72 icon_(new views::ImageView), |
| 74 title_(new CachedLabel), | 73 title_(new views::Label), |
| 75 progress_bar_(new ProgressBarView), | 74 progress_bar_(new ProgressBarView), |
| 76 ui_state_(UI_STATE_NORMAL), | 75 ui_state_(UI_STATE_NORMAL), |
| 77 touch_dragging_(false) { | 76 touch_dragging_(false) { |
| 78 icon_->set_interactive(false); | 77 icon_->set_interactive(false); |
| 79 | 78 |
| 80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 81 title_->SetBackgroundColor(0); | |
| 82 title_->SetAutoColorReadabilityEnabled(false); | 80 title_->SetAutoColorReadabilityEnabled(false); |
| 83 title_->SetEnabledColor(kGridTitleColor); | 81 title_->SetEnabledColor(kGridTitleColor); |
| 84 title_->SetFontList( | 82 title_->SetFontList( |
| 85 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); | 83 rb.GetFontList(kItemTextFontStyle).DeriveWithSizeDelta(kFontSizeDelta)); |
| 86 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 87 title_->SetVisible(!item_->is_installing()); | 84 title_->SetVisible(!item_->is_installing()); |
| 88 title_->Invalidate(); | |
| 89 SetTitleSubpixelAA(); | |
| 90 | 85 |
| 91 const gfx::ShadowValue kIconShadows[] = { | 86 const gfx::ShadowValue kIconShadows[] = { |
| 92 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), | 87 gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)), |
| 93 }; | 88 }; |
| 94 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); | 89 icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows)); |
| 95 | 90 |
| 96 AddChildView(icon_); | 91 AddChildView(icon_); |
| 97 AddChildView(title_); | 92 AddChildView(title_); |
| 98 AddChildView(progress_bar_); | 93 AddChildView(progress_bar_); |
| 99 | 94 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 layer()->SetTransform(gfx::GetScaleTransform( | 175 layer()->SetTransform(gfx::GetScaleTransform( |
| 181 bounds.CenterPoint(), | 176 bounds.CenterPoint(), |
| 182 kDraggingIconScale)); | 177 kDraggingIconScale)); |
| 183 break; | 178 break; |
| 184 } | 179 } |
| 185 case UI_STATE_DROPPING_IN_FOLDER: | 180 case UI_STATE_DROPPING_IN_FOLDER: |
| 186 break; | 181 break; |
| 187 } | 182 } |
| 188 #endif // !OS_WIN | 183 #endif // !OS_WIN |
| 189 | 184 |
| 190 SchedulePaint(); | 185 Layout(); |
| 191 } | 186 } |
| 192 | 187 |
| 193 void AppListItemView::SetTouchDragging(bool touch_dragging) { | 188 void AppListItemView::SetTouchDragging(bool touch_dragging) { |
| 194 if (touch_dragging_ == touch_dragging) | 189 if (touch_dragging_ == touch_dragging) |
| 195 return; | 190 return; |
| 196 | 191 |
| 197 touch_dragging_ = touch_dragging; | 192 touch_dragging_ = touch_dragging; |
| 198 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); | 193 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); |
| 199 } | 194 } |
| 200 | 195 |
| 201 void AppListItemView::OnMouseDragTimer() { | 196 void AppListItemView::OnMouseDragTimer() { |
| 202 DCHECK(apps_grid_view_->IsDraggedView(this)); | 197 DCHECK(apps_grid_view_->IsDraggedView(this)); |
| 203 SetUIState(UI_STATE_DRAGGING); | 198 SetUIState(UI_STATE_DRAGGING); |
| 204 } | 199 } |
| 205 | 200 |
| 206 void AppListItemView::SetTitleSubpixelAA() { | |
| 207 // TODO(tapted): Enable AA for folders as well, taking care to play nice with | |
| 208 // the folder bubble animation. | |
| 209 bool enable_aa = !item_->IsInFolder() && ui_state_ == UI_STATE_NORMAL && | |
| 210 !item_->highlighted() && | |
| 211 !apps_grid_view_->IsSelectedView(this) && | |
| 212 !apps_grid_view_->IsAnimatingView(this); | |
| 213 | |
| 214 bool currently_enabled = title_->background() != NULL; | |
| 215 if (currently_enabled == enable_aa) | |
| 216 return; | |
| 217 | |
| 218 if (enable_aa) { | |
| 219 title_->SetBackgroundColor(app_list::kContentsBackgroundColor); | |
| 220 title_->set_background(views::Background::CreateSolidBackground( | |
| 221 app_list::kContentsBackgroundColor)); | |
| 222 } else { | |
| 223 // In other cases, keep the background transparent to ensure correct | |
| 224 // interactions with animations. This will temporarily disable subpixel AA. | |
| 225 title_->SetBackgroundColor(0); | |
| 226 title_->set_background(NULL); | |
| 227 } | |
| 228 title_->Invalidate(); | |
| 229 title_->SchedulePaint(); | |
| 230 } | |
| 231 | |
| 232 void AppListItemView::Prerender() { | |
| 233 title_->PaintToBackingImage(); | |
| 234 } | |
| 235 | |
| 236 void AppListItemView::CancelContextMenu() { | 201 void AppListItemView::CancelContextMenu() { |
| 237 if (context_menu_runner_) | 202 if (context_menu_runner_) |
| 238 context_menu_runner_->Cancel(); | 203 context_menu_runner_->Cancel(); |
| 239 } | 204 } |
| 240 | 205 |
| 241 gfx::ImageSkia AppListItemView::GetDragImage() { | 206 gfx::ImageSkia AppListItemView::GetDragImage() { |
| 242 return icon_->GetImage(); | 207 return icon_->GetImage(); |
| 243 } | 208 } |
| 244 | 209 |
| 245 void AppListItemView::OnDragEnded() { | 210 void AppListItemView::OnDragEnded() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 258 else | 223 else |
| 259 SetUIState(UI_STATE_NORMAL); | 224 SetUIState(UI_STATE_NORMAL); |
| 260 } | 225 } |
| 261 | 226 |
| 262 void AppListItemView::ItemIconChanged() { | 227 void AppListItemView::ItemIconChanged() { |
| 263 UpdateIcon(); | 228 UpdateIcon(); |
| 264 } | 229 } |
| 265 | 230 |
| 266 void AppListItemView::ItemNameChanged() { | 231 void AppListItemView::ItemNameChanged() { |
| 267 title_->SetText(base::UTF8ToUTF16(item_->GetDisplayName())); | 232 title_->SetText(base::UTF8ToUTF16(item_->GetDisplayName())); |
| 268 title_->Invalidate(); | |
| 269 UpdateTooltip(); | 233 UpdateTooltip(); |
| 270 // Use full name for accessibility. | 234 // Use full name for accessibility. |
| 271 SetAccessibleName(item_->GetItemType() == AppListFolderItem::kItemType | 235 SetAccessibleName(item_->GetItemType() == AppListFolderItem::kItemType |
| 272 ? l10n_util::GetStringFUTF16( | 236 ? l10n_util::GetStringFUTF16( |
| 273 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, | 237 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, |
| 274 base::UTF8ToUTF16(item_->name())) | 238 base::UTF8ToUTF16(item_->name())) |
| 275 : base::UTF8ToUTF16(item_->name())); | 239 : base::UTF8ToUTF16(item_->name())); |
| 276 Layout(); | 240 Layout(); |
| 277 } | 241 } |
| 278 | 242 |
| 279 void AppListItemView::ItemHighlightedChanged() { | 243 void AppListItemView::ItemHighlightedChanged() { |
| 280 apps_grid_view_->EnsureViewVisible(this); | 244 apps_grid_view_->EnsureViewVisible(this); |
| 281 SchedulePaint(); | 245 Layout(); |
| 282 } | 246 } |
| 283 | 247 |
| 284 void AppListItemView::ItemIsInstallingChanged() { | 248 void AppListItemView::ItemIsInstallingChanged() { |
| 285 if (item_->is_installing()) | 249 if (item_->is_installing()) |
| 286 apps_grid_view_->EnsureViewVisible(this); | 250 apps_grid_view_->EnsureViewVisible(this); |
| 287 title_->SetVisible(!item_->is_installing()); | 251 title_->SetVisible(!item_->is_installing()); |
| 288 progress_bar_->SetVisible(item_->is_installing()); | 252 progress_bar_->SetVisible(item_->is_installing()); |
| 289 SchedulePaint(); | 253 Layout(); |
| 290 } | 254 } |
| 291 | 255 |
| 292 void AppListItemView::ItemPercentDownloadedChanged() { | 256 void AppListItemView::ItemPercentDownloadedChanged() { |
| 293 // A percent_downloaded() of -1 can mean it's not known how much percent is | 257 // A percent_downloaded() of -1 can mean it's not known how much percent is |
| 294 // completed, or the download hasn't been marked complete, as is the case | 258 // completed, or the download hasn't been marked complete, as is the case |
| 295 // while an extension is being installed after being downloaded. | 259 // while an extension is being installed after being downloaded. |
| 296 if (item_->percent_downloaded() == -1) | 260 if (item_->percent_downloaded() == -1) |
| 297 return; | 261 return; |
| 298 progress_bar_->SetValue(item_->percent_downloaded() / 100.0); | 262 progress_bar_->SetValue(item_->percent_downloaded() / 100.0); |
| 299 } | 263 } |
| 300 | 264 |
| 301 const char* AppListItemView::GetClassName() const { | 265 const char* AppListItemView::GetClassName() const { |
| 302 return kViewClassName; | 266 return kViewClassName; |
| 303 } | 267 } |
| 304 | 268 |
| 305 void AppListItemView::Layout() { | 269 void AppListItemView::Layout() { |
| 306 gfx::Rect rect(GetContentsBounds()); | 270 SkColor color = app_list::kContentsBackgroundColor; |
| 307 | 271 if (item_->highlighted() && !item_->is_installing()) |
| 308 const int left_right_padding = | 272 color = kHighlightedColor; |
| 309 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 273 else if (apps_grid_view_->IsSelectedView(this)) |
| 310 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 274 color = kSelectedColor; |
| 311 const int y = rect.y(); | 275 set_background(views::Background::CreateSolidBackground(color)); |
| 312 | 276 |
| 313 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); | 277 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
| 314 const gfx::Size title_size = title_->GetPreferredSize(); | 278 |
| 315 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 279 gfx::Rect rect(icon_->bounds()); |
| 316 y + icon_size_.height() + kIconTitleSpacing, | 280 rect.set_y(icon_->bounds().bottom() + kIconTitleSpacing); |
| 317 title_size.width(), | 281 rect.set_height(title_->GetPreferredSize().height()); |
| 318 title_size.height()); | 282 rect.Intersect(GetContentsBounds()); |
| 319 title_bounds.Intersect(rect); | 283 title_->SetBoundsRect(rect); |
| 320 title_->SetBoundsRect(title_bounds); | 284 title_->SetBackgroundColor(color); |
| 321 | 285 |
| 322 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 286 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
| 323 progress_bar_bounds.set_x(GetContentsBounds().x() + | 287 progress_bar_bounds.set_x(GetContentsBounds().x() + |
| 324 kProgressBarHorizontalPadding); | 288 kProgressBarHorizontalPadding); |
| 325 progress_bar_bounds.set_y(title_bounds.y()); | 289 progress_bar_bounds.set_y(rect.y()); |
| 326 progress_bar_->SetBoundsRect(progress_bar_bounds); | 290 progress_bar_->SetBoundsRect(progress_bar_bounds); |
| 327 } | |
| 328 | 291 |
| 329 void AppListItemView::SchedulePaintInRect(const gfx::Rect& r) { | 292 SchedulePaint(); |
| 330 SetTitleSubpixelAA(); | |
| 331 views::CustomButton::SchedulePaintInRect(r); | |
| 332 } | 293 } |
| 333 | 294 |
| 334 void AppListItemView::OnPaint(gfx::Canvas* canvas) { | 295 void AppListItemView::OnPaint(gfx::Canvas* canvas) { |
| 335 if (apps_grid_view_->IsDraggedView(this)) | 296 CustomButton::OnPaint(canvas); |
| 336 return; | |
| 337 | |
| 338 gfx::Rect rect(GetContentsBounds()); | |
| 339 if (item_->highlighted() && !item_->is_installing()) { | |
| 340 canvas->FillRect(rect, kHighlightedColor); | |
| 341 return; | |
| 342 } | |
| 343 if (apps_grid_view_->IsSelectedView(this)) | |
| 344 canvas->FillRect(rect, kSelectedColor); | |
| 345 | |
| 346 if (ui_state_ == UI_STATE_DROPPING_IN_FOLDER) { | 297 if (ui_state_ == UI_STATE_DROPPING_IN_FOLDER) { |
| 347 DCHECK(apps_grid_view_->model()->folders_enabled()); | 298 DCHECK(apps_grid_view_->model()->folders_enabled()); |
| 348 | 299 |
| 349 // Draw folder dropping preview circle. | 300 // Draw folder dropping preview circle. |
| 350 gfx::Point center = gfx::Point(icon_->x() + icon_->size().width() / 2, | 301 gfx::Point center = gfx::Point(icon_->x() + icon_->size().width() / 2, |
| 351 icon_->y() + icon_->size().height() / 2); | 302 icon_->y() + icon_->size().height() / 2); |
| 352 SkPaint paint; | 303 SkPaint paint; |
| 353 paint.setStyle(SkPaint::kFill_Style); | 304 paint.setStyle(SkPaint::kFill_Style); |
| 354 paint.setAntiAlias(true); | 305 paint.setAntiAlias(true); |
| 355 paint.setColor(kFolderBubbleColor); | 306 paint.setColor(kFolderBubbleColor); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 377 } | 328 } |
| 378 | 329 |
| 379 void AppListItemView::StateChanged() { | 330 void AppListItemView::StateChanged() { |
| 380 const bool is_folder_ui_enabled = apps_grid_view_->model()->folders_enabled(); | 331 const bool is_folder_ui_enabled = apps_grid_view_->model()->folders_enabled(); |
| 381 if (is_folder_ui_enabled) | 332 if (is_folder_ui_enabled) |
| 382 apps_grid_view_->ClearAnySelectedView(); | 333 apps_grid_view_->ClearAnySelectedView(); |
| 383 | 334 |
| 384 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 335 if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
| 385 if (!is_folder_ui_enabled) | 336 if (!is_folder_ui_enabled) |
| 386 apps_grid_view_->SetSelectedView(this); | 337 apps_grid_view_->SetSelectedView(this); |
| 338 item_->SetHighlighted(true); |
| 387 title_->SetEnabledColor(kGridTitleHoverColor); | 339 title_->SetEnabledColor(kGridTitleHoverColor); |
| 388 } else { | 340 } else { |
| 389 if (!is_folder_ui_enabled) | 341 if (!is_folder_ui_enabled) |
| 390 apps_grid_view_->ClearSelectedView(this); | 342 apps_grid_view_->ClearSelectedView(this); |
| 391 item_->SetHighlighted(false); | 343 item_->SetHighlighted(false); |
| 392 title_->SetEnabledColor(kGridTitleColor); | 344 title_->SetEnabledColor(kGridTitleColor); |
| 393 } | 345 } |
| 394 title_->Invalidate(); | 346 Layout(); |
| 395 } | 347 } |
| 396 | 348 |
| 397 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { | 349 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { |
| 398 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray | 350 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray |
| 399 // background does not show up during scroll. | 351 // background does not show up during scroll. |
| 400 if (event.type() == ui::ET_GESTURE_TAP_DOWN) | 352 if (event.type() == ui::ET_GESTURE_TAP_DOWN) |
| 401 return false; | 353 return false; |
| 402 | 354 |
| 403 return views::CustomButton::ShouldEnterPushedState(event); | 355 return views::CustomButton::ShouldEnterPushedState(event); |
| 404 } | 356 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 const int left_right_padding = | 476 const int left_right_padding = |
| 525 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 477 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
| 526 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 478 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
| 527 | 479 |
| 528 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); | 480 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); |
| 529 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | 481 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); |
| 530 return icon_bounds; | 482 return icon_bounds; |
| 531 } | 483 } |
| 532 | 484 |
| 533 } // namespace app_list | 485 } // namespace app_list |
| OLD | NEW |