| 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/profiler/scoped_tracker.h" | 9 #include "base/profiler/scoped_tracker.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 layer()->SetTransform(gfx::GetScaleTransform( | 180 layer()->SetTransform(gfx::GetScaleTransform( |
| 181 bounds.CenterPoint(), | 181 bounds.CenterPoint(), |
| 182 kDraggingIconScale)); | 182 kDraggingIconScale)); |
| 183 break; | 183 break; |
| 184 } | 184 } |
| 185 case UI_STATE_DROPPING_IN_FOLDER: | 185 case UI_STATE_DROPPING_IN_FOLDER: |
| 186 break; | 186 break; |
| 187 } | 187 } |
| 188 #endif // !OS_WIN | 188 #endif // !OS_WIN |
| 189 | 189 |
| 190 SetTitleSubpixelAA(); |
| 190 SchedulePaint(); | 191 SchedulePaint(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 void AppListItemView::SetTouchDragging(bool touch_dragging) { | 194 void AppListItemView::SetTouchDragging(bool touch_dragging) { |
| 194 if (touch_dragging_ == touch_dragging) | 195 if (touch_dragging_ == touch_dragging) |
| 195 return; | 196 return; |
| 196 | 197 |
| 197 touch_dragging_ = touch_dragging; | 198 touch_dragging_ = touch_dragging; |
| 198 SetState(STATE_NORMAL); | 199 SetState(STATE_NORMAL); |
| 199 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); | 200 SetUIState(touch_dragging_ ? UI_STATE_DRAGGING : UI_STATE_NORMAL); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void AppListItemView::OnMouseDragTimer() { | 203 void AppListItemView::OnMouseDragTimer() { |
| 203 DCHECK(apps_grid_view_->IsDraggedView(this)); | 204 DCHECK(apps_grid_view_->IsDraggedView(this)); |
| 204 SetUIState(UI_STATE_DRAGGING); | 205 SetUIState(UI_STATE_DRAGGING); |
| 205 } | 206 } |
| 206 | 207 |
| 207 void AppListItemView::SetTitleSubpixelAA() { | 208 void AppListItemView::SetTitleSubpixelAA() { |
| 208 // TODO(tapted): Enable AA for folders as well, taking care to play nice with | 209 // TODO(tapted): Enable AA for folders as well, taking care to play nice with |
| 209 // the folder bubble animation. | 210 // the folder bubble animation. |
| 210 bool enable_aa = !is_in_folder_ && ui_state_ == UI_STATE_NORMAL && | 211 bool enable_aa = !is_in_folder_ && ui_state_ == UI_STATE_NORMAL && |
| 211 !is_highlighted_ && !apps_grid_view_->IsSelectedView(this) && | 212 !is_highlighted_ && !apps_grid_view_->IsSelectedView(this) && |
| 212 !apps_grid_view_->IsAnimatingView(this); | 213 !apps_grid_view_->IsAnimatingView(this); |
| 213 | 214 |
| 214 bool currently_enabled = title_->background() != NULL; | 215 title_->SetSubpixelRenderingEnabled(enable_aa); |
| 215 if (currently_enabled == enable_aa) | |
| 216 return; | |
| 217 | |
| 218 if (enable_aa) { | 216 if (enable_aa) { |
| 219 title_->SetBackgroundColor(app_list::kLabelBackgroundColor); | 217 title_->SetBackgroundColor(app_list::kLabelBackgroundColor); |
| 220 title_->set_background(views::Background::CreateSolidBackground( | 218 title_->set_background(views::Background::CreateSolidBackground( |
| 221 app_list::kLabelBackgroundColor)); | 219 app_list::kLabelBackgroundColor)); |
| 222 } else { | 220 } else { |
| 223 // In other cases, keep the background transparent to ensure correct | 221 // In other cases, keep the background transparent to ensure correct |
| 224 // interactions with animations. This will temporarily disable subpixel AA. | 222 // interactions with animations. This will temporarily disable subpixel AA. |
| 225 title_->SetBackgroundColor(0); | 223 title_->SetBackgroundColor(0); |
| 226 title_->set_background(NULL); | 224 title_->set_background(NULL); |
| 227 } | 225 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // Use full name for accessibility. | 267 // Use full name for accessibility. |
| 270 SetAccessibleName( | 268 SetAccessibleName( |
| 271 is_folder_ ? l10n_util::GetStringFUTF16( | 269 is_folder_ ? l10n_util::GetStringFUTF16( |
| 272 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, full_name) | 270 IDS_APP_LIST_FOLDER_BUTTON_ACCESSIBILE_NAME, full_name) |
| 273 : full_name); | 271 : full_name); |
| 274 Layout(); | 272 Layout(); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void AppListItemView::SetItemIsHighlighted(bool is_highlighted) { | 275 void AppListItemView::SetItemIsHighlighted(bool is_highlighted) { |
| 278 is_highlighted_ = is_highlighted; | 276 is_highlighted_ = is_highlighted; |
| 277 SetTitleSubpixelAA(); |
| 279 SchedulePaint(); | 278 SchedulePaint(); |
| 280 } | 279 } |
| 281 | 280 |
| 282 void AppListItemView::SetItemIsInstalling(bool is_installing) { | 281 void AppListItemView::SetItemIsInstalling(bool is_installing) { |
| 283 is_installing_ = is_installing; | 282 is_installing_ = is_installing; |
| 284 if (ui_state_ == UI_STATE_NORMAL) { | 283 if (ui_state_ == UI_STATE_NORMAL) { |
| 285 title_->SetVisible(!is_installing); | 284 title_->SetVisible(!is_installing); |
| 286 progress_bar_->SetVisible(is_installing); | 285 progress_bar_->SetVisible(is_installing); |
| 287 } | 286 } |
| 287 SetTitleSubpixelAA(); |
| 288 SchedulePaint(); | 288 SchedulePaint(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void AppListItemView::SetItemPercentDownloaded(int percent_downloaded) { | 291 void AppListItemView::SetItemPercentDownloaded(int percent_downloaded) { |
| 292 // A percent_downloaded() of -1 can mean it's not known how much percent is | 292 // A percent_downloaded() of -1 can mean it's not known how much percent is |
| 293 // completed, or the download hasn't been marked complete, as is the case | 293 // completed, or the download hasn't been marked complete, as is the case |
| 294 // while an extension is being installed after being downloaded. | 294 // while an extension is being installed after being downloaded. |
| 295 if (percent_downloaded == -1) | 295 if (percent_downloaded == -1) |
| 296 return; | 296 return; |
| 297 progress_bar_->SetValue(percent_downloaded / 100.0); | 297 progress_bar_->SetValue(percent_downloaded / 100.0); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 324 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 324 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 325 tracked_objects::ScopedTracker tracking_profile3( | 325 tracked_objects::ScopedTracker tracking_profile3( |
| 326 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 AppListItemView::Layout3")); | 326 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 AppListItemView::Layout3")); |
| 327 | 327 |
| 328 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 328 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
| 329 y + kGridIconDimension + kIconTitleSpacing, | 329 y + kGridIconDimension + kIconTitleSpacing, |
| 330 title_size.width(), | 330 title_size.width(), |
| 331 title_size.height()); | 331 title_size.height()); |
| 332 title_bounds.Intersect(rect); | 332 title_bounds.Intersect(rect); |
| 333 title_->SetBoundsRect(title_bounds); | 333 title_->SetBoundsRect(title_bounds); |
| 334 SetTitleSubpixelAA(); |
| 334 | 335 |
| 335 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 336 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
| 336 progress_bar_bounds.set_x(GetContentsBounds().x() + | 337 progress_bar_bounds.set_x(GetContentsBounds().x() + |
| 337 kProgressBarHorizontalPadding); | 338 kProgressBarHorizontalPadding); |
| 338 progress_bar_bounds.set_y(title_bounds.y()); | 339 progress_bar_bounds.set_y(title_bounds.y()); |
| 339 progress_bar_->SetBoundsRect(progress_bar_bounds); | 340 progress_bar_->SetBoundsRect(progress_bar_bounds); |
| 340 } | 341 } |
| 341 | 342 |
| 342 void AppListItemView::SchedulePaintInRect(const gfx::Rect& r) { | |
| 343 SetTitleSubpixelAA(); | |
| 344 views::CustomButton::SchedulePaintInRect(r); | |
| 345 } | |
| 346 | |
| 347 void AppListItemView::OnPaint(gfx::Canvas* canvas) { | 343 void AppListItemView::OnPaint(gfx::Canvas* canvas) { |
| 348 if (apps_grid_view_->IsDraggedView(this)) | 344 if (apps_grid_view_->IsDraggedView(this)) |
| 349 return; | 345 return; |
| 350 | 346 |
| 351 gfx::Rect rect(GetContentsBounds()); | 347 gfx::Rect rect(GetContentsBounds()); |
| 352 if (apps_grid_view_->IsSelectedView(this)) { | 348 if (apps_grid_view_->IsSelectedView(this)) { |
| 353 canvas->FillRect(rect, kSelectedColor); | 349 canvas->FillRect(rect, kSelectedColor); |
| 354 } else if (is_highlighted_ && !is_installing_) { | 350 } else if (is_highlighted_ && !is_installing_) { |
| 355 canvas->FillRect(rect, kHighlightedColor); | 351 canvas->FillRect(rect, kHighlightedColor); |
| 356 return; | 352 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 // keyboard selection; for mouse hover, keyboard selection takes precedence. | 394 // keyboard selection; for mouse hover, keyboard selection takes precedence. |
| 399 if (!apps_grid_view_->IsSelectedView(this) || state() == STATE_PRESSED) | 395 if (!apps_grid_view_->IsSelectedView(this) || state() == STATE_PRESSED) |
| 400 SetItemIsHighlighted(true); | 396 SetItemIsHighlighted(true); |
| 401 title_->SetEnabledColor(kGridTitleHoverColor); | 397 title_->SetEnabledColor(kGridTitleHoverColor); |
| 402 } else { | 398 } else { |
| 403 SetItemIsHighlighted(false); | 399 SetItemIsHighlighted(false); |
| 404 if (item_weak_) | 400 if (item_weak_) |
| 405 item_weak_->set_highlighted(false); | 401 item_weak_->set_highlighted(false); |
| 406 title_->SetEnabledColor(kGridTitleColor); | 402 title_->SetEnabledColor(kGridTitleColor); |
| 407 } | 403 } |
| 408 title_->Invalidate(); | 404 SetTitleSubpixelAA(); |
| 409 } | 405 } |
| 410 | 406 |
| 411 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { | 407 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { |
| 412 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray | 408 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray |
| 413 // background does not show up during scroll. | 409 // background does not show up during scroll. |
| 414 if (event.type() == ui::ET_GESTURE_TAP_DOWN) | 410 if (event.type() == ui::ET_GESTURE_TAP_DOWN) |
| 415 return false; | 411 return false; |
| 416 | 412 |
| 417 return views::CustomButton::ShouldEnterPushedState(event); | 413 return views::CustomButton::ShouldEnterPushedState(event); |
| 418 } | 414 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 SetItemPercentDownloaded(item_weak_->percent_downloaded()); | 584 SetItemPercentDownloaded(item_weak_->percent_downloaded()); |
| 589 } | 585 } |
| 590 | 586 |
| 591 void AppListItemView::ItemBeingDestroyed() { | 587 void AppListItemView::ItemBeingDestroyed() { |
| 592 DCHECK(item_weak_); | 588 DCHECK(item_weak_); |
| 593 item_weak_->RemoveObserver(this); | 589 item_weak_->RemoveObserver(this); |
| 594 item_weak_ = NULL; | 590 item_weak_ = NULL; |
| 595 } | 591 } |
| 596 | 592 |
| 597 } // namespace app_list | 593 } // namespace app_list |
| OLD | NEW |