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

Side by Side Diff: chrome/browser/ui/views/download/download_item_view_md.cc

Issue 1750403005: [MD] some tweaks to download shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove app menu button changes 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
OLDNEW
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 "chrome/browser/ui/views/download/download_item_view_md.h" 5 #include "chrome/browser/ui/views/download/download_item_view_md.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "ui/events/event.h" 50 #include "ui/events/event.h"
51 #include "ui/gfx/animation/slide_animation.h" 51 #include "ui/gfx/animation/slide_animation.h"
52 #include "ui/gfx/canvas.h" 52 #include "ui/gfx/canvas.h"
53 #include "ui/gfx/color_palette.h" 53 #include "ui/gfx/color_palette.h"
54 #include "ui/gfx/color_utils.h" 54 #include "ui/gfx/color_utils.h"
55 #include "ui/gfx/image/image.h" 55 #include "ui/gfx/image/image.h"
56 #include "ui/gfx/paint_vector_icon.h" 56 #include "ui/gfx/paint_vector_icon.h"
57 #include "ui/gfx/text_elider.h" 57 #include "ui/gfx/text_elider.h"
58 #include "ui/gfx/text_utils.h" 58 #include "ui/gfx/text_utils.h"
59 #include "ui/gfx/vector_icons_public.h" 59 #include "ui/gfx/vector_icons_public.h"
60 #include "ui/views/animation/ink_drop_delegate.h"
60 #include "ui/views/border.h" 61 #include "ui/views/border.h"
61 #include "ui/views/controls/button/image_button.h" 62 #include "ui/views/controls/button/image_button.h"
62 #include "ui/views/controls/button/label_button.h" 63 #include "ui/views/controls/button/label_button.h"
63 #include "ui/views/controls/label.h" 64 #include "ui/views/controls/label.h"
64 #include "ui/views/mouse_constants.h" 65 #include "ui/views/mouse_constants.h"
65 #include "ui/views/widget/root_view.h" 66 #include "ui/views/widget/root_view.h"
66 #include "ui/views/widget/widget.h" 67 #include "ui/views/widget/widget.h"
67 68
68 using content::DownloadItem; 69 using content::DownloadItem;
69 using extensions::ExperienceSamplingEvent; 70 using extensions::ExperienceSamplingEvent;
(...skipping 15 matching lines...) Expand all
85 // This is only used when the text size is large. 86 // This is only used when the text size is large.
86 const int kMinimumVerticalPadding = 2 + kTopBottomPadding; 87 const int kMinimumVerticalPadding = 2 + kTopBottomPadding;
87 88
88 // Vertical padding between filename and status text. 89 // Vertical padding between filename and status text.
89 const int kVerticalTextPadding = 1; 90 const int kVerticalTextPadding = 1;
90 91
91 const int kTooltipMaxWidth = 800; 92 const int kTooltipMaxWidth = 800;
92 93
93 // Padding before the icon and at end of the item. 94 // Padding before the icon and at end of the item.
94 const int kStartPadding = 12; 95 const int kStartPadding = 12;
95 const int kEndPadding = 19; 96 const int kEndPadding = 6;
96 97
97 // Horizontal padding between progress indicator and filename/status text. 98 // Horizontal padding between progress indicator and filename/status text.
98 const int kProgressTextPadding = 8; 99 const int kProgressTextPadding = 8;
99 100
100 // The space between the Save and Discard buttons when prompting for a dangerous 101 // The space between the Save and Discard buttons when prompting for a dangerous
101 // download. 102 // download.
102 const int kButtonPadding = 5; 103 const int kButtonPadding = 5;
103 104
104 // The space on the left and right side of the dangerous download label. 105 // The touchable space around the dropdown button's icon.
106 const int kDropdownBorderWidth = 10;
107
108 // The space on the right side of the dangerous download label.
105 const int kLabelPadding = 8; 109 const int kLabelPadding = 8;
106 110
107 // Height/width of the warning icon, also in dp. 111 // Height/width of the warning icon, also in dp.
108 const int kWarningIconSize = 24; 112 const int kWarningIconSize = 24;
109 113
110 // How long the 'download complete' animation should last for. 114 // How long the 'download complete' animation should last for.
111 const int kCompleteAnimationDurationMs = 2500; 115 const int kCompleteAnimationDurationMs = 2500;
112 116
113 // How long the 'download interrupted' animation should last for. 117 // How long the 'download interrupted' animation should last for.
114 const int kInterruptedAnimationDurationMs = 2500; 118 const int kInterruptedAnimationDurationMs = 2500;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 dangerous_download_label_sized_(false), 164 dangerous_download_label_sized_(false),
161 disabled_while_opening_(false), 165 disabled_while_opening_(false),
162 creation_time_(base::Time::Now()), 166 creation_time_(base::Time::Now()),
163 time_download_warning_shown_(base::Time()), 167 time_download_warning_shown_(base::Time()),
164 weak_ptr_factory_(this) { 168 weak_ptr_factory_(this) {
165 DCHECK(download()); 169 DCHECK(download());
166 DCHECK(ui::MaterialDesignController::IsModeMaterial()); 170 DCHECK(ui::MaterialDesignController::IsModeMaterial());
167 download()->AddObserver(this); 171 download()->AddObserver(this);
168 set_context_menu_controller(this); 172 set_context_menu_controller(this);
169 173
174 dropdown_button_->SetBorder(
175 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth)));
176 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32));
170 AddChildView(dropdown_button_); 177 AddChildView(dropdown_button_);
171 178
172 LoadIcon(); 179 LoadIcon();
173 180
174 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 181 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
175 font_list_ = 182 font_list_ =
176 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); 183 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1);
177 status_font_list_ = 184 status_font_list_ =
178 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); 185 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2);
179 186
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 shelf_->OpenedDownload(); 317 shelf_->OpenedDownload();
311 } 318 }
312 319
313 // View overrides 320 // View overrides
314 321
315 // In dangerous mode we have to layout our buttons. 322 // In dangerous mode we have to layout our buttons.
316 void DownloadItemViewMd::Layout() { 323 void DownloadItemViewMd::Layout() {
317 UpdateColorsFromTheme(); 324 UpdateColorsFromTheme();
318 325
319 if (IsShowingWarningDialog()) { 326 if (IsShowingWarningDialog()) {
320 int x = kStartPadding + kWarningIconSize + kStartPadding; 327 gfx::Point child_origin(
321 int y = (height() - dangerous_download_label_->height()) / 2; 328 kStartPadding + kWarningIconSize + kStartPadding,
322 dangerous_download_label_->SetBounds(x, y, 329 (height() - dangerous_download_label_->height()) / 2);
323 dangerous_download_label_->width(), 330 dangerous_download_label_->SetPosition(child_origin);
324 dangerous_download_label_->height()); 331
332 child_origin.Offset(dangerous_download_label_->width() + kLabelPadding, 0);
325 gfx::Size button_size = GetButtonSize(); 333 gfx::Size button_size = GetButtonSize();
326 x += dangerous_download_label_->width() + kLabelPadding; 334 child_origin.set_y((height() - button_size.height()) / 2);
327 y = (height() - button_size.height()) / 2;
328 if (save_button_) { 335 if (save_button_) {
329 save_button_->SetBounds(x, y, button_size.width(), button_size.height()); 336 save_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
330 x += button_size.width() + kButtonPadding; 337 child_origin.Offset(button_size.width() + kButtonPadding, 0);
331 } 338 }
332 discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); 339 discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
340 DCHECK_EQ(GetPreferredSize().width(),
341 discard_button_->bounds().right() + kEndPadding);
333 } else { 342 } else {
334 dropdown_button_->SizeToPreferredSize(); 343 dropdown_button_->SizeToPreferredSize();
335 dropdown_button_->SetPosition( 344 dropdown_button_->SetPosition(
336 gfx::Point(width() - dropdown_button_->width(), 345 gfx::Point(width() - dropdown_button_->width() - kEndPadding,
337 (height() - dropdown_button_->height()) / 2)); 346 (height() - dropdown_button_->height()) / 2));
338 } 347 }
339 } 348 }
340 349
341 gfx::Size DownloadItemViewMd::GetPreferredSize() const { 350 gfx::Size DownloadItemViewMd::GetPreferredSize() const {
342 int width, height; 351 int width = 0;
343 352 // We set the height to the height of two rows or text plus margins.
344 // First, we set the height to the height of two rows or text plus margins. 353 int child_height = font_list_.GetBaseline() + kVerticalTextPadding +
345 height = std::max(kDefaultHeight, 354 status_font_list_.GetHeight();
346 2 * kMinimumVerticalPadding + font_list_.GetBaseline() +
347 kVerticalTextPadding + status_font_list_.GetHeight());
348 355
349 if (IsShowingWarningDialog()) { 356 if (IsShowingWarningDialog()) {
350 width = kStartPadding + kWarningIconSize + kLabelPadding + 357 // Width.
358 width = kStartPadding + kWarningIconSize + kStartPadding +
351 dangerous_download_label_->width() + kLabelPadding; 359 dangerous_download_label_->width() + kLabelPadding;
352 gfx::Size button_size = GetButtonSize(); 360 gfx::Size button_size = GetButtonSize();
353 // Make sure the button fits.
354 height = std::max<int>(height,
355 2 * kMinimumVerticalPadding + button_size.height());
356 // Then we make sure the warning icon fits.
357 height = std::max<int>(
358 height, 2 * kMinimumVerticalPadding + kWarningIconSize);
359 if (save_button_) 361 if (save_button_)
360 width += button_size.width() + kButtonPadding; 362 width += button_size.width() + kButtonPadding;
361 width += button_size.width() + kEndPadding; 363 width += button_size.width() + kEndPadding;
364
365 // Height: make sure the button fits and the warning icon fits.
366 child_height =
367 std::max({child_height, button_size.height(), kWarningIconSize});
362 } else { 368 } else {
363 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + 369 width = kStartPadding + DownloadShelf::kProgressIndicatorSize +
364 kProgressTextPadding + kTextWidth + kEndPadding; 370 kProgressTextPadding + kTextWidth +
371 dropdown_button_->GetPreferredSize().width() + kEndPadding;
365 } 372 }
366 return gfx::Size(width, height); 373
374 return gfx::Size(width, std::max(kDefaultHeight,
375 2 * kMinimumVerticalPadding + child_height));
367 } 376 }
368 377
369 // Handle a mouse click and open the context menu if the mouse is 378 // Handle a mouse click and open the context menu if the mouse is
370 // over the drop-down region. 379 // over the drop-down region.
371 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { 380 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) {
372 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); 381 HandlePressEvent(event, event.IsOnlyLeftMouseButton());
373 return true; 382 return true;
374 } 383 }
375 384
376 // Handle drag (file copy) operations. 385 // Handle drag (file copy) operations.
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 // Avoid extra SchedulePaint()s if the state is going to be the same and 817 // Avoid extra SchedulePaint()s if the state is going to be the same and
809 // |dropdown_button_| has already been initialized. 818 // |dropdown_button_| has already been initialized.
810 if (dropdown_state_ == new_state && 819 if (dropdown_state_ == new_state &&
811 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) 820 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull())
812 return; 821 return;
813 822
814 dropdown_button_->SetIcon( 823 dropdown_button_->SetIcon(
815 new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT 824 new_state == PUSHED ? gfx::VectorIconId::FIND_NEXT
816 : gfx::VectorIconId::FIND_PREV, 825 : gfx::VectorIconId::FIND_PREV,
817 base::Bind(&DownloadItemViewMd::GetTextColor, base::Unretained(this))); 826 base::Bind(&DownloadItemViewMd::GetTextColor, base::Unretained(this)));
827 dropdown_button_->ink_drop_delegate()->OnAction(
828 new_state == PUSHED ? views::InkDropState::ACTIVATED
829 : views::InkDropState::DEACTIVATED);
818 dropdown_button_->OnThemeChanged(); 830 dropdown_button_->OnThemeChanged();
819 dropdown_state_ = new_state; 831 dropdown_state_ = new_state;
820 SchedulePaint(); 832 SchedulePaint();
821 } 833 }
822 834
823 void DownloadItemViewMd::ToggleWarningDialog() { 835 void DownloadItemViewMd::ToggleWarningDialog() {
824 if (model_.IsDangerous()) 836 if (model_.IsDangerous())
825 ShowWarningDialog(); 837 ShowWarningDialog();
826 else 838 else
827 ClearWarningDialog(); 839 ClearWarningDialog();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 // If the width is growing again, it means we passed the optimal width spot. 1015 // If the width is growing again, it means we passed the optimal width spot.
1004 if (size.width() > min_width) { 1016 if (size.width() > min_width) {
1005 dangerous_download_label_->SetText(prev_text); 1017 dangerous_download_label_->SetText(prev_text);
1006 break; 1018 break;
1007 } else { 1019 } else {
1008 min_width = size.width(); 1020 min_width = size.width();
1009 } 1021 }
1010 prev_text = current_text; 1022 prev_text = current_text;
1011 } 1023 }
1012 1024
1013 dangerous_download_label_->SetBounds(0, 0, size.width(), size.height()); 1025 dangerous_download_label_->SetSize(size);
1014 dangerous_download_label_sized_ = true; 1026 dangerous_download_label_sized_ = true;
1015 } 1027 }
1016 1028
1017 void DownloadItemViewMd::Reenable() { 1029 void DownloadItemViewMd::Reenable() {
1018 disabled_while_opening_ = false; 1030 disabled_while_opening_ = false;
1019 SetEnabled(true); // Triggers a repaint. 1031 SetEnabled(true); // Triggers a repaint.
1020 } 1032 }
1021 1033
1022 void DownloadItemViewMd::ReleaseDropdown() { 1034 void DownloadItemViewMd::ReleaseDropdown() {
1023 SetDropdownState(NORMAL); 1035 SetDropdownState(NORMAL);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 SchedulePaint(); 1072 SchedulePaint();
1061 } 1073 }
1062 1074
1063 SkColor DownloadItemViewMd::GetTextColor() { 1075 SkColor DownloadItemViewMd::GetTextColor() {
1064 return GetTextColorForThemeProvider(GetThemeProvider()); 1076 return GetTextColorForThemeProvider(GetThemeProvider());
1065 } 1077 }
1066 1078
1067 SkColor DownloadItemViewMd::GetDimmedTextColor() { 1079 SkColor DownloadItemViewMd::GetDimmedTextColor() {
1068 return SkColorSetA(GetTextColor(), 0xC7); 1080 return SkColorSetA(GetTextColor(), 0xC7);
1069 } 1081 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698