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 42 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 (is_highlighted_ && !is_installing_) { | 349 if (is_highlighted_ && !is_installing_) { |
354 canvas->FillRect(rect, kHighlightedColor); | 350 canvas->FillRect(rect, kHighlightedColor); |
355 return; | 351 return; |
356 } | 352 } |
357 if (apps_grid_view_->IsSelectedView(this)) | 353 if (apps_grid_view_->IsSelectedView(this)) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 // keyboard selection; for mouse hover, keyboard selection takes precedence. | 393 // keyboard selection; for mouse hover, keyboard selection takes precedence. |
398 if (!apps_grid_view_->IsSelectedView(this) || state() == STATE_PRESSED) | 394 if (!apps_grid_view_->IsSelectedView(this) || state() == STATE_PRESSED) |
399 SetItemIsHighlighted(true); | 395 SetItemIsHighlighted(true); |
400 title_->SetEnabledColor(kGridTitleHoverColor); | 396 title_->SetEnabledColor(kGridTitleHoverColor); |
401 } else { | 397 } else { |
402 SetItemIsHighlighted(false); | 398 SetItemIsHighlighted(false); |
403 if (item_weak_) | 399 if (item_weak_) |
404 item_weak_->set_highlighted(false); | 400 item_weak_->set_highlighted(false); |
405 title_->SetEnabledColor(kGridTitleColor); | 401 title_->SetEnabledColor(kGridTitleColor); |
406 } | 402 } |
407 title_->Invalidate(); | 403 SetTitleSubpixelAA(); |
408 } | 404 } |
409 | 405 |
410 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { | 406 bool AppListItemView::ShouldEnterPushedState(const ui::Event& event) { |
411 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray | 407 // Don't enter pushed state for ET_GESTURE_TAP_DOWN so that hover gray |
412 // background does not show up during scroll. | 408 // background does not show up during scroll. |
413 if (event.type() == ui::ET_GESTURE_TAP_DOWN) | 409 if (event.type() == ui::ET_GESTURE_TAP_DOWN) |
414 return false; | 410 return false; |
415 | 411 |
416 return views::CustomButton::ShouldEnterPushedState(event); | 412 return views::CustomButton::ShouldEnterPushedState(event); |
417 } | 413 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 SetItemPercentDownloaded(item_weak_->percent_downloaded()); | 567 SetItemPercentDownloaded(item_weak_->percent_downloaded()); |
572 } | 568 } |
573 | 569 |
574 void AppListItemView::ItemBeingDestroyed() { | 570 void AppListItemView::ItemBeingDestroyed() { |
575 DCHECK(item_weak_); | 571 DCHECK(item_weak_); |
576 item_weak_->RemoveObserver(this); | 572 item_weak_->RemoveObserver(this); |
577 item_weak_ = NULL; | 573 item_weak_ = NULL; |
578 } | 574 } |
579 | 575 |
580 } // namespace app_list | 576 } // namespace app_list |
OLD | NEW |