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

Side by Side Diff: chrome/browser/ui/views/new_back_shortcut_bubble.cc

Issue 1983803002: Added notification when user presses backspace to use new shortcut. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@subtle-notification-view-refactor
Patch Set: Fix alphabetical order in chrome_browser_ui.gypi. Created 4 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/new_back_shortcut_bubble.h"
6
7 #include <utility>
8
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h"
12 #include "chrome/browser/ui/views/subtle_notification_view.h"
13 #include "chrome/grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/animation/animation.h"
16 #include "ui/gfx/animation/slide_animation.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "ui/strings/grit/ui_strings.h"
20 #include "ui/views/border.h"
21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h"
23
24 namespace {
25
26 const int kPopupTopPx = 45;
27 const int kSlideInDurationMs = 350;
28 const int kSlideOutDurationMs = 700;
29 const int kShowDurationMs = 3800;
30
31 }
32
33 NewBackShortcutBubble::NewBackShortcutBubble(
34 ExclusiveAccessBubbleViewsContext* context,
35 bool forward)
36 : bubble_view_context_(context),
37 animation_(new gfx::SlideAnimation(this)),
38 view_(new SubtleNotificationView(nullptr)),
39 popup_(SubtleNotificationView::CreatePopupWidget(
40 bubble_view_context_->GetBubbleParentView(),
41 view_,
42 false)) {
43 UpdateContent(forward);
44 }
45
46 NewBackShortcutBubble::~NewBackShortcutBubble() {
47 // We might need to delete the widget asynchronously. See rationale in
48 // ~ExclusiveAccessBubbleViews.
49 popup_->Close();
50 base::MessageLoop::current()->DeleteSoon(FROM_HERE, popup_);
51 }
52
53 void NewBackShortcutBubble::UpdateContent(bool forward) {
54 // Note: The key names are parameters so that we can vary by operating system
55 // or change the direction of the arrow as necessary (see
56 // https://crbug.com/612685).
57
58 #if defined(OS_MACOSX)
59 // U+2318 = PLACE OF INTEREST SIGN (Mac Command symbol).
60 base::string16 accelerator = base::WideToUTF16(L"\x2318");
61 #else
62 base::string16 accelerator = l10n_util::GetStringUTF16(IDS_APP_ALT_KEY);
63 #endif
64
65 int message_id = forward ? IDS_PRESS_ALT_RIGHT_TO_GO_FORWARD
66 : IDS_PRESS_ALT_LEFT_TO_GO_BACK;
67 // U+2192 = RIGHTWARDS ARROW; U+2190 = LEFTWARDS ARROW.
68 base::string16 arrow_key = base::WideToUTF16(forward ? L"\x2192" : L"\x2190");
69 view_->UpdateContent(
70 l10n_util::GetStringFUTF16(message_id, accelerator, arrow_key),
71 base::string16());
72
73 view_->SetSize(GetPopupRect(true).size());
74 popup_->SetBounds(GetPopupRect(false));
75
76 // Show the bubble.
77 animation_->SetSlideDuration(kSlideInDurationMs);
78 animation_->Show();
79
80 // Wait a few seconds before hiding.
81 hide_timeout_.Start(FROM_HERE,
82 base::TimeDelta::FromMilliseconds(kShowDurationMs), this,
83 &NewBackShortcutBubble::OnTimerElapsed);
84 }
85
86 void NewBackShortcutBubble::AnimationProgressed(
87 const gfx::Animation* animation) {
88 int opacity = animation_->CurrentValueBetween(0, 255);
89 if (opacity == 0) {
90 popup_->Hide();
91 } else {
92 if (!popup_->IsVisible())
93 popup_->Show();
94
95 popup_->SetOpacity(opacity);
96 }
97 }
98
99 void NewBackShortcutBubble::AnimationEnded(const gfx::Animation* animation) {
100 AnimationProgressed(animation);
101 }
102
103 gfx::Rect NewBackShortcutBubble::GetPopupRect(
104 bool ignore_animation_state) const {
105 gfx::Size size = view_->GetPreferredSize();
106 gfx::Rect widget_bounds = bubble_view_context_->GetClientAreaBoundsInScreen();
107 int x = widget_bounds.x() + (widget_bounds.width() - size.width()) / 2;
108 // |desired_top| is the top of the bubble area including the shadow.
109 int desired_top = kPopupTopPx - view_->border()->GetInsets().top();
110 int y = widget_bounds.y() + desired_top;
111 return gfx::Rect(gfx::Point(x, y), size);
112 }
113
114 void NewBackShortcutBubble::OnTimerElapsed() {
115 // Hide the bubble.
116 animation_->SetSlideDuration(kSlideOutDurationMs);
117 animation_->Hide();
118 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_back_shortcut_bubble.h ('k') | chrome/browser/ui/views/subtle_notification_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698