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

Side by Side Diff: chrome/browser/ui/views/location_bar/star_view.cc

Issue 25373009: Translate: New Bubble UX (for the view toolkit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sky's review (3) Created 7 years, 2 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
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/location_bar/star_view.h" 5 #include "chrome/browser/ui/views/location_bar/star_view.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/bookmarks/bookmark_stats.h" 10 #include "chrome/browser/bookmarks/bookmark_stats.h"
11 #include "chrome/browser/command_updater.h"
12 #include "chrome/browser/ui/view_ids.h" 11 #include "chrome/browser/ui/view_ids.h"
13 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" 12 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 13 #include "chrome/browser/ui/views/location_bar/bubble_icon_view_delegate.h"
15 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/events/event.h" 18
19 namespace {
20
21 class BubbleIconViewDelegateImpl : public BubbleIconViewDelegate {
22 public:
23 BubbleIconViewDelegateImpl() {
24 }
25
26 virtual bool IsBubbleShowing() const OVERRIDE {
27 return BookmarkBubbleView::IsShowing();
28 }
29
30 virtual void OnExecutingByMouse() OVERRIDE {
31 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
32 BOOKMARK_ENTRY_POINT_STAR_MOUSE,
33 BOOKMARK_ENTRY_POINT_LIMIT);
34 }
35
36 virtual void OnExecutingByKey() OVERRIDE {
37 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
38 BOOKMARK_ENTRY_POINT_STAR_KEY,
39 BOOKMARK_ENTRY_POINT_LIMIT);
40 }
41
42 virtual void OnExecutingByGesture() OVERRIDE {
43 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
44 BOOKMARK_ENTRY_POINT_STAR_GESTURE,
45 BOOKMARK_ENTRY_POINT_LIMIT);
46 }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(BubbleIconViewDelegateImpl);
50 };
51
52 } // namespace
21 53
22 StarView::StarView(CommandUpdater* command_updater) 54 StarView::StarView(CommandUpdater* command_updater)
23 : command_updater_(command_updater), 55 : BubbleIconView(command_updater, IDC_BOOKMARK_PAGE_FROM_STAR) {
24 suppress_mouse_released_action_(false) { 56 delegate_.reset(new BubbleIconViewDelegateImpl);
57 set_delegate(delegate_.get());
58
25 set_id(VIEW_ID_STAR_BUTTON); 59 set_id(VIEW_ID_STAR_BUTTON);
26 SetToggled(false); 60 SetToggled(false);
27 set_accessibility_focusable(true);
28 LocationBarView::InitTouchableLocationBarChildView(this);
29 } 61 }
30 62
31 StarView::~StarView() {} 63 StarView::~StarView() {}
32 64
33 void StarView::SetToggled(bool on) { 65 void StarView::SetToggled(bool on) {
34 SetTooltipText(l10n_util::GetStringUTF16( 66 SetTooltipText(l10n_util::GetStringUTF16(
35 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR)); 67 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR));
36 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 68 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
37 on ? IDR_STAR_LIT : IDR_STAR)); 69 on ? IDR_STAR_LIT : IDR_STAR));
38 } 70 }
39
40 void StarView::GetAccessibleState(ui::AccessibleViewState* state) {
41 ImageView::GetAccessibleState(state);
42 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
43 }
44
45 bool StarView::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
46 // Don't show tooltip to distract user if BookmarkBubbleView is showing.
47 if (BookmarkBubbleView::IsShowing())
48 return false;
49
50 return views::ImageView::GetTooltipText(p, tooltip);
51 }
52
53 bool StarView::OnMousePressed(const ui::MouseEvent& event) {
54 // If the bookmark bubble is showing then don't reshow it when the mouse is
55 // released.
56 suppress_mouse_released_action_ = BookmarkBubbleView::IsShowing();
57
58 // We want to show the bubble on mouse release; that is the standard behavior
59 // for buttons.
60 return true;
61 }
62
63 void StarView::OnMouseReleased(const ui::MouseEvent& event) {
64 // If this is the second click on this view then the bookmark bubble was
65 // showing on the mouse pressed event and is hidden now. Prevent the bubble
66 // from reshowing by doing nothing here.
67 if (suppress_mouse_released_action_) {
68 suppress_mouse_released_action_ = false;
69 return;
70 }
71
72 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
73 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
74 BOOKMARK_ENTRY_POINT_STAR_MOUSE,
75 BOOKMARK_ENTRY_POINT_LIMIT);
76 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
77 }
78 }
79
80 bool StarView::OnKeyPressed(const ui::KeyEvent& event) {
81 if (event.key_code() == ui::VKEY_SPACE ||
82 event.key_code() == ui::VKEY_RETURN) {
83 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
84 BOOKMARK_ENTRY_POINT_STAR_KEY,
85 BOOKMARK_ENTRY_POINT_LIMIT);
86 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
87 return true;
88 }
89 return false;
90 }
91
92 void StarView::OnGestureEvent(ui::GestureEvent* event) {
93 if (event->type() == ui::ET_GESTURE_TAP) {
94 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
95 BOOKMARK_ENTRY_POINT_STAR_GESTURE,
96 BOOKMARK_ENTRY_POINT_LIMIT);
97 command_updater_->ExecuteCommand(IDC_BOOKMARK_PAGE_FROM_STAR);
98 event->SetHandled();
99 }
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698