OLD | NEW |
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 dangerous_download_label_->SetPosition(child_origin); | 331 dangerous_download_label_->SetPosition(child_origin); |
332 | 332 |
333 child_origin.Offset(dangerous_download_label_->width() + kLabelPadding, 0); | 333 child_origin.Offset(dangerous_download_label_->width() + kLabelPadding, 0); |
334 gfx::Size button_size = GetButtonSize(); | 334 gfx::Size button_size = GetButtonSize(); |
335 child_origin.set_y((height() - button_size.height()) / 2); | 335 child_origin.set_y((height() - button_size.height()) / 2); |
336 if (save_button_) { | 336 if (save_button_) { |
337 save_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); | 337 save_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); |
338 child_origin.Offset(button_size.width() + kButtonPadding, 0); | 338 child_origin.Offset(button_size.width() + kButtonPadding, 0); |
339 } | 339 } |
340 discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); | 340 discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); |
341 DCHECK_EQ(GetPreferredSize().width(), | 341 } |
342 discard_button_->bounds().right() + kEndPadding); | 342 |
343 } else { | 343 if (mode_ != DANGEROUS_MODE) { |
344 dropdown_button_->SizeToPreferredSize(); | 344 dropdown_button_->SizeToPreferredSize(); |
345 dropdown_button_->SetPosition( | 345 dropdown_button_->SetPosition( |
346 gfx::Point(width() - dropdown_button_->width() - kEndPadding, | 346 gfx::Point(width() - dropdown_button_->width() - kEndPadding, |
347 (height() - dropdown_button_->height()) / 2)); | 347 (height() - dropdown_button_->height()) / 2)); |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 gfx::Size DownloadItemViewMd::GetPreferredSize() const { | 351 gfx::Size DownloadItemViewMd::GetPreferredSize() const { |
352 int width = 0; | 352 int width = 0; |
353 // We set the height to the height of two rows or text plus margins. | 353 // We set the height to the height of two rows or text plus margins. |
354 int child_height = font_list_.GetBaseline() + kVerticalTextPadding + | 354 int child_height = font_list_.GetBaseline() + kVerticalTextPadding + |
355 status_font_list_.GetHeight(); | 355 status_font_list_.GetHeight(); |
356 | 356 |
357 if (IsShowingWarningDialog()) { | 357 if (IsShowingWarningDialog()) { |
358 // Width. | 358 // Width. |
359 width = kStartPadding + kWarningIconSize + kStartPadding + | 359 width = kStartPadding + kWarningIconSize + kStartPadding + |
360 dangerous_download_label_->width() + kLabelPadding; | 360 dangerous_download_label_->width() + kLabelPadding; |
361 gfx::Size button_size = GetButtonSize(); | 361 gfx::Size button_size = GetButtonSize(); |
362 if (save_button_) | 362 if (save_button_) |
363 width += button_size.width() + kButtonPadding; | 363 width += button_size.width() + kButtonPadding; |
364 width += button_size.width() + kEndPadding; | 364 width += button_size.width() + kEndPadding; |
365 | 365 |
366 // Height: make sure the button fits and the warning icon fits. | 366 // Height: make sure the button fits and the warning icon fits. |
367 child_height = | 367 child_height = |
368 std::max({child_height, button_size.height(), kWarningIconSize}); | 368 std::max({child_height, button_size.height(), kWarningIconSize}); |
369 } else { | 369 } else { |
370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + | 370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + |
371 kProgressTextPadding + kTextWidth + | 371 kProgressTextPadding + kTextWidth + kEndPadding; |
372 dropdown_button_->GetPreferredSize().width() + kEndPadding; | |
373 } | 372 } |
374 | 373 |
| 374 if (mode_ != DANGEROUS_MODE) |
| 375 width += dropdown_button_->GetPreferredSize().width(); |
| 376 |
375 return gfx::Size(width, std::max(kDefaultHeight, | 377 return gfx::Size(width, std::max(kDefaultHeight, |
376 2 * kMinimumVerticalPadding + child_height)); | 378 2 * kMinimumVerticalPadding + child_height)); |
377 } | 379 } |
378 | 380 |
379 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { | 381 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { |
380 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); | 382 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); |
381 return true; | 383 return true; |
382 } | 384 } |
383 | 385 |
384 // Handle drag (file copy) operations. | 386 // Handle drag (file copy) operations. |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 | 961 |
960 base::string16 dangerous_label = | 962 base::string16 dangerous_label = |
961 model_.GetWarningText(font_list_, kTextWidth); | 963 model_.GetWarningText(font_list_, kTextWidth); |
962 dangerous_download_label_ = new views::Label(dangerous_label); | 964 dangerous_download_label_ = new views::Label(dangerous_label); |
963 dangerous_download_label_->SetMultiLine(true); | 965 dangerous_download_label_->SetMultiLine(true); |
964 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 966 dangerous_download_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
965 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); | 967 dangerous_download_label_->SetAutoColorReadabilityEnabled(false); |
966 AddChildView(dangerous_download_label_); | 968 AddChildView(dangerous_download_label_); |
967 SizeLabelToMinWidth(); | 969 SizeLabelToMinWidth(); |
968 | 970 |
969 dropdown_button_->SetVisible(false); | 971 dropdown_button_->SetVisible(mode_ == MALICIOUS_MODE); |
970 } | 972 } |
971 | 973 |
972 gfx::ImageSkia DownloadItemViewMd::GetWarningIcon() { | 974 gfx::ImageSkia DownloadItemViewMd::GetWarningIcon() { |
973 switch (download()->GetDangerType()) { | 975 switch (download()->GetDangerType()) { |
974 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: | 976 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL: |
975 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: | 977 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT: |
976 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: | 978 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT: |
977 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: | 979 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST: |
978 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: | 980 case content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED: |
979 return gfx::CreateVectorIcon(gfx::VectorIconId::REMOVE_CIRCLE, | 981 return gfx::CreateVectorIcon(gfx::VectorIconId::REMOVE_CIRCLE, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 SchedulePaint(); | 1116 SchedulePaint(); |
1115 } | 1117 } |
1116 | 1118 |
1117 SkColor DownloadItemViewMd::GetTextColor() const { | 1119 SkColor DownloadItemViewMd::GetTextColor() const { |
1118 return GetTextColorForThemeProvider(GetThemeProvider()); | 1120 return GetTextColorForThemeProvider(GetThemeProvider()); |
1119 } | 1121 } |
1120 | 1122 |
1121 SkColor DownloadItemViewMd::GetDimmedTextColor() const { | 1123 SkColor DownloadItemViewMd::GetDimmedTextColor() const { |
1122 return SkColorSetA(GetTextColor(), 0xC7); | 1124 return SkColorSetA(GetTextColor(), 0xC7); |
1123 } | 1125 } |
OLD | NEW |