| 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" | |
| 14 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 15 #include "ui/app_list/app_list_folder_item.h" | 12 #include "ui/app_list/app_list_folder_item.h" |
| 16 #include "ui/app_list/app_list_switches.h" | 13 #include "ui/app_list/app_list_switches.h" |
| 17 #include "ui/app_list/app_list_view_delegate.h" | |
| 18 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
| 19 #include "ui/app_list/views/app_list_item_view.h" | 15 #include "ui/app_list/views/app_list_item_view.h" |
| 20 #include "ui/app_list/views/app_list_main_view.h" | 16 #include "ui/app_list/views/app_list_main_view.h" |
| 21 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
| 22 #include "ui/app_list/views/folder_background_view.h" | 18 #include "ui/app_list/views/folder_background_view.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | |
| 24 #include "ui/events/event.h" | 19 #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" | |
| 32 | 20 |
| 33 namespace app_list { | 21 namespace app_list { |
| 34 | 22 |
| 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 | |
| 141 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, | 23 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, |
| 142 AppListModel* model) | 24 AppListModel* model) |
| 143 : show_state_(SHOW_NONE), | 25 : show_state_(SHOW_NONE), top_icon_animation_pending_count_(0) { |
| 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 | |
| 151 apps_grid_view_ = new AppsGridView(app_list_main_view); | 26 apps_grid_view_ = new AppsGridView(app_list_main_view); |
| 152 int cols; | 27 int cols; |
| 153 int rows; | 28 int rows; |
| 154 if (switches::IsExperimentalAppListEnabled()) { | 29 if (switches::IsExperimentalAppListEnabled()) { |
| 155 cols = kExperimentalPreferredCols; | 30 cols = kExperimentalPreferredCols; |
| 156 rows = kExperimentalPreferredRows; | 31 rows = kExperimentalPreferredRows; |
| 157 } else if (app_list_main_view->ShouldCenterWindow()) { | 32 } else if (app_list_main_view->ShouldCenterWindow()) { |
| 158 cols = kCenteredPreferredCols; | 33 cols = kCenteredPreferredCols; |
| 159 rows = kCenteredPreferredRows; | 34 rows = kCenteredPreferredRows; |
| 160 } else { | 35 } else { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 bool AppsContainerView::IsInFolderView() const { | 103 bool AppsContainerView::IsInFolderView() const { |
| 229 return show_state_ == SHOW_ACTIVE_FOLDER; | 104 return show_state_ == SHOW_ACTIVE_FOLDER; |
| 230 } | 105 } |
| 231 | 106 |
| 232 void AppsContainerView::ReparentDragEnded() { | 107 void AppsContainerView::ReparentDragEnded() { |
| 233 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_); | 108 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_); |
| 234 show_state_ = AppsContainerView::SHOW_APPS; | 109 show_state_ = AppsContainerView::SHOW_APPS; |
| 235 } | 110 } |
| 236 | 111 |
| 237 gfx::Size AppsContainerView::GetPreferredSize() const { | 112 gfx::Size AppsContainerView::GetPreferredSize() const { |
| 238 const int deprecation_banner_height = | |
| 239 deprecation_banner_view_ | |
| 240 ? deprecation_banner_view_->GetPreferredSize().height() | |
| 241 : 0; | |
| 242 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); | 113 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); |
| 243 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); | 114 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); |
| 244 | 115 |
| 245 int width = std::max(grid_size.width(), folder_view_size.width()); | 116 int width = std::max(grid_size.width(), folder_view_size.width()); |
| 246 int height = std::max(grid_size.height() + deprecation_banner_height, | 117 int height = std::max(grid_size.height(), folder_view_size.height()); |
| 247 folder_view_size.height()); | |
| 248 return gfx::Size(width, height); | 118 return gfx::Size(width, height); |
| 249 } | 119 } |
| 250 | 120 |
| 251 void AppsContainerView::Layout() { | 121 void AppsContainerView::Layout() { |
| 252 gfx::Rect rect(GetContentsBounds()); | 122 gfx::Rect rect(GetContentsBounds()); |
| 253 if (rect.IsEmpty()) | 123 if (rect.IsEmpty()) |
| 254 return; | 124 return; |
| 255 | 125 |
| 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 | |
| 265 switch (show_state_) { | 126 switch (show_state_) { |
| 266 case SHOW_APPS: | 127 case SHOW_APPS: |
| 267 rect.Inset(0, deprecation_banner_height, 0, 0); | |
| 268 apps_grid_view_->SetBoundsRect(rect); | 128 apps_grid_view_->SetBoundsRect(rect); |
| 269 break; | 129 break; |
| 270 case SHOW_ACTIVE_FOLDER: | 130 case SHOW_ACTIVE_FOLDER: |
| 271 folder_background_view_->SetBoundsRect(rect); | 131 folder_background_view_->SetBoundsRect(rect); |
| 272 app_list_folder_view_->SetBoundsRect(rect); | 132 app_list_folder_view_->SetBoundsRect(rect); |
| 273 break; | 133 break; |
| 274 case SHOW_ITEM_REPARENT: | 134 case SHOW_ITEM_REPARENT: |
| 275 break; | 135 break; |
| 276 default: | 136 default: |
| 277 NOTREACHED(); | 137 NOTREACHED(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 307 top_icon_views_.clear(); | 167 top_icon_views_.clear(); |
| 308 | 168 |
| 309 // Show the folder icon when closing the folder. | 169 // Show the folder icon when closing the folder. |
| 310 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && | 170 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && |
| 311 apps_grid_view_->activated_folder_item_view()) { | 171 apps_grid_view_->activated_folder_item_view()) { |
| 312 apps_grid_view_->activated_folder_item_view()->SetVisible(true); | 172 apps_grid_view_->activated_folder_item_view()->SetVisible(true); |
| 313 } | 173 } |
| 314 } | 174 } |
| 315 } | 175 } |
| 316 | 176 |
| 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 | |
| 327 void AppsContainerView::SetShowState(ShowState show_state, | 177 void AppsContainerView::SetShowState(ShowState show_state, |
| 328 bool show_apps_with_animation) { | 178 bool show_apps_with_animation) { |
| 329 if (show_state_ == show_state) | 179 if (show_state_ == show_state) |
| 330 return; | 180 return; |
| 331 | 181 |
| 332 show_state_ = show_state; | 182 show_state_ = show_state; |
| 333 | 183 |
| 334 switch (show_state_) { | 184 switch (show_state_) { |
| 335 case SHOW_APPS: | 185 case SHOW_APPS: |
| 336 if (deprecation_banner_view_) | |
| 337 deprecation_banner_view_->SetVisible(true); | |
| 338 folder_background_view_->SetVisible(false); | 186 folder_background_view_->SetVisible(false); |
| 339 if (show_apps_with_animation) { | 187 if (show_apps_with_animation) { |
| 340 app_list_folder_view_->ScheduleShowHideAnimation(false, false); | 188 app_list_folder_view_->ScheduleShowHideAnimation(false, false); |
| 341 apps_grid_view_->ScheduleShowHideAnimation(true); | 189 apps_grid_view_->ScheduleShowHideAnimation(true); |
| 342 } else { | 190 } else { |
| 343 app_list_folder_view_->HideViewImmediately(); | 191 app_list_folder_view_->HideViewImmediately(); |
| 344 apps_grid_view_->ResetForShowApps(); | 192 apps_grid_view_->ResetForShowApps(); |
| 345 } | 193 } |
| 346 break; | 194 break; |
| 347 case SHOW_ACTIVE_FOLDER: | 195 case SHOW_ACTIVE_FOLDER: |
| 348 if (deprecation_banner_view_) | |
| 349 deprecation_banner_view_->SetVisible(false); | |
| 350 folder_background_view_->SetVisible(true); | 196 folder_background_view_->SetVisible(true); |
| 351 apps_grid_view_->ScheduleShowHideAnimation(false); | 197 apps_grid_view_->ScheduleShowHideAnimation(false); |
| 352 app_list_folder_view_->ScheduleShowHideAnimation(true, false); | 198 app_list_folder_view_->ScheduleShowHideAnimation(true, false); |
| 353 break; | 199 break; |
| 354 case SHOW_ITEM_REPARENT: | 200 case SHOW_ITEM_REPARENT: |
| 355 if (deprecation_banner_view_) | |
| 356 deprecation_banner_view_->SetVisible(true); | |
| 357 folder_background_view_->SetVisible(false); | 201 folder_background_view_->SetVisible(false); |
| 358 folder_background_view_->UpdateFolderContainerBubble( | 202 folder_background_view_->UpdateFolderContainerBubble( |
| 359 FolderBackgroundView::NO_BUBBLE); | 203 FolderBackgroundView::NO_BUBBLE); |
| 360 app_list_folder_view_->ScheduleShowHideAnimation(false, true); | 204 app_list_folder_view_->ScheduleShowHideAnimation(false, true); |
| 361 apps_grid_view_->ScheduleShowHideAnimation(true); | 205 apps_grid_view_->ScheduleShowHideAnimation(true); |
| 362 break; | 206 break; |
| 363 default: | 207 default: |
| 364 NOTREACHED(); | 208 NOTREACHED(); |
| 365 } | 209 } |
| 366 | 210 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { | 253 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { |
| 410 if (folder_item) | 254 if (folder_item) |
| 411 CreateViewsForFolderTopItemsAnimation(folder_item, false); | 255 CreateViewsForFolderTopItemsAnimation(folder_item, false); |
| 412 | 256 |
| 413 // Hide the active folder item until the animation completes. | 257 // Hide the active folder item until the animation completes. |
| 414 if (apps_grid_view_->activated_folder_item_view()) | 258 if (apps_grid_view_->activated_folder_item_view()) |
| 415 apps_grid_view_->activated_folder_item_view()->SetVisible(false); | 259 apps_grid_view_->activated_folder_item_view()->SetVisible(false); |
| 416 } | 260 } |
| 417 | 261 |
| 418 } // namespace app_list | 262 } // namespace app_list |
| OLD | NEW |