| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/apps_container_view.h" | 5 #include "ui/app_list/views/apps_container_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "ui/app_list/app_list_constants.h" | 14 #include "ui/app_list/app_list_constants.h" |
| 12 #include "ui/app_list/app_list_folder_item.h" | 15 #include "ui/app_list/app_list_folder_item.h" |
| 13 #include "ui/app_list/app_list_switches.h" | 16 #include "ui/app_list/app_list_switches.h" |
| 17 #include "ui/app_list/app_list_view_delegate.h" |
| 14 #include "ui/app_list/views/app_list_folder_view.h" | 18 #include "ui/app_list/views/app_list_folder_view.h" |
| 15 #include "ui/app_list/views/app_list_item_view.h" | 19 #include "ui/app_list/views/app_list_item_view.h" |
| 16 #include "ui/app_list/views/app_list_main_view.h" | 20 #include "ui/app_list/views/app_list_main_view.h" |
| 17 #include "ui/app_list/views/apps_grid_view.h" | 21 #include "ui/app_list/views/apps_grid_view.h" |
| 18 #include "ui/app_list/views/folder_background_view.h" | 22 #include "ui/app_list/views/folder_background_view.h" |
| 23 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
| 25 #include "ui/gfx/canvas.h" |
| 26 #include "ui/views/background.h" |
| 27 #include "ui/views/border.h" |
| 28 #include "ui/views/controls/label.h" |
| 29 #include "ui/views/controls/styled_label.h" |
| 30 #include "ui/views/layout/box_layout.h" |
| 31 #include "ui/views/view.h" |
| 20 | 32 |
| 21 namespace app_list { | 33 namespace app_list { |
| 22 | 34 |
| 35 namespace { |
| 36 |
| 37 #if !defined(OS_CHROMEOS) |
| 38 // Deprecation notice dimensions. |
| 39 const int kDeprecationBannerLabelSpacingPx = 6; |
| 40 const int kDeprecationBannerPaddingPx = 16; |
| 41 const int kDeprecationBannerMarginPx = 12; |
| 42 const SkColor kDeprecationBannerBackgroundColor = |
| 43 SkColorSetRGB(0xff, 0xfd, 0xe7); |
| 44 const SkColor kDeprecationBannerBorderColor = SkColorSetRGB(0xc1, 0xc1, 0xc1); |
| 45 const int kDeprecationBannerBorderThickness = 1; |
| 46 const int kDeprecationBannerBorderCornerRadius = 2; |
| 47 // Relative to the platform-default font size. |
| 48 const int kDeprecationBannerTitleSize = 2; |
| 49 const int kDeprecationBannerTextSize = 0; |
| 50 const SkColor kLinkColor = SkColorSetRGB(0x33, 0x67, 0xd6); |
| 51 |
| 52 // A background that paints a filled rounded rectangle. |
| 53 class RoundedRectBackground : public views::Background { |
| 54 public: |
| 55 RoundedRectBackground(SkColor color, int corner_radius) |
| 56 : color_(color), corner_radius_(corner_radius) {} |
| 57 ~RoundedRectBackground() override {} |
| 58 |
| 59 // views::Background overrides: |
| 60 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 61 gfx::Rect bounds = view->GetContentsBounds(); |
| 62 |
| 63 SkPaint paint; |
| 64 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 65 paint.setColor(color_); |
| 66 canvas->DrawRoundRect(bounds, corner_radius_, paint); |
| 67 } |
| 68 |
| 69 private: |
| 70 SkColor color_; |
| 71 int corner_radius_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(RoundedRectBackground); |
| 74 }; |
| 75 |
| 76 base::string16 GetDeprecationText(const AppListViewDelegate& delegate) { |
| 77 size_t message_break; |
| 78 base::string16 text = delegate.GetMessageText(&message_break); |
| 79 base::string16 apps_shortcut_name = delegate.GetAppsShortcutName(); |
| 80 |
| 81 // TODO(mgiuca): Insert the Apps shortcut with an image, rather than just |
| 82 // concatenating it into the string. |
| 83 text.insert(message_break, apps_shortcut_name); |
| 84 return text; |
| 85 } |
| 86 |
| 87 views::View* BuildDeprecationNotice(const AppListViewDelegate& delegate, |
| 88 views::StyledLabelListener* listener) { |
| 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 90 const gfx::FontList& title_font = |
| 91 rb.GetFontListWithDelta(kDeprecationBannerTitleSize); |
| 92 const gfx::FontList& text_font = |
| 93 rb.GetFontListWithDelta(kDeprecationBannerTextSize); |
| 94 |
| 95 base::string16 title = delegate.GetMessageTitle(); |
| 96 views::Label* title_label = new views::Label(title); |
| 97 title_label->SetMultiLine(true); |
| 98 title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT); |
| 99 title_label->SetFontList(title_font); |
| 100 title_label->SetBackgroundColor(kDeprecationBannerBackgroundColor); |
| 101 |
| 102 base::string16 text = GetDeprecationText(delegate); |
| 103 base::string16 learn_more = delegate.GetLearnMoreText(); |
| 104 base::string16 message = text + base::ASCIIToUTF16(" ") + learn_more; |
| 105 size_t learn_more_start = text.size() + 1; |
| 106 size_t learn_more_end = learn_more_start + learn_more.size(); |
| 107 views::StyledLabel* text_label = new views::StyledLabel(message, listener); |
| 108 auto learn_more_style = views::StyledLabel::RangeStyleInfo::CreateForLink(); |
| 109 learn_more_style.color = kLinkColor; |
| 110 if (learn_more.size()) { |
| 111 text_label->AddStyleRange(gfx::Range(learn_more_start, learn_more_end), |
| 112 learn_more_style); |
| 113 } |
| 114 text_label->SetDisplayedOnBackgroundColor(kDeprecationBannerBackgroundColor); |
| 115 text_label->SetBaseFontList(text_font); |
| 116 |
| 117 views::View* deprecation_banner_box = new views::View; |
| 118 deprecation_banner_box->SetLayoutManager(new views::BoxLayout( |
| 119 views::BoxLayout::kVertical, kDeprecationBannerPaddingPx, |
| 120 kDeprecationBannerPaddingPx, kDeprecationBannerLabelSpacingPx)); |
| 121 deprecation_banner_box->AddChildView(title_label); |
| 122 deprecation_banner_box->AddChildView(text_label); |
| 123 deprecation_banner_box->set_background(new RoundedRectBackground( |
| 124 kDeprecationBannerBackgroundColor, kDeprecationBannerBorderCornerRadius)); |
| 125 deprecation_banner_box->SetBorder(views::Border::CreateRoundedRectBorder( |
| 126 kDeprecationBannerBorderThickness, kDeprecationBannerBorderCornerRadius, |
| 127 kDeprecationBannerBorderColor)); |
| 128 |
| 129 views::View* deprecation_banner_view = new views::View; |
| 130 deprecation_banner_view->AddChildView(deprecation_banner_box); |
| 131 deprecation_banner_view->SetLayoutManager(new views::BoxLayout( |
| 132 views::BoxLayout::kVertical, kDeprecationBannerMarginPx, |
| 133 kDeprecationBannerMarginPx, 0)); |
| 134 |
| 135 return deprecation_banner_view; |
| 136 } |
| 137 #endif // !defined(OS_CHROMEOS) |
| 138 |
| 139 } // namespace |
| 140 |
| 23 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, | 141 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, |
| 24 AppListModel* model) | 142 AppListModel* model) |
| 25 : show_state_(SHOW_NONE), top_icon_animation_pending_count_(0) { | 143 : show_state_(SHOW_NONE), |
| 144 view_delegate_(app_list_main_view->view_delegate()), |
| 145 top_icon_animation_pending_count_(0) { |
| 146 #if !defined(OS_CHROMEOS) |
| 147 deprecation_banner_view_ = BuildDeprecationNotice(*view_delegate_, this); |
| 148 AddChildView(deprecation_banner_view_); |
| 149 #endif // !defined(OS_CHROMEOS) |
| 150 |
| 26 apps_grid_view_ = new AppsGridView(app_list_main_view); | 151 apps_grid_view_ = new AppsGridView(app_list_main_view); |
| 27 int cols; | 152 int cols; |
| 28 int rows; | 153 int rows; |
| 29 if (switches::IsExperimentalAppListEnabled()) { | 154 if (switches::IsExperimentalAppListEnabled()) { |
| 30 cols = kExperimentalPreferredCols; | 155 cols = kExperimentalPreferredCols; |
| 31 rows = kExperimentalPreferredRows; | 156 rows = kExperimentalPreferredRows; |
| 32 } else if (app_list_main_view->ShouldCenterWindow()) { | 157 } else if (app_list_main_view->ShouldCenterWindow()) { |
| 33 cols = kCenteredPreferredCols; | 158 cols = kCenteredPreferredCols; |
| 34 rows = kCenteredPreferredRows; | 159 rows = kCenteredPreferredRows; |
| 35 } else { | 160 } else { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 bool AppsContainerView::IsInFolderView() const { | 228 bool AppsContainerView::IsInFolderView() const { |
| 104 return show_state_ == SHOW_ACTIVE_FOLDER; | 229 return show_state_ == SHOW_ACTIVE_FOLDER; |
| 105 } | 230 } |
| 106 | 231 |
| 107 void AppsContainerView::ReparentDragEnded() { | 232 void AppsContainerView::ReparentDragEnded() { |
| 108 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_); | 233 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_); |
| 109 show_state_ = AppsContainerView::SHOW_APPS; | 234 show_state_ = AppsContainerView::SHOW_APPS; |
| 110 } | 235 } |
| 111 | 236 |
| 112 gfx::Size AppsContainerView::GetPreferredSize() const { | 237 gfx::Size AppsContainerView::GetPreferredSize() const { |
| 238 const int deprecation_banner_height = |
| 239 deprecation_banner_view_ |
| 240 ? deprecation_banner_view_->GetPreferredSize().height() |
| 241 : 0; |
| 113 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); | 242 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); |
| 114 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); | 243 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); |
| 115 | 244 |
| 116 int width = std::max(grid_size.width(), folder_view_size.width()); | 245 int width = std::max(grid_size.width(), folder_view_size.width()); |
| 117 int height = std::max(grid_size.height(), folder_view_size.height()); | 246 int height = std::max(grid_size.height() + deprecation_banner_height, |
| 247 folder_view_size.height()); |
| 118 return gfx::Size(width, height); | 248 return gfx::Size(width, height); |
| 119 } | 249 } |
| 120 | 250 |
| 121 void AppsContainerView::Layout() { | 251 void AppsContainerView::Layout() { |
| 122 gfx::Rect rect(GetContentsBounds()); | 252 gfx::Rect rect(GetContentsBounds()); |
| 123 if (rect.IsEmpty()) | 253 if (rect.IsEmpty()) |
| 124 return; | 254 return; |
| 125 | 255 |
| 256 int deprecation_banner_height = 0; |
| 257 if (deprecation_banner_view_) { |
| 258 deprecation_banner_height = |
| 259 deprecation_banner_view_->GetPreferredSize().height(); |
| 260 gfx::Size deprecation_banner_size(rect.width(), deprecation_banner_height); |
| 261 deprecation_banner_view_->SetBoundsRect( |
| 262 gfx::Rect(rect.origin(), deprecation_banner_size)); |
| 263 } |
| 264 |
| 126 switch (show_state_) { | 265 switch (show_state_) { |
| 127 case SHOW_APPS: | 266 case SHOW_APPS: |
| 267 rect.Inset(0, deprecation_banner_height, 0, 0); |
| 128 apps_grid_view_->SetBoundsRect(rect); | 268 apps_grid_view_->SetBoundsRect(rect); |
| 129 break; | 269 break; |
| 130 case SHOW_ACTIVE_FOLDER: | 270 case SHOW_ACTIVE_FOLDER: |
| 131 folder_background_view_->SetBoundsRect(rect); | 271 folder_background_view_->SetBoundsRect(rect); |
| 132 app_list_folder_view_->SetBoundsRect(rect); | 272 app_list_folder_view_->SetBoundsRect(rect); |
| 133 break; | 273 break; |
| 134 case SHOW_ITEM_REPARENT: | 274 case SHOW_ITEM_REPARENT: |
| 135 break; | 275 break; |
| 136 default: | 276 default: |
| 137 NOTREACHED(); | 277 NOTREACHED(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 167 top_icon_views_.clear(); | 307 top_icon_views_.clear(); |
| 168 | 308 |
| 169 // Show the folder icon when closing the folder. | 309 // Show the folder icon when closing the folder. |
| 170 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && | 310 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && |
| 171 apps_grid_view_->activated_folder_item_view()) { | 311 apps_grid_view_->activated_folder_item_view()) { |
| 172 apps_grid_view_->activated_folder_item_view()->SetVisible(true); | 312 apps_grid_view_->activated_folder_item_view()->SetVisible(true); |
| 173 } | 313 } |
| 174 } | 314 } |
| 175 } | 315 } |
| 176 | 316 |
| 317 void AppsContainerView::StyledLabelLinkClicked(views::StyledLabel* label, |
| 318 const gfx::Range& range, |
| 319 int event_flags) { |
| 320 #if !defined(OS_CHROMEOS) |
| 321 // The only style label is the "Learn more" link in the deprecation banner, so |
| 322 // assume that that's what was clicked. |
| 323 view_delegate_->OpenLearnMoreLink(); |
| 324 #endif // !defined(OS_CHROMEOS) |
| 325 } |
| 326 |
| 177 void AppsContainerView::SetShowState(ShowState show_state, | 327 void AppsContainerView::SetShowState(ShowState show_state, |
| 178 bool show_apps_with_animation) { | 328 bool show_apps_with_animation) { |
| 179 if (show_state_ == show_state) | 329 if (show_state_ == show_state) |
| 180 return; | 330 return; |
| 181 | 331 |
| 182 show_state_ = show_state; | 332 show_state_ = show_state; |
| 183 | 333 |
| 184 switch (show_state_) { | 334 switch (show_state_) { |
| 185 case SHOW_APPS: | 335 case SHOW_APPS: |
| 336 if (deprecation_banner_view_) |
| 337 deprecation_banner_view_->SetVisible(true); |
| 186 folder_background_view_->SetVisible(false); | 338 folder_background_view_->SetVisible(false); |
| 187 if (show_apps_with_animation) { | 339 if (show_apps_with_animation) { |
| 188 app_list_folder_view_->ScheduleShowHideAnimation(false, false); | 340 app_list_folder_view_->ScheduleShowHideAnimation(false, false); |
| 189 apps_grid_view_->ScheduleShowHideAnimation(true); | 341 apps_grid_view_->ScheduleShowHideAnimation(true); |
| 190 } else { | 342 } else { |
| 191 app_list_folder_view_->HideViewImmediately(); | 343 app_list_folder_view_->HideViewImmediately(); |
| 192 apps_grid_view_->ResetForShowApps(); | 344 apps_grid_view_->ResetForShowApps(); |
| 193 } | 345 } |
| 194 break; | 346 break; |
| 195 case SHOW_ACTIVE_FOLDER: | 347 case SHOW_ACTIVE_FOLDER: |
| 348 if (deprecation_banner_view_) |
| 349 deprecation_banner_view_->SetVisible(false); |
| 196 folder_background_view_->SetVisible(true); | 350 folder_background_view_->SetVisible(true); |
| 197 apps_grid_view_->ScheduleShowHideAnimation(false); | 351 apps_grid_view_->ScheduleShowHideAnimation(false); |
| 198 app_list_folder_view_->ScheduleShowHideAnimation(true, false); | 352 app_list_folder_view_->ScheduleShowHideAnimation(true, false); |
| 199 break; | 353 break; |
| 200 case SHOW_ITEM_REPARENT: | 354 case SHOW_ITEM_REPARENT: |
| 355 if (deprecation_banner_view_) |
| 356 deprecation_banner_view_->SetVisible(true); |
| 201 folder_background_view_->SetVisible(false); | 357 folder_background_view_->SetVisible(false); |
| 202 folder_background_view_->UpdateFolderContainerBubble( | 358 folder_background_view_->UpdateFolderContainerBubble( |
| 203 FolderBackgroundView::NO_BUBBLE); | 359 FolderBackgroundView::NO_BUBBLE); |
| 204 app_list_folder_view_->ScheduleShowHideAnimation(false, true); | 360 app_list_folder_view_->ScheduleShowHideAnimation(false, true); |
| 205 apps_grid_view_->ScheduleShowHideAnimation(true); | 361 apps_grid_view_->ScheduleShowHideAnimation(true); |
| 206 break; | 362 break; |
| 207 default: | 363 default: |
| 208 NOTREACHED(); | 364 NOTREACHED(); |
| 209 } | 365 } |
| 210 | 366 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { | 409 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { |
| 254 if (folder_item) | 410 if (folder_item) |
| 255 CreateViewsForFolderTopItemsAnimation(folder_item, false); | 411 CreateViewsForFolderTopItemsAnimation(folder_item, false); |
| 256 | 412 |
| 257 // Hide the active folder item until the animation completes. | 413 // Hide the active folder item until the animation completes. |
| 258 if (apps_grid_view_->activated_folder_item_view()) | 414 if (apps_grid_view_->activated_folder_item_view()) |
| 259 apps_grid_view_->activated_folder_item_view()->SetVisible(false); | 415 apps_grid_view_->activated_folder_item_view()->SetVisible(false); |
| 260 } | 416 } |
| 261 | 417 |
| 262 } // namespace app_list | 418 } // namespace app_list |
| OLD | NEW |