| 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.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 HandleClickEvent(*event, true); | 510 HandleClickEvent(*event, true); |
| 511 event->SetHandled(); | 511 event->SetHandled(); |
| 512 return; | 512 return; |
| 513 } | 513 } |
| 514 | 514 |
| 515 SetState(NORMAL, NORMAL); | 515 SetState(NORMAL, NORMAL); |
| 516 views::View::OnGestureEvent(event); | 516 views::View::OnGestureEvent(event); |
| 517 } | 517 } |
| 518 | 518 |
| 519 void DownloadItemView::ShowContextMenuForView(View* source, | 519 void DownloadItemView::ShowContextMenuForView(View* source, |
| 520 const gfx::Point& point) { | 520 const gfx::Point& point, |
| 521 ui::MenuSourceType source_type) { |
| 521 // |point| is in screen coordinates. So convert it to local coordinates first. | 522 // |point| is in screen coordinates. So convert it to local coordinates first. |
| 522 gfx::Point local_point = point; | 523 gfx::Point local_point = point; |
| 523 ConvertPointFromScreen(this, &local_point); | 524 ConvertPointFromScreen(this, &local_point); |
| 524 ShowContextMenuImpl(local_point, true); | 525 ShowContextMenuImpl(local_point, source_type); |
| 525 } | 526 } |
| 526 | 527 |
| 527 void DownloadItemView::ButtonPressed( | 528 void DownloadItemView::ButtonPressed( |
| 528 views::Button* sender, const ui::Event& event) { | 529 views::Button* sender, const ui::Event& event) { |
| 529 if (sender == discard_button_) { | 530 if (sender == discard_button_) { |
| 530 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback()) | 531 if (model_.ShouldAllowDownloadFeedback() && BeginDownloadFeedback()) |
| 531 return; | 532 return; |
| 532 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", | 533 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", |
| 533 base::Time::Now() - creation_time_); | 534 base::Time::Now() - creation_time_); |
| 534 download()->Remove(); | 535 download()->Remove(); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 } | 883 } |
| 883 | 884 |
| 884 void DownloadItemView::UpdateColorsFromTheme() { | 885 void DownloadItemView::UpdateColorsFromTheme() { |
| 885 if (dangerous_download_label_ && GetThemeProvider()) { | 886 if (dangerous_download_label_ && GetThemeProvider()) { |
| 886 dangerous_download_label_->SetEnabledColor( | 887 dangerous_download_label_->SetEnabledColor( |
| 887 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); | 888 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| 888 } | 889 } |
| 889 } | 890 } |
| 890 | 891 |
| 891 void DownloadItemView::ShowContextMenuImpl(const gfx::Point& p, | 892 void DownloadItemView::ShowContextMenuImpl(const gfx::Point& p, |
| 892 bool is_mouse_gesture) { | 893 ui::MenuSourceType source_type) { |
| 893 gfx::Point point = p; | 894 gfx::Point point = p; |
| 894 gfx::Size size; | 895 gfx::Size size; |
| 895 | 896 |
| 896 // Similar hack as in MenuButton. | 897 // Similar hack as in MenuButton. |
| 897 // We're about to show the menu from a mouse press. By showing from the | 898 // We're about to show the menu from a mouse press. By showing from the |
| 898 // mouse press event we block RootView in mouse dispatching. This also | 899 // mouse press event we block RootView in mouse dispatching. This also |
| 899 // appears to cause RootView to get a mouse pressed BEFORE the mouse | 900 // appears to cause RootView to get a mouse pressed BEFORE the mouse |
| 900 // release is seen, which means RootView sends us another mouse press no | 901 // release is seen, which means RootView sends us another mouse press no |
| 901 // matter where the user pressed. To force RootView to recalculate the | 902 // matter where the user pressed. To force RootView to recalculate the |
| 902 // mouse target during the mouse press we explicitly set the mouse handler | 903 // mouse target during the mouse press we explicitly set the mouse handler |
| 903 // to NULL. | 904 // to NULL. |
| 904 static_cast<views::internal::RootView*>(GetWidget()->GetRootView())-> | 905 static_cast<views::internal::RootView*>(GetWidget()->GetRootView())-> |
| 905 SetMouseHandler(NULL); | 906 SetMouseHandler(NULL); |
| 906 | 907 |
| 907 // If |is_mouse_gesture| is false, |p| is ignored. The menu is shown aligned | 908 // If |is_mouse_gesture| is false, |p| is ignored. The menu is shown aligned |
| 908 // to drop down arrow button. | 909 // to drop down arrow button. |
| 909 if (!is_mouse_gesture) { | 910 if (!source_type == ui::MENU_SOURCE_MOUSE) { |
| 910 drop_down_pressed_ = true; | 911 drop_down_pressed_ = true; |
| 911 SetState(NORMAL, PUSHED); | 912 SetState(NORMAL, PUSHED); |
| 912 point.SetPoint(drop_down_x_left_, box_y_); | 913 point.SetPoint(drop_down_x_left_, box_y_); |
| 913 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); | 914 size.SetSize(drop_down_x_right_ - drop_down_x_left_, box_height_); |
| 914 } | 915 } |
| 915 // Post a task to release the button. When we call the Run method on the menu | 916 // Post a task to release the button. When we call the Run method on the menu |
| 916 // below, it runs an inner message loop that might cause us to be deleted. | 917 // below, it runs an inner message loop that might cause us to be deleted. |
| 917 // Posting a task with a WeakPtr lets us safely handle the button release. | 918 // Posting a task with a WeakPtr lets us safely handle the button release. |
| 918 base::MessageLoop::current()->PostNonNestableTask( | 919 base::MessageLoop::current()->PostNonNestableTask( |
| 919 FROM_HERE, | 920 FROM_HERE, |
| 920 base::Bind(&DownloadItemView::ReleaseDropDown, | 921 base::Bind(&DownloadItemView::ReleaseDropDown, |
| 921 weak_ptr_factory_.GetWeakPtr())); | 922 weak_ptr_factory_.GetWeakPtr())); |
| 922 views::View::ConvertPointToScreen(this, &point); | 923 views::View::ConvertPointToScreen(this, &point); |
| 923 | 924 |
| 924 if (!context_menu_.get()) { | 925 if (!context_menu_.get()) { |
| 925 context_menu_.reset( | 926 context_menu_.reset( |
| 926 new DownloadShelfContextMenuView(download(), shelf_->GetNavigator())); | 927 new DownloadShelfContextMenuView(download(), shelf_->GetNavigator())); |
| 927 } | 928 } |
| 928 context_menu_->Run(GetWidget()->GetTopLevelWidget(), | 929 context_menu_->Run(GetWidget()->GetTopLevelWidget(), |
| 929 gfx::Rect(point, size)); | 930 gfx::Rect(point, size), source_type); |
| 930 // We could be deleted now. | 931 // We could be deleted now. |
| 931 } | 932 } |
| 932 | 933 |
| 933 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, | 934 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, |
| 934 bool active_event) { | 935 bool active_event) { |
| 935 // The event should not activate us in dangerous mode. | 936 // The event should not activate us in dangerous mode. |
| 936 if (mode_ == DANGEROUS_MODE) | 937 if (mode_ == DANGEROUS_MODE) |
| 937 return; | 938 return; |
| 938 | 939 |
| 939 // Stop any completion animation. | 940 // Stop any completion animation. |
| 940 if (complete_animation_.get() && complete_animation_->is_animating()) | 941 if (complete_animation_.get() && complete_animation_->is_animating()) |
| 941 complete_animation_->End(); | 942 complete_animation_->End(); |
| 942 | 943 |
| 943 if (active_event) { | 944 if (active_event) { |
| 944 if (InDropDownButtonXCoordinateRange(event.x())) { | 945 if (InDropDownButtonXCoordinateRange(event.x())) { |
| 945 drop_down_pressed_ = true; | 946 drop_down_pressed_ = true; |
| 946 SetState(NORMAL, PUSHED); | 947 SetState(NORMAL, PUSHED); |
| 947 // We are setting is_mouse_gesture to false when calling ShowContextMenu | 948 // We are setting is_mouse_gesture to false when calling ShowContextMenu |
| 948 // so that the positioning of the context menu will be similar to a | 949 // so that the positioning of the context menu will be similar to a |
| 949 // keyboard invocation. I.e. we want the menu to always be positioned | 950 // keyboard invocation. I.e. we want the menu to always be positioned |
| 950 // next to the drop down button instead of the next to the pointer. | 951 // next to the drop down button instead of the next to the pointer. |
| 951 ShowContextMenuImpl(event.location(), false); | 952 ShowContextMenuImpl(event.location(), ui::MENU_SOURCE_KEYBOARD); |
| 952 // Once called, it is possible that *this was deleted (e.g.: due to | 953 // Once called, it is possible that *this was deleted (e.g.: due to |
| 953 // invoking the 'Discard' action.) | 954 // invoking the 'Discard' action.) |
| 954 } else if (!IsShowingWarningDialog()) { | 955 } else if (!IsShowingWarningDialog()) { |
| 955 SetState(PUSHED, NORMAL); | 956 SetState(PUSHED, NORMAL); |
| 956 } | 957 } |
| 957 } | 958 } |
| 958 } | 959 } |
| 959 | 960 |
| 960 void DownloadItemView::HandleClickEvent(const ui::LocatedEvent& event, | 961 void DownloadItemView::HandleClickEvent(const ui::LocatedEvent& event, |
| 961 bool active_event) { | 962 bool active_event) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 void DownloadItemView::AnimateStateTransition(State from, State to, | 1242 void DownloadItemView::AnimateStateTransition(State from, State to, |
| 1242 ui::SlideAnimation* animation) { | 1243 ui::SlideAnimation* animation) { |
| 1243 if (from == NORMAL && to == HOT) { | 1244 if (from == NORMAL && to == HOT) { |
| 1244 animation->Show(); | 1245 animation->Show(); |
| 1245 } else if (from == HOT && to == NORMAL) { | 1246 } else if (from == HOT && to == NORMAL) { |
| 1246 animation->Hide(); | 1247 animation->Hide(); |
| 1247 } else if (from != to) { | 1248 } else if (from != to) { |
| 1248 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1249 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1249 } | 1250 } |
| 1250 } | 1251 } |
| OLD | NEW |