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