Chromium Code Reviews| 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_md.h" | 5 #include "chrome/browser/ui/views/download/download_item_view_md.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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 #include "ui/views/controls/button/image_button.h" | 58 #include "ui/views/controls/button/image_button.h" |
| 59 #include "ui/views/controls/button/label_button.h" | 59 #include "ui/views/controls/button/label_button.h" |
| 60 #include "ui/views/controls/label.h" | 60 #include "ui/views/controls/label.h" |
| 61 #include "ui/views/mouse_constants.h" | 61 #include "ui/views/mouse_constants.h" |
| 62 #include "ui/views/widget/root_view.h" | 62 #include "ui/views/widget/root_view.h" |
| 63 #include "ui/views/widget/widget.h" | 63 #include "ui/views/widget/widget.h" |
| 64 | 64 |
| 65 using content::DownloadItem; | 65 using content::DownloadItem; |
| 66 using extensions::ExperienceSamplingEvent; | 66 using extensions::ExperienceSamplingEvent; |
| 67 | 67 |
| 68 // TODO(paulg): These may need to be adjusted when download progress | 68 namespace { |
| 69 // animation is added, and also possibly to take into account | |
| 70 // different screen resolutions. | |
| 71 static const int kTextWidth = 140; // Pixels | |
| 72 static const int kDangerousTextWidth = 200; // Pixels | |
| 73 static const int kVerticalPadding = 3; // Pixels | |
| 74 static const int kVerticalTextPadding = 2; // Pixels | |
| 75 static const int kTooltipMaxWidth = 800; // Pixels | |
| 76 | 69 |
| 77 // We add some padding before the left image so that the progress animation icon | 70 // All values in dp. |
|
sky
2015/09/23 23:42:27
do we really use dp? I thought it was dips.
Evan Stade
2015/09/24 00:34:26
I thought "dp" and "dip" were synonyms. Sources on
| |
| 78 // hides the corners of the left image. | 71 const int kTextWidth = 140; |
| 79 static const int kLeftPadding = 0; // Pixels. | 72 const int kDangerousTextWidth = 200; |
| 73 | |
| 74 // The normal height of the item which may be exceeded if text is large. | |
| 75 const int kDefaultHeight = 36; | |
| 76 | |
| 77 // The minimum vertical padding above and below contents of the download item. | |
| 78 // This is only used when the text size is large. | |
| 79 const int kMinimumVerticalPadding = 2; | |
| 80 | |
| 81 // Vertical padding between filename and status text. | |
| 82 const int kVerticalTextPadding = 1; | |
| 83 | |
| 84 const int kTooltipMaxWidth = 800; | |
| 85 | |
| 86 // Padding before the icon and at end of the item. TODO(estade): this needs to | |
| 87 // be used when drawing the non-warning dialog state. Currently we just use the | |
| 88 // built in padding for the progress indicator. | |
| 89 const int kStartPadding = 12; | |
| 90 const int kEndPadding = 19; | |
| 80 | 91 |
| 81 // The space between the Save and Discard buttons when prompting for a dangerous | 92 // The space between the Save and Discard buttons when prompting for a dangerous |
| 82 // download. | 93 // download. |
| 83 static const int kButtonPadding = 5; // Pixels. | 94 const int kButtonPadding = 5; |
| 84 | 95 |
| 85 // The space on the left and right side of the dangerous download label. | 96 // The space on the left and right side of the dangerous download label. |
| 86 static const int kLabelPadding = 4; // Pixels. | 97 const int kLabelPadding = 8; |
| 87 | 98 |
| 88 static const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212); | 99 const SkColor kFileNameDisabledColor = SkColorSetRGB(171, 192, 212); |
| 89 | 100 |
| 90 // How long the 'download complete' animation should last for. | 101 // How long the 'download complete' animation should last for. |
| 91 static const int kCompleteAnimationDurationMs = 2500; | 102 const int kCompleteAnimationDurationMs = 2500; |
| 92 | 103 |
| 93 // How long the 'download interrupted' animation should last for. | 104 // How long the 'download interrupted' animation should last for. |
| 94 static const int kInterruptedAnimationDurationMs = 2500; | 105 const int kInterruptedAnimationDurationMs = 2500; |
| 95 | 106 |
| 96 // How long we keep the item disabled after the user clicked it to open the | 107 // How long we keep the item disabled after the user clicked it to open the |
| 97 // downloaded item. | 108 // downloaded item. |
| 98 static const int kDisabledOnOpenDuration = 3000; | 109 const int kDisabledOnOpenDuration = 3000; |
| 99 | 110 |
| 100 // Darken light-on-dark download status text by 20% before drawing, thus | 111 } // namespace |
| 101 // creating a "muted" version of title text for both dark-on-light and | |
| 102 // light-on-dark themes. | |
| 103 static const double kDownloadItemLuminanceMod = 0.8; | |
| 104 | 112 |
| 105 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, | 113 DownloadItemViewMd::DownloadItemViewMd(DownloadItem* download_item, |
| 106 DownloadShelfView* parent) | 114 DownloadShelfView* parent) |
| 107 : warning_icon_(nullptr), | 115 : warning_icon_(nullptr), |
| 108 shelf_(parent), | 116 shelf_(parent), |
| 109 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), | 117 status_text_(l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING)), |
| 110 dropdown_state_(NORMAL), | 118 dropdown_state_(NORMAL), |
| 111 mode_(NORMAL_MODE), | 119 mode_(NORMAL_MODE), |
| 112 dragging_(false), | 120 dragging_(false), |
| 113 starting_drag_(false), | 121 starting_drag_(false), |
| 114 model_(download_item), | 122 model_(download_item), |
| 115 save_button_(nullptr), | 123 save_button_(nullptr), |
| 116 discard_button_(nullptr), | 124 discard_button_(nullptr), |
| 117 dropdown_button_(nullptr), | 125 dropdown_button_(nullptr), |
| 118 dangerous_download_label_(nullptr), | 126 dangerous_download_label_(nullptr), |
| 119 dangerous_download_label_sized_(false), | 127 dangerous_download_label_sized_(false), |
| 120 disabled_while_opening_(false), | 128 disabled_while_opening_(false), |
| 121 creation_time_(base::Time::Now()), | 129 creation_time_(base::Time::Now()), |
| 122 time_download_warning_shown_(base::Time()), | 130 time_download_warning_shown_(base::Time()), |
| 123 weak_ptr_factory_(this) { | 131 weak_ptr_factory_(this) { |
| 124 DCHECK(download()); | 132 DCHECK(download()); |
| 125 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | 133 DCHECK(ui::MaterialDesignController::IsModeMaterial()); |
| 126 download()->AddObserver(this); | 134 download()->AddObserver(this); |
| 127 set_context_menu_controller(this); | 135 set_context_menu_controller(this); |
| 128 | 136 |
| 129 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 130 | |
| 131 BodyImageSet normal_body_image_set = { | |
| 132 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), | |
| 133 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), | |
| 134 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), | |
| 135 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), | |
| 136 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE), | |
| 137 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM), | |
| 138 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP), | |
| 139 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE), | |
| 140 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM)}; | |
| 141 normal_body_image_set_ = normal_body_image_set; | |
| 142 | |
| 143 DropdownImageSet normal_dropdown_image_set = { | |
| 144 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP), | |
| 145 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE), | |
| 146 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM)}; | |
| 147 normal_dropdown_image_set_ = normal_dropdown_image_set; | |
| 148 | |
| 149 BodyImageSet hot_body_image_set = { | |
| 150 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP_H), | |
| 151 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_H), | |
| 152 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_H), | |
| 153 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP_H), | |
| 154 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_H), | |
| 155 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_H), | |
| 156 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_H), | |
| 157 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_H), | |
| 158 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_H)}; | |
| 159 hot_body_image_set_ = hot_body_image_set; | |
| 160 | |
| 161 DropdownImageSet hot_dropdown_image_set = { | |
| 162 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP_H), | |
| 163 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_H), | |
| 164 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_H)}; | |
| 165 hot_dropdown_image_set_ = hot_dropdown_image_set; | |
| 166 | |
| 167 BodyImageSet pushed_body_image_set = { | |
| 168 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP_P), | |
| 169 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE_P), | |
| 170 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM_P), | |
| 171 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP_P), | |
| 172 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE_P), | |
| 173 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM_P), | |
| 174 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_P), | |
| 175 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_P), | |
| 176 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_P)}; | |
| 177 pushed_body_image_set_ = pushed_body_image_set; | |
| 178 | |
| 179 DropdownImageSet pushed_dropdown_image_set = { | |
| 180 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_TOP_P), | |
| 181 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_MIDDLE_P), | |
| 182 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_MENU_BOTTOM_P)}; | |
| 183 pushed_dropdown_image_set_ = pushed_dropdown_image_set; | |
| 184 | |
| 185 BodyImageSet dangerous_mode_body_image_set = { | |
| 186 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_TOP), | |
| 187 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_MIDDLE), | |
| 188 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_LEFT_BOTTOM), | |
| 189 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_TOP), | |
| 190 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_MIDDLE), | |
| 191 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_CENTER_BOTTOM), | |
| 192 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_TOP_NO_DD), | |
| 193 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_MIDDLE_NO_DD), | |
| 194 rb.GetImageSkiaNamed(IDR_DOWNLOAD_BUTTON_RIGHT_BOTTOM_NO_DD)}; | |
| 195 dangerous_mode_body_image_set_ = dangerous_mode_body_image_set; | |
| 196 | |
| 197 malicious_mode_body_image_set_ = normal_body_image_set; | |
| 198 | |
| 199 LoadIcon(); | 137 LoadIcon(); |
| 200 | 138 |
| 201 font_list_ = rb.GetFontList(ui::ResourceBundle::BaseFont); | 139 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 202 box_height_ = std::max<int>(2 * kVerticalPadding + font_list_.GetHeight() + | 140 font_list_ = |
| 203 kVerticalTextPadding + font_list_.GetHeight(), | 141 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(1); |
| 204 2 * kVerticalPadding + | 142 status_font_list_ = |
| 205 normal_body_image_set_.top_left->height() + | 143 rb.GetFontList(ui::ResourceBundle::BaseFont).DeriveWithSizeDelta(-2); |
| 206 normal_body_image_set_.bottom_left->height()); | |
| 207 box_y_ = | |
| 208 std::max(0, (DownloadShelf::kProgressIndicatorSize - box_height_) / 2); | |
| 209 | 144 |
| 210 body_hover_animation_.reset(new gfx::SlideAnimation(this)); | 145 body_hover_animation_.reset(new gfx::SlideAnimation(this)); |
| 211 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); | 146 drop_hover_animation_.reset(new gfx::SlideAnimation(this)); |
| 212 | 147 |
| 213 SetAccessibilityFocusable(true); | 148 SetAccessibilityFocusable(true); |
| 214 | 149 |
| 215 OnDownloadUpdated(download()); | 150 OnDownloadUpdated(download()); |
| 216 | 151 |
| 217 // TODO(estade): share this button init code with the find in page bar; | 152 // TODO(estade): share this button init code with the find in page bar; |
| 218 // also fix theming. | 153 // also fix theming. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 shelf_->OpenedDownload(); | 287 shelf_->OpenedDownload(); |
| 353 } | 288 } |
| 354 | 289 |
| 355 // View overrides | 290 // View overrides |
| 356 | 291 |
| 357 // In dangerous mode we have to layout our buttons. | 292 // In dangerous mode we have to layout our buttons. |
| 358 void DownloadItemViewMd::Layout() { | 293 void DownloadItemViewMd::Layout() { |
| 359 UpdateColorsFromTheme(); | 294 UpdateColorsFromTheme(); |
| 360 | 295 |
| 361 if (IsShowingWarningDialog()) { | 296 if (IsShowingWarningDialog()) { |
| 362 BodyImageSet* body_image_set = (mode_ == DANGEROUS_MODE) | 297 int x = kStartPadding + warning_icon_->width() + kStartPadding; |
| 363 ? &dangerous_mode_body_image_set_ | |
| 364 : &malicious_mode_body_image_set_; | |
| 365 int x = kLeftPadding + body_image_set->top_left->width() + | |
| 366 warning_icon_->width() + kLabelPadding; | |
| 367 int y = (height() - dangerous_download_label_->height()) / 2; | 298 int y = (height() - dangerous_download_label_->height()) / 2; |
| 368 dangerous_download_label_->SetBounds(x, y, | 299 dangerous_download_label_->SetBounds(x, y, |
| 369 dangerous_download_label_->width(), | 300 dangerous_download_label_->width(), |
| 370 dangerous_download_label_->height()); | 301 dangerous_download_label_->height()); |
| 371 gfx::Size button_size = GetButtonSize(); | 302 gfx::Size button_size = GetButtonSize(); |
| 372 x += dangerous_download_label_->width() + kLabelPadding; | 303 x += dangerous_download_label_->width() + kLabelPadding; |
| 373 y = (height() - button_size.height()) / 2; | 304 y = (height() - button_size.height()) / 2; |
| 374 if (save_button_) { | 305 if (save_button_) { |
| 375 save_button_->SetBounds(x, y, button_size.width(), button_size.height()); | 306 save_button_->SetBounds(x, y, button_size.width(), button_size.height()); |
| 376 x += button_size.width() + kButtonPadding; | 307 x += button_size.width() + kButtonPadding; |
| 377 } | 308 } |
| 378 discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); | 309 discard_button_->SetBounds(x, y, button_size.width(), button_size.height()); |
| 379 } else { | 310 } else { |
| 380 dropdown_button_->SizeToPreferredSize(); | 311 dropdown_button_->SizeToPreferredSize(); |
| 381 dropdown_button_->SetPosition( | 312 dropdown_button_->SetPosition( |
| 382 gfx::Point(width() - dropdown_button_->width(), | 313 gfx::Point(width() - dropdown_button_->width(), |
| 383 (height() - dropdown_button_->height()) / 2)); | 314 (height() - dropdown_button_->height()) / 2)); |
| 384 } | 315 } |
| 385 } | 316 } |
| 386 | 317 |
| 387 gfx::Size DownloadItemViewMd::GetPreferredSize() const { | 318 gfx::Size DownloadItemViewMd::GetPreferredSize() const { |
| 388 int width, height; | 319 int width, height; |
| 389 | 320 |
| 390 // First, we set the height to the height of two rows or text plus margins. | 321 // First, we set the height to the height of two rows or text plus margins. |
| 391 height = | 322 height = std::max(kDefaultHeight, |
| 392 2 * kVerticalPadding + 2 * font_list_.GetHeight() + kVerticalTextPadding; | 323 2 * kMinimumVerticalPadding + font_list_.GetBaseline() + |
|
sky
2015/09/23 23:42:27
Why are you using baseline instead of height?
Evan Stade
2015/09/24 00:34:26
The specs use the baseline for alignment, e.g. ali
sky
2015/09/24 15:05:53
For alignment, sure, but in calculating the prefer
Evan Stade
2015/09/24 17:28:03
Hmm, I guess that's fair. I left the filename one
| |
| 324 kVerticalTextPadding + status_font_list_.GetBaseline()); | |
| 393 // Then we increase the size if the progress icon doesn't fit. | 325 // Then we increase the size if the progress icon doesn't fit. |
| 394 height = std::max<int>(height, DownloadShelf::kProgressIndicatorSize); | 326 height = std::max<int>(height, DownloadShelf::kProgressIndicatorSize); |
| 395 | 327 |
| 396 if (IsShowingWarningDialog()) { | 328 if (IsShowingWarningDialog()) { |
| 397 const BodyImageSet* body_image_set = (mode_ == DANGEROUS_MODE) | 329 width = kStartPadding + warning_icon_->width() + kLabelPadding + |
| 398 ? &dangerous_mode_body_image_set_ | 330 dangerous_download_label_->width() + kLabelPadding; |
| 399 : &malicious_mode_body_image_set_; | |
| 400 width = kLeftPadding + body_image_set->top_left->width(); | |
| 401 width += warning_icon_->width() + kLabelPadding; | |
| 402 width += dangerous_download_label_->width() + kLabelPadding; | |
| 403 gfx::Size button_size = GetButtonSize(); | 331 gfx::Size button_size = GetButtonSize(); |
| 404 // Make sure the button fits. | 332 // Make sure the button fits. |
| 405 height = std::max<int>(height, 2 * kVerticalPadding + button_size.height()); | 333 height = std::max<int>(height, |
| 334 2 * kMinimumVerticalPadding + button_size.height()); | |
| 406 // Then we make sure the warning icon fits. | 335 // Then we make sure the warning icon fits. |
| 407 height = | 336 height = std::max<int>( |
| 408 std::max<int>(height, 2 * kVerticalPadding + warning_icon_->height()); | 337 height, 2 * kMinimumVerticalPadding + warning_icon_->height()); |
| 409 if (save_button_) | 338 if (save_button_) |
| 410 width += button_size.width() + kButtonPadding; | 339 width += button_size.width() + kButtonPadding; |
| 411 width += button_size.width(); | 340 width += button_size.width() + kEndPadding; |
| 412 width += body_image_set->top_right->width(); | |
| 413 if (mode_ == MALICIOUS_MODE) | |
| 414 width += normal_dropdown_image_set_.top->width(); | |
| 415 } else { | 341 } else { |
| 416 width = kLeftPadding + normal_body_image_set_.top_left->width(); | 342 width = kStartPadding + DownloadShelf::kProgressIndicatorSize + kTextWidth + |
| 417 width += DownloadShelf::kProgressIndicatorSize; | 343 kEndPadding; |
| 418 width += kTextWidth; | |
| 419 width += normal_body_image_set_.top_right->width(); | |
| 420 width += normal_dropdown_image_set_.top->width(); | |
| 421 } | 344 } |
| 422 return gfx::Size(width, height); | 345 return gfx::Size(width, height); |
| 423 } | 346 } |
| 424 | 347 |
| 425 // Handle a mouse click and open the context menu if the mouse is | 348 // Handle a mouse click and open the context menu if the mouse is |
| 426 // over the drop-down region. | 349 // over the drop-down region. |
| 427 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { | 350 bool DownloadItemViewMd::OnMousePressed(const ui::MouseEvent& event) { |
| 428 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); | 351 HandlePressEvent(event, event.IsOnlyLeftMouseButton()); |
| 429 return true; | 352 return true; |
| 430 } | 353 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 void DownloadItemViewMd::OnPaint(gfx::Canvas* canvas) { | 534 void DownloadItemViewMd::OnPaint(gfx::Canvas* canvas) { |
| 612 DrawStatusText(canvas); | 535 DrawStatusText(canvas); |
| 613 DrawFilename(canvas); | 536 DrawFilename(canvas); |
| 614 DrawIcon(canvas); | 537 DrawIcon(canvas); |
| 615 OnPaintBorder(canvas); | 538 OnPaintBorder(canvas); |
| 616 | 539 |
| 617 if (HasFocus()) | 540 if (HasFocus()) |
| 618 canvas->DrawFocusRect(GetLocalBounds()); | 541 canvas->DrawFocusRect(GetLocalBounds()); |
| 619 } | 542 } |
| 620 | 543 |
| 544 int DownloadItemViewMd::GetYForFilenameText() const { | |
| 545 int text_height = font_list_.GetBaseline(); | |
| 546 if (!status_text_.empty()) | |
| 547 text_height += kVerticalTextPadding + status_font_list_.GetBaseline(); | |
| 548 return (height() - text_height) / 2; | |
| 549 } | |
| 550 | |
| 621 void DownloadItemViewMd::DrawStatusText(gfx::Canvas* canvas) { | 551 void DownloadItemViewMd::DrawStatusText(gfx::Canvas* canvas) { |
| 622 if (status_text_.empty()) | 552 if (status_text_.empty() || IsShowingWarningDialog()) |
| 623 return; | 553 return; |
| 624 | 554 |
| 625 int mirrored_x = GetMirroredXWithWidthInView( | 555 int mirrored_x = GetMirroredXWithWidthInView( |
| 626 DownloadShelf::kProgressIndicatorSize, kTextWidth); | 556 DownloadShelf::kProgressIndicatorSize, kTextWidth); |
| 627 // Add font_list_.height() to compensate for title, which is drawn later. | |
| 628 int y = | 557 int y = |
| 629 box_y_ + kVerticalPadding + font_list_.GetHeight() + kVerticalTextPadding; | 558 GetYForFilenameText() + font_list_.GetBaseline() + kVerticalTextPadding; |
| 630 SkColor file_name_color = | 559 SkColor file_name_color = SkColorSetA( |
| 631 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 560 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT), 0xC7); |
| 632 // If text is light-on-dark, lightening it alone will do nothing. | |
| 633 // Therefore we mute luminance a wee bit before drawing in this case. | |
| 634 if (color_utils::RelativeLuminance(file_name_color) > 0.5) | |
| 635 file_name_color = | |
| 636 SkColorSetRGB(static_cast<int>(kDownloadItemLuminanceMod * | |
| 637 SkColorGetR(file_name_color)), | |
| 638 static_cast<int>(kDownloadItemLuminanceMod * | |
| 639 SkColorGetG(file_name_color)), | |
| 640 static_cast<int>(kDownloadItemLuminanceMod * | |
| 641 SkColorGetB(file_name_color))); | |
| 642 canvas->DrawStringRect( | 561 canvas->DrawStringRect( |
| 643 status_text_, font_list_, file_name_color, | 562 status_text_, status_font_list_, file_name_color, |
| 644 gfx::Rect(mirrored_x, y, kTextWidth, font_list_.GetHeight())); | 563 gfx::Rect(mirrored_x, y, kTextWidth, status_font_list_.GetHeight())); |
| 645 } | 564 } |
| 646 | 565 |
| 647 void DownloadItemViewMd::DrawFilename(gfx::Canvas* canvas) { | 566 void DownloadItemViewMd::DrawFilename(gfx::Canvas* canvas) { |
| 567 if (IsShowingWarningDialog()) | |
| 568 return; | |
| 569 | |
| 648 // Print the text, left aligned and always print the file extension. | 570 // Print the text, left aligned and always print the file extension. |
| 649 // Last value of x was the end of the right image, just before the button. | 571 // Last value of x was the end of the right image, just before the button. |
| 650 // Note that in dangerous mode we use a label (as the text is multi-line). | 572 // Note that in dangerous mode we use a label (as the text is multi-line). |
| 651 base::string16 filename; | 573 base::string16 filename; |
| 652 if (!disabled_while_opening_) { | 574 if (!disabled_while_opening_) { |
| 653 filename = gfx::ElideFilename(download()->GetFileNameToReportUser(), | 575 filename = gfx::ElideFilename(download()->GetFileNameToReportUser(), |
| 654 font_list_, kTextWidth); | 576 font_list_, kTextWidth); |
| 655 } else { | 577 } else { |
| 656 // First, Calculate the download status opening string width. | 578 // First, Calculate the download status opening string width. |
| 657 base::string16 status_string = l10n_util::GetStringFUTF16( | 579 base::string16 status_string = l10n_util::GetStringFUTF16( |
| 658 IDS_DOWNLOAD_STATUS_OPENING, base::string16()); | 580 IDS_DOWNLOAD_STATUS_OPENING, base::string16()); |
| 659 int status_string_width = gfx::GetStringWidth(status_string, font_list_); | 581 int status_string_width = gfx::GetStringWidth(status_string, font_list_); |
| 660 // Then, elide the file name. | 582 // Then, elide the file name. |
| 661 base::string16 filename_string = | 583 base::string16 filename_string = |
| 662 gfx::ElideFilename(download()->GetFileNameToReportUser(), font_list_, | 584 gfx::ElideFilename(download()->GetFileNameToReportUser(), font_list_, |
| 663 kTextWidth - status_string_width); | 585 kTextWidth - status_string_width); |
| 664 // Last, concat the whole string. | 586 // Last, concat the whole string. |
| 665 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, | 587 filename = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPENING, |
| 666 filename_string); | 588 filename_string); |
| 667 } | 589 } |
| 668 | 590 |
| 669 int mirrored_x = GetMirroredXWithWidthInView( | 591 int mirrored_x = GetMirroredXWithWidthInView( |
| 670 DownloadShelf::kProgressIndicatorSize, kTextWidth); | 592 DownloadShelf::kProgressIndicatorSize, kTextWidth); |
| 671 SkColor file_name_color = | 593 SkColor file_name_color = |
| 672 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 594 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| 673 int y = box_y_ + (status_text_.empty() | |
| 674 ? ((box_height_ - font_list_.GetHeight()) / 2) | |
| 675 : kVerticalPadding); | |
| 676 | 595 |
| 677 canvas->DrawStringRect( | 596 canvas->DrawStringRect(filename, font_list_, |
| 678 filename, font_list_, | 597 enabled() ? file_name_color : kFileNameDisabledColor, |
| 679 enabled() ? file_name_color : kFileNameDisabledColor, | 598 gfx::Rect(mirrored_x, GetYForFilenameText(), |
| 680 gfx::Rect(mirrored_x, y, kTextWidth, font_list_.GetHeight())); | 599 kTextWidth, font_list_.GetHeight())); |
| 681 } | 600 } |
| 682 | 601 |
| 683 void DownloadItemViewMd::DrawIcon(gfx::Canvas* canvas) { | 602 void DownloadItemViewMd::DrawIcon(gfx::Canvas* canvas) { |
| 684 if (IsShowingWarningDialog()) { | 603 if (IsShowingWarningDialog()) { |
| 685 int icon_x = kLeftPadding + normal_body_image_set_.top_left->width(); | 604 int icon_x = kStartPadding; |
| 686 int icon_y = (height() - warning_icon_->height()) / 2; | 605 int icon_y = (height() - warning_icon_->height()) / 2; |
| 687 canvas->DrawImageInt(*warning_icon_, icon_x, icon_y); | 606 canvas->DrawImageInt(*warning_icon_, icon_x, icon_y); |
| 688 return; | 607 return; |
| 689 } | 608 } |
| 690 | 609 |
| 691 // Paint download progress. | 610 // Paint download progress. |
| 692 DownloadItem::DownloadState state = download()->GetState(); | 611 DownloadItem::DownloadState state = download()->GetState(); |
| 693 canvas->Save(); | 612 canvas->Save(); |
| 694 if (base::i18n::IsRTL()) { | 613 if (base::i18n::IsRTL()) { |
| 695 canvas->Translate( | 614 canvas->Translate( |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1110 State to, | 1029 State to, |
| 1111 gfx::SlideAnimation* animation) { | 1030 gfx::SlideAnimation* animation) { |
| 1112 if (from == NORMAL && to == HOT) { | 1031 if (from == NORMAL && to == HOT) { |
| 1113 animation->Show(); | 1032 animation->Show(); |
| 1114 } else if (from == HOT && to == NORMAL) { | 1033 } else if (from == HOT && to == NORMAL) { |
| 1115 animation->Hide(); | 1034 animation->Hide(); |
| 1116 } else if (from != to) { | 1035 } else if (from != to) { |
| 1117 animation->Reset((to == HOT) ? 1.0 : 0.0); | 1036 animation->Reset((to == HOT) ? 1.0 : 0.0); |
| 1118 } | 1037 } |
| 1119 } | 1038 } |
| OLD | NEW |