Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/download/download_item_model.h" | 18 #include "chrome/browser/download/download_item_model.h" |
| 19 #include "chrome/browser/download/download_shelf_context_menu.h" | |
| 20 #include "chrome/browser/download/download_util.h" | 19 #include "chrome/browser/download/download_util.h" |
| 21 #include "chrome/browser/themes/theme_service.h" | 20 #include "chrome/browser/themes/theme_service.h" |
| 21 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" | |
| 22 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 22 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 25 #include "ui/base/accessibility/accessible_view_state.h" | 25 #include "ui/base/accessibility/accessible_view_state.h" |
| 26 #include "ui/base/animation/slide_animation.h" | 26 #include "ui/base/animation/slide_animation.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/base/text/text_elider.h" | 29 #include "ui/base/text/text_elider.h" |
| 30 #include "ui/gfx/canvas_skia.h" | 30 #include "ui/gfx/canvas_skia.h" |
| 31 #include "ui/gfx/color_utils.h" | 31 #include "ui/gfx/color_utils.h" |
| 32 #include "ui/gfx/image.h" | 32 #include "ui/gfx/image.h" |
| 33 #include "unicode/uchar.h" | 33 #include "unicode/uchar.h" |
| 34 #include "views/controls/button/native_button.h" | 34 #include "views/controls/button/native_button.h" |
| 35 #include "views/controls/label.h" | 35 #include "views/controls/label.h" |
| 36 #include "views/controls/menu/menu_2.h" | |
| 37 #include "views/widget/root_view.h" | 36 #include "views/widget/root_view.h" |
| 38 #include "views/widget/widget.h" | 37 #include "views/widget/widget.h" |
| 39 | 38 |
| 40 // TODO(paulg): These may need to be adjusted when download progress | 39 // TODO(paulg): These may need to be adjusted when download progress |
| 41 // animation is added, and also possibly to take into account | 40 // animation is added, and also possibly to take into account |
| 42 // different screen resolutions. | 41 // different screen resolutions. |
| 43 static const int kTextWidth = 140; // Pixels | 42 static const int kTextWidth = 140; // Pixels |
| 44 static const int kDangerousTextWidth = 200; // Pixels | 43 static const int kDangerousTextWidth = 200; // Pixels |
| 45 static const int kHorizontalTextPadding = 2; // Pixels | 44 static const int kHorizontalTextPadding = 2; // Pixels |
| 46 static const int kVerticalPadding = 3; // Pixels | 45 static const int kVerticalPadding = 3; // Pixels |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 72 | 71 |
| 73 // How long we keep the item disabled after the user clicked it to open the | 72 // How long we keep the item disabled after the user clicked it to open the |
| 74 // downloaded item. | 73 // downloaded item. |
| 75 static const int kDisabledOnOpenDuration = 3000; | 74 static const int kDisabledOnOpenDuration = 3000; |
| 76 | 75 |
| 77 // Darken light-on-dark download status text by 20% before drawing, thus | 76 // Darken light-on-dark download status text by 20% before drawing, thus |
| 78 // creating a "muted" version of title text for both dark-on-light and | 77 // creating a "muted" version of title text for both dark-on-light and |
| 79 // light-on-dark themes. | 78 // light-on-dark themes. |
| 80 static const double kDownloadItemLuminanceMod = 0.8; | 79 static const double kDownloadItemLuminanceMod = 0.8; |
| 81 | 80 |
| 82 // DownloadShelfContextMenuWin ------------------------------------------------- | |
| 83 | |
| 84 class DownloadShelfContextMenuWin : public DownloadShelfContextMenu { | |
| 85 public: | |
| 86 explicit DownloadShelfContextMenuWin(BaseDownloadItemModel* model) | |
| 87 : DownloadShelfContextMenu(model) { | |
| 88 DCHECK(model); | |
| 89 } | |
| 90 | |
| 91 void Run(const gfx::Point& point) { | |
| 92 if (download_item()->IsComplete()) | |
| 93 menu_.reset(new views::Menu2(GetFinishedMenuModel())); | |
| 94 else | |
| 95 menu_.reset(new views::Menu2(GetInProgressMenuModel())); | |
| 96 | |
| 97 // The menu's alignment is determined based on the UI layout. | |
| 98 views::Menu2::Alignment alignment; | |
| 99 if (base::i18n::IsRTL()) | |
| 100 alignment = views::Menu2::ALIGN_TOPRIGHT; | |
| 101 else | |
| 102 alignment = views::Menu2::ALIGN_TOPLEFT; | |
| 103 menu_->RunMenuAt(point, alignment); | |
| 104 } | |
| 105 | |
| 106 // This method runs when the caller has been deleted and we should not attempt | |
| 107 // to access |download_|. | |
| 108 void Stop() { | |
| 109 set_download_item(NULL); | |
| 110 } | |
| 111 | |
| 112 private: | |
| 113 scoped_ptr<views::Menu2> menu_; | |
| 114 }; | |
| 115 | |
| 116 // DownloadItemView ------------------------------------------------------------ | 81 // DownloadItemView ------------------------------------------------------------ |
|
asanka
2011/05/20 21:45:16
Nit: Don't need a section here.
tfarina
2011/05/20 22:19:23
Done.
| |
| 117 | 82 |
| 118 DownloadItemView::DownloadItemView(DownloadItem* download, | 83 DownloadItemView::DownloadItemView(DownloadItem* download, |
| 119 DownloadShelfView* parent, | 84 DownloadShelfView* parent, |
| 120 BaseDownloadItemModel* model) | 85 BaseDownloadItemModel* model) |
| 121 : warning_icon_(NULL), | 86 : warning_icon_(NULL), |
| 122 download_(download), | 87 download_(download), |
| 123 parent_(parent), | 88 parent_(parent), |
| 124 status_text_(UTF16ToWide( | 89 status_text_(UTF16ToWide( |
| 125 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING))), | 90 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING))), |
| 126 show_status_text_(true), | 91 show_status_text_(true), |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 point.set_y(height()); | 618 point.set_y(height()); |
| 654 if (base::i18n::IsRTL()) | 619 if (base::i18n::IsRTL()) |
| 655 point.set_x(drop_down_x_right_); | 620 point.set_x(drop_down_x_right_); |
| 656 else | 621 else |
| 657 point.set_x(drop_down_x_left_); | 622 point.set_x(drop_down_x_left_); |
| 658 } | 623 } |
| 659 | 624 |
| 660 views::View::ConvertPointToScreen(this, &point); | 625 views::View::ConvertPointToScreen(this, &point); |
| 661 | 626 |
| 662 if (!context_menu_.get()) | 627 if (!context_menu_.get()) |
| 663 context_menu_.reset(new DownloadShelfContextMenuWin(model_.get())); | 628 context_menu_.reset(new DownloadShelfContextMenuView(model_.get())); |
| 664 // When we call the Run method on the menu, it runs an inner message loop | 629 // When we call the Run method on the menu, it runs an inner message loop |
| 665 // that might causes us to be deleted. | 630 // that might causes us to be deleted. |
| 666 bool deleted = false; | 631 bool deleted = false; |
| 667 deleted_ = &deleted; | 632 deleted_ = &deleted; |
| 668 context_menu_->Run(point); | 633 context_menu_->Run(point); |
| 669 if (deleted) | 634 if (deleted) |
| 670 return; // We have been deleted! Don't access 'this'. | 635 return; // We have been deleted! Don't access 'this'. |
| 671 deleted_ = NULL; | 636 deleted_ = NULL; |
| 672 | 637 |
| 673 // If the menu action was to remove the download, this view will also be | 638 // If the menu action was to remove the download, this view will also be |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1148 // If the name has changed, notify assistive technology that the name | 1113 // If the name has changed, notify assistive technology that the name |
| 1149 // has changed so they can announce it immediately. | 1114 // has changed so they can announce it immediately. |
| 1150 if (new_name != accessible_name_) { | 1115 if (new_name != accessible_name_) { |
| 1151 accessible_name_ = new_name; | 1116 accessible_name_ = new_name; |
| 1152 if (GetWidget()) { | 1117 if (GetWidget()) { |
| 1153 GetWidget()->NotifyAccessibilityEvent( | 1118 GetWidget()->NotifyAccessibilityEvent( |
| 1154 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); | 1119 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); |
| 1155 } | 1120 } |
| 1156 } | 1121 } |
| 1157 } | 1122 } |
| OLD | NEW |