Chromium Code Reviews| 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 "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 ItemIsInstallingChanged(); | 89 ItemIsInstallingChanged(); |
| 90 item_->AddObserver(this); | 90 item_->AddObserver(this); |
| 91 | 91 |
| 92 set_context_menu_controller(this); | 92 set_context_menu_controller(this); |
| 93 set_request_focus_on_press(false); | 93 set_request_focus_on_press(false); |
| 94 | 94 |
| 95 SetAnimationDuration(0); | 95 SetAnimationDuration(0); |
| 96 } | 96 } |
| 97 | 97 |
| 98 AppListItemView::~AppListItemView() { | 98 AppListItemView::~AppListItemView() { |
| 99 item_->RemoveObserver(this); | 99 if (item_) |
|
xiyuan
2014/02/06 22:45:12
When will this happen?
jennyz
2014/02/07 00:03:10
You're right, I don't need to do so as long as mak
| |
| 100 item_->RemoveObserver(this); | |
| 100 } | 101 } |
| 101 | 102 |
| 102 void AppListItemView::SetIconSize(const gfx::Size& size) { | 103 void AppListItemView::SetIconSize(const gfx::Size& size) { |
| 103 if (icon_size_ == size) | 104 if (icon_size_ == size) |
| 104 return; | 105 return; |
| 105 | 106 |
| 106 icon_size_ = size; | 107 icon_size_ = size; |
| 107 UpdateIcon(); | 108 UpdateIcon(); |
| 108 } | 109 } |
| 109 | 110 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 260 } |
| 260 | 261 |
| 261 void AppListItemView::Layout() { | 262 void AppListItemView::Layout() { |
| 262 gfx::Rect rect(GetContentsBounds()); | 263 gfx::Rect rect(GetContentsBounds()); |
| 263 | 264 |
| 264 const int left_right_padding = | 265 const int left_right_padding = |
| 265 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | 266 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); |
| 266 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | 267 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); |
| 267 const int y = rect.y(); | 268 const int y = rect.y(); |
| 268 | 269 |
| 269 gfx::Rect icon_bounds(rect.x(), y, rect.width(), icon_size_.height()); | 270 icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); |
| 270 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | |
| 271 icon_->SetBoundsRect(icon_bounds); | |
| 272 const gfx::Size title_size = title_->GetPreferredSize(); | 271 const gfx::Size title_size = title_->GetPreferredSize(); |
| 273 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, | 272 gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, |
| 274 y + icon_size_.height() + kIconTitleSpacing, | 273 y + icon_size_.height() + kIconTitleSpacing, |
| 275 title_size.width(), | 274 title_size.width(), |
| 276 title_size.height()); | 275 title_size.height()); |
| 277 title_bounds.Intersect(rect); | 276 title_bounds.Intersect(rect); |
| 278 title_->SetBoundsRect(title_bounds); | 277 title_->SetBoundsRect(title_bounds); |
| 279 | 278 |
| 280 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); | 279 gfx::Rect progress_bar_bounds(progress_bar_->GetPreferredSize()); |
| 281 progress_bar_bounds.set_x(GetContentsBounds().x() + | 280 progress_bar_bounds.set_x(GetContentsBounds().x() + |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 459 } | 458 } |
| 460 | 459 |
| 461 void AppListItemView::OnSyncDragEnd() { | 460 void AppListItemView::OnSyncDragEnd() { |
| 462 SetUIState(UI_STATE_NORMAL); | 461 SetUIState(UI_STATE_NORMAL); |
| 463 } | 462 } |
| 464 | 463 |
| 465 const gfx::Rect& AppListItemView::GetIconBounds() const { | 464 const gfx::Rect& AppListItemView::GetIconBounds() const { |
| 466 return icon_->bounds(); | 465 return icon_->bounds(); |
| 467 } | 466 } |
| 468 | 467 |
| 468 void AppListItemView::SetDragUIState() { | |
|
xiyuan
2014/02/06 22:45:12
nit: Move the block under GetIconBounds to be cons
jennyz
2014/02/07 00:03:10
Isn't this just under GetIconsBound?
xiyuan
2014/02/07 00:32:19
Oops, I am blind. :p
| |
| 469 SetUIState(UI_STATE_DRAGGING); | |
| 470 } | |
| 471 | |
| 472 gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( | |
| 473 const gfx::Rect& target_bounds) { | |
| 474 gfx::Rect rect(target_bounds); | |
| 475 | |
| 476 const int left_right_padding = | |
| 477 title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); | |
| 478 rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); | |
| 479 | |
| 480 gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); | |
| 481 icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); | |
| 482 return icon_bounds; | |
| 483 } | |
| 484 | |
| 469 } // namespace app_list | 485 } // namespace app_list |
| OLD | NEW |