Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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/flood_fill_ink_drop_animation.h" | |
| 60 #include "ui/views/animation/ink_drop_delegate.h" | 61 #include "ui/views/animation/ink_drop_delegate.h" |
| 62 #include "ui/views/animation/ink_drop_hover.h" | |
| 61 #include "ui/views/border.h" | 63 #include "ui/views/border.h" |
| 62 #include "ui/views/controls/button/image_button.h" | 64 #include "ui/views/controls/button/image_button.h" |
| 63 #include "ui/views/controls/button/label_button.h" | 65 #include "ui/views/controls/button/label_button.h" |
| 64 #include "ui/views/controls/button/md_text_button.h" | 66 #include "ui/views/controls/button/md_text_button.h" |
| 65 #include "ui/views/controls/label.h" | 67 #include "ui/views/controls/label.h" |
| 66 #include "ui/views/mouse_constants.h" | 68 #include "ui/views/mouse_constants.h" |
| 67 #include "ui/views/widget/root_view.h" | 69 #include "ui/views/widget/root_view.h" |
| 68 #include "ui/views/widget/widget.h" | 70 #include "ui/views/widget/widget.h" |
| 69 | 71 |
| 70 using content::DownloadItem; | 72 using content::DownloadItem; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 | 153 |
| 152 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, | 154 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, |
| 153 DownloadShelfView* parent) | 155 DownloadShelfView* parent) |
| 154 : shelf_(parent), | 156 : shelf_(parent), |
| 155 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 157 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 156 dropdown_state_(NORMAL), | 158 dropdown_state_(NORMAL), |
| 157 mode_(NORMAL_MODE), | 159 mode_(NORMAL_MODE), |
| 158 dragging_(false), | 160 dragging_(false), |
| 159 starting_drag_(false), | 161 starting_drag_(false), |
| 160 model_(download_item), | 162 model_(download_item), |
| 163 ink_drop_delegate_(this, this), | |
| 161 save_button_(nullptr), | 164 save_button_(nullptr), |
| 162 discard_button_(nullptr), | 165 discard_button_(nullptr), |
| 163 dropdown_button_(new BarControlButton(this)), | 166 dropdown_button_(new BarControlButton(this)), |
| 164 dangerous_download_label_(nullptr), | 167 dangerous_download_label_(nullptr), |
| 165 dangerous_download_label_sized_(false), | 168 dangerous_download_label_sized_(false), |
| 166 disabled_while_opening_(false), | 169 disabled_while_opening_(false), |
| 167 creation_time_(base::Time::Now()), | 170 creation_time_(base::Time::Now()), |
| 168 time_download_warning_shown_(base::Time()), | 171 time_download_warning_shown_(base::Time()), |
| 169 weak_ptr_factory_(this) { | 172 weak_ptr_factory_(this) { |
| 170 DCHECK(download()); | 173 DCHECK(download()); |
| 171 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | 174 DCHECK(ui::MaterialDesignController::IsModeMaterial()); |
| 172 download()->AddObserver(this); | 175 download()->AddObserver(this); |
| 173 set_context_menu_controller(this); | 176 set_context_menu_controller(this); |
| 174 | 177 |
| 175 dropdown_button_->SetBorder( | 178 dropdown_button_->SetBorder( |
| 176 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); | 179 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); |
| 177 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); | 180 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); |
| 178 AddChildView(dropdown_button_); | 181 AddChildView(dropdown_button_); |
| 179 | 182 |
| 180 LoadIcon(); | 183 LoadIcon(); |
| 181 | 184 |
| 182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 185 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 183 font_list_ = | 186 font_list_ = |
| 184 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); | 187 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); |
| 185 status_font_list_ = | 188 status_font_list_ = |
| 186 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); | 189 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); |
| 187 | 190 |
| 188 body_hover_animation_.reset(new gfx::SlideAnimation(this)); | |
| 189 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); | |
| 190 | |
| 191 SetAccessibilityFocusable(true); | 191 SetAccessibilityFocusable(true); |
| 192 | 192 |
| 193 OnDownloadUpdated(download()); | 193 OnDownloadUpdated(download()); |
| 194 | 194 |
| 195 SetDropdownState(NORMAL); | 195 SetDropdownState(NORMAL); |
| 196 UpdateColorsFromTheme(); | 196 UpdateColorsFromTheme(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 DownloadItemViewMd::~DownloadItemViewMd() { | 199 DownloadItemViewMd::~DownloadItemViewMd() { |
| 200 StopDownloadProgress(); | 200 StopDownloadProgress(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 } else { | 369 } else { |
| 370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + | 370 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + |
| 371 kProgressTextPadding + kTextWidth + | 371 kProgressTextPadding + kTextWidth + |
| 372 dropdown_button_->GetPreferredSize().width() + kEndPadding; | 372 dropdown_button_->GetPreferredSize().width() + kEndPadding; |
| 373 } | 373 } |
| 374 | 374 |
| 375 return gfx::Size(width, std::max(kDefaultHeight, | 375 return gfx::Size(width, std::max(kDefaultHeight, |
| 376 2 * kMinimumVerticalPadding + child_height)); | 376 2 * kMinimumVerticalPadding + child_height)); |
| 377 } | 377 } |
| 378 | 378 |
| 379 // Handle a mouse click and open the context menu if the mouse is | |
| 380 // over the drop-down region. | |
| 381 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { | 379 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { |
| 382 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); | 380 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); |
| 381 if (!IsShowingWarningDialog()) { | |
| 382 last_ink_drop_location_ = event.location(); | |
| 383 ink_drop_delegate_.OnAction(views::InkDropState::ACTION_PENDING); | |
| 384 } | |
| 383 return true; | 385 return true; |
| 384 } | 386 } |
| 385 | 387 |
| 386 // Handle drag (file copy) operations. | 388 // Handle drag (file copy) operations. |
| 387 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) { | 389 bool DownloadItemViewMd::OnMouseDragged(const ui::MouseEvent& event) { |
| 388 // Mouse should not activate us in dangerous mode. | 390 // Mouse should not activate us in dangerous mode. |
| 389 if (IsShowingWarningDialog()) | 391 if (IsShowingWarningDialog()) |
| 390 return true; | 392 return true; |
| 391 | 393 |
| 392 if (!starting_drag_) { | 394 if (!starting_drag_) { |
| 393 starting_drag_ = true; | 395 starting_drag_ = true; |
| 394 drag_start_point_ = event.location(); | 396 drag_start_point_ = event.location(); |
| 397 ink_drop_delegate_.OnAction(views::InkDropState::HIDDEN); | |
| 395 } | 398 } |
| 396 if (dragging_) { | 399 if (dragging_) { |
| 397 if (download()->GetState() == DownloadItem::COMPLETE) { | 400 if (download()->GetState() == DownloadItem::COMPLETE) { |
| 398 IconManager* im = g_browser_process->icon_manager(); | 401 IconManager* im = g_browser_process->icon_manager(); |
| 399 gfx::Image* icon = im->LookupIconFromFilepath( | 402 gfx::Image* icon = im->LookupIconFromFilepath( |
| 400 download()->GetTargetFilePath(), IconLoader::SMALL); | 403 download()->GetTargetFilePath(), IconLoader::SMALL); |
| 401 views::Widget* widget = GetWidget(); | 404 views::Widget* widget = GetWidget(); |
| 402 DragDownloadItem(download(), icon, | 405 DragDownloadItem(download(), icon, |
| 403 widget ? widget->GetNativeView() : NULL); | 406 widget ? widget->GetNativeView() : NULL); |
| 404 } | 407 } |
| 405 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { | 408 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { |
| 406 dragging_ = true; | 409 dragging_ = true; |
| 407 } | 410 } |
| 408 return true; | 411 return true; |
| 409 } | 412 } |
| 410 | 413 |
| 411 void DownloadItemViewMd::OnMouseReleased(const ui::MouseEvent& event) { | 414 void DownloadItemViewMd::OnMouseReleased(const ui::MouseEvent& event) { |
| 412 HandleClickEvent(event, event.IsOnlyLeftMouseButton()); | 415 HandleClickEvent(event, event.IsOnlyLeftMouseButton()); |
| 413 } | 416 } |
| 414 | 417 |
| 415 void DownloadItemViewMd::OnMouseCaptureLost() { | 418 void DownloadItemViewMd::OnMouseCaptureLost() { |
| 416 // Mouse should not activate us in dangerous mode. | 419 // Mouse should not activate us in dangerous mode. |
| 417 if (mode_ == DANGEROUS_MODE) | 420 if (mode_ != NORMAL_MODE) |
| 418 return; | 421 return; |
| 419 | 422 |
| 420 if (dragging_) { | 423 if (dragging_) { |
| 421 // Starting a drag results in a MouseCaptureLost. | 424 // Starting a drag results in a MouseCaptureLost. |
| 422 dragging_ = false; | 425 dragging_ = false; |
| 423 starting_drag_ = false; | 426 starting_drag_ = false; |
| 424 } | 427 } |
| 425 } | 428 } |
| 426 | 429 |
| 427 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { | 430 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { |
| 428 // Key press should not activate us in dangerous mode. | 431 // Key press should not activate us in dangerous mode. |
| 429 if (IsShowingWarningDialog()) | 432 if (IsShowingWarningDialog()) |
| 430 return true; | 433 return true; |
| 431 | 434 |
| 432 if (event.key_code() == ui::VKEY_SPACE || | 435 if (event.key_code() == ui::VKEY_SPACE || |
| 433 event.key_code() == ui::VKEY_RETURN) { | 436 event.key_code() == ui::VKEY_RETURN) { |
| 437 last_ink_drop_location_ = GetLocalBounds().CenterPoint(); | |
| 438 ink_drop_delegate_.OnAction(views::InkDropState::QUICK_ACTION); | |
| 434 // OpenDownload may delete this, so don't add any code after this line. | 439 // OpenDownload may delete this, so don't add any code after this line. |
| 435 OpenDownload(); | 440 OpenDownload(); |
| 436 return true; | 441 return true; |
| 437 } | 442 } |
| 438 return false; | 443 return false; |
| 439 } | 444 } |
| 440 | 445 |
| 441 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, | 446 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, |
| 442 base::string16* tooltip) const { | 447 base::string16* tooltip) const { |
| 443 if (IsShowingWarningDialog()) { | 448 if (IsShowingWarningDialog()) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 456 if (model_.IsDangerous()) | 461 if (model_.IsDangerous()) |
| 457 state->AddStateFlag(ui::AX_STATE_DISABLED); | 462 state->AddStateFlag(ui::AX_STATE_DISABLED); |
| 458 else | 463 else |
| 459 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 464 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 460 } | 465 } |
| 461 | 466 |
| 462 void DownloadItemViewMd::OnThemeChanged() { | 467 void DownloadItemViewMd::OnThemeChanged() { |
| 463 UpdateColorsFromTheme(); | 468 UpdateColorsFromTheme(); |
| 464 } | 469 } |
| 465 | 470 |
| 471 scoped_ptr<views::InkDropAnimation> DownloadItemViewMd::CreateInkDropAnimation() | |
| 472 const { | |
| 473 return make_scoped_ptr(new views::FloodFillInkDropAnimation( | |
| 474 size(), last_ink_drop_location_, | |
| 475 color_utils::DeriveDefaultIconColor(GetTextColor()))); | |
| 476 } | |
| 477 | |
| 478 scoped_ptr<views::InkDropHover> DownloadItemViewMd::CreateInkDropHover() const { | |
| 479 if (IsShowingWarningDialog()) | |
| 480 return nullptr; | |
| 481 | |
| 482 // TODO(estade): when the item is animating open and the user hovers, the | |
| 483 // effect gets stuck at that size and does not grow with the item. Using | |
| 484 // GetPreferredSize() instead of size() here does not fix it. | |
| 485 return make_scoped_ptr(new views::InkDropHover( | |
| 486 size(), kInkDropSmallCornerRadius, | |
| 487 GetLocalBounds().CenterPoint(), | |
| 488 color_utils::DeriveDefaultIconColor(GetTextColor()))); | |
| 489 } | |
| 490 | |
| 466 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) { | 491 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) { |
| 467 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 492 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 468 HandlePressEvent(*event, true); | 493 HandlePressEvent(*event, true); |
| 469 event->SetHandled(); | 494 event->SetHandled(); |
| 495 if (mode_ == NORMAL_MODE) { | |
| 496 last_ink_drop_location_ = event->location(); | |
| 497 ink_drop_delegate_.OnAction(views::InkDropState::QUICK_ACTION); | |
| 498 } | |
| 470 return; | 499 return; |
| 471 } | 500 } |
| 472 | 501 |
| 473 if (event->type() == ui::ET_GESTURE_TAP) { | 502 if (event->type() == ui::ET_GESTURE_TAP) { |
| 474 HandleClickEvent(*event, true); | 503 HandleClickEvent(*event, true); |
| 475 event->SetHandled(); | 504 event->SetHandled(); |
| 476 return; | 505 return; |
| 477 } | 506 } |
| 478 | 507 |
| 479 views::View::OnGestureEvent(event); | 508 views::View::OnGestureEvent(event); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 | 832 |
| 804 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event, | 833 void DownloadItemViewMd::HandleClickEvent(const ui::LocatedEvent& event, |
| 805 bool active_event) { | 834 bool active_event) { |
| 806 // Mouse should not activate us in dangerous mode. | 835 // Mouse should not activate us in dangerous mode. |
| 807 if (mode_ == DANGEROUS_MODE) | 836 if (mode_ == DANGEROUS_MODE) |
| 808 return; | 837 return; |
| 809 | 838 |
| 810 if (!active_event || IsShowingWarningDialog()) | 839 if (!active_event || IsShowingWarningDialog()) |
| 811 return; | 840 return; |
| 812 | 841 |
| 842 ink_drop_delegate_.OnAction(views::InkDropState::HIDDEN); | |
|
bruthig
2016/03/31 22:46:19
Is this necessary? The QUICK_ACTION animations sh
Evan Stade
2016/04/01 19:03:13
ok, no it's not.
| |
| 843 | |
| 813 // OpenDownload may delete this, so don't add any code after this line. | 844 // OpenDownload may delete this, so don't add any code after this line. |
| 814 OpenDownload(); | 845 OpenDownload(); |
| 815 } | 846 } |
| 816 | 847 |
| 817 void DownloadItemViewMd::SetDropdownState(State new_state) { | 848 void DownloadItemViewMd::SetDropdownState(State new_state) { |
| 818 // Avoid extra SchedulePaint()s if the state is going to be the same and | 849 // Avoid extra SchedulePaint()s if the state is going to be the same and |
| 819 // |dropdown_button_| has already been initialized. | 850 // |dropdown_button_| has already been initialized. |
| 820 if (dropdown_state_ == new_state && | 851 if (dropdown_state_ == new_state && |
| 821 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) | 852 !dropdown_button_->GetImage(views::CustomButton::STATE_NORMAL).isNull()) |
| 822 return; | 853 return; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 } | 1097 } |
| 1067 } | 1098 } |
| 1068 | 1099 |
| 1069 void DownloadItemViewMd::ProgressTimerFired() { | 1100 void DownloadItemViewMd::ProgressTimerFired() { |
| 1070 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only | 1101 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only |
| 1071 // when there's an update notified via OnDownloadUpdated(). | 1102 // when there's an update notified via OnDownloadUpdated(). |
| 1072 if (model_.PercentComplete() < 0) | 1103 if (model_.PercentComplete() < 0) |
| 1073 SchedulePaint(); | 1104 SchedulePaint(); |
| 1074 } | 1105 } |
| 1075 | 1106 |
| 1076 SkColor DownloadItemViewMd::GetTextColor() { | 1107 SkColor DownloadItemViewMd::GetTextColor() const { |
| 1077 return GetTextColorForThemeProvider(GetThemeProvider()); | 1108 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1078 } | 1109 } |
| 1079 | 1110 |
| 1080 SkColor DownloadItemViewMd::GetDimmedTextColor() { | 1111 SkColor DownloadItemViewMd::GetDimmedTextColor() const { |
| 1081 return SkColorSetA(GetTextColor(), 0xC7); | 1112 return SkColorSetA(GetTextColor(), 0xC7); |
| 1082 } | 1113 } |
| OLD | NEW |