| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // A view that implements one download on the Download shelf. | 5 // A view that implements one download on the Download shelf. |
| 6 // Each DownloadItemView contains an application icon, a text label | 6 // Each DownloadItemView contains an application icon, a text label |
| 7 // indicating the download's file name, a text label indicating the | 7 // indicating the download's file name, a text label indicating the |
| 8 // download's status (such as the number of bytes downloaded so far) | 8 // download's status (such as the number of bytes downloaded so far) |
| 9 // and a button for canceling an in progress download, or opening | 9 // and a button for canceling an in progress download, or opening |
| 10 // the completed download. | 10 // the completed download. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "base/timer/timer.h" | 27 #include "base/timer/timer.h" |
| 28 #include "chrome/browser/download/download_commands.h" | 28 #include "chrome/browser/download/download_commands.h" |
| 29 #include "chrome/browser/download/download_item_model.h" | 29 #include "chrome/browser/download/download_item_model.h" |
| 30 #include "chrome/browser/icon_manager.h" | 30 #include "chrome/browser/icon_manager.h" |
| 31 #include "content/public/browser/download_item.h" | 31 #include "content/public/browser/download_item.h" |
| 32 #include "content/public/browser/download_manager.h" | 32 #include "content/public/browser/download_manager.h" |
| 33 #include "ui/gfx/animation/animation_delegate.h" | 33 #include "ui/gfx/animation/animation_delegate.h" |
| 34 #include "ui/gfx/font_list.h" | 34 #include "ui/gfx/font_list.h" |
| 35 #include "ui/views/animation/ink_drop_host_view.h" | 35 #include "ui/views/animation/ink_drop_host_view.h" |
| 36 #include "ui/views/context_menu_controller.h" | 36 #include "ui/views/context_menu_controller.h" |
| 37 #include "ui/views/controls/button/vector_icon_button_delegate.h" | 37 #include "ui/views/controls/button/image_button.h" |
| 38 | 38 |
| 39 class DownloadShelfView; | 39 class DownloadShelfView; |
| 40 class DownloadShelfContextMenuView; | 40 class DownloadShelfContextMenuView; |
| 41 | 41 |
| 42 namespace extensions { | 42 namespace extensions { |
| 43 class ExperienceSamplingEvent; | 43 class ExperienceSamplingEvent; |
| 44 } | 44 } |
| 45 | 45 |
| 46 namespace gfx { | 46 namespace gfx { |
| 47 class Image; | 47 class Image; |
| 48 class ImageSkia; | 48 class ImageSkia; |
| 49 class SlideAnimation; | 49 class SlideAnimation; |
| 50 } | 50 } |
| 51 | 51 |
| 52 namespace ui { | 52 namespace ui { |
| 53 class ThemeProvider; | 53 class ThemeProvider; |
| 54 } | 54 } |
| 55 | 55 |
| 56 namespace views { | 56 namespace views { |
| 57 class Label; | 57 class Label; |
| 58 class MdTextButton; | 58 class MdTextButton; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Represents a single download item on the download shelf. Encompasses an icon, | 61 // Represents a single download item on the download shelf. Encompasses an icon, |
| 62 // text, malicious download warnings, etc. | 62 // text, malicious download warnings, etc. |
| 63 class DownloadItemView : public views::InkDropHostView, | 63 class DownloadItemView : public views::InkDropHostView, |
| 64 public views::VectorIconButtonDelegate, | 64 public views::ImageButtonDelegate, |
| 65 public views::ContextMenuController, | 65 public views::ContextMenuController, |
| 66 public content::DownloadItem::Observer, | 66 public content::DownloadItem::Observer, |
| 67 public gfx::AnimationDelegate { | 67 public gfx::AnimationDelegate { |
| 68 public: | 68 public: |
| 69 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); | 69 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); |
| 70 ~DownloadItemView() override; | 70 ~DownloadItemView() override; |
| 71 | 71 |
| 72 // Timer callback for handling animations | 72 // Timer callback for handling animations |
| 73 void UpdateDownloadProgress(); | 73 void UpdateDownloadProgress(); |
| 74 void StartDownloadProgress(); | 74 void StartDownloadProgress(); |
| 75 void StopDownloadProgress(); | 75 void StopDownloadProgress(); |
| 76 | 76 |
| 77 // Returns the base color for text on this download item, based on |theme|. | 77 // Returns the base color for text on this download item, based on |theme|. |
| 78 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); | 78 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); |
| 79 | 79 |
| 80 // IconManager::Client interface. | 80 // IconManager::Client interface. |
| 81 void OnExtractIconComplete(gfx::Image* icon); | 81 void OnExtractIconComplete(gfx::Image* icon); |
| 82 | 82 |
| 83 // Returns the DownloadItem model object belonging to this item. | 83 // Returns the DownloadItem model object belonging to this item. |
| 84 content::DownloadItem* download() { return model_.download(); } | 84 content::DownloadItem* download() { return model_.download(); } |
| 85 | 85 |
| 86 // Submits download to download feedback service if the user has approved and | 86 // Submits download to download feedback service if the user has approved and |
| 87 // the download is suitable for submission, then apply |download_command|. | 87 // the download is suitable for submission, then apply |download_command|. |
| 88 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first. | 88 // If user hasn't seen SBER opt-in text before, show SBER opt-in dialog first. |
| 89 void MaybeSubmitDownloadToFeedbackService( | 89 void MaybeSubmitDownloadToFeedbackService( |
| 90 DownloadCommands::Command download_command); | 90 DownloadCommands::Command download_command); |
| 91 | 91 |
| 92 // DownloadItem::Observer methods | 92 // content::DownloadItem::Observer: |
| 93 void OnDownloadUpdated(content::DownloadItem* download) override; | 93 void OnDownloadUpdated(content::DownloadItem* download) override; |
| 94 void OnDownloadOpened(content::DownloadItem* download) override; | 94 void OnDownloadOpened(content::DownloadItem* download) override; |
| 95 void OnDownloadDestroyed(content::DownloadItem* download) override; | 95 void OnDownloadDestroyed(content::DownloadItem* download) override; |
| 96 | 96 |
| 97 // Overridden from views::View: | 97 // views::View: |
| 98 void Layout() override; | 98 void Layout() override; |
| 99 gfx::Size GetPreferredSize() const override; | 99 gfx::Size GetPreferredSize() const override; |
| 100 bool OnMousePressed(const ui::MouseEvent& event) override; | 100 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 101 bool OnMouseDragged(const ui::MouseEvent& event) override; | 101 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 102 void OnMouseReleased(const ui::MouseEvent& event) override; | 102 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 103 void OnMouseCaptureLost() override; | 103 void OnMouseCaptureLost() override; |
| 104 bool OnKeyPressed(const ui::KeyEvent& event) override; | 104 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 105 bool GetTooltipText(const gfx::Point& p, | 105 bool GetTooltipText(const gfx::Point& p, |
| 106 base::string16* tooltip) const override; | 106 base::string16* tooltip) const override; |
| 107 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 107 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 108 void OnThemeChanged() override; | 108 void OnThemeChanged() override; |
| 109 | 109 |
| 110 // Overridden from view::InkDropHostView: | 110 // view::InkDropHostView: |
| 111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 112 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | 112 std::unique_ptr<views::InkDrop> CreateInkDrop() override; |
| 113 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | 113 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; |
| 114 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 114 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 115 const override; | 115 const override; |
| 116 | 116 |
| 117 // Overridden from ui::EventHandler: | 117 // ui::EventHandler: |
| 118 void OnGestureEvent(ui::GestureEvent* event) override; | 118 void OnGestureEvent(ui::GestureEvent* event) override; |
| 119 | 119 |
| 120 // Overridden from views::ContextMenuController. | 120 // views::ContextMenuController. |
| 121 void ShowContextMenuForView(View* source, | 121 void ShowContextMenuForView(View* source, |
| 122 const gfx::Point& point, | 122 const gfx::Point& point, |
| 123 ui::MenuSourceType source_type) override; | 123 ui::MenuSourceType source_type) override; |
| 124 | 124 |
| 125 // VectorIconButtonDelegate implementation. | 125 // views::ImageButtonDelegate: |
| 126 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 126 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 127 SkColor GetVectorIconBaseColor() const override; | 127 SkColor GetVectorIconColor() const override; |
| 128 | 128 |
| 129 // gfx::AnimationDelegate implementation. | 129 // gfx::AnimationDelegate: |
| 130 void AnimationProgressed(const gfx::Animation* animation) override; | 130 void AnimationProgressed(const gfx::Animation* animation) override; |
| 131 | 131 |
| 132 protected: | 132 protected: |
| 133 // Overridden from views::View: | 133 // views::View: |
| 134 void OnPaint(gfx::Canvas* canvas) override; | 134 void OnPaint(gfx::Canvas* canvas) override; |
| 135 void OnFocus() override; | 135 void OnFocus() override; |
| 136 void OnBlur() override; | 136 void OnBlur() override; |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest, | 139 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest, |
| 140 AdjustTextAndGetSize); | 140 AdjustTextAndGetSize); |
| 141 | 141 |
| 142 enum State { NORMAL = 0, HOT, PUSHED }; | 142 enum State { NORMAL = 0, HOT, PUSHED }; |
| 143 class DropDownButton; | 143 class DropDownButton; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; | 338 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; |
| 339 | 339 |
| 340 // Method factory used to delay reenabling of the item when opening the | 340 // Method factory used to delay reenabling of the item when opening the |
| 341 // downloaded file. | 341 // downloaded file. |
| 342 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; | 342 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; |
| 343 | 343 |
| 344 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); | 344 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); |
| 345 }; | 345 }; |
| 346 | 346 |
| 347 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ | 347 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ |
| OLD | NEW |