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

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: Bug fix: view id on tests Created 7 years, 1 month 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"
15 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
16 #include "grit/theme_resources.h" 14 #include "grit/theme_resources.h"
17 #include "ui/base/accessibility/accessible_view_state.h"
18 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/events/event.h"
21 17
22 StarView::StarView(CommandUpdater* command_updater) 18 StarView::StarView(CommandUpdater* command_updater)
23 : command_updater_(command_updater), 19 : BubbleIconView(command_updater, IDC_BOOKMARK_PAGE_FROM_STAR) {
24 suppress_mouse_released_action_(false) {
25 set_id(VIEW_ID_STAR_BUTTON); 20 set_id(VIEW_ID_STAR_BUTTON);
26 SetToggled(false); 21 SetToggled(false);
27 set_accessibility_focusable(true);
28 LocationBarView::InitTouchableLocationBarChildView(this);
29 } 22 }
30 23
31 StarView::~StarView() {} 24 StarView::~StarView() {}
32 25
33 void StarView::SetToggled(bool on) { 26 void StarView::SetToggled(bool on) {
34 SetTooltipText(l10n_util::GetStringUTF16( 27 SetTooltipText(l10n_util::GetStringUTF16(
35 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR)); 28 on ? IDS_TOOLTIP_STARRED : IDS_TOOLTIP_STAR));
36 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 29 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
37 on ? IDR_STAR_LIT : IDR_STAR)); 30 on ? IDR_STAR_LIT : IDR_STAR));
38 } 31 }
39 32
40 void StarView::GetAccessibleState(ui::AccessibleViewState* state) { 33 bool StarView::IsBubbleShowing() const {
41 ImageView::GetAccessibleState(state); 34 return BookmarkBubbleView::IsShowing();
42 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
43 } 35 }
44 36
45 bool StarView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { 37 void StarView::OnExecuting(
46 // Don't show tooltip to distract user if BookmarkBubbleView is showing. 38 BubbleIconView::ExecuteSource execute_source) {
47 if (BookmarkBubbleView::IsShowing()) 39 BookmarkEntryPoint entry_point = BOOKMARK_ENTRY_POINT_STAR_MOUSE;
48 return false; 40 switch (execute_source) {
49 41 case EXECUTE_SOURCE_MOUSE:
50 return views::ImageView::GetTooltipText(p, tooltip); 42 entry_point = BOOKMARK_ENTRY_POINT_STAR_MOUSE;
43 break;
44 case EXECUTE_SOURCE_KEYBOARD:
45 entry_point = BOOKMARK_ENTRY_POINT_STAR_KEY;
46 break;
47 case EXECUTE_SOURCE_GESTURE:
48 entry_point = BOOKMARK_ENTRY_POINT_STAR_GESTURE;
49 break;
50 }
51 UMA_HISTOGRAM_ENUMERATION("Bookmarks.EntryPoint",
52 entry_point,
53 BOOKMARK_ENTRY_POINT_LIMIT);
51 } 54 }
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
« no previous file with comments | « chrome/browser/ui/views/location_bar/star_view.h ('k') | chrome/browser/ui/views/location_bar/translate_icon_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698