| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/system/toast/toast_overlay.h" | 5 #include "ash/system/toast/toast_overlay.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/ash_typography.h" |
| 7 #include "ash/public/cpp/shell_window_ids.h" | 8 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/wm_shelf.h" | 10 #include "ash/shelf/wm_shelf.h" |
| 10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 11 #include "ash/strings/grit/ash_strings.h" | 12 #include "ash/strings/grit/ash_strings.h" |
| 12 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
| 21 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| 22 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
| 23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 24 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
| 25 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
| 28 #include "ui/wm/core/window_animations.h" | 28 #include "ui/wm/core/window_animations.h" |
| 29 | 29 |
| 30 namespace ash { | 30 namespace ash { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Offset of the overlay from the edge of the work area. | 34 // Offset of the overlay from the edge of the work area. |
| 35 const int kOffset = 5; | 35 const int kOffset = 5; |
| 36 | 36 |
| 37 // Font style used for modifier key labels. | |
| 38 const ui::ResourceBundle::FontStyle kTextFontStyle = | |
| 39 ui::ResourceBundle::MediumFont; | |
| 40 | |
| 41 // Duration of slide animation when overlay is shown or hidden. | 37 // Duration of slide animation when overlay is shown or hidden. |
| 42 const int kSlideAnimationDurationMs = 100; | 38 const int kSlideAnimationDurationMs = 100; |
| 43 | 39 |
| 44 // Colors for the dismiss button. | 40 // Colors for the dismiss button. |
| 45 const SkColor kButtonBackgroundColor = SkColorSetARGB(0xFF, 0x32, 0x32, 0x32); | 41 const SkColor kButtonBackgroundColor = SkColorSetARGB(0xFF, 0x32, 0x32, 0x32); |
| 46 const SkColor kButtonTextColor = SkColorSetARGB(0xFF, 0x7B, 0xAA, 0xF7); | 42 const SkColor kButtonTextColor = SkColorSetARGB(0xFF, 0x7B, 0xAA, 0xF7); |
| 47 | 43 |
| 48 // These values are in DIP. | 44 // These values are in DIP. |
| 49 const int kToastHorizontalSpacing = 16; | 45 const int kToastHorizontalSpacing = 16; |
| 50 const int kToastVerticalSpacing = 16; | 46 const int kToastVerticalSpacing = 16; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 // ToastOverlayLabel | 60 // ToastOverlayLabel |
| 65 class ToastOverlayLabel : public views::Label { | 61 class ToastOverlayLabel : public views::Label { |
| 66 public: | 62 public: |
| 67 explicit ToastOverlayLabel(const base::string16& label); | 63 explicit ToastOverlayLabel(const base::string16& label); |
| 68 ~ToastOverlayLabel() override; | 64 ~ToastOverlayLabel() override; |
| 69 | 65 |
| 70 private: | 66 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(ToastOverlayLabel); | 67 DISALLOW_COPY_AND_ASSIGN(ToastOverlayLabel); |
| 72 }; | 68 }; |
| 73 | 69 |
| 74 ToastOverlayLabel::ToastOverlayLabel(const base::string16& label) { | 70 ToastOverlayLabel::ToastOverlayLabel(const base::string16& label) |
| 75 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 71 : Label(label, CONTEXT_TOAST_OVERLAY) { |
| 76 | |
| 77 SetText(label); | |
| 78 SetHorizontalAlignment(gfx::ALIGN_LEFT); | 72 SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 79 SetFontList(rb->GetFontList(kTextFontStyle)); | |
| 80 SetAutoColorReadabilityEnabled(false); | 73 SetAutoColorReadabilityEnabled(false); |
| 81 SetMultiLine(true); | 74 SetMultiLine(true); |
| 82 SetEnabledColor(SK_ColorWHITE); | 75 SetEnabledColor(SK_ColorWHITE); |
| 83 SetDisabledColor(SK_ColorWHITE); | 76 SetDisabledColor(SK_ColorWHITE); |
| 84 SetSubpixelRenderingEnabled(false); | 77 SetSubpixelRenderingEnabled(false); |
| 85 | 78 |
| 86 int verticalSpacing = | 79 int verticalSpacing = |
| 87 kToastVerticalSpacing - (GetPreferredSize().height() - GetBaseline()); | 80 kToastVerticalSpacing - (GetPreferredSize().height() - GetBaseline()); |
| 88 SetBorder(views::CreateEmptyBorder(verticalSpacing, kToastHorizontalSpacing, | 81 SetBorder(views::CreateEmptyBorder(verticalSpacing, kToastHorizontalSpacing, |
| 89 verticalSpacing, kToastHorizontalSpacing)); | 82 verticalSpacing, kToastHorizontalSpacing)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 ~ToastOverlayButton() override {} | 93 ~ToastOverlayButton() override {} |
| 101 | 94 |
| 102 private: | 95 private: |
| 103 friend class ToastOverlay; // for ToastOverlay::ClickDismissButtonForTesting. | 96 friend class ToastOverlay; // for ToastOverlay::ClickDismissButtonForTesting. |
| 104 | 97 |
| 105 DISALLOW_COPY_AND_ASSIGN(ToastOverlayButton); | 98 DISALLOW_COPY_AND_ASSIGN(ToastOverlayButton); |
| 106 }; | 99 }; |
| 107 | 100 |
| 108 ToastOverlayButton::ToastOverlayButton(views::ButtonListener* listener, | 101 ToastOverlayButton::ToastOverlayButton(views::ButtonListener* listener, |
| 109 const base::string16& text) | 102 const base::string16& text) |
| 110 : views::LabelButton(listener, text) { | 103 : views::LabelButton(listener, text, CONTEXT_TOAST_OVERLAY) { |
| 111 SetInkDropMode(InkDropMode::ON); | 104 SetInkDropMode(InkDropMode::ON); |
| 112 set_has_ink_drop_action_on_click(true); | 105 set_has_ink_drop_action_on_click(true); |
| 113 set_ink_drop_base_color(SK_ColorWHITE); | 106 set_ink_drop_base_color(SK_ColorWHITE); |
| 114 | 107 |
| 115 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
| 116 | |
| 117 SetEnabledTextColors(kButtonTextColor); | 108 SetEnabledTextColors(kButtonTextColor); |
| 118 SetFontList(rb->GetFontList(kTextFontStyle)); | |
| 119 | 109 |
| 120 // Treat the space below the baseline as a margin. | 110 // Treat the space below the baseline as a margin. |
| 121 int verticalSpacing = kToastVerticalSpacing - | 111 int verticalSpacing = kToastVerticalSpacing - |
| 122 (GetPreferredSize().height() - label()->GetBaseline()); | 112 (GetPreferredSize().height() - label()->GetBaseline()); |
| 123 SetBorder(views::CreateEmptyBorder(verticalSpacing, kToastHorizontalSpacing, | 113 SetBorder(views::CreateEmptyBorder(verticalSpacing, kToastHorizontalSpacing, |
| 124 verticalSpacing, kToastHorizontalSpacing)); | 114 verticalSpacing, kToastHorizontalSpacing)); |
| 125 } | 115 } |
| 126 | 116 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 117 /////////////////////////////////////////////////////////////////////////////// |
| 128 // ToastOverlayView | 118 // ToastOverlayView |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 ToastOverlayButton* ToastOverlay::dismiss_button_for_testing() { | 290 ToastOverlayButton* ToastOverlay::dismiss_button_for_testing() { |
| 301 return overlay_view_->button(); | 291 return overlay_view_->button(); |
| 302 } | 292 } |
| 303 | 293 |
| 304 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { | 294 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { |
| 305 DCHECK(overlay_view_->button()); | 295 DCHECK(overlay_view_->button()); |
| 306 overlay_view_->button()->NotifyClick(event); | 296 overlay_view_->button()->NotifyClick(event); |
| 307 } | 297 } |
| 308 | 298 |
| 309 } // namespace ash | 299 } // namespace ash |
| OLD | NEW |