Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 7056001: views: Split DownloadShelfContextMenuWin out to its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asanka review Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 ------------------------------------------------------------
117
118 DownloadItemView::DownloadItemView(DownloadItem* download, 81 DownloadItemView::DownloadItemView(DownloadItem* download,
119 DownloadShelfView* parent, 82 DownloadShelfView* parent,
120 BaseDownloadItemModel* model) 83 BaseDownloadItemModel* model)
121 : warning_icon_(NULL), 84 : warning_icon_(NULL),
122 download_(download), 85 download_(download),
123 parent_(parent), 86 parent_(parent),
124 status_text_(UTF16ToWide( 87 status_text_(UTF16ToWide(
125 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING))), 88 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING))),
126 show_status_text_(true), 89 show_status_text_(true),
127 body_state_(NORMAL), 90 body_state_(NORMAL),
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 point.set_y(height()); 617 point.set_y(height());
655 if (base::i18n::IsRTL()) 618 if (base::i18n::IsRTL())
656 point.set_x(drop_down_x_right_); 619 point.set_x(drop_down_x_right_);
657 else 620 else
658 point.set_x(drop_down_x_left_); 621 point.set_x(drop_down_x_left_);
659 } 622 }
660 623
661 views::View::ConvertPointToScreen(this, &point); 624 views::View::ConvertPointToScreen(this, &point);
662 625
663 if (!context_menu_.get()) 626 if (!context_menu_.get())
664 context_menu_.reset(new DownloadShelfContextMenuWin(model_.get())); 627 context_menu_.reset(new DownloadShelfContextMenuView(model_.get()));
665 // When we call the Run method on the menu, it runs an inner message loop 628 // When we call the Run method on the menu, it runs an inner message loop
666 // that might causes us to be deleted. 629 // that might causes us to be deleted.
667 bool deleted = false; 630 bool deleted = false;
668 deleted_ = &deleted; 631 deleted_ = &deleted;
669 context_menu_->Run(point); 632 context_menu_->Run(point);
670 if (deleted) 633 if (deleted)
671 return; // We have been deleted! Don't access 'this'. 634 return; // We have been deleted! Don't access 'this'.
672 deleted_ = NULL; 635 deleted_ = NULL;
673 636
674 // If the menu action was to remove the download, this view will also be 637 // 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
1149 // If the name has changed, notify assistive technology that the name 1112 // If the name has changed, notify assistive technology that the name
1150 // has changed so they can announce it immediately. 1113 // has changed so they can announce it immediately.
1151 if (new_name != accessible_name_) { 1114 if (new_name != accessible_name_) {
1152 accessible_name_ = new_name; 1115 accessible_name_ = new_name;
1153 if (GetWidget()) { 1116 if (GetWidget()) {
1154 GetWidget()->NotifyAccessibilityEvent( 1117 GetWidget()->NotifyAccessibilityEvent(
1155 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true); 1118 this, ui::AccessibilityTypes::EVENT_NAME_CHANGED, true);
1156 } 1119 }
1157 } 1120 }
1158 } 1121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698