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 "chrome/browser/ui/views/new_back_shortcut_bubble.h" | 5 #include "chrome/browser/ui/views/new_back_shortcut_bubble.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h" | 14 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h" |
14 #include "chrome/browser/ui/views/subtle_notification_view.h" | 15 #include "chrome/browser/ui/views/subtle_notification_view.h" |
15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/gfx/animation/animation.h" | 18 #include "ui/gfx/animation/animation.h" |
18 #include "ui/gfx/animation/slide_animation.h" | 19 #include "ui/gfx/animation/slide_animation.h" |
19 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
21 #include "ui/strings/grit/ui_strings.h" | 22 #include "ui/strings/grit/ui_strings.h" |
22 #include "ui/views/border.h" | 23 #include "ui/views/border.h" |
(...skipping 25 matching lines...) Expand all Loading... |
48 // ~ExclusiveAccessBubbleViews. | 49 // ~ExclusiveAccessBubbleViews. |
49 popup_->Close(); | 50 popup_->Close(); |
50 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, popup_); | 51 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, popup_); |
51 } | 52 } |
52 | 53 |
53 bool NewBackShortcutBubble::IsVisible() const { | 54 bool NewBackShortcutBubble::IsVisible() const { |
54 return popup_->IsVisible(); | 55 return popup_->IsVisible(); |
55 } | 56 } |
56 | 57 |
57 void NewBackShortcutBubble::UpdateContent(bool forward) { | 58 void NewBackShortcutBubble::UpdateContent(bool forward) { |
58 // Note: The key names are parameters so that we can vary by operating system | 59 const int command_id = forward ? IDC_FORWARD : IDC_BACK; |
59 // or change the direction of the arrow as necessary (see | 60 ui::Accelerator accelerator; |
60 // https://crbug.com/612685). | 61 const bool got_accelerator = |
61 | 62 bubble_view_context_->GetAcceleratorProvider() |
62 #if defined(OS_MACOSX) | 63 ->GetAcceleratorForCommandId(command_id, &accelerator); |
63 // U+2318 = PLACE OF INTEREST SIGN (Mac Command symbol). | 64 DCHECK(got_accelerator); |
64 base::string16 accelerator = base::WideToUTF16(L"\x2318"); | 65 const int message_id = forward ? IDS_PRESS_SHORTCUT_TO_GO_FORWARD |
65 #else | 66 : IDS_PRESS_SHORTCUT_TO_GO_BACK; |
66 base::string16 accelerator = l10n_util::GetStringUTF16(IDS_APP_ALT_KEY); | |
67 #endif | |
68 | |
69 int message_id = forward ? IDS_PRESS_ALT_RIGHT_TO_GO_FORWARD | |
70 : IDS_PRESS_ALT_LEFT_TO_GO_BACK; | |
71 // U+2192 = RIGHTWARDS ARROW; U+2190 = LEFTWARDS ARROW. | |
72 base::string16 arrow_key = base::WideToUTF16(forward ? L"\x2192" : L"\x2190"); | |
73 view_->UpdateContent( | 67 view_->UpdateContent( |
74 l10n_util::GetStringFUTF16(message_id, accelerator, arrow_key), | 68 l10n_util::GetStringFUTF16(message_id, accelerator.GetShortcutText()), |
75 base::string16()); | 69 base::string16()); |
76 | 70 |
77 view_->SetSize(GetPopupRect(true).size()); | 71 view_->SetSize(GetPopupRect(true).size()); |
78 popup_->SetBounds(GetPopupRect(false)); | 72 popup_->SetBounds(GetPopupRect(false)); |
79 | 73 |
80 // Show the bubble. | 74 // Show the bubble. |
81 animation_->SetSlideDuration(kSlideInDurationMs); | 75 animation_->SetSlideDuration(kSlideInDurationMs); |
82 animation_->Show(); | 76 animation_->Show(); |
83 | 77 |
84 // Wait a few seconds before hiding. | 78 // Wait a few seconds before hiding. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 int desired_top = kPopupTopPx - view_->border()->GetInsets().top(); | 112 int desired_top = kPopupTopPx - view_->border()->GetInsets().top(); |
119 int y = widget_bounds.y() + desired_top; | 113 int y = widget_bounds.y() + desired_top; |
120 return gfx::Rect(gfx::Point(x, y), size); | 114 return gfx::Rect(gfx::Point(x, y), size); |
121 } | 115 } |
122 | 116 |
123 void NewBackShortcutBubble::OnTimerElapsed() { | 117 void NewBackShortcutBubble::OnTimerElapsed() { |
124 // Hide the bubble. | 118 // Hide the bubble. |
125 animation_->SetSlideDuration(kSlideOutDurationMs); | 119 animation_->SetSlideDuration(kSlideOutDurationMs); |
126 animation_->Hide(); | 120 animation_->Hide(); |
127 } | 121 } |
OLD | NEW |