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)); | |
|
bruthig
2016/03/31 19:39:03
Is this not needed for non-md?
Evan Stade
2016/03/31 21:07:38
no, this file is md-only.
bruthig
2016/03/31 22:46:19
Acknowledged.
| |
| 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(); |
| 395 } | 397 } |
| 396 if (dragging_) { | 398 if (dragging_) { |
| 397 if (download()->GetState() == DownloadItem::COMPLETE) { | 399 if (download()->GetState() == DownloadItem::COMPLETE) { |
| 398 IconManager* im = g_browser_process->icon_manager(); | 400 IconManager* im = g_browser_process->icon_manager(); |
| 399 gfx::Image* icon = im->LookupIconFromFilepath( | 401 gfx::Image* icon = im->LookupIconFromFilepath( |
| 400 download()->GetTargetFilePath(), IconLoader::SMALL); | 402 download()->GetTargetFilePath(), IconLoader::SMALL); |
| 401 views::Widget* widget = GetWidget(); | 403 views::Widget* widget = GetWidget(); |
| 402 DragDownloadItem(download(), icon, | 404 DragDownloadItem(download(), icon, |
| 403 widget ? widget->GetNativeView() : NULL); | 405 widget ? widget->GetNativeView() : NULL); |
| 406 ink_drop_delegate_.OnAction(views::InkDropState::ACTIVATED); | |
|
bruthig
2016/03/31 19:39:02
How come you are leaving a ripple active during a
Evan Stade
2016/03/31 21:07:38
ok, done
| |
| 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()); |
| 416 | |
| 417 if (!IsShowingWarningDialog()) { | |
| 418 ink_drop_delegate_.OnAction(views::InkDropState::HIDDEN); | |
|
bruthig
2016/03/31 19:39:02
Does it make sense to move this to the HandleClick
Evan Stade
2016/03/31 21:07:38
Done.
| |
| 419 ink_drop_delegate_.SetHovered(IsMouseHovered()); | |
|
bruthig
2016/03/31 19:39:02
Why do you need to set hovered here? When the HID
Evan Stade
2016/03/31 21:07:38
doesn't seem to really do anything. Removed.
| |
| 420 } | |
| 413 } | 421 } |
| 414 | 422 |
| 415 void DownloadItemViewMd::OnMouseCaptureLost() { | 423 void DownloadItemViewMd::OnMouseCaptureLost() { |
| 416 // Mouse should not activate us in dangerous mode. | 424 // Mouse should not activate us in dangerous mode. |
| 417 if (mode_ == DANGEROUS_MODE) | 425 if (mode_ != NORMAL_MODE) |
| 418 return; | 426 return; |
| 419 | 427 |
| 420 if (dragging_) { | 428 if (dragging_) { |
| 421 // Starting a drag results in a MouseCaptureLost. | 429 // Starting a drag results in a MouseCaptureLost. |
| 422 dragging_ = false; | 430 dragging_ = false; |
| 423 starting_drag_ = false; | 431 starting_drag_ = false; |
| 424 } | 432 } |
| 425 } | 433 } |
| 426 | 434 |
| 435 void DownloadItemViewMd::OnMouseEntered(const ui::MouseEvent& event) { | |
| 436 if (!IsShowingWarningDialog()) | |
| 437 ink_drop_delegate_.SetHovered(true); | |
|
bruthig
2016/03/31 19:39:02
How come the ButtonInkDropAnimation::OnMouseEntere
Evan Stade
2016/03/31 21:07:38
I dunno why I added this. Removed. Added a check f
| |
| 438 } | |
| 439 | |
| 440 void DownloadItemViewMd::OnMouseExited(const ui::MouseEvent& event) { | |
| 441 ink_drop_delegate_.SetHovered(false); | |
| 442 } | |
| 443 | |
| 427 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { | 444 bool DownloadItemViewMd::OnKeyPressed(const ui::KeyEvent& event) { |
| 428 // Key press should not activate us in dangerous mode. | 445 // Key press should not activate us in dangerous mode. |
| 429 if (IsShowingWarningDialog()) | 446 if (IsShowingWarningDialog()) |
| 430 return true; | 447 return true; |
| 431 | 448 |
| 432 if (event.key_code() == ui::VKEY_SPACE || | 449 if (event.key_code() == ui::VKEY_SPACE || |
| 433 event.key_code() == ui::VKEY_RETURN) { | 450 event.key_code() == ui::VKEY_RETURN) { |
| 434 // OpenDownload may delete this, so don't add any code after this line. | 451 // OpenDownload may delete this, so don't add any code after this line. |
| 435 OpenDownload(); | 452 OpenDownload(); |
| 436 return true; | 453 return true; |
| 437 } | 454 } |
| 438 return false; | 455 return false; |
| 439 } | 456 } |
| 440 | 457 |
| 441 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, | 458 bool DownloadItemViewMd::GetTooltipText(const gfx::Point& p, |
| 442 base::string16* tooltip) const { | 459 base::string16* tooltip) const { |
| 443 if (IsShowingWarningDialog()) { | 460 if (IsShowingWarningDialog()) { |
| 444 tooltip->clear(); | 461 tooltip->clear(); |
| 445 return false; | 462 return false; |
| 446 } | 463 } |
| 447 | 464 |
| 448 tooltip->assign(tooltip_text_); | 465 tooltip->assign(tooltip_text_); |
| 449 | 466 |
| 450 return true; | 467 return true; |
| 451 } | 468 } |
| 452 | 469 |
| 470 void DownloadItemViewMd::OnDragDone() { | |
| 471 ink_drop_delegate_.OnAction(views::InkDropState::DEACTIVATED); | |
|
bruthig
2016/03/31 19:39:03
FYI On Chrome-Linux I am able to get the ripple to
Evan Stade
2016/03/31 21:07:38
removed
| |
| 472 } | |
| 473 | |
| 453 void DownloadItemViewMd::GetAccessibleState(ui::AXViewState* state) { | 474 void DownloadItemViewMd::GetAccessibleState(ui::AXViewState* state) { |
| 454 state->name = accessible_name_; | 475 state->name = accessible_name_; |
| 455 state->role = ui::AX_ROLE_BUTTON; | 476 state->role = ui::AX_ROLE_BUTTON; |
| 456 if (model_.IsDangerous()) | 477 if (model_.IsDangerous()) |
| 457 state->AddStateFlag(ui::AX_STATE_DISABLED); | 478 state->AddStateFlag(ui::AX_STATE_DISABLED); |
| 458 else | 479 else |
| 459 state->AddStateFlag(ui::AX_STATE_HASPOPUP); | 480 state->AddStateFlag(ui::AX_STATE_HASPOPUP); |
| 460 } | 481 } |
| 461 | 482 |
| 462 void DownloadItemViewMd::OnThemeChanged() { | 483 void DownloadItemViewMd::OnThemeChanged() { |
| 463 UpdateColorsFromTheme(); | 484 UpdateColorsFromTheme(); |
| 464 } | 485 } |
| 465 | 486 |
| 487 scoped_ptr<views::InkDropAnimation> DownloadItemViewMd::CreateInkDropAnimation() | |
| 488 const { | |
| 489 return make_scoped_ptr(new views::FloodFillInkDropAnimation( | |
| 490 size(), last_ink_drop_location_, | |
| 491 color_utils::DeriveDefaultIconColor(GetTextColor()))); | |
| 492 } | |
| 493 | |
| 494 scoped_ptr<views::InkDropHover> DownloadItemViewMd::CreateInkDropHover() const { | |
| 495 // TODO(estade): when the item is animating open and the user hovers, the | |
|
bruthig
2016/03/31 19:39:02
Is the size still stuck if you mouse off and mouse
Evan Stade
2016/03/31 21:07:38
nope
| |
| 496 // effect gets stuck at that size and does not grow with the item. Using | |
| 497 // GetPreferredSize() instead of size() here does not fix it. | |
| 498 return make_scoped_ptr(new views::InkDropHover( | |
| 499 size(), kInkDropSmallCornerRadius, | |
| 500 GetLocalBounds().CenterPoint(), | |
| 501 color_utils::DeriveDefaultIconColor(GetTextColor()))); | |
| 502 } | |
| 503 | |
| 466 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) { | 504 void DownloadItemViewMd::OnGestureEvent(ui::GestureEvent* event) { |
| 467 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 505 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 468 HandlePressEvent(*event, true); | 506 HandlePressEvent(*event, true); |
| 469 event->SetHandled(); | 507 event->SetHandled(); |
| 508 if (mode_ == NORMAL_MODE) { | |
| 509 last_ink_drop_location_ = event->location(); | |
| 510 ink_drop_delegate_.OnAction(views::InkDropState::QUICK_ACTION); | |
|
bruthig
2016/03/31 19:39:02
I would expect the QUICK_ACTION trigger to be tied
Evan Stade
2016/03/31 21:07:38
I only did this because of this comment above the
bruthig
2016/03/31 22:46:19
If both event handling methods delegate to a commo
Evan Stade
2016/04/01 19:03:13
Why is that odd? We're calling OnAction twice in t
Evan Stade
2016/04/01 19:04:08
you can ignore this comment -- I understand better
| |
| 511 } | |
| 470 return; | 512 return; |
| 471 } | 513 } |
| 472 | 514 |
| 473 if (event->type() == ui::ET_GESTURE_TAP) { | 515 if (event->type() == ui::ET_GESTURE_TAP) { |
| 474 HandleClickEvent(*event, true); | 516 HandleClickEvent(*event, true); |
| 475 event->SetHandled(); | 517 event->SetHandled(); |
| 476 return; | 518 return; |
| 477 } | 519 } |
| 478 | 520 |
| 479 views::View::OnGestureEvent(event); | 521 views::View::OnGestureEvent(event); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 } | 1108 } |
| 1067 } | 1109 } |
| 1068 | 1110 |
| 1069 void DownloadItemViewMd::ProgressTimerFired() { | 1111 void DownloadItemViewMd::ProgressTimerFired() { |
| 1070 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only | 1112 // Only repaint for the indeterminate size case. Otherwise, we'll repaint only |
| 1071 // when there's an update notified via OnDownloadUpdated(). | 1113 // when there's an update notified via OnDownloadUpdated(). |
| 1072 if (model_.PercentComplete() < 0) | 1114 if (model_.PercentComplete() < 0) |
| 1073 SchedulePaint(); | 1115 SchedulePaint(); |
| 1074 } | 1116 } |
| 1075 | 1117 |
| 1076 SkColor DownloadItemViewMd::GetTextColor() { | 1118 SkColor DownloadItemViewMd::GetTextColor() const { |
| 1077 return GetTextColorForThemeProvider(GetThemeProvider()); | 1119 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1078 } | 1120 } |
| 1079 | 1121 |
| 1080 SkColor DownloadItemViewMd::GetDimmedTextColor() { | 1122 SkColor DownloadItemViewMd::GetDimmedTextColor() const { |
| 1081 return SkColorSetA(GetTextColor(), 0xC7); | 1123 return SkColorSetA(GetTextColor(), 0xC7); |
| 1082 } | 1124 } |
| OLD | NEW |