| 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/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 ImageButton; |
| 57 class Label; | 58 class Label; |
| 58 class MdTextButton; | 59 class MdTextButton; |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Represents a single download item on the download shelf. Encompasses an icon, | 62 // Represents a single download item on the download shelf. Encompasses an icon, |
| 62 // text, malicious download warnings, etc. | 63 // text, malicious download warnings, etc. |
| 63 class DownloadItemView : public views::InkDropHostView, | 64 class DownloadItemView : public views::InkDropHostView, |
| 64 public views::VectorIconButtonDelegate, | 65 public views::ButtonListener, |
| 65 public views::ContextMenuController, | 66 public views::ContextMenuController, |
| 66 public content::DownloadItem::Observer, | 67 public content::DownloadItem::Observer, |
| 67 public gfx::AnimationDelegate { | 68 public gfx::AnimationDelegate { |
| 68 public: | 69 public: |
| 69 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); | 70 DownloadItemView(content::DownloadItem* download, DownloadShelfView* parent); |
| 70 ~DownloadItemView() override; | 71 ~DownloadItemView() override; |
| 71 | 72 |
| 72 // Timer callback for handling animations | 73 // Timer callback for handling animations |
| 73 void UpdateDownloadProgress(); | 74 void UpdateDownloadProgress(); |
| 74 void StartDownloadProgress(); | 75 void StartDownloadProgress(); |
| 75 void StopDownloadProgress(); | 76 void StopDownloadProgress(); |
| 76 | 77 |
| 77 // Returns the base color for text on this download item, based on |theme|. | 78 // Returns the base color for text on this download item, based on |theme|. |
| 78 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); | 79 static SkColor GetTextColorForThemeProvider(const ui::ThemeProvider* theme); |
| 79 | 80 |
| 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 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 109 | 110 |
| 110 // Overridden from view::InkDropHostView: | 111 // view::InkDropHostView: |
| 111 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; | 112 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 112 std::unique_ptr<views::InkDrop> CreateInkDrop() override; | 113 std::unique_ptr<views::InkDrop> CreateInkDrop() override; |
| 113 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; | 114 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; |
| 114 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() | 115 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() |
| 115 const override; | 116 const override; |
| 116 | 117 |
| 117 // Overridden from ui::EventHandler: | 118 // ui::EventHandler: |
| 118 void OnGestureEvent(ui::GestureEvent* event) override; | 119 void OnGestureEvent(ui::GestureEvent* event) override; |
| 119 | 120 |
| 120 // Overridden from views::ContextMenuController. | 121 // views::ContextMenuController. |
| 121 void ShowContextMenuForView(View* source, | 122 void ShowContextMenuForView(View* source, |
| 122 const gfx::Point& point, | 123 const gfx::Point& point, |
| 123 ui::MenuSourceType source_type) override; | 124 ui::MenuSourceType source_type) override; |
| 124 | 125 |
| 125 // VectorIconButtonDelegate implementation. | 126 // views::ButtonListener: |
| 126 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 127 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 127 SkColor GetVectorIconBaseColor() const override; | |
| 128 | 128 |
| 129 // gfx::AnimationDelegate implementation. | 129 // gfx::AnimationDelegate implementation. |
| 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; | |
| 144 | 143 |
| 145 enum Mode { | 144 enum Mode { |
| 146 NORMAL_MODE = 0, // Showing download item. | 145 NORMAL_MODE = 0, // Showing download item. |
| 147 DANGEROUS_MODE, // Displaying the dangerous download warning. | 146 DANGEROUS_MODE, // Displaying the dangerous download warning. |
| 148 MALICIOUS_MODE // Displaying the malicious download warning. | 147 MALICIOUS_MODE // Displaying the malicious download warning. |
| 149 }; | 148 }; |
| 150 | 149 |
| 151 void OpenDownload(); | 150 void OpenDownload(); |
| 152 | 151 |
| 153 // Submits the downloaded file to the safebrowsing download feedback service. | 152 // Submits the downloaded file to the safebrowsing download feedback service. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 170 void DrawStatusText(gfx::Canvas* canvas); | 169 void DrawStatusText(gfx::Canvas* canvas); |
| 171 void DrawFilename(gfx::Canvas* canvas); | 170 void DrawFilename(gfx::Canvas* canvas); |
| 172 void DrawIcon(gfx::Canvas* canvas); | 171 void DrawIcon(gfx::Canvas* canvas); |
| 173 | 172 |
| 174 void LoadIcon(); | 173 void LoadIcon(); |
| 175 void LoadIconIfItemPathChanged(); | 174 void LoadIconIfItemPathChanged(); |
| 176 | 175 |
| 177 // Update the button colors based on the current theme. | 176 // Update the button colors based on the current theme. |
| 178 void UpdateColorsFromTheme(); | 177 void UpdateColorsFromTheme(); |
| 179 | 178 |
| 179 void UpdateDropdownButton(); |
| 180 |
| 180 // Shows the context menu at the specified location. |point| is in the view's | 181 // Shows the context menu at the specified location. |point| is in the view's |
| 181 // coordinate system. | 182 // coordinate system. |
| 182 void ShowContextMenuImpl(const gfx::Rect& rect, | 183 void ShowContextMenuImpl(const gfx::Rect& rect, |
| 183 ui::MenuSourceType source_type); | 184 ui::MenuSourceType source_type); |
| 184 | 185 |
| 185 // Common code for handling pointer events (i.e. mouse or gesture). | 186 // Common code for handling pointer events (i.e. mouse or gesture). |
| 186 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event); | 187 void HandlePressEvent(const ui::LocatedEvent& event, bool active_event); |
| 187 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event); | 188 void HandleClickEvent(const ui::LocatedEvent& event, bool active_event); |
| 188 | 189 |
| 189 // Sets the state and triggers a repaint. | 190 // Sets the state and triggers a repaint. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 std::unique_ptr<gfx::SlideAnimation> complete_animation_; | 299 std::unique_ptr<gfx::SlideAnimation> complete_animation_; |
| 299 | 300 |
| 300 // Progress animation | 301 // Progress animation |
| 301 base::RepeatingTimer progress_timer_; | 302 base::RepeatingTimer progress_timer_; |
| 302 | 303 |
| 303 // Dangerous mode buttons. | 304 // Dangerous mode buttons. |
| 304 views::MdTextButton* save_button_; | 305 views::MdTextButton* save_button_; |
| 305 views::MdTextButton* discard_button_; | 306 views::MdTextButton* discard_button_; |
| 306 | 307 |
| 307 // The drop down button. | 308 // The drop down button. |
| 308 DropDownButton* dropdown_button_; | 309 views::ImageButton* dropdown_button_; |
| 309 | 310 |
| 310 // Dangerous mode label. | 311 // Dangerous mode label. |
| 311 views::Label* dangerous_download_label_; | 312 views::Label* dangerous_download_label_; |
| 312 | 313 |
| 313 // Whether the dangerous mode label has been sized yet. | 314 // Whether the dangerous mode label has been sized yet. |
| 314 bool dangerous_download_label_sized_; | 315 bool dangerous_download_label_sized_; |
| 315 | 316 |
| 316 // Whether we are currently disabled as part of opening the downloaded file. | 317 // Whether we are currently disabled as part of opening the downloaded file. |
| 317 bool disabled_while_opening_; | 318 bool disabled_while_opening_; |
| 318 | 319 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 338 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; | 339 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; |
| 339 | 340 |
| 340 // Method factory used to delay reenabling of the item when opening the | 341 // Method factory used to delay reenabling of the item when opening the |
| 341 // downloaded file. | 342 // downloaded file. |
| 342 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; | 343 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; |
| 343 | 344 |
| 344 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); | 345 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); |
| 345 }; | 346 }; |
| 346 | 347 |
| 347 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ | 348 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ |
| OLD | NEW |