| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/tile_item_view.h" | 5 #include "ui/app_list/views/tile_item_view.h" |
| 6 | 6 |
| 7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
| 8 #include "ui/app_list/app_list_features.h" | 8 #include "ui/app_list/app_list_features.h" |
| 9 #include "ui/app_list/views/app_list_main_view.h" | 9 #include "ui/app_list/views/app_list_main_view.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/image/canvas_image_source.h" | 11 #include "ui/gfx/image/canvas_image_source.h" |
| 12 #include "ui/gfx/image/image_skia_operations.h" | 12 #include "ui/gfx/image/image_skia_operations.h" |
| 13 #include "ui/views/background.h" | 13 #include "ui/views/background.h" |
| 14 #include "ui/views/controls/image_view.h" | 14 #include "ui/views/controls/image_view.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 constexpr int kTopPadding = 5; | 20 constexpr int kTopPadding = 5; |
| 21 constexpr int kTileSize = 90; | 21 constexpr int kTileSize = 90; |
| 22 constexpr int kIconTitleSpacing = 6; | 22 constexpr int kIconTitleSpacing = 6; |
| 23 | 23 |
| 24 constexpr int kBadgeBackgroundRadius = 10; | |
| 25 | |
| 26 // The background image source for badge. | 24 // The background image source for badge. |
| 27 class BadgeBackgroundImageSource : public gfx::CanvasImageSource { | 25 class BadgeBackgroundImageSource : public gfx::CanvasImageSource { |
| 28 public: | 26 public: |
| 29 explicit BadgeBackgroundImageSource(int size) | 27 explicit BadgeBackgroundImageSource(int size) |
| 30 : CanvasImageSource(gfx::Size(size, size), false), | 28 : CanvasImageSource(gfx::Size(size, size), false), |
| 31 radius_(static_cast<float>(size / 2)) {} | 29 radius_(static_cast<float>(size / 2)) {} |
| 32 ~BadgeBackgroundImageSource() override = default; | 30 ~BadgeBackgroundImageSource() override = default; |
| 33 | 31 |
| 34 private: | 32 private: |
| 35 // gfx::CanvasImageSource overrides: | 33 // gfx::CanvasImageSource overrides: |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 title_->SetText(title); | 145 title_->SetText(title); |
| 148 SetAccessibleName(title); | 146 SetAccessibleName(title); |
| 149 } | 147 } |
| 150 | 148 |
| 151 void TileItemView::StateChanged(ButtonState old_state) { | 149 void TileItemView::StateChanged(ButtonState old_state) { |
| 152 UpdateBackgroundColor(); | 150 UpdateBackgroundColor(); |
| 153 } | 151 } |
| 154 | 152 |
| 155 void TileItemView::Layout() { | 153 void TileItemView::Layout() { |
| 156 gfx::Rect rect(GetContentsBounds()); | 154 gfx::Rect rect(GetContentsBounds()); |
| 157 if (rect.IsEmpty()) | |
| 158 return; | |
| 159 | 155 |
| 160 rect.Inset(0, kTopPadding, 0, 0); | 156 rect.Inset(0, kTopPadding, 0, 0); |
| 161 icon_->SetBoundsRect(rect); | 157 icon_->SetBoundsRect(rect); |
| 162 | 158 |
| 163 if (badge_) { | |
| 164 gfx::Rect badge_rect(rect); | |
| 165 gfx::Size icon_size = icon_->GetImage().size(); | |
| 166 badge_rect.Offset( | |
| 167 (icon_size.width() - kAppBadgeIconSize) / 2, | |
| 168 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2); | |
| 169 badge_->SetBoundsRect(badge_rect); | |
| 170 } | |
| 171 | |
| 172 rect.Inset(0, kGridIconDimension + kIconTitleSpacing, 0, 0); | 159 rect.Inset(0, kGridIconDimension + kIconTitleSpacing, 0, 0); |
| 173 rect.set_height(title_->GetPreferredSize().height()); | 160 rect.set_height(title_->GetPreferredSize().height()); |
| 174 title_->SetBoundsRect(rect); | 161 title_->SetBoundsRect(rect); |
| 175 } | 162 } |
| 176 | 163 |
| 177 const char* TileItemView::GetClassName() const { | 164 const char* TileItemView::GetClassName() const { |
| 178 return "TileItemView"; | 165 return "TileItemView"; |
| 179 } | 166 } |
| 180 | 167 |
| 181 void TileItemView::ImageShadowAnimationProgressed( | 168 void TileItemView::ImageShadowAnimationProgressed( |
| 182 ImageShadowAnimator* animator) { | 169 ImageShadowAnimator* animator) { |
| 183 icon_->SetImage(animator->shadow_image()); | 170 icon_->SetImage(animator->shadow_image()); |
| 184 } | 171 } |
| 185 | 172 |
| 173 gfx::Size TileItemView::CalculatePreferredSize() const { |
| 174 return gfx::Size(kTileSize, kTileSize); |
| 175 } |
| 176 |
| 177 bool TileItemView::GetTooltipText(const gfx::Point& p, |
| 178 base::string16* tooltip) const { |
| 179 // Use the label to generate a tooltip, so that it will consider its text |
| 180 // truncation in making the tooltip. We do not want the label itself to have a |
| 181 // tooltip, so we only temporarily enable it to get the tooltip text from the |
| 182 // label, then disable it again. |
| 183 title_->SetHandlesTooltips(true); |
| 184 bool handled = title_->GetTooltipText(p, tooltip); |
| 185 title_->SetHandlesTooltips(false); |
| 186 return handled; |
| 187 } |
| 188 |
| 186 void TileItemView::UpdateBackgroundColor() { | 189 void TileItemView::UpdateBackgroundColor() { |
| 187 std::unique_ptr<views::Background> background; | 190 std::unique_ptr<views::Background> background; |
| 188 SkColor background_color = parent_background_color_; | 191 SkColor background_color = parent_background_color_; |
| 189 | 192 |
| 190 if (selected_) { | 193 if (selected_) { |
| 191 background_color = kSelectedColor; | 194 background_color = kSelectedColor; |
| 192 background = views::CreateSolidBackground(background_color); | 195 background = views::CreateSolidBackground(background_color); |
| 193 } else if (image_shadow_animator_) { | 196 } else if (image_shadow_animator_) { |
| 194 if (state() == STATE_HOVERED || state() == STATE_PRESSED) | 197 if (state() == STATE_HOVERED || state() == STATE_PRESSED) |
| 195 image_shadow_animator_->animation()->Show(); | 198 image_shadow_animator_->animation()->Show(); |
| 196 else | 199 else |
| 197 image_shadow_animator_->animation()->Hide(); | 200 image_shadow_animator_->animation()->Hide(); |
| 198 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 201 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
| 199 background_color = kHighlightedColor; | 202 background_color = kHighlightedColor; |
| 200 background = views::CreateSolidBackground(background_color); | 203 background = views::CreateSolidBackground(background_color); |
| 201 } | 204 } |
| 202 | 205 |
| 203 // Tell the label what color it will be drawn onto. It will use whether the | 206 // Tell the label what color it will be drawn onto. It will use whether the |
| 204 // background color is opaque or transparent to decide whether to use subpixel | 207 // background color is opaque or transparent to decide whether to use subpixel |
| 205 // rendering. Does not actually set the label's background color. | 208 // rendering. Does not actually set the label's background color. |
| 206 title_->SetBackgroundColor(background_color); | 209 title_->SetBackgroundColor(background_color); |
| 207 | 210 |
| 208 SetBackground(std::move(background)); | 211 SetBackground(std::move(background)); |
| 209 SchedulePaint(); | 212 SchedulePaint(); |
| 210 } | 213 } |
| 211 | 214 |
| 212 gfx::Size TileItemView::CalculatePreferredSize() const { | |
| 213 return gfx::Size(kTileSize, kTileSize); | |
| 214 } | |
| 215 | |
| 216 bool TileItemView::GetTooltipText(const gfx::Point& p, | |
| 217 base::string16* tooltip) const { | |
| 218 // Use the label to generate a tooltip, so that it will consider its text | |
| 219 // truncation in making the tooltip. We do not want the label itself to have a | |
| 220 // tooltip, so we only temporarily enable it to get the tooltip text from the | |
| 221 // label, then disable it again. | |
| 222 title_->SetHandlesTooltips(true); | |
| 223 bool handled = title_->GetTooltipText(p, tooltip); | |
| 224 title_->SetHandlesTooltips(false); | |
| 225 return handled; | |
| 226 } | |
| 227 | |
| 228 } // namespace app_list | 215 } // namespace app_list |
| OLD | NEW |