Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(331)

Side by Side Diff: ui/app_list/views/apps_container_view.cc

Issue 1818913004: Add deprecation warning banner to App Launcher on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tapted-applist-deprecation-mac
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/apps_container_view.h ('k') | ui/app_list/views/contents_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ui/app_list/app_list_constants.h" 12 #include "ui/app_list/app_list_constants.h"
12 #include "ui/app_list/app_list_folder_item.h" 13 #include "ui/app_list/app_list_folder_item.h"
13 #include "ui/app_list/app_list_switches.h" 14 #include "ui/app_list/app_list_switches.h"
15 #include "ui/app_list/app_list_view_delegate.h"
14 #include "ui/app_list/views/app_list_folder_view.h" 16 #include "ui/app_list/views/app_list_folder_view.h"
15 #include "ui/app_list/views/app_list_item_view.h" 17 #include "ui/app_list/views/app_list_item_view.h"
16 #include "ui/app_list/views/app_list_main_view.h" 18 #include "ui/app_list/views/app_list_main_view.h"
17 #include "ui/app_list/views/apps_grid_view.h" 19 #include "ui/app_list/views/apps_grid_view.h"
18 #include "ui/app_list/views/folder_background_view.h" 20 #include "ui/app_list/views/folder_background_view.h"
21 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/events/event.h" 22 #include "ui/events/event.h"
23 #include "ui/views/background.h"
24 #include "ui/views/border.h"
25 #include "ui/views/controls/label.h"
26 #include "ui/views/controls/styled_label.h"
27 #include "ui/views/layout/box_layout.h"
20 28
21 namespace app_list { 29 namespace app_list {
22 30
31 namespace {
32
33 #if !defined(OS_CHROMEOS)
34 // Deprecation notice dimensions.
35 const int kDeprecationBannerLabelSpacingPx = 6;
36 const int kDeprecationBannerPaddingPx = 16;
37 const int kDeprecationBannerMarginPx = 12;
38 const SkColor kDeprecationBannerBackgroundColor =
39 SkColorSetRGB(0xff, 0xfd, 0xe7);
40 const SkColor kDeprecationBannerBorderColor = SkColorSetRGB(0xc1, 0xc1, 0xc1);
41 // Relative to the platform-default font size.
42 const int kDeprecationBannerTitleSize = 2;
43 const int kDeprecationBannerTextSize = 0;
44 const SkColor kLinkColor = SkColorSetRGB(0x33, 0x67, 0xd6);
45
46 base::string16 GetDeprecationText(const AppListViewDelegate& delegate) {
47 size_t message_break;
48 base::string16 text = delegate.GetMessageText(&message_break);
49 base::string16 apps_shortcut_name = delegate.GetAppsShortcutName();
50
51 // TODO(mgiuca): Insert the Apps shortcut with an image, rather than just
52 // concatenating it into the string.
53 text.insert(message_break, apps_shortcut_name);
54 return text;
55 }
56
57 views::View* BuildDeprecationNotice(const AppListViewDelegate& delegate,
58 views::StyledLabelListener* listener) {
59 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
60 const gfx::FontList& title_font =
61 rb.GetFontListWithDelta(kDeprecationBannerTitleSize);
62 const gfx::FontList& text_font =
63 rb.GetFontListWithDelta(kDeprecationBannerTextSize);
64
65 base::string16 title = delegate.GetMessageTitle();
66 views::Label* title_label = new views::Label(title);
67 title_label->SetMultiLine(true);
68 title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
69 title_label->SetFontList(title_font);
70 title_label->SetBackgroundColor(kDeprecationBannerBackgroundColor);
71
72 base::string16 text = GetDeprecationText(delegate);
73 base::string16 learn_more = delegate.GetLearnMoreText();
74 base::string16 message = text + base::ASCIIToUTF16(" ") + learn_more;
75 size_t learn_more_start = text.size() + 1;
76 size_t learn_more_end = learn_more_start + learn_more.size();
77 views::StyledLabel* text_label = new views::StyledLabel(message, listener);
78 auto learn_more_style = views::StyledLabel::RangeStyleInfo::CreateForLink();
79 learn_more_style.color = kLinkColor;
80 text_label->AddStyleRange(gfx::Range(learn_more_start, learn_more_end),
81 learn_more_style);
82 text_label->SetDisplayedOnBackgroundColor(kDeprecationBannerBackgroundColor);
tapted 2016/03/24 02:56:34 I don't think this is enough to trigger subpixel A
Matt Giuca 2016/03/30 07:08:24 Graa... OK I tried the magic incantation: depreca
83 text_label->SetBaseFontList(text_font);
84
85 views::View* deprecation_banner_box = new views::View;
86 deprecation_banner_box->SetLayoutManager(new views::BoxLayout(
87 views::BoxLayout::kVertical, kDeprecationBannerPaddingPx,
88 kDeprecationBannerPaddingPx, kDeprecationBannerLabelSpacingPx));
89 deprecation_banner_box->AddChildView(title_label);
90 deprecation_banner_box->AddChildView(text_label);
91 deprecation_banner_box->set_background(
92 views::Background::CreateSolidBackground(
93 kDeprecationBannerBackgroundColor));
94 deprecation_banner_box->SetBorder(views::Border::CreateRoundedRectBorder(
95 1, 2, kDeprecationBannerBorderColor));
tapted 2016/03/24 04:46:12 Ah, also there's a tiny glitch here. This will pai
Matt Giuca 2016/03/30 07:08:24 Done (now based on CL 1836353005 which adds the Ro
96
97 views::View* deprecation_banner_view = new views::View;
98 deprecation_banner_view->AddChildView(deprecation_banner_box);
99 deprecation_banner_view->SetLayoutManager(new views::BoxLayout(
100 views::BoxLayout::kHorizontal, kDeprecationBannerMarginPx,
101 kDeprecationBannerMarginPx, 0));
102
103 return deprecation_banner_view;
104 }
105 #endif // !defined(OS_CHROMEOS)
106
107 } // namespace
108
23 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, 109 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view,
24 AppListModel* model) 110 AppListModel* model)
25 : show_state_(SHOW_NONE), top_icon_animation_pending_count_(0) { 111 : show_state_(SHOW_NONE),
112 view_delegate_(app_list_main_view->view_delegate()),
113 top_icon_animation_pending_count_(0) {
114 #if !defined(OS_CHROMEOS)
115 deprecation_banner_view_ = BuildDeprecationNotice(*view_delegate_, this);
116 AddChildView(deprecation_banner_view_);
117 #endif // !defined(OS_CHROMEOS)
118
26 apps_grid_view_ = new AppsGridView(app_list_main_view); 119 apps_grid_view_ = new AppsGridView(app_list_main_view);
27 int cols; 120 int cols;
28 int rows; 121 int rows;
29 if (switches::IsExperimentalAppListEnabled()) { 122 if (switches::IsExperimentalAppListEnabled()) {
30 cols = kExperimentalPreferredCols; 123 cols = kExperimentalPreferredCols;
31 rows = kExperimentalPreferredRows; 124 rows = kExperimentalPreferredRows;
32 } else if (app_list_main_view->ShouldCenterWindow()) { 125 } else if (app_list_main_view->ShouldCenterWindow()) {
33 cols = kCenteredPreferredCols; 126 cols = kCenteredPreferredCols;
34 rows = kCenteredPreferredRows; 127 rows = kCenteredPreferredRows;
35 } else { 128 } else {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 bool AppsContainerView::IsInFolderView() const { 196 bool AppsContainerView::IsInFolderView() const {
104 return show_state_ == SHOW_ACTIVE_FOLDER; 197 return show_state_ == SHOW_ACTIVE_FOLDER;
105 } 198 }
106 199
107 void AppsContainerView::ReparentDragEnded() { 200 void AppsContainerView::ReparentDragEnded() {
108 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_); 201 DCHECK_EQ(SHOW_ITEM_REPARENT, show_state_);
109 show_state_ = AppsContainerView::SHOW_APPS; 202 show_state_ = AppsContainerView::SHOW_APPS;
110 } 203 }
111 204
112 gfx::Size AppsContainerView::GetPreferredSize() const { 205 gfx::Size AppsContainerView::GetPreferredSize() const {
206 const int deprecation_banner_height =
207 deprecation_banner_view_
208 ? deprecation_banner_view_->GetPreferredSize().height()
209 : 0;
113 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); 210 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize();
114 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); 211 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize();
115 212
116 int width = std::max(grid_size.width(), folder_view_size.width()); 213 int width = std::max(grid_size.width(), folder_view_size.width());
117 int height = std::max(grid_size.height(), folder_view_size.height()); 214 int height = std::max(grid_size.height() + deprecation_banner_height,
215 folder_view_size.height());
118 return gfx::Size(width, height); 216 return gfx::Size(width, height);
119 } 217 }
120 218
121 void AppsContainerView::Layout() { 219 void AppsContainerView::Layout() {
122 gfx::Rect rect(GetContentsBounds()); 220 gfx::Rect rect(GetContentsBounds());
123 if (rect.IsEmpty()) 221 if (rect.IsEmpty())
124 return; 222 return;
125 223
224 int deprecation_banner_height = 0;
225 if (deprecation_banner_view_) {
226 deprecation_banner_height =
227 deprecation_banner_view_->GetPreferredSize().height();
228 gfx::Size deprecation_banner_size(rect.width(), deprecation_banner_height);
229 deprecation_banner_view_->SetBoundsRect(
230 gfx::Rect(rect.origin(), deprecation_banner_size));
231 }
232
126 switch (show_state_) { 233 switch (show_state_) {
127 case SHOW_APPS: 234 case SHOW_APPS:
235 rect.Inset(0, deprecation_banner_height, 0, 0);
128 apps_grid_view_->SetBoundsRect(rect); 236 apps_grid_view_->SetBoundsRect(rect);
129 break; 237 break;
130 case SHOW_ACTIVE_FOLDER: 238 case SHOW_ACTIVE_FOLDER:
131 folder_background_view_->SetBoundsRect(rect); 239 folder_background_view_->SetBoundsRect(rect);
132 app_list_folder_view_->SetBoundsRect(rect); 240 app_list_folder_view_->SetBoundsRect(rect);
133 break; 241 break;
134 case SHOW_ITEM_REPARENT: 242 case SHOW_ITEM_REPARENT:
135 break; 243 break;
136 default: 244 default:
137 NOTREACHED(); 245 NOTREACHED();
(...skipping 29 matching lines...) Expand all
167 top_icon_views_.clear(); 275 top_icon_views_.clear();
168 276
169 // Show the folder icon when closing the folder. 277 // Show the folder icon when closing the folder.
170 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) && 278 if ((show_state_ == SHOW_APPS || show_state_ == SHOW_ITEM_REPARENT) &&
171 apps_grid_view_->activated_folder_item_view()) { 279 apps_grid_view_->activated_folder_item_view()) {
172 apps_grid_view_->activated_folder_item_view()->SetVisible(true); 280 apps_grid_view_->activated_folder_item_view()->SetVisible(true);
173 } 281 }
174 } 282 }
175 } 283 }
176 284
285 void AppsContainerView::StyledLabelLinkClicked(views::StyledLabel* label,
286 const gfx::Range& range,
287 int event_flags) {
288 #if !defined(OS_CHROMEOS)
289 // The only style label is the "Learn more" link in the deprecation banner, so
290 // assume that that's what was clicked.
291 view_delegate_->OpenLearnMoreLink();
292 #endif // !defined(OS_CHROMEOS)
293 }
294
177 void AppsContainerView::SetShowState(ShowState show_state, 295 void AppsContainerView::SetShowState(ShowState show_state,
178 bool show_apps_with_animation) { 296 bool show_apps_with_animation) {
179 if (show_state_ == show_state) 297 if (show_state_ == show_state)
180 return; 298 return;
181 299
182 show_state_ = show_state; 300 show_state_ = show_state;
183 301
184 switch (show_state_) { 302 switch (show_state_) {
185 case SHOW_APPS: 303 case SHOW_APPS:
304 if (deprecation_banner_view_)
305 deprecation_banner_view_->SetVisible(true);
186 folder_background_view_->SetVisible(false); 306 folder_background_view_->SetVisible(false);
187 if (show_apps_with_animation) { 307 if (show_apps_with_animation) {
188 app_list_folder_view_->ScheduleShowHideAnimation(false, false); 308 app_list_folder_view_->ScheduleShowHideAnimation(false, false);
189 apps_grid_view_->ScheduleShowHideAnimation(true); 309 apps_grid_view_->ScheduleShowHideAnimation(true);
190 } else { 310 } else {
191 app_list_folder_view_->HideViewImmediately(); 311 app_list_folder_view_->HideViewImmediately();
192 apps_grid_view_->ResetForShowApps(); 312 apps_grid_view_->ResetForShowApps();
193 } 313 }
194 break; 314 break;
195 case SHOW_ACTIVE_FOLDER: 315 case SHOW_ACTIVE_FOLDER:
316 if (deprecation_banner_view_)
317 deprecation_banner_view_->SetVisible(false);
196 folder_background_view_->SetVisible(true); 318 folder_background_view_->SetVisible(true);
197 apps_grid_view_->ScheduleShowHideAnimation(false); 319 apps_grid_view_->ScheduleShowHideAnimation(false);
198 app_list_folder_view_->ScheduleShowHideAnimation(true, false); 320 app_list_folder_view_->ScheduleShowHideAnimation(true, false);
199 break; 321 break;
200 case SHOW_ITEM_REPARENT: 322 case SHOW_ITEM_REPARENT:
323 if (deprecation_banner_view_)
324 deprecation_banner_view_->SetVisible(true);
201 folder_background_view_->SetVisible(false); 325 folder_background_view_->SetVisible(false);
202 folder_background_view_->UpdateFolderContainerBubble( 326 folder_background_view_->UpdateFolderContainerBubble(
203 FolderBackgroundView::NO_BUBBLE); 327 FolderBackgroundView::NO_BUBBLE);
204 app_list_folder_view_->ScheduleShowHideAnimation(false, true); 328 app_list_folder_view_->ScheduleShowHideAnimation(false, true);
205 apps_grid_view_->ScheduleShowHideAnimation(true); 329 apps_grid_view_->ScheduleShowHideAnimation(true);
206 break; 330 break;
207 default: 331 default:
208 NOTREACHED(); 332 NOTREACHED();
209 } 333 }
210 334
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) { 377 void AppsContainerView::PrepareToShowApps(AppListFolderItem* folder_item) {
254 if (folder_item) 378 if (folder_item)
255 CreateViewsForFolderTopItemsAnimation(folder_item, false); 379 CreateViewsForFolderTopItemsAnimation(folder_item, false);
256 380
257 // Hide the active folder item until the animation completes. 381 // Hide the active folder item until the animation completes.
258 if (apps_grid_view_->activated_folder_item_view()) 382 if (apps_grid_view_->activated_folder_item_view())
259 apps_grid_view_->activated_folder_item_view()->SetVisible(false); 383 apps_grid_view_->activated_folder_item_view()->SetVisible(false);
260 } 384 }
261 385
262 } // namespace app_list 386 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/apps_container_view.h ('k') | ui/app_list/views/contents_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698